@onekeyfe/hd-core 1.2.0-alpha.30 → 1.2.0-alpha.32
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__/check-all-firmware-release-protocol-v2.test.ts +251 -0
- package/__tests__/connectSettings.test.ts +5 -47
- package/__tests__/device-state-mapper.test.ts +10 -1
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +31 -59
- package/__tests__/networkUtils.test.ts +20 -0
- package/__tests__/open-wallet-session.test.ts +19 -5
- package/__tests__/protocol-v2-firmware-targets.test.ts +18 -0
- package/__tests__/protocol-v2.test.ts +58 -240
- package/__tests__/public-device-state-api.test.ts +10 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts +24 -1
- 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 +6 -22
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/PromptWebDeviceAccess.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/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/stellar/StellarSignTransaction.d.ts +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/DeviceStateMapper.d.ts.map +1 -1
- package/dist/index.d.ts +43 -179
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1048 -2606
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.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 +25 -7
- 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 +2 -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/index.d.ts +3 -10
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +9 -3
- package/dist/types/api/openWalletSession.d.ts.map +1 -1
- package/dist/types/device.d.ts +6 -0
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/settings.d.ts +1 -13
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/networkUtils.d.ts +1 -0
- package/dist/utils/networkUtils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/CheckAllFirmwareRelease.ts +368 -50
- package/src/api/FirmwareUpdateV2.ts +120 -298
- package/src/api/FirmwareUpdateV3.ts +56 -258
- package/src/api/FirmwareUpdateV4.ts +328 -765
- package/src/api/OpenWalletSession.ts +12 -8
- package/src/api/PromptWebDeviceAccess.ts +2 -6
- package/src/api/device/DeviceUpdateBootloader.ts +6 -122
- 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/data/messages/messages-protocol-v2.json +4 -0
- package/src/data-manager/DataManager.ts +33 -33
- package/src/data-manager/connectSettings.ts +0 -11
- package/src/device/DeviceStateMapper.ts +6 -0
- package/src/index.ts +0 -5
- package/src/inject.ts +2 -22
- package/src/lowLevelInject.ts +1 -5
- package/src/protocols/protocol-v2/walletSession.ts +2 -1
- package/src/topLevelInject.ts +1 -5
- package/src/types/api/checkAllFirmwareRelease.ts +46 -7
- package/src/types/api/deviceUpdateBootloader.ts +0 -6
- package/src/types/api/export.ts +5 -18
- package/src/types/api/firmwareUpdate.ts +0 -76
- package/src/types/api/index.ts +6 -15
- package/src/types/api/openWalletSession.ts +12 -3
- package/src/types/device.ts +6 -0
- package/src/types/settings.ts +3 -13
- package/src/utils/networkUtils.ts +5 -3
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +0 -174
- 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-preparation-error.test.ts +0 -27
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +0 -13
- package/__tests__/firmware-update/firmware-update-plan.test.ts +0 -593
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +0 -213
- package/__tests__/firmware-update/firmware-upload-source.test.ts +0 -70
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -25
- 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/FirmwarePreparationError.d.ts +0 -3
- package/dist/api/firmware/FirmwarePreparationError.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 -25
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +0 -30
- 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 -28
- 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/FirmwarePreparationError.ts +0 -12
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +0 -9
- package/src/api/firmware/FirmwareUpdatePlan.ts +0 -745
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +0 -392
- package/src/types/api/firmwareUpdateCapabilities.ts +0 -9
- package/src/types/api/firmwareUpdatePlan.ts +0 -38
- package/src/types/api/firmwareUpdatePreparedPlan.ts +0 -53
|
@@ -14,44 +14,18 @@ import { BaseMethod } from './BaseMethod';
|
|
|
14
14
|
import { validateParams } from './helpers/paramsValidator';
|
|
15
15
|
import { DevicePool } from '../device/DevicePool';
|
|
16
16
|
import { getBinary, getInfo, getSysResourceBinary } from './firmware/getBinary';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
updateResources,
|
|
20
|
-
updateResourcesFromSources,
|
|
21
|
-
uploadFirmwareFromSource,
|
|
22
|
-
} from './firmware/uploadFirmware';
|
|
23
|
-
import { LoggerNames, getDeviceUUID, getLogger, wait } from '../utils';
|
|
17
|
+
import { updateResources, uploadFirmware } from './firmware/uploadFirmware';
|
|
18
|
+
import { LoggerNames, getLogger, wait } from '../utils';
|
|
24
19
|
import { FirmwareUpdateTipMessage, createUiMessage } from '../events/ui-request';
|
|
25
20
|
import { DeviceModelToTypes } from '../types';
|
|
26
21
|
import { DataManager } from '../data-manager';
|
|
27
22
|
import { DEVICE } from '../events';
|
|
28
|
-
import { type FirmwareByteSource, openFirmwareByteSource } from './firmware/FirmwareArtifactSource';
|
|
29
|
-
import { resolveFirmwareUpdateHostBinding } from './firmware/FirmwareHostBinding';
|
|
30
|
-
import {
|
|
31
|
-
assertFirmwareUpdatePreparedPlanBinding,
|
|
32
|
-
assertFirmwareUpdatePreparedPlanDeviceIdentity,
|
|
33
|
-
getFirmwareUpdateResourceName,
|
|
34
|
-
} from './firmware/FirmwareUpdatePreparedPlan';
|
|
35
23
|
|
|
36
24
|
import type { Features, KnownDevice } from '../types';
|
|
37
25
|
import type { FirmwareBinary } from './firmware/getBinary';
|
|
38
|
-
import type {
|
|
39
|
-
FirmwareArtifactReader,
|
|
40
|
-
FirmwareArtifactReference,
|
|
41
|
-
} from '../types/api/firmwareUpdate';
|
|
42
|
-
import type { FirmwareUpdatePreparedPlan } from '../types/api/firmwareUpdatePreparedPlan';
|
|
43
26
|
|
|
44
27
|
type Params = {
|
|
45
28
|
binary?: ArrayBuffer;
|
|
46
|
-
artifact?: FirmwareArtifactReference;
|
|
47
|
-
resourceArtifact?: FirmwareArtifactReference;
|
|
48
|
-
resourceEntries?: Array<{
|
|
49
|
-
entryName: string;
|
|
50
|
-
artifact: FirmwareArtifactReference;
|
|
51
|
-
}>;
|
|
52
|
-
artifactReader?: FirmwareArtifactReader;
|
|
53
|
-
preparedPlan?: FirmwareUpdatePreparedPlan;
|
|
54
|
-
platform?: FirmwareUpdatePreparedPlan['platform'];
|
|
55
29
|
version?: number[];
|
|
56
30
|
updateType: 'firmware' | 'ble';
|
|
57
31
|
forcedUpdateRes?: boolean;
|
|
@@ -132,13 +106,6 @@ const normalizeFirmwareBinary = (binary: unknown): FirmwareBinary | undefined =>
|
|
|
132
106
|
return normalized.buffer;
|
|
133
107
|
};
|
|
134
108
|
|
|
135
|
-
const toArrayBuffer = (binary: FirmwareBinary): ArrayBuffer => {
|
|
136
|
-
if (binary instanceof ArrayBuffer) {
|
|
137
|
-
return binary;
|
|
138
|
-
}
|
|
139
|
-
return new Uint8Array(binary.buffer, binary.byteOffset, binary.byteLength).slice().buffer;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
109
|
export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
143
110
|
checkPromise: Deferred<any> | null = null;
|
|
144
111
|
|
|
@@ -185,38 +152,6 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
|
185
152
|
binary: payload.binary,
|
|
186
153
|
};
|
|
187
154
|
}
|
|
188
|
-
|
|
189
|
-
if ('artifact' in payload) {
|
|
190
|
-
const hostBinding = resolveFirmwareUpdateHostBinding(payload.hostBindingGeneration);
|
|
191
|
-
const target = payload.isUpdateBootloader ? 'bootloader' : payload.updateType;
|
|
192
|
-
const resourceBindings = [
|
|
193
|
-
...(payload.resourceArtifact
|
|
194
|
-
? [{ target: 'resource' as const, artifact: payload.resourceArtifact }]
|
|
195
|
-
: []),
|
|
196
|
-
...(payload.resourceEntries ?? []).map(
|
|
197
|
-
(entry: { entryName: string; artifact: FirmwareArtifactReference }) => ({
|
|
198
|
-
target: 'resource' as const,
|
|
199
|
-
entryName: entry.entryName,
|
|
200
|
-
artifact: entry.artifact,
|
|
201
|
-
})
|
|
202
|
-
),
|
|
203
|
-
];
|
|
204
|
-
assertFirmwareUpdatePreparedPlanBinding({
|
|
205
|
-
preparedPlan: payload.preparedPlan,
|
|
206
|
-
executor: 'v2',
|
|
207
|
-
platform: payload.platform,
|
|
208
|
-
scopeTargets: [target, ...(target === 'firmware' ? (['resource'] as const) : [])],
|
|
209
|
-
bindings: [{ target, artifact: payload.artifact }, ...resourceBindings],
|
|
210
|
-
});
|
|
211
|
-
this.params = {
|
|
212
|
-
...this.params,
|
|
213
|
-
preparedPlan: payload.preparedPlan,
|
|
214
|
-
artifact: payload.artifact,
|
|
215
|
-
resourceArtifact: payload.resourceArtifact,
|
|
216
|
-
resourceEntries: payload.resourceEntries,
|
|
217
|
-
artifactReader: hostBinding.artifactReader,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
155
|
}
|
|
221
156
|
|
|
222
157
|
postTipMessage = (message: string) => {
|
|
@@ -406,264 +341,151 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
|
406
341
|
const { features, commands } = device;
|
|
407
342
|
const deviceType = device.getCurrentDeviceType();
|
|
408
343
|
|
|
409
|
-
// Protocol V2 (Pro2) uses DeviceFirmwareUpdate and must not enter this legacy flow.
|
|
410
|
-
if (device.isProtocolV2()) {
|
|
411
|
-
throw ERRORS.TypedError(
|
|
412
|
-
HardwareErrorCode.RuntimeError,
|
|
413
|
-
'Protocol V2 firmware update must use firmwareUpdateV4'
|
|
414
|
-
);
|
|
415
|
-
}
|
|
416
|
-
if (params.preparedPlan) {
|
|
417
|
-
assertFirmwareUpdatePreparedPlanDeviceIdentity({
|
|
418
|
-
preparedPlan: params.preparedPlan,
|
|
419
|
-
deviceIdentity: getDeviceUUID(features) || undefined,
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
|
|
423
344
|
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
424
345
|
const firmwareType = params.firmwareType ?? deviceFirmwareType;
|
|
425
346
|
|
|
426
347
|
this.checkVersionForCopyTouchResource(features, firmwareType);
|
|
427
348
|
|
|
428
|
-
let
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
349
|
+
let preparedBinary: FirmwareBinary | undefined;
|
|
350
|
+
const acquireFirmwareBinary = async (): Promise<FirmwareBinary> => {
|
|
351
|
+
try {
|
|
352
|
+
if (preparedBinary) {
|
|
353
|
+
return preparedBinary;
|
|
354
|
+
}
|
|
435
355
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
const source = await openFirmwareByteSource({
|
|
442
|
-
binary: toArrayBuffer(binary),
|
|
443
|
-
});
|
|
444
|
-
if (!source) {
|
|
445
|
-
throw new Error('firmware binary is empty or invalid');
|
|
446
|
-
}
|
|
447
|
-
preparedSource = source;
|
|
448
|
-
return source;
|
|
356
|
+
if (params.binary !== undefined) {
|
|
357
|
+
preparedBinary = normalizeFirmwareBinary(params.binary);
|
|
358
|
+
if (!preparedBinary) {
|
|
359
|
+
throw new Error('firmware binary is empty or invalid');
|
|
449
360
|
}
|
|
361
|
+
return preparedBinary;
|
|
362
|
+
}
|
|
450
363
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
throw new Error('firmware artifact is not prepared');
|
|
458
|
-
}
|
|
459
|
-
preparedSource = source;
|
|
460
|
-
return source;
|
|
461
|
-
}
|
|
364
|
+
if (!device.features) {
|
|
365
|
+
throw ERRORS.TypedError(
|
|
366
|
+
HardwareErrorCode.RuntimeError,
|
|
367
|
+
'no features found for this device'
|
|
368
|
+
);
|
|
369
|
+
}
|
|
462
370
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
371
|
+
this.postTipMessage('DownloadFirmware');
|
|
372
|
+
const firmware = await getBinary({
|
|
373
|
+
features: device.features,
|
|
374
|
+
version: params.version,
|
|
375
|
+
updateType: params.updateType,
|
|
376
|
+
isUpdateBootloader: params.isUpdateBootloader,
|
|
377
|
+
firmwareType,
|
|
378
|
+
requestOptions: FIRMWARE_DOWNLOAD_REQUEST_OPTIONS,
|
|
379
|
+
});
|
|
380
|
+
preparedBinary = normalizeFirmwareBinary(firmware.binary);
|
|
381
|
+
if (!preparedBinary) {
|
|
382
|
+
throw new Error('downloaded firmware binary is empty or invalid');
|
|
383
|
+
}
|
|
384
|
+
this.postTipMessage('DownloadFirmwareSuccess');
|
|
385
|
+
return preparedBinary;
|
|
386
|
+
} catch (err) {
|
|
387
|
+
throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateDownloadFailed, err.message ?? err);
|
|
388
|
+
}
|
|
389
|
+
};
|
|
469
390
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
'Firmware must be prepared by the external firmware host',
|
|
477
|
-
{
|
|
478
|
-
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
479
|
-
artifactName: 'firmware',
|
|
480
|
-
}
|
|
481
|
-
);
|
|
482
|
-
}
|
|
391
|
+
if (!device.isBootloader() && features) {
|
|
392
|
+
const serialNo = device.getCurrentSerialNo();
|
|
393
|
+
// should go to bootloader mode manually
|
|
394
|
+
if (this.isEnteredManuallyBoot()) {
|
|
395
|
+
return Promise.reject(ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateManuallyEnterBoot));
|
|
396
|
+
}
|
|
483
397
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
398
|
+
// check & upgrade firmware resource
|
|
399
|
+
if (this.isSupportResourceUpdate(params.updateType)) {
|
|
400
|
+
this.postTipMessage('CheckLatestUiResource');
|
|
401
|
+
const resourceUrl = DataManager.getSysResourcesLatestRelease({
|
|
402
|
+
features,
|
|
403
|
+
forcedUpdateRes: params.forcedUpdateRes,
|
|
404
|
+
firmwareType,
|
|
405
|
+
});
|
|
406
|
+
if (resourceUrl) {
|
|
407
|
+
this.postTipMessage('DownloadLatestUiResource');
|
|
408
|
+
const resource = await getSysResourceBinary(resourceUrl);
|
|
409
|
+
this.postTipMessage('DownloadLatestUiResourceSuccess');
|
|
410
|
+
if (resource) {
|
|
411
|
+
await updateResources(
|
|
412
|
+
this.device.getCommands().typedCall.bind(this.device.getCommands()),
|
|
413
|
+
this.postMessage,
|
|
414
|
+
device,
|
|
415
|
+
resource.binary
|
|
416
|
+
);
|
|
502
417
|
}
|
|
503
|
-
preparedSource = source;
|
|
504
|
-
this.postTipMessage('DownloadFirmwareSuccess');
|
|
505
|
-
return source;
|
|
506
|
-
} catch (err) {
|
|
507
|
-
throw normalizeFirmwarePreparationError(err);
|
|
508
418
|
}
|
|
509
|
-
}
|
|
419
|
+
}
|
|
510
420
|
|
|
511
|
-
if
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
421
|
+
// check if the device commands has been disposed
|
|
422
|
+
this.device?.commands?.checkDisposed();
|
|
423
|
+
|
|
424
|
+
// A failed firmware download must leave the device in normal mode.
|
|
425
|
+
await acquireFirmwareBinary();
|
|
426
|
+
|
|
427
|
+
// The request may outlive the current transport command instance.
|
|
428
|
+
this.device?.commands?.checkDisposed();
|
|
429
|
+
|
|
430
|
+
// auto go to bootloader mode
|
|
431
|
+
try {
|
|
432
|
+
this.postTipMessage('AutoRebootToBootloader');
|
|
433
|
+
const bootRes = await commands.typedCall('DeviceBackToBoot', 'Success');
|
|
434
|
+
// @ts-expect-error
|
|
435
|
+
if (bootRes.type === 'CallMethodError') {
|
|
436
|
+
throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure);
|
|
516
437
|
}
|
|
438
|
+
this.postTipMessage('GoToBootloaderSuccess');
|
|
439
|
+
this.checkDeviceToBootloader(this.payload.connectId);
|
|
517
440
|
|
|
518
|
-
//
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
// check & upgrade firmware resource
|
|
522
|
-
if (this.isSupportResourceUpdate(params.updateType)) {
|
|
523
|
-
this.postTipMessage('CheckLatestUiResource');
|
|
524
|
-
const resourceUrl = DataManager.getSysResourcesLatestRelease({
|
|
525
|
-
features,
|
|
526
|
-
forcedUpdateRes: params.forcedUpdateRes,
|
|
527
|
-
firmwareType,
|
|
528
|
-
});
|
|
529
|
-
if (resourceUrl) {
|
|
530
|
-
this.postTipMessage('DownloadLatestUiResource');
|
|
531
|
-
if (params.resourceEntries?.length) {
|
|
532
|
-
const sources: Array<{
|
|
533
|
-
entryName: string;
|
|
534
|
-
source: FirmwareByteSource;
|
|
535
|
-
}> = [];
|
|
536
|
-
try {
|
|
537
|
-
for (const entry of params.resourceEntries) {
|
|
538
|
-
const resourceName = getFirmwareUpdateResourceName(entry.entryName);
|
|
539
|
-
const source = await openFirmwareByteSource({
|
|
540
|
-
artifact: entry.artifact,
|
|
541
|
-
reader: params.artifactReader,
|
|
542
|
-
});
|
|
543
|
-
if (!source) {
|
|
544
|
-
throw new Error('Firmware resource entry is not prepared');
|
|
545
|
-
}
|
|
546
|
-
sources.push({ entryName: resourceName, source });
|
|
547
|
-
}
|
|
548
|
-
await updateResourcesFromSources(
|
|
549
|
-
this.device.getCommands().typedCall.bind(this.device.getCommands()),
|
|
550
|
-
this.postMessage,
|
|
551
|
-
device,
|
|
552
|
-
sources.map(entry => ({
|
|
553
|
-
entryName: entry.entryName,
|
|
554
|
-
source: entry.source,
|
|
555
|
-
}))
|
|
556
|
-
);
|
|
557
|
-
} finally {
|
|
558
|
-
await Promise.all(
|
|
559
|
-
sources.map(entry => entry.source.close().catch(() => undefined))
|
|
560
|
-
);
|
|
561
|
-
}
|
|
562
|
-
this.postTipMessage('DownloadLatestUiResourceSuccess');
|
|
563
|
-
} else {
|
|
564
|
-
let resourceBinary: ArrayBuffer | Buffer;
|
|
565
|
-
if (params.resourceArtifact) {
|
|
566
|
-
throw ERRORS.TypedError(
|
|
567
|
-
HardwareErrorCode.RuntimeError,
|
|
568
|
-
'Firmware resource archive must be materialized into prepared entries',
|
|
569
|
-
{
|
|
570
|
-
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
571
|
-
artifactName: 'resource',
|
|
572
|
-
}
|
|
573
|
-
);
|
|
574
|
-
} else {
|
|
575
|
-
if (
|
|
576
|
-
params.artifactReader ||
|
|
577
|
-
DataManager.getSettings('firmwareManifestMode') === 'external-only'
|
|
578
|
-
) {
|
|
579
|
-
throw ERRORS.TypedError(
|
|
580
|
-
HardwareErrorCode.RuntimeError,
|
|
581
|
-
'Firmware resource must be prepared by the external firmware host',
|
|
582
|
-
{
|
|
583
|
-
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
584
|
-
artifactName: 'resource',
|
|
585
|
-
}
|
|
586
|
-
);
|
|
587
|
-
}
|
|
588
|
-
resourceBinary = (await getSysResourceBinary(resourceUrl)).binary;
|
|
589
|
-
}
|
|
590
|
-
this.postTipMessage('DownloadLatestUiResourceSuccess');
|
|
591
|
-
await updateResources(
|
|
592
|
-
this.device.getCommands().typedCall.bind(this.device.getCommands()),
|
|
593
|
-
this.postMessage,
|
|
594
|
-
device,
|
|
595
|
-
resourceBinary
|
|
596
|
-
);
|
|
597
|
-
}
|
|
598
|
-
}
|
|
441
|
+
// force clean classic device cache so that the device can initialize again
|
|
442
|
+
if (DeviceModelToTypes.model_classic.includes(deviceType)) {
|
|
443
|
+
DevicePool.clearDeviceCache(serialNo);
|
|
599
444
|
}
|
|
445
|
+
delete DevicePool.devicesCache[''];
|
|
446
|
+
await this.checkPromise?.promise;
|
|
447
|
+
this.checkPromise = null;
|
|
600
448
|
|
|
601
|
-
//
|
|
449
|
+
// check if the device commands has been disposed
|
|
602
450
|
this.device?.commands?.checkDisposed();
|
|
603
451
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
this.postTipMessage('GoToBootloaderSuccess');
|
|
613
|
-
this.checkDeviceToBootloader(this.payload.connectId);
|
|
614
|
-
|
|
615
|
-
// force clean classic device cache so that the device can initialize again
|
|
616
|
-
if (DeviceModelToTypes.model_classic.includes(deviceType)) {
|
|
617
|
-
DevicePool.clearDeviceCache(serialNo);
|
|
618
|
-
}
|
|
619
|
-
delete DevicePool.devicesCache[''];
|
|
620
|
-
await this.checkPromise?.promise;
|
|
621
|
-
this.checkPromise = null;
|
|
622
|
-
|
|
623
|
-
// check if the device commands has been disposed
|
|
624
|
-
this.device?.commands?.checkDisposed();
|
|
625
|
-
|
|
626
|
-
/**
|
|
627
|
-
* Touch 1 with bootloader v2.5.0 issue: BLE chip need more time for looking up name, here change the delay time to 3000ms after rebooting.
|
|
628
|
-
*/
|
|
629
|
-
const isTouch = DeviceModelToTypes.model_touch.includes(deviceType);
|
|
630
|
-
await wait(isTouch ? 3000 : 1500);
|
|
631
|
-
} catch (e) {
|
|
632
|
-
if (e instanceof HardwareError) {
|
|
633
|
-
return Promise.reject(e);
|
|
634
|
-
}
|
|
635
|
-
console.log('auto go to bootloader mode failed: ', e);
|
|
636
|
-
return Promise.reject(
|
|
637
|
-
ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure)
|
|
638
|
-
);
|
|
452
|
+
/**
|
|
453
|
+
* Touch 1 with bootloader v2.5.0 issue: BLE chip need more time for looking up name, here change the delay time to 3000ms after rebooting.
|
|
454
|
+
*/
|
|
455
|
+
const isTouch = DeviceModelToTypes.model_touch.includes(deviceType);
|
|
456
|
+
await wait(isTouch ? 3000 : 1500);
|
|
457
|
+
} catch (e) {
|
|
458
|
+
if (e instanceof HardwareError) {
|
|
459
|
+
return Promise.reject(e);
|
|
639
460
|
}
|
|
461
|
+
console.log('auto go to bootloader mode failed: ', e);
|
|
462
|
+
return Promise.reject(
|
|
463
|
+
ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure)
|
|
464
|
+
);
|
|
640
465
|
}
|
|
466
|
+
}
|
|
641
467
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
// check if the device commands has been disposed
|
|
646
|
-
this.device?.commands?.checkDisposed();
|
|
468
|
+
// Devices already in bootloader mode still acquire through the same helper.
|
|
469
|
+
const binary = await acquireFirmwareBinary();
|
|
647
470
|
|
|
648
|
-
|
|
471
|
+
// check if the device commands has been disposed
|
|
472
|
+
this.device?.commands?.checkDisposed();
|
|
649
473
|
|
|
650
|
-
|
|
651
|
-
params.updateType,
|
|
652
|
-
this.device.getCommands().typedCall.bind(this.device.getCommands()),
|
|
653
|
-
this.postMessage,
|
|
654
|
-
device,
|
|
655
|
-
source,
|
|
656
|
-
true,
|
|
657
|
-
params.isUpdateBootloader
|
|
658
|
-
);
|
|
474
|
+
await this.device.acquire();
|
|
659
475
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
476
|
+
const response = await uploadFirmware(
|
|
477
|
+
params.updateType,
|
|
478
|
+
this.device.getCommands().typedCall.bind(this.device.getCommands()),
|
|
479
|
+
this.postMessage,
|
|
480
|
+
device,
|
|
481
|
+
{ payload: binary, rebootOnSuccess: true },
|
|
482
|
+
params.isUpdateBootloader
|
|
483
|
+
);
|
|
663
484
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
await preparedSource?.close().catch(() => undefined);
|
|
485
|
+
if (this.connectId) {
|
|
486
|
+
DevicePool.clearDeviceCache(this.connectId);
|
|
667
487
|
}
|
|
488
|
+
|
|
489
|
+
return response;
|
|
668
490
|
}
|
|
669
491
|
}
|