From a5402e7c6a7098392b50ad100863296c9d68b45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Sun, 29 Oct 2017 17:47:24 +0100 Subject: [PATCH] Extract checkFirmwareImage() --- scripts/shared.js | 18 ++++++++++++++++++ scripts/update-slave-firmware.js | 21 ++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/scripts/shared.js b/scripts/shared.js index 8e080e2..7d7f896 100644 --- a/scripts/shared.js +++ b/scripts/shared.js @@ -1,5 +1,22 @@ require('shelljs/global'); +function checkFirmwareImage(imagePath, extension) { + if (!imagePath) { + echo('No firmware image specified'); + exit(1); + } + + if (!imagePath.endsWith(extension)) { + echo(`Firmware image extension is not ${extension}`); + exit(1); + } + + if (!test('-f', imagePath)) { + echo('Firmware image does not exist'); + exit(1); + } +} + function getBlhostCmd() { let blhostPath; switch (process.platform) { @@ -37,6 +54,7 @@ function execRetry(command) { } const exp = { + checkFirmwareImage, getBlhostCmd, execRetry, } diff --git a/scripts/update-slave-firmware.js b/scripts/update-slave-firmware.js index 54ab18e..b8b9575 100755 --- a/scripts/update-slave-firmware.js +++ b/scripts/update-slave-firmware.js @@ -3,33 +3,20 @@ const program = require('commander'); require('shelljs/global'); require('./shared') +const extension = '.bin'; config.fatal = true; program - .usage('update-slave-firmware ') + .usage(`update-slave-firmware `) .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); -} - const usbDir = '../../../lib/agent/packages/usb'; const blhostUsb = getBlhostCmd(); const blhostBuspal = blhostUsb + ' --buspal i2c,0x10,100k'; +checkFirmwareImage(firmwareImage, extension); + config.verbose = true; exec(`${usbDir}/send-kboot-command-to-slave.js ping 0x10`); exec(`${usbDir}/jump-to-slave-bootloader.js`);