@onekeyfe/hd-core 1.2.0-alpha.22 → 1.2.0-alpha.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/DeviceCommands.test.ts +43 -8
- package/__tests__/connectSettings.test.ts +5 -47
- package/__tests__/device-lifecycle-events.test.ts +59 -0
- package/__tests__/device-settings.test.ts +1 -1
- package/__tests__/device-wallet-session-store.test.ts +41 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +30 -39
- package/__tests__/logBlockEvent.test.ts +17 -0
- package/__tests__/open-wallet-session.test.ts +233 -111
- package/__tests__/protocol-v2-ping.test.ts +28 -0
- package/__tests__/protocol-v2.test.ts +513 -313
- package/__tests__/public-pro2-api-boundary.test.ts +22 -0
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +0 -11
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +3 -7
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +5 -21
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts +1 -8
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +1 -5
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +0 -7
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +0 -7
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +0 -2
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +1 -9
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/Ping.d.ts +2 -0
- package/dist/api/protocol-v2/Ping.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +0 -1
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +3 -2
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/events/device.d.ts +1 -0
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +1 -0
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +98 -278
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +876 -2647
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +2 -3
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +12 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +0 -3
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +0 -6
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +1 -4
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +0 -69
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +4 -10
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +0 -12
- package/dist/types/api/openWalletSession.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +4 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/settings.d.ts +0 -13
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/CheckAllFirmwareRelease.ts +3 -16
- package/src/api/FirmwareUpdateV2.ts +119 -284
- package/src/api/FirmwareUpdateV3.ts +55 -248
- package/src/api/FirmwareUpdateV4.ts +293 -751
- package/src/api/GetPassphraseState.ts +11 -5
- package/src/api/OpenWalletSession.ts +23 -86
- package/src/api/device/DeviceUpdateBootloader.ts +6 -114
- package/src/api/device/DeviceWipe.ts +2 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +0 -50
- package/src/api/firmware/updateBootloader.ts +4 -19
- package/src/api/firmware/uploadFirmware.ts +22 -140
- package/src/api/index.ts +1 -0
- package/src/api/protocol-v2/Ping.ts +32 -1
- package/src/core/index.ts +40 -7
- package/src/data/messages/messages-protocol-v2.json +49 -56
- package/src/data-manager/DataManager.ts +33 -33
- package/src/data-manager/connectSettings.ts +0 -11
- package/src/device/Device.ts +29 -8
- package/src/device/DeviceCommands.ts +43 -151
- package/src/events/device.ts +1 -0
- package/src/events/logBlockEvent.ts +1 -15
- package/src/events/ui-request.ts +1 -0
- package/src/index.ts +0 -5
- package/src/inject.ts +4 -22
- package/src/lowLevelInject.ts +1 -5
- package/src/protocols/protocol-v2/deviceSession.ts +1 -1
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +0 -1
- package/src/protocols/protocol-v2/unlockRetry.ts +20 -3
- package/src/protocols/protocol-v2/walletSession.ts +57 -18
- package/src/topLevelInject.ts +1 -5
- package/src/types/api/checkAllFirmwareRelease.ts +0 -3
- package/src/types/api/deviceUpdateBootloader.ts +0 -6
- package/src/types/api/export.ts +0 -18
- package/src/types/api/firmwareUpdate.ts +0 -76
- package/src/types/api/getPassphraseState.ts +4 -3
- package/src/types/api/index.ts +3 -14
- package/src/types/api/openWalletSession.ts +0 -19
- package/src/types/api/protocolV2.ts +10 -0
- package/src/types/settings.ts +0 -13
- package/src/utils/deviceInfoUtils.ts +2 -3
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +0 -119
- package/__tests__/firmware-update/firmware-host-binding.test.ts +0 -70
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +0 -13
- package/__tests__/firmware-update/firmware-update-plan.test.ts +0 -326
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +0 -200
- package/__tests__/firmware-update/firmware-upload-source.test.ts +0 -70
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -26
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareHostBinding.d.ts +0 -6
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +0 -3
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -24
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +0 -25
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +0 -9
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdatePlan.d.ts +0 -27
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +0 -42
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +0 -1
- package/src/api/firmware/FirmwareArtifactSource.ts +0 -278
- package/src/api/firmware/FirmwareHostBinding.ts +0 -100
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +0 -9
- package/src/api/firmware/FirmwareUpdatePlan.ts +0 -621
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +0 -378
- package/src/types/api/firmwareUpdateCapabilities.ts +0 -9
- package/src/types/api/firmwareUpdatePlan.ts +0 -36
- package/src/types/api/firmwareUpdatePreparedPlan.ts +0 -53
|
@@ -14,42 +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
|
-
updateResources,
|
|
19
|
-
updateResourcesFromSources,
|
|
20
|
-
uploadFirmwareFromSource,
|
|
21
|
-
} from './firmware/uploadFirmware';
|
|
17
|
+
import { updateResources, uploadFirmware } from './firmware/uploadFirmware';
|
|
22
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
|
-
assertFirmwareUpdatePreparedPlanBinding,
|
|
31
|
-
getFirmwareUpdateResourceName,
|
|
32
|
-
} from './firmware/FirmwareUpdatePreparedPlan';
|
|
33
23
|
|
|
34
24
|
import type { Features, KnownDevice } from '../types';
|
|
35
25
|
import type { FirmwareBinary } from './firmware/getBinary';
|
|
36
|
-
import type {
|
|
37
|
-
FirmwareArtifactReader,
|
|
38
|
-
FirmwareArtifactReference,
|
|
39
|
-
} from '../types/api/firmwareUpdate';
|
|
40
|
-
import type { FirmwareUpdatePreparedPlan } from '../types/api/firmwareUpdatePreparedPlan';
|
|
41
26
|
|
|
42
27
|
type Params = {
|
|
43
28
|
binary?: ArrayBuffer;
|
|
44
|
-
artifact?: FirmwareArtifactReference;
|
|
45
|
-
resourceArtifact?: FirmwareArtifactReference;
|
|
46
|
-
resourceEntries?: Array<{
|
|
47
|
-
entryName: string;
|
|
48
|
-
artifact: FirmwareArtifactReference;
|
|
49
|
-
}>;
|
|
50
|
-
artifactReader?: FirmwareArtifactReader;
|
|
51
|
-
preparedPlan?: FirmwareUpdatePreparedPlan;
|
|
52
|
-
platform?: FirmwareUpdatePreparedPlan['platform'];
|
|
53
29
|
version?: number[];
|
|
54
30
|
updateType: 'firmware' | 'ble';
|
|
55
31
|
forcedUpdateRes?: boolean;
|
|
@@ -130,13 +106,6 @@ const normalizeFirmwareBinary = (binary: unknown): FirmwareBinary | undefined =>
|
|
|
130
106
|
return normalized.buffer;
|
|
131
107
|
};
|
|
132
108
|
|
|
133
|
-
const toArrayBuffer = (binary: FirmwareBinary): ArrayBuffer => {
|
|
134
|
-
if (binary instanceof ArrayBuffer) {
|
|
135
|
-
return binary;
|
|
136
|
-
}
|
|
137
|
-
return new Uint8Array(binary.buffer, binary.byteOffset, binary.byteLength).slice().buffer;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
109
|
export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
141
110
|
checkPromise: Deferred<any> | null = null;
|
|
142
111
|
|
|
@@ -183,38 +152,6 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
|
183
152
|
binary: payload.binary,
|
|
184
153
|
};
|
|
185
154
|
}
|
|
186
|
-
|
|
187
|
-
if ('artifact' in payload) {
|
|
188
|
-
const hostBinding = resolveFirmwareUpdateHostBinding(payload.hostBindingGeneration);
|
|
189
|
-
const target = payload.isUpdateBootloader ? 'bootloader' : payload.updateType;
|
|
190
|
-
const resourceBindings = [
|
|
191
|
-
...(payload.resourceArtifact
|
|
192
|
-
? [{ target: 'resource' as const, artifact: payload.resourceArtifact }]
|
|
193
|
-
: []),
|
|
194
|
-
...(payload.resourceEntries ?? []).map(
|
|
195
|
-
(entry: { entryName: string; artifact: FirmwareArtifactReference }) => ({
|
|
196
|
-
target: 'resource' as const,
|
|
197
|
-
entryName: entry.entryName,
|
|
198
|
-
artifact: entry.artifact,
|
|
199
|
-
})
|
|
200
|
-
),
|
|
201
|
-
];
|
|
202
|
-
assertFirmwareUpdatePreparedPlanBinding({
|
|
203
|
-
preparedPlan: payload.preparedPlan,
|
|
204
|
-
executor: 'v2',
|
|
205
|
-
platform: payload.platform,
|
|
206
|
-
scopeTargets: [target, ...(target === 'firmware' ? (['resource'] as const) : [])],
|
|
207
|
-
bindings: [{ target, artifact: payload.artifact }, ...resourceBindings],
|
|
208
|
-
});
|
|
209
|
-
this.params = {
|
|
210
|
-
...this.params,
|
|
211
|
-
preparedPlan: payload.preparedPlan,
|
|
212
|
-
artifact: payload.artifact,
|
|
213
|
-
resourceArtifact: payload.resourceArtifact,
|
|
214
|
-
resourceEntries: payload.resourceEntries,
|
|
215
|
-
artifactReader: hostBinding.artifactReader,
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
155
|
}
|
|
219
156
|
|
|
220
157
|
postTipMessage = (message: string) => {
|
|
@@ -417,248 +354,146 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
|
417
354
|
|
|
418
355
|
this.checkVersionForCopyTouchResource(features, firmwareType);
|
|
419
356
|
|
|
420
|
-
let
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
}
|
|
357
|
+
let preparedBinary: FirmwareBinary | undefined;
|
|
358
|
+
const acquireFirmwareBinary = async (): Promise<FirmwareBinary> => {
|
|
359
|
+
try {
|
|
360
|
+
if (preparedBinary) {
|
|
361
|
+
return preparedBinary;
|
|
362
|
+
}
|
|
427
363
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
const source = await openFirmwareByteSource({
|
|
434
|
-
binary: toArrayBuffer(binary),
|
|
435
|
-
});
|
|
436
|
-
if (!source) {
|
|
437
|
-
throw new Error('firmware binary is empty or invalid');
|
|
438
|
-
}
|
|
439
|
-
preparedSource = source;
|
|
440
|
-
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');
|
|
441
368
|
}
|
|
369
|
+
return preparedBinary;
|
|
370
|
+
}
|
|
442
371
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
throw new Error('firmware artifact is not prepared');
|
|
450
|
-
}
|
|
451
|
-
preparedSource = source;
|
|
452
|
-
return source;
|
|
453
|
-
}
|
|
372
|
+
if (!device.features) {
|
|
373
|
+
throw ERRORS.TypedError(
|
|
374
|
+
HardwareErrorCode.RuntimeError,
|
|
375
|
+
'no features found for this device'
|
|
376
|
+
);
|
|
377
|
+
}
|
|
454
378
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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
|
+
};
|
|
461
398
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
'Firmware must be prepared by the external firmware host',
|
|
469
|
-
{
|
|
470
|
-
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
471
|
-
artifactName: 'firmware',
|
|
472
|
-
}
|
|
473
|
-
);
|
|
474
|
-
}
|
|
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
|
+
}
|
|
475
405
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
+
);
|
|
494
425
|
}
|
|
495
|
-
preparedSource = source;
|
|
496
|
-
this.postTipMessage('DownloadFirmwareSuccess');
|
|
497
|
-
return source;
|
|
498
|
-
} catch (err) {
|
|
499
|
-
throw ERRORS.TypedError(
|
|
500
|
-
HardwareErrorCode.FirmwareUpdateDownloadFailed,
|
|
501
|
-
err.message ?? err
|
|
502
|
-
);
|
|
503
426
|
}
|
|
504
|
-
}
|
|
427
|
+
}
|
|
428
|
+
|
|
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();
|
|
505
437
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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);
|
|
511
445
|
}
|
|
446
|
+
this.postTipMessage('GoToBootloaderSuccess');
|
|
447
|
+
this.checkDeviceToBootloader(this.payload.connectId);
|
|
512
448
|
|
|
513
|
-
//
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
// check & upgrade firmware resource
|
|
517
|
-
if (this.isSupportResourceUpdate(params.updateType)) {
|
|
518
|
-
this.postTipMessage('CheckLatestUiResource');
|
|
519
|
-
const resourceUrl = DataManager.getSysResourcesLatestRelease({
|
|
520
|
-
features,
|
|
521
|
-
forcedUpdateRes: params.forcedUpdateRes,
|
|
522
|
-
firmwareType,
|
|
523
|
-
});
|
|
524
|
-
if (resourceUrl) {
|
|
525
|
-
this.postTipMessage('DownloadLatestUiResource');
|
|
526
|
-
if (params.resourceEntries?.length) {
|
|
527
|
-
const sources: Array<{
|
|
528
|
-
entryName: string;
|
|
529
|
-
source: FirmwareByteSource;
|
|
530
|
-
}> = [];
|
|
531
|
-
try {
|
|
532
|
-
for (const entry of params.resourceEntries) {
|
|
533
|
-
const resourceName = getFirmwareUpdateResourceName(entry.entryName);
|
|
534
|
-
const source = await openFirmwareByteSource({
|
|
535
|
-
artifact: entry.artifact,
|
|
536
|
-
reader: params.artifactReader,
|
|
537
|
-
});
|
|
538
|
-
if (!source) {
|
|
539
|
-
throw new Error('Firmware resource entry is not prepared');
|
|
540
|
-
}
|
|
541
|
-
sources.push({ entryName: resourceName, source });
|
|
542
|
-
}
|
|
543
|
-
await updateResourcesFromSources(
|
|
544
|
-
this.device.getCommands().typedCall.bind(this.device.getCommands()),
|
|
545
|
-
this.postMessage,
|
|
546
|
-
device,
|
|
547
|
-
sources.map(entry => ({
|
|
548
|
-
entryName: entry.entryName,
|
|
549
|
-
source: entry.source,
|
|
550
|
-
}))
|
|
551
|
-
);
|
|
552
|
-
} finally {
|
|
553
|
-
await Promise.all(
|
|
554
|
-
sources.map(entry => entry.source.close().catch(() => undefined))
|
|
555
|
-
);
|
|
556
|
-
}
|
|
557
|
-
this.postTipMessage('DownloadLatestUiResourceSuccess');
|
|
558
|
-
} else {
|
|
559
|
-
let resourceBinary: ArrayBuffer | Buffer;
|
|
560
|
-
if (params.resourceArtifact) {
|
|
561
|
-
throw ERRORS.TypedError(
|
|
562
|
-
HardwareErrorCode.RuntimeError,
|
|
563
|
-
'Firmware resource archive must be materialized into prepared entries',
|
|
564
|
-
{
|
|
565
|
-
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
566
|
-
artifactName: 'resource',
|
|
567
|
-
}
|
|
568
|
-
);
|
|
569
|
-
} else {
|
|
570
|
-
if (
|
|
571
|
-
params.artifactReader ||
|
|
572
|
-
DataManager.getSettings('firmwareManifestMode') === 'external-only'
|
|
573
|
-
) {
|
|
574
|
-
throw ERRORS.TypedError(
|
|
575
|
-
HardwareErrorCode.RuntimeError,
|
|
576
|
-
'Firmware resource must be prepared by the external firmware host',
|
|
577
|
-
{
|
|
578
|
-
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
579
|
-
artifactName: 'resource',
|
|
580
|
-
}
|
|
581
|
-
);
|
|
582
|
-
}
|
|
583
|
-
resourceBinary = (await getSysResourceBinary(resourceUrl)).binary;
|
|
584
|
-
}
|
|
585
|
-
this.postTipMessage('DownloadLatestUiResourceSuccess');
|
|
586
|
-
await updateResources(
|
|
587
|
-
this.device.getCommands().typedCall.bind(this.device.getCommands()),
|
|
588
|
-
this.postMessage,
|
|
589
|
-
device,
|
|
590
|
-
resourceBinary
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
449
|
+
// force clean classic device cache so that the device can initialize again
|
|
450
|
+
if (DeviceModelToTypes.model_classic.includes(deviceType)) {
|
|
451
|
+
DevicePool.clearDeviceCache(serialNo);
|
|
594
452
|
}
|
|
453
|
+
delete DevicePool.devicesCache[''];
|
|
454
|
+
await this.checkPromise?.promise;
|
|
455
|
+
this.checkPromise = null;
|
|
595
456
|
|
|
596
|
-
//
|
|
457
|
+
// check if the device commands has been disposed
|
|
597
458
|
this.device?.commands?.checkDisposed();
|
|
598
459
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
this.postTipMessage('GoToBootloaderSuccess');
|
|
608
|
-
this.checkDeviceToBootloader(this.payload.connectId);
|
|
609
|
-
|
|
610
|
-
// force clean classic device cache so that the device can initialize again
|
|
611
|
-
if (DeviceModelToTypes.model_classic.includes(deviceType)) {
|
|
612
|
-
DevicePool.clearDeviceCache(serialNo);
|
|
613
|
-
}
|
|
614
|
-
delete DevicePool.devicesCache[''];
|
|
615
|
-
await this.checkPromise?.promise;
|
|
616
|
-
this.checkPromise = null;
|
|
617
|
-
|
|
618
|
-
// check if the device commands has been disposed
|
|
619
|
-
this.device?.commands?.checkDisposed();
|
|
620
|
-
|
|
621
|
-
/**
|
|
622
|
-
* 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.
|
|
623
|
-
*/
|
|
624
|
-
const isTouch = DeviceModelToTypes.model_touch.includes(deviceType);
|
|
625
|
-
await wait(isTouch ? 3000 : 1500);
|
|
626
|
-
} catch (e) {
|
|
627
|
-
if (e instanceof HardwareError) {
|
|
628
|
-
return Promise.reject(e);
|
|
629
|
-
}
|
|
630
|
-
console.log('auto go to bootloader mode failed: ', e);
|
|
631
|
-
return Promise.reject(
|
|
632
|
-
ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure)
|
|
633
|
-
);
|
|
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);
|
|
634
468
|
}
|
|
469
|
+
console.log('auto go to bootloader mode failed: ', e);
|
|
470
|
+
return Promise.reject(
|
|
471
|
+
ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure)
|
|
472
|
+
);
|
|
635
473
|
}
|
|
474
|
+
}
|
|
636
475
|
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
// check if the device commands has been disposed
|
|
641
|
-
this.device?.commands?.checkDisposed();
|
|
476
|
+
// Devices already in bootloader mode still acquire through the same helper.
|
|
477
|
+
const binary = await acquireFirmwareBinary();
|
|
642
478
|
|
|
643
|
-
|
|
479
|
+
// check if the device commands has been disposed
|
|
480
|
+
this.device?.commands?.checkDisposed();
|
|
644
481
|
|
|
645
|
-
|
|
646
|
-
params.updateType,
|
|
647
|
-
this.device.getCommands().typedCall.bind(this.device.getCommands()),
|
|
648
|
-
this.postMessage,
|
|
649
|
-
device,
|
|
650
|
-
source,
|
|
651
|
-
true,
|
|
652
|
-
params.isUpdateBootloader
|
|
653
|
-
);
|
|
482
|
+
await this.device.acquire();
|
|
654
483
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
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
|
+
);
|
|
658
492
|
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
await preparedSource?.close().catch(() => undefined);
|
|
493
|
+
if (this.connectId) {
|
|
494
|
+
DevicePool.clearDeviceCache(this.connectId);
|
|
662
495
|
}
|
|
496
|
+
|
|
497
|
+
return response;
|
|
663
498
|
}
|
|
664
499
|
}
|