Extract getBlhostCmd() to shared.js
This commit is contained in:
+23
-1
@@ -1,5 +1,26 @@
|
|||||||
require('shelljs/global');
|
require('shelljs/global');
|
||||||
|
|
||||||
|
function getBlhostCmd() {
|
||||||
|
let blhostPath;
|
||||||
|
switch (process.platform) {
|
||||||
|
case 'linux':
|
||||||
|
blhostPath = 'linux/amd64/blhost';
|
||||||
|
break;
|
||||||
|
case 'darwin':
|
||||||
|
blhostPath = 'mac/blhost';
|
||||||
|
break;
|
||||||
|
case 'win32':
|
||||||
|
blhostPath = 'win/blhost.exe';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
echo('Your operating system is not supported');
|
||||||
|
exit(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `../../../lib/bootloader/bin/Tools/blhost/${blhostPath} --usb 0x1d50,0x6121`;
|
||||||
|
}
|
||||||
|
|
||||||
function execRetry(command) {
|
function execRetry(command) {
|
||||||
let firstRun = true;
|
let firstRun = true;
|
||||||
let remainingRetries = 3;
|
let remainingRetries = 3;
|
||||||
@@ -16,7 +37,8 @@ function execRetry(command) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exp = {
|
const exp = {
|
||||||
execRetry
|
getBlhostCmd,
|
||||||
|
execRetry,
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(exp).forEach(function (cmd) {
|
Object.keys(exp).forEach(function (cmd) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ program
|
|||||||
.usage('update-slave-firmware <firmware-image>')
|
.usage('update-slave-firmware <firmware-image>')
|
||||||
.parse(process.argv)
|
.parse(process.argv)
|
||||||
|
|
||||||
let firmwareImage = program.args[0];
|
const firmwareImage = program.args[0];
|
||||||
|
|
||||||
if (!firmwareImage) {
|
if (!firmwareImage) {
|
||||||
echo('No firmware image specified');
|
echo('No firmware image specified');
|
||||||
@@ -26,31 +26,11 @@ if (!test('-f', firmwareImage)) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let usbDir = '../../../lib/agent/packages/usb';
|
const usbDir = '../../../lib/agent/packages/usb';
|
||||||
let usbBinding = usbDir + '/node_modules/usb/build/Release/usb_bindings.node';
|
const blhostUsb = getBlhostCmd();
|
||||||
|
const blhostBuspal = blhostUsb + ' --buspal i2c,0x10,100k';
|
||||||
let blhostPath;
|
|
||||||
switch (process.platform) {
|
|
||||||
case 'linux':
|
|
||||||
blhostPath = 'linux/amd64/blhost';
|
|
||||||
break;
|
|
||||||
case 'darwin':
|
|
||||||
blhostPath = 'mac/blhost';
|
|
||||||
break;
|
|
||||||
case 'win32':
|
|
||||||
blhostPath = 'win/blhost.exe';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
echo('Your operating system is not supported');
|
|
||||||
exit(1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
let blhostUsb = `../../../lib/bootloader/bin/Tools/blhost/${blhostPath} --usb 0x1d50,0x6121`;
|
|
||||||
let blhostBuspal = blhostUsb + ' --buspal i2c,0x10,100k';
|
|
||||||
|
|
||||||
config.verbose = true;
|
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`);
|
||||||
@@ -60,6 +40,6 @@ exec(`${blhostBuspal} write-memory 0x0 ${firmwareImage}`);
|
|||||||
exec(`${blhostUsb} reset`);
|
exec(`${blhostUsb} reset`);
|
||||||
exec(`${usbDir}/reenumerate.js normalKeyboard`);
|
exec(`${usbDir}/reenumerate.js normalKeyboard`);
|
||||||
execRetry(`${usbDir}/send-kboot-command-to-slave.js reset 0x10`);
|
execRetry(`${usbDir}/send-kboot-command-to-slave.js reset 0x10`);
|
||||||
|
|
||||||
config.verbose = false;
|
config.verbose = false;
|
||||||
|
|
||||||
echo('Firmware updated successfully');
|
echo('Firmware updated successfully');
|
||||||
|
|||||||
Reference in New Issue
Block a user