Make update-slave-firmware.js extremely resilient (not a single failure out of 100 updates). Add shared.js
This commit is contained in:
24
scripts/shared.js
Normal file
24
scripts/shared.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
require('shelljs/global');
|
||||||
|
|
||||||
|
function execRetry(command) {
|
||||||
|
let firstRun = true;
|
||||||
|
let remainingRetries = 3;
|
||||||
|
let code;
|
||||||
|
do {
|
||||||
|
if (!firstRun) {
|
||||||
|
console.log(`Retrying ${command}`)
|
||||||
|
}
|
||||||
|
config.fatal = !remainingRetries;
|
||||||
|
code = exec(command).code;
|
||||||
|
config.fatal = true;
|
||||||
|
firstRun = false;
|
||||||
|
} while(code && --remainingRetries);
|
||||||
|
}
|
||||||
|
|
||||||
|
const exp = {
|
||||||
|
execRetry
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys(exp).forEach(function (cmd) {
|
||||||
|
global[cmd] = exp[cmd];
|
||||||
|
});
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const program = require('commander');
|
const program = require('commander');
|
||||||
require('shelljs/global');
|
require('shelljs/global');
|
||||||
|
require('./shared')
|
||||||
|
|
||||||
config.fatal = true;
|
config.fatal = true;
|
||||||
|
|
||||||
@@ -53,9 +54,12 @@ config.verbose = true;
|
|||||||
exec(`${usbDir}/send-kboot-command-to-slave.js ping 0x10`);
|
exec(`${usbDir}/send-kboot-command-to-slave.js ping 0x10`);
|
||||||
exec(`${usbDir}/jump-to-slave-bootloader.js`);
|
exec(`${usbDir}/jump-to-slave-bootloader.js`);
|
||||||
exec(`${usbDir}/reenumerate.js buspal`);
|
exec(`${usbDir}/reenumerate.js buspal`);
|
||||||
exec(`${blhostBuspal} get-property 1`);
|
execRetry(`${blhostBuspal} get-property 1`);
|
||||||
exec(`${blhostBuspal} flash-erase-all-unsecure`);
|
exec(`${blhostBuspal} flash-erase-all-unsecure`);
|
||||||
exec(`${blhostBuspal} write-memory 0x0 ${firmwareImage}`);
|
exec(`${blhostBuspal} write-memory 0x0 ${firmwareImage}`);
|
||||||
exec(`${blhostUsb} reset`);
|
exec(`${blhostUsb} reset`);
|
||||||
exec(`${usbDir}/reenumerate.js normalKeyboard`);
|
exec(`${usbDir}/reenumerate.js normalKeyboard`);
|
||||||
exec(`${usbDir}/send-kboot-command-to-slave.js reset 0x10`);
|
execRetry(`${usbDir}/send-kboot-command-to-slave.js reset 0x10`);
|
||||||
|
|
||||||
|
config.verbose = false;
|
||||||
|
echo('Firmware updated successfully');
|
||||||
|
|||||||
Reference in New Issue
Block a user