23
23
24
24
SCRIPT_DIR = dirname (abspath (__file__ ))
25
25
MBED_OS_ROOT = abspath (path_join (SCRIPT_DIR , os .pardir , os .pardir ))
26
- MUSCA_B1_BASE = path_join (MBED_OS_ROOT , 'targets' , 'TARGET_ARM_SSG' , 'TARGET_MUSCA_B1' )
27
26
28
- def musca_tfm_bin (t_self , non_secure_bin , secure_bin ):
27
+ def musca_tfm_bin (t_self , non_secure_bin , secure_bin , target_name ):
29
28
29
+ MUSCA_BASE = path_join (MBED_OS_ROOT , 'targets' , 'TARGET_ARM_SSG' , ('TARGET_' + target_name ))
30
30
assert os .path .isfile (secure_bin )
31
31
assert os .path .isfile (non_secure_bin )
32
32
33
33
build_dir = dirname (non_secure_bin )
34
34
tempdir = path_join (build_dir , 'temp' )
35
35
if not isdir (tempdir ):
36
36
os .makedirs (tempdir )
37
- flash_layout = path_join (MUSCA_B1_BASE , 'partition' , 'flash_layout.h' )
38
- mcuboot_bin = path_join (MUSCA_B1_BASE , 'bl2.bin' )
39
- image_macros_s = path_join (MUSCA_B1_BASE , 'partition' , 'signing_layout_s.c' )
40
- image_macros_ns = path_join (MUSCA_B1_BASE , 'partition' , 'signing_layout_ns.c' )
37
+ flash_layout = path_join (MUSCA_BASE , 'partition' , 'flash_layout.h' )
38
+ mcuboot_bin = path_join (MUSCA_BASE , 'bl2.bin' )
39
+ image_macros_s = path_join (MUSCA_BASE , 'partition' , 'signing_layout_s.c' )
40
+ image_macros_ns = path_join (MUSCA_BASE , 'partition' , 'signing_layout_ns.c' )
41
41
s_bin_name , s_bin_ext = splitext (basename (secure_bin ))
42
42
s_signed_bin = abspath (path_join (tempdir , s_bin_name + '_signed' + s_bin_ext ))
43
43
ns_bin_name , ns_bin_ext = splitext (basename (non_secure_bin ))
@@ -54,7 +54,7 @@ def musca_tfm_bin(t_self, non_secure_bin, secure_bin):
54
54
"-v" ,
55
55
'1.2.0' ,
56
56
"-k" ,
57
- path_join (SCRIPT_DIR , 'musca_b1 -root-rsa-3072.pem' ),
57
+ path_join (SCRIPT_DIR , ( target_name . lower () + ' -root-rsa-3072.pem') ),
58
58
"--layout" ,
59
59
image_macros_s ,
60
60
"--public-key-format" ,
@@ -74,7 +74,11 @@ def musca_tfm_bin(t_self, non_secure_bin, secure_bin):
74
74
s_signed_bin ,
75
75
]
76
76
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
78
82
79
83
#2. Run wrapper to sign the non-secure mbed binary
80
84
cmd = [
@@ -83,7 +87,7 @@ def musca_tfm_bin(t_self, non_secure_bin, secure_bin):
83
87
"-v" ,
84
88
'1.2.0' ,
85
89
"-k" ,
86
- path_join (SCRIPT_DIR , 'musca_b1 -root-rsa-3072_1.pem' ),
90
+ path_join (SCRIPT_DIR , ( target_name . lower () + ' -root-rsa-3072_1.pem') ),
87
91
"--layout" ,
88
92
image_macros_ns ,
89
93
"--public-key-format" ,
@@ -103,7 +107,11 @@ def musca_tfm_bin(t_self, non_secure_bin, secure_bin):
103
107
ns_signed_bin ,
104
108
]
105
109
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
107
115
108
116
#3. Concatenate signed secure TFM and non-secure mbed binaries
109
117
cmd = [
@@ -119,7 +127,11 @@ def musca_tfm_bin(t_self, non_secure_bin, secure_bin):
119
127
concatenated_bin ,
120
128
]
121
129
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
123
135
124
136
#4. Concatenate mcuboot and signed binary and overwrite mbed built binary file
125
137
mcuboot_image_size = find_bl2_size (flash_layout )
@@ -145,7 +157,11 @@ def run_cmd(cmd, directory):
145
157
146
158
POPEN_INSTANCE = subprocess .Popen (
147
159
cmd ,
160
+ stdout = subprocess .PIPE ,
161
+ stderr = subprocess .STDOUT ,
148
162
cwd = directory ,
149
163
)
150
164
151
165
POPEN_INSTANCE .communicate ()
166
+ return POPEN_INSTANCE .returncode
167
+
0 commit comments