diff --git a/lib/flashing/index.ts b/lib/flashing/index.ts index 2061adb..89d3404 100644 --- a/lib/flashing/index.ts +++ b/lib/flashing/index.ts @@ -380,97 +380,106 @@ async function flashJetson(filename: string, autoKit: Autokit, deviceType: strin await autoKit.power.on(); const powerOnDelay = Number(process.env.CAP_DELAY) || 1000*60*5; + try{ + if(nvme){ + await new Promise(async (resolve, reject) => { + let build = spawn('docker', + [ + 'build', + '-t', + 'jetson-flash-image', + `${JETSON_FLASH_DIR}` + ], + { + 'stdio': 'inherit' + } + ) - if(nvme){ - await new Promise(async (resolve, reject) => { - let build = spawn('docker', - [ - 'build', - '-t', - 'jf-image', - `${JETSON_FLASH_DIR}` - ], - { - 'stdio': 'inherit' - } - ) - - build.on('exit', (code) => { - if (code === 0) { - resolve(); - } else { - reject() - } + build.on('exit', (code) => { + if (code === 0) { + resolve(); + } else { + reject(new Error(`Docker build exit code was: ${code}`)); + } + }); + build.on('error', (err) => { + reject(new Error(`Error with docker build: ${err.message}`)); + }); }); - build.on('error', (err) => { - reject(err); + } else { + await new Promise(async (resolve, reject) => { + let buildAndRun = spawn(`./build.sh`, + [ + `-m`, + `${deviceType}` + ], + { + 'stdio': 'inherit', + 'shell': true, + 'cwd': JETSON_FLASH_DIR + } + ) + + buildAndRun.on('exit', (code) => { + if (code === 0) { + resolve(); + } else { + console.log(`Got exit code ${code}.. error`); + reject(new Error(`Docker build exit code was: ${code}`)); + } + }); + buildAndRun.on('error', (err) => { + reject(new Error(`Error with docker build: ${err.message}`)); + }); }); - }); - } else { + } + } catch (err: any){ + throw new Error(`Failed during jetson-flash container build: ${err.message}`); + } + + // run flash container + console.log(`File path: ${filename}`) + // Then run container + try{ await new Promise(async (resolve, reject) => { - let buildAndRun = spawn(`./build.sh`, + let flash = spawn('docker', [ - `-m`, - `${deviceType}` + 'container', + 'run', + '--rm', + '-it', + '--privileged', + '-v', + '/dev/bus/usb:/dev/bus/usb', + '-v', + '/data:/data/', + '-v', + '/dev:/dev', + 'jetson-flash-image', + `./${JETSON_FLASH_SCRIPT} -f ${filename} -m ${deviceType} --accept-license yes` ], { 'stdio': 'inherit', 'shell': true, - 'cwd': JETSON_FLASH_DIR } ) - buildAndRun.on('exit', (code) => { + flash.on('exit', (code) => { if (code === 0) { resolve(); } else { - reject() + console.log(`Got exit code ${code}.. error`); + reject(new Error(`Docker run exit code was: ${code}`)) } }); - buildAndRun.on('error', (err) => { - reject(err); + flash.on('error', (err) => { + reject(new Error(`Error with docker run: ${err.message}`)); }); }); + } catch(err:any){ + throw new Error(`Failed during jetson-flash container run: ${err.message}`) } - // run flash container - console.log(`File path: ${filename}`) - // Then run container - await new Promise(async (resolve, reject) => { - let flash = spawn('docker', - [ - 'container', - 'run', - '--rm', - '-it', - '--privileged', - '-v', - '/dev/bus/usb:/dev/bus/usb', - '-v', - '/data:/data/', - '-v', - '/dev:/dev', - 'jf-image', - `./${JETSON_FLASH_SCRIPT} -f ${filename} -m ${deviceType} --accept-license yes` - ], - { - 'stdio': 'inherit', - 'shell': true, - } - ) - - flash.on('exit', (code) => { - if (code === 0) { - resolve(); - } else { - reject() - } - }); - flash.on('error', (err) => { - reject(err); - }); - }); - if(nvme){ // wait for jetson to power off @@ -548,34 +557,38 @@ async function flashIotGate(filename: string, autoKit: Autokit, port: usbPort, d await autoKit.power.on(); // run flash container - await new Promise(async (resolve, reject) => { - let flash = spawn('./run_container.sh', - [ - '-a', - 'armv7', - '-d', - dram, - '-i', - filename - ], - { - 'stdio': 'inherit', - 'shell': true, - 'cwd': '/usr/app/iot-gate-imx8plus-flashtools' - } - ) + try{ + await new Promise(async (resolve, reject) => { + let flash = spawn('./run_container.sh', + [ + '-a', + 'armv7', + '-d', + dram, + '-i', + filename + ], + { + 'stdio': 'inherit', + 'shell': true, + 'cwd': '/usr/app/iot-gate-imx8plus-flashtools' + } + ) - flash.on('exit', (code) => { - if (code === 0) { - resolve(); - } else { - reject() - } - }); - flash.on('error', (err) => { - reject(err); + flash.on('exit', (code) => { + if (code === 0) { + resolve(); + } else { + reject(new Error(`Docker run exit code was: ${code}`)) + } + }); + flash.on('error', (err) => { + reject(new Error(`Error with docker run: ${err.message}`)); + }); }); - }); + } catch(err:any){ + throw new Error(`IOT-gate-imx8plus flasher tool failed: ${err.message}`) + } await autoKit.power.off();