@nordicsemiconductor/pc-nrfconnect-shared 60.0.0-pre1 → 60.0.0-pre2
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/dist/bootstrap.css +8951 -0
- package/dist/index.css +1451 -0
- package/dist/index.js +122119 -0
- package/{src/Logo/nordic-logo-blue-icon-only.png → dist/nordic-logo-blue-icon-only-H7BABN6D.png} +0 -0
- package/{src/Logo/nordic-logo-gray-icon-only.png → dist/nordic-logo-gray-icon-only-GATOTR3L.png} +0 -0
- package/package.json +12 -3
- package/typings/generated/src/Device/deviceInfo/deviceInfo.d.ts +1 -2
- package/.github/ISSUE_TEMPLATE/custom.md +0 -10
- package/.husky/pre-push +0 -3
- package/.renovaterc.json +0 -10
- package/Changelog.md +0 -2973
- package/azure-pipelines.yml +0 -34
- package/config/eslintrc.js +0 -190
- package/config/jest.config.js +0 -41
- package/config/prettier.config.js +0 -13
- package/config/tsconfig.json +0 -15
- package/fw/bootloader/graviton_bootloader_v1.0.1-[nRF5_SDK_15.0.1-1.alpha_f76d012].zip +0 -0
- package/jest.config.js +0 -7
- package/main/index.ts +0 -32
- package/mocks/deviceLibMock.ts +0 -21
- package/mocks/electronMock.ts +0 -15
- package/mocks/electronStoreMock.ts +0 -19
- package/mocks/emptyMock.ts +0 -7
- package/mocks/fileMock.ts +0 -13
- package/mocks/gaMock.ts +0 -9
- package/mocks/mockTests.test.ts +0 -15
- package/mocks/packageJsonMock.ts +0 -10
- package/mocks/remoteMock.ts +0 -17
- package/scripts/esbuild-bootstrap.js +0 -15
- package/scripts/esbuild-renderer.js +0 -131
- package/scripts/installHusky.ts +0 -17
- package/scripts/prepare-shared-release.ts +0 -122
- package/scripts/release-shared.test.ts +0 -132
- package/scripts/release-shared.ts +0 -207
- package/src/About/About.tsx +0 -25
- package/src/About/AboutButton.tsx +0 -28
- package/src/About/ApplicationCard.tsx +0 -83
- package/src/About/DeviceCard.tsx +0 -74
- package/src/About/DocumentationCard.tsx +0 -18
- package/src/About/DocumentationSection.tsx +0 -24
- package/src/About/Section.tsx +0 -21
- package/src/About/ShortcutButton.tsx +0 -41
- package/src/About/SupportCard.tsx +0 -97
- package/src/About/about.scss +0 -40
- package/src/About/documentationSlice.ts +0 -41
- package/src/About/section.scss +0 -15
- package/src/About/shortcutSlice.ts +0 -52
- package/src/Alert/Alert.module.scss +0 -29
- package/src/Alert/Alert.tsx +0 -37
- package/src/App/App.test.tsx +0 -47
- package/src/App/App.tsx +0 -227
- package/src/App/ConnectedToStore.tsx +0 -19
- package/src/App/VisibilityBar.tsx +0 -103
- package/src/App/app.scss +0 -83
- package/src/App/appLayout.ts +0 -95
- package/src/App/shared.scss +0 -49
- package/src/App/visibility-bar.scss +0 -55
- package/src/Button/Button.tsx +0 -66
- package/src/Button/button.module.scss +0 -154
- package/src/Card/Card.tsx +0 -26
- package/src/Card/card.module.scss +0 -28
- package/src/Device/BrokenDeviceDialog/BrokenDeviceDialog.tsx +0 -58
- package/src/Device/BrokenDeviceDialog/broken-device-dialog.scss +0 -18
- package/src/Device/BrokenDeviceDialog/brokenDeviceDialogSlice.tsx +0 -48
- package/src/Device/DeviceSelector/BasicDeviceInfo.tsx +0 -115
- package/src/Device/DeviceSelector/DeviceIcon.tsx +0 -27
- package/src/Device/DeviceSelector/DeviceList/AnimatedList.tsx +0 -62
- package/src/Device/DeviceSelector/DeviceList/BrokenDevice.tsx +0 -34
- package/src/Device/DeviceSelector/DeviceList/Device.tsx +0 -84
- package/src/Device/DeviceSelector/DeviceList/DeviceList.tsx +0 -113
- package/src/Device/DeviceSelector/DeviceList/EditDeviceButtons.tsx +0 -28
- package/src/Device/DeviceSelector/DeviceList/MoreDeviceInfo.tsx +0 -65
- package/src/Device/DeviceSelector/DeviceList/RenameDevice.tsx +0 -22
- package/src/Device/DeviceSelector/DeviceList/broken-device.scss +0 -32
- package/src/Device/DeviceSelector/DeviceList/device-list.scss +0 -64
- package/src/Device/DeviceSelector/DeviceList/device.scss +0 -28
- package/src/Device/DeviceSelector/DeviceList/edit-device-buttons.scss +0 -31
- package/src/Device/DeviceSelector/DeviceList/more-device-info.scss +0 -33
- package/src/Device/DeviceSelector/DeviceList/rename-device.scss +0 -13
- package/src/Device/DeviceSelector/DeviceSelector.test.tsx +0 -342
- package/src/Device/DeviceSelector/DeviceSelector.tsx +0 -173
- package/src/Device/DeviceSelector/Favorite.tsx +0 -49
- package/src/Device/DeviceSelector/SelectDevice.tsx +0 -36
- package/src/Device/DeviceSelector/SelectedDevice.tsx +0 -65
- package/src/Device/DeviceSelector/arrow-down.svg +0 -1
- package/src/Device/DeviceSelector/basic-device-info.scss +0 -62
- package/src/Device/DeviceSelector/device-icon.scss +0 -27
- package/src/Device/DeviceSelector/favorite.scss +0 -17
- package/src/Device/DeviceSelector/select-device.scss +0 -38
- package/src/Device/DeviceSelector/selected-device.scss +0 -57
- package/src/Device/DeviceSetup/DeviceSetupView.tsx +0 -102
- package/src/Device/deviceAutoSelectSlice.ts +0 -144
- package/src/Device/deviceInfo/deviceInfo.ts +0 -254
- package/src/Device/deviceInfo/nRF51-Series-logo.svg +0 -1
- package/src/Device/deviceInfo/nRF52-Series-logo.svg +0 -1
- package/src/Device/deviceInfo/nRF53-Series-logo.svg +0 -1
- package/src/Device/deviceInfo/nRF70-Series_no-background_RGB.svg +0 -36
- package/src/Device/deviceInfo/nRF91-Series-logo.svg +0 -1
- package/src/Device/deviceInfo/ppk-logo.svg +0 -1
- package/src/Device/deviceInfo/unknown-logo.svg +0 -30
- package/src/Device/deviceInfo/unknown-nordic-logo.svg +0 -25
- package/src/Device/deviceLibWrapper.test.ts +0 -97
- package/src/Device/deviceLibWrapper.ts +0 -133
- package/src/Device/deviceLister.test.ts +0 -89
- package/src/Device/deviceLister.ts +0 -396
- package/src/Device/deviceSetup.ts +0 -264
- package/src/Device/deviceSetupSlice.ts +0 -94
- package/src/Device/deviceSlice.ts +0 -248
- package/src/Device/dfu-cc.ts +0 -162
- package/src/Device/initPacket.ts +0 -402
- package/src/Device/jprogOperations.ts +0 -206
- package/src/Device/sdfuOperations.ts +0 -601
- package/src/Dialog/Dialog.test.tsx +0 -134
- package/src/Dialog/Dialog.tsx +0 -236
- package/src/Dialog/dialog.scss +0 -60
- package/src/Dropdown/Dropdown.module.scss +0 -83
- package/src/Dropdown/Dropdown.test.tsx +0 -62
- package/src/Dropdown/Dropdown.tsx +0 -106
- package/src/ErrorBoundary/ErrorBoundary.test.tsx +0 -105
- package/src/ErrorBoundary/ErrorBoundary.tsx +0 -186
- package/src/ErrorBoundary/bug.svg +0 -1
- package/src/ErrorBoundary/error-boundary.scss +0 -102
- package/src/ErrorDialog/ErrorDialog.test.tsx +0 -70
- package/src/ErrorDialog/ErrorDialog.tsx +0 -94
- package/src/ErrorDialog/error.scss +0 -14
- package/src/ErrorDialog/errorDialogSlice.test.ts +0 -64
- package/src/ErrorDialog/errorDialogSlice.ts +0 -80
- package/src/FactoryReset/FactoryResetButton.test.tsx +0 -46
- package/src/FactoryReset/FactoryResetButton.tsx +0 -81
- package/src/InlineInput/InlineInput.tsx +0 -170
- package/src/InlineInput/NumberInlineInput.tsx +0 -107
- package/src/InlineInput/inline-input.scss +0 -38
- package/src/InlineInput/number-inline-input.scss +0 -15
- package/src/Log/LogEntry.tsx +0 -62
- package/src/Log/LogViewer.tsx +0 -54
- package/src/Log/log-entry.scss +0 -30
- package/src/Log/log-viewer.scss +0 -24
- package/src/Log/logSlice.ts +0 -73
- package/src/Log/syncLogToStore.ts +0 -36
- package/src/Logo/Logo.tsx +0 -48
- package/src/Logo/logo.scss +0 -11
- package/src/Main/Main.tsx +0 -13
- package/src/Main/main.scss +0 -13
- package/src/MasonryLayout/MasonryLayout.tsx +0 -234
- package/src/MasonryLayout/masonryLayout.module.scss +0 -46
- package/src/NavBar/NavBar.tsx +0 -22
- package/src/NavBar/NavMenu.test.tsx +0 -41
- package/src/NavBar/NavMenu.tsx +0 -53
- package/src/NavBar/NavMenuItem.tsx +0 -41
- package/src/NavBar/nav-bar.scss +0 -26
- package/src/NavBar/nav-menu-item.scss +0 -34
- package/src/OpenApp/openApp.ts +0 -18
- package/src/Panes/FeedbackPane.tsx +0 -149
- package/src/PseudoButton/PseudoButton.tsx +0 -56
- package/src/PseudoButton/pseudo-button.scss +0 -11
- package/src/SerialPort/ConflictingSettingsDialog.tsx +0 -242
- package/src/SerialPort/SerialPort.test.ts +0 -54
- package/src/SerialPort/SerialPort.ts +0 -202
- package/src/Shortcuts/Shortcut-item.scss +0 -33
- package/src/Shortcuts/Shortcut-modal.scss +0 -20
- package/src/Shortcuts/ShortcutItem.tsx +0 -48
- package/src/Shortcuts/ShortcutModal.tsx +0 -67
- package/src/SidePanel/Group.tsx +0 -106
- package/src/SidePanel/SidePanel.tsx +0 -19
- package/src/SidePanel/group.scss +0 -42
- package/src/SidePanel/sidepanel.scss +0 -20
- package/src/Slider/Bar.tsx +0 -24
- package/src/Slider/Factor.test.ts +0 -48
- package/src/Slider/Handle.tsx +0 -121
- package/src/Slider/Slider.test.tsx +0 -25
- package/src/Slider/Slider.tsx +0 -91
- package/src/Slider/Ticks.tsx +0 -54
- package/src/Slider/__snapshots__/Slider.test.tsx.snap +0 -50
- package/src/Slider/bar.scss +0 -24
- package/src/Slider/factor.ts +0 -24
- package/src/Slider/handle.scss +0 -32
- package/src/Slider/percentage.ts +0 -67
- package/src/Slider/range.ts +0 -92
- package/src/Slider/slider.scss +0 -14
- package/src/Slider/ticks.scss +0 -28
- package/src/Slider/variables.scss +0 -16
- package/src/StartStopButton/StartStopButton.tsx +0 -60
- package/src/StartStopButton/play-circle.svg +0 -1
- package/src/StartStopButton/start-stop-button.scss +0 -47
- package/src/StartStopButton/stop-circle.svg +0 -1
- package/src/StateSelector/StateSelector.tsx +0 -64
- package/src/StateSelector/state-selector.scss +0 -38
- package/src/Stepper/Stepper.tsx +0 -139
- package/src/Stepper/stepper.scss +0 -127
- package/src/Toggle/Toggle.tsx +0 -120
- package/src/Toggle/toggle.scss +0 -109
- package/src/bootstrap.scss +0 -14
- package/src/index.ts +0 -146
- package/src/logging/appTransport.test.ts +0 -78
- package/src/logging/appTransport.ts +0 -41
- package/src/logging/describeError.test.ts +0 -38
- package/src/logging/describeError.ts +0 -56
- package/src/logging/index.ts +0 -103
- package/src/logging/logBuffer.test.ts +0 -41
- package/src/logging/logBuffer.ts +0 -24
- package/src/logging/sendInitialLogMessages.ts +0 -64
- package/src/store.ts +0 -60
- package/src/svg.d.ts +0 -15
- package/src/utils/AppTypes.ts +0 -60
- package/src/utils/appDirs.ts +0 -78
- package/src/utils/bleChannels.ts +0 -16
- package/src/utils/classNames.test.ts +0 -29
- package/src/utils/classNames.ts +0 -25
- package/src/utils/colors.scss +0 -46
- package/src/utils/colors.ts +0 -38
- package/src/utils/describeVersion.ts +0 -21
- package/src/utils/environment.ts +0 -6
- package/src/utils/logLibVersions.ts +0 -103
- package/src/utils/open.ts +0 -46
- package/src/utils/packageJson.ts +0 -60
- package/src/utils/persistentStore.ts +0 -144
- package/src/utils/systemReport.ts +0 -160
- package/src/utils/truncateMiddle.test.ts +0 -21
- package/src/utils/truncateMiddle.ts +0 -20
- package/src/utils/usageData.ts +0 -189
- package/src/utils/useHotKey.ts +0 -62
- package/src/utils/useStopwatch.test.tsx +0 -311
- package/src/utils/useStopwatch.ts +0 -140
- package/src/variables.scss +0 -820
- package/styles.scss +0 -88
- package/test/dispatchTo.ts +0 -23
- package/test/index.ts +0 -7
- package/test/jestResolver.js +0 -28
- package/test/setupTests.ts +0 -27
- package/test/testUtil.ts +0 -20
- package/test/testrenderer.tsx +0 -39
- /package/{src/Logo/nordic-logo-white-icon-only.png → dist/nordic-logo-white-icon-only-XIZBW537.png} +0 -0
|
@@ -1,601 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2015 Nordic Semiconductor ASA
|
|
3
|
-
*
|
|
4
|
-
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import nrfDeviceLib from '@nordicsemiconductor/nrf-device-lib-js';
|
|
8
|
-
import AdmZip from 'adm-zip';
|
|
9
|
-
import { createHash } from 'crypto';
|
|
10
|
-
import fs from 'fs';
|
|
11
|
-
import MemoryMap from 'nrf-intel-hex';
|
|
12
|
-
|
|
13
|
-
import logger from '../logging';
|
|
14
|
-
import { AppDispatch } from '../store';
|
|
15
|
-
import { getAppFile } from '../utils/appDirs';
|
|
16
|
-
import { setWaitForDevice } from './deviceAutoSelectSlice';
|
|
17
|
-
import { getDeviceLibContext } from './deviceLibWrapper';
|
|
18
|
-
import { DeviceSetup, DfuEntry } from './deviceSetup';
|
|
19
|
-
import { openDeviceSetupDialog } from './deviceSetupSlice';
|
|
20
|
-
import { Device } from './deviceSlice';
|
|
21
|
-
import {
|
|
22
|
-
createInitPacketBuffer,
|
|
23
|
-
defaultInitPacket,
|
|
24
|
-
DfuImage,
|
|
25
|
-
FwType,
|
|
26
|
-
HashType,
|
|
27
|
-
InitPacket,
|
|
28
|
-
} from './initPacket';
|
|
29
|
-
|
|
30
|
-
const NORDIC_DFU_PRODUCT_ID = 0x521f;
|
|
31
|
-
const NORDIC_VENDOR_ID = 0x1915;
|
|
32
|
-
const DEFAULT_DEVICE_WAIT_TIME = 10000;
|
|
33
|
-
|
|
34
|
-
const LATEST_BOOTLOADER =
|
|
35
|
-
'fw/graviton_bootloader_v1.0.1-[nRF5_SDK_15.0.1-1.alpha_f76d012].zip';
|
|
36
|
-
const LATEST_BOOTLOADER_VERSION = 3; // check with nrfutil pkg display ...
|
|
37
|
-
|
|
38
|
-
export const isDeviceInDFUBootloader = (device: Device) => {
|
|
39
|
-
if (!device) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
if (device.usb) {
|
|
43
|
-
const { descriptor: d } = device.usb.device;
|
|
44
|
-
return (
|
|
45
|
-
d.idVendor === NORDIC_VENDOR_ID &&
|
|
46
|
-
d.idProduct === NORDIC_DFU_PRODUCT_ID
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
if (device.serialport) {
|
|
50
|
-
const { vendorId, productId } = device.serialport;
|
|
51
|
-
return vendorId === '1915' && productId?.toUpperCase() === '521F';
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const ensureBootloaderMode = (device: Device) => {
|
|
57
|
-
if (isDeviceInDFUBootloader(device)) {
|
|
58
|
-
logger.debug('Device is in bootloader mode');
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
logger.debug('Device is NOT in bootloader mode');
|
|
62
|
-
return false;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const getBootloaderInformation = async (device: Device) => {
|
|
66
|
-
const info = await nrfDeviceLib.readFwInfo(
|
|
67
|
-
getDeviceLibContext(),
|
|
68
|
-
device.id
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const index = info.imageInfoList.findIndex(
|
|
72
|
-
imageInfo => imageInfo.imageType === 'NRFDL_IMAGE_TYPE_BOOTLOADER'
|
|
73
|
-
);
|
|
74
|
-
if (index !== -1) {
|
|
75
|
-
return {
|
|
76
|
-
bootloaderType: info.bootloaderType,
|
|
77
|
-
version: info.imageInfoList[index].version,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return null;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const updateBootloader =
|
|
85
|
-
(
|
|
86
|
-
device: Device,
|
|
87
|
-
onSuccess: (device: Device) => void,
|
|
88
|
-
onFail: (reason?: unknown) => void,
|
|
89
|
-
onProgress: (progress: number, message?: string) => void
|
|
90
|
-
) =>
|
|
91
|
-
async (dispatch: AppDispatch) => {
|
|
92
|
-
logger.info(`Update Bootloader ${device}`);
|
|
93
|
-
const zip = new AdmZip(getAppFile(LATEST_BOOTLOADER));
|
|
94
|
-
const zipBuffer = zip.toBuffer();
|
|
95
|
-
|
|
96
|
-
logger.debug('Starting Bootloader Update');
|
|
97
|
-
|
|
98
|
-
onProgress(0, 'Updating Bootloader');
|
|
99
|
-
|
|
100
|
-
dispatch(
|
|
101
|
-
setWaitForDevice({
|
|
102
|
-
timeout: DEFAULT_DEVICE_WAIT_TIME,
|
|
103
|
-
when: 'always',
|
|
104
|
-
once: false,
|
|
105
|
-
onSuccess,
|
|
106
|
-
onFail,
|
|
107
|
-
})
|
|
108
|
-
);
|
|
109
|
-
await nrfDeviceLib.firmwareProgram(
|
|
110
|
-
getDeviceLibContext(),
|
|
111
|
-
device.id,
|
|
112
|
-
'NRFDL_FW_BUFFER',
|
|
113
|
-
'NRFDL_FW_SDFU_ZIP',
|
|
114
|
-
zipBuffer,
|
|
115
|
-
err => {
|
|
116
|
-
if (err) {
|
|
117
|
-
logger.error(
|
|
118
|
-
`Failed to write bootloader to the target device: ${
|
|
119
|
-
err.message || err
|
|
120
|
-
}`
|
|
121
|
-
);
|
|
122
|
-
onFail(err.message);
|
|
123
|
-
} else {
|
|
124
|
-
dispatch(
|
|
125
|
-
setWaitForDevice({
|
|
126
|
-
timeout: DEFAULT_DEVICE_WAIT_TIME,
|
|
127
|
-
when: 'always',
|
|
128
|
-
once: true,
|
|
129
|
-
onSuccess,
|
|
130
|
-
onFail,
|
|
131
|
-
})
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
onProgress(100, 'Bootloader updated');
|
|
135
|
-
logger.info(
|
|
136
|
-
'Bootloader has been written to the target device'
|
|
137
|
-
);
|
|
138
|
-
logger.debug('Bootloader DFU completed successfully!');
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
progress => {
|
|
142
|
-
onProgress(
|
|
143
|
-
progress.progressJson.progressPercentage,
|
|
144
|
-
progress.progressJson.message ?? 'Programming bootloader'
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const switchToDeviceMode =
|
|
151
|
-
(
|
|
152
|
-
device: Device,
|
|
153
|
-
mcuState: nrfDeviceLib.MCUState,
|
|
154
|
-
onSuccess: (device: Device) => void,
|
|
155
|
-
onFail: (reason?: unknown) => void
|
|
156
|
-
) =>
|
|
157
|
-
(dispatch: AppDispatch) => {
|
|
158
|
-
nrfDeviceLib
|
|
159
|
-
.deviceControlSetMcuState(
|
|
160
|
-
getDeviceLibContext(),
|
|
161
|
-
device.id,
|
|
162
|
-
mcuState
|
|
163
|
-
)
|
|
164
|
-
.then(() => {
|
|
165
|
-
dispatch(
|
|
166
|
-
setWaitForDevice({
|
|
167
|
-
timeout: 10000,
|
|
168
|
-
when:
|
|
169
|
-
mcuState === 'NRFDL_MCU_STATE_APPLICATION'
|
|
170
|
-
? 'applicationMode'
|
|
171
|
-
: 'dfuBootLoaderMode',
|
|
172
|
-
once: true,
|
|
173
|
-
onSuccess,
|
|
174
|
-
onFail,
|
|
175
|
-
})
|
|
176
|
-
);
|
|
177
|
-
})
|
|
178
|
-
.catch(err => onFail(err));
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
export const switchToBootloaderMode =
|
|
182
|
-
(
|
|
183
|
-
device: Device,
|
|
184
|
-
onSuccess: (device: Device) => void,
|
|
185
|
-
onFail: (reason?: unknown) => void
|
|
186
|
-
) =>
|
|
187
|
-
(dispatch: AppDispatch) => {
|
|
188
|
-
if (!isDeviceInDFUBootloader(device)) {
|
|
189
|
-
dispatch(
|
|
190
|
-
switchToDeviceMode(
|
|
191
|
-
device,
|
|
192
|
-
'NRFDL_MCU_STATE_PROGRAMMING',
|
|
193
|
-
d => {
|
|
194
|
-
if (!isDeviceInDFUBootloader(d))
|
|
195
|
-
onFail(
|
|
196
|
-
new Error('Failed to switch To Bootloader Mode')
|
|
197
|
-
);
|
|
198
|
-
else onSuccess(d);
|
|
199
|
-
},
|
|
200
|
-
onFail
|
|
201
|
-
)
|
|
202
|
-
);
|
|
203
|
-
} else if (onSuccess) {
|
|
204
|
-
onSuccess(device);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
export const switchToApplicationMode =
|
|
209
|
-
(
|
|
210
|
-
device: Device,
|
|
211
|
-
onSuccess: (device: Device) => void,
|
|
212
|
-
onFail: (reason?: unknown) => void
|
|
213
|
-
) =>
|
|
214
|
-
(dispatch: AppDispatch) => {
|
|
215
|
-
dispatch(
|
|
216
|
-
switchToDeviceMode(
|
|
217
|
-
device,
|
|
218
|
-
'NRFDL_MCU_STATE_APPLICATION',
|
|
219
|
-
d => {
|
|
220
|
-
if (isDeviceInDFUBootloader(d))
|
|
221
|
-
onFail(
|
|
222
|
-
new Error('Failed to switch to Application Mode')
|
|
223
|
-
);
|
|
224
|
-
else onSuccess(d);
|
|
225
|
-
},
|
|
226
|
-
onFail
|
|
227
|
-
)
|
|
228
|
-
);
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const isLatestBootloader = async (device: Device) => {
|
|
232
|
-
if (!isDeviceInDFUBootloader(device)) {
|
|
233
|
-
throw new Error('Cannot read bootloader information.');
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const bootloaderInfo = await getBootloaderInformation(device);
|
|
237
|
-
|
|
238
|
-
if (
|
|
239
|
-
!bootloaderInfo ||
|
|
240
|
-
bootloaderInfo.bootloaderType !== 'NRFDL_BOOTLOADER_TYPE_SDFU' ||
|
|
241
|
-
bootloaderInfo.version.toString() >=
|
|
242
|
-
LATEST_BOOTLOADER_VERSION.toString()
|
|
243
|
-
) {
|
|
244
|
-
return true;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return false;
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const askAndUpdateBootloader =
|
|
251
|
-
(
|
|
252
|
-
device: Device,
|
|
253
|
-
onSuccess: (device: Device) => void,
|
|
254
|
-
onFail: (reason?: unknown) => void,
|
|
255
|
-
onProgress: (progress: number, message?: string) => void
|
|
256
|
-
) =>
|
|
257
|
-
(dispatch: AppDispatch) => {
|
|
258
|
-
dispatch(
|
|
259
|
-
switchToBootloaderMode(
|
|
260
|
-
device,
|
|
261
|
-
async d => {
|
|
262
|
-
if (!(await isLatestBootloader(d))) {
|
|
263
|
-
dispatch(
|
|
264
|
-
openDeviceSetupDialog({
|
|
265
|
-
onUserInput: isConfirmed => {
|
|
266
|
-
if (isConfirmed) {
|
|
267
|
-
logger.info(
|
|
268
|
-
'Continuing with old bootloader'
|
|
269
|
-
);
|
|
270
|
-
onSuccess(d);
|
|
271
|
-
} else {
|
|
272
|
-
const action = (dd: Device) => {
|
|
273
|
-
dispatch(
|
|
274
|
-
switchToBootloaderMode(
|
|
275
|
-
dd,
|
|
276
|
-
onSuccess,
|
|
277
|
-
onFail
|
|
278
|
-
)
|
|
279
|
-
);
|
|
280
|
-
};
|
|
281
|
-
dispatch(
|
|
282
|
-
updateBootloader(
|
|
283
|
-
d,
|
|
284
|
-
action,
|
|
285
|
-
onFail,
|
|
286
|
-
onProgress
|
|
287
|
-
)
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
},
|
|
291
|
-
message:
|
|
292
|
-
'Device will be programmed. A Newer version of the bootloader is available, do you want to update it as well?',
|
|
293
|
-
})
|
|
294
|
-
);
|
|
295
|
-
} else {
|
|
296
|
-
onSuccess(d);
|
|
297
|
-
}
|
|
298
|
-
},
|
|
299
|
-
onFail
|
|
300
|
-
)
|
|
301
|
-
);
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Loads firmware image from HEX file
|
|
306
|
-
*
|
|
307
|
-
* @param {Buffer|string} firmware contents of HEX file if Buffer otherwise path of HEX file
|
|
308
|
-
* @returns {Uint8Array} the loaded firmware
|
|
309
|
-
*/
|
|
310
|
-
function parseFirmwareImage(firmware: Buffer | string) {
|
|
311
|
-
const contents =
|
|
312
|
-
firmware instanceof Buffer ? firmware : fs.readFileSync(firmware);
|
|
313
|
-
|
|
314
|
-
const memMap = MemoryMap.fromHex(contents.toString());
|
|
315
|
-
let startAddress = 0;
|
|
316
|
-
let endAddress = 0;
|
|
317
|
-
memMap.forEach((block, address) => {
|
|
318
|
-
startAddress = !startAddress ? address : startAddress;
|
|
319
|
-
endAddress = address + block.length;
|
|
320
|
-
});
|
|
321
|
-
return memMap.slicePad(
|
|
322
|
-
startAddress,
|
|
323
|
-
Math.ceil((endAddress - startAddress) / 4) * 4
|
|
324
|
-
) as Buffer;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function calculateSHA256Hash(image: Uint8Array) {
|
|
328
|
-
const digest = createHash('sha256');
|
|
329
|
-
digest.update(image);
|
|
330
|
-
return Buffer.from(digest.digest().reverse());
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
interface DfuData {
|
|
334
|
-
application?: { bin: Buffer; dat: Buffer };
|
|
335
|
-
softdevice?: { bin: Uint8Array; dat: Uint8Array };
|
|
336
|
-
params?: InitPacket;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
const createDfuDataFromImages = (dfuImages: DfuImage[]): DfuData => {
|
|
340
|
-
const extract = (image: DfuImage) => ({
|
|
341
|
-
bin: image.firmwareImage,
|
|
342
|
-
dat: createInitPacketBuffer(
|
|
343
|
-
image.initPacket.fwVersion as number,
|
|
344
|
-
image.initPacket.hwVersion as number,
|
|
345
|
-
image.initPacket.sdReq as number[],
|
|
346
|
-
image.initPacket.fwType as number,
|
|
347
|
-
image.initPacket.sdSize,
|
|
348
|
-
image.initPacket.blSize,
|
|
349
|
-
image.initPacket.appSize,
|
|
350
|
-
image.initPacket.hashType,
|
|
351
|
-
image.initPacket.hash as Buffer,
|
|
352
|
-
image.initPacket.isDebug,
|
|
353
|
-
image.initPacket.signatureType as number,
|
|
354
|
-
image.initPacket.signature as []
|
|
355
|
-
),
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
const application = dfuImages.find(i => i.name === 'Application');
|
|
359
|
-
const softdevice = dfuImages.find(i => i.name === 'SoftDevice');
|
|
360
|
-
|
|
361
|
-
return {
|
|
362
|
-
application: application && extract(application),
|
|
363
|
-
softdevice: softdevice && extract(softdevice),
|
|
364
|
-
};
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
interface Manifest {
|
|
368
|
-
application?: { bin_file: string; dat_file: string };
|
|
369
|
-
softdevice?: { bin_file: string; dat_file: string };
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
const createDfuZip = (dfuImages: DfuImage[]) =>
|
|
373
|
-
new Promise<AdmZip>(resolve => {
|
|
374
|
-
const data = createDfuDataFromImages(dfuImages);
|
|
375
|
-
const zip = new AdmZip();
|
|
376
|
-
const manifest: Manifest = {};
|
|
377
|
-
|
|
378
|
-
if (data.application) {
|
|
379
|
-
manifest.application = {
|
|
380
|
-
bin_file: 'application.bin',
|
|
381
|
-
dat_file: 'application.dat',
|
|
382
|
-
};
|
|
383
|
-
zip.addFile('application.bin', data.application.bin);
|
|
384
|
-
zip.addFile('application.dat', data.application.dat);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (data.softdevice) {
|
|
388
|
-
manifest.softdevice = {
|
|
389
|
-
bin_file: 'softdevice.bin',
|
|
390
|
-
dat_file: 'softdevice.dat',
|
|
391
|
-
};
|
|
392
|
-
zip.addFile('softdevice.bin', data.softdevice.bin as Buffer);
|
|
393
|
-
zip.addFile('softdevice.dat', data.softdevice.dat as Buffer);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
const manifestJson = JSON.stringify({ manifest });
|
|
397
|
-
const manifestBuffer = Buffer.alloc(manifestJson.length, manifestJson);
|
|
398
|
-
zip.addFile('manifest.json', manifestBuffer);
|
|
399
|
-
|
|
400
|
-
resolve(zip);
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
const createDfuZipBuffer = async (dfuImages: DfuImage[]) => {
|
|
404
|
-
const zip = await createDfuZip(dfuImages);
|
|
405
|
-
const buffer = zip.toBuffer();
|
|
406
|
-
return buffer;
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
const programInDFUBootloader =
|
|
410
|
-
(
|
|
411
|
-
device: Device,
|
|
412
|
-
dfu: DfuEntry,
|
|
413
|
-
onProgress: (progress: number, message?: string) => void,
|
|
414
|
-
onSuccess: (device: Device) => void,
|
|
415
|
-
onFail: (reason?: unknown) => void
|
|
416
|
-
) =>
|
|
417
|
-
async (dispatch: AppDispatch) => {
|
|
418
|
-
logger.debug(
|
|
419
|
-
`${device.serialNumber} on ${device.serialport?.comName} is now in DFU-Bootloader...`
|
|
420
|
-
);
|
|
421
|
-
const { application, softdevice } = dfu;
|
|
422
|
-
const params: Partial<InitPacket> = dfu.params || {};
|
|
423
|
-
|
|
424
|
-
const dfuImages: DfuImage[] = [];
|
|
425
|
-
if (softdevice) {
|
|
426
|
-
const firmwareImage = parseFirmwareImage(softdevice);
|
|
427
|
-
|
|
428
|
-
const initPacketParams = {
|
|
429
|
-
fwType: FwType.SOFTDEVICE,
|
|
430
|
-
fwVersion: 0xffffffff,
|
|
431
|
-
hwVersion: params.hwVersion || 52,
|
|
432
|
-
hashType: HashType.SHA256,
|
|
433
|
-
hash: calculateSHA256Hash(firmwareImage),
|
|
434
|
-
sdSize: firmwareImage.length,
|
|
435
|
-
sdReq: params.sdReq || [],
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
const packet: InitPacket = {
|
|
439
|
-
...defaultInitPacket,
|
|
440
|
-
...initPacketParams,
|
|
441
|
-
};
|
|
442
|
-
dfuImages.push({
|
|
443
|
-
name: 'SoftDevice',
|
|
444
|
-
initPacket: packet,
|
|
445
|
-
firmwareImage,
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
const firmwareImage = parseFirmwareImage(application);
|
|
450
|
-
|
|
451
|
-
const initPacketParams = {
|
|
452
|
-
fwType: FwType.APPLICATION,
|
|
453
|
-
fwVersion: params.fwVersion || 4,
|
|
454
|
-
hwVersion: params.hwVersion || 52,
|
|
455
|
-
hashType: HashType.SHA256,
|
|
456
|
-
hash: calculateSHA256Hash(firmwareImage),
|
|
457
|
-
appSize: firmwareImage.length,
|
|
458
|
-
// @ts-expect-error This parameter is set.
|
|
459
|
-
sdReq: params.sdId || [],
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
const packet = { ...defaultInitPacket, ...initPacketParams };
|
|
463
|
-
dfuImages.push({
|
|
464
|
-
name: 'Application',
|
|
465
|
-
initPacket: packet,
|
|
466
|
-
firmwareImage,
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
const zipBuffer = await createDfuZipBuffer(dfuImages);
|
|
470
|
-
|
|
471
|
-
logger.debug('Starting DFU');
|
|
472
|
-
|
|
473
|
-
onProgress(0, 'Preparing to program');
|
|
474
|
-
|
|
475
|
-
dispatch(
|
|
476
|
-
setWaitForDevice({
|
|
477
|
-
timeout: DEFAULT_DEVICE_WAIT_TIME,
|
|
478
|
-
when: 'always',
|
|
479
|
-
once: false,
|
|
480
|
-
onSuccess,
|
|
481
|
-
onFail,
|
|
482
|
-
})
|
|
483
|
-
);
|
|
484
|
-
nrfDeviceLib.firmwareProgram(
|
|
485
|
-
getDeviceLibContext(),
|
|
486
|
-
device.id,
|
|
487
|
-
'NRFDL_FW_BUFFER',
|
|
488
|
-
'NRFDL_FW_SDFU_ZIP',
|
|
489
|
-
zipBuffer,
|
|
490
|
-
err => {
|
|
491
|
-
if (err) {
|
|
492
|
-
logger.error(
|
|
493
|
-
`Failed to write to the target device: ${
|
|
494
|
-
err.message || err
|
|
495
|
-
}`
|
|
496
|
-
);
|
|
497
|
-
onFail(err);
|
|
498
|
-
} else {
|
|
499
|
-
logger.info(
|
|
500
|
-
'All dfu images have been written to the target device'
|
|
501
|
-
);
|
|
502
|
-
logger.debug('DFU completed successfully!');
|
|
503
|
-
dispatch(
|
|
504
|
-
setWaitForDevice({
|
|
505
|
-
timeout: DEFAULT_DEVICE_WAIT_TIME,
|
|
506
|
-
when: 'applicationMode',
|
|
507
|
-
once: true,
|
|
508
|
-
onSuccess,
|
|
509
|
-
onFail,
|
|
510
|
-
})
|
|
511
|
-
);
|
|
512
|
-
onProgress(100, 'Waiting for device to reboot');
|
|
513
|
-
}
|
|
514
|
-
},
|
|
515
|
-
progress => {
|
|
516
|
-
onProgress(
|
|
517
|
-
progress.progressJson.progressPercentage,
|
|
518
|
-
progress.progressJson.message ?? ''
|
|
519
|
-
);
|
|
520
|
-
}
|
|
521
|
-
);
|
|
522
|
-
};
|
|
523
|
-
|
|
524
|
-
const programDeviceWithFw =
|
|
525
|
-
(
|
|
526
|
-
device: Device,
|
|
527
|
-
selectedFw: DfuEntry,
|
|
528
|
-
onProgress: (progress: number, message?: string) => void
|
|
529
|
-
) =>
|
|
530
|
-
(dispatch: AppDispatch) =>
|
|
531
|
-
new Promise<Device>((resolve, reject) => {
|
|
532
|
-
const action = (d: Device) => {
|
|
533
|
-
dispatch(
|
|
534
|
-
programInDFUBootloader(
|
|
535
|
-
d,
|
|
536
|
-
selectedFw,
|
|
537
|
-
onProgress,
|
|
538
|
-
resolve,
|
|
539
|
-
reject
|
|
540
|
-
)
|
|
541
|
-
);
|
|
542
|
-
logger.debug('DFU finished: ', d);
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
dispatch(
|
|
546
|
-
askAndUpdateBootloader(device, action, reject, onProgress)
|
|
547
|
-
);
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
export const sdfuDeviceSetup = (
|
|
551
|
-
dfuFirmware: DfuEntry[],
|
|
552
|
-
needSerialport = false
|
|
553
|
-
): DeviceSetup => ({
|
|
554
|
-
supportsProgrammingMode: (device: Device) =>
|
|
555
|
-
((!!device.dfuTriggerVersion &&
|
|
556
|
-
device.dfuTriggerVersion.semVer.length > 0) ||
|
|
557
|
-
isDeviceInDFUBootloader(device)) &&
|
|
558
|
-
(needSerialport === device.traits.serialPorts || !needSerialport),
|
|
559
|
-
getFirmwareOptions: device =>
|
|
560
|
-
dfuFirmware.map(firmwareOption => ({
|
|
561
|
-
key: firmwareOption.key,
|
|
562
|
-
description: firmwareOption.description,
|
|
563
|
-
programDevice: onProgress => (dispatch: AppDispatch) =>
|
|
564
|
-
dispatch(
|
|
565
|
-
programDeviceWithFw(device, firmwareOption, onProgress)
|
|
566
|
-
),
|
|
567
|
-
})),
|
|
568
|
-
isExpectedFirmware: (device: Device) => () =>
|
|
569
|
-
new Promise<{
|
|
570
|
-
device: Device;
|
|
571
|
-
validFirmware: boolean;
|
|
572
|
-
}>(resolve => {
|
|
573
|
-
if (device.dfuTriggerVersion) {
|
|
574
|
-
logger.debug(
|
|
575
|
-
'Device has DFU trigger interface, the device is in Application mode'
|
|
576
|
-
);
|
|
577
|
-
|
|
578
|
-
const { semVer } = device.dfuTriggerVersion;
|
|
579
|
-
|
|
580
|
-
if (dfuFirmware.filter(fw => fw.semver === semVer).length > 0) {
|
|
581
|
-
resolve({
|
|
582
|
-
device,
|
|
583
|
-
validFirmware: true,
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
} else {
|
|
587
|
-
resolve({
|
|
588
|
-
device,
|
|
589
|
-
validFirmware: false,
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
}),
|
|
593
|
-
tryToSwitchToApplicationMode: device => (dispatch: AppDispatch) =>
|
|
594
|
-
new Promise<Device>((resolve, reject) => {
|
|
595
|
-
dispatch(switchToApplicationMode(device, resolve, reject));
|
|
596
|
-
}),
|
|
597
|
-
});
|
|
598
|
-
|
|
599
|
-
export default {
|
|
600
|
-
createDfuZipBuffer,
|
|
601
|
-
};
|