@nordicsemiconductor/pc-nrfconnect-shared 213.0.0 → 214.0.0

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.
Files changed (101) hide show
  1. package/Changelog.md +21 -0
  2. package/nrfutil/collectingResultParser.ts +82 -0
  3. package/nrfutil/common.ts +41 -0
  4. package/nrfutil/device/batch.ts +25 -62
  5. package/nrfutil/device/batchTypes.ts +8 -46
  6. package/nrfutil/device/boardController.ts +2 -2
  7. package/nrfutil/device/common.ts +6 -10
  8. package/nrfutil/device/deviceInfo.ts +4 -3
  9. package/nrfutil/device/erase.ts +4 -3
  10. package/nrfutil/device/getBoardControllerConfig.ts +2 -2
  11. package/nrfutil/device/getBoardControllerVersion.ts +2 -2
  12. package/nrfutil/device/getCoreInfo.ts +4 -3
  13. package/nrfutil/device/getFwInfo.ts +4 -3
  14. package/nrfutil/device/getProtectionStatus.ts +4 -3
  15. package/nrfutil/device/list.ts +5 -10
  16. package/nrfutil/device/logLibVersions.ts +8 -69
  17. package/nrfutil/device/program.ts +60 -66
  18. package/nrfutil/device/recover.ts +4 -3
  19. package/nrfutil/device/reset.ts +7 -13
  20. package/nrfutil/device/setMcuState.ts +2 -2
  21. package/nrfutil/device/setProtectionStatus.ts +4 -3
  22. package/nrfutil/device/xRead.ts +26 -28
  23. package/nrfutil/index.ts +2 -3
  24. package/nrfutil/modules.ts +10 -15
  25. package/nrfutil/sandbox.ts +162 -327
  26. package/nrfutil/sandboxTypes.ts +4 -43
  27. package/nrfutil/{jlinkVersion.test.ts → version/jlinkVersion.test.ts} +1 -1
  28. package/nrfutil/{jlinkVersion.ts → version/jlinkVersion.ts} +2 -2
  29. package/nrfutil/{moduleVersion.ts → version/moduleVersion.ts} +44 -7
  30. package/package.json +1 -1
  31. package/scripts/nordic-publish.js +4 -2
  32. package/scripts/nordic-publish.ts +44 -7
  33. package/src/logging/index.ts +0 -1
  34. package/src/utils/systemReport.ts +4 -1
  35. package/typings/generated/nrfutil/collectingResultParser.d.ts +19 -0
  36. package/typings/generated/nrfutil/collectingResultParser.d.ts.map +1 -0
  37. package/typings/generated/nrfutil/common.d.ts +6 -0
  38. package/typings/generated/nrfutil/common.d.ts.map +1 -0
  39. package/typings/generated/nrfutil/device/__mocks__/device.d.ts +1 -1
  40. package/typings/generated/nrfutil/device/batch.d.ts +6 -4
  41. package/typings/generated/nrfutil/device/batch.d.ts.map +1 -1
  42. package/typings/generated/nrfutil/device/batchTypes.d.ts +8 -30
  43. package/typings/generated/nrfutil/device/batchTypes.d.ts.map +1 -1
  44. package/typings/generated/nrfutil/device/boardController.d.ts +2 -2
  45. package/typings/generated/nrfutil/device/boardController.d.ts.map +1 -1
  46. package/typings/generated/nrfutil/device/common.d.ts +4 -3
  47. package/typings/generated/nrfutil/device/common.d.ts.map +1 -1
  48. package/typings/generated/nrfutil/device/device.d.ts +14 -14
  49. package/typings/generated/nrfutil/device/deviceInfo.d.ts +2 -2
  50. package/typings/generated/nrfutil/device/deviceInfo.d.ts.map +1 -1
  51. package/typings/generated/nrfutil/device/erase.d.ts +2 -2
  52. package/typings/generated/nrfutil/device/erase.d.ts.map +1 -1
  53. package/typings/generated/nrfutil/device/getBoardControllerConfig.d.ts +2 -2
  54. package/typings/generated/nrfutil/device/getBoardControllerConfig.d.ts.map +1 -1
  55. package/typings/generated/nrfutil/device/getBoardControllerVersion.d.ts +2 -2
  56. package/typings/generated/nrfutil/device/getBoardControllerVersion.d.ts.map +1 -1
  57. package/typings/generated/nrfutil/device/getCoreInfo.d.ts +2 -2
  58. package/typings/generated/nrfutil/device/getCoreInfo.d.ts.map +1 -1
  59. package/typings/generated/nrfutil/device/getFwInfo.d.ts +2 -2
  60. package/typings/generated/nrfutil/device/getFwInfo.d.ts.map +1 -1
  61. package/typings/generated/nrfutil/device/getProtectionStatus.d.ts +2 -2
  62. package/typings/generated/nrfutil/device/getProtectionStatus.d.ts.map +1 -1
  63. package/typings/generated/nrfutil/device/list.d.ts.map +1 -1
  64. package/typings/generated/nrfutil/device/logLibVersions.d.ts +2 -2
  65. package/typings/generated/nrfutil/device/logLibVersions.d.ts.map +1 -1
  66. package/typings/generated/nrfutil/device/program.d.ts +13 -13
  67. package/typings/generated/nrfutil/device/program.d.ts.map +1 -1
  68. package/typings/generated/nrfutil/device/recover.d.ts +2 -2
  69. package/typings/generated/nrfutil/device/recover.d.ts.map +1 -1
  70. package/typings/generated/nrfutil/device/reset.d.ts +2 -2
  71. package/typings/generated/nrfutil/device/reset.d.ts.map +1 -1
  72. package/typings/generated/nrfutil/device/setMcuState.d.ts +2 -2
  73. package/typings/generated/nrfutil/device/setMcuState.d.ts.map +1 -1
  74. package/typings/generated/nrfutil/device/setProtectionStatus.d.ts +2 -2
  75. package/typings/generated/nrfutil/device/setProtectionStatus.d.ts.map +1 -1
  76. package/typings/generated/nrfutil/device/xRead.d.ts +9 -2
  77. package/typings/generated/nrfutil/device/xRead.d.ts.map +1 -1
  78. package/typings/generated/nrfutil/index.d.ts +2 -3
  79. package/typings/generated/nrfutil/index.d.ts.map +1 -1
  80. package/typings/generated/nrfutil/modules.d.ts +1 -1
  81. package/typings/generated/nrfutil/modules.d.ts.map +1 -1
  82. package/typings/generated/nrfutil/sandbox.d.ts +27 -35
  83. package/typings/generated/nrfutil/sandbox.d.ts.map +1 -1
  84. package/typings/generated/nrfutil/sandboxTypes.d.ts +4 -29
  85. package/typings/generated/nrfutil/sandboxTypes.d.ts.map +1 -1
  86. package/typings/generated/nrfutil/{jlinkVersion.d.ts → version/jlinkVersion.d.ts} +1 -1
  87. package/typings/generated/nrfutil/version/jlinkVersion.d.ts.map +1 -0
  88. package/typings/generated/nrfutil/version/jlinkVersion.test.d.ts.map +1 -0
  89. package/typings/generated/nrfutil/version/moduleVersion.d.ts +40 -0
  90. package/typings/generated/nrfutil/version/moduleVersion.d.ts.map +1 -0
  91. package/typings/generated/nrfutil/version/version.d.ts.map +1 -0
  92. package/typings/generated/src/logging/index.d.ts.map +1 -1
  93. package/typings/generated/src/utils/systemReport.d.ts.map +1 -1
  94. package/typings/generated/nrfutil/jlinkVersion.d.ts.map +0 -1
  95. package/typings/generated/nrfutil/jlinkVersion.test.d.ts.map +0 -1
  96. package/typings/generated/nrfutil/moduleVersion.d.ts +0 -12
  97. package/typings/generated/nrfutil/moduleVersion.d.ts.map +0 -1
  98. package/typings/generated/nrfutil/version.d.ts.map +0 -1
  99. /package/nrfutil/{version.ts → version/version.ts} +0 -0
  100. /package/typings/generated/nrfutil/{jlinkVersion.test.d.ts → version/jlinkVersion.test.d.ts} +0 -0
  101. /package/typings/generated/nrfutil/{version.d.ts → version/version.d.ts} +0 -0
@@ -4,14 +4,15 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { spawn } from 'child_process';
8
- import os from 'os';
9
-
10
7
  import describeError from '../../src/logging/describeError';
11
- import { getJlinkCompatibility } from '../jlinkVersion';
12
- import { describeVersion, findDependency } from '../moduleVersion';
13
8
  import { getNrfutilLogger } from '../nrfutilLogger';
14
- import type { Dependency, ModuleVersion } from '../sandboxTypes';
9
+ import { getJlinkCompatibility } from '../version/jlinkVersion';
10
+ import {
11
+ type Dependency,
12
+ describeVersion,
13
+ findDependency,
14
+ type ModuleVersion,
15
+ } from '../version/moduleVersion';
15
16
 
16
17
  const log = (
17
18
  description: string,
@@ -29,49 +30,7 @@ const log = (
29
30
  }
30
31
  };
31
32
 
32
- const pathEnvVariable = () => {
33
- if (process.platform !== 'darwin') return process.env;
34
-
35
- return {
36
- ...process.env,
37
- PATH: `/bin:/usr/bin:/usr/local/bin:${process.env.PATH}`,
38
- };
39
- };
40
-
41
- const spawnAsync = (cmd: string, params?: string[]) =>
42
- new Promise<string>((resolve, reject) => {
43
- const codeProcess = spawn(cmd, params, {
44
- shell: true,
45
- env: pathEnvVariable(),
46
- });
47
- let stdout = '';
48
- let stderr = '';
49
- codeProcess.stdout.on('data', data => {
50
- stdout += data;
51
- });
52
- codeProcess.stderr.on('data', data => {
53
- stderr += data;
54
- });
55
-
56
- codeProcess.on('close', (code, signal) => {
57
- if (stderr) console.log(stderr);
58
- if (code === 0 && signal === null) {
59
- return resolve(stdout);
60
- }
61
- return reject();
62
- });
63
- });
64
-
65
- const checkJLinkArchitectureOnDarwin = async () => {
66
- const stdout = await spawnAsync('file $(which JLinkExe)');
67
- const universalMatch = 'Mach-O universal binary with 2 architectures';
68
- const intelMatch = 'Mach-O 64-bit executable x86_64';
69
- if (stdout.includes(universalMatch)) return 'universal';
70
- if (stdout.includes(intelMatch)) return 'x86_64';
71
- return 'arm';
72
- };
73
-
74
- export default async (moduleVersion: ModuleVersion) => {
33
+ export default (moduleVersion: ModuleVersion) => {
75
34
  const logger = getNrfutilLogger();
76
35
  try {
77
36
  const dependencies = moduleVersion.dependencies;
@@ -107,26 +66,6 @@ export default async (moduleVersion: ModuleVersion) => {
107
66
  );
108
67
  break;
109
68
  }
110
-
111
- if (
112
- process.platform === 'darwin' &&
113
- os.cpus()[0].model.includes('Apple')
114
- ) {
115
- const JLinkArchOnDarwin = await checkJLinkArchitectureOnDarwin();
116
-
117
- if (JLinkArchOnDarwin && JLinkArchOnDarwin !== 'universal') {
118
- const JLinkInstallerVersion =
119
- JLinkArchOnDarwin === 'arm'
120
- ? '64-bit Apple M1 Installer'
121
- : '64-bit Intel Installer';
122
- logger?.warn(
123
- `It looks like you have installed JLink using ${JLinkInstallerVersion}, but currently we only support their Universal Installer for your system.`
124
- );
125
- logger?.warn(
126
- `Please install JLink: https://www.segger.com/downloads/jlink/JLink_MacOSX_V818_universal.pkg`
127
- );
128
- }
129
- }
130
69
  } catch (error) {
131
70
  logger?.error(
132
71
  `Failed to get the library versions${
@@ -9,45 +9,48 @@ import os from 'os';
9
9
  import path from 'path';
10
10
  import { v4 as uuid } from 'uuid';
11
11
 
12
- import { Progress } from '../sandboxTypes';
12
+ import { type OnProgress } from '../sandboxTypes';
13
13
  import {
14
+ coreArg,
14
15
  DeviceCore,
15
16
  deviceSingleTaskEndOperationVoid,
16
- DeviceTraits,
17
+ deviceTraitsToArgs,
17
18
  NrfutilDevice,
18
19
  ResetKind,
19
20
  } from './common';
20
21
 
21
- export type FileExtensions = 'zip' | 'hex';
22
- export type FirmwareType = { buffer: Buffer; type: FileExtensions } | string;
22
+ export type FileExtension = 'zip' | 'hex';
23
+
24
+ type FirmwareBuffer = { buffer: Buffer; type: FileExtension };
25
+ export type Firmware = FirmwareBuffer | string;
23
26
 
24
27
  export type ProgrammingOptions =
25
28
  | JLinkProgrammingOptions
26
29
  | McuBootProgrammingOptions
27
30
  | NordicDfuProgrammingOptions;
28
31
 
29
- export interface JLinkProgrammingOptions {
30
- chipEraseMode?: 'ERASE_ALL' | 'ERASE_NONE';
32
+ interface JLinkProgrammingOptions {
33
+ chipEraseMode: 'ERASE_ALL' | 'ERASE_NONE';
31
34
  reset?: ResetKind;
32
35
  verify?: 'VERIFY_HASH' | 'VERIFY_NONE' | 'VERIFY_READ';
33
36
  }
34
37
 
35
- export interface McuBootProgrammingOptions {
38
+ interface McuBootProgrammingOptions {
36
39
  mcuEndState?: 'NRFDL_MCU_STATE_APPLICATION' | 'NRFDL_MCU_STATE_PROGRAMMING';
37
40
  netCoreUploadDelay?: number;
38
41
  target?: string;
39
42
  }
40
43
 
41
- export interface NordicDfuProgrammingOptions {
42
- mcuEndState?: 'NRFDL_MCU_STATE_APPLICATION' | 'NRFDL_MCU_STATE_PROGRAMMING';
44
+ interface NordicDfuProgrammingOptions {
45
+ mcuEndState: 'NRFDL_MCU_STATE_APPLICATION' | 'NRFDL_MCU_STATE_PROGRAMMING';
43
46
  }
44
47
 
45
- export const isJLinkProgrammingOptions = (
48
+ const isJLinkProgrammingOptions = (
46
49
  options: ProgrammingOptions
47
50
  ): options is JLinkProgrammingOptions =>
48
51
  (options as JLinkProgrammingOptions).chipEraseMode !== undefined;
49
52
 
50
- export const isMcuBootProgrammingOptions = (
53
+ const isMcuBootProgrammingOptions = (
51
54
  options: ProgrammingOptions
52
55
  ): options is McuBootProgrammingOptions =>
53
56
  (options as McuBootProgrammingOptions).netCoreUploadDelay !== undefined ||
@@ -59,52 +62,45 @@ export const isNordicDfuProgrammingOptions = (
59
62
  !isMcuBootProgrammingOptions(options) &&
60
63
  (options as NordicDfuProgrammingOptions).mcuEndState !== undefined;
61
64
 
62
- const deviceTraitsToArgs = (traits: DeviceTraits) => {
63
- const args: string[] = [];
64
- const traitsString = Object.keys(traits)
65
- .map(trait => (traits[trait as keyof DeviceTraits] ? trait : null))
66
- .filter(t => t !== null)
67
- .join(',');
68
-
69
- if (traitsString.length > 0) {
70
- args.push('--traits');
71
- args.push(traitsString);
72
- }
73
-
74
- return args;
75
- };
76
-
77
- export const programmingOptionsToArgs = (options?: ProgrammingOptions) => {
65
+ const programmingOptionsToStrings = (options?: ProgrammingOptions) => {
78
66
  if (!options) return [];
79
67
 
80
- const args: string[] = [];
81
-
82
68
  if (isJLinkProgrammingOptions(options)) {
83
- if (options.chipEraseMode)
84
- args.push(`chip_erase_mode=${options.chipEraseMode}`);
85
- if (options.reset) args.push(`reset=${options.reset}`);
86
- if (options.verify) args.push(`verify=${options.verify}`);
87
- } else if (isMcuBootProgrammingOptions(options)) {
88
- if (options.mcuEndState)
89
- args.push(`mcu_end_state=${options.mcuEndState}`);
90
- if (options.netCoreUploadDelay)
91
- args.push(
69
+ return [
70
+ `chip_erase_mode=${options.chipEraseMode}`,
71
+ options.reset && `reset=${options.reset}`,
72
+ options.verify && `verify=${options.verify}`,
73
+ ].filter(Boolean);
74
+ }
75
+
76
+ if (isMcuBootProgrammingOptions(options)) {
77
+ return [
78
+ options.mcuEndState && `mcu_end_state=${options.mcuEndState}`,
79
+ options.target && `target=${options.target}`,
80
+ options.netCoreUploadDelay &&
92
81
  `net_core_upload_delay=${Math.round(
93
82
  options.netCoreUploadDelay
94
- )}`
95
- );
96
- if (options.target) args.push(`target=${options.target}`);
97
- } else if (isNordicDfuProgrammingOptions(options)) {
98
- if (options.mcuEndState)
99
- args.push(`mcu_end_state=${options.mcuEndState}`);
83
+ )}`,
84
+ ].filter(Boolean);
85
+ }
86
+
87
+ if (isNordicDfuProgrammingOptions(options)) {
88
+ return [`mcu_end_state=${options.mcuEndState}`];
100
89
  }
101
90
 
102
- return args.length > 0 ? ['--options', `${args.join(',')}`] : [];
91
+ throw new Error(`Unhandled ProgrammingOptions: ${options}`);
103
92
  };
93
+
94
+ export const programmingOptionsToArgs = (options?: ProgrammingOptions) => {
95
+ const optionsString = programmingOptionsToStrings(options).join(',');
96
+
97
+ return optionsString.length > 0 ? ['--options', optionsString] : [];
98
+ };
99
+
104
100
  const program = (
105
101
  device: NrfutilDevice,
106
102
  firmwarePath: string,
107
- onProgress?: (progress: Progress) => void,
103
+ onProgress?: OnProgress,
108
104
  core?: DeviceCore,
109
105
  programmingOptions?: ProgrammingOptions,
110
106
  controller?: AbortController
@@ -118,32 +114,31 @@ const program = (
118
114
  '--firmware',
119
115
  firmwarePath,
120
116
  ...deviceTraitsToArgs(device.traits),
121
- ...(core ? ['--core', core] : []),
117
+ ...coreArg(core),
122
118
  ...programmingOptionsToArgs(programmingOptions),
123
119
  ]
124
120
  );
125
121
 
122
+ export const createTempFile = (firmware: FirmwareBuffer): string => {
123
+ let tempFilePath;
124
+ do {
125
+ tempFilePath = path.join(os.tmpdir(), `${uuid()}.${firmware.type}`);
126
+ } while (fs.existsSync(tempFilePath));
127
+
128
+ fs.writeFileSync(tempFilePath, firmware.buffer);
129
+
130
+ return tempFilePath;
131
+ };
132
+
126
133
  const programBuffer = async (
127
134
  device: NrfutilDevice,
128
- firmware: Buffer,
129
- type: FileExtensions,
130
- onProgress?: (progress: Progress) => void,
135
+ firmware: FirmwareBuffer,
136
+ onProgress?: OnProgress,
131
137
  core?: DeviceCore,
132
138
  programmingOptions?: ProgrammingOptions,
133
139
  controller?: AbortController
134
140
  ) => {
135
- const saveTemp = (): string => {
136
- let tempFilePath;
137
- do {
138
- tempFilePath = path.join(os.tmpdir(), `${uuid()}.${type}`);
139
- } while (fs.existsSync(tempFilePath));
140
-
141
- fs.writeFileSync(tempFilePath, firmware);
142
-
143
- return tempFilePath;
144
- };
145
-
146
- const tempFilePath = saveTemp();
141
+ const tempFilePath = createTempFile(firmware);
147
142
  try {
148
143
  await program(
149
144
  device,
@@ -161,8 +156,8 @@ const programBuffer = async (
161
156
 
162
157
  export default async (
163
158
  device: NrfutilDevice,
164
- firmware: FirmwareType,
165
- onProgress?: (progress: Progress) => void,
159
+ firmware: Firmware,
160
+ onProgress?: OnProgress,
166
161
  core?: DeviceCore,
167
162
  programmingOptions?: ProgrammingOptions,
168
163
  controller?: AbortController
@@ -179,8 +174,7 @@ export default async (
179
174
  } else {
180
175
  await programBuffer(
181
176
  device,
182
- firmware.buffer,
183
- firmware.type,
177
+ firmware,
184
178
  onProgress,
185
179
  core,
186
180
  programmingOptions,
@@ -4,8 +4,9 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress } from '../sandboxTypes';
7
+ import { type OnProgress } from '../sandboxTypes';
8
8
  import {
9
+ coreArg,
9
10
  DeviceCore,
10
11
  deviceSingleTaskEndOperationVoid,
11
12
  NrfutilDevice,
@@ -14,7 +15,7 @@ import {
14
15
  export default (
15
16
  device: NrfutilDevice,
16
17
  core?: DeviceCore,
17
- onProgress?: (progress: Progress) => void,
18
+ onProgress?: OnProgress,
18
19
  controller?: AbortController
19
20
  ) =>
20
21
  deviceSingleTaskEndOperationVoid(
@@ -22,5 +23,5 @@ export default (
22
23
  'recover',
23
24
  onProgress,
24
25
  controller,
25
- core ? ['--core', core] : []
26
+ coreArg(core)
26
27
  );
@@ -4,8 +4,9 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress } from '../sandboxTypes';
7
+ import { type OnProgress } from '../sandboxTypes';
8
8
  import {
9
+ coreArg,
9
10
  DeviceCore,
10
11
  deviceSingleTaskEndOperationVoid,
11
12
  NrfutilDevice,
@@ -16,20 +17,13 @@ export default async (
16
17
  device: NrfutilDevice,
17
18
  core?: DeviceCore,
18
19
  resetKind?: ResetKind,
19
- onProgress?: (progress: Progress) => void,
20
+ onProgress?: OnProgress,
20
21
  controller?: AbortController
21
22
  ) => {
22
- const args: string[] = [];
23
-
24
- if (resetKind) {
25
- args.push('--reset-kind');
26
- args.push(resetKind);
27
- }
28
-
29
- if (core) {
30
- args.push('--core');
31
- args.push(core);
32
- }
23
+ const args = [
24
+ ...(resetKind ? ['--reset-kind', resetKind] : []),
25
+ ...coreArg(core),
26
+ ];
33
27
 
34
28
  await deviceSingleTaskEndOperationVoid(
35
29
  device,
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress } from '../sandboxTypes';
7
+ import { type OnProgress } from '../sandboxTypes';
8
8
  import { deviceSingleTaskEndOperationVoid, NrfutilDevice } from './common';
9
9
 
10
10
  export type McuState = 'Application' | 'Programming';
@@ -12,7 +12,7 @@ export type McuState = 'Application' | 'Programming';
12
12
  export default (
13
13
  device: NrfutilDevice,
14
14
  state: McuState,
15
- onProgress?: (progress: Progress) => void,
15
+ onProgress?: OnProgress,
16
16
  controller?: AbortController,
17
17
  target?: string
18
18
  ) =>
@@ -4,8 +4,9 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress } from '../sandboxTypes';
7
+ import { type OnProgress } from '../sandboxTypes';
8
8
  import {
9
+ coreArg,
9
10
  DeviceCore,
10
11
  deviceSingleTaskEndOperationVoid,
11
12
  NrfutilDevice,
@@ -15,7 +16,7 @@ export default (
15
16
  device: NrfutilDevice,
16
17
  region: 'All' | 'SecureRegions' | 'Region0' | 'Region0Region1',
17
18
  core?: DeviceCore,
18
- onProgress?: (progress: Progress) => void,
19
+ onProgress?: OnProgress,
19
20
  controller?: AbortController
20
21
  ) =>
21
22
  deviceSingleTaskEndOperationVoid(
@@ -23,5 +24,5 @@ export default (
23
24
  'protection-set',
24
25
  onProgress,
25
26
  controller,
26
- [region, ...(core ? ['--core', core] : [])]
27
+ [region, ...coreArg(core)]
27
28
  );
@@ -5,8 +5,9 @@
5
5
  */
6
6
 
7
7
  /* eslint-disable no-bitwise */
8
- import { Progress } from '../sandboxTypes';
8
+ import { type OnProgress } from '../sandboxTypes';
9
9
  import {
10
+ coreArg,
10
11
  DeviceCore,
11
12
  deviceSingleTaskEndOperation,
12
13
  NrfutilDevice,
@@ -88,43 +89,40 @@ export function toIntelHex(memoryData: MemoryData[]) {
88
89
  return { intelHex: records.join('\n') };
89
90
  }
90
91
 
92
+ export type XReadOptions = {
93
+ address: number;
94
+ bytes: number;
95
+ width?: 8 | 15 | 32; // defaults to 32
96
+ direct?: boolean;
97
+ };
98
+
99
+ export const xReadOptionsToArgs = ({
100
+ address,
101
+ bytes,
102
+ width,
103
+ direct,
104
+ }: XReadOptions) => [
105
+ '--address',
106
+ address.toString(),
107
+ '--bytes',
108
+ bytes.toString(),
109
+ ...(direct ? ['--direct'] : []),
110
+ ...(width ? ['--width', width.toString()] : []),
111
+ ];
112
+
91
113
  const xRead = async (
92
114
  device: NrfutilDevice,
93
- address: number,
94
- bytes: number,
115
+ options: XReadOptions,
95
116
  core?: DeviceCore,
96
- width?: 8 | 15 | 32, // defaults to 32
97
- direct?: boolean,
98
- onProgress?: (progress: Progress) => void,
117
+ onProgress?: OnProgress,
99
118
  controller?: AbortController
100
119
  ) => {
101
- const args: string[] = [
102
- '--address',
103
- address.toString(),
104
- '--bytes',
105
- bytes.toString(),
106
- ];
107
-
108
- if (direct) {
109
- args.push('--direct');
110
- }
111
-
112
- if (width) {
113
- args.push('--width');
114
- args.push(width.toString());
115
- }
116
-
117
- if (core) {
118
- args.push('--core');
119
- args.push(core);
120
- }
121
-
122
120
  const result = await deviceSingleTaskEndOperation<MemoryReadRaw>(
123
121
  device,
124
122
  'x-read',
125
123
  onProgress,
126
124
  controller,
127
- args
125
+ [...xReadOptionsToArgs(options), ...coreArg(core)]
128
126
  );
129
127
 
130
128
  return toIntelHex(result.memoryData);
package/nrfutil/index.ts CHANGED
@@ -4,8 +4,7 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- export { default as prepareSandbox } from './sandbox';
8
- export type { NrfutilSandbox } from './sandbox';
7
+ export { NrfutilSandbox } from './sandbox';
9
8
  export type { Progress } from './sandboxTypes';
10
9
  export { getNrfutilLogger, setNrfutilLogger } from './nrfutilLogger';
11
10
  export {
@@ -14,4 +13,4 @@ export {
14
13
  setVerboseLogging,
15
14
  getAllModuleVersions,
16
15
  } from './modules';
17
- export { getJlinkCompatibility } from './jlinkVersion';
16
+ export { getJlinkCompatibility } from './version/jlinkVersion';
@@ -8,10 +8,10 @@ import { getUserDataDir } from '../src/utils/appDirs';
8
8
  import { isLauncher, packageJsonApp } from '../src/utils/packageJson';
9
9
  import { getIsLoggingVerbose } from '../src/utils/persistentStore';
10
10
  import logLibVersions from './device/logLibVersions';
11
- import { describeVersion } from './moduleVersion';
12
11
  import { getNrfutilLogger } from './nrfutilLogger';
13
- import sandbox, { NrfutilSandbox } from './sandbox';
12
+ import { NrfutilSandbox } from './sandbox';
14
13
  import { LogLevel } from './sandboxTypes';
14
+ import { describeVersion } from './version/moduleVersion';
15
15
 
16
16
  const fallbackLevel = process.env.NODE_ENV === 'production' ? 'off' : 'error';
17
17
 
@@ -40,31 +40,26 @@ const logModuleVersions = (module: string, moduleSandbox: NrfutilSandbox) => {
40
40
  const forwardLogging = (moduleSandbox: NrfutilSandbox) => {
41
41
  moduleSandbox.onLogging((evt, pid) => {
42
42
  const logger = getNrfutilLogger();
43
- const formatMsg = (msg: string) =>
44
- `${
45
- pid && moduleSandbox?.logLevel === 'trace'
46
- ? `[PID:${pid}] `
47
- : ''
48
- }${msg}`;
43
+ const msg = `${moduleSandbox.pidIfTraceLogging(pid)}${evt.message}`;
49
44
 
50
45
  switch (evt.level) {
51
46
  case 'TRACE':
52
- logger?.verbose(formatMsg(evt.message));
47
+ logger?.verbose(msg);
53
48
  break;
54
49
  case 'DEBUG':
55
- logger?.debug(formatMsg(evt.message));
50
+ logger?.debug(msg);
56
51
  break;
57
52
  case 'INFO':
58
- logger?.info(formatMsg(evt.message));
53
+ logger?.info(msg);
59
54
  break;
60
55
  case 'WARN':
61
- logger?.warn(formatMsg(evt.message));
56
+ logger?.warn(msg);
62
57
  break;
63
58
  case 'ERROR':
64
- logger?.error(formatMsg(evt.message));
59
+ logger?.error(msg);
65
60
  break;
66
61
  case 'CRITICAL':
67
- logger?.error(formatMsg(evt.message));
62
+ logger?.error(msg);
68
63
  break;
69
64
  case 'OFF':
70
65
  default:
@@ -79,7 +74,7 @@ const getModuleSandbox = (module: string) => {
79
74
 
80
75
  const createModuleSandbox = async () => {
81
76
  getNrfutilLogger()?.info(`Initialising the bundled nrfutil ${module}`);
82
- promiseModuleSandbox = sandbox(getUserDataDir(), module);
77
+ promiseModuleSandbox = NrfutilSandbox.create(getUserDataDir(), module);
83
78
  moduleSandbox = await promiseModuleSandbox;
84
79
 
85
80
  logModuleVersions(module, moduleSandbox);