Skip to content

Commit 6a08b17

Browse files
committed
Add error handling for post binary hook script
Raise an exception if there was an issue with handling any command when signing the binaries for MUSCA targets.
1 parent c5e5487 commit 6a08b17

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

tools/targets/ARM_MUSCA.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def musca_tfm_bin(t_self, non_secure_bin, secure_bin, target_name):
7474
s_signed_bin,
7575
]
7676

77-
run_cmd(cmd, MBED_OS_ROOT)
77+
retcode = run_cmd(cmd, MBED_OS_ROOT)
78+
if retcode:
79+
raise Exception("Unable to sign " + target_name +
80+
" secure binary, Error code: " + retcode)
81+
return
7882

7983
#2. Run wrapper to sign the non-secure mbed binary
8084
cmd = [
@@ -103,7 +107,11 @@ def musca_tfm_bin(t_self, non_secure_bin, secure_bin, target_name):
103107
ns_signed_bin,
104108
]
105109

106-
run_cmd(cmd, MBED_OS_ROOT)
110+
retcode = run_cmd(cmd, MBED_OS_ROOT)
111+
if retcode:
112+
raise Exception("Unable to sign " + target_name +
113+
" non-secure binary, Error code: " + retcode)
114+
return
107115

108116
#3. Concatenate signed secure TFM and non-secure mbed binaries
109117
cmd = [
@@ -119,7 +127,11 @@ def musca_tfm_bin(t_self, non_secure_bin, secure_bin, target_name):
119127
concatenated_bin,
120128
]
121129

122-
run_cmd(cmd, MBED_OS_ROOT)
130+
retcode = run_cmd(cmd, MBED_OS_ROOT)
131+
if retcode:
132+
raise Exception("Unable to concatenate " + target_name +
133+
" binaries, Error code: " + retcode)
134+
return
123135

124136
#4. Concatenate mcuboot and signed binary and overwrite mbed built binary file
125137
mcuboot_image_size = find_bl2_size(flash_layout)
@@ -145,7 +157,11 @@ def run_cmd(cmd, directory):
145157

146158
POPEN_INSTANCE = subprocess.Popen(
147159
cmd,
160+
stdout=subprocess.PIPE,
161+
stderr=subprocess.STDOUT,
148162
cwd=directory,
149163
)
150164

151165
POPEN_INSTANCE.communicate()
166+
return POPEN_INSTANCE.returncode
167+

0 commit comments

Comments
 (0)