summaryrefslogtreecommitdiffstats
path: root/assets/js
diff options
context:
space:
mode:
authorErnesto Castellotti <mail@ernestocastellotti.it>2023-01-11 00:55:41 +0100
committerSimone <26844016+simonebortolin@users.noreply.github.com>2023-01-12 00:02:02 +0100
commit85e80a257f014abf1dae161ad1052d65bb6bea85 (patch)
tree2b0662a0b06a484f705febb0f4546e4e86978eca /assets/js
parentMoved all root process to rootLantiq.js (diff)
downloadhack-gpon.github.io-85e80a257f014abf1dae161ad1052d65bb6bea85.tar
hack-gpon.github.io-85e80a257f014abf1dae161ad1052d65bb6bea85.tar.gz
hack-gpon.github.io-85e80a257f014abf1dae161ad1052d65bb6bea85.tar.bz2
hack-gpon.github.io-85e80a257f014abf1dae161ad1052d65bb6bea85.tar.lz
hack-gpon.github.io-85e80a257f014abf1dae161ad1052d65bb6bea85.tar.xz
hack-gpon.github.io-85e80a257f014abf1dae161ad1052d65bb6bea85.tar.zst
hack-gpon.github.io-85e80a257f014abf1dae161ad1052d65bb6bea85.zip
Diffstat (limited to '')
-rw-r--r--assets/js/rootLantiq.js96
-rw-r--r--assets/js/utils.js29
2 files changed, 86 insertions, 39 deletions
diff --git a/assets/js/rootLantiq.js b/assets/js/rootLantiq.js
index a25d202..36e6506 100644
--- a/assets/js/rootLantiq.js
+++ b/assets/js/rootLantiq.js
@@ -1,7 +1,3 @@
-function delay(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
-}
-
async function waitUbootStop(writer, reader, outputMsgCallback) {
const interval = setInterval(function() {
writer.write(String.fromCharCode(3));
@@ -67,47 +63,69 @@ async function waitFailbackShell(writer, reader, outputMsgCallback) {
}
}
-async function lantiqRootUboot(writer, reader, outputMsgCallback) {
- await delay(10000);
- outputMsgCallback("Now you need to insert the Huawei MA5671A into the SFP adapter, if the procedure does not go ahead, check the connections and then remove and reconnect the Huawei MA5671A again",0);
+async function lantiqRootUboot(port, outputMsgCallback, outputErrorCallback, successCallback, baudRate = 115200) {
+ outputMsgCallback("Please disconnect the Huawei MA5671A from the SFP adapter if it is currently plugged in!");
- while(true) {
- await waitUbootStop(writer, reader, outputMsgCallback);
- const ubootUnlocked = await checkUbootUnlocked(reader);
+ const { reader, writer, readableStreamClosed, writerStreamClosed } = await openPortLineBreak(port, baudRate, outputErrorCallback);
- if (ubootUnlocked == true) {
- break;
+ try {
+ await delay(10000);
+ outputMsgCallback("Now you need to insert the Huawei MA5671A into the SFP adapter, if the procedure does not go ahead, check the connections and then remove and reconnect the Huawei MA5671A again",0);
+
+ while(true) {
+ await waitUbootStop(writer, reader, outputMsgCallback);
+ const ubootUnlocked = await checkUbootUnlocked(reader);
+
+ if (ubootUnlocked == true) {
+ break;
+ }
+
+ outputMsgCallback("Root in progress: Set U-Boot bootdelay to 5...");
+ writer.write('setenv bootdelay 5\n');
+ await delay(1000);
+ outputMsgCallback("Root in progress: Enable ASC serial...");
+ writer.write('setenv asc0 0\n');
+ await delay(1000);
+ outputMsgCallback("Root in progress: Set GPIO to unlock serial...");
+ writer.write('setenv preboot "gpio set 3;gpio input 2;gpio input 105;gpio input 106;gpio input 107;gpio input 108"\n');
+ await delay(1000);
+ outputMsgCallback("Root in progress: Save changes...");
+ writer.write('saveenv\n');
+ await delay(1000);
+ outputMsgCallback("Root in progress: Rebooting...");
+ writer.write('reset\n');
+ await delay(1000);
}
- outputMsgCallback("Root in progress: Set U-Boot bootdelay to 5...");
- writer.write('setenv bootdelay 5\n');
- await delay(1000);
- outputMsgCallback("Root in progress: Enable ASC serial...");
- writer.write('setenv asc0 0\n');
- await delay(1000);
- outputMsgCallback("Root in progress: Set GPIO to unlock serial...");
- writer.write('setenv preboot "gpio set 3;gpio input 2;gpio input 105;gpio input 106;gpio input 107;gpio input 108"\n');
- await delay(1000);
- outputMsgCallback("Root in progress: Save changes...");
- writer.write('saveenv\n');
- await delay(1000);
+ successCallback();
+ } catch (err) {
+ outputErrorCallback(`Error: ${err.message}`);
+ } finally {
+ await closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed);
+ return;
+ }
+}
+
+async function unlockHuaweiShell(port, outputMsgCallback, outputErrorCallback, successCallback, baudRate = 115200) {
+ const { reader, writer, readableStreamClosed, writerStreamClosed } = await openPortLineBreak(port, baudRate, outputErrorCallback);
+
+ try {
outputMsgCallback("Root in progress: Rebooting...");
writer.write('reset\n');
await delay(1000);
+ outputMsgCallback("Waiting for reboot");
+ await waitFailbackShell(writer, reader, outputMsgCallback);
+ outputMsgCallback("Root in progress: Enable full Linux shell...");
+ writer.write('mount_root && mkdir -p /overlay/etc && sed "s|/opt/lantiq/bin/minishell|/bin/ash|g" /rom/etc/passwd > /overlay/etc/passwd\n');
+ await delay(1000);
+ outputMsgCallback("Root in progress: Umount rootfs partitions...");
+ writer.write('umount /overlay && umount -a\n');
+ await delay(1000);
+ successCallback();
+ } catch (err) {
+ outputErrorCallback(`Error: ${err.message}`);
+ } finally {
+ await closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed);
+ return;
}
-
- outputMsgCallback("Root in progress: RebootingYY...");
- writer.write('reset\n');
- await delay(1000);
-}
-
-async function unlockHuaweiShell(writer, reader, outputMsgCallback) {
- outputMsgCallback("Waiting for reboot");
- await waitFailbackShell(writer, reader);
- outputMsgCallback("Root in progress: Enable full Linux shell...");
- writer.write('mount_root && mkdir -p /overlay/etc && sed "s|/opt/lantiq/bin/minishell|/bin/ash|g" /rom/etc/passwd > /overlay/etc/passwd\n');
- await delay(1000);
- outputMsgCallback("Root in progress: Umount rootfs partitions...");
- writer.write('umount /overlay && umount -a\n');
- await delay(1000);
}
diff --git a/assets/js/utils.js b/assets/js/utils.js
new file mode 100644
index 0000000..8ce3c6e
--- /dev/null
+++ b/assets/js/utils.js
@@ -0,0 +1,29 @@
+function delay(ms) {
+ return new Promise(resolve => setTimeout(resolve, ms));
+}
+
+async function openPortLineBreak(port, baudRate, outputErrorCallback) {
+ try {
+ await port.open({ baudRate: baudRate });
+ } catch (err) {
+ outputErrorCallback(`Error: ${err.message}`);
+ return;
+ }
+
+ const textDecoder = new TextDecoderStream();
+ const readableStreamClosed = port.readable.pipeTo(textDecoder.writable);
+ const reader = await textDecoder.readable.pipeThrough(new TransformStream(new LineBreakTransformer())).getReader();
+ const textEncoderStream = new TextEncoderStream();
+ const writerStreamClosed = textEncoderStream.readable.pipeTo(port.writable);
+ const writer = await textEncoderStream.writable.getWriter();
+
+ return { reader, writer, readableStreamClosed, writerStreamClosed };
+}
+
+async function closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed) {
+ reader.cancel();
+ await readableStreamClosed.catch(() => { /* Ignore the error */ });
+ writer.close();
+ await writerStreamClosed;
+ await port.close();
+}