@onekeyfe/hardware-cli 1.2.0-alpha.96 → 1.2.0-alpha.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +5 -2
- package/dist/cli.js +20 -4
- package/package.json +6 -6
- package/src/__tests__/firmware-update-v4-command.test.ts +0 -1
- package/src/cli.ts +27 -7
package/dist/cli.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ export declare function runFirmwareUpdateV4WithRetry({ sdk, globalOpts, params,
|
|
|
53
53
|
}): Promise<unknown>;
|
|
54
54
|
declare function buildFirmwareUpdateV4Params(opts: {
|
|
55
55
|
chunkSize?: string;
|
|
56
|
+
resourceFile?: string[];
|
|
56
57
|
romloader?: string;
|
|
57
58
|
bootloader?: string;
|
|
58
59
|
applicationP1?: string;
|
|
@@ -62,13 +63,16 @@ declare function buildFirmwareUpdateV4Params(opts: {
|
|
|
62
63
|
se02?: string;
|
|
63
64
|
se03?: string;
|
|
64
65
|
se04?: string;
|
|
65
|
-
resourceArchive?: string;
|
|
66
66
|
forcedUpdateRes?: boolean;
|
|
67
67
|
}): {
|
|
68
68
|
platform: "desktop";
|
|
69
69
|
connectProtocol: "V2";
|
|
70
70
|
chunkSize: number | undefined;
|
|
71
71
|
forcedUpdateRes: boolean | undefined;
|
|
72
|
+
resourceFiles: {
|
|
73
|
+
binary: ArrayBuffer;
|
|
74
|
+
devicePath: string;
|
|
75
|
+
}[] | undefined;
|
|
72
76
|
romloaderBinary: ArrayBuffer | undefined;
|
|
73
77
|
bootloaderBinary: ArrayBuffer | undefined;
|
|
74
78
|
applicationP1Binary: ArrayBuffer | undefined;
|
|
@@ -78,6 +82,5 @@ declare function buildFirmwareUpdateV4Params(opts: {
|
|
|
78
82
|
se02Binary: ArrayBuffer | undefined;
|
|
79
83
|
se03Binary: ArrayBuffer | undefined;
|
|
80
84
|
se04Binary: ArrayBuffer | undefined;
|
|
81
|
-
resourceArchiveBinary: ArrayBuffer | undefined;
|
|
82
85
|
};
|
|
83
86
|
export { program };
|
package/dist/cli.js
CHANGED
|
@@ -485,6 +485,7 @@ program
|
|
|
485
485
|
.command('firmware-update-v4')
|
|
486
486
|
.description('Run Protocol V2 firmware update through sdk.firmwareUpdateV4')
|
|
487
487
|
.option('--chunk-size <bytes>', 'Transfer chunk size in bytes')
|
|
488
|
+
.option('--resource-file <spec...>', 'Resource direct-write spec: <localPath>:<devicePath>, e.g. wallpaper.okpkg:vol0:/bundles/images/wallpaper.okpkg')
|
|
488
489
|
.option('--romloader <path>', 'FW_MGMT_TARGET_ROMLOADER binary path')
|
|
489
490
|
.option('--bootloader <path>', 'FW_MGMT_TARGET_BOOTLOADER binary path')
|
|
490
491
|
.option('--application-p1 <path>', 'FW_MGMT_TARGET_APPLICATION_P1 binary path')
|
|
@@ -494,7 +495,6 @@ program
|
|
|
494
495
|
.option('--se02 <path>', 'FW_MGMT_TARGET_SE02 binary path')
|
|
495
496
|
.option('--se03 <path>', 'FW_MGMT_TARGET_SE03 binary path')
|
|
496
497
|
.option('--se04 <path>', 'FW_MGMT_TARGET_SE04 binary path')
|
|
497
|
-
.option('--resource-archive <path>', 'Complete signed Protocol V2 resource ZIP path')
|
|
498
498
|
.option('--forced-update-res', 'Force resource update')
|
|
499
499
|
.option('--retries <count>', 'Retry count for transient Protocol V2 USB probe failures')
|
|
500
500
|
.action(opts => runCommand({}, async ({ sdk, globalOpts }) => {
|
|
@@ -957,8 +957,24 @@ async function resolveLegacyFirmwareConnectId(sdk, explicitConnectId, deviceName
|
|
|
957
957
|
throw new Error(`BLE device has no connect ID: ${name}`);
|
|
958
958
|
return connectId;
|
|
959
959
|
}
|
|
960
|
+
function parseResourceFileParam(spec) {
|
|
961
|
+
const sep = spec.indexOf(':');
|
|
962
|
+
if (sep <= 0 || sep === spec.length - 1) {
|
|
963
|
+
throw new Error(`Invalid --resource-file value: "${spec}". Expected <localPath>:<devicePath>`);
|
|
964
|
+
}
|
|
965
|
+
const localPath = spec.slice(0, sep);
|
|
966
|
+
const devicePath = spec.slice(sep + 1);
|
|
967
|
+
if (!devicePath.startsWith('vol')) {
|
|
968
|
+
throw new Error(`Invalid --resource-file device path: "${devicePath}". Expected a vol*:/... path`);
|
|
969
|
+
}
|
|
970
|
+
return {
|
|
971
|
+
binary: readBinaryParam(localPath),
|
|
972
|
+
devicePath,
|
|
973
|
+
};
|
|
974
|
+
}
|
|
960
975
|
function getFirmwareUpdateV4TotalBytes(params) {
|
|
961
976
|
return [
|
|
977
|
+
...(params.resourceFiles?.map(item => item.binary) ?? []),
|
|
962
978
|
params.bootloaderBinary,
|
|
963
979
|
params.applicationP1Binary,
|
|
964
980
|
params.applicationP2Binary,
|
|
@@ -1193,6 +1209,7 @@ function buildFirmwareUpdateV4Params(opts) {
|
|
|
1193
1209
|
connectProtocol: 'V2',
|
|
1194
1210
|
chunkSize: opts.chunkSize ? safeParseInt(opts.chunkSize, '--chunk-size') : undefined,
|
|
1195
1211
|
forcedUpdateRes: opts.forcedUpdateRes,
|
|
1212
|
+
resourceFiles: opts.resourceFile?.map(parseResourceFileParam),
|
|
1196
1213
|
romloaderBinary: opts.romloader ? readBinaryParam(opts.romloader) : undefined,
|
|
1197
1214
|
bootloaderBinary: opts.bootloader ? readBinaryParam(opts.bootloader) : undefined,
|
|
1198
1215
|
applicationP1Binary: opts.applicationP1 ? readBinaryParam(opts.applicationP1) : undefined,
|
|
@@ -1202,9 +1219,9 @@ function buildFirmwareUpdateV4Params(opts) {
|
|
|
1202
1219
|
se02Binary: opts.se02 ? readBinaryParam(opts.se02) : undefined,
|
|
1203
1220
|
se03Binary: opts.se03 ? readBinaryParam(opts.se03) : undefined,
|
|
1204
1221
|
se04Binary: opts.se04 ? readBinaryParam(opts.se04) : undefined,
|
|
1205
|
-
resourceArchiveBinary: opts.resourceArchive ? readBinaryParam(opts.resourceArchive) : undefined,
|
|
1206
1222
|
};
|
|
1207
1223
|
const hasPayload = [
|
|
1224
|
+
params.resourceFiles,
|
|
1208
1225
|
params.romloaderBinary,
|
|
1209
1226
|
params.bootloaderBinary,
|
|
1210
1227
|
params.applicationP1Binary,
|
|
@@ -1214,10 +1231,9 @@ function buildFirmwareUpdateV4Params(opts) {
|
|
|
1214
1231
|
params.se02Binary,
|
|
1215
1232
|
params.se03Binary,
|
|
1216
1233
|
params.se04Binary,
|
|
1217
|
-
params.resourceArchiveBinary,
|
|
1218
1234
|
].some(Boolean);
|
|
1219
1235
|
if (!hasPayload) {
|
|
1220
|
-
const err = new Error('firmware-update-v4 requires at least one
|
|
1236
|
+
const err = new Error('firmware-update-v4 requires at least one binary path');
|
|
1221
1237
|
err.code = 'MISSING_FIRMWARE_BINARY';
|
|
1222
1238
|
throw err;
|
|
1223
1239
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hardware-cli",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.97",
|
|
4
4
|
"description": "OneKey hardware wallet CLI for testing device communication",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"test": "jest"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@onekeyfe/hd-common-connect-sdk": "1.2.0-alpha.
|
|
35
|
-
"@onekeyfe/hd-core": "1.2.0-alpha.
|
|
36
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
37
|
-
"@onekeyfe/hd-transport-usb": "1.2.0-alpha.
|
|
34
|
+
"@onekeyfe/hd-common-connect-sdk": "1.2.0-alpha.97",
|
|
35
|
+
"@onekeyfe/hd-core": "1.2.0-alpha.97",
|
|
36
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.97",
|
|
37
|
+
"@onekeyfe/hd-transport-usb": "1.2.0-alpha.97",
|
|
38
38
|
"@stoprocent/noble": "2.3.16",
|
|
39
39
|
"commander": "^12.0.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "d68cfec311df84b21124066ce3fe608596e4af0d"
|
|
42
42
|
}
|
|
@@ -36,7 +36,6 @@ describe('firmware-update-v4 CLI command', () => {
|
|
|
36
36
|
expect(command?.description()).toBe(
|
|
37
37
|
'Run Protocol V2 firmware update through sdk.firmwareUpdateV4'
|
|
38
38
|
);
|
|
39
|
-
expect(command?.options.some(option => option.long === '--resource-archive')).toBe(true);
|
|
40
39
|
});
|
|
41
40
|
|
|
42
41
|
test('does not expose the pre-release firmware-update-v4-debug command', () => {
|
package/src/cli.ts
CHANGED
|
@@ -628,6 +628,10 @@ program
|
|
|
628
628
|
.command('firmware-update-v4')
|
|
629
629
|
.description('Run Protocol V2 firmware update through sdk.firmwareUpdateV4')
|
|
630
630
|
.option('--chunk-size <bytes>', 'Transfer chunk size in bytes')
|
|
631
|
+
.option(
|
|
632
|
+
'--resource-file <spec...>',
|
|
633
|
+
'Resource direct-write spec: <localPath>:<devicePath>, e.g. wallpaper.okpkg:vol0:/bundles/images/wallpaper.okpkg'
|
|
634
|
+
)
|
|
631
635
|
.option('--romloader <path>', 'FW_MGMT_TARGET_ROMLOADER binary path')
|
|
632
636
|
.option('--bootloader <path>', 'FW_MGMT_TARGET_BOOTLOADER binary path')
|
|
633
637
|
.option('--application-p1 <path>', 'FW_MGMT_TARGET_APPLICATION_P1 binary path')
|
|
@@ -637,7 +641,6 @@ program
|
|
|
637
641
|
.option('--se02 <path>', 'FW_MGMT_TARGET_SE02 binary path')
|
|
638
642
|
.option('--se03 <path>', 'FW_MGMT_TARGET_SE03 binary path')
|
|
639
643
|
.option('--se04 <path>', 'FW_MGMT_TARGET_SE04 binary path')
|
|
640
|
-
.option('--resource-archive <path>', 'Complete signed Protocol V2 resource ZIP path')
|
|
641
644
|
.option('--forced-update-res', 'Force resource update')
|
|
642
645
|
.option('--retries <count>', 'Retry count for transient Protocol V2 USB probe failures')
|
|
643
646
|
.action(opts =>
|
|
@@ -1250,8 +1253,27 @@ async function resolveLegacyFirmwareConnectId(
|
|
|
1250
1253
|
return connectId;
|
|
1251
1254
|
}
|
|
1252
1255
|
|
|
1256
|
+
function parseResourceFileParam(spec: string): { binary: ArrayBuffer; devicePath: string } {
|
|
1257
|
+
const sep = spec.indexOf(':');
|
|
1258
|
+
if (sep <= 0 || sep === spec.length - 1) {
|
|
1259
|
+
throw new Error(`Invalid --resource-file value: "${spec}". Expected <localPath>:<devicePath>`);
|
|
1260
|
+
}
|
|
1261
|
+
const localPath = spec.slice(0, sep);
|
|
1262
|
+
const devicePath = spec.slice(sep + 1);
|
|
1263
|
+
if (!devicePath.startsWith('vol')) {
|
|
1264
|
+
throw new Error(
|
|
1265
|
+
`Invalid --resource-file device path: "${devicePath}". Expected a vol*:/... path`
|
|
1266
|
+
);
|
|
1267
|
+
}
|
|
1268
|
+
return {
|
|
1269
|
+
binary: readBinaryParam(localPath),
|
|
1270
|
+
devicePath,
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1253
1274
|
function getFirmwareUpdateV4TotalBytes(params: ReturnType<typeof buildFirmwareUpdateV4Params>) {
|
|
1254
1275
|
return [
|
|
1276
|
+
...(params.resourceFiles?.map(item => item.binary) ?? []),
|
|
1255
1277
|
params.bootloaderBinary,
|
|
1256
1278
|
params.applicationP1Binary,
|
|
1257
1279
|
params.applicationP2Binary,
|
|
@@ -1576,6 +1598,7 @@ export async function runFirmwareUpdateV4WithRetry({
|
|
|
1576
1598
|
|
|
1577
1599
|
function buildFirmwareUpdateV4Params(opts: {
|
|
1578
1600
|
chunkSize?: string;
|
|
1601
|
+
resourceFile?: string[];
|
|
1579
1602
|
romloader?: string;
|
|
1580
1603
|
bootloader?: string;
|
|
1581
1604
|
applicationP1?: string;
|
|
@@ -1585,7 +1608,6 @@ function buildFirmwareUpdateV4Params(opts: {
|
|
|
1585
1608
|
se02?: string;
|
|
1586
1609
|
se03?: string;
|
|
1587
1610
|
se04?: string;
|
|
1588
|
-
resourceArchive?: string;
|
|
1589
1611
|
forcedUpdateRes?: boolean;
|
|
1590
1612
|
}) {
|
|
1591
1613
|
const params = {
|
|
@@ -1593,6 +1615,7 @@ function buildFirmwareUpdateV4Params(opts: {
|
|
|
1593
1615
|
connectProtocol: 'V2' as const,
|
|
1594
1616
|
chunkSize: opts.chunkSize ? safeParseInt(opts.chunkSize, '--chunk-size') : undefined,
|
|
1595
1617
|
forcedUpdateRes: opts.forcedUpdateRes,
|
|
1618
|
+
resourceFiles: opts.resourceFile?.map(parseResourceFileParam),
|
|
1596
1619
|
romloaderBinary: opts.romloader ? readBinaryParam(opts.romloader) : undefined,
|
|
1597
1620
|
bootloaderBinary: opts.bootloader ? readBinaryParam(opts.bootloader) : undefined,
|
|
1598
1621
|
applicationP1Binary: opts.applicationP1 ? readBinaryParam(opts.applicationP1) : undefined,
|
|
@@ -1602,10 +1625,10 @@ function buildFirmwareUpdateV4Params(opts: {
|
|
|
1602
1625
|
se02Binary: opts.se02 ? readBinaryParam(opts.se02) : undefined,
|
|
1603
1626
|
se03Binary: opts.se03 ? readBinaryParam(opts.se03) : undefined,
|
|
1604
1627
|
se04Binary: opts.se04 ? readBinaryParam(opts.se04) : undefined,
|
|
1605
|
-
resourceArchiveBinary: opts.resourceArchive ? readBinaryParam(opts.resourceArchive) : undefined,
|
|
1606
1628
|
};
|
|
1607
1629
|
|
|
1608
1630
|
const hasPayload = [
|
|
1631
|
+
params.resourceFiles,
|
|
1609
1632
|
params.romloaderBinary,
|
|
1610
1633
|
params.bootloaderBinary,
|
|
1611
1634
|
params.applicationP1Binary,
|
|
@@ -1615,13 +1638,10 @@ function buildFirmwareUpdateV4Params(opts: {
|
|
|
1615
1638
|
params.se02Binary,
|
|
1616
1639
|
params.se03Binary,
|
|
1617
1640
|
params.se04Binary,
|
|
1618
|
-
params.resourceArchiveBinary,
|
|
1619
1641
|
].some(Boolean);
|
|
1620
1642
|
|
|
1621
1643
|
if (!hasPayload) {
|
|
1622
|
-
const err = new Error(
|
|
1623
|
-
'firmware-update-v4 requires at least one firmware binary or resource archive path'
|
|
1624
|
-
);
|
|
1644
|
+
const err = new Error('firmware-update-v4 requires at least one binary path');
|
|
1625
1645
|
(err as Error & { code?: string }).code = 'MISSING_FIRMWARE_BINARY';
|
|
1626
1646
|
throw err;
|
|
1627
1647
|
}
|