@onekeyfe/hd-core 1.2.0-alpha.164 → 1.2.0-alpha.166
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__/device-state-events.test.ts +2 -2
- package/__tests__/device-state-mapper.test.ts +11 -2
- package/__tests__/device-utils.test.ts +6 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +13 -3
- package/__tests__/protocol-v2-resources.test.ts +35 -2
- package/__tests__/protocol-v2.test.ts +89 -42
- package/__tests__/search-devices.test.ts +4 -3
- package/dist/api/FirmwareUpdateV4.d.ts +3 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -15
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/index.d.ts +2 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +98 -245
- package/dist/protocols/protocol-v2/resources.d.ts +1 -0
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +75 -179
- package/src/api/SearchDevices.ts +2 -2
- package/src/api/firmware/FirmwareUpdatePlan.ts +0 -41
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +10 -6
- package/src/core/index.ts +16 -6
- package/src/device/Device.ts +3 -1
- package/src/device/DeviceStateMapper.ts +2 -2
- package/src/deviceProfile/buildDeviceFeatures.ts +7 -2
- package/src/index.ts +0 -6
- package/src/protocols/protocol-v2/resources.ts +16 -12
- package/src/types/api/firmwareUpdate.ts +1 -1
- package/src/utils/deviceFeaturesCompat.ts +9 -4
- package/src/utils/deviceInfoUtils.ts +3 -1
- package/__tests__/firmware-memory-host.test.ts +0 -126
- package/dist/api/firmware/FirmwareMemoryHost.d.ts +0 -22
- package/dist/api/firmware/FirmwareMemoryHost.d.ts.map +0 -1
- package/src/api/firmware/FirmwareMemoryHost.ts +0 -143
|
@@ -4,6 +4,7 @@ export declare const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH: string;
|
|
|
4
4
|
export declare const PROTOCOL_V2_ROM_PARAMS_PACKAGE_PATH = "vol0:/loaders/rom/params.okpkg";
|
|
5
5
|
export declare const PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE = 24464;
|
|
6
6
|
export declare function parseProtocolV2Resources(value: unknown): IProtocolV2Resources | undefined;
|
|
7
|
+
export declare function isProtocolV2ResourceArchiveEntryName(entryName: string): boolean;
|
|
7
8
|
export type ProtocolV2ResourcePackageHeader = {
|
|
8
9
|
version: IVersionArray;
|
|
9
10
|
payloadLength: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/resources.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEvE,eAAO,MAAM,sCAAsC,iDACH,CAAC;AACjD,eAAO,MAAM,8CAA8C,QAAsD,CAAC;AAClH,eAAO,MAAM,mCAAmC,mCAAmC,CAAC;AACpF,eAAO,MAAM,wCAAwC,QAAS,CAAC;AAW/D,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CA8BzF;
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/resources.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEvE,eAAO,MAAM,sCAAsC,iDACH,CAAC;AACjD,eAAO,MAAM,8CAA8C,QAAsD,CAAC;AAClH,eAAO,MAAM,mCAAmC,mCAAmC,CAAC;AACpF,eAAO,MAAM,wCAAwC,QAAS,CAAC;AAW/D,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CA8BzF;AAED,wBAAgB,oCAAoC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAY/E;AA0CD,MAAM,MAAM,+BAA+B,GAAG;IAC5C,OAAO,EAAE,aAAa,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,oCAAoC,CAClD,KAAK,EAAE,UAAU,EACjB,WAAW,EAAE,MAAM,GAClB,+BAA+B,CAyCjC;AAED,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,WAAW,GAAG,UAAU,GAC/B,+BAA+B,CAGjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceFeaturesCompat.d.ts","sourceRoot":"","sources":["../../src/utils/deviceFeaturesCompat.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"deviceFeaturesCompat.d.ts","sourceRoot":"","sources":["../../src/utils/deviceFeaturesCompat.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EAEd,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEtD,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;AAoB5D,eAAO,MAAM,qBAAqB,cAAe,mBAAmB,KAAG,MAWtE,CAAC;AAEF,eAAO,MAAM,2BAA2B,cAAe,mBAAmB,KAAG,OAI5E,CAAC;AAEF,eAAO,MAAM,iBAAiB,cAAe,mBAAmB,KAAG,WAqDlE,CAAC;AAEF,eAAO,MAAM,yBAAyB,cAAe,mBAAmB,KAAG,aAsB1E,CAAC;AAEF,eAAO,MAAM,oBAAoB,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAO9E,CAAC;AAEF,eAAO,MAAM,4BAA4B,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAgBtF,CAAC;AAEF,eAAO,MAAM,8BAA8B,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAiBxF,CAAC;AAEF,eAAO,MAAM,yBAAyB,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAUnF,CAAC;AAEF,eAAO,MAAM,+BAA+B,cAAe,mBAAmB,KAAG,MAAM,GAAG,IASzF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceInfoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceInfoUtils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAKlE,eAAO,MAAM,aAAa,cAAe,mBAAmB,KAAG,WAClC,CAAC;AAM9B,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"deviceInfoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceInfoUtils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAKlE,eAAO,MAAM,aAAa,cAAe,mBAAmB,KAAG,WAClC,CAAC;AAM9B,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,WAqBtD,CAAC;AAMF,eAAO,MAAM,gBAAgB,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAC3C,CAAC;AAKjC,eAAO,MAAM,iBAAiB,cAAe,mBAAmB,KAAG,MAClC,CAAC;AAKlC,eAAO,MAAM,aAAa,cANmB,mBAAmB,KAAG,MAMrB,CAAC;AAK/C,eAAO,MAAM,cAAc,cAAe,mBAAmB,kBAkB5D,CAAC;AAMF,eAAO,MAAM,qBAAqB,aACtB,mBAAmB,GAAG,SAAS,iCACV,WAAW,GAAG,YAAY,KAAK,aAAa,GAAG,SAAS,KACtF,aAAa,GAAG,SAyBlB,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,mBAAmB,gDACzB,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.166",
|
|
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.166",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.166",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "3dd1b964d8503ee800f44466b8c08e3d59be67e8"
|
|
50
50
|
}
|
|
@@ -32,11 +32,13 @@ import {
|
|
|
32
32
|
} from '../protocols/protocol-v2';
|
|
33
33
|
import { requestProtocolV2DeviceInfo } from '../protocols/protocol-v2/features';
|
|
34
34
|
import {
|
|
35
|
+
PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH,
|
|
35
36
|
PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH,
|
|
36
37
|
PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE,
|
|
38
|
+
type ProtocolV2ResourcePackageHeader,
|
|
39
|
+
isProtocolV2ResourceArchiveEntryName,
|
|
37
40
|
parseProtocolV2ResourcePackage,
|
|
38
41
|
parseProtocolV2ResourcePackageHeader,
|
|
39
|
-
type ProtocolV2ResourcePackageHeader,
|
|
40
42
|
} from '../protocols/protocol-v2/resources';
|
|
41
43
|
import {
|
|
42
44
|
getProtocolV2UnknownErrorText,
|
|
@@ -47,20 +49,12 @@ import {
|
|
|
47
49
|
readFirmwareByteSourceFully,
|
|
48
50
|
writeFirmwareByteSource,
|
|
49
51
|
} from './firmware/FirmwareArtifactSource';
|
|
50
|
-
import {
|
|
51
|
-
registerFirmwareUpdateHostBinding,
|
|
52
|
-
resolveFirmwareUpdateHostBinding,
|
|
53
|
-
unregisterFirmwareUpdateHostBinding,
|
|
54
|
-
} from './firmware/FirmwareHostBinding';
|
|
52
|
+
import { resolveFirmwareUpdateHostBinding } from './firmware/FirmwareHostBinding';
|
|
55
53
|
import {
|
|
56
54
|
assertFirmwareUpdatePreparedPlanBinding,
|
|
57
55
|
assertFirmwareUpdatePreparedPlanDeviceIdentity,
|
|
58
|
-
prepareFirmwareUpdatePlan,
|
|
59
56
|
validateFirmwareUpdatePreparedPlan,
|
|
60
57
|
} from './firmware/FirmwareUpdatePreparedPlan';
|
|
61
|
-
import { prepareFirmwareUpdateV4MemoryHost } from './firmware/FirmwareMemoryHost';
|
|
62
|
-
import { buildProtocolV2LocalFirmwareUpdatePlan } from './firmware/FirmwareUpdatePlan';
|
|
63
|
-
|
|
64
58
|
import type {
|
|
65
59
|
FirmwareArtifactReference,
|
|
66
60
|
FirmwareUpdateV4Params,
|
|
@@ -77,11 +71,6 @@ import type {
|
|
|
77
71
|
KnownDevice,
|
|
78
72
|
} from '../types';
|
|
79
73
|
import type { FirmwareByteSource } from './firmware/FirmwareArtifactSource';
|
|
80
|
-
import type {
|
|
81
|
-
FirmwareMemoryArtifact,
|
|
82
|
-
FirmwareMemoryArtifactEntry,
|
|
83
|
-
FirmwareUpdateV4MemoryHost,
|
|
84
|
-
} from './firmware/FirmwareMemoryHost';
|
|
85
74
|
|
|
86
75
|
const Log = getLogger(LoggerNames.Method);
|
|
87
76
|
|
|
@@ -230,7 +219,6 @@ type ProtocolV2ResourceBundleSource = {
|
|
|
230
219
|
|
|
231
220
|
type ProtocolV2LocalResourceArchive = {
|
|
232
221
|
binary: ArrayBuffer;
|
|
233
|
-
materializedEntries: FirmwareMemoryArtifactEntry[];
|
|
234
222
|
resources: Array<{
|
|
235
223
|
entryName: string;
|
|
236
224
|
binary: ArrayBuffer;
|
|
@@ -792,15 +780,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
792
780
|
this.params.resourceArchiveBinary &&
|
|
793
781
|
this.params.targetsToUpdate?.includes('resource')
|
|
794
782
|
) {
|
|
795
|
-
|
|
796
|
-
features: deviceFeatures,
|
|
797
|
-
firmwareType,
|
|
798
|
-
});
|
|
799
|
-
try {
|
|
800
|
-
return await this.runProtocolV2PreparedArtifacts(deviceFeatures, firmwareType);
|
|
801
|
-
} finally {
|
|
802
|
-
localMemoryHost.release();
|
|
803
|
-
}
|
|
783
|
+
return this.runProtocolV2DirectArtifacts({});
|
|
804
784
|
}
|
|
805
785
|
|
|
806
786
|
const hasPreparedComponentArtifacts = Object.values(this.params.componentArtifacts ?? {}).some(
|
|
@@ -813,12 +793,12 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
813
793
|
let fwBinaryMap: ProtocolV2TargetBinary[] = [];
|
|
814
794
|
let bootloaderBinary: ArrayBuffer | null = null;
|
|
815
795
|
let installItems: ProtocolV2InstallItem[] | undefined;
|
|
816
|
-
let
|
|
796
|
+
let explicitInstallItems: ProtocolV2InstallItem[] | undefined;
|
|
817
797
|
try {
|
|
818
798
|
this.postTipMessage(FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
819
799
|
fwBinaryMap = this.collectExplicitTargetBinaries();
|
|
820
800
|
bootloaderBinary = this.prepareBootloaderBinary();
|
|
821
|
-
|
|
801
|
+
explicitInstallItems = this.buildProtocolV2InstallItems({
|
|
822
802
|
bootloaderBinary,
|
|
823
803
|
fwBinaryMap,
|
|
824
804
|
});
|
|
@@ -874,15 +854,9 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
874
854
|
deviceFeatures,
|
|
875
855
|
firmwareType
|
|
876
856
|
);
|
|
877
|
-
resourceMemoryHost = await this.prepareProtocolV2LocalMemoryHost({
|
|
878
|
-
features: deviceFeatures,
|
|
879
|
-
firmwareType,
|
|
880
|
-
availableInstallItems: installItems ?? explicitInstallItems,
|
|
881
|
-
});
|
|
882
857
|
}
|
|
883
858
|
this.postTipMessage(FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
884
859
|
} catch (err) {
|
|
885
|
-
resourceMemoryHost?.release();
|
|
886
860
|
if (
|
|
887
861
|
typeof err === 'object' &&
|
|
888
862
|
err !== null &&
|
|
@@ -897,12 +871,11 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
897
871
|
throw normalizeFirmwarePreparationError(err);
|
|
898
872
|
}
|
|
899
873
|
|
|
900
|
-
if (
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}
|
|
874
|
+
if (wantsResources && this.params.resourceArchiveBinary) {
|
|
875
|
+
return this.runProtocolV2DirectArtifacts({
|
|
876
|
+
availableInstallItems: installItems ?? explicitInstallItems,
|
|
877
|
+
announceDownload: false,
|
|
878
|
+
});
|
|
906
879
|
}
|
|
907
880
|
|
|
908
881
|
if (!bootloaderBinary && fwBinaryMap.length === 0 && !installItems?.length) {
|
|
@@ -1055,133 +1028,69 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1055
1028
|
return installSources;
|
|
1056
1029
|
}
|
|
1057
1030
|
|
|
1058
|
-
private async
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
availableInstallItems = this.buildProtocolV2InstallItems({
|
|
1062
|
-
bootloaderBinary: this.prepareBootloaderBinary(),
|
|
1063
|
-
fwBinaryMap: this.collectExplicitTargetBinaries(),
|
|
1064
|
-
}),
|
|
1031
|
+
private async runProtocolV2DirectArtifacts({
|
|
1032
|
+
availableInstallItems,
|
|
1033
|
+
announceDownload = true,
|
|
1065
1034
|
}: {
|
|
1066
|
-
features: Features;
|
|
1067
|
-
firmwareType: EFirmwareType;
|
|
1068
1035
|
availableInstallItems?: ProtocolV2InstallItem[];
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
);
|
|
1082
|
-
const missingTarget = Array.from(requestedComponentTargets).find(
|
|
1083
|
-
target => !localComponentTargets.has(target)
|
|
1084
|
-
);
|
|
1085
|
-
if (missingTarget) {
|
|
1086
|
-
throw ERRORS.TypedError(
|
|
1087
|
-
HardwareErrorCode.RuntimeError,
|
|
1088
|
-
`Protocol V2 local update has no binary for requested target ${missingTarget}`,
|
|
1089
|
-
{
|
|
1090
|
-
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
1091
|
-
artifactName: missingTarget,
|
|
1092
|
-
}
|
|
1036
|
+
announceDownload?: boolean;
|
|
1037
|
+
}) {
|
|
1038
|
+
try {
|
|
1039
|
+
if (announceDownload) {
|
|
1040
|
+
this.postTipMessage(FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
1041
|
+
}
|
|
1042
|
+
const installItems = this.filterProtocolV2LocalInstallItems(
|
|
1043
|
+
availableInstallItems ??
|
|
1044
|
+
this.buildProtocolV2InstallItems({
|
|
1045
|
+
bootloaderBinary: this.prepareBootloaderBinary(),
|
|
1046
|
+
fwBinaryMap: this.collectExplicitTargetBinaries(),
|
|
1047
|
+
})
|
|
1093
1048
|
);
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1049
|
+
const installSources = await Promise.all(
|
|
1050
|
+
installItems.map(async item => ({
|
|
1051
|
+
fileName: item.fileName,
|
|
1052
|
+
source: await this.openProtocolV2MemorySource(item.binary),
|
|
1053
|
+
targetId: item.targetId,
|
|
1054
|
+
kind: item.kind,
|
|
1055
|
+
}))
|
|
1056
|
+
);
|
|
1057
|
+
const resourceSources = this.params.resourceArchiveBinary
|
|
1058
|
+
? await this.createProtocolV2ResourceSourcesFromArchive(this.params.resourceArchiveBinary)
|
|
1059
|
+
: [];
|
|
1060
|
+
if (installSources.length === 0 && resourceSources.length === 0) {
|
|
1103
1061
|
throw ERRORS.TypedError(
|
|
1104
|
-
HardwareErrorCode.
|
|
1105
|
-
|
|
1106
|
-
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1062
|
+
HardwareErrorCode.FirmwareUpdateDownloadFailed,
|
|
1063
|
+
'No firmware to update'
|
|
1107
1064
|
);
|
|
1108
1065
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
expectedSize: item.binary.byteLength,
|
|
1116
|
-
expectedSha256: bytesToHex(sha256(new Uint8Array(item.binary))),
|
|
1117
|
-
...(this.params.expectedTargetVersions?.[target]
|
|
1118
|
-
? { targetVersion: this.params.expectedTargetVersions[target] }
|
|
1119
|
-
: {}),
|
|
1066
|
+
if (announceDownload) {
|
|
1067
|
+
this.postTipMessage(FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
1068
|
+
}
|
|
1069
|
+
return await this.executeProtocolV2SourceUpdate({
|
|
1070
|
+
installSources,
|
|
1071
|
+
resourceSources,
|
|
1120
1072
|
});
|
|
1121
|
-
|
|
1073
|
+
} finally {
|
|
1074
|
+
await this.closeProtocolV2PreparedSources();
|
|
1122
1075
|
}
|
|
1076
|
+
}
|
|
1123
1077
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
const
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
artifactId: resourceArtifactId,
|
|
1138
|
-
binary: resourceArchive.binary,
|
|
1139
|
-
materializedEntries: resourceArchive.materializedEntries,
|
|
1140
|
-
});
|
|
1141
|
-
|
|
1142
|
-
const plan = buildProtocolV2LocalFirmwareUpdatePlan({
|
|
1143
|
-
features,
|
|
1144
|
-
firmwareType,
|
|
1145
|
-
platform: this.params.platform,
|
|
1146
|
-
artifacts: planArtifacts,
|
|
1147
|
-
});
|
|
1148
|
-
let memoryHost: FirmwareUpdateV4MemoryHost | undefined;
|
|
1149
|
-
try {
|
|
1150
|
-
memoryHost = prepareFirmwareUpdateV4MemoryHost({
|
|
1151
|
-
sdk: {
|
|
1152
|
-
prepareFirmwareUpdatePlan,
|
|
1153
|
-
registerFirmwareUpdateHostBinding,
|
|
1154
|
-
unregisterFirmwareUpdateHostBinding,
|
|
1155
|
-
},
|
|
1156
|
-
plan,
|
|
1157
|
-
artifacts: memoryArtifacts,
|
|
1158
|
-
});
|
|
1159
|
-
const preparedPlan = validateFirmwareUpdatePreparedPlan(memoryHost.preparedPlan);
|
|
1160
|
-
assertFirmwareUpdatePreparedPlanBinding({
|
|
1161
|
-
preparedPlan,
|
|
1162
|
-
executor: 'v4',
|
|
1163
|
-
platform: this.params.platform,
|
|
1164
|
-
scopeTargets: [],
|
|
1165
|
-
bindings: [],
|
|
1166
|
-
});
|
|
1167
|
-
assertFirmwareUpdatePreparedPlanDeviceIdentity({
|
|
1168
|
-
preparedPlan,
|
|
1169
|
-
deviceIdentity: this.protocolV2ExpectedSerialNumber,
|
|
1170
|
-
deviceModel: this.getProtocolV2PreparedPlanDeviceModel(features),
|
|
1078
|
+
private async createProtocolV2ResourceSourcesFromArchive(
|
|
1079
|
+
binary: ArrayBuffer
|
|
1080
|
+
): Promise<ProtocolV2ResourceBundleSource[]> {
|
|
1081
|
+
const archive = await this.prepareProtocolV2LocalResourceArchive(binary);
|
|
1082
|
+
const sources: ProtocolV2ResourceBundleSource[] = [];
|
|
1083
|
+
for (const resource of archive.resources) {
|
|
1084
|
+
sources.push({
|
|
1085
|
+
name: resource.entryName.split('/').pop() ?? resource.entryName,
|
|
1086
|
+
source: await this.openProtocolV2MemorySource(resource.binary),
|
|
1087
|
+
devicePath: resource.header.devicePath,
|
|
1088
|
+
version: resource.header.version,
|
|
1089
|
+
payloadHash: resource.header.payloadHash,
|
|
1090
|
+
headerHash: resource.header.headerHash,
|
|
1171
1091
|
});
|
|
1172
|
-
const hostBinding = resolveFirmwareUpdateHostBinding(
|
|
1173
|
-
memoryHost.hostBindingGeneration,
|
|
1174
|
-
preparedPlan.preparedPlanDigest
|
|
1175
|
-
);
|
|
1176
|
-
this.params.preparedPlan = preparedPlan;
|
|
1177
|
-
this.params.targetsToUpdate = [...preparedPlan.targetsToUpdate] as FirmwareUpdateV4Target[];
|
|
1178
|
-
this.params.artifactReader = hostBinding.artifactReader;
|
|
1179
|
-
this.params.componentArtifacts = undefined;
|
|
1180
|
-
return memoryHost;
|
|
1181
|
-
} catch (error) {
|
|
1182
|
-
memoryHost?.release();
|
|
1183
|
-
throw error;
|
|
1184
1092
|
}
|
|
1093
|
+
return sources;
|
|
1185
1094
|
}
|
|
1186
1095
|
|
|
1187
1096
|
private async prepareProtocolV2LocalResourceArchive(
|
|
@@ -1206,7 +1115,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1206
1115
|
}
|
|
1207
1116
|
const zipEntries = Object.values(zip.files);
|
|
1208
1117
|
const resourceEntries = zipEntries.filter(
|
|
1209
|
-
entry => !entry.dir && entry.name
|
|
1118
|
+
entry => !entry.dir && isProtocolV2ResourceArchiveEntryName(entry.name)
|
|
1210
1119
|
);
|
|
1211
1120
|
if (
|
|
1212
1121
|
resourceEntries.length === 0 ||
|
|
@@ -1220,7 +1129,6 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1220
1129
|
}
|
|
1221
1130
|
|
|
1222
1131
|
let totalSize = 0;
|
|
1223
|
-
const materializedEntries: FirmwareMemoryArtifactEntry[] = [];
|
|
1224
1132
|
const resources: ProtocolV2LocalResourceArchive['resources'] = [];
|
|
1225
1133
|
const devicePaths = new Set<string>();
|
|
1226
1134
|
for (const entry of resourceEntries) {
|
|
@@ -1264,10 +1172,9 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1264
1172
|
);
|
|
1265
1173
|
}
|
|
1266
1174
|
devicePaths.add(canonicalDevicePath);
|
|
1267
|
-
materializedEntries.push({ entryName: entry.name, binary: fileBinary });
|
|
1268
1175
|
resources.push({ entryName: entry.name, binary: fileBinary, header });
|
|
1269
1176
|
}
|
|
1270
|
-
return { binary,
|
|
1177
|
+
return { binary, resources };
|
|
1271
1178
|
}
|
|
1272
1179
|
|
|
1273
1180
|
private async prepareProtocolV2ResourceSources(): Promise<ProtocolV2ResourceBundleSource[]> {
|
|
@@ -1334,20 +1241,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1334
1241
|
|
|
1335
1242
|
// The verified ZIP bytes are authoritative. Non-okpkg entries are release
|
|
1336
1243
|
// metadata only; each RESOURCE package carries its own device path.
|
|
1337
|
-
|
|
1338
|
-
const sources: ProtocolV2ResourceBundleSource[] = [];
|
|
1339
|
-
for (const resource of verifiedArchive.resources) {
|
|
1340
|
-
const source = await this.openProtocolV2MemorySource(resource.binary);
|
|
1341
|
-
sources.push({
|
|
1342
|
-
name: resource.entryName.split('/').pop() ?? resource.entryName,
|
|
1343
|
-
source,
|
|
1344
|
-
devicePath: resource.header.devicePath,
|
|
1345
|
-
version: resource.header.version,
|
|
1346
|
-
payloadHash: resource.header.payloadHash,
|
|
1347
|
-
headerHash: resource.header.headerHash,
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
1350
|
-
return sources;
|
|
1244
|
+
return this.createProtocolV2ResourceSourcesFromArchive(archiveBinary);
|
|
1351
1245
|
}
|
|
1352
1246
|
|
|
1353
1247
|
private async runProtocolV2PreparedArtifacts(
|
|
@@ -1831,6 +1725,12 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1831
1725
|
return `vol0:/${path}`;
|
|
1832
1726
|
}
|
|
1833
1727
|
|
|
1728
|
+
private getProtocolV2ResourceComparePath(devicePath: string) {
|
|
1729
|
+
return isProtocolV2BootResourcePackagePath(devicePath)
|
|
1730
|
+
? PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH
|
|
1731
|
+
: devicePath;
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1834
1734
|
private async readProtocolV2DeviceFileHeader(path: string, expectedSize?: number) {
|
|
1835
1735
|
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
1836
1736
|
const filePath = this.getProtocolV2ResourceFilePath(path);
|
|
@@ -1893,7 +1793,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1893
1793
|
|
|
1894
1794
|
try {
|
|
1895
1795
|
const header = await this.readProtocolV2DeviceFileHeader(
|
|
1896
|
-
bundle.devicePath,
|
|
1796
|
+
this.getProtocolV2ResourceComparePath(bundle.devicePath),
|
|
1897
1797
|
bundle.source.size
|
|
1898
1798
|
);
|
|
1899
1799
|
if (!header) return false;
|
|
@@ -2152,11 +2052,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2152
2052
|
let totalSize = installSources.reduce((total, item) => total + item.source.size, 0);
|
|
2153
2053
|
const resourcesToSync: ProtocolV2ResourceBundleSource[] = [];
|
|
2154
2054
|
for (const resource of resourceSources) {
|
|
2155
|
-
|
|
2156
|
-
// stale staging bytes with the artifact approved by the current PreparedPlan,
|
|
2157
|
-
// even when the mounted final file itself is already current.
|
|
2158
|
-
const requiresFreshStaging = isProtocolV2BootResourcePackagePath(resource.devicePath);
|
|
2159
|
-
if (!requiresFreshStaging && (await this.isProtocolV2ResourceBundleUpToDate(resource))) {
|
|
2055
|
+
if (await this.isProtocolV2ResourceBundleUpToDate(resource)) {
|
|
2160
2056
|
Log.log(`[FirmwareUpdateV4] skip RESC bundle ${resource.name}; already up to date`);
|
|
2161
2057
|
} else {
|
|
2162
2058
|
resourcesToSync.push(resource);
|
package/src/api/SearchDevices.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { canonicalizePro2BleAdvertisementName } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from './BaseMethod';
|
|
4
4
|
import TransportManager from '../data-manager/TransportManager';
|
|
@@ -40,7 +40,7 @@ export default class SearchDevices extends BaseMethod {
|
|
|
40
40
|
seenIds.add(lowerId);
|
|
41
41
|
const rawBleName =
|
|
42
42
|
device.name ?? (device as unknown as { localName?: string }).localName ?? '';
|
|
43
|
-
const bleName =
|
|
43
|
+
const bleName = canonicalizePro2BleAdvertisementName(rawBleName);
|
|
44
44
|
devices.push({
|
|
45
45
|
...device,
|
|
46
46
|
connectId: device.id,
|
|
@@ -654,47 +654,6 @@ const finalizeFirmwareUpdatePlan = ({
|
|
|
654
654
|
});
|
|
655
655
|
};
|
|
656
656
|
|
|
657
|
-
export type ProtocolV2LocalFirmwareUpdatePlanArtifact = {
|
|
658
|
-
artifactId: string;
|
|
659
|
-
target: Exclude<FirmwareUpdateV4Target, 'boot_resources'>;
|
|
660
|
-
container: 'raw' | 'zip';
|
|
661
|
-
logicalName: string;
|
|
662
|
-
expectedSize: number;
|
|
663
|
-
expectedSha256: string;
|
|
664
|
-
targetVersion?: string;
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
export const buildProtocolV2LocalFirmwareUpdatePlan = ({
|
|
668
|
-
features,
|
|
669
|
-
firmwareType,
|
|
670
|
-
platform,
|
|
671
|
-
artifacts,
|
|
672
|
-
}: {
|
|
673
|
-
features: Features;
|
|
674
|
-
firmwareType: EFirmwareType;
|
|
675
|
-
platform: FirmwareUpdatePlatform;
|
|
676
|
-
artifacts: ProtocolV2LocalFirmwareUpdatePlanArtifact[];
|
|
677
|
-
}): FirmwareUpdatePlan => {
|
|
678
|
-
if (artifacts.length === 0) {
|
|
679
|
-
return planError('Protocol V2 local firmware plan has no artifacts');
|
|
680
|
-
}
|
|
681
|
-
const plan = finalizeFirmwareUpdatePlan({
|
|
682
|
-
features,
|
|
683
|
-
firmwareType,
|
|
684
|
-
platform,
|
|
685
|
-
artifacts: artifacts.map(artifact => ({
|
|
686
|
-
...artifact,
|
|
687
|
-
role: artifact.target === 'resource' ? 'resourceBundle' : 'component',
|
|
688
|
-
url: `https://local-firmware.invalid/${encodeURIComponent(artifact.artifactId)}`,
|
|
689
|
-
})),
|
|
690
|
-
targetsToUpdate: artifacts.map(artifact => artifact.target),
|
|
691
|
-
});
|
|
692
|
-
if (plan.executor !== 'v4') {
|
|
693
|
-
return planError('Protocol V2 local firmware plan requires executor v4');
|
|
694
|
-
}
|
|
695
|
-
return plan;
|
|
696
|
-
};
|
|
697
|
-
|
|
698
657
|
export const buildProtocolV2FirmwareUpdatePlan = ({
|
|
699
658
|
features,
|
|
700
659
|
firmwareType,
|
|
@@ -71,6 +71,13 @@ export const getFirmwareUpdateResourceName = (value: unknown): string => {
|
|
|
71
71
|
return resourceName;
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
+
const getPreparedEntryIdentity = (entryName: unknown): string => {
|
|
75
|
+
getFirmwareUpdateResourceName(entryName);
|
|
76
|
+
// Protocol V2 resource ZIPs can ship the same basename from different
|
|
77
|
+
// directories, such as rom/params.okpkg and bootloader/params.okpkg.
|
|
78
|
+
return (entryName as string).toLowerCase();
|
|
79
|
+
};
|
|
80
|
+
|
|
74
81
|
const assertPreparedEntry = (value: unknown): FirmwareUpdatePreparedEntry => {
|
|
75
82
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
76
83
|
return preparedPlanError('Firmware prepared plan entry must be an object');
|
|
@@ -141,11 +148,8 @@ const assertPreparedArtifacts = ({
|
|
|
141
148
|
}
|
|
142
149
|
if (
|
|
143
150
|
materializedEntries &&
|
|
144
|
-
new Set(
|
|
145
|
-
materializedEntries.
|
|
146
|
-
getFirmwareUpdateResourceName(entry.entryName).toLowerCase()
|
|
147
|
-
)
|
|
148
|
-
).size !== materializedEntries.length
|
|
151
|
+
new Set(materializedEntries.map(entry => getPreparedEntryIdentity(entry.entryName))).size !==
|
|
152
|
+
materializedEntries.length
|
|
149
153
|
) {
|
|
150
154
|
return preparedPlanError('Firmware prepared plan contains duplicate entry names');
|
|
151
155
|
}
|
|
@@ -281,7 +285,7 @@ export const validateFirmwareUpdatePreparedPlan = (value: unknown): FirmwareUpda
|
|
|
281
285
|
const materializedEntryNames =
|
|
282
286
|
artifact.materializedEntries?.map(entry => {
|
|
283
287
|
assertPreparedEntry(entry);
|
|
284
|
-
return
|
|
288
|
+
return getPreparedEntryIdentity(entry.entryName);
|
|
285
289
|
}) ?? [];
|
|
286
290
|
if (new Set(materializedEntryNames).size !== materializedEntryNames.length) {
|
|
287
291
|
return preparedPlanError('Firmware prepared plan contains duplicate entry names');
|
package/src/core/index.ts
CHANGED
|
@@ -415,9 +415,12 @@ const onCallDevice = async (
|
|
|
415
415
|
if (method.payload?.onlyConnectBleDevice) {
|
|
416
416
|
preWarmCallbackTask?.resolve();
|
|
417
417
|
Log.debug('Call API - only connect ble device: ', device?.mainId);
|
|
418
|
-
// This early return bypasses the normal-path
|
|
419
|
-
// call
|
|
420
|
-
// and cancel sweep (field log: a completed task lingered for 6 minutes)
|
|
418
|
+
// This early return bypasses the normal-path bookkeeping at the end of the
|
|
419
|
+
// call. Without it the task leaks and haunts every later queue snapshot
|
|
420
|
+
// and cancel sweep (field log: a completed task lingered for 6 minutes),
|
|
421
|
+
// and the request stays in the active maps, so repeated preconnects pile
|
|
422
|
+
// up phantom work in diagnostics.
|
|
423
|
+
completeMethodRequestContext(method);
|
|
421
424
|
requestQueue.releaseTask(method.responseID);
|
|
422
425
|
return createResponseMessage(method.responseID, true, null);
|
|
423
426
|
}
|
|
@@ -1048,9 +1051,16 @@ async function connectDeviceForBle(
|
|
|
1048
1051
|
abortSignal
|
|
1049
1052
|
);
|
|
1050
1053
|
} catch (err) {
|
|
1051
|
-
//
|
|
1052
|
-
//
|
|
1053
|
-
//
|
|
1054
|
+
// The abandoned acquire keeps running: raceBleAcquire only rejects
|
|
1055
|
+
// its own wrapper. Supersede it so that, if it settles later, the
|
|
1056
|
+
// generation guard in Device.acquire drops the link it built instead
|
|
1057
|
+
// of committing mainId/commands over the newer attempt.
|
|
1058
|
+
device.beginConnectionAttempt();
|
|
1059
|
+
// A deadline hit also means the transport is wedged mid-acquire; drop
|
|
1060
|
+
// the link we know about before the retry so it cold-connects instead
|
|
1061
|
+
// of stacking a second connect onto the half-open one. `mainId` is
|
|
1062
|
+
// unset while the first acquire is still pending, which is exactly
|
|
1063
|
+
// the case the generation bump above covers.
|
|
1054
1064
|
if (
|
|
1055
1065
|
err.errorCode === HardwareErrorCode.BleTimeoutError &&
|
|
1056
1066
|
device.mainId &&
|
package/src/device/Device.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ERROR_CODES_REQUIRE_RELEASE,
|
|
10
10
|
HardwareError,
|
|
11
11
|
HardwareErrorCode,
|
|
12
|
+
canonicalizePro2BleAdvertisementName,
|
|
12
13
|
createDeferred,
|
|
13
14
|
createDeviceNotSupportMethodError,
|
|
14
15
|
} from '@onekeyfe/hd-shared';
|
|
@@ -672,7 +673,8 @@ export class Device extends EventEmitter {
|
|
|
672
673
|
}
|
|
673
674
|
|
|
674
675
|
getCurrentBleName() {
|
|
675
|
-
|
|
676
|
+
const bleName = this.state?.identity.bleName ?? null;
|
|
677
|
+
return bleName ? canonicalizePro2BleAdvertisementName(bleName) : null;
|
|
676
678
|
}
|
|
677
679
|
|
|
678
680
|
getCurrentLabel() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EFirmwareType,
|
|
1
|
+
import { EFirmwareType, canonicalizePro2BleAdvertisementName } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { buildProtocolV1FeaturesPayload } from '../deviceProfile/buildDeviceFeatures';
|
|
4
4
|
import { resolveProtocolV2DeviceIdentity } from '../deviceProfile/protocolV2DeviceIdentity';
|
|
@@ -248,7 +248,7 @@ export const mapProtocolV2DeviceInfoToState = (
|
|
|
248
248
|
vendor: 'onekey.so',
|
|
249
249
|
serialNo: info.hw?.serial_no,
|
|
250
250
|
bleName: info.coprocessor?.bt_adv_name
|
|
251
|
-
?
|
|
251
|
+
? canonicalizePro2BleAdvertisementName(info.coprocessor.bt_adv_name)
|
|
252
252
|
: undefined,
|
|
253
253
|
deviceId: loader ? null : undefined,
|
|
254
254
|
}),
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EDeviceType,
|
|
3
|
+
EFirmwareType,
|
|
4
|
+
canonicalizePro2BleAdvertisementName,
|
|
5
|
+
} from '@onekeyfe/hd-shared';
|
|
2
6
|
|
|
3
7
|
import {
|
|
4
8
|
resolveDeviceBleFirmwareVersion,
|
|
@@ -245,7 +249,8 @@ export const buildProtocolV2FeaturesPayload = ({
|
|
|
245
249
|
const deviceId = status?.device_id ?? cached?.deviceId ?? null;
|
|
246
250
|
const serialNo = firstValue(incomingSerialNo, cached?.serialNo) ?? '';
|
|
247
251
|
const label = cached?.label ?? null;
|
|
248
|
-
const
|
|
252
|
+
const rawBleName = firstValue(info?.coprocessor?.bt_adv_name, cached?.bleName);
|
|
253
|
+
const bleName = rawBleName ? canonicalizePro2BleAdvertisementName(rawBleName) : rawBleName;
|
|
249
254
|
const initialized = firstValue(status?.init_states, cached?.initialized) ?? null;
|
|
250
255
|
// passphrase_enabled from a locked Pro2 is not authoritative. Only DeviceStatus
|
|
251
256
|
// after PIN unlock can determine the final passphrase setting.
|
package/src/index.ts
CHANGED
|
@@ -21,12 +21,6 @@ export { executeCallback, cleanupCallback };
|
|
|
21
21
|
export { preloadSessionCache } from './device/Device';
|
|
22
22
|
export { projectFeatures as projectDeviceStateFeatures } from './device/DeviceStateProjector';
|
|
23
23
|
export { getMethodSupportedProtocols } from './api/utils';
|
|
24
|
-
export { prepareFirmwareUpdateV4MemoryHost } from './api/firmware/FirmwareMemoryHost';
|
|
25
|
-
export type {
|
|
26
|
-
FirmwareMemoryArtifact,
|
|
27
|
-
FirmwareMemoryArtifactEntry,
|
|
28
|
-
FirmwareUpdateV4MemoryHost,
|
|
29
|
-
} from './api/firmware/FirmwareMemoryHost';
|
|
30
24
|
export {
|
|
31
25
|
getFirmwareUpdateHostBindingGeneration,
|
|
32
26
|
registerFirmwareUpdateHostBinding,
|