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