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