@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
|
@@ -21,13 +21,6 @@ const requiredString = (value: unknown, name: string) => {
|
|
|
21
21
|
return value.trim();
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
const optionalBoolean = (value: unknown, name: string) => {
|
|
25
|
-
if (value !== undefined && typeof value !== 'boolean') {
|
|
26
|
-
throw invalidParameter(`Parameter [${name}] must be a boolean.`);
|
|
27
|
-
}
|
|
28
|
-
return value;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
24
|
const wasResumed = (session: unknown) =>
|
|
32
25
|
!!session &&
|
|
33
26
|
typeof session === 'object' &&
|
|
@@ -53,72 +46,31 @@ const requireHiddenWalletResponse = (session: {
|
|
|
53
46
|
};
|
|
54
47
|
};
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
passphraseState: string;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const normalizeParams = (payload: Record<string, unknown>): NormalizedOpenWalletSessionParams => {
|
|
64
|
-
if (payload.mode !== undefined) {
|
|
65
|
-
if (
|
|
66
|
-
payload.mode !== 'standard' &&
|
|
67
|
-
payload.mode !== 'select-hidden' &&
|
|
68
|
-
payload.mode !== 'resume-hidden'
|
|
69
|
-
) {
|
|
70
|
-
throw invalidParameter(
|
|
71
|
-
'Parameter [mode] must be one of standard, select-hidden, or resume-hidden.'
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
if (payload.useEmptyPassphrase !== undefined || payload.initSession !== undefined) {
|
|
75
|
-
throw invalidParameter(
|
|
76
|
-
'Parameters [useEmptyPassphrase] and [initSession] cannot be used with [mode].'
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
if (payload.mode === 'standard' || payload.mode === 'select-hidden') {
|
|
80
|
-
if (payload.deviceId !== undefined || payload.passphraseState !== undefined) {
|
|
81
|
-
throw invalidParameter(
|
|
82
|
-
'Parameters [deviceId] and [passphraseState] are only allowed with mode [resume-hidden].'
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
return { mode: payload.mode };
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
mode: 'resume-hidden',
|
|
89
|
-
deviceId: requiredString(payload.deviceId, 'deviceId'),
|
|
90
|
-
passphraseState: requiredString(payload.passphraseState, 'passphraseState'),
|
|
91
|
-
};
|
|
49
|
+
const normalizeParams = (payload: Record<string, unknown>): OpenWalletSessionParams => {
|
|
50
|
+
if (payload.mode === undefined) {
|
|
51
|
+
throw invalidParameter('Parameter [mode] is required.');
|
|
92
52
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
53
|
+
if (
|
|
54
|
+
payload.mode !== 'standard' &&
|
|
55
|
+
payload.mode !== 'select-hidden' &&
|
|
56
|
+
payload.mode !== 'resume-hidden'
|
|
57
|
+
) {
|
|
58
|
+
throw invalidParameter(
|
|
59
|
+
'Parameter [mode] must be one of standard, select-hidden, or resume-hidden.'
|
|
60
|
+
);
|
|
98
61
|
}
|
|
99
|
-
if (initSession
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
payload.passphraseState === undefined
|
|
104
|
-
? undefined
|
|
105
|
-
: requiredString(payload.passphraseState, 'passphraseState');
|
|
106
|
-
return {
|
|
107
|
-
mode: 'select-hidden',
|
|
108
|
-
...(passphraseState
|
|
109
|
-
? {
|
|
110
|
-
legacySessionToClear: {
|
|
111
|
-
deviceId,
|
|
112
|
-
passphraseState,
|
|
113
|
-
},
|
|
114
|
-
}
|
|
115
|
-
: {}),
|
|
116
|
-
};
|
|
62
|
+
if (payload.useEmptyPassphrase !== undefined || payload.initSession !== undefined) {
|
|
63
|
+
throw invalidParameter(
|
|
64
|
+
'Legacy parameters [useEmptyPassphrase] and [initSession] are not supported by openWalletSession.'
|
|
65
|
+
);
|
|
117
66
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
67
|
+
if (payload.mode === 'standard' || payload.mode === 'select-hidden') {
|
|
68
|
+
if (payload.deviceId !== undefined || payload.passphraseState !== undefined) {
|
|
69
|
+
throw invalidParameter(
|
|
70
|
+
'Parameters [deviceId] and [passphraseState] are only allowed with mode [resume-hidden].'
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return { mode: payload.mode };
|
|
122
74
|
}
|
|
123
75
|
return {
|
|
124
76
|
mode: 'resume-hidden',
|
|
@@ -127,7 +79,7 @@ const normalizeParams = (payload: Record<string, unknown>): NormalizedOpenWallet
|
|
|
127
79
|
};
|
|
128
80
|
};
|
|
129
81
|
|
|
130
|
-
export default class OpenWalletSession extends BaseMethod<
|
|
82
|
+
export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParams> {
|
|
131
83
|
init() {
|
|
132
84
|
this.useDevicePassphraseState = false;
|
|
133
85
|
this.skipForceUpdateCheck = true;
|
|
@@ -139,33 +91,18 @@ export default class OpenWalletSession extends BaseMethod<NormalizedOpenWalletSe
|
|
|
139
91
|
const isProtocolV2 = this.device.isProtocolV2();
|
|
140
92
|
const state = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
141
93
|
let currentDeviceId = state.identity.deviceId;
|
|
142
|
-
const { legacySessionToClear } = this.params;
|
|
143
94
|
const requireDeviceId = () => {
|
|
144
95
|
if (!currentDeviceId) {
|
|
145
96
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
146
97
|
}
|
|
147
98
|
return currentDeviceId;
|
|
148
99
|
};
|
|
149
|
-
const clearLegacySession = () => {
|
|
150
|
-
const deviceId = requireDeviceId();
|
|
151
|
-
if (
|
|
152
|
-
legacySessionToClear &&
|
|
153
|
-
(!legacySessionToClear.deviceId || legacySessionToClear.deviceId === deviceId)
|
|
154
|
-
) {
|
|
155
|
-
deviceWalletSessionStore.delete(deviceId, legacySessionToClear.passphraseState);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
100
|
const refreshProtocolV2DeviceId = async () => {
|
|
159
101
|
const refreshedState = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
160
102
|
currentDeviceId = refreshedState.identity.deviceId;
|
|
161
|
-
clearLegacySession();
|
|
162
103
|
return requireDeviceId();
|
|
163
104
|
};
|
|
164
105
|
|
|
165
|
-
if (!isProtocolV2) {
|
|
166
|
-
clearLegacySession();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
106
|
const protocol = isProtocolV2 ? 'V2' : 'V1';
|
|
170
107
|
|
|
171
108
|
if (this.params.mode === 'standard') {
|
|
@@ -5,23 +5,15 @@ import { UI_REQUEST } from '../../constants/ui-request';
|
|
|
5
5
|
import { FirmwareUpdateTipMessage } from '../../events/ui-request';
|
|
6
6
|
import { FirmwareUpdateBaseMethod } from '../firmware/FirmwareUpdateBaseMethod';
|
|
7
7
|
import { getSysResourceBinary } from '../firmware/getBinary';
|
|
8
|
-
import { updateBootloader
|
|
8
|
+
import { updateBootloader } from '../firmware/uploadFirmware';
|
|
9
9
|
import { DeviceModelToTypes } from '../../types';
|
|
10
10
|
import { DataManager } from '../../data-manager';
|
|
11
|
-
import { checkBootloaderLength
|
|
12
|
-
import { openFirmwareByteSource } from '../firmware/FirmwareArtifactSource';
|
|
13
|
-
import { resolveFirmwareUpdateHostBinding } from '../firmware/FirmwareHostBinding';
|
|
14
|
-
import {
|
|
15
|
-
assertFirmwareUpdatePreparedPlanBinding,
|
|
16
|
-
assertFirmwareUpdatePreparedPlanDeviceIdentity,
|
|
17
|
-
} from '../firmware/FirmwareUpdatePreparedPlan';
|
|
18
|
-
import { getDeviceUUID } from '../../utils';
|
|
11
|
+
import { checkBootloaderLength } from '../firmware/updateBootloader';
|
|
19
12
|
|
|
20
13
|
import type { DeviceUpdateBootloaderParams } from '../../types/api/deviceUpdateBootloader';
|
|
21
14
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
22
15
|
import type { Device } from '../../device/Device';
|
|
23
16
|
import type { Features } from '../../types';
|
|
24
|
-
import type { FirmwareByteSource } from '../firmware/FirmwareArtifactSource';
|
|
25
17
|
|
|
26
18
|
export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any> {
|
|
27
19
|
init() {
|
|
@@ -51,68 +43,17 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
51
43
|
return true;
|
|
52
44
|
}
|
|
53
45
|
|
|
54
|
-
async updateBootloaderWithEmmcFileWriteFromSource(_device: Device, source: FirmwareByteSource) {
|
|
55
|
-
const filePath = '0:boot/bootloader.bin';
|
|
56
|
-
|
|
57
|
-
this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
|
|
58
|
-
await this.emmcCommonUpdateProcessFromSource({
|
|
59
|
-
source,
|
|
60
|
-
filePath,
|
|
61
|
-
});
|
|
62
|
-
this.postTipMessage(FirmwareUpdateTipMessage.ConfirmOnDevice);
|
|
63
|
-
await this.reboot(RebootType.Normal);
|
|
64
|
-
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloaderSuccess);
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
46
|
async updateTouchBootloader({
|
|
69
47
|
device,
|
|
70
48
|
features,
|
|
71
49
|
firmwareType,
|
|
72
|
-
binary: preparedBinary,
|
|
73
|
-
source: preparedSource,
|
|
74
50
|
}: {
|
|
75
51
|
device: Device;
|
|
76
52
|
features?: Features;
|
|
77
53
|
firmwareType: EFirmwareType;
|
|
78
|
-
binary?: ArrayBuffer;
|
|
79
|
-
source?: FirmwareByteSource;
|
|
80
54
|
}) {
|
|
81
|
-
|
|
82
|
-
if (!(await checkBootloaderSourceLength(preparedSource))) {
|
|
83
|
-
throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
|
|
84
|
-
}
|
|
85
|
-
if (features && device.isBootloader()) {
|
|
86
|
-
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
|
|
87
|
-
const result = await this.updateBootloaderWithEmmcFileWriteFromSource(
|
|
88
|
-
device,
|
|
89
|
-
preparedSource
|
|
90
|
-
);
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
if (features && !device.isBootloader()) {
|
|
94
|
-
await updateBootloaderFromSource(
|
|
95
|
-
this.device.getCommands().typedCall.bind(this.device.getCommands()),
|
|
96
|
-
this.postMessage,
|
|
97
|
-
device,
|
|
98
|
-
preparedSource
|
|
99
|
-
);
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let binary = preparedBinary;
|
|
55
|
+
let { binary } = this.payload;
|
|
105
56
|
if (!binary) {
|
|
106
|
-
if (DataManager.getSettings('firmwareManifestMode') === 'external-only') {
|
|
107
|
-
throw ERRORS.TypedError(
|
|
108
|
-
HardwareErrorCode.RuntimeError,
|
|
109
|
-
'Bootloader must be prepared by the external firmware host',
|
|
110
|
-
{
|
|
111
|
-
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
112
|
-
artifactName: 'bootloader',
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
57
|
this.postTipMessage(FirmwareUpdateTipMessage.CheckLatestUiResource);
|
|
117
58
|
const resourceUrl = features
|
|
118
59
|
? DataManager.getBootloaderResource(features, firmwareType)
|
|
@@ -127,7 +68,7 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
127
68
|
}
|
|
128
69
|
}
|
|
129
70
|
|
|
130
|
-
if (!
|
|
71
|
+
if (!checkBootloaderLength(binary)) {
|
|
131
72
|
throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
|
|
132
73
|
}
|
|
133
74
|
|
|
@@ -135,8 +76,7 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
135
76
|
if (features && device.isBootloader()) {
|
|
136
77
|
// Use emmcFileWrite + reboot logic for bootloader mode
|
|
137
78
|
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
|
|
138
|
-
|
|
139
|
-
return result;
|
|
79
|
+
return this.updateBootloaderWithEmmcFileWrite(device, binary);
|
|
140
80
|
}
|
|
141
81
|
|
|
142
82
|
if (features && !device.isBootloader()) {
|
|
@@ -156,69 +96,13 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
156
96
|
const { features } = device;
|
|
157
97
|
|
|
158
98
|
const payload = this.payload as DeviceUpdateBootloaderParams;
|
|
159
|
-
const hostBinding = payload.artifact
|
|
160
|
-
? resolveFirmwareUpdateHostBinding(payload.hostBindingGeneration)
|
|
161
|
-
: undefined;
|
|
162
|
-
const executionParams = {
|
|
163
|
-
...payload,
|
|
164
|
-
artifactReader: hostBinding?.artifactReader ?? payload.artifactReader,
|
|
165
|
-
};
|
|
166
|
-
if (payload.artifact) {
|
|
167
|
-
assertFirmwareUpdatePreparedPlanDeviceIdentity({
|
|
168
|
-
preparedPlan: payload.preparedPlan,
|
|
169
|
-
deviceIdentity: getDeviceUUID(features) || undefined,
|
|
170
|
-
});
|
|
171
|
-
assertFirmwareUpdatePreparedPlanBinding({
|
|
172
|
-
preparedPlan: payload.preparedPlan,
|
|
173
|
-
executor: 'v2',
|
|
174
|
-
scopeTargets: ['bootloader'],
|
|
175
|
-
bindings: [
|
|
176
|
-
{
|
|
177
|
-
target: 'bootloader',
|
|
178
|
-
artifact: payload.artifact,
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
});
|
|
182
|
-
const source = await openFirmwareByteSource({
|
|
183
|
-
artifact: payload.artifact,
|
|
184
|
-
reader: executionParams.artifactReader,
|
|
185
|
-
});
|
|
186
|
-
if (!source) {
|
|
187
|
-
throw ERRORS.TypedError(
|
|
188
|
-
HardwareErrorCode.RuntimeError,
|
|
189
|
-
'Bootloader artifact is not prepared'
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
try {
|
|
193
|
-
const deviceType = device.getCurrentDeviceType();
|
|
194
|
-
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
195
|
-
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
196
|
-
if (DeviceModelToTypes.model_touch.includes(deviceType)) {
|
|
197
|
-
return await this.updateTouchBootloader({
|
|
198
|
-
device,
|
|
199
|
-
features,
|
|
200
|
-
firmwareType,
|
|
201
|
-
source,
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
return true;
|
|
205
|
-
} finally {
|
|
206
|
-
await source.close();
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
99
|
|
|
210
|
-
const { binary } = payload;
|
|
211
100
|
const deviceType = device.getCurrentDeviceType();
|
|
212
101
|
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
213
102
|
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
214
103
|
|
|
215
104
|
if (DeviceModelToTypes.model_touch.includes(deviceType)) {
|
|
216
|
-
return this.updateTouchBootloader({
|
|
217
|
-
device,
|
|
218
|
-
features,
|
|
219
|
-
firmwareType,
|
|
220
|
-
binary,
|
|
221
|
-
});
|
|
105
|
+
return this.updateTouchBootloader({ device, features, firmwareType });
|
|
222
106
|
}
|
|
223
107
|
|
|
224
108
|
return Promise.resolve(true);
|
|
@@ -14,7 +14,6 @@ import { DataManager } from '../../data-manager';
|
|
|
14
14
|
import { BaseMethod } from '../BaseMethod';
|
|
15
15
|
import { DEVICE } from '../../events';
|
|
16
16
|
import { createFirmwareProgressThrottle } from './progressThrottle';
|
|
17
|
-
import { writeFirmwareByteSource } from './FirmwareArtifactSource';
|
|
18
17
|
|
|
19
18
|
import type {
|
|
20
19
|
IFirmwareUpdateProgressType,
|
|
@@ -25,7 +24,6 @@ import type { RebootType } from '@onekeyfe/hd-transport';
|
|
|
25
24
|
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
26
25
|
import type { KnownDevice } from '../../types';
|
|
27
26
|
import type { TypedResponseMessage } from '../../device/DeviceCommands';
|
|
28
|
-
import type { FirmwareByteSource } from './FirmwareArtifactSource';
|
|
29
27
|
|
|
30
28
|
const Log = getLogger(LoggerNames.Method);
|
|
31
29
|
const SESSION_ERROR = 'session not found';
|
|
@@ -389,54 +387,6 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
389
387
|
return totalSize !== undefined ? (processedSize ?? 0) + payload.byteLength : 0;
|
|
390
388
|
}
|
|
391
389
|
|
|
392
|
-
async emmcCommonUpdateProcessFromSource({
|
|
393
|
-
source,
|
|
394
|
-
filePath,
|
|
395
|
-
processedSize,
|
|
396
|
-
totalSize,
|
|
397
|
-
}: {
|
|
398
|
-
source: FirmwareByteSource;
|
|
399
|
-
filePath: string;
|
|
400
|
-
processedSize?: number;
|
|
401
|
-
totalSize?: number;
|
|
402
|
-
}) {
|
|
403
|
-
if (!filePath.startsWith('0:')) {
|
|
404
|
-
throw new Error('filePath must start with 0:');
|
|
405
|
-
}
|
|
406
|
-
const env = DataManager.getSettings('env');
|
|
407
|
-
const chunkSize = 1024 * (DataManager.isBleConnect(env) ? 16 : 128);
|
|
408
|
-
|
|
409
|
-
await writeFirmwareByteSource({
|
|
410
|
-
source,
|
|
411
|
-
chunkSize,
|
|
412
|
-
write: async ({ data, sourceOffset, length, first }) => {
|
|
413
|
-
const progress =
|
|
414
|
-
totalSize !== undefined && processedSize !== undefined
|
|
415
|
-
? Math.min(Math.ceil(((processedSize + sourceOffset + length) / totalSize) * 100), 99)
|
|
416
|
-
: Math.min(Math.ceil(((sourceOffset + length) / source.size) * 100), 99);
|
|
417
|
-
const writeRes = await this.emmcFileWriteWithRetry(
|
|
418
|
-
filePath,
|
|
419
|
-
length,
|
|
420
|
-
sourceOffset,
|
|
421
|
-
data,
|
|
422
|
-
first,
|
|
423
|
-
progress
|
|
424
|
-
);
|
|
425
|
-
if (!writeRes) {
|
|
426
|
-
throw ERRORS.TypedError(
|
|
427
|
-
HardwareErrorCode.EmmcFileWriteFirmwareError,
|
|
428
|
-
'transfer data error'
|
|
429
|
-
);
|
|
430
|
-
}
|
|
431
|
-
const processedBytes = Number(writeRes.message.processed_byte);
|
|
432
|
-
this.postProgressMessage(progress, 'transferData');
|
|
433
|
-
return Number.isFinite(processedBytes) ? processedBytes : length;
|
|
434
|
-
},
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
return totalSize !== undefined ? (processedSize ?? 0) + source.size : 0;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
390
|
async emmcFileWriteWithRetry(
|
|
441
391
|
filePath: string,
|
|
442
392
|
chunkLength: number,
|
|
@@ -8,7 +8,6 @@ import { shouldUpdateBootloaderForClassicAndMini } from './bootloaderHelper';
|
|
|
8
8
|
|
|
9
9
|
import type { Features } from '../../types';
|
|
10
10
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
11
|
-
import type { FirmwareByteSource } from './FirmwareArtifactSource';
|
|
12
11
|
|
|
13
12
|
export function checkNeedUpdateBootForTouch(features: Features, firmwareType: EFirmwareType) {
|
|
14
13
|
const deviceType = getDeviceType(features);
|
|
@@ -63,7 +62,8 @@ export function checkNeedUpdateBootForClassicAndMini({
|
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
const INIT_DATA_CHUNK_SIZE = 16 * 1024;
|
|
66
|
-
|
|
65
|
+
export function checkBootloaderLength(data: ArrayBuffer) {
|
|
66
|
+
const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE, data.byteLength)));
|
|
67
67
|
const buffer = ByteBuffer.wrap(chunk, undefined, undefined, true);
|
|
68
68
|
buffer.LE();
|
|
69
69
|
// byte 'O', 'K', 'T', 'B'
|
|
@@ -77,21 +77,6 @@ const readBootloaderLength = (chunk: Uint8Array) => {
|
|
|
77
77
|
buffer.readUint32();
|
|
78
78
|
// codelen
|
|
79
79
|
const codelen = buffer.readUint32();
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export function checkBootloaderLength(data: ArrayBuffer) {
|
|
84
|
-
if (data.byteLength < 16) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE, data.byteLength)));
|
|
88
|
-
return readBootloaderLength(chunk) === data.byteLength;
|
|
80
|
+
const bootloaderLength = hdrlen + codelen;
|
|
81
|
+
return bootloaderLength === data.byteLength;
|
|
89
82
|
}
|
|
90
|
-
|
|
91
|
-
export const checkBootloaderSourceLength = async (source: FirmwareByteSource) => {
|
|
92
|
-
if (source.size < 16) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
const chunk = new Uint8Array(await source.readAt(0, Math.min(INIT_DATA_CHUNK_SIZE, source.size)));
|
|
96
|
-
return readBootloaderLength(chunk) === source.size;
|
|
97
|
-
};
|