Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error handling on containerised flash tools and fix jetson flash image name #73

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 109 additions & 96 deletions lib/flashing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>(async (resolve, reject) => {
let build = spawn('docker',
[
'build',
'-t',
'jetson-flash-image',
`${JETSON_FLASH_DIR}`
],
{
'stdio': 'inherit'
}
)

if(nvme){
await new Promise<void>(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<void>(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<void>(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<void>(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
Expand Down Expand Up @@ -548,34 +557,38 @@ async function flashIotGate(filename: string, autoKit: Autokit, port: usbPort, d
await autoKit.power.on();

// run flash container
await new Promise<void>(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<void>(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();
Expand Down
Loading