Move updateDeviceFirmware() from update-device-firmware.js to uhk.js

This commit is contained in:
László Monda
2018-01-30 21:48:42 +01:00
parent ca9bf60a1b
commit cac6fdc190
2 changed files with 20 additions and 20 deletions

View File

@@ -127,6 +127,23 @@ let eepromOperations = {
write: 1,
};
async function updateDeviceFirmware(firmwareImage, extension) {
const usbDir = `${__dirname}`;
const blhost = uhk.getBlhostCmd(uhk.enumerationNameToProductId.bootloader);
uhk.checkFirmwareImage(firmwareImage, extension);
config.verbose = true;
await uhk.reenumerate('bootloader');
exec(`${blhost} flash-security-disable 0403020108070605`);
exec(`${blhost} flash-erase-region 0xc000 475136`);
exec(`${blhost} flash-image ${firmwareImage}`);
exec(`${blhost} reset`);
config.verbose = false;
echo('Firmware updated successfully.');
};
// USB commands
function reenumerate(enumerationMode) {
@@ -179,7 +196,7 @@ function reenumerate(enumerationMode) {
})
};
exports = module.exports = moduleExports = {
uhk = exports = module.exports = moduleExports = {
bufferToString,
getUint16,
getUint32,
@@ -192,6 +209,7 @@ exports = module.exports = moduleExports = {
checkFirmwareImage,
getBlhostCmd,
execRetry,
updateDeviceFirmware,
reenumerate,
usbCommands: {
getDeviceProperty : 0x00,

View File

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