@onekeyfe/hd-core 1.2.0-alpha.4 → 1.2.0-alpha.5
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/__tests__/protocol-v2.test.ts +69 -3
- package/dist/api/FirmwareUpdateV4.d.ts +2 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/progressThrottle.d.ts +3 -0
- package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +3 -2
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts +4 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +138 -69
- package/dist/protocols/protocol-v2/firmware.d.ts +1 -0
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -3
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +108 -70
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +7 -0
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +37 -3
- package/src/api/protocol-v2/helpers.ts +5 -0
- package/src/data/messages/messages-protocol-v2.json +2 -0
- package/src/protocols/protocol-v2/firmware.ts +1 -0
- package/src/types/api/firmwareUpdate.ts +1 -1
- package/src/types/api/protocolV2.ts +3 -1
|
@@ -10,6 +10,7 @@ import FileWrite from '../src/api/FileWrite';
|
|
|
10
10
|
import DeviceFactoryInfoGet from '../src/api/protocol-v2/DeviceFactoryInfoGet';
|
|
11
11
|
import DeviceFactoryInfoSet from '../src/api/protocol-v2/DeviceFactoryInfoSet';
|
|
12
12
|
import DeviceFirmwareUpdate from '../src/api/protocol-v2/DeviceFirmwareUpdate';
|
|
13
|
+
import DeviceGetFirmwareUpdateStatus from '../src/api/protocol-v2/DeviceGetFirmwareUpdateStatus';
|
|
13
14
|
import DeviceInfoGet from '../src/api/protocol-v2/DeviceInfoGet';
|
|
14
15
|
import DeviceReboot from '../src/api/protocol-v2/DeviceReboot';
|
|
15
16
|
import FilesystemPermissionFix from '../src/api/protocol-v2/FilesystemPermissionFix';
|
|
@@ -2590,6 +2591,7 @@ describe('Protocol V2 firmware update targets', () => {
|
|
|
2590
2591
|
resourceBinaryMap: [],
|
|
2591
2592
|
bootloaderBinary: null,
|
|
2592
2593
|
fwBinaryMap: [],
|
|
2594
|
+
installItems: [],
|
|
2593
2595
|
});
|
|
2594
2596
|
expect(getSysResourceBinarySpy).not.toHaveBeenCalled();
|
|
2595
2597
|
expect(typedCall.mock.calls[0][2]).toEqual({
|
|
@@ -2721,6 +2723,14 @@ describe('Protocol V2 firmware update targets', () => {
|
|
|
2721
2723
|
],
|
|
2722
2724
|
bootloaderBinary: null,
|
|
2723
2725
|
fwBinaryMap: [],
|
|
2726
|
+
installItems: [
|
|
2727
|
+
{
|
|
2728
|
+
fileName: 'resource-resource.bin',
|
|
2729
|
+
binary: resourceBinary,
|
|
2730
|
+
targetId: 1,
|
|
2731
|
+
kind: 'resource',
|
|
2732
|
+
},
|
|
2733
|
+
],
|
|
2724
2734
|
});
|
|
2725
2735
|
|
|
2726
2736
|
getSysResourceBinarySpy.mockRestore();
|
|
@@ -2844,14 +2854,23 @@ describe('Protocol V2 firmware update targets', () => {
|
|
|
2844
2854
|
},
|
|
2845
2855
|
});
|
|
2846
2856
|
|
|
2857
|
+
const operations: string[] = [];
|
|
2847
2858
|
method.postTipMessage = jest.fn();
|
|
2848
2859
|
method.postProgressMessage = jest.fn();
|
|
2849
2860
|
(method as any).protocolV2CommonUpdateProcess = jest
|
|
2850
2861
|
.fn()
|
|
2851
|
-
.mockImplementation(params =>
|
|
2852
|
-
|
|
2862
|
+
.mockImplementation(params => {
|
|
2863
|
+
operations.push(`write:${params.filePath}`);
|
|
2864
|
+
return Promise.resolve(
|
|
2865
|
+
Number(params.processedSize ?? 0) + Number(params.payload.byteLength)
|
|
2866
|
+
);
|
|
2867
|
+
});
|
|
2868
|
+
(method as any).protocolV2StartFirmwareUpdate = jest.fn().mockImplementation(({ targets }) => {
|
|
2869
|
+
operations.push(
|
|
2870
|
+
`install:${targets.map((target: { path: string }) => target.path).join(',')}`
|
|
2853
2871
|
);
|
|
2854
|
-
|
|
2872
|
+
return Promise.resolve(undefined);
|
|
2873
|
+
});
|
|
2855
2874
|
(method as any).waitForProtocolV2FirmwareUpdateComplete = jest
|
|
2856
2875
|
.fn()
|
|
2857
2876
|
.mockResolvedValue(undefined);
|
|
@@ -2888,6 +2907,14 @@ describe('Protocol V2 firmware update targets', () => {
|
|
|
2888
2907
|
expect((method as any).protocolV2StartFirmwareUpdate).toHaveBeenNthCalledWith(3, {
|
|
2889
2908
|
targets: [{ target_id: 4, path: 'vol1:application_p1.bin' }],
|
|
2890
2909
|
});
|
|
2910
|
+
expect(operations).toEqual([
|
|
2911
|
+
'write:vol1:resource-images.bin',
|
|
2912
|
+
'write:vol1:resource-fonts.bin',
|
|
2913
|
+
'write:vol1:application_p1.bin',
|
|
2914
|
+
'install:vol1:resource-images.bin',
|
|
2915
|
+
'install:vol1:resource-fonts.bin',
|
|
2916
|
+
'install:vol1:application_p1.bin',
|
|
2917
|
+
]);
|
|
2891
2918
|
});
|
|
2892
2919
|
|
|
2893
2920
|
test('skips Pro2 firmware components when configured versions are already installed', async () => {
|
|
@@ -2944,6 +2971,7 @@ describe('Protocol V2 firmware update targets', () => {
|
|
|
2944
2971
|
resourceBinaryMap: [],
|
|
2945
2972
|
bootloaderBinary: null,
|
|
2946
2973
|
fwBinaryMap: [],
|
|
2974
|
+
installItems: [],
|
|
2947
2975
|
});
|
|
2948
2976
|
expect(getSysResourceBinarySpy).not.toHaveBeenCalled();
|
|
2949
2977
|
|
|
@@ -3361,6 +3389,44 @@ describe('Protocol V2 firmware update method', () => {
|
|
|
3361
3389
|
targets: [{ target_id: 1, path: 'vol0:resource.bin' }],
|
|
3362
3390
|
});
|
|
3363
3391
|
});
|
|
3392
|
+
|
|
3393
|
+
test('passes firmware update status fields through to Protocol V2', async () => {
|
|
3394
|
+
const typedCall = jest.fn().mockResolvedValue({
|
|
3395
|
+
message: {
|
|
3396
|
+
records: [{ target_id: 4, status: 2, payload_version: 1, path: 'vol1:application_p1.bin' }],
|
|
3397
|
+
},
|
|
3398
|
+
});
|
|
3399
|
+
const method = new DeviceGetFirmwareUpdateStatus({
|
|
3400
|
+
id: 1,
|
|
3401
|
+
payload: {
|
|
3402
|
+
method: 'deviceGetFirmwareUpdateStatus',
|
|
3403
|
+
fields: {
|
|
3404
|
+
status: true,
|
|
3405
|
+
payload_version: true,
|
|
3406
|
+
path: true,
|
|
3407
|
+
},
|
|
3408
|
+
},
|
|
3409
|
+
});
|
|
3410
|
+
method.init();
|
|
3411
|
+
(method as any).device = stubDevice({
|
|
3412
|
+
commands: { typedCall },
|
|
3413
|
+
});
|
|
3414
|
+
|
|
3415
|
+
await expect(method.run()).resolves.toEqual({
|
|
3416
|
+
records: [{ target_id: 4, status: 2, payload_version: 1, path: 'vol1:application_p1.bin' }],
|
|
3417
|
+
});
|
|
3418
|
+
expect(typedCall).toHaveBeenCalledWith(
|
|
3419
|
+
'DeviceFirmwareUpdateStatusGet',
|
|
3420
|
+
'DeviceFirmwareUpdateStatus',
|
|
3421
|
+
{
|
|
3422
|
+
fields: {
|
|
3423
|
+
status: true,
|
|
3424
|
+
payload_version: true,
|
|
3425
|
+
path: true,
|
|
3426
|
+
},
|
|
3427
|
+
}
|
|
3428
|
+
);
|
|
3429
|
+
});
|
|
3364
3430
|
});
|
|
3365
3431
|
|
|
3366
3432
|
describe('Protocol V2 reboot methods', () => {
|
|
@@ -13,6 +13,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
13
13
|
private prepareResourceBinaries;
|
|
14
14
|
private prepareBootloaderBinary;
|
|
15
15
|
private hasExplicitProtocolV2Payload;
|
|
16
|
+
private buildProtocolV2InstallItems;
|
|
16
17
|
private getRemoteComponentEntries;
|
|
17
18
|
private getRemoteComponentTarget;
|
|
18
19
|
private getProtocolV2ComponentTargetVersion;
|
|
@@ -32,6 +33,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
32
33
|
private waitForProtocolV2BootloaderMode;
|
|
33
34
|
private collectExplicitTargetBinaries;
|
|
34
35
|
private executeProtocolV2Update;
|
|
36
|
+
private getProtocolV2InstallItemStagingPath;
|
|
35
37
|
private queryProtocolV2FirmwareUpdateStatus;
|
|
36
38
|
private pingProtocolV2Device;
|
|
37
39
|
private isProtocolV2NormalModeFeatures;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FirmwareUpdateV4.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV4.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAa/E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"FirmwareUpdateV4.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV4.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAa/E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAmV1E,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,wBAAwB,CAAC,sBAAsB,CAAC;IAC5F,IAAI;IAwDJ,OAAO,CAAC,8BAA8B;IAgBhC,GAAG;;;;;YAYK,aAAa;YAsDb,2BAA2B;YAW3B,uBAAuB;IAqCrC,OAAO,CAAC,uBAAuB;IAI/B,OAAO,CAAC,4BAA4B;IAQpC,OAAO,CAAC,2BAA2B;IA2BnC,OAAO,CAAC,yBAAyB;IAiBjC,OAAO,CAAC,wBAAwB;IAkBhC,OAAO,CAAC,mCAAmC;IAkB3C,OAAO,CAAC,oCAAoC;IAyB5C,OAAO,CAAC,qCAAqC;IAc7C,OAAO,CAAC,6BAA6B;YAMvB,8BAA8B;YA6C9B,kCAAkC;YA4BlC,qCAAqC;IAanD,OAAO,CAAC,6BAA6B;IAOrC,OAAO,CAAC,sCAAsC;YAKhC,sCAAsC;YAoCtC,iCAAiC;YAmBjC,+BAA+B;IAkE7C,OAAO,CAAC,0BAA0B;IAO5B,6BAA6B;YAsBrB,+BAA+B;IAsC7C,OAAO,CAAC,6BAA6B;YAkCvB,uBAAuB;IAkHrC,OAAO,CAAC,mCAAmC;YAI7B,mCAAmC;YAYnC,oBAAoB;IAYlC,OAAO,CAAC,8BAA8B;YAIxB,yBAAyB;IAcvC,OAAO,CAAC,4BAA4B;YAqCtB,uCAAuC;YA6DvC,gCAAgC;YAchC,8BAA8B;YAqB9B,qCAAqC;YAoCrC,yBAAyB;YA+CzB,6BAA6B;IA2D3C,OAAO,CAAC,sCAAsC;YAchC,kBAAkB;YA6DlB,0BAA0B;YAS1B,6BAA6B;YAsC7B,gBAAgB;IAe9B,OAAO,CAAC,qBAAqB;CAM9B"}
|
|
@@ -7,6 +7,7 @@ import type { Deferred } from '@onekeyfe/hd-shared';
|
|
|
7
7
|
import type { TypedResponseMessage } from '../../device/DeviceCommands';
|
|
8
8
|
export declare class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
9
9
|
checkPromise: Deferred<any> | null;
|
|
10
|
+
private shouldPostFirmwareProgress;
|
|
10
11
|
init(): void;
|
|
11
12
|
run(): Promise<any>;
|
|
12
13
|
isBleReconnect(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FirmwareUpdateBaseMethod.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/FirmwareUpdateBaseMethod.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"FirmwareUpdateBaseMethod.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/FirmwareUpdateBaseMethod.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,KAAK,EACV,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAexE,qBAAa,wBAAwB,CAAC,MAAM,CAAE,SAAQ,UAAU,CAAC,MAAM,CAAC;IACtE,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,OAAO,CAAC,0BAA0B,CAAoC;IAEtE,IAAI,IAAI,IAAI;IAEZ,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IAInB,cAAc,IAAI,OAAO;IASzB,cAAc,YAAa,yBAAyB,UASlD;IAMF,qBAAqB,SAAU,UAAU,GAAG,KAAK,GAAG,YAAY,GAAG,UAAU,UAM3E;IAMF,mBAAmB,aAAc,MAAM,gBAAgB,2BAA2B,UAYhF;cAEc,qCAAqC;cAkBrC,uCAAuC;IAkBvD,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;YA0FvC,4BAA4B;IAuBpC,mBAAmB;IA8CnB,uBAAuB,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;IA6BlD,8BAA8B,CAAC,IAAI,EAAE,MAAM;IAW3C,uBAAuB,CAAC,EAC5B,OAAO,EACP,QAAQ,EACR,aAAa,EACb,SAAS,GACV,EAAE,KAAK,CAAC,cAAc,GAAG;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;IA4CK,sBAAsB,CAC1B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,WAAW,GAAG,MAAM,EAC3B,SAAS,EAAE,OAAO,EAClB,QAAQ,EAAE,MAAM,GAAG,IAAI;IAwEnB,MAAM,CAAC,UAAU,EAAE,UAAU;CAsBpC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { IFirmwareUpdateProgressType } from '../../events/ui-request';
|
|
2
|
+
export declare const createFirmwareProgressThrottle: (intervalMs?: number) => (progress: number, progressType: IFirmwareUpdateProgressType) => boolean;
|
|
3
|
+
//# sourceMappingURL=progressThrottle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progressThrottle.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/progressThrottle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAS3E,eAAO,MAAM,8BAA8B,sCAKvB,MAAM,gBAAgB,2BAA2B,YA6BpE,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
|
|
2
|
+
import type { DeviceFirmwareUpdateStatusGetParams } from './helpers';
|
|
3
|
+
export default class DeviceGetFirmwareUpdateStatus extends BaseMethod<DeviceFirmwareUpdateStatusGetParams> {
|
|
3
4
|
init(): void;
|
|
4
|
-
run(): Promise<import("
|
|
5
|
+
run(): Promise<import("@onekeyfe/hd-transport").DeviceFirmwareUpdateStatus>;
|
|
5
6
|
}
|
|
6
7
|
//# sourceMappingURL=DeviceGetFirmwareUpdateStatus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceGetFirmwareUpdateStatus.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"DeviceGetFirmwareUpdateStatus.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,WAAW,CAAC;AAgCrE,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,UAAU,CAAC,mCAAmC,CAAC;IACxG,IAAI;IASE,GAAG;CAQV"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
2
|
-
import type { DeviceFirmwareTarget, DeviceFirmwareTargetType, TransportCallOptions } from '@onekeyfe/hd-transport';
|
|
2
|
+
import type { DeviceFirmwareTarget, DeviceFirmwareUpdateRecordFields, DeviceFirmwareTargetType, TransportCallOptions } from '@onekeyfe/hd-transport';
|
|
3
3
|
export type RebootTypeInput = DeviceRebootType | keyof typeof DeviceRebootType | string | number;
|
|
4
4
|
export type DeviceRebootParams = {
|
|
5
5
|
rebootType?: RebootTypeInput;
|
|
@@ -16,6 +16,9 @@ export type DeviceFirmwareUpdateParams = {
|
|
|
16
16
|
target_id?: DeviceFirmwareTargetType | string | number;
|
|
17
17
|
path?: string;
|
|
18
18
|
};
|
|
19
|
+
export type DeviceFirmwareUpdateStatusGetParams = {
|
|
20
|
+
fields?: DeviceFirmwareUpdateRecordFields;
|
|
21
|
+
};
|
|
19
22
|
export type DeviceFactoryInfoSetParams = {
|
|
20
23
|
version?: number;
|
|
21
24
|
serial_number?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAK1D,OAAO,KAAK,EACV,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,MAAM,OAAO,gBAAgB,GAAG,MAAM,GAAG,MAAM,CAAC;AAEjG,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC,oBAAoB,GACpB;IACE,QAAQ,CAAC,EAAE,wBAAwB,GAAG,MAAM,GAAG,MAAM,CAAC;IACtD,SAAS,CAAC,EAAE,wBAAwB,GAAG,MAAM,GAAG,MAAM,CAAC;IACvD,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEN,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,CAAC,EAAE,yBAAyB,EAAE,CAAC;IACtC,QAAQ,CAAC,EAAE,wBAAwB,GAAG,MAAM,GAAG,MAAM,CAAC;IACtD,SAAS,CAAC,EAAE,wBAAwB,GAAG,MAAM,GAAG,MAAM,CAAC;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,gBAAgB,CAAC,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAA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-
import { DeviceFirmwareTargetType, DeviceRebootType, DeviceFirmwareTarget, Messages, Transport, TransportCallOptions, OneKeyDeviceInfo, ProtocolV2DeviceInfo, Success as Success$1, LowlevelTransportSharedPlugin, ProtocolInfo, DeviceFirmwareUpdateStatus, DeviceFactoryInfo, OneKeyDeviceCommType, Features as Features$1, ProtocolType, RecoveryDeviceType, SafetyCheckLevel, ResourceType, NextU2FCounter, SetU2FCounter, CipheredKeyValue as CipheredKeyValue$1, UintType, EthereumPublicKey, EthereumMessageSignature, Address, MultisigRedeemScriptType, InputScriptType, PublicKey, MessageSignature, SignedPsbt, PrevInput, TxOutputBinType, TxInput, TxOutputType, TxInputType, StarcoinAddress as StarcoinAddress$1, StarcoinPublicKey as StarcoinPublicKey$1, StarcoinMessageSignature, StarcoinSignedTx, NEMAddress as NEMAddress$1, NEMSignedTx, SolanaAddress as SolanaAddress$1, SolanaSignedTx as SolanaSignedTx$1, SolanaTxExtraInfo, SolanaOffChainMessageVersion, SolanaOffChainMessageFormat, StellarAddress as StellarAddress$1, StellarSignedTx, TronAddress as TronAddress$1, TronResourceCode, TronSignedTx, TronMessageSignature, ConfluxAddress as ConfluxAddress$1, ConfluxMessageSignature, NearAddress as NearAddress$1, NearSignedTx, AptosAddress as AptosAddress$1, AptosMessageSignature as AptosMessageSignature$1, AptosSignedTx as AptosSignedTx$1, AlgorandAddress, AlgorandSignedTx, CosmosAddress as CosmosAddress$1, CosmosSignedTx as CosmosSignedTx$1, SuiAddress as SuiAddress$1, SuiMessageSignature, CardanoAddressParametersType, CardanoMessageSignature, FilecoinAddress as FilecoinAddress$1, FilecoinSignedTx as FilecoinSignedTx$1, PolkadotAddress as PolkadotAddress$1, PolkadotSignedTx as PolkadotSignedTx$1, KaspaAddress as KaspaAddress$1, NervosAddress as NervosAddress$1, NervosSignedTx as NervosSignedTx$1, DnxAddress as DnxAddress$1, TonWalletVersion, TonWorkChain, TonSignedMessage, TonSignedProof, TonSignDataType, TonSignedData, ScdoAddress as ScdoAddress$1, ScdoSignedMessage, ScdoSignedTx as ScdoSignedTx$1, AlephiumMessageSignature, AlephiumSignedTx as AlephiumSignedTx$1, BenfenAddress as BenfenAddress$1, BenfenMessageSignature, ChangeOutputScriptType } from '@onekeyfe/hd-transport';
|
|
2
|
+
import { DeviceFirmwareTargetType, DeviceFirmwareUpdateRecordFields, DeviceRebootType, DeviceFirmwareTarget, Messages, Transport, TransportCallOptions, OneKeyDeviceInfo, ProtocolV2DeviceInfo, Success as Success$1, LowlevelTransportSharedPlugin, ProtocolInfo, DeviceFirmwareUpdateStatus, DeviceFactoryInfo, OneKeyDeviceCommType, Features as Features$1, ProtocolType, RecoveryDeviceType, SafetyCheckLevel, ResourceType, NextU2FCounter, SetU2FCounter, CipheredKeyValue as CipheredKeyValue$1, UintType, EthereumPublicKey, EthereumMessageSignature, Address, MultisigRedeemScriptType, InputScriptType, PublicKey, MessageSignature, SignedPsbt, PrevInput, TxOutputBinType, TxInput, TxOutputType, TxInputType, StarcoinAddress as StarcoinAddress$1, StarcoinPublicKey as StarcoinPublicKey$1, StarcoinMessageSignature, StarcoinSignedTx, NEMAddress as NEMAddress$1, NEMSignedTx, SolanaAddress as SolanaAddress$1, SolanaSignedTx as SolanaSignedTx$1, SolanaTxExtraInfo, SolanaOffChainMessageVersion, SolanaOffChainMessageFormat, StellarAddress as StellarAddress$1, StellarSignedTx, TronAddress as TronAddress$1, TronResourceCode, TronSignedTx, TronMessageSignature, ConfluxAddress as ConfluxAddress$1, ConfluxMessageSignature, NearAddress as NearAddress$1, NearSignedTx, AptosAddress as AptosAddress$1, AptosMessageSignature as AptosMessageSignature$1, AptosSignedTx as AptosSignedTx$1, AlgorandAddress, AlgorandSignedTx, CosmosAddress as CosmosAddress$1, CosmosSignedTx as CosmosSignedTx$1, SuiAddress as SuiAddress$1, SuiMessageSignature, CardanoAddressParametersType, CardanoMessageSignature, FilecoinAddress as FilecoinAddress$1, FilecoinSignedTx as FilecoinSignedTx$1, PolkadotAddress as PolkadotAddress$1, PolkadotSignedTx as PolkadotSignedTx$1, KaspaAddress as KaspaAddress$1, NervosAddress as NervosAddress$1, NervosSignedTx as NervosSignedTx$1, DnxAddress as DnxAddress$1, TonWalletVersion, TonWorkChain, TonSignedMessage, TonSignedProof, TonSignDataType, TonSignedData, ScdoAddress as ScdoAddress$1, ScdoSignedMessage, ScdoSignedTx as ScdoSignedTx$1, AlephiumMessageSignature, AlephiumSignedTx as AlephiumSignedTx$1, BenfenAddress as BenfenAddress$1, BenfenMessageSignature, ChangeOutputScriptType } from '@onekeyfe/hd-transport';
|
|
3
3
|
export { Success as DeviceSuccess, HDNodeType, Messages as PROTO, ResourceType, TonSignDataType, TonWalletVersion } from '@onekeyfe/hd-transport';
|
|
4
4
|
import * as _onekeyfe_hd_shared from '@onekeyfe/hd-shared';
|
|
5
5
|
import { HardwareConnectProtocol, Deferred, EFirmwareType, EDeviceType } from '@onekeyfe/hd-shared';
|
|
@@ -55,6 +55,9 @@ type DeviceFirmwareUpdateParams = {
|
|
|
55
55
|
target_id?: DeviceFirmwareTargetType | string | number;
|
|
56
56
|
path?: string;
|
|
57
57
|
};
|
|
58
|
+
type DeviceFirmwareUpdateStatusGetParams = {
|
|
59
|
+
fields?: DeviceFirmwareUpdateRecordFields;
|
|
60
|
+
};
|
|
58
61
|
type DeviceFactoryInfoSetParams = {
|
|
59
62
|
version?: number;
|
|
60
63
|
serial_number?: string;
|
|
@@ -425,7 +428,7 @@ declare function ping(connectId: string, params?: CommonParams & {
|
|
|
425
428
|
declare function deviceReboot(connectId: string, params: CommonParams & DeviceRebootParams): Response<Success$1>;
|
|
426
429
|
declare function deviceInfoGet(connectId: string, params?: CommonParams & DeviceInfoGetParams): Response<ProtocolV2DeviceInfo>;
|
|
427
430
|
declare function deviceFirmwareUpdate(connectId: string, params: CommonParams & DeviceFirmwareUpdateParams): Response<Success$1 | DeviceFirmwareUpdateStatus>;
|
|
428
|
-
declare function deviceGetFirmwareUpdateStatus(connectId: string, params?: CommonParams): Response<DeviceFirmwareUpdateStatus>;
|
|
431
|
+
declare function deviceGetFirmwareUpdateStatus(connectId: string, params?: CommonParams & DeviceFirmwareUpdateStatusGetParams): Response<DeviceFirmwareUpdateStatus>;
|
|
429
432
|
declare function deviceFactoryInfoSet(connectId: string, params: CommonParams & DeviceFactoryInfoSetParams): Response<Success$1>;
|
|
430
433
|
declare function deviceFactoryInfoGet(connectId: string, params?: CommonParams): Response<DeviceFactoryInfo>;
|
|
431
434
|
declare function filesystemPermissionFix(connectId: string, params?: CommonParams): Response<Success$1>;
|
package/dist/index.js
CHANGED
|
@@ -25394,6 +25394,8 @@ var nested = {
|
|
|
25394
25394
|
MessageType_FirmwareHash: 89,
|
|
25395
25395
|
MessageType_UnlockPath: 93,
|
|
25396
25396
|
MessageType_UnlockedPathRequest: 94,
|
|
25397
|
+
MessageType_UnLockDevice: 10030,
|
|
25398
|
+
MessageType_UnLockDeviceResponse: 10031,
|
|
25397
25399
|
MessageType_SetU2FCounter: 63,
|
|
25398
25400
|
MessageType_GetNextU2FCounter: 80,
|
|
25399
25401
|
MessageType_NextU2FCounter: 81,
|
|
@@ -42297,6 +42299,7 @@ class GetFeatures extends BaseMethod {
|
|
|
42297
42299
|
}
|
|
42298
42300
|
|
|
42299
42301
|
const ProtocolV2FirmwareTargetType = {
|
|
42302
|
+
FW_MGMT_TARGET_INVALID: 0,
|
|
42300
42303
|
FW_MGMT_TARGET_CRATE: 1,
|
|
42301
42304
|
FW_MGMT_TARGET_ROMLOADER: 2,
|
|
42302
42305
|
FW_MGMT_TARGET_BOOTLOADER: 3,
|
|
@@ -43953,6 +43956,35 @@ class DeviceFullyUploadResource extends BaseMethod {
|
|
|
43953
43956
|
}
|
|
43954
43957
|
}
|
|
43955
43958
|
|
|
43959
|
+
const DEFAULT_FIRMWARE_PROGRESS_INTERVAL_MS = 250;
|
|
43960
|
+
const createFirmwareProgressThrottle = (intervalMs = DEFAULT_FIRMWARE_PROGRESS_INTERVAL_MS) => {
|
|
43961
|
+
const stateByType = new Map();
|
|
43962
|
+
return (progress, progressType) => {
|
|
43963
|
+
if (progressType !== 'transferData') {
|
|
43964
|
+
return true;
|
|
43965
|
+
}
|
|
43966
|
+
const normalizedProgress = Math.max(0, Math.min(100, Math.floor(progress)));
|
|
43967
|
+
if (normalizedProgress === 0 || normalizedProgress === 100) {
|
|
43968
|
+
stateByType.set(progressType, {
|
|
43969
|
+
lastEmittedAt: Date.now(),
|
|
43970
|
+
lastProgress: normalizedProgress,
|
|
43971
|
+
});
|
|
43972
|
+
return true;
|
|
43973
|
+
}
|
|
43974
|
+
const now = Date.now();
|
|
43975
|
+
const state = stateByType.get(progressType);
|
|
43976
|
+
if (state &&
|
|
43977
|
+
(state.lastProgress === normalizedProgress || now - state.lastEmittedAt < intervalMs)) {
|
|
43978
|
+
return false;
|
|
43979
|
+
}
|
|
43980
|
+
stateByType.set(progressType, {
|
|
43981
|
+
lastEmittedAt: now,
|
|
43982
|
+
lastProgress: normalizedProgress,
|
|
43983
|
+
});
|
|
43984
|
+
return true;
|
|
43985
|
+
};
|
|
43986
|
+
};
|
|
43987
|
+
|
|
43956
43988
|
const Log$8 = getLogger(exports.LoggerNames.Method);
|
|
43957
43989
|
const SESSION_ERROR$1 = 'session not found';
|
|
43958
43990
|
const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
|
|
@@ -43966,6 +43998,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
43966
43998
|
constructor() {
|
|
43967
43999
|
super(...arguments);
|
|
43968
44000
|
this.checkPromise = null;
|
|
44001
|
+
this.shouldPostFirmwareProgress = createFirmwareProgressThrottle();
|
|
43969
44002
|
this.postTipMessage = (message) => {
|
|
43970
44003
|
this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_TIP, {
|
|
43971
44004
|
device: this.device.toMessageObject(),
|
|
@@ -43980,6 +44013,9 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
43980
44013
|
}));
|
|
43981
44014
|
};
|
|
43982
44015
|
this.postProgressMessage = (progress, progressType) => {
|
|
44016
|
+
if (!this.shouldPostFirmwareProgress(progress, progressType)) {
|
|
44017
|
+
return;
|
|
44018
|
+
}
|
|
43983
44019
|
this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
43984
44020
|
device: this.device.toMessageObject(),
|
|
43985
44021
|
progress,
|
|
@@ -45763,6 +45799,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
45763
45799
|
let resourceBinaryMap = [];
|
|
45764
45800
|
let fwBinaryMap = [];
|
|
45765
45801
|
let bootloaderBinary = null;
|
|
45802
|
+
let installItems;
|
|
45766
45803
|
try {
|
|
45767
45804
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
45768
45805
|
resourceBinaryMap = yield this.prepareResourceBinaries(firmwareType, deviceFeatures);
|
|
@@ -45773,6 +45810,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
45773
45810
|
resourceBinaryMap = remoteBinaries.resourceBinaryMap;
|
|
45774
45811
|
bootloaderBinary = remoteBinaries.bootloaderBinary;
|
|
45775
45812
|
fwBinaryMap = remoteBinaries.fwBinaryMap;
|
|
45813
|
+
installItems = remoteBinaries.installItems;
|
|
45776
45814
|
}
|
|
45777
45815
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
45778
45816
|
}
|
|
@@ -45783,11 +45821,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
45783
45821
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, 'No firmware to update');
|
|
45784
45822
|
}
|
|
45785
45823
|
yield this.enterProtocolV2BootloaderMode();
|
|
45786
|
-
yield this.executeProtocolV2Update({
|
|
45787
|
-
resourceBinaryMap,
|
|
45824
|
+
yield this.executeProtocolV2Update(Object.assign({ resourceBinaryMap,
|
|
45788
45825
|
fwBinaryMap,
|
|
45789
|
-
bootloaderBinary,
|
|
45790
|
-
});
|
|
45826
|
+
bootloaderBinary }, (installItems ? { installItems } : undefined)));
|
|
45791
45827
|
yield this.exitProtocolV2BootloaderToNormal();
|
|
45792
45828
|
const versions = yield this.waitForProtocolV2FinalFeatures();
|
|
45793
45829
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.FirmwareUpdateCompleted);
|
|
@@ -45852,6 +45888,19 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
45852
45888
|
!!this.params.bootloaderBinary ||
|
|
45853
45889
|
fwBinaryMap.length > 0);
|
|
45854
45890
|
}
|
|
45891
|
+
buildProtocolV2InstallItems({ resourceBinaryMap, bootloaderBinary, fwBinaryMap, }) {
|
|
45892
|
+
const installItems = resourceBinaryMap.map(resource => (Object.assign(Object.assign({}, resource), { kind: 'resource' })));
|
|
45893
|
+
if (bootloaderBinary) {
|
|
45894
|
+
installItems.push({
|
|
45895
|
+
fileName: 'bootloader.bin',
|
|
45896
|
+
binary: bootloaderBinary,
|
|
45897
|
+
targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER,
|
|
45898
|
+
kind: 'bootloader',
|
|
45899
|
+
});
|
|
45900
|
+
}
|
|
45901
|
+
installItems.push(...fwBinaryMap.map(item => (Object.assign(Object.assign({}, item), { kind: 'firmware' }))));
|
|
45902
|
+
return installItems;
|
|
45903
|
+
}
|
|
45855
45904
|
getRemoteComponentEntries(release) {
|
|
45856
45905
|
var _a;
|
|
45857
45906
|
const { components } = release;
|
|
@@ -46058,11 +46107,13 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
46058
46107
|
const resourceBinaryMap = [];
|
|
46059
46108
|
let bootloaderBinary = null;
|
|
46060
46109
|
const fwBinaryMap = [];
|
|
46110
|
+
const installItems = [];
|
|
46061
46111
|
if (!release) {
|
|
46062
46112
|
return {
|
|
46063
46113
|
resourceBinaryMap,
|
|
46064
46114
|
bootloaderBinary,
|
|
46065
46115
|
fwBinaryMap,
|
|
46116
|
+
installItems,
|
|
46066
46117
|
};
|
|
46067
46118
|
}
|
|
46068
46119
|
const entries = this.getRemoteComponentEntries(release);
|
|
@@ -46072,21 +46123,31 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
46072
46123
|
if (shouldInstall) {
|
|
46073
46124
|
const remoteBinary = yield this.downloadRemoteProtocolV2Component(key, component);
|
|
46074
46125
|
if (remoteBinary.kind === 'resource') {
|
|
46075
|
-
|
|
46126
|
+
const binaryEntry = {
|
|
46076
46127
|
fileName: this.getProtocolV2ResourceComponentFileName(key),
|
|
46077
46128
|
binary: remoteBinary.binary,
|
|
46078
46129
|
targetId: remoteBinary.targetId,
|
|
46079
|
-
}
|
|
46130
|
+
};
|
|
46131
|
+
resourceBinaryMap.push(binaryEntry);
|
|
46132
|
+
installItems.push(Object.assign(Object.assign({}, binaryEntry), { kind: remoteBinary.kind }));
|
|
46080
46133
|
}
|
|
46081
46134
|
else if (remoteBinary.kind === 'bootloader') {
|
|
46082
46135
|
bootloaderBinary = remoteBinary.binary;
|
|
46136
|
+
installItems.push({
|
|
46137
|
+
fileName: remoteBinary.fileName,
|
|
46138
|
+
binary: remoteBinary.binary,
|
|
46139
|
+
targetId: remoteBinary.targetId,
|
|
46140
|
+
kind: remoteBinary.kind,
|
|
46141
|
+
});
|
|
46083
46142
|
}
|
|
46084
46143
|
else {
|
|
46085
|
-
|
|
46144
|
+
const binaryEntry = {
|
|
46086
46145
|
fileName: remoteBinary.fileName,
|
|
46087
46146
|
binary: remoteBinary.binary,
|
|
46088
46147
|
targetId: remoteBinary.targetId,
|
|
46089
|
-
}
|
|
46148
|
+
};
|
|
46149
|
+
fwBinaryMap.push(binaryEntry);
|
|
46150
|
+
installItems.push(Object.assign(Object.assign({}, binaryEntry), { kind: remoteBinary.kind }));
|
|
46090
46151
|
}
|
|
46091
46152
|
}
|
|
46092
46153
|
}
|
|
@@ -46094,6 +46155,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
46094
46155
|
resourceBinaryMap,
|
|
46095
46156
|
bootloaderBinary,
|
|
46096
46157
|
fwBinaryMap,
|
|
46158
|
+
installItems,
|
|
46097
46159
|
};
|
|
46098
46160
|
});
|
|
46099
46161
|
}
|
|
@@ -46171,17 +46233,18 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
46171
46233
|
push(this.params.se04Binary, 'se04.bin', ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE04);
|
|
46172
46234
|
return entries;
|
|
46173
46235
|
}
|
|
46174
|
-
executeProtocolV2Update({ resourceBinaryMap, fwBinaryMap, bootloaderBinary, }) {
|
|
46236
|
+
executeProtocolV2Update({ resourceBinaryMap, fwBinaryMap, bootloaderBinary, installItems, }) {
|
|
46175
46237
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46238
|
+
const orderedInstallItems = installItems !== null && installItems !== void 0 ? installItems : this.buildProtocolV2InstallItems({
|
|
46239
|
+
resourceBinaryMap: resourceBinaryMap !== null && resourceBinaryMap !== void 0 ? resourceBinaryMap : [],
|
|
46240
|
+
bootloaderBinary: bootloaderBinary !== null && bootloaderBinary !== void 0 ? bootloaderBinary : null,
|
|
46241
|
+
fwBinaryMap: fwBinaryMap !== null && fwBinaryMap !== void 0 ? fwBinaryMap : [],
|
|
46242
|
+
});
|
|
46176
46243
|
let totalSize = 0;
|
|
46177
46244
|
let processedSize = 0;
|
|
46178
46245
|
let transferredSize = 0;
|
|
46179
|
-
for (const
|
|
46180
|
-
totalSize +=
|
|
46181
|
-
for (const fwbinary of fwBinaryMap)
|
|
46182
|
-
totalSize += fwbinary.binary.byteLength;
|
|
46183
|
-
if (bootloaderBinary)
|
|
46184
|
-
totalSize += bootloaderBinary.byteLength;
|
|
46246
|
+
for (const item of orderedInstallItems)
|
|
46247
|
+
totalSize += item.binary.byteLength;
|
|
46185
46248
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartTransferData);
|
|
46186
46249
|
const transferStartTime = Date.now();
|
|
46187
46250
|
const transferTransport = this.getProtocolV2FirmwareTransferTransport();
|
|
@@ -46190,56 +46253,20 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
46190
46253
|
transferredSize = bytes;
|
|
46191
46254
|
};
|
|
46192
46255
|
Log$4.log(`[FirmwareUpdateV4] transfer started transport=${transferTransport} total=${totalSize} bytes chunk=${chunkSize} bytes`);
|
|
46193
|
-
const
|
|
46194
|
-
const targets = [];
|
|
46256
|
+
const stagedInstallTargets = [];
|
|
46195
46257
|
try {
|
|
46196
|
-
for (const
|
|
46197
|
-
const
|
|
46198
|
-
Log$4.log(`[FirmwareUpdateV4] staging
|
|
46199
|
-
processedSize = yield this.protocolV2CommonUpdateProcess({
|
|
46200
|
-
payload: resource.binary,
|
|
46201
|
-
filePath: resourceFilePath,
|
|
46202
|
-
processedSize,
|
|
46203
|
-
totalSize,
|
|
46204
|
-
onTransferredBytes,
|
|
46205
|
-
});
|
|
46206
|
-
transferredSize = processedSize;
|
|
46207
|
-
resourceTargets.push({
|
|
46208
|
-
target_id: resource.targetId,
|
|
46209
|
-
path: resourceFilePath,
|
|
46210
|
-
});
|
|
46211
|
-
}
|
|
46212
|
-
if (bootloaderBinary) {
|
|
46213
|
-
const bootloaderPath = `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}bootloader.bin`;
|
|
46214
|
-
Log$4.log(`[FirmwareUpdateV4] staging bootloader via FilesystemFileWrite target=${ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER} path=${bootloaderPath} bytes=${bootloaderBinary.byteLength}`);
|
|
46258
|
+
for (const item of orderedInstallItems) {
|
|
46259
|
+
const filePath = this.getProtocolV2InstallItemStagingPath(item);
|
|
46260
|
+
Log$4.log(`[FirmwareUpdateV4] staging ${item.kind} via FilesystemFileWrite target=${item.targetId} path=${filePath} source=${item.fileName} bytes=${item.binary.byteLength}`);
|
|
46215
46261
|
processedSize = yield this.protocolV2CommonUpdateProcess({
|
|
46216
|
-
payload:
|
|
46217
|
-
filePath
|
|
46262
|
+
payload: item.binary,
|
|
46263
|
+
filePath,
|
|
46218
46264
|
processedSize,
|
|
46219
46265
|
totalSize,
|
|
46220
46266
|
onTransferredBytes,
|
|
46221
46267
|
});
|
|
46222
46268
|
transferredSize = processedSize;
|
|
46223
|
-
|
|
46224
|
-
target_id: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER,
|
|
46225
|
-
path: bootloaderPath,
|
|
46226
|
-
});
|
|
46227
|
-
}
|
|
46228
|
-
for (const fwbinary of fwBinaryMap) {
|
|
46229
|
-
const firmwarePath = `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}${fwbinary.fileName}`;
|
|
46230
|
-
Log$4.log(`[FirmwareUpdateV4] staging firmware via FilesystemFileWrite target=${fwbinary.targetId} path=${firmwarePath} bytes=${fwbinary.binary.byteLength}`);
|
|
46231
|
-
processedSize = yield this.protocolV2CommonUpdateProcess({
|
|
46232
|
-
payload: fwbinary.binary,
|
|
46233
|
-
filePath: firmwarePath,
|
|
46234
|
-
processedSize,
|
|
46235
|
-
totalSize,
|
|
46236
|
-
onTransferredBytes,
|
|
46237
|
-
});
|
|
46238
|
-
transferredSize = processedSize;
|
|
46239
|
-
targets.push({
|
|
46240
|
-
target_id: fwbinary.targetId,
|
|
46241
|
-
path: firmwarePath,
|
|
46242
|
-
});
|
|
46269
|
+
stagedInstallTargets.push(Object.assign(Object.assign({}, item), { path: filePath }));
|
|
46243
46270
|
}
|
|
46244
46271
|
if (totalSize > 0) {
|
|
46245
46272
|
this.postProgressMessage(100, 'transferData');
|
|
@@ -46253,21 +46280,39 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
46253
46280
|
throw error;
|
|
46254
46281
|
}
|
|
46255
46282
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.ConfirmOnDevice);
|
|
46256
|
-
|
|
46257
|
-
|
|
46258
|
-
|
|
46259
|
-
|
|
46260
|
-
|
|
46261
|
-
});
|
|
46262
|
-
yield this.waitForProtocolV2FirmwareUpdateComplete(resourceTargetsBatch, startResponse);
|
|
46263
|
-
}
|
|
46264
|
-
if (targets.length > 0) {
|
|
46283
|
+
const firmwareTargets = [];
|
|
46284
|
+
const flushFirmwareTargets = () => __awaiter(this, void 0, void 0, function* () {
|
|
46285
|
+
if (firmwareTargets.length === 0)
|
|
46286
|
+
return;
|
|
46287
|
+
const targets = firmwareTargets.splice(0, firmwareTargets.length);
|
|
46265
46288
|
Log$4.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateRequest targets=${JSON.stringify(targets)}`);
|
|
46266
46289
|
const startResponse = yield this.protocolV2StartFirmwareUpdate({ targets });
|
|
46267
46290
|
yield this.waitForProtocolV2FirmwareUpdateComplete(targets, startResponse);
|
|
46291
|
+
});
|
|
46292
|
+
for (const item of stagedInstallTargets) {
|
|
46293
|
+
const target = {
|
|
46294
|
+
target_id: item.targetId,
|
|
46295
|
+
path: item.path,
|
|
46296
|
+
};
|
|
46297
|
+
if (item.kind === 'resource') {
|
|
46298
|
+
yield flushFirmwareTargets();
|
|
46299
|
+
const resourceTargets = [target];
|
|
46300
|
+
Log$4.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateRequest resources=${JSON.stringify(resourceTargets)}`);
|
|
46301
|
+
const startResponse = yield this.protocolV2StartFirmwareUpdate({
|
|
46302
|
+
targets: resourceTargets,
|
|
46303
|
+
});
|
|
46304
|
+
yield this.waitForProtocolV2FirmwareUpdateComplete(resourceTargets, startResponse);
|
|
46305
|
+
}
|
|
46306
|
+
else {
|
|
46307
|
+
firmwareTargets.push(target);
|
|
46308
|
+
}
|
|
46268
46309
|
}
|
|
46310
|
+
yield flushFirmwareTargets();
|
|
46269
46311
|
});
|
|
46270
46312
|
}
|
|
46313
|
+
getProtocolV2InstallItemStagingPath(item) {
|
|
46314
|
+
return `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}${item.fileName}`;
|
|
46315
|
+
}
|
|
46271
46316
|
queryProtocolV2FirmwareUpdateStatus() {
|
|
46272
46317
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46273
46318
|
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
@@ -46868,16 +46913,40 @@ class DeviceFirmwareUpdate extends BaseMethod {
|
|
|
46868
46913
|
}
|
|
46869
46914
|
}
|
|
46870
46915
|
|
|
46916
|
+
const DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS = ['status', 'payload_version', 'path'];
|
|
46917
|
+
function normalizeStatusFields(fields) {
|
|
46918
|
+
if (fields === undefined || fields === null)
|
|
46919
|
+
return undefined;
|
|
46920
|
+
if (typeof fields !== 'object' || Array.isArray(fields)) {
|
|
46921
|
+
throw invalidParameter('Parameter [fields] must be an object.');
|
|
46922
|
+
}
|
|
46923
|
+
const unknownField = Object.keys(fields).find(field => !DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS.includes(field));
|
|
46924
|
+
if (unknownField) {
|
|
46925
|
+
throw invalidParameter(`Unsupported firmware update status field: ${unknownField}`);
|
|
46926
|
+
}
|
|
46927
|
+
const normalized = {};
|
|
46928
|
+
for (const field of DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS) {
|
|
46929
|
+
const value = fields[field];
|
|
46930
|
+
if (value === undefined)
|
|
46931
|
+
continue;
|
|
46932
|
+
if (typeof value !== 'boolean') {
|
|
46933
|
+
throw invalidParameter(`Parameter [fields.${field}] must be a boolean.`);
|
|
46934
|
+
}
|
|
46935
|
+
normalized[field] = value;
|
|
46936
|
+
}
|
|
46937
|
+
return normalized;
|
|
46938
|
+
}
|
|
46871
46939
|
class DeviceGetFirmwareUpdateStatus extends BaseMethod {
|
|
46872
46940
|
init() {
|
|
46873
46941
|
this.requireProtocolV2 = true;
|
|
46874
46942
|
this.skipForceUpdateCheck = true;
|
|
46875
46943
|
this.useDevicePassphraseState = false;
|
|
46876
|
-
|
|
46944
|
+
const fields = normalizeStatusFields(this.payload.fields);
|
|
46945
|
+
this.params = fields ? { fields } : {};
|
|
46877
46946
|
}
|
|
46878
46947
|
run() {
|
|
46879
46948
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46880
|
-
const res = yield this.device.commands.typedCall('DeviceFirmwareUpdateStatusGet', 'DeviceFirmwareUpdateStatus',
|
|
46949
|
+
const res = yield this.device.commands.typedCall('DeviceFirmwareUpdateStatusGet', 'DeviceFirmwareUpdateStatus', this.params);
|
|
46881
46950
|
return Promise.resolve(res.message);
|
|
46882
46951
|
});
|
|
46883
46952
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firmware.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/firmware.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,4BAA4B
|
|
1
|
+
{"version":3,"file":"firmware.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/firmware.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,4BAA4B;;;;;;;;;;;;CAY/B,CAAC;AAEX,MAAM,MAAM,4BAA4B,GACtC,CAAC,OAAO,4BAA4B,CAAC,CAAC,MAAM,OAAO,4BAA4B,CAAC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CommonParams, Response } from '../params';
|
|
2
2
|
import type { DeviceFirmwareUpdateStatus, DeviceFactoryInfo, ProtocolInfo, ProtocolV2DeviceInfo, Success } from '@onekeyfe/hd-transport';
|
|
3
|
-
import type { DeviceFirmwareUpdateParams, DeviceRebootParams, DeviceFactoryInfoSetParams } from '../../api/protocol-v2/helpers';
|
|
3
|
+
import type { DeviceFirmwareUpdateParams, DeviceFirmwareUpdateStatusGetParams, DeviceRebootParams, DeviceFactoryInfoSetParams } from '../../api/protocol-v2/helpers';
|
|
4
4
|
import type { DeviceInfoGetParams } from '../../api/protocol-v2/DeviceInfoGet';
|
|
5
|
-
export type { DeviceFirmwareTargetInput, DeviceFirmwareUpdateParams, DeviceRebootParams, DeviceFactoryInfoSetParams, RebootTypeInput, } from '../../api/protocol-v2/helpers';
|
|
5
|
+
export type { DeviceFirmwareTargetInput, DeviceFirmwareUpdateParams, DeviceFirmwareUpdateStatusGetParams, DeviceRebootParams, DeviceFactoryInfoSetParams, RebootTypeInput, } from '../../api/protocol-v2/helpers';
|
|
6
6
|
export type { DeviceInfoGetParams, DeviceInfoGetTargets, DeviceInfoGetTypes, } from '../../api/protocol-v2/DeviceInfoGet';
|
|
7
7
|
export type FileOpSuccess = {
|
|
8
8
|
message?: string;
|
|
@@ -43,7 +43,7 @@ export declare function ping(connectId: string, params?: CommonParams & {
|
|
|
43
43
|
export declare function deviceReboot(connectId: string, params: CommonParams & DeviceRebootParams): Response<Success>;
|
|
44
44
|
export declare function deviceInfoGet(connectId: string, params?: CommonParams & DeviceInfoGetParams): Response<ProtocolV2DeviceInfo>;
|
|
45
45
|
export declare function deviceFirmwareUpdate(connectId: string, params: CommonParams & DeviceFirmwareUpdateParams): Response<Success | DeviceFirmwareUpdateStatus>;
|
|
46
|
-
export declare function deviceGetFirmwareUpdateStatus(connectId: string, params?: CommonParams): Response<DeviceFirmwareUpdateStatus>;
|
|
46
|
+
export declare function deviceGetFirmwareUpdateStatus(connectId: string, params?: CommonParams & DeviceFirmwareUpdateStatusGetParams): Response<DeviceFirmwareUpdateStatus>;
|
|
47
47
|
export declare function deviceFactoryInfoSet(connectId: string, params: CommonParams & DeviceFactoryInfoSetParams): Response<Success>;
|
|
48
48
|
export declare function deviceFactoryInfoGet(connectId: string, params?: CommonParams): Response<DeviceFactoryInfo>;
|
|
49
49
|
export declare function filesystemPermissionFix(connectId: string, params?: CommonParams): Response<Success>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocolV2.d.ts","sourceRoot":"","sources":["../../../src/types/api/protocolV2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC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AE,MAAM,EAEjB,MAAM,EAAE,YAAY,GAAG;IAAE,MAAM,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAC9E,QAAQ,CAAC,OAAO,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.5",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.5",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.5",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"bytebuffer": "^5.0.1",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"@types/w3c-web-usb": "^1.0.10",
|
|
45
45
|
"@types/web-bluetooth": "^0.0.21"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "703cfb4e17c6f9315afcb0522ee23ea016ede659"
|
|
48
48
|
}
|
|
@@ -100,6 +100,12 @@ type ProtocolV2FirmwareUpdateStartResponse =
|
|
|
100
100
|
| undefined;
|
|
101
101
|
|
|
102
102
|
type ProtocolV2TargetBinary = { fileName: string; binary: ArrayBuffer; targetId: number };
|
|
103
|
+
type ProtocolV2InstallItem = ProtocolV2TargetBinary & {
|
|
104
|
+
kind: ProtocolV2RemoteComponentTarget['kind'];
|
|
105
|
+
};
|
|
106
|
+
type ProtocolV2InstallTarget = ProtocolV2InstallItem & {
|
|
107
|
+
path: string;
|
|
108
|
+
};
|
|
103
109
|
|
|
104
110
|
type ProtocolV2RemoteComponentBinary = ProtocolV2RemoteComponentTarget & {
|
|
105
111
|
binary: ArrayBuffer;
|
|
@@ -456,6 +462,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
456
462
|
let resourceBinaryMap: ProtocolV2TargetBinary[] = [];
|
|
457
463
|
let fwBinaryMap: ProtocolV2TargetBinary[] = [];
|
|
458
464
|
let bootloaderBinary: ArrayBuffer | null = null;
|
|
465
|
+
let installItems: ProtocolV2InstallItem[] | undefined;
|
|
459
466
|
try {
|
|
460
467
|
this.postTipMessage(FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
461
468
|
resourceBinaryMap = await this.prepareResourceBinaries(firmwareType, deviceFeatures);
|
|
@@ -469,6 +476,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
469
476
|
resourceBinaryMap = remoteBinaries.resourceBinaryMap;
|
|
470
477
|
bootloaderBinary = remoteBinaries.bootloaderBinary;
|
|
471
478
|
fwBinaryMap = remoteBinaries.fwBinaryMap;
|
|
479
|
+
installItems = remoteBinaries.installItems;
|
|
472
480
|
}
|
|
473
481
|
this.postTipMessage(FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
474
482
|
} catch (err) {
|
|
@@ -488,6 +496,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
488
496
|
resourceBinaryMap,
|
|
489
497
|
fwBinaryMap,
|
|
490
498
|
bootloaderBinary,
|
|
499
|
+
...(installItems ? { installItems } : undefined),
|
|
491
500
|
});
|
|
492
501
|
|
|
493
502
|
await this.exitProtocolV2BootloaderToNormal();
|
|
@@ -559,6 +568,33 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
559
568
|
);
|
|
560
569
|
}
|
|
561
570
|
|
|
571
|
+
private buildProtocolV2InstallItems({
|
|
572
|
+
resourceBinaryMap,
|
|
573
|
+
bootloaderBinary,
|
|
574
|
+
fwBinaryMap,
|
|
575
|
+
}: {
|
|
576
|
+
resourceBinaryMap: ProtocolV2TargetBinary[];
|
|
577
|
+
bootloaderBinary: ArrayBuffer | null;
|
|
578
|
+
fwBinaryMap: ProtocolV2TargetBinary[];
|
|
579
|
+
}): ProtocolV2InstallItem[] {
|
|
580
|
+
const installItems: ProtocolV2InstallItem[] = resourceBinaryMap.map(resource => ({
|
|
581
|
+
...resource,
|
|
582
|
+
kind: 'resource',
|
|
583
|
+
}));
|
|
584
|
+
|
|
585
|
+
if (bootloaderBinary) {
|
|
586
|
+
installItems.push({
|
|
587
|
+
fileName: 'bootloader.bin',
|
|
588
|
+
binary: bootloaderBinary,
|
|
589
|
+
targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER,
|
|
590
|
+
kind: 'bootloader',
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
installItems.push(...fwBinaryMap.map(item => ({ ...item, kind: 'firmware' as const })));
|
|
595
|
+
return installItems;
|
|
596
|
+
}
|
|
597
|
+
|
|
562
598
|
private getRemoteComponentEntries(release: IFirmwareReleaseInfo) {
|
|
563
599
|
const { components } = release;
|
|
564
600
|
if (!components) return [];
|
|
@@ -816,12 +852,14 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
816
852
|
const resourceBinaryMap: ProtocolV2TargetBinary[] = [];
|
|
817
853
|
let bootloaderBinary: ArrayBuffer | null = null;
|
|
818
854
|
const fwBinaryMap: ProtocolV2TargetBinary[] = [];
|
|
855
|
+
const installItems: ProtocolV2InstallItem[] = [];
|
|
819
856
|
|
|
820
857
|
if (!release) {
|
|
821
858
|
return {
|
|
822
859
|
resourceBinaryMap,
|
|
823
860
|
bootloaderBinary,
|
|
824
861
|
fwBinaryMap,
|
|
862
|
+
installItems,
|
|
825
863
|
};
|
|
826
864
|
}
|
|
827
865
|
|
|
@@ -839,19 +877,29 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
839
877
|
if (shouldInstall) {
|
|
840
878
|
const remoteBinary = await this.downloadRemoteProtocolV2Component(key, component);
|
|
841
879
|
if (remoteBinary.kind === 'resource') {
|
|
842
|
-
|
|
880
|
+
const binaryEntry = {
|
|
843
881
|
fileName: this.getProtocolV2ResourceComponentFileName(key),
|
|
844
882
|
binary: remoteBinary.binary,
|
|
845
883
|
targetId: remoteBinary.targetId,
|
|
846
|
-
}
|
|
884
|
+
};
|
|
885
|
+
resourceBinaryMap.push(binaryEntry);
|
|
886
|
+
installItems.push({ ...binaryEntry, kind: remoteBinary.kind });
|
|
847
887
|
} else if (remoteBinary.kind === 'bootloader') {
|
|
848
888
|
bootloaderBinary = remoteBinary.binary;
|
|
849
|
-
|
|
850
|
-
fwBinaryMap.push({
|
|
889
|
+
installItems.push({
|
|
851
890
|
fileName: remoteBinary.fileName,
|
|
852
891
|
binary: remoteBinary.binary,
|
|
853
892
|
targetId: remoteBinary.targetId,
|
|
893
|
+
kind: remoteBinary.kind,
|
|
854
894
|
});
|
|
895
|
+
} else {
|
|
896
|
+
const binaryEntry = {
|
|
897
|
+
fileName: remoteBinary.fileName,
|
|
898
|
+
binary: remoteBinary.binary,
|
|
899
|
+
targetId: remoteBinary.targetId,
|
|
900
|
+
};
|
|
901
|
+
fwBinaryMap.push(binaryEntry);
|
|
902
|
+
installItems.push({ ...binaryEntry, kind: remoteBinary.kind });
|
|
855
903
|
}
|
|
856
904
|
}
|
|
857
905
|
}
|
|
@@ -860,6 +908,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
860
908
|
resourceBinaryMap,
|
|
861
909
|
bootloaderBinary,
|
|
862
910
|
fwBinaryMap,
|
|
911
|
+
installItems,
|
|
863
912
|
};
|
|
864
913
|
}
|
|
865
914
|
|
|
@@ -968,18 +1017,25 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
968
1017
|
resourceBinaryMap,
|
|
969
1018
|
fwBinaryMap,
|
|
970
1019
|
bootloaderBinary,
|
|
1020
|
+
installItems,
|
|
971
1021
|
}: {
|
|
972
|
-
resourceBinaryMap
|
|
973
|
-
fwBinaryMap
|
|
974
|
-
bootloaderBinary
|
|
1022
|
+
resourceBinaryMap?: ProtocolV2TargetBinary[];
|
|
1023
|
+
fwBinaryMap?: ProtocolV2TargetBinary[];
|
|
1024
|
+
bootloaderBinary?: ArrayBuffer | null;
|
|
1025
|
+
installItems?: ProtocolV2InstallItem[];
|
|
975
1026
|
}) {
|
|
1027
|
+
const orderedInstallItems =
|
|
1028
|
+
installItems ??
|
|
1029
|
+
this.buildProtocolV2InstallItems({
|
|
1030
|
+
resourceBinaryMap: resourceBinaryMap ?? [],
|
|
1031
|
+
bootloaderBinary: bootloaderBinary ?? null,
|
|
1032
|
+
fwBinaryMap: fwBinaryMap ?? [],
|
|
1033
|
+
});
|
|
976
1034
|
let totalSize = 0;
|
|
977
1035
|
let processedSize = 0;
|
|
978
1036
|
let transferredSize = 0;
|
|
979
1037
|
|
|
980
|
-
for (const
|
|
981
|
-
for (const fwbinary of fwBinaryMap) totalSize += fwbinary.binary.byteLength;
|
|
982
|
-
if (bootloaderBinary) totalSize += bootloaderBinary.byteLength;
|
|
1038
|
+
for (const item of orderedInstallItems) totalSize += item.binary.byteLength;
|
|
983
1039
|
|
|
984
1040
|
this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
|
|
985
1041
|
const transferStartTime = Date.now();
|
|
@@ -992,64 +1048,26 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
992
1048
|
`[FirmwareUpdateV4] transfer started transport=${transferTransport} total=${totalSize} bytes chunk=${chunkSize} bytes`
|
|
993
1049
|
);
|
|
994
1050
|
|
|
995
|
-
const
|
|
996
|
-
const targets: Array<{ target_id: number; path: string }> = [];
|
|
1051
|
+
const stagedInstallTargets: ProtocolV2InstallTarget[] = [];
|
|
997
1052
|
|
|
998
1053
|
try {
|
|
999
|
-
for (const
|
|
1000
|
-
const
|
|
1001
|
-
Log.log(
|
|
1002
|
-
`[FirmwareUpdateV4] staging resource via FilesystemFileWrite target=${resource.targetId} path=${resourceFilePath} bytes=${resource.binary.byteLength}`
|
|
1003
|
-
);
|
|
1004
|
-
processedSize = await this.protocolV2CommonUpdateProcess({
|
|
1005
|
-
payload: resource.binary,
|
|
1006
|
-
filePath: resourceFilePath,
|
|
1007
|
-
processedSize,
|
|
1008
|
-
totalSize,
|
|
1009
|
-
onTransferredBytes,
|
|
1010
|
-
});
|
|
1011
|
-
transferredSize = processedSize;
|
|
1012
|
-
resourceTargets.push({
|
|
1013
|
-
target_id: resource.targetId,
|
|
1014
|
-
path: resourceFilePath,
|
|
1015
|
-
});
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
if (bootloaderBinary) {
|
|
1019
|
-
const bootloaderPath = `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}bootloader.bin`;
|
|
1054
|
+
for (const item of orderedInstallItems) {
|
|
1055
|
+
const filePath = this.getProtocolV2InstallItemStagingPath(item);
|
|
1020
1056
|
Log.log(
|
|
1021
|
-
`[FirmwareUpdateV4] staging
|
|
1057
|
+
`[FirmwareUpdateV4] staging ${item.kind} via FilesystemFileWrite target=${item.targetId} path=${filePath} source=${item.fileName} bytes=${item.binary.byteLength}`
|
|
1022
1058
|
);
|
|
1023
1059
|
processedSize = await this.protocolV2CommonUpdateProcess({
|
|
1024
|
-
payload:
|
|
1025
|
-
filePath
|
|
1060
|
+
payload: item.binary,
|
|
1061
|
+
filePath,
|
|
1026
1062
|
processedSize,
|
|
1027
1063
|
totalSize,
|
|
1028
1064
|
onTransferredBytes,
|
|
1029
1065
|
});
|
|
1030
1066
|
transferredSize = processedSize;
|
|
1031
|
-
targets.push({
|
|
1032
|
-
target_id: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER,
|
|
1033
|
-
path: bootloaderPath,
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
1067
|
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
`[FirmwareUpdateV4] staging firmware via FilesystemFileWrite target=${fwbinary.targetId} path=${firmwarePath} bytes=${fwbinary.binary.byteLength}`
|
|
1041
|
-
);
|
|
1042
|
-
processedSize = await this.protocolV2CommonUpdateProcess({
|
|
1043
|
-
payload: fwbinary.binary,
|
|
1044
|
-
filePath: firmwarePath,
|
|
1045
|
-
processedSize,
|
|
1046
|
-
totalSize,
|
|
1047
|
-
onTransferredBytes,
|
|
1048
|
-
});
|
|
1049
|
-
transferredSize = processedSize;
|
|
1050
|
-
targets.push({
|
|
1051
|
-
target_id: fwbinary.targetId,
|
|
1052
|
-
path: firmwarePath,
|
|
1068
|
+
stagedInstallTargets.push({
|
|
1069
|
+
...item,
|
|
1070
|
+
path: filePath,
|
|
1053
1071
|
});
|
|
1054
1072
|
}
|
|
1055
1073
|
|
|
@@ -1074,23 +1092,43 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1074
1092
|
}
|
|
1075
1093
|
|
|
1076
1094
|
this.postTipMessage(FirmwareUpdateTipMessage.ConfirmOnDevice);
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
)}`
|
|
1083
|
-
);
|
|
1084
|
-
const startResponse = await this.protocolV2StartFirmwareUpdate({
|
|
1085
|
-
targets: resourceTargetsBatch,
|
|
1086
|
-
});
|
|
1087
|
-
await this.waitForProtocolV2FirmwareUpdateComplete(resourceTargetsBatch, startResponse);
|
|
1088
|
-
}
|
|
1089
|
-
if (targets.length > 0) {
|
|
1095
|
+
|
|
1096
|
+
const firmwareTargets: Array<{ target_id: number; path: string }> = [];
|
|
1097
|
+
const flushFirmwareTargets = async () => {
|
|
1098
|
+
if (firmwareTargets.length === 0) return;
|
|
1099
|
+
const targets = firmwareTargets.splice(0, firmwareTargets.length);
|
|
1090
1100
|
Log.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateRequest targets=${JSON.stringify(targets)}`);
|
|
1091
1101
|
const startResponse = await this.protocolV2StartFirmwareUpdate({ targets });
|
|
1092
1102
|
await this.waitForProtocolV2FirmwareUpdateComplete(targets, startResponse);
|
|
1103
|
+
};
|
|
1104
|
+
|
|
1105
|
+
for (const item of stagedInstallTargets) {
|
|
1106
|
+
const target = {
|
|
1107
|
+
target_id: item.targetId,
|
|
1108
|
+
path: item.path,
|
|
1109
|
+
};
|
|
1110
|
+
if (item.kind === 'resource') {
|
|
1111
|
+
await flushFirmwareTargets();
|
|
1112
|
+
const resourceTargets = [target];
|
|
1113
|
+
Log.log(
|
|
1114
|
+
`[FirmwareUpdateV4] DeviceFirmwareUpdateRequest resources=${JSON.stringify(
|
|
1115
|
+
resourceTargets
|
|
1116
|
+
)}`
|
|
1117
|
+
);
|
|
1118
|
+
const startResponse = await this.protocolV2StartFirmwareUpdate({
|
|
1119
|
+
targets: resourceTargets,
|
|
1120
|
+
});
|
|
1121
|
+
await this.waitForProtocolV2FirmwareUpdateComplete(resourceTargets, startResponse);
|
|
1122
|
+
} else {
|
|
1123
|
+
firmwareTargets.push(target);
|
|
1124
|
+
}
|
|
1093
1125
|
}
|
|
1126
|
+
|
|
1127
|
+
await flushFirmwareTargets();
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
private getProtocolV2InstallItemStagingPath(item: ProtocolV2InstallItem) {
|
|
1131
|
+
return `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}${item.fileName}`;
|
|
1094
1132
|
}
|
|
1095
1133
|
|
|
1096
1134
|
private async queryProtocolV2FirmwareUpdateStatus() {
|
|
@@ -13,6 +13,7 @@ import { DeviceModelToTypes } from '../../types';
|
|
|
13
13
|
import { DataManager } from '../../data-manager';
|
|
14
14
|
import { BaseMethod } from '../BaseMethod';
|
|
15
15
|
import { DEVICE } from '../../events';
|
|
16
|
+
import { createFirmwareProgressThrottle } from './progressThrottle';
|
|
16
17
|
|
|
17
18
|
import type {
|
|
18
19
|
IFirmwareUpdateProgressType,
|
|
@@ -40,6 +41,8 @@ const isDeviceDisconnectedError = (error: unknown) => {
|
|
|
40
41
|
export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
41
42
|
checkPromise: Deferred<any> | null = null;
|
|
42
43
|
|
|
44
|
+
private shouldPostFirmwareProgress = createFirmwareProgressThrottle();
|
|
45
|
+
|
|
43
46
|
init(): void {}
|
|
44
47
|
|
|
45
48
|
run(): Promise<any> {
|
|
@@ -83,6 +86,10 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
83
86
|
* @param progress Post the percentage of the progress
|
|
84
87
|
*/
|
|
85
88
|
postProgressMessage = (progress: number, progressType: IFirmwareUpdateProgressType) => {
|
|
89
|
+
if (!this.shouldPostFirmwareProgress(progress, progressType)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
86
93
|
this.postMessage(
|
|
87
94
|
createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
88
95
|
device: this.device.toMessageObject() as KnownDevice,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { IFirmwareUpdateProgressType } from '../../events/ui-request';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_FIRMWARE_PROGRESS_INTERVAL_MS = 250;
|
|
4
|
+
|
|
5
|
+
type FirmwareProgressThrottleState = {
|
|
6
|
+
lastEmittedAt: number;
|
|
7
|
+
lastProgress?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const createFirmwareProgressThrottle = (
|
|
11
|
+
intervalMs = DEFAULT_FIRMWARE_PROGRESS_INTERVAL_MS
|
|
12
|
+
) => {
|
|
13
|
+
const stateByType = new Map<IFirmwareUpdateProgressType, FirmwareProgressThrottleState>();
|
|
14
|
+
|
|
15
|
+
return (progress: number, progressType: IFirmwareUpdateProgressType) => {
|
|
16
|
+
if (progressType !== 'transferData') {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const normalizedProgress = Math.max(0, Math.min(100, Math.floor(progress)));
|
|
21
|
+
if (normalizedProgress === 0 || normalizedProgress === 100) {
|
|
22
|
+
stateByType.set(progressType, {
|
|
23
|
+
lastEmittedAt: Date.now(),
|
|
24
|
+
lastProgress: normalizedProgress,
|
|
25
|
+
});
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
const state = stateByType.get(progressType);
|
|
31
|
+
if (
|
|
32
|
+
state &&
|
|
33
|
+
(state.lastProgress === normalizedProgress || now - state.lastEmittedAt < intervalMs)
|
|
34
|
+
) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
stateByType.set(progressType, {
|
|
39
|
+
lastEmittedAt: now,
|
|
40
|
+
lastProgress: normalizedProgress,
|
|
41
|
+
});
|
|
42
|
+
return true;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -1,19 +1,53 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
import { invalidParameter } from '../helpers/filesystemValidation';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import type { DeviceFirmwareUpdateStatusGetParams } from './helpers';
|
|
5
|
+
import type { DeviceFirmwareUpdateRecordFields } from '@onekeyfe/hd-transport';
|
|
6
|
+
|
|
7
|
+
const DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS = ['status', 'payload_version', 'path'] as const;
|
|
8
|
+
|
|
9
|
+
function normalizeStatusFields(
|
|
10
|
+
fields: DeviceFirmwareUpdateStatusGetParams['fields']
|
|
11
|
+
): DeviceFirmwareUpdateRecordFields | undefined {
|
|
12
|
+
if (fields === undefined || fields === null) return undefined;
|
|
13
|
+
if (typeof fields !== 'object' || Array.isArray(fields)) {
|
|
14
|
+
throw invalidParameter('Parameter [fields] must be an object.');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const unknownField = Object.keys(fields).find(
|
|
18
|
+
field => !DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS.includes(field as any)
|
|
19
|
+
);
|
|
20
|
+
if (unknownField) {
|
|
21
|
+
throw invalidParameter(`Unsupported firmware update status field: ${unknownField}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const normalized: DeviceFirmwareUpdateRecordFields = {};
|
|
25
|
+
for (const field of DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS) {
|
|
26
|
+
const value = fields[field];
|
|
27
|
+
if (value === undefined) continue;
|
|
28
|
+
if (typeof value !== 'boolean') {
|
|
29
|
+
throw invalidParameter(`Parameter [fields.${field}] must be a boolean.`);
|
|
30
|
+
}
|
|
31
|
+
normalized[field] = value;
|
|
32
|
+
}
|
|
33
|
+
return normalized;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default class DeviceGetFirmwareUpdateStatus extends BaseMethod<DeviceFirmwareUpdateStatusGetParams> {
|
|
4
37
|
init() {
|
|
5
38
|
// Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
|
|
6
39
|
this.requireProtocolV2 = true;
|
|
7
40
|
this.skipForceUpdateCheck = true;
|
|
8
41
|
this.useDevicePassphraseState = false;
|
|
9
|
-
|
|
42
|
+
const fields = normalizeStatusFields(this.payload.fields);
|
|
43
|
+
this.params = fields ? { fields } : {};
|
|
10
44
|
}
|
|
11
45
|
|
|
12
46
|
async run() {
|
|
13
47
|
const res = await this.device.commands.typedCall(
|
|
14
48
|
'DeviceFirmwareUpdateStatusGet',
|
|
15
49
|
'DeviceFirmwareUpdateStatus',
|
|
16
|
-
|
|
50
|
+
this.params
|
|
17
51
|
);
|
|
18
52
|
return Promise.resolve(res.message);
|
|
19
53
|
}
|
|
@@ -5,6 +5,7 @@ import { ProtocolV2FirmwareTargetType } from '../../protocols/protocol-v2/firmwa
|
|
|
5
5
|
|
|
6
6
|
import type {
|
|
7
7
|
DeviceFirmwareTarget,
|
|
8
|
+
DeviceFirmwareUpdateRecordFields,
|
|
8
9
|
DeviceFirmwareTargetType,
|
|
9
10
|
TransportCallOptions,
|
|
10
11
|
} from '@onekeyfe/hd-transport';
|
|
@@ -31,6 +32,10 @@ export type DeviceFirmwareUpdateParams = {
|
|
|
31
32
|
path?: string;
|
|
32
33
|
};
|
|
33
34
|
|
|
35
|
+
export type DeviceFirmwareUpdateStatusGetParams = {
|
|
36
|
+
fields?: DeviceFirmwareUpdateRecordFields;
|
|
37
|
+
};
|
|
38
|
+
|
|
34
39
|
export type DeviceFactoryInfoSetParams = {
|
|
35
40
|
version?: number;
|
|
36
41
|
serial_number?: string;
|
|
@@ -107,6 +107,8 @@
|
|
|
107
107
|
"MessageType_FirmwareHash": 89,
|
|
108
108
|
"MessageType_UnlockPath": 93,
|
|
109
109
|
"MessageType_UnlockedPathRequest": 94,
|
|
110
|
+
"MessageType_UnLockDevice": 10030,
|
|
111
|
+
"MessageType_UnLockDeviceResponse": 10031,
|
|
110
112
|
"MessageType_SetU2FCounter": 63,
|
|
111
113
|
"MessageType_GetNextU2FCounter": 80,
|
|
112
114
|
"MessageType_NextU2FCounter": 81,
|
|
@@ -81,7 +81,7 @@ export interface FirmwareUpdateV4Params {
|
|
|
81
81
|
se02Binary?: ArrayBuffer;
|
|
82
82
|
se03Binary?: ArrayBuffer;
|
|
83
83
|
se04Binary?: ArrayBuffer;
|
|
84
|
-
/** 资源包通过 FW_MGMT_TARGET_CRATE = 1
|
|
84
|
+
/** 资源包通过 FW_MGMT_TARGET_CRATE = 1 安装;每个元素是一个独立资源包 */
|
|
85
85
|
resourceBinaries?: ArrayBuffer[];
|
|
86
86
|
forcedUpdateRes?: boolean;
|
|
87
87
|
}
|
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
} from '@onekeyfe/hd-transport';
|
|
9
9
|
import type {
|
|
10
10
|
DeviceFirmwareUpdateParams,
|
|
11
|
+
DeviceFirmwareUpdateStatusGetParams,
|
|
11
12
|
DeviceRebootParams,
|
|
12
13
|
DeviceFactoryInfoSetParams,
|
|
13
14
|
} from '../../api/protocol-v2/helpers';
|
|
@@ -17,6 +18,7 @@ import type { DeviceInfoGetParams } from '../../api/protocol-v2/DeviceInfoGet';
|
|
|
17
18
|
export type {
|
|
18
19
|
DeviceFirmwareTargetInput,
|
|
19
20
|
DeviceFirmwareUpdateParams,
|
|
21
|
+
DeviceFirmwareUpdateStatusGetParams,
|
|
20
22
|
DeviceRebootParams,
|
|
21
23
|
DeviceFactoryInfoSetParams,
|
|
22
24
|
RebootTypeInput,
|
|
@@ -93,7 +95,7 @@ export declare function deviceFirmwareUpdate(
|
|
|
93
95
|
|
|
94
96
|
export declare function deviceGetFirmwareUpdateStatus(
|
|
95
97
|
connectId: string,
|
|
96
|
-
params?: CommonParams
|
|
98
|
+
params?: CommonParams & DeviceFirmwareUpdateStatusGetParams
|
|
97
99
|
): Response<DeviceFirmwareUpdateStatus>;
|
|
98
100
|
|
|
99
101
|
export declare function deviceFactoryInfoSet(
|