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