@onekeyfe/hd-core 1.2.0-alpha.21 → 1.2.0-alpha.22
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__/DeviceCommands.test.ts +87 -2
- package/__tests__/connectSettings.test.ts +47 -5
- package/__tests__/device-identity.test.ts +24 -2
- package/__tests__/device-settings.test.ts +1 -1
- package/__tests__/device-wallet-session-store.test.ts +111 -7
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
- package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +326 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +200 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +39 -30
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/open-wallet-session.test.ts +253 -13
- package/__tests__/pro2Wallpaper.test.ts +7 -18
- package/__tests__/protocol-v2-unlock-policy.test.ts +45 -0
- package/__tests__/protocol-v2.test.ts +415 -145
- package/__tests__/public-device-state-api.test.ts +69 -62
- package/__tests__/public-pro2-api-boundary.test.ts +8 -34
- package/dist/api/BaseMethod.d.ts +2 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/ClearSessionCache.d.ts.map +1 -1
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +11 -0
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +7 -3
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +29 -10
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxGetAddress.d.ts +1 -0
- package/dist/api/conflux/ConfluxGetAddress.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessage.d.ts +1 -0
- package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts +1 -0
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.d.ts +1 -0
- package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +1 -1
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +26 -0
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +7 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +24 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +25 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/api/firmware/getBinary.d.ts +7 -0
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +2 -0
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +9 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -17
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts +1 -0
- package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/data-manager/DataManager.d.ts +1 -0
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts.map +1 -1
- package/dist/device/DeviceStateProjector.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/index.d.ts +265 -226
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3045 -1550
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +4 -0
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +3 -0
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +2 -2
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +4 -1
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +69 -0
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts +27 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +10 -19
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +1 -0
- package/dist/types/api/openWalletSession.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -76
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/api/sessionCache.d.ts +4 -1
- package/dist/types/api/sessionCache.d.ts.map +1 -1
- package/dist/types/settings.d.ts +13 -0
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +8 -3
- package/src/api/CheckAllFirmwareRelease.ts +16 -3
- package/src/api/ClearSessionCache.ts +4 -0
- package/src/api/FirmwareUpdate.ts +8 -1
- package/src/api/FirmwareUpdateV2.ts +284 -119
- package/src/api/FirmwareUpdateV3.ts +248 -55
- package/src/api/FirmwareUpdateV4.ts +816 -328
- package/src/api/OpenWalletSession.ts +74 -25
- package/src/api/UploadPortfolio.ts +1 -1
- package/src/api/conflux/ConfluxGetAddress.ts +2 -0
- package/src/api/conflux/ConfluxSignMessage.ts +2 -0
- package/src/api/conflux/ConfluxSignMessageCIP23.ts +2 -0
- package/src/api/conflux/ConfluxSignTransaction.ts +2 -0
- package/src/api/device/DeviceChangePin.ts +1 -1
- package/src/api/device/DeviceUnlock.ts +1 -2
- package/src/api/device/DeviceUpdateBootloader.ts +114 -6
- package/src/api/device/DeviceWipe.ts +1 -1
- package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
- package/src/api/firmware/FirmwareHostBinding.ts +100 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +50 -0
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +621 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +378 -0
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +140 -22
- package/src/api/helpers/protocolV2FileWrite.ts +6 -0
- package/src/api/index.ts +0 -18
- package/src/api/nexa/NexaSignTransaction.ts +2 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +1 -1
- package/src/data/messages/messages-protocol-v2.json +77 -4
- package/src/data-manager/DataManager.ts +33 -33
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +50 -60
- package/src/device/DeviceCommands.ts +58 -14
- package/src/device/DeviceStateMapper.ts +18 -1
- package/src/device/DeviceStateProjector.ts +7 -1
- package/src/events/logBlockEvent.ts +1 -0
- package/src/index.ts +5 -0
- package/src/inject.ts +22 -25
- package/src/lowLevelInject.ts +5 -1
- package/src/protocols/protocol-v2/deviceSession.ts +1 -1
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +2 -2
- package/src/protocols/protocol-v2/unlockPolicy.ts +105 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +1 -3
- package/src/protocols/protocol-v2/walletSession.ts +68 -12
- package/src/topLevelInject.ts +5 -1
- package/src/types/api/checkAllFirmwareRelease.ts +3 -0
- package/src/types/api/deviceUnlock.ts +2 -5
- package/src/types/api/deviceUpdateBootloader.ts +6 -0
- package/src/types/api/export.ts +18 -0
- package/src/types/api/firmwareUpdate.ts +76 -0
- package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
- package/src/types/api/firmwareUpdatePlan.ts +36 -0
- package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
- package/src/types/api/index.ts +14 -34
- package/src/types/api/openWalletSession.ts +2 -0
- package/src/types/api/protocolV2.ts +3 -156
- package/src/types/api/sessionCache.ts +9 -4
- package/src/types/settings.ts +13 -0
- package/src/utils/deviceFeaturesUtils.ts +5 -1
|
@@ -17,10 +17,20 @@ import { FirmwareUpdateBaseMethod } from './firmware/FirmwareUpdateBaseMethod';
|
|
|
17
17
|
import { DevicePool } from '../device/DevicePool';
|
|
18
18
|
import { DEVICE } from '../events';
|
|
19
19
|
import { buildProtocolV1FeaturesPayload } from '../deviceProfile';
|
|
20
|
-
|
|
21
|
-
import
|
|
20
|
+
import { openFirmwareByteSource } from './firmware/FirmwareArtifactSource';
|
|
21
|
+
import { resolveFirmwareUpdateHostBinding } from './firmware/FirmwareHostBinding';
|
|
22
|
+
import {
|
|
23
|
+
assertFirmwareUpdatePreparedPlanBinding,
|
|
24
|
+
getFirmwareUpdateResourceName,
|
|
25
|
+
} from './firmware/FirmwareUpdatePreparedPlan';
|
|
26
|
+
|
|
27
|
+
import type {
|
|
28
|
+
FirmwareArtifactReference,
|
|
29
|
+
FirmwareUpdateV3Params,
|
|
30
|
+
} from '../types/api/firmwareUpdate';
|
|
22
31
|
import type { Deferred, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
23
32
|
import type { TypedResponseMessage } from '../device/DeviceCommands';
|
|
33
|
+
import type { FirmwareByteSource } from './firmware/FirmwareArtifactSource';
|
|
24
34
|
|
|
25
35
|
const Log = getLogger(LoggerNames.Method);
|
|
26
36
|
|
|
@@ -42,6 +52,8 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
42
52
|
|
|
43
53
|
private isSwitchFirmware = false;
|
|
44
54
|
|
|
55
|
+
private artifactSources: FirmwareByteSource[] = [];
|
|
56
|
+
|
|
45
57
|
init() {
|
|
46
58
|
this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.NOT_INITIALIZE];
|
|
47
59
|
this.requireDeviceMode = [];
|
|
@@ -62,8 +74,54 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
62
74
|
{ name: 'firmwareType', type: 'string' },
|
|
63
75
|
{ name: 'platform', type: 'string' },
|
|
64
76
|
]);
|
|
77
|
+
const hostBinding =
|
|
78
|
+
payload.artifacts || payload.preparedPlan
|
|
79
|
+
? resolveFirmwareUpdateHostBinding(payload.hostBindingGeneration)
|
|
80
|
+
: undefined;
|
|
81
|
+
if (hostBinding) {
|
|
82
|
+
assertFirmwareUpdatePreparedPlanBinding({
|
|
83
|
+
preparedPlan: payload.preparedPlan,
|
|
84
|
+
executor: 'v3',
|
|
85
|
+
platform: payload.platform,
|
|
86
|
+
scopeTargets: ['bootloader', 'firmware', 'resource', 'ble'],
|
|
87
|
+
bindings: [
|
|
88
|
+
...(payload.artifacts?.bootloader
|
|
89
|
+
? [
|
|
90
|
+
{
|
|
91
|
+
target: 'bootloader' as const,
|
|
92
|
+
artifact: payload.artifacts.bootloader,
|
|
93
|
+
},
|
|
94
|
+
]
|
|
95
|
+
: []),
|
|
96
|
+
...(payload.artifacts?.firmware
|
|
97
|
+
? [
|
|
98
|
+
{
|
|
99
|
+
target: 'firmware' as const,
|
|
100
|
+
artifact: payload.artifacts.firmware,
|
|
101
|
+
},
|
|
102
|
+
]
|
|
103
|
+
: []),
|
|
104
|
+
...(payload.artifacts?.ble
|
|
105
|
+
? [
|
|
106
|
+
{
|
|
107
|
+
target: 'ble' as const,
|
|
108
|
+
artifact: payload.artifacts.ble,
|
|
109
|
+
},
|
|
110
|
+
]
|
|
111
|
+
: []),
|
|
112
|
+
...(payload.artifacts?.resourceEntries ?? []).map(
|
|
113
|
+
(entry: { entryName: string; artifact: FirmwareArtifactReference }) => ({
|
|
114
|
+
target: 'resource' as const,
|
|
115
|
+
entryName: entry.entryName,
|
|
116
|
+
artifact: entry.artifact,
|
|
117
|
+
})
|
|
118
|
+
),
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
}
|
|
65
122
|
|
|
66
123
|
this.params = {
|
|
124
|
+
preparedPlan: payload.preparedPlan,
|
|
67
125
|
bleBinary: payload.bleBinary,
|
|
68
126
|
firmwareBinary: payload.firmwareBinary,
|
|
69
127
|
forcedUpdateRes: payload.forcedUpdateRes,
|
|
@@ -74,6 +132,8 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
74
132
|
resourceBinary: payload.resourceBinary,
|
|
75
133
|
firmwareType: payload.firmwareType,
|
|
76
134
|
platform: payload.platform,
|
|
135
|
+
artifactReader: hostBinding?.artifactReader ?? payload.artifactReader,
|
|
136
|
+
artifacts: payload.artifacts,
|
|
77
137
|
};
|
|
78
138
|
}
|
|
79
139
|
|
|
@@ -109,33 +169,41 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
109
169
|
this.isSwitchFirmware = firmwareType !== deviceFirmwareType;
|
|
110
170
|
|
|
111
171
|
let resourceBinary: ArrayBuffer | null = null;
|
|
112
|
-
let
|
|
113
|
-
let
|
|
172
|
+
let resourceEntries: Array<{ entryName: string; source: FirmwareByteSource }> = [];
|
|
173
|
+
let fwSources: Array<{ fileName: string; source: FirmwareByteSource }> = [];
|
|
174
|
+
let bootloaderSource: FirmwareByteSource | null = null;
|
|
114
175
|
try {
|
|
115
176
|
this.postTipMessage(FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
177
|
+
const resourceInput = await this.prepareResourceInput(firmwareType);
|
|
178
|
+
resourceBinary = resourceInput.resourceBinary;
|
|
179
|
+
resourceEntries = resourceInput.resourceEntries;
|
|
180
|
+
fwSources = await this.prepareFirmwareAndBleSources(firmwareType);
|
|
181
|
+
bootloaderSource = await this.prepareBootloaderSource(firmwareType);
|
|
119
182
|
this.postTipMessage(FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
120
183
|
} catch (err) {
|
|
184
|
+
await this.closeArtifactSources();
|
|
121
185
|
throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateDownloadFailed, err.message ?? err);
|
|
122
186
|
}
|
|
123
187
|
|
|
124
|
-
if (!
|
|
188
|
+
if (!bootloaderSource && fwSources.length === 0) {
|
|
189
|
+
await this.closeArtifactSources();
|
|
125
190
|
throw ERRORS.TypedError(
|
|
126
191
|
HardwareErrorCode.FirmwareUpdateDownloadFailed,
|
|
127
192
|
'No firmware to update'
|
|
128
193
|
);
|
|
129
194
|
}
|
|
130
195
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
196
|
+
try {
|
|
197
|
+
await this.enterBootloaderMode();
|
|
198
|
+
return await this.executeUpdate({
|
|
199
|
+
resourceBinary,
|
|
200
|
+
resourceEntries,
|
|
201
|
+
fwSources,
|
|
202
|
+
bootloaderSource,
|
|
203
|
+
});
|
|
204
|
+
} finally {
|
|
205
|
+
await this.closeArtifactSources();
|
|
206
|
+
}
|
|
139
207
|
}
|
|
140
208
|
|
|
141
209
|
private validateDeviceAndVersion(deviceType: EDeviceType, bootloaderVersion: string) {
|
|
@@ -155,12 +223,81 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
155
223
|
}
|
|
156
224
|
}
|
|
157
225
|
|
|
158
|
-
private async
|
|
226
|
+
private async openArtifactSource(
|
|
227
|
+
binary: ArrayBuffer | undefined,
|
|
228
|
+
artifact: FirmwareArtifactReference | undefined
|
|
229
|
+
) {
|
|
230
|
+
const source = await openFirmwareByteSource({
|
|
231
|
+
binary,
|
|
232
|
+
artifact,
|
|
233
|
+
reader: this.params.artifactReader,
|
|
234
|
+
});
|
|
235
|
+
if (source) {
|
|
236
|
+
this.artifactSources.push(source);
|
|
237
|
+
}
|
|
238
|
+
return source;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private async closeArtifactSources() {
|
|
242
|
+
const sources = this.artifactSources.splice(0);
|
|
243
|
+
await Promise.all(sources.map(source => source.close().catch(() => undefined)));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private assertSdkDownloadAllowed(artifactName: string) {
|
|
247
|
+
if (
|
|
248
|
+
this.params.artifactReader ||
|
|
249
|
+
DataManager.getSettings('firmwareManifestMode') === 'external-only'
|
|
250
|
+
) {
|
|
251
|
+
throw ERRORS.TypedError(
|
|
252
|
+
HardwareErrorCode.RuntimeError,
|
|
253
|
+
`${artifactName} must be prepared by the external firmware host`,
|
|
254
|
+
{
|
|
255
|
+
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
256
|
+
artifactName,
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
private async prepareResourceInput(firmwareType: EFirmwareType) {
|
|
263
|
+
const preparedEntries = this.params.artifacts?.resourceEntries;
|
|
264
|
+
if (preparedEntries?.length && this.params.resourceBinary) {
|
|
265
|
+
throw ERRORS.TypedError(
|
|
266
|
+
HardwareErrorCode.RuntimeError,
|
|
267
|
+
'Firmware resource input must not contain both archive binary and prepared entries'
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
if (preparedEntries?.length) {
|
|
271
|
+
const resourceEntries: Array<{ entryName: string; source: FirmwareByteSource }> = [];
|
|
272
|
+
for (const entry of preparedEntries) {
|
|
273
|
+
const resourceName = getFirmwareUpdateResourceName(entry.entryName);
|
|
274
|
+
const source = await this.openArtifactSource(undefined, entry.artifact);
|
|
275
|
+
if (!source) {
|
|
276
|
+
throw ERRORS.TypedError(
|
|
277
|
+
HardwareErrorCode.RuntimeError,
|
|
278
|
+
`Firmware resource entry ${entry.entryName} is not prepared`
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
resourceEntries.push({ entryName: resourceName, source });
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
resourceBinary: null,
|
|
285
|
+
resourceEntries,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
159
288
|
if (this.params.resourceBinary) {
|
|
160
|
-
return
|
|
289
|
+
return {
|
|
290
|
+
resourceBinary: this.params.resourceBinary,
|
|
291
|
+
resourceEntries: [],
|
|
292
|
+
};
|
|
161
293
|
}
|
|
162
294
|
const { features } = this.device;
|
|
163
|
-
if (!features)
|
|
295
|
+
if (!features) {
|
|
296
|
+
return {
|
|
297
|
+
resourceBinary: null,
|
|
298
|
+
resourceEntries: [],
|
|
299
|
+
};
|
|
300
|
+
}
|
|
164
301
|
const resourceUrl = DataManager.getSysResourcesLatestRelease({
|
|
165
302
|
features,
|
|
166
303
|
forcedUpdateRes: this.params.forcedUpdateRes,
|
|
@@ -168,16 +305,27 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
168
305
|
});
|
|
169
306
|
|
|
170
307
|
if (resourceUrl) {
|
|
171
|
-
|
|
172
|
-
return
|
|
308
|
+
this.assertSdkDownloadAllowed('resource');
|
|
309
|
+
return {
|
|
310
|
+
resourceBinary: (await getSysResourceBinary(resourceUrl)).binary,
|
|
311
|
+
resourceEntries: [],
|
|
312
|
+
};
|
|
173
313
|
}
|
|
174
314
|
Log.warn('No resource url found');
|
|
175
|
-
return
|
|
315
|
+
return {
|
|
316
|
+
resourceBinary: null,
|
|
317
|
+
resourceEntries: [],
|
|
318
|
+
};
|
|
176
319
|
}
|
|
177
320
|
|
|
178
|
-
private async
|
|
179
|
-
|
|
180
|
-
|
|
321
|
+
private async prepareBootloaderSource(
|
|
322
|
+
firmwareType: EFirmwareType
|
|
323
|
+
): Promise<FirmwareByteSource | null> {
|
|
324
|
+
if (this.params.bootloaderBinary || this.params.artifacts?.bootloader) {
|
|
325
|
+
return this.openArtifactSource(
|
|
326
|
+
this.params.bootloaderBinary,
|
|
327
|
+
this.params.artifacts?.bootloader
|
|
328
|
+
);
|
|
181
329
|
}
|
|
182
330
|
const { features } = this.device;
|
|
183
331
|
if (!features) return null;
|
|
@@ -185,23 +333,35 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
185
333
|
if (this.params.bootloaderVersion) {
|
|
186
334
|
const bootResourceUrl = DataManager.getBootloaderResource(features, firmwareType);
|
|
187
335
|
if (bootResourceUrl) {
|
|
336
|
+
this.assertSdkDownloadAllowed('bootloader');
|
|
188
337
|
const bootBinary = (await getSysResourceBinary(bootResourceUrl)).binary;
|
|
189
|
-
return bootBinary;
|
|
338
|
+
return this.openArtifactSource(bootBinary, undefined);
|
|
190
339
|
}
|
|
191
340
|
}
|
|
192
341
|
return null;
|
|
193
342
|
}
|
|
194
343
|
|
|
195
|
-
private async
|
|
196
|
-
const
|
|
197
|
-
if (this.params.firmwareBinary) {
|
|
198
|
-
|
|
344
|
+
private async prepareFirmwareAndBleSources(firmwareType: EFirmwareType) {
|
|
345
|
+
const fwSources: Array<{ fileName: string; source: FirmwareByteSource }> = [];
|
|
346
|
+
if (this.params.firmwareBinary || this.params.artifacts?.firmware) {
|
|
347
|
+
const source = await this.openArtifactSource(
|
|
348
|
+
this.params.firmwareBinary,
|
|
349
|
+
this.params.artifacts?.firmware
|
|
350
|
+
);
|
|
351
|
+
if (!source) {
|
|
352
|
+
throw ERRORS.TypedError(
|
|
353
|
+
HardwareErrorCode.RuntimeError,
|
|
354
|
+
'Firmware artifact is not prepared'
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
fwSources.push({
|
|
199
358
|
fileName: 'firmware.bin',
|
|
200
|
-
|
|
359
|
+
source,
|
|
201
360
|
});
|
|
202
361
|
} else if (this.params.firmwareVersion) {
|
|
203
362
|
const { features } = this.device;
|
|
204
363
|
if (features) {
|
|
364
|
+
this.assertSdkDownloadAllowed('firmware');
|
|
205
365
|
const firmwareBinary = (
|
|
206
366
|
await getBinary({
|
|
207
367
|
features,
|
|
@@ -211,44 +371,65 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
211
371
|
firmwareType,
|
|
212
372
|
})
|
|
213
373
|
).binary;
|
|
214
|
-
|
|
374
|
+
const source = await this.openArtifactSource(firmwareBinary, undefined);
|
|
375
|
+
if (!source) {
|
|
376
|
+
throw ERRORS.TypedError(
|
|
377
|
+
HardwareErrorCode.RuntimeError,
|
|
378
|
+
'Firmware binary is not prepared'
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
fwSources.push({
|
|
215
382
|
fileName: 'firmware.bin',
|
|
216
|
-
|
|
383
|
+
source,
|
|
217
384
|
});
|
|
218
385
|
}
|
|
219
386
|
}
|
|
220
387
|
|
|
221
|
-
if (this.params.bleBinary) {
|
|
222
|
-
|
|
388
|
+
if (this.params.bleBinary || this.params.artifacts?.ble) {
|
|
389
|
+
const source = await this.openArtifactSource(
|
|
390
|
+
this.params.bleBinary,
|
|
391
|
+
this.params.artifacts?.ble
|
|
392
|
+
);
|
|
393
|
+
if (!source) {
|
|
394
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'BLE artifact is not prepared');
|
|
395
|
+
}
|
|
396
|
+
fwSources.push({
|
|
223
397
|
fileName: 'ble-firmware.bin',
|
|
224
|
-
|
|
398
|
+
source,
|
|
225
399
|
});
|
|
226
400
|
} else if (this.params.bleVersion) {
|
|
227
401
|
const { features } = this.device;
|
|
228
402
|
if (features) {
|
|
403
|
+
this.assertSdkDownloadAllowed('ble');
|
|
229
404
|
const bleBinary = await getBinary({
|
|
230
405
|
features,
|
|
231
406
|
version: this.params.bleVersion,
|
|
232
407
|
updateType: 'ble',
|
|
233
408
|
firmwareType,
|
|
234
409
|
});
|
|
235
|
-
|
|
410
|
+
const source = await this.openArtifactSource(bleBinary.binary, undefined);
|
|
411
|
+
if (!source) {
|
|
412
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'BLE binary is not prepared');
|
|
413
|
+
}
|
|
414
|
+
fwSources.push({
|
|
236
415
|
fileName: 'ble-firmware.bin',
|
|
237
|
-
|
|
416
|
+
source,
|
|
238
417
|
});
|
|
239
418
|
}
|
|
240
419
|
}
|
|
241
|
-
return
|
|
420
|
+
return fwSources;
|
|
242
421
|
}
|
|
243
422
|
|
|
244
423
|
private async executeUpdate({
|
|
245
424
|
resourceBinary,
|
|
246
|
-
|
|
247
|
-
|
|
425
|
+
resourceEntries,
|
|
426
|
+
fwSources,
|
|
427
|
+
bootloaderSource,
|
|
248
428
|
}: {
|
|
249
429
|
resourceBinary: ArrayBuffer | null;
|
|
250
|
-
|
|
251
|
-
|
|
430
|
+
resourceEntries: Array<{ entryName: string; source: FirmwareByteSource }>;
|
|
431
|
+
fwSources: Array<{ fileName: string; source: FirmwareByteSource }>;
|
|
432
|
+
bootloaderSource: FirmwareByteSource | null;
|
|
252
433
|
}) {
|
|
253
434
|
let totalSize = 0;
|
|
254
435
|
let processedSize = 0;
|
|
@@ -256,11 +437,14 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
256
437
|
if (resourceBinary) {
|
|
257
438
|
totalSize += resourceBinary.byteLength;
|
|
258
439
|
}
|
|
259
|
-
for (const
|
|
260
|
-
totalSize +=
|
|
440
|
+
for (const entry of resourceEntries) {
|
|
441
|
+
totalSize += entry.source.size;
|
|
261
442
|
}
|
|
262
|
-
|
|
263
|
-
totalSize +=
|
|
443
|
+
for (const firmware of fwSources) {
|
|
444
|
+
totalSize += firmware.source.size;
|
|
445
|
+
}
|
|
446
|
+
if (bootloaderSource) {
|
|
447
|
+
totalSize += bootloaderSource.size;
|
|
264
448
|
}
|
|
265
449
|
|
|
266
450
|
this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
|
|
@@ -283,9 +467,18 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
283
467
|
}
|
|
284
468
|
}
|
|
285
469
|
|
|
286
|
-
|
|
287
|
-
processedSize = await this.
|
|
288
|
-
|
|
470
|
+
for (const entry of resourceEntries) {
|
|
471
|
+
processedSize = await this.emmcCommonUpdateProcessFromSource({
|
|
472
|
+
source: entry.source,
|
|
473
|
+
filePath: `0:res/${entry.entryName}`,
|
|
474
|
+
processedSize,
|
|
475
|
+
totalSize,
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (bootloaderSource) {
|
|
480
|
+
processedSize = await this.emmcCommonUpdateProcessFromSource({
|
|
481
|
+
source: bootloaderSource,
|
|
289
482
|
filePath: `0:boot/bootloader.bin`,
|
|
290
483
|
processedSize,
|
|
291
484
|
totalSize,
|
|
@@ -294,11 +487,11 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
294
487
|
|
|
295
488
|
await this.createUpdatesFolderIfNotExists(`0:updates/`);
|
|
296
489
|
|
|
297
|
-
for (const
|
|
298
|
-
if (
|
|
299
|
-
processedSize = await this.
|
|
300
|
-
|
|
301
|
-
filePath: `0:updates/${
|
|
490
|
+
for (const firmware of fwSources) {
|
|
491
|
+
if (firmware) {
|
|
492
|
+
processedSize = await this.emmcCommonUpdateProcessFromSource({
|
|
493
|
+
source: firmware.source,
|
|
494
|
+
filePath: `0:updates/${firmware.fileName}`,
|
|
302
495
|
processedSize,
|
|
303
496
|
totalSize,
|
|
304
497
|
});
|