From 48a265bc42fa1017c95806803eb257b1e6863696 Mon Sep 17 00:00:00 2001 From: Ernesto Castellotti Date: Wed, 7 Jun 2023 19:47:46 +0200 Subject: Removed use of openPortLineBreak/LineBreakTransformer in unlockHuaweiShell() (#228) --- assets/js/rootLantiq.js | 59 +++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/assets/js/rootLantiq.js b/assets/js/rootLantiq.js index 0bd78fe..f13690c 100644 --- a/assets/js/rootLantiq.js +++ b/assets/js/rootLantiq.js @@ -36,35 +36,33 @@ async function checkUbootUnlocked(serial) { return unlocked; } -async function waitFailbackShell(writer, reader, outputMsgCallback) { - while (true) { - const { value, done } = await reader.read(); - - if (value.startsWith('Press the [f] key and hit [enter] to enter failsafe mode')) { - const interval = setInterval(function() { - writer.write('f\n'); - }, 10); - - outputMsgCallback("Root in progress: Trigger characters received. Waiting for boot to end..."); - await delay(3000); - clearInterval(interval); - break; +async function waitFailbackShell(serial, outputMsgCallback) { + await serial.readLine((line) => { + if (line.startsWith('Press the [f] key and hit [enter] to enter failsafe mode')) { + return true; } - } + }); - const interval = setInterval(function() { - writer.write(String.fromCharCode(10)); + let interval = setInterval(function() { + serial.writeString('f\n'); }, 10); - while (true) { - const { value, done } = await reader.read(); + outputMsgCallback("Root in progress: Trigger characters received. Waiting for boot to end..."); + await delay(3000); + clearInterval(interval); - if (value.includes('root@(none)')) { - await delay(1000); - clearInterval(interval); - break; + interval = setInterval(function() { + serial.writeString(String.fromCharCode(10)); + }, 10); + + await serial.readLine((line) => { + if (line.includes('root@(none)')) { + return true; } - } + }); + + await delay(1000); + clearInterval(interval); } async function lantiqRootUboot(port, sfpModel, outputMsgCallback, outputErrorCallback, baudRate = 115200) { @@ -110,27 +108,26 @@ async function lantiqRootUboot(port, sfpModel, outputMsgCallback, outputErrorCal } async function unlockHuaweiShell(port, outputMsgCallback, outputErrorCallback, baudRate = 115200) { - let reader,writer, readableStreamClosed, writerStreamClosed; + const serial = new SerialReadWrite(port, baudRate); try { - ({ reader, writer, readableStreamClosed, writerStreamClosed } = await openPortLineBreak(port, baudRate)); outputMsgCallback("Root in progress: Rebooting..."); - writer.write('reset\n'); + await serial.writeString('reset\n'); await delay(1000); outputMsgCallback("Waiting for reboot"); - await waitFailbackShell(writer, reader, outputMsgCallback); + await waitFailbackShell(serial, 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 serial.writeString('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 serial.writeString('umount /overlay && umount -a\n'); await delay(1000); - await closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed); return true; } catch (err) { outputErrorCallback(`Error: ${err.message}`); - await closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed); return false; + } finally { + await serial.closePort(); } } -- cgit v1.2.3