scripts: runners: nrf: Use nrfutil error codes
Standardize to nrfutil error codes instead of nrfjprog ones. This is
because nrfutil has a wider range of functionality and will eventually
be the default runner for all nRF devices. It is also consistent with
the internal operation representation, which is now using the nrfutil
format already.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
diff --git a/scripts/west_commands/runners/nrf_common.py b/scripts/west_commands/runners/nrf_common.py
index 22f4bc3..3767db3 100644
--- a/scripts/west_commands/runners/nrf_common.py
+++ b/scripts/west_commands/runners/nrf_common.py
@@ -21,9 +21,8 @@
except ImportError:
IntelHex = None
-# https://infocenter.nordicsemi.com/index.jsp?topic=%2Fug_nrf_cltools%2FUG%2Fcltools%2Fnrf_nrfjprogexe_return_codes.html&cp=9_1_3_1
-UnavailableOperationBecauseProtectionError = 16
-VerifyError = 55
+ErrNotAvailableBecauseProtection = 24
+ErrVerify = 25
class NrfBinaryRunner(ZephyrBinaryRunner):
'''Runner front-end base class for nrf tools.'''
@@ -230,7 +229,7 @@
try:
self.flush_ops()
except subprocess.CalledProcessError as cpe:
- if cpe.returncode == UnavailableOperationBecauseProtectionError:
+ if cpe.returncode == ErrNotAvailableBecauseProtection:
if self.family == 'NRF53_FAMILY':
family_help = (
' Note: your target is an nRF53; all flash memory '
@@ -245,7 +244,7 @@
'must be recovered.\n'
' To fix, run "west flash --recover" instead.\n' +
family_help)
- if cpe.returncode == VerifyError:
+ if cpe.returncode == ErrVerify:
# If there are data in the UICR region it is likely that the
# verify failed du to the UICR not been erased before, so giving
# a warning here will hopefully enhance UX.
diff --git a/scripts/west_commands/runners/nrfjprog.py b/scripts/west_commands/runners/nrfjprog.py
index 4d76b43..9671def 100644
--- a/scripts/west_commands/runners/nrfjprog.py
+++ b/scripts/west_commands/runners/nrfjprog.py
@@ -5,9 +5,15 @@
'''Runner for flashing with nrfjprog.'''
+import subprocess
import sys
-from runners.nrf_common import NrfBinaryRunner
+from runners.nrf_common import ErrNotAvailableBecauseProtection, ErrVerify, \
+ NrfBinaryRunner
+
+# https://infocenter.nordicsemi.com/index.jsp?topic=%2Fug_nrf_cltools%2FUG%2Fcltools%2Fnrf_nrfjprogexe_return_codes.html&cp=9_1_3_1
+UnavailableOperationBecauseProtectionError = 16
+VerifyError = 55
class NrfJprogBinaryRunner(NrfBinaryRunner):
'''Runner front-end for nrfjprog.'''
@@ -81,6 +87,14 @@
else:
raise RuntimeError(f'Invalid operation: {op_type}')
- self.check_call(cmd + ['-f', families[self.family]] + core_opt +
- ['--snr', self.dev_id] + self.tool_opt)
+ try:
+ self.check_call(cmd + ['-f', families[self.family]] + core_opt +
+ ['--snr', self.dev_id] + self.tool_opt)
+ except subprocess.CalledProcessError as cpe:
+ # Translate error codes
+ if cpe.returncode == UnavailableOperationBecauseProtectionError:
+ cpe.returncode = ErrNotAvailableBecauseProtection
+ elif cpe.returncode == VerifyError:
+ cpe.returncode = ErrVerify
+ raise cpe
return True