@@ -40,43 +40,63 @@ def musca_tfm_bin(t_self, non_secure_bin, secure_bin):
40
40
os .makedirs (tempdir )
41
41
flash_layout = path_join (MUSCA_B1_BASE , 'partition' , 'flash_layout.h' )
42
42
mcuboot_bin = path_join (MUSCA_B1_BASE , 'prebuilt' , 'mcuboot.bin' )
43
- image_macros = path_join (MUSCA_B1_BASE , 'partition' , 'image_macros_preprocessed.c' )
43
+ image_macros_s = path_join (MUSCA_B1_BASE , 'partition' , 'image_macros_preprocessed_s.c' )
44
+ image_macros_ns = path_join (MUSCA_B1_BASE , 'partition' , 'image_macros_preprocessed_ns.c' )
45
+ s_bin_name , s_bin_ext = splitext (basename (secure_bin ))
46
+ s_signed_bin = path_join (tempdir , s_bin_name + '_signed' + s_bin_ext )
44
47
ns_bin_name , ns_bin_ext = splitext (basename (non_secure_bin ))
45
- concatenated_bin = path_join (tempdir , 'tfm_' + ns_bin_name + ns_bin_ext )
46
- signed_bin = path_join (tempdir , 'tfm_ ' + ns_bin_name + '_signed ' + ns_bin_ext )
48
+ ns_signed_bin = path_join (tempdir , 'tfm_' + ns_bin_name + '_signed' + ns_bin_ext )
49
+ concatenated_bin = path_join (tempdir , s_bin_name + '_ ' + ns_bin_name + '_concat ' + ns_bin_ext )
47
50
48
- assert os .path .isfile (image_macros )
51
+ assert os .path .isfile (image_macros_s )
52
+ assert os .path .isfile (image_macros_ns )
49
53
50
- #1. Concatenate secure TFM and non-secure mbed binaries
51
- output = Assembly (image_macros , concatenated_bin )
52
- output .add_image (secure_bin , "SECURE" )
53
- output .add_image (non_secure_bin , "NON_SECURE" )
54
+ #1. Run imgtool to sign the secure binary
55
+ sign_args = Namespace (
56
+ layout = image_macros_s ,
57
+ key = path_join (SCRIPT_DIR , 'musca_b1-root-rsa-3072.pem' ),
58
+ public_key_format = None ,
59
+ align = 1 ,
60
+ dependencies = None ,
61
+ version = version .decode_version ('1.0' ),
62
+ header_size = 0x400 ,
63
+ security_counter = None ,
64
+ rsa_pkcs1_15 = False ,
65
+ included_header = False ,
66
+ infile = secure_bin ,
67
+ outfile = s_signed_bin
68
+ )
69
+ do_sign (sign_args )
54
70
55
- #2. Run imgtool to sign the concatenated binary
71
+ #2. Run imgtool to sign the non-secure mbed binary
56
72
sign_args = Namespace (
57
- layout = image_macros ,
73
+ layout = image_macros_ns ,
58
74
key = path_join (SCRIPT_DIR , 'musca_b1-root-rsa-3072.pem' ),
59
75
public_key_format = None ,
60
76
align = 1 ,
61
77
dependencies = None ,
62
78
version = version .decode_version ('1.0' ),
63
79
header_size = 0x400 ,
64
- pad = 0xE0000 ,
65
80
security_counter = None ,
66
81
rsa_pkcs1_15 = False ,
67
82
included_header = False ,
68
- infile = concatenated_bin ,
69
- outfile = signed_bin
83
+ infile = non_secure_bin ,
84
+ outfile = ns_signed_bin
70
85
)
71
86
do_sign (sign_args )
72
87
88
+ #1. Concatenate signed secure TFM and non-secure mbed binaries
89
+ output = Assembly (image_macros_s , concatenated_bin )
90
+ output .add_image (s_signed_bin , "SECURE" )
91
+ output .add_image (ns_signed_bin , "NON_SECURE" )
92
+
73
93
#3. Concatenate mcuboot and signed binary and overwrite mbed built binary file
74
94
mcuboot_image_size = find_bl2_size (flash_layout )
75
- with open (mcuboot_bin , "rb" ) as mcuboot_fh , open (signed_bin , "rb" ) as signed_fh :
95
+ with open (mcuboot_bin , "rb" ) as mcuboot_fh , open (concatenated_bin , "rb" ) as concat_fh :
76
96
with open (non_secure_bin , "w+b" ) as out_fh :
77
97
out_fh .write (mcuboot_fh .read ())
78
98
out_fh .seek (mcuboot_image_size )
79
- out_fh .write (signed_fh .read ())
99
+ out_fh .write (concat_fh .read ())
80
100
81
101
82
102
def find_bl2_size (configFile ):
0 commit comments