From 1cacc6a72f00a9b1b965494550d5175a76aca218 Mon Sep 17 00:00:00 2001 From: rcooke-warwick Date: Mon, 18 Dec 2023 12:43:57 +0000 Subject: [PATCH] add iot-gate devices Change-type: patch Signed-off-by: Ryan Cooke --- .../devices/ iot-gate-imx8plus-d1d8.json | 4 + lib/flashing/devices/iot-gate-imx8plus.json | 4 + lib/flashing/index.ts | 81 ++++++++++++++++++- lib/index.ts | 2 +- lib/interfaces.d.ts | 9 ++- 5 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 lib/flashing/devices/ iot-gate-imx8plus-d1d8.json create mode 100644 lib/flashing/devices/iot-gate-imx8plus.json diff --git a/lib/flashing/devices/ iot-gate-imx8plus-d1d8.json b/lib/flashing/devices/ iot-gate-imx8plus-d1d8.json new file mode 100644 index 0000000..dc69cb5 --- /dev/null +++ b/lib/flashing/devices/ iot-gate-imx8plus-d1d8.json @@ -0,0 +1,4 @@ +{ + "type": "iot-gate", + "dram": "d1d8" +} \ No newline at end of file diff --git a/lib/flashing/devices/iot-gate-imx8plus.json b/lib/flashing/devices/iot-gate-imx8plus.json new file mode 100644 index 0000000..e645f05 --- /dev/null +++ b/lib/flashing/devices/iot-gate-imx8plus.json @@ -0,0 +1,4 @@ +{ + "type": "iot-gate", + "dram": "d2d4" +} \ No newline at end of file diff --git a/lib/flashing/index.ts b/lib/flashing/index.ts index a5978a1..056012d 100644 --- a/lib/flashing/index.ts +++ b/lib/flashing/index.ts @@ -92,10 +92,15 @@ async function getDrive( /** * Toggles uhubctl-compatible USB port power state **/ -async function toggleUsb(state: boolean, port: string) { +async function toggleUsb(state: boolean, port: usbPort) { console.log(`Toggling USB ${state ? 'on' : 'off'}`); + let loc = '' + if(port.location !== undefined){ + loc = `-l ${port.location}` + } + console.log(`trying: uhubctl -r 1000 -a ${state ? 'on' : 'off'} -p ${port.port} ${loc}`) await exec( - `uhubctl -r 1000 -a ${state ? 'on' : 'off'} -p ${port} -l 1-1`, + `uhubctl -r 1000 -a ${state ? 'on' : 'off'} -p ${port.port} ${loc}`, ).catch(() => { console.log(`Failed. Check that uhubctl is available.`); }); @@ -214,7 +219,7 @@ async function flashFlasher(filename: string, autoKit: Autokit, jumper: boolean) await delay(powerOnDelay) } -async function flashUsbBoot(filename: string, autoKit: Autokit, port: string, power: boolean, jumper: boolean){ +async function flashUsbBoot(filename: string, autoKit: Autokit, port: usbPort, power: boolean, jumper: boolean){ // this delay is how long to wait after internal flashing before trying to re power the board. For the case where devices have capacitors that // take time to drain const powerOnDelay = Number(process.env.CAP_DELAY) || 1000*60; @@ -512,11 +517,73 @@ async function flashJetson(filename: string, autoKit: Autokit, deviceType: strin } +async function flashIotGate(filename: string, autoKit: Autokit, port: usbPort, dram: string){ + const powerOnDelay = Number(process.env.CAP_DELAY) || 1000*60*5; + + // ensure we have latest flasher tool + const IOT_GATE_FLASH_BRANCH = process.env.IOT_GATE_FLASH_BRANCH || 'master'; + let checkout = await exec(`cd /usr/app/iot-gate-imx8plus-flashtools && git fetch && git reset --hard origin/${IOT_GATE_FLASH_BRANCH}`); + + // Ensure DUT is powered off + await autoKit.power.off(); + await delay(5 * 1000); + + // VCC of the programming USB cable is connected to NO relay + // toggle relay "ON" to connect to USB + await autoKit.digitalRelay.on(); + await delay(5 * 1000); + + // Power DUT on + 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' + } + ) + + flash.on('exit', (code) => { + if (code === 0) { + resolve(); + } else { + reject() + } + }); + flash.on('error', (err) => { + reject(err); + }); + }); + + + await autoKit.power.off(); + + // simulate unplugging of the USB programming cable + + // VCC of the programming USB cable is connected to NO relay + // toggle relay "OFF" to connect to disconnect USB + await autoKit.digitalRelay.off(); + await delay(5 * 1000); + + await delay(powerOnDelay); +} + /** * * Flash a given device type, automatically selecting the corresponding flashing method */ -async function flash(filename: string, deviceType: string, autoKit: Autokit, port?: string){ +async function flash(filename: string, deviceType: string, autoKit: Autokit, port?: usbPort){ const flashProcedure = await import(`${__dirname}/devices/${deviceType}.json`); console.log(flashProcedure) switch(flashProcedure.type){ @@ -539,6 +606,12 @@ async function flash(filename: string, deviceType: string, autoKit: Autokit, por await flashJetson(filename, autoKit, deviceType, flashProcedure.nvme); break; } + case 'iot-gate': { + if(port === undefined){ + throw new Error('No usb port specified!') + } + await flashIotGate(filename, autoKit, port, flashProcedure.dram) + } } } diff --git a/lib/index.ts b/lib/index.ts index a237c56..21be759 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -53,7 +53,7 @@ export class Autokit { * Flash a DUT from a file path. **/ async flash(filename: string, deviceType: string){ - await flash(filename, deviceType, this ,this.config.usbBootPort); + await flash(filename, deviceType, this , this.config.usbBootPort); } /** diff --git a/lib/interfaces.d.ts b/lib/interfaces.d.ts index 8cd1cda..5755d1c 100644 --- a/lib/interfaces.d.ts +++ b/lib/interfaces.d.ts @@ -48,10 +48,15 @@ interface AutokitConfig{ sdMux: string; network: string; video: string; - usbBootPort?: string; + usbBootPort?: usbPort; serial: string; digitalRelay: string; } // utility from angular -interface Type extends Function { new (...args: any[]): T; } \ No newline at end of file +interface Type extends Function { new (...args: any[]): T; } + +interface usbPort{ + port: string, + location?: string +} \ No newline at end of file