Port blhost-unix.sh as update-slave-firmware.js using ShellJS.
This commit is contained in:
@@ -1,56 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -e # fail the script if a command fails
|
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
|
||||||
echo "No firmware image specified"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
firmware_image="`pwd`/$1"
|
|
||||||
|
|
||||||
if [ ${firmware_image: -4} != ".bin" ]; then
|
|
||||||
echo "Firmware image extension is not .bin"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f "$firmware_image" ]; then
|
|
||||||
echo "Firmware image does not exist"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
PATH=$PATH:/usr/local/bin # This should make node and npm accessible on OSX.
|
|
||||||
usb_dir=../../../lib/agent/packages/usb
|
|
||||||
usb_binding=$usb_dir/node_modules/usb/build/Release/usb_bindings.node
|
|
||||||
|
|
||||||
case "$(uname -s)" in
|
|
||||||
Linux)
|
|
||||||
blhost_path=linux/amd64
|
|
||||||
;;
|
|
||||||
Darwin)
|
|
||||||
blhost_path=mac
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Your operating system is not supported."
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
blhost_usb="../../../lib/bootloader/bin/Tools/blhost/$blhost_path/blhost --usb 0x1d50,0x6121"
|
|
||||||
blhost_buspal="$blhost_usb --buspal i2c,0x10,100k"
|
|
||||||
|
|
||||||
set -x # echo on
|
|
||||||
|
|
||||||
#if [ ! -f $usb_binding ]; then
|
|
||||||
# cd $usb_dir
|
|
||||||
# npm install
|
|
||||||
#fi
|
|
||||||
|
|
||||||
$usb_dir/send-kboot-command-to-slave.js ping 0x10
|
|
||||||
$usb_dir/jump-to-slave-bootloader.js
|
|
||||||
$usb_dir/reenumerate.js buspal
|
|
||||||
$blhost_buspal get-property 1
|
|
||||||
$blhost_buspal flash-erase-all-unsecure
|
|
||||||
$blhost_buspal write-memory 0x0 "$firmware_image"
|
|
||||||
$blhost_usb reset
|
|
||||||
$usb_dir/reenumerate.js normalKeyboard
|
|
||||||
$usb_dir/send-kboot-command-to-slave.js reset 0x10
|
|
||||||
@@ -11,6 +11,10 @@
|
|||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/UltimateHackingKeyboard/firmware/issues"
|
"url": "https://github.com/UltimateHackingKeyboard/firmware/issues"
|
||||||
},
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"commander": "^2.11.0",
|
||||||
|
"shelljs": "^0.7.8"
|
||||||
|
},
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"dataModelVersion": "1.0.0",
|
"dataModelVersion": "1.0.0",
|
||||||
"usbProtocolVersion": "1.2.0",
|
"usbProtocolVersion": "1.2.0",
|
||||||
|
|||||||
61
scripts/update-slave-firmware.js
Executable file
61
scripts/update-slave-firmware.js
Executable file
@@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const program = require('commander');
|
||||||
|
require('shelljs/global');
|
||||||
|
|
||||||
|
config.fatal = true;
|
||||||
|
|
||||||
|
program
|
||||||
|
.usage('update-slave-firmware <firmware-image>')
|
||||||
|
.parse(process.argv)
|
||||||
|
|
||||||
|
const firmwareImage = program.args[0];
|
||||||
|
|
||||||
|
if (!firmwareImage) {
|
||||||
|
echo('No firmware image specified');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!firmwareImage.endsWith('.bin')) {
|
||||||
|
echo('Firmware image extension is not .bin');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!test('-f', firmwareImage)) {
|
||||||
|
echo('Firmware image does not exist');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var usbDir = '../../../lib/agent/packages/usb';
|
||||||
|
var usbBinding = usbDir + '/node_modules/usb/build/Release/usb_bindings.node';
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
var blhostUsb = `../../../lib/bootloader/bin/Tools/blhost/${blhostPath} --usb 0x1d50,0x6121`;
|
||||||
|
var blhostBuspal = blhostUsb + ' --buspal i2c,0x10,100k';
|
||||||
|
|
||||||
|
config.verbose = true;
|
||||||
|
|
||||||
|
exec(`${usbDir}/send-kboot-command-to-slave.js ping 0x10`);
|
||||||
|
exec(`${usbDir}/jump-to-slave-bootloader.js`);
|
||||||
|
exec(`${usbDir}/reenumerate.js buspal`);
|
||||||
|
exec(`${blhostBuspal} get-property 1`);
|
||||||
|
exec(`${blhostBuspal} flash-erase-all-unsecure`);
|
||||||
|
exec(`${blhostBuspal} write-memory 0x0 ${firmwareImage}`);
|
||||||
|
exec(`${blhostUsb} reset`);
|
||||||
|
exec(`${usbDir}/reenumerate.js normalKeyboard`);
|
||||||
|
exec(`${usbDir}/send-kboot-command-to-slave.js reset 0x10`);
|
||||||
Reference in New Issue
Block a user