@onekeyfe/hd-core 1.2.0-alpha.164 → 1.2.0-alpha.165
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/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 +96 -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/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
|
@@ -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/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,
|
|
@@ -49,10 +49,22 @@ export function parseProtocolV2Resources(value: unknown): IProtocolV2Resources |
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
export function isProtocolV2ResourceArchiveEntryName(entryName: string): boolean {
|
|
53
|
+
const normalized = entryName.replace(/\\/g, '/');
|
|
54
|
+
if (!normalized.toLowerCase().endsWith('.okpkg')) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const parts = normalized.split('/');
|
|
58
|
+
const fileName = parts[parts.length - 1] ?? '';
|
|
59
|
+
return (
|
|
60
|
+
fileName.length > 0 &&
|
|
61
|
+
!fileName.startsWith('.') &&
|
|
62
|
+
!parts.some(part => part === '__MACOSX' || part === '.' || part === '..' || part === '')
|
|
63
|
+
);
|
|
64
|
+
}
|
|
53
65
|
|
|
54
|
-
function
|
|
55
|
-
|
|
66
|
+
function isSafeResourceDevicePath(path: string): boolean {
|
|
67
|
+
return !(
|
|
56
68
|
path.includes('\\') ||
|
|
57
69
|
path.includes('//') ||
|
|
58
70
|
[...path].some(char => {
|
|
@@ -60,14 +72,6 @@ function isAllowedResourceDevicePath(path: string): boolean {
|
|
|
60
72
|
return code <= 0x1f || code === 0x7f;
|
|
61
73
|
}) ||
|
|
62
74
|
path.split('/').some(part => part === '.' || part === '..')
|
|
63
|
-
) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
if (path === PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH) {
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
return (
|
|
70
|
-
path.endsWith('.okpkg') && PROTOCOL_V2_RESOURCE_DEVICE_ROOTS.some(root => path.startsWith(root))
|
|
71
75
|
);
|
|
72
76
|
}
|
|
73
77
|
|
|
@@ -93,7 +97,7 @@ function readResourceDevicePath(bytes: Uint8Array): string {
|
|
|
93
97
|
throw new Error('Invalid Pro2 RESOURCE package device path metadata');
|
|
94
98
|
}
|
|
95
99
|
const path = readAscii(pathBytes, 0, pathBytes.byteLength);
|
|
96
|
-
if (!
|
|
100
|
+
if (!isSafeResourceDevicePath(path)) {
|
|
97
101
|
throw new Error(`Invalid Pro2 RESOURCE package device path: ${path}`);
|
|
98
102
|
}
|
|
99
103
|
return path;
|
|
@@ -158,7 +158,7 @@ export interface FirmwareUpdateV4Params {
|
|
|
158
158
|
se02Binary?: ArrayBuffer;
|
|
159
159
|
se03Binary?: ArrayBuffer;
|
|
160
160
|
se04Binary?: ArrayBuffer;
|
|
161
|
-
/** Complete Protocol V2 resource ZIP
|
|
161
|
+
/** Complete Protocol V2 resource ZIP. Core parses RESC packages and writes only changed files. */
|
|
162
162
|
resourceArchiveBinary?: ArrayBuffer;
|
|
163
163
|
forcedUpdateRes?: boolean;
|
|
164
164
|
artifactReader?: FirmwareArtifactReader;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EDeviceType,
|
|
3
|
+
EFirmwareType,
|
|
4
|
+
canonicalizePro2BleAdvertisementName,
|
|
5
|
+
} from '@onekeyfe/hd-shared';
|
|
2
6
|
import { Enum_Capability } from '@onekeyfe/hd-transport';
|
|
3
7
|
|
|
4
8
|
import type { PROTO } from '../constants';
|
|
@@ -125,9 +129,10 @@ export const resolveDeviceFirmwareType = (features?: DeviceFeaturesInput): EFirm
|
|
|
125
129
|
export const resolveDeviceBleName = (features?: DeviceFeaturesInput): string | null => {
|
|
126
130
|
if (!features) return null;
|
|
127
131
|
const compatible = asCompatibleFeatures(features);
|
|
128
|
-
|
|
129
|
-
firstNonEmptyString(compatible.bleName, compatible.onekey_ble_name, compatible.ble_name) ??
|
|
130
|
-
|
|
132
|
+
const bleName =
|
|
133
|
+
firstNonEmptyString(compatible.bleName, compatible.onekey_ble_name, compatible.ble_name) ??
|
|
134
|
+
null;
|
|
135
|
+
return bleName ? canonicalizePro2BleAdvertisementName(bleName) : null;
|
|
131
136
|
};
|
|
132
137
|
|
|
133
138
|
export const resolveDeviceFirmwareVersion = (features?: DeviceFeaturesInput): string | null => {
|
|
@@ -31,7 +31,9 @@ export const getDeviceTypeByBleName = (name?: string): IDeviceType => {
|
|
|
31
31
|
if (/^Touch/i.test(name)) return EDeviceType.Touch;
|
|
32
32
|
|
|
33
33
|
const compactName = name.replace(/[\s-]/g, '');
|
|
34
|
-
|
|
34
|
+
// Require a 4-hex Pro2 suffix in the compact form. A bare `^Pro2` prefix
|
|
35
|
+
// would also match OneKey Pro names such as "Pro 22D8" / "Pro 2D8F".
|
|
36
|
+
if (/\bPro\s*2\b/i.test(name) || /^(?:OneKey)?Pro2[a-f0-9]{4}$/i.test(compactName)) {
|
|
35
37
|
return EDeviceType.Pro2;
|
|
36
38
|
}
|
|
37
39
|
if (/\bNeo\b/i.test(name) || /^Neo/i.test(name) || /^(?:OneKey)?Neo/i.test(compactName)) {
|