@onekeyfe/hd-core 1.2.0-alpha.68 → 1.2.0-alpha.69

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.
Files changed (121) hide show
  1. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +28 -0
  2. package/__tests__/connectSettings.test.ts +5 -47
  3. package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +31 -59
  4. package/__tests__/protocol-v2-firmware-targets.test.ts +33 -1
  5. package/__tests__/protocol-v2-resources.test.ts +9 -6
  6. package/__tests__/protocol-v2.test.ts +174 -383
  7. package/__tests__/protocolV2FileWrite.test.ts +48 -7
  8. package/dist/api/CheckAllFirmwareRelease.d.ts +2 -1
  9. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  10. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  11. package/dist/api/FirmwareUpdateV2.d.ts +0 -10
  12. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  13. package/dist/api/FirmwareUpdateV3.d.ts +3 -7
  14. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  15. package/dist/api/FirmwareUpdateV4.d.ts +6 -25
  16. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  17. package/dist/api/device/DeviceUpdateBootloader.d.ts +1 -5
  18. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  19. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +0 -8
  20. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  21. package/dist/api/firmware/getBinary.d.ts +0 -7
  22. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  23. package/dist/api/firmware/updateBootloader.d.ts +0 -2
  24. package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
  25. package/dist/api/firmware/uploadFirmware.d.ts +1 -9
  26. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  27. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  28. package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
  29. package/dist/data-manager/DataManager.d.ts +0 -1
  30. package/dist/data-manager/DataManager.d.ts.map +1 -1
  31. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  32. package/dist/device/Device.d.ts +0 -1
  33. package/dist/device/Device.d.ts.map +1 -1
  34. package/dist/index.d.ts +2 -180
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +1041 -3037
  37. package/dist/inject.d.ts.map +1 -1
  38. package/dist/lowLevelInject.d.ts.map +1 -1
  39. package/dist/protocols/protocol-v2/resources.d.ts +1 -1
  40. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  41. package/dist/topLevelInject.d.ts.map +1 -1
  42. package/dist/types/api/checkAllFirmwareRelease.d.ts +0 -4
  43. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  44. package/dist/types/api/deviceUpdateBootloader.d.ts +0 -6
  45. package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
  46. package/dist/types/api/export.d.ts +1 -4
  47. package/dist/types/api/export.d.ts.map +1 -1
  48. package/dist/types/api/firmwareUpdate.d.ts +0 -68
  49. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  50. package/dist/types/api/index.d.ts +1 -9
  51. package/dist/types/api/index.d.ts.map +1 -1
  52. package/dist/types/settings.d.ts +1 -14
  53. package/dist/types/settings.d.ts.map +1 -1
  54. package/dist/utils/deviceFeaturesCompat.d.ts +0 -1
  55. package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
  56. package/package.json +4 -4
  57. package/src/api/CheckAllFirmwareRelease.ts +25 -61
  58. package/src/api/FirmwareUpdate.ts +1 -13
  59. package/src/api/FirmwareUpdateV2.ts +121 -296
  60. package/src/api/FirmwareUpdateV3.ts +57 -263
  61. package/src/api/FirmwareUpdateV4.ts +287 -865
  62. package/src/api/device/DeviceUpdateBootloader.ts +6 -125
  63. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +1 -72
  64. package/src/api/firmware/updateBootloader.ts +4 -19
  65. package/src/api/firmware/uploadFirmware.ts +22 -140
  66. package/src/api/helpers/protocolV2FileWrite.ts +54 -4
  67. package/src/data-manager/DataManager.ts +54 -59
  68. package/src/data-manager/connectSettings.ts +0 -11
  69. package/src/device/Device.ts +1 -6
  70. package/src/index.ts +0 -5
  71. package/src/inject.ts +2 -22
  72. package/src/lowLevelInject.ts +1 -5
  73. package/src/protocols/protocol-v2/resources.ts +5 -1
  74. package/src/topLevelInject.ts +1 -5
  75. package/src/types/api/checkAllFirmwareRelease.ts +0 -4
  76. package/src/types/api/deviceUpdateBootloader.ts +0 -6
  77. package/src/types/api/export.ts +0 -18
  78. package/src/types/api/firmwareUpdate.ts +0 -75
  79. package/src/types/api/index.ts +0 -14
  80. package/src/types/settings.ts +2 -14
  81. package/src/utils/deviceFeaturesCompat.ts +0 -6
  82. package/__tests__/device-initialize-timeout.test.ts +0 -56
  83. package/__tests__/firmware-update/check-all-firmware-release.test.ts +0 -175
  84. package/__tests__/firmware-update/device-update-bootloader.test.ts +0 -87
  85. package/__tests__/firmware-update/firmware-artifact-source.test.ts +0 -119
  86. package/__tests__/firmware-update/firmware-host-binding.test.ts +0 -70
  87. package/__tests__/firmware-update/firmware-preparation-error.test.ts +0 -27
  88. package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +0 -200
  89. package/__tests__/firmware-update/firmware-update-capabilities.test.ts +0 -13
  90. package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +0 -394
  91. package/__tests__/firmware-update/firmware-update-plan.test.ts +0 -593
  92. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +0 -231
  93. package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +0 -63
  94. package/__tests__/firmware-update/firmware-upload-source.test.ts +0 -70
  95. package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -25
  96. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +0 -1
  97. package/dist/api/firmware/FirmwareHostBinding.d.ts +0 -6
  98. package/dist/api/firmware/FirmwareHostBinding.d.ts.map +0 -1
  99. package/dist/api/firmware/FirmwarePreparationError.d.ts +0 -3
  100. package/dist/api/firmware/FirmwarePreparationError.d.ts.map +0 -1
  101. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +0 -3
  102. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +0 -1
  103. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -25
  104. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +0 -1
  105. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +0 -32
  106. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +0 -1
  107. package/dist/types/api/firmwareUpdateCapabilities.d.ts +0 -9
  108. package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +0 -1
  109. package/dist/types/api/firmwareUpdatePlan.d.ts +0 -28
  110. package/dist/types/api/firmwareUpdatePlan.d.ts.map +0 -1
  111. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +0 -42
  112. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +0 -1
  113. package/src/api/firmware/FirmwareArtifactSource.ts +0 -278
  114. package/src/api/firmware/FirmwareHostBinding.ts +0 -100
  115. package/src/api/firmware/FirmwarePreparationError.ts +0 -12
  116. package/src/api/firmware/FirmwareUpdateCapabilities.ts +0 -9
  117. package/src/api/firmware/FirmwareUpdatePlan.ts +0 -772
  118. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +0 -449
  119. package/src/types/api/firmwareUpdateCapabilities.ts +0 -9
  120. package/src/types/api/firmwareUpdatePlan.ts +0 -38
  121. package/src/types/api/firmwareUpdatePreparedPlan.ts +0 -53
@@ -9,31 +9,18 @@ import {
9
9
  getDeviceBLEFirmwareVersion,
10
10
  getDeviceBootloaderVersion,
11
11
  getDeviceFirmwareVersion,
12
- getDeviceUUID,
13
12
  getLogger,
14
13
  } from '../utils';
15
14
  import { getBinary, getSysResourceBinary } from './firmware/getBinary';
16
- import { normalizeFirmwarePreparationError } from './firmware/FirmwarePreparationError';
17
15
  import { DataManager } from '../data-manager';
18
16
  import { FirmwareUpdateBaseMethod } from './firmware/FirmwareUpdateBaseMethod';
19
17
  import { DevicePool } from '../device/DevicePool';
20
18
  import { DEVICE } from '../events';
21
19
  import { buildProtocolV1FeaturesPayload } from '../deviceProfile';
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';
20
+
21
+ import type { FirmwareUpdateV3Params } from '../types/api/firmwareUpdate';
34
22
  import type { Deferred, EFirmwareType } from '@onekeyfe/hd-shared';
35
23
  import type { TypedResponseMessage } from '../device/DeviceCommands';
36
- import type { FirmwareByteSource } from './firmware/FirmwareArtifactSource';
37
24
 
38
25
  const Log = getLogger(LoggerNames.Method);
39
26
 
@@ -55,8 +42,6 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
55
42
 
56
43
  private isSwitchFirmware = false;
57
44
 
58
- private artifactSources: FirmwareByteSource[] = [];
59
-
60
45
  init() {
61
46
  this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.NOT_INITIALIZE];
62
47
  this.requireDeviceMode = [];
@@ -77,54 +62,8 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
77
62
  { name: 'firmwareType', type: 'string' },
78
63
  { name: 'platform', type: 'string' },
79
64
  ]);
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
- }
125
65
 
126
66
  this.params = {
127
- preparedPlan: payload.preparedPlan,
128
67
  bleBinary: payload.bleBinary,
129
68
  firmwareBinary: payload.firmwareBinary,
130
69
  forcedUpdateRes: payload.forcedUpdateRes,
@@ -135,8 +74,6 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
135
74
  resourceBinary: payload.resourceBinary,
136
75
  firmwareType: payload.firmwareType,
137
76
  platform: payload.platform,
138
- artifactReader: hostBinding?.artifactReader ?? payload.artifactReader,
139
- artifacts: payload.artifacts,
140
77
  };
141
78
  }
142
79
 
@@ -160,53 +97,39 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
160
97
  if (!features) {
161
98
  throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device features not available');
162
99
  }
163
- if (this.params.preparedPlan) {
164
- assertFirmwareUpdatePreparedPlanDeviceIdentity({
165
- preparedPlan: this.params.preparedPlan,
166
- deviceIdentity: getDeviceUUID(features) || undefined,
167
- });
168
- }
169
100
 
170
101
  const deviceFirmwareType = device.getCurrentFirmwareType();
171
102
  const firmwareType = this.params.firmwareType ?? deviceFirmwareType;
172
103
  this.isSwitchFirmware = firmwareType !== deviceFirmwareType;
173
104
 
174
105
  let resourceBinary: ArrayBuffer | null = null;
175
- let resourceEntries: Array<{ entryName: string; source: FirmwareByteSource }> = [];
176
- let fwSources: Array<{ fileName: string; source: FirmwareByteSource }> = [];
177
- let bootloaderSource: FirmwareByteSource | null = null;
106
+ let fwBinaryMap: { fileName: string; binary: ArrayBuffer }[] = [];
107
+ let bootloaderBinary: ArrayBuffer | null = null;
178
108
  try {
179
109
  this.postTipMessage(FirmwareUpdateTipMessage.StartDownloadFirmware);
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);
110
+ resourceBinary = await this.prepareResourceBinary(firmwareType);
111
+ fwBinaryMap = await this.prepareFirmwareAndBleBinary(firmwareType);
112
+ bootloaderBinary = await this.prepareBootloaderBinary(firmwareType);
185
113
  this.postTipMessage(FirmwareUpdateTipMessage.FinishDownloadFirmware);
186
114
  } catch (err) {
187
- await this.closeArtifactSources();
188
- throw normalizeFirmwarePreparationError(err);
115
+ throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateDownloadFailed, err.message ?? err);
189
116
  }
190
117
 
191
- if (!bootloaderSource && fwSources.length === 0) {
192
- await this.closeArtifactSources();
118
+ if (!bootloaderBinary && fwBinaryMap.length === 0) {
193
119
  throw ERRORS.TypedError(
194
120
  HardwareErrorCode.FirmwareUpdateDownloadFailed,
195
121
  'No firmware to update'
196
122
  );
197
123
  }
198
124
 
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
- }
125
+ await this.enterBootloaderMode();
126
+
127
+ const updateResult = await this.executeUpdate({
128
+ resourceBinary,
129
+ fwBinaryMap,
130
+ bootloaderBinary,
131
+ });
132
+ return updateResult;
210
133
  }
211
134
 
212
135
  private validateDeviceAndVersion(deviceType: EDeviceType, bootloaderVersion: string) {
@@ -226,81 +149,12 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
226
149
  }
227
150
  }
228
151
 
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
- }
152
+ private async prepareResourceBinary(firmwareType: EFirmwareType) {
291
153
  if (this.params.resourceBinary) {
292
- return {
293
- resourceBinary: this.params.resourceBinary,
294
- resourceEntries: [],
295
- };
154
+ return this.params.resourceBinary;
296
155
  }
297
156
  const { features } = this.device;
298
- if (!features) {
299
- return {
300
- resourceBinary: null,
301
- resourceEntries: [],
302
- };
303
- }
157
+ if (!features) return null;
304
158
  const resourceUrl = DataManager.getSysResourcesLatestRelease({
305
159
  features,
306
160
  forcedUpdateRes: this.params.forcedUpdateRes,
@@ -308,27 +162,16 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
308
162
  });
309
163
 
310
164
  if (resourceUrl) {
311
- this.assertSdkDownloadAllowed('resource');
312
- return {
313
- resourceBinary: (await getSysResourceBinary(resourceUrl)).binary,
314
- resourceEntries: [],
315
- };
165
+ const resource = (await getSysResourceBinary(resourceUrl)).binary;
166
+ return resource;
316
167
  }
317
168
  Log.warn('No resource url found');
318
- return {
319
- resourceBinary: null,
320
- resourceEntries: [],
321
- };
169
+ return null;
322
170
  }
323
171
 
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
- );
172
+ private async prepareBootloaderBinary(firmwareType: EFirmwareType): Promise<ArrayBuffer | null> {
173
+ if (this.params.bootloaderBinary) {
174
+ return this.params.bootloaderBinary;
332
175
  }
333
176
  const { features } = this.device;
334
177
  if (!features) return null;
@@ -336,35 +179,23 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
336
179
  if (this.params.bootloaderVersion) {
337
180
  const bootResourceUrl = DataManager.getBootloaderResource(features, firmwareType);
338
181
  if (bootResourceUrl) {
339
- this.assertSdkDownloadAllowed('bootloader');
340
182
  const bootBinary = (await getSysResourceBinary(bootResourceUrl)).binary;
341
- return this.openArtifactSource(bootBinary, undefined);
183
+ return bootBinary;
342
184
  }
343
185
  }
344
186
  return null;
345
187
  }
346
188
 
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({
189
+ private async prepareFirmwareAndBleBinary(firmwareType: EFirmwareType) {
190
+ const fwBinaryMap: { fileName: string; binary: ArrayBuffer }[] = [];
191
+ if (this.params.firmwareBinary) {
192
+ fwBinaryMap.push({
361
193
  fileName: 'firmware.bin',
362
- source,
194
+ binary: this.params.firmwareBinary,
363
195
  });
364
196
  } else if (this.params.firmwareVersion) {
365
197
  const { features } = this.device;
366
198
  if (features) {
367
- this.assertSdkDownloadAllowed('firmware');
368
199
  const firmwareBinary = (
369
200
  await getBinary({
370
201
  features,
@@ -374,65 +205,44 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
374
205
  firmwareType,
375
206
  })
376
207
  ).binary;
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({
208
+ fwBinaryMap.push({
385
209
  fileName: 'firmware.bin',
386
- source,
210
+ binary: firmwareBinary,
387
211
  });
388
212
  }
389
213
  }
390
214
 
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({
215
+ if (this.params.bleBinary) {
216
+ fwBinaryMap.push({
400
217
  fileName: 'ble-firmware.bin',
401
- source,
218
+ binary: this.params.bleBinary,
402
219
  });
403
220
  } else if (this.params.bleVersion) {
404
221
  const { features } = this.device;
405
222
  if (features) {
406
- this.assertSdkDownloadAllowed('ble');
407
223
  const bleBinary = await getBinary({
408
224
  features,
409
225
  version: this.params.bleVersion,
410
226
  updateType: 'ble',
411
227
  firmwareType,
412
228
  });
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({
229
+ fwBinaryMap.push({
418
230
  fileName: 'ble-firmware.bin',
419
- source,
231
+ binary: bleBinary.binary,
420
232
  });
421
233
  }
422
234
  }
423
- return fwSources;
235
+ return fwBinaryMap;
424
236
  }
425
237
 
426
238
  private async executeUpdate({
427
239
  resourceBinary,
428
- resourceEntries,
429
- fwSources,
430
- bootloaderSource,
240
+ fwBinaryMap,
241
+ bootloaderBinary,
431
242
  }: {
432
243
  resourceBinary: ArrayBuffer | null;
433
- resourceEntries: Array<{ entryName: string; source: FirmwareByteSource }>;
434
- fwSources: Array<{ fileName: string; source: FirmwareByteSource }>;
435
- bootloaderSource: FirmwareByteSource | null;
244
+ fwBinaryMap: { fileName: string; binary: ArrayBuffer }[];
245
+ bootloaderBinary: ArrayBuffer | null;
436
246
  }) {
437
247
  let totalSize = 0;
438
248
  let processedSize = 0;
@@ -440,14 +250,11 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
440
250
  if (resourceBinary) {
441
251
  totalSize += resourceBinary.byteLength;
442
252
  }
443
- for (const entry of resourceEntries) {
444
- totalSize += entry.source.size;
253
+ for (const fwbinary of fwBinaryMap) {
254
+ totalSize += fwbinary.binary.byteLength;
445
255
  }
446
- for (const firmware of fwSources) {
447
- totalSize += firmware.source.size;
448
- }
449
- if (bootloaderSource) {
450
- totalSize += bootloaderSource.size;
256
+ if (bootloaderBinary) {
257
+ totalSize += bootloaderBinary.byteLength;
451
258
  }
452
259
 
453
260
  this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
@@ -470,18 +277,9 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
470
277
  }
471
278
  }
472
279
 
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,
280
+ if (bootloaderBinary) {
281
+ processedSize = await this.emmcCommonUpdateProcess({
282
+ payload: bootloaderBinary,
485
283
  filePath: `0:boot/bootloader.bin`,
486
284
  processedSize,
487
285
  totalSize,
@@ -490,11 +288,11 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
490
288
 
491
289
  await this.createUpdatesFolderIfNotExists(`0:updates/`);
492
290
 
493
- for (const firmware of fwSources) {
494
- if (firmware) {
495
- processedSize = await this.emmcCommonUpdateProcessFromSource({
496
- source: firmware.source,
497
- filePath: `0:updates/${firmware.fileName}`,
291
+ for (const fwbinary of fwBinaryMap) {
292
+ if (fwbinary) {
293
+ processedSize = await this.emmcCommonUpdateProcess({
294
+ payload: fwbinary.binary,
295
+ filePath: `0:updates/${fwbinary.fileName}`,
498
296
  processedSize,
499
297
  totalSize,
500
298
  });
@@ -750,11 +548,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
750
548
 
751
549
  if (deviceList.length === 1) {
752
550
  this.device.updateFromCache(deviceList[0]);
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
- });
551
+ await this.device.acquire();
758
552
  this.device.commands.disposed = false;
759
553
  this.device.getCommands().mainId = this.device.mainId ?? '';
760
554
  return;