Skip to content

Commit

Permalink
[nrf fromlist] scripts: runners: nrf: Check device family
Browse files Browse the repository at this point in the history
This patch makes the nrfjprog runner check the device family
before flashing. Otherwise, it is very easy to break some devices
that have multiple different chips.

(cherry picked from commit e0aa35d74a5aaa6b2fa9f684385c8e8fcda2ad30)
Signed-off-by: Maximilian Deubel <[email protected]>
  • Loading branch information
maxd-nordic committed Mar 14, 2024
1 parent ecb16c7 commit b6faf2f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions scripts/west_commands/runners/nrfjprog.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ def do_exec_op(self, op, force=False):
else:
raise RuntimeError(f'Invalid operation: {op_type}')

# Make sure the device is in the expected family
try:
output = self.check_output(['nrfjprog', '--deviceversion', '--snr', self.dev_id])
if families[self.family] not in output.decode("ASCII"):
raise RuntimeError(f'Family mismatch: {families[self.family]} expected, but got {output.decode("ASCII")}')
except subprocess.CalledProcessError as cpe:
if cpe.returncode == UnavailableOperationBecauseProtectionError:
cpe.returncode = ErrNotAvailableBecauseProtection
raise cpe

# Execute the flash command
try:
self.check_call(cmd + ['-f', families[self.family]] + core_opt +
['--snr', self.dev_id] + self.tool_opt)
Expand Down

0 comments on commit b6faf2f

Please sign in to comment.