|
| 1 | + # |
| 2 | + # Copyright (c) 2018 Arm Limited |
| 3 | + # |
| 4 | + # Licensed under the Apache License Version 2.0 (the "License"); |
| 5 | + # you may not use this file except in compliance with the License. |
| 6 | + # You may obtain a copy of the License at |
| 7 | + # |
| 8 | + # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + # |
| 10 | + # Unless required by applicable law or agreed to in writing software |
| 11 | + # distributed under the License is distributed on an "AS IS" BASIS |
| 12 | + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied. |
| 13 | + # See the License for the specific language governing permissions and |
| 14 | + # limitations under the License. |
| 15 | + # |
| 16 | + |
| 17 | +import os |
| 18 | +from os.path import abspath, basename, dirname, splitext |
| 19 | +from os.path import join as path_join |
| 20 | +import tempfile |
| 21 | + |
| 22 | +from tools.psa.tfm.bin_utils.assemble import Assembly |
| 23 | + |
| 24 | +SCRIPT_DIR = dirname(abspath(__file__)) |
| 25 | +MBED_OS_ROOT = abspath(path_join(SCRIPT_DIR, os.pardir, os.pardir)) |
| 26 | +LPC55S69_BASE = path_join(MBED_OS_ROOT, 'targets', 'TARGET_NXP', 'TARGET_MCUXpresso_MCUS', 'TARGET_LPC55S69') |
| 27 | + |
| 28 | +def lpc55s69_tfm_bin(t_self, non_secure_bin): |
| 29 | + tempdir = tempfile.mkdtemp() |
| 30 | + flash_layout = path_join(LPC55S69_BASE, 'partition', 'flash_layout.h') |
| 31 | + secure_bin = path_join(LPC55S69_BASE, 'TARGET_M33_NS', 'device', 'tfm.bin') |
| 32 | + ns_bin_name, ns_bin_ext = splitext(basename(non_secure_bin)) |
| 33 | + concatenated_bin = path_join(tempdir, 'tfm_' + ns_bin_name + ns_bin_ext) |
| 34 | + |
| 35 | + #1. Concatenate secure TFM and non-secure mbed binaries |
| 36 | + output = Assembly(flash_layout, concatenated_bin) |
| 37 | + output.add_image(secure_bin, "SECURE") |
| 38 | + output.add_image(non_secure_bin, "NON_SECURE") |
| 39 | + |
| 40 | + #2. Delete the original binary file name |
| 41 | + os.remove(non_secure_bin) |
| 42 | + |
| 43 | + #3. Rename to new concatenated binary to the original binary file name |
| 44 | + os.rename(concatenated_bin, non_secure_bin) |
| 45 | + |
0 commit comments