Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Dec 9, 2024
1 parent 78a800d commit 812ed57
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
4 changes: 0 additions & 4 deletions src/cli/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ module.exports = ({ commandProcessor, root }) => {
'tachyon' : {
boolean: true,
description: 'Flash Tachyon'
},
'verbose' : {
boolean: false,
description: 'Enable logging'
}
},
handler: (args) => {
Expand Down
33 changes: 6 additions & 27 deletions src/cmd/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ module.exports = class FlashCommand extends CLICommandBase {
target,
port,
yes,
verbose,
tachyon,
verbose,
'application-only': applicationOnly
}) {
if (!tachyon && !device && !binary && !local) {
Expand Down Expand Up @@ -87,39 +87,18 @@ module.exports = class FlashCommand extends CLICommandBase {
unpackToolFolder = path.dirname(files[0]);
}

const parsedFiles = await this._analyzeFiles(files);
let linxuFiles = await this._findLinuxExecutableFiles(parsedFiles.files, { directory: unpackToolFolder });
let linxuFiles = await this._findLinuxExecutableFiles(files, { directory: unpackToolFolder });
linxuFiles = linxuFiles.map(f => path.basename(f));


const elfFiles = linxuFiles.filter(f => f.startsWith('prog') && f.endsWith('.elf'));
const rawProgramFiles = linxuFiles.filter(f => f.startsWith('rawprogram') && f.endsWith('.xml'));
const patchFiles = linxuFiles.filter(f => f.startsWith('patch') && f.endsWith('.xml'));

if (!elfFiles.length || !rawProgramFiles.length || !patchFiles.length) {
throw new Error('The directory should contain at least one .elf file, one rawprogram file, and one patch file');
}

const sortByNumber = (a, b) => {
const extractNumber = str => parseInt(str.match(/(\d+).xml/)[1]);
return extractNumber(a) - extractNumber(b);
};

rawProgramFiles.sort(sortByNumber);
patchFiles.sort(sortByNumber);

if (rawProgramFiles.length !== patchFiles.length) {
throw new Error('The number of rawprogram files should match the number of patch files');
}

let filesToProgram = [];
// interleave the rawprogram files and patch files
for (let i = 0; i < rawProgramFiles.length; i++) {
filesToProgram.push(rawProgramFiles[i]);
filesToProgram.push(patchFiles[i]);
if (!elfFiles.length || !rawProgramFiles.length) {
throw new Error('The directory should contain at least one .elf file, one rawprogram file');
}

filesToProgram.unshift(elfFiles[0]);
let filesToProgram = [elfFiles[0], ...rawProgramFiles, ...patchFiles];

this.ui.write(`Found the following files in the directory:${os.EOL}`);
this.ui.write('Loader file:');
Expand Down Expand Up @@ -157,7 +136,7 @@ module.exports = class FlashCommand extends CLICommandBase {
this.ui.write(`Download complete${os.EOL}`);
}
} catch (err) {
throw new Error(`Download failed. Try powering up your board in EDL mode and try again.${os.EOL}Error: ${err.message}${os.EOL}`);
throw new Error(`Download failed. Try powering up your board in EDL mode and try again.${os.EOL}${err.message}${os.EOL}`);
}
// TODO: Handle errors
}
Expand Down

0 comments on commit 812ed57

Please sign in to comment.