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