Skip to content

Commit 48a265b

Browse files
author
Ernesto Castellotti
authored
Removed use of openPortLineBreak/LineBreakTransformer in unlockHuaweiShell() (#228)
1 parent b9c46c0 commit 48a265b

1 file changed

Lines changed: 28 additions & 31 deletions

File tree

assets/js/rootLantiq.js

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,33 @@ async function checkUbootUnlocked(serial) {
3636
return unlocked;
3737
}
3838

39-
async function waitFailbackShell(writer, reader, outputMsgCallback) {
40-
while (true) {
41-
const { value, done } = await reader.read();
42-
43-
if (value.startsWith('Press the [f] key and hit [enter] to enter failsafe mode')) {
44-
const interval = setInterval(function() {
45-
writer.write('f\n');
46-
}, 10);
47-
48-
outputMsgCallback("Root in progress: Trigger characters received. Waiting for boot to end...");
49-
await delay(3000);
50-
clearInterval(interval);
51-
break;
39+
async function waitFailbackShell(serial, outputMsgCallback) {
40+
await serial.readLine((line) => {
41+
if (line.startsWith('Press the [f] key and hit [enter] to enter failsafe mode')) {
42+
return true;
5243
}
53-
}
44+
});
5445

55-
const interval = setInterval(function() {
56-
writer.write(String.fromCharCode(10));
46+
let interval = setInterval(function() {
47+
serial.writeString('f\n');
5748
}, 10);
5849

59-
while (true) {
60-
const { value, done } = await reader.read();
50+
outputMsgCallback("Root in progress: Trigger characters received. Waiting for boot to end...");
51+
await delay(3000);
52+
clearInterval(interval);
6153

62-
if (value.includes('root@(none)')) {
63-
await delay(1000);
64-
clearInterval(interval);
65-
break;
54+
interval = setInterval(function() {
55+
serial.writeString(String.fromCharCode(10));
56+
}, 10);
57+
58+
await serial.readLine((line) => {
59+
if (line.includes('root@(none)')) {
60+
return true;
6661
}
67-
}
62+
});
63+
64+
await delay(1000);
65+
clearInterval(interval);
6866
}
6967

7068
async function lantiqRootUboot(port, sfpModel, outputMsgCallback, outputErrorCallback, baudRate = 115200) {
@@ -110,27 +108,26 @@ async function lantiqRootUboot(port, sfpModel, outputMsgCallback, outputErrorCal
110108
}
111109

112110
async function unlockHuaweiShell(port, outputMsgCallback, outputErrorCallback, baudRate = 115200) {
113-
let reader,writer, readableStreamClosed, writerStreamClosed;
111+
const serial = new SerialReadWrite(port, baudRate);
114112

115113
try {
116-
({ reader, writer, readableStreamClosed, writerStreamClosed } = await openPortLineBreak(port, baudRate));
117114
outputMsgCallback("Root in progress: Rebooting...");
118-
writer.write('reset\n');
115+
await serial.writeString('reset\n');
119116
await delay(1000);
120117
outputMsgCallback("Waiting for reboot");
121-
await waitFailbackShell(writer, reader, outputMsgCallback);
118+
await waitFailbackShell(serial, outputMsgCallback);
122119
outputMsgCallback("Root in progress: Enable full Linux shell...");
123-
writer.write('mount_root && mkdir -p /overlay/etc && sed "s|/opt/lantiq/bin/minishell|/bin/ash|g" /rom/etc/passwd > /overlay/etc/passwd\n');
120+
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');
124121
await delay(1000);
125122
outputMsgCallback("Root in progress: Umount rootfs partitions...");
126-
writer.write('umount /overlay && umount -a\n');
123+
await serial.writeString('umount /overlay && umount -a\n');
127124
await delay(1000);
128-
await closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed);
129125
return true;
130126
} catch (err) {
131127
outputErrorCallback(`Error: ${err.message}`);
132-
await closePortLineBreak(port, reader, writer, readableStreamClosed, writerStreamClosed);
133128
return false;
129+
} finally {
130+
await serial.closePort();
134131
}
135132
}
136133

0 commit comments

Comments
 (0)