Extract updateDeviceFirmware()

This commit is contained in:
László Monda
2018-01-30 21:46:39 +01:00
parent bb7edb8e4d
commit ca9bf60a1b

View File

@@ -3,26 +3,30 @@ const uhk = require('./uhk');
const program = require('commander'); const program = require('commander');
require('shelljs/global'); require('shelljs/global');
const extension = '.hex';
config.fatal = true; config.fatal = true;
const extension = '.hex';
program program
.usage(`firmwareImage${extension}`) .usage(`firmwareImage${extension}`)
.parse(process.argv) .parse(process.argv)
const firmwareImage = program.args[0]; const firmwareImage = program.args[0];
const usbDir = `${__dirname}`;
const blhost = uhk.getBlhostCmd(uhk.enumerationNameToProductId.bootloader);
uhk.checkFirmwareImage(firmwareImage, extension); async function updateDeviceFirmware(firmwareImage, extension) {
const usbDir = `${__dirname}`;
const blhost = uhk.getBlhostCmd(uhk.enumerationNameToProductId.bootloader);
(async function() { uhk.checkFirmwareImage(firmwareImage, extension);
config.verbose = true; config.verbose = true;
await uhk.reenumerate('bootloader'); await uhk.reenumerate('bootloader');
exec(`${blhost} flash-security-disable 0403020108070605`); exec(`${blhost} flash-security-disable 0403020108070605`);
exec(`${blhost} flash-erase-region 0xc000 475136`); exec(`${blhost} flash-erase-region 0xc000 475136`);
exec(`${blhost} flash-image ${firmwareImage}`); exec(`${blhost} flash-image ${firmwareImage}`);
exec(`${blhost} reset`); exec(`${blhost} reset`);
config.verbose = false; config.verbose = false;
echo('Firmware updated successfully.'); echo('Firmware updated successfully.');
})(); };
updateDeviceFirmware(firmwareImage, extension);