Skip to content

Commit

Permalink
Flashing tachyon via zip file and directory works
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Dec 17, 2024
1 parent e70ea14 commit 254448d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
Binary file modified assets/qdl/darwin/x64/qdl
Binary file not shown.
Binary file added assets/qdl/darwin/x64/qdl-old
Binary file not shown.
57 changes: 36 additions & 21 deletions src/cmd/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ module.exports = class FlashCommand extends CLICommandBase {
this.ui.write(`${os.EOL}Ensure only one device is connected to the computer${os.EOL}`);

let zipFile;
let includeDir;
let includeDir = '';
let updateFolder = '';

if (files.length == 0) {
if (files.length === 0) {
// If no files are passed, use the current directory
files = ['.'];
}
Expand All @@ -86,30 +87,42 @@ module.exports = class FlashCommand extends CLICommandBase {
let filesToProgram;

if (stats.isDirectory()) {
({ baseDir: includeDir, filesToProgram } = await this._extractFlashFilesFromDir(input));
updateFolder = path.dirname(input);
const dirInfo = await this._extractFlashFilesFromDir(input);
includeDir = path.join(path.basename(input),dirInfo.baseDir);
filesToProgram = dirInfo.filesToProgram;
} else if (utilities.getFilenameExt(input) === '.zip') {
updateFolder = path.dirname(input);
zipFile = path.basename(input);
({ baseDir: includeDir, filesToProgram } = await this._extractFlashFilesFromZip(input));
const zipInfo = await this._extractFlashFilesFromZip(input);
const zipFileName = path.basename(input, '.zip'); // remove the .zip extension
includeDir = path.join(zipFileName, zipInfo.baseDir);
filesToProgram = zipInfo.filesToProgram;
} else {
filesToProgram = files;
}
// remove the first / from the update folder and all the files
includeDir = includeDir.replace(/^\//, '');

filesToProgram = filesToProgram.map((file) => path.join(includeDir, file));
filesToProgram = filesToProgram.map((file) => file.replace(/^\//, ''));

this.ui.write(`Starting download. The download may take several minutes...${os.EOL}`);

const res = await qdl.run({
files: filesToProgram,
updateFolder: includeDir,
includeDir,
updateFolder,
zip: zipFile,
verbose,
ui: this.ui
});
// put the output in a log file if not verbose
if (!verbose) {
const outputLog = path.join(process.cwd(), `qdl-output-${Date.now()}.log`);
await fs.writeFile(outputLog, res.stdout);
if (res?.stdout) {
await fs.writeFile(outputLog, res.stdout);
}
this.ui.write(`Download complete. Output log available at ${outputLog}${os.EOL}`);
} else {
this.ui.write(`Download complete${os.EOL}`);
Expand All @@ -124,12 +137,13 @@ module.exports = class FlashCommand extends CLICommandBase {
}
const data = await this._loadManifestFromFile(manifestPath);
const parsed = this._parseManfiestData(data);

const baseDir = path.join(path.dirname(manifestPath), parsed.base);

// const baseDir = path.join(path.dirname(manifestPath), parsed.base);
const baseDir = parsed.base;
const filesToProgram = await this._getFilesInOrder({
programXml: parsed.programXml.map(p => path.join(baseDir, p)),
patchXml: parsed.patchXml.map(p => path.join(baseDir, p)),
firehoseElf: path.join(baseDir, parsed.firehose)
programXml: parsed.programXml,
patchXml: parsed.patchXml.map,
firehoseElf: parsed.firehose
});

return { baseDir, filesToProgram };
Expand All @@ -145,9 +159,9 @@ module.exports = class FlashCommand extends CLICommandBase {
const baseDir = parsed.base;

const filesToProgram = await this._getFilesInOrder({
programXml: parsed.programXml.map(p => path.join(baseDir, p)),
patchXml: parsed.patchXml.map(p => path.join(baseDir, p)),
firehoseElf: path.join(baseDir, parsed.firehose)
programXml: parsed.programXml,
patchXml: parsed.patchXml,
firehoseElf: parsed.firehose
});

return { baseDir, filesToProgram };
Expand Down Expand Up @@ -186,13 +200,14 @@ module.exports = class FlashCommand extends CLICommandBase {
if (programXml.length === 0) {
throw new Error('Unable to find program xml files');
}
let files = [];
// interleave the rawprogram files and patch files
for (let i = 0; i < programXml.length; i++) {
files.push(programXml[i]);
files.push(patchXml[i]);
}
files.unshift(firehoseElf);
let files = [
firehoseElf,
...programXml.flatMap((programFile, i) => [
programFile,
patchXml[i]
].filter(Boolean))
].filter(Boolean);

return files;
}

Expand Down
13 changes: 6 additions & 7 deletions src/lib/qdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const utilities = require('../lib/utilities');
const path = require('path');
const fs = require('fs-extra');
const os = require('os');
const { update } = require('lodash');

const TACHYON_STORAGE_TYPE = 'ufs';

Expand All @@ -18,23 +17,23 @@ async function getExecutable() {

/**
*/
async function run({ files, updateFolder, zip, verbose, ui }) {
async function run({ files, includeDir, updateFolder, zip, verbose, ui }) {
const qdl = await getExecutable();

const qdlArgs = [
'--storage',
'--storage',
TACHYON_STORAGE_TYPE,
...(zip ? ['--zip', zip] : []),
...(updateFolder ? ['--include', updateFolder] : []),
...(includeDir ? ['--include', includeDir] : []),
...files
];

if (verbose) {
ui.write(`Command: ${qdl} ${qdlArgs.join(' ')}`);
ui.write(`Command: ${qdl} ${qdlArgs.join(' ')}${os.EOL}`);
}

const res = await execa(qdl, qdlArgs, {
cwd: updateFolder,
cwd: updateFolder || process.cwd(),
stdio: verbose ? 'inherit' : 'pipe'
});

Expand Down

0 comments on commit 254448d

Please sign in to comment.