@@ -12,7 +12,7 @@ const CloudCommand = require('./cloud');
12
12
const BundleCommand = require ( './bundle' ) ;
13
13
const temp = require ( 'temp' ) . track ( ) ;
14
14
const { knownAppNames, knownAppsForPlatform } = require ( '../lib/known-apps' ) ;
15
- const { sourcePatterns, binaryPatterns, binaryExtensions, linuxExecPatterns } = require ( '../lib/file-types' ) ;
15
+ const { sourcePatterns, binaryPatterns, binaryExtensions } = require ( '../lib/file-types' ) ;
16
16
const deviceOsUtils = require ( '../lib/device-os-version-util' ) ;
17
17
const os = require ( 'os' ) ;
18
18
const semver = require ( 'semver' ) ;
@@ -26,8 +26,11 @@ const {
26
26
} = require ( '../lib/flash-helper' ) ;
27
27
const createApiCache = require ( '../lib/api-cache' ) ;
28
28
const { validateDFUSupport } = require ( './device-util' ) ;
29
+ const unzip = require ( 'unzipper' ) ;
29
30
const qdl = require ( '../lib/qdl' ) ;
30
31
32
+ const TACHYON_MANIFEST_FILE = 'release.json' ;
33
+
31
34
module . exports = class FlashCommand extends CLICommandBase {
32
35
constructor ( ...args ) {
33
36
super ( ...args ) ;
@@ -70,63 +73,105 @@ module.exports = class FlashCommand extends CLICommandBase {
70
73
async flashTachyon ( { verbose, files } ) {
71
74
this . ui . write ( `${ os . EOL } Ensure only one device is connected to the computer${ os . EOL } ` ) ;
72
75
73
- let unpackToolFolder ;
74
- if ( files . length === 0 ) {
75
- // If no files are passed, assume the current directory
76
- unpackToolFolder = process . cwd ( ) ;
77
- files = await fs . readdir ( unpackToolFolder ) ;
78
- } else if ( files . length === 1 ) {
79
- // If only one file is passed, check if it's a directory
80
- const stats = await fs . stat ( files [ 0 ] ) ;
76
+ let zipFile ;
77
+ let includeDir ;
78
+ let firehoseElf ;
79
+ let programXmlFilesWithPath ;
80
+ let patchXmlFilesWithPath ;
81
+
82
+ const readManifest = async ( manifestPath ) => {
83
+ const manifestFile = await fs . readFile ( manifestPath , 'utf8' ) ;
84
+ const manifestData = JSON . parse ( manifestFile ) ;
85
+
86
+ const base = manifestData . targets [ 0 ] . qcm6490 . edl . base ;
87
+ const firehose = manifestData . targets [ 0 ] . qcm6490 . edl . firehose ;
88
+ const programXmlFiles = manifestData . targets [ 0 ] . qcm6490 . edl . program_xml ;
89
+ const patchXmlFiles = manifestData . targets [ 0 ] . qcm6490 . edl . patch_xml ;
90
+
91
+ const baseDir = path . join ( path . dirname ( manifestPath ) , base ) ;
92
+ const programXmlFilesWithPath = programXmlFiles . map ( p => path . join ( baseDir , p ) ) ;
93
+ const patchXmlFilesWithPath = patchXmlFiles . map ( p => path . join ( baseDir , p ) ) ;
94
+
95
+ return { baseDir, firehose, programXmlFilesWithPath, patchXmlFilesWithPath } ;
96
+ } ;
97
+
98
+ const extractZipManifest = async ( zipPath ) => {
99
+ const dir = await unzip . Open . file ( zipPath ) ;
100
+ const zipName = path . basename ( zipPath , '.zip' ) ;
101
+ const manifestFile = dir . files . find ( file => file . path === path . join ( zipName , TACHYON_MANIFEST_FILE ) ) ;
102
+ if ( ! manifestFile ) {
103
+ throw new Error ( `Unable to find ${ TACHYON_MANIFEST_FILE } ${ os . EOL } ` ) ;
104
+ }
105
+
106
+ const manifest = await manifestFile . buffer ( ) ;
107
+ const manifestData = JSON . parse ( manifest . toString ( ) ) ;
108
+
109
+ const baseDir = manifestData . targets [ 0 ] . qcm6490 . edl . base ;
110
+ const firehose = manifestData . targets [ 0 ] . qcm6490 . edl . firehose ;
111
+ const programXmlFiles = manifestData . targets [ 0 ] . qcm6490 . edl . program_xml ;
112
+ const patchXmlFiles = manifestData . targets [ 0 ] . qcm6490 . edl . patch_xml ;
113
+
114
+ const programXmlFilesWithPath = programXmlFiles . map ( p => path . join ( baseDir , p ) ) ;
115
+ const patchXmlFilesWithPath = patchXmlFiles . map ( p => path . join ( baseDir , p ) ) ;
116
+ return { baseDir, firehose, programXmlFilesWithPath, patchXmlFilesWithPath } ;
117
+ } ;
118
+
119
+ const sortByNumber = ( a , b ) => {
120
+ const extractNumber = str => parseInt ( str . match ( / ( \d + ) .x m l / ) [ 1 ] , 10 ) ;
121
+ return extractNumber ( a ) - extractNumber ( b ) ;
122
+ } ;
123
+
124
+ if ( files . length <= 1 ) {
125
+ // If no files are passed, use the current directory
126
+ const input = files . length === 1 ? files [ 0 ] : process . cwd ( ) ;
127
+ const stats = await fs . stat ( input ) ;
128
+
81
129
if ( stats . isDirectory ( ) ) {
82
- unpackToolFolder = files [ 0 ] ;
83
- files = await fs . readdir ( files [ 0 ] ) ;
130
+ const manifestPath = path . join ( input , TACHYON_MANIFEST_FILE ) ;
131
+ if ( ! fs . existsSync ( manifestPath ) ) {
132
+ throw new Error ( `Unable to find ${ TACHYON_MANIFEST_FILE } ${ os . EOL } ` ) ;
133
+ }
134
+ ( { baseDir : includeDir , firehose : firehoseElf , programXmlFilesWithPath, patchXmlFilesWithPath } = await readManifest ( manifestPath ) ) ;
135
+ } else if ( utilities . getFilenameExt ( input ) === '.zip' ) {
136
+ zipFile = path . basename ( input ) ;
137
+ ( { baseDir : includeDir , firehose : firehoseElf , programXmlFilesWithPath, patchXmlFilesWithPath } = await extractZipManifest ( input ) ) ;
138
+ } else {
139
+ throw new Error ( `The provided file is not a directory or a zip file${ os . EOL } ` ) ;
84
140
}
85
141
} else {
86
- // If multiple files are passed, check the directory from the first file
87
- unpackToolFolder = path . dirname ( files [ 0 ] ) ;
142
+ includeDir = path . dirname ( files [ 0 ] ) ;
143
+ firehoseElf = files . filter ( f => f . includes ( 'firehose' ) && f . endsWith ( '.elf' ) ) ;
144
+ programXmlFilesWithPath = files . filter ( f => f . startsWith ( 'rawprogram' ) && f . endsWith ( '.xml' ) ) ;
145
+ patchXmlFilesWithPath = files . filter ( f => f . startsWith ( 'patch' ) && f . endsWith ( '.xml' ) ) ;
88
146
}
89
147
90
- let linxuFiles = await this . _findLinuxExecutableFiles ( files , { directory : unpackToolFolder } ) ;
91
- linxuFiles = linxuFiles . map ( f => path . basename ( f ) ) ;
92
-
93
- const elfFiles = linxuFiles . filter ( f => f . includes ( 'firehose' ) && f . endsWith ( '.elf' ) ) ;
94
- const rawProgramFiles = linxuFiles . filter ( f => f . startsWith ( 'rawprogram' ) && f . endsWith ( '.xml' ) ) ;
95
- const patchFiles = linxuFiles . filter ( f => f . startsWith ( 'patch' ) && f . endsWith ( '.xml' ) ) ;
96
-
97
- if ( ! elfFiles . length || ! rawProgramFiles . length ) {
148
+ if ( ! firehoseElf . length || ! programXmlFilesWithPath . length ) {
98
149
throw new Error ( 'The directory should contain at least one .elf file and one rawprogram file' ) ;
99
150
}
100
151
101
- const sortByNumber = ( a , b ) => {
102
- const extractNumber = str => parseInt ( str . match ( / ( \d + ) .x m l / ) [ 1 ] ) ;
103
- return extractNumber ( a ) - extractNumber ( b ) ;
104
- } ;
105
-
106
- rawProgramFiles . sort ( sortByNumber ) ;
107
- patchFiles . sort ( sortByNumber ) ;
152
+ programXmlFilesWithPath . sort ( sortByNumber ) ;
153
+ patchXmlFilesWithPath . sort ( sortByNumber ) ;
108
154
109
155
let filesToProgram = [ ] ;
110
156
// interleave the rawprogram files and patch files
111
- for ( let i = 0 ; i < rawProgramFiles . length ; i ++ ) {
112
- filesToProgram . push ( rawProgramFiles [ i ] ) ;
113
- filesToProgram . push ( patchFiles [ i ] ) ;
157
+ for ( let i = 0 ; i < programXmlFilesWithPath . length ; i ++ ) {
158
+ filesToProgram . push ( programXmlFilesWithPath [ i ] ) ;
159
+ filesToProgram . push ( patchXmlFilesWithPath [ i ] ) ;
114
160
}
161
+ filesToProgram . unshift ( firehoseElf ) ;
115
162
116
- filesToProgram . unshift ( elfFiles [ 0 ] ) ;
117
-
118
- this . ui . write ( `Found the following files in the directory:${ os . EOL } ` ) ;
163
+ this . ui . write ( `Found the following files:${ os . EOL } ` ) ;
119
164
this . ui . write ( ' Loader file:' ) ;
120
- this . ui . write ( ` - ${ elfFiles [ 0 ] } ${ os . EOL } ` ) ;
165
+ this . ui . write ( ` - ${ firehoseElf } ${ os . EOL } ` ) ;
121
166
122
167
this . ui . write ( ' Program files:' ) ;
123
- for ( const file of rawProgramFiles ) {
168
+ for ( const file of programXmlFilesWithPath ) {
124
169
this . ui . write ( ` - ${ file } ` ) ;
125
170
}
126
171
this . ui . write ( os . EOL ) ;
127
172
128
173
this . ui . write ( ' Patch files:' ) ;
129
- for ( const file of patchFiles ) {
174
+ for ( const file of patchXmlFilesWithPath ) {
130
175
this . ui . write ( ` - ${ file } ` ) ;
131
176
}
132
177
this . ui . write ( os . EOL ) ;
@@ -136,7 +181,8 @@ module.exports = class FlashCommand extends CLICommandBase {
136
181
try {
137
182
const res = await qdl . run ( {
138
183
files : filesToProgram ,
139
- updateFolder : unpackToolFolder ,
184
+ updateFolder : includeDir ,
185
+ zip : zipFile ,
140
186
verbose,
141
187
ui : this . ui
142
188
} ) ;
@@ -387,37 +433,24 @@ module.exports = class FlashCommand extends CLICommandBase {
387
433
}
388
434
389
435
async _findBinaries ( parsedFiles ) {
390
- return this . _findFiles ( parsedFiles , binaryPatterns ) ;
391
- }
392
-
393
- async _findLinuxExecutableFiles ( parsedFiles , { directory } ) {
394
-
395
- if ( directory ) {
396
- const files = parsedFiles . map ( f => path . join ( directory , f ) ) ;
397
- return this . _findFiles ( files , linuxExecPatterns ) ;
398
- }
399
- return this . _findFiles ( parsedFiles , linuxExecPatterns ) ;
400
- }
401
-
402
- async _findFiles ( files , patterns ) {
403
- const resFiles = new Set ( ) ;
404
- for ( const filePath of files ) {
436
+ const binaries = new Set ( ) ;
437
+ for ( const filePath of parsedFiles ) {
405
438
try {
406
439
const stats = await fs . stat ( filePath ) ;
407
440
if ( stats . isDirectory ( ) ) {
408
- const found = utilities . globList ( filePath , patterns ) ;
409
- for ( const file of found ) {
410
- resFiles . add ( file ) ;
441
+ const found = utilities . globList ( filePath , binaryPatterns ) ;
442
+ for ( const binary of found ) {
443
+ binaries . add ( binary ) ;
411
444
}
412
445
} else {
413
- resFiles . add ( filePath ) ;
446
+ binaries . add ( filePath ) ;
414
447
}
415
448
} catch ( error ) {
416
449
throw new Error ( `I couldn't find that: ${ filePath } ` ) ;
417
450
}
418
451
419
452
}
420
- return Array . from ( resFiles ) ;
453
+ return Array . from ( binaries ) ;
421
454
}
422
455
423
456
async _processBundle ( { filesToFlash } ) {
0 commit comments