summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--_ont/ont-huawei-ma5671a-root-web.md75
-rw-r--r--assets/js/rootLantiq.js96
-rw-r--r--assets/js/utils.js29
3 files changed, 111 insertions, 89 deletions
diff --git a/_ont/ont-huawei-ma5671a-root-web.md b/_ont/ont-huawei-ma5671a-root-web.md
index 9f3eeaf..a68c09d 100644
--- a/_ont/ont-huawei-ma5671a-root-web.md
+++ b/_ont/ont-huawei-ma5671a-root-web.md
@@ -103,6 +103,7 @@ FALCON => saveenv
</div>
</div>
</div>
+<script type="text/javascript" src="/assets/js/utils.js"></script>
<script type="text/javascript" src="/assets/js/rootLantiq.js"></script>
<script>
if ('serial' in navigator) {
@@ -183,58 +184,32 @@ FALCON => saveenv
console.log('Error: port not open\n');
return;
}
- loading("Please disconnect the Huawei MA5671A from the SFP adapter if it is currently plugged in!",0);
- try {
- await port.open({ baudRate: 115200 });
- } catch (err) {
- showError(`Error: ${err.message}`,0);
- console.log(`Error: ${err.message}\n`);
- return;
- }
- const textDecoder = new TextDecoderStream();
- const readableStreamClosed = port.readable.pipeTo(textDecoder.writable);
- const reader = textDecoder.readable.pipeThrough(new TransformStream(new LineBreakTransformer())).getReader();
- const textEncoderStream = new TextEncoderStream();
- const writerStreamClosed = textEncoderStream.readable.pipeTo(port.writable);
- const writer = textEncoderStream.writable.getWriter();
- try {
- await lantiqRootUboot(writer, reader, (msg) => {
- loading(msg, 0);
- });
- showSuccess("Congratulations! Step completed.", 0);
- } catch (err) {
- showError(`Error: ${err.message}`,0);
- console.log(`Error: ${err.message}\n`);
- reader.cancel();
- await readableStreamClosed.catch(() => { /* Ignore the error */ });
- writer.close();
- await writerStreamClosed;
- await port.close();
- return;
- }
- try {
- await unlockHuaweiShell(writer, reader, (msg) => {
+ await lantiqRootUboot(port,
+ (msg) => {
+ loading(msg, 0);
+ },
+ (err) => {
+ showError(err, 0);
+ console.log(err);
+ },
+ () => {
+ showSuccess("Congratulations! Step completed.", 0);
+ }
+ );
+
+ await unlockHuaweiShell(port,
+ (msg) => {
loading(msg, 1);
- });
-
- showSuccess("Congratulations! Step completed.",1);
- } catch (err) {
- showError(`Error: ${err.message}`,1);
- console.log(`Error: ${err.message}\n`);
- reader.cancel();
- await readableStreamClosed.catch(() => { /* Ignore the error */ });
- writer.close();
- await writerStreamClosed;
- await port.close();
- return;
- }
-
- reader.cancel();
- await readableStreamClosed.catch(() => { /* Ignore the error */ });
- writer.close();
- await writerStreamClosed;
- await port.close();
+ },
+ (err) => {
+ showError(err, 1);
+ console.log(err);
+ },
+ () => {
+ showSuccess("Congratulations! Step completed.", 1);
+ }
+ );
}
</script>
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();
+}