From 7b44834d8134fc662449b9c25c3192d8cc1b9ce3 Mon Sep 17 00:00:00 2001 From: Oren Cohen Date: Mon, 4 Mar 2019 16:54:07 +0200 Subject: [PATCH 1/2] Secure binaries release script This script will find all the PSA targets and compile their secure binaries Including test secure binaries --- tools/psa/release.py | 139 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 tools/psa/release.py diff --git a/tools/psa/release.py b/tools/psa/release.py new file mode 100644 index 0000000000..72519afdf8 --- /dev/null +++ b/tools/psa/release.py @@ -0,0 +1,139 @@ +#!/usr/bin/python +# Copyright (c) 2017-2018 ARM Limited +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import subprocess +import sys +import shutil + +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) +sys.path.insert(0, ROOT) +from tools.targets import Target, TARGET_MAP, TARGET_NAMES + +MAKE_PY_LOCATTION = os.path.join(ROOT, 'tools', 'make.py') +TEST_PY_LOCATTION = os.path.join(ROOT, 'tools', 'test.py') +MBED_PSA_TESTS = '*psa-spm*,*psa-crypto_access_control' +TFM_MBED_APP = os.path.join(ROOT, 'tools', 'psa', 'tfm', 'mbed_app.json') +TFM_TESTS = { + '*psa-spm_smoke': ['USE_PSA_TEST_PARTITIONS', 'USE_SMOKE_TESTS_PART1'], + '*psa-spm_client': ['USE_PSA_TEST_PARTITIONS', 'USE_CLIENT_TESTS_PART1'], + '*psa-spm_server': ['USE_PSA_TEST_PARTITIONS', 'USE_SERVER_TESTS_PART1', 'USE_SERVER_TESTS_PART2'], + '*psa-crypto_access_control': ['USE_PSA_TEST_PARTITIONS', 'USE_CRYPTO_ACL_TEST'] +} + + +def _psa_backend(target_name): + return 'TFM' if 'TFM' in Target.get_target(target_name).labels else 'MBED_SPM' + + +def get_mbed_official_psa_release(): + psa_targets_release_dict = { + 'TFM': [], + 'MBED_SPM': [] + } + + psa_secure_targets = [t for t in TARGET_NAMES if Target.get_target(t).is_PSA_secure_target] + for t in psa_secure_targets: + psa_targets_release_dict[_psa_backend(t)].append( + tuple( + [ + TARGET_MAP[t].name, + TARGET_MAP[t].default_toolchain + ] + ) + ) + + return psa_targets_release_dict + + +def create_mbed_ignore(build_dir): + with open(os.path.join(build_dir, '.mbedignore'), 'w') as f: + f.write('*\n') + + +def build_mbed_spm_platform(target, toolchain): + subprocess.call([ + sys.executable, '-u', TEST_PY_LOCATTION, + '--greentea', + '--profile', 'debug', + '-t', toolchain, + '-m', target, + '--source', ROOT, + '--build', os.path.join(ROOT, 'BUILD', 'tests', target), + '--test-spec', os.path.join(ROOT, 'BUILD', 'tests', target, 'test_spec.json'), + '--build-data', os.path.join(ROOT, 'BUILD', 'tests', target, 'build_data.json'), + '-n', MBED_PSA_TESTS + ]) + + subprocess.call([ + sys.executable, '-u', MAKE_PY_LOCATTION, + '-t', toolchain, + '-m', target, + '--profile', 'release', + '--source', ROOT, + '--build', os.path.join(ROOT, 'BUILD', target), + '--artifact-name', 'psa_release_1.0' + ]) + + +def _tfm_test_defines(test): + return ['-D{}'.format(define) for define in TFM_TESTS[test]] + + +def build_tfm_platform(target, toolchain): + for test in TFM_TESTS.keys(): + subprocess.call([ + sys.executable, '-u', TEST_PY_LOCATTION, + '--greentea', + '--profile', 'debug', + '-t', toolchain, + '-m', target, + '--source', ROOT, + '--build', os.path.join(ROOT, 'BUILD', 'tests', target), + '--test-spec', os.path.join(ROOT, 'BUILD', 'tests', target, 'test_spec.json'), + '--build-data', os.path.join(ROOT, 'BUILD', 'tests', target, 'build_data.json'), + '--app-config', TFM_MBED_APP, '-n', test] + _tfm_test_defines(test)) + + subprocess.call([ + sys.executable, '-u', MAKE_PY_LOCATTION, + '-t', toolchain, + '-m', target, + '--profile', 'release', + '--source', ROOT, + '--build', os.path.join(ROOT, 'BUILD', target), + '--app-config', TFM_MBED_APP + ]) + + +def main(): + build_dir = os.path.join(ROOT, 'BUILD') + if os.path.exists(build_dir): + shutil.rmtree(build_dir) + + os.makedirs(build_dir) + create_mbed_ignore(build_dir) + + psa_platforms_dict = get_mbed_official_psa_release() + for target, toolchain in psa_platforms_dict['MBED_SPM']: + build_mbed_spm_platform(target, toolchain) + + for target, toolchain in psa_platforms_dict['TFM']: + build_tfm_platform(target, toolchain) + + +if __name__ == '__main__': + main() From cf8ab27080ae6195c75bd1cb9b8fbd03d610d7a9 Mon Sep 17 00:00:00 2001 From: Oren Cohen Date: Mon, 4 Mar 2019 19:11:38 +0200 Subject: [PATCH 2/2] Add option to run on a single target --- tools/psa/release.py | 48 +++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/tools/psa/release.py b/tools/psa/release.py index 72519afdf8..5b5a131422 100644 --- a/tools/psa/release.py +++ b/tools/psa/release.py @@ -19,6 +19,7 @@ import os import subprocess import sys import shutil +from argparse import ArgumentParser ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) sys.path.insert(0, ROOT) @@ -41,14 +42,10 @@ def _psa_backend(target_name): def get_mbed_official_psa_release(): - psa_targets_release_dict = { - 'TFM': [], - 'MBED_SPM': [] - } - + psa_targets_release_list = [] psa_secure_targets = [t for t in TARGET_NAMES if Target.get_target(t).is_PSA_secure_target] for t in psa_secure_targets: - psa_targets_release_dict[_psa_backend(t)].append( + psa_targets_release_list.append( tuple( [ TARGET_MAP[t].name, @@ -57,7 +54,7 @@ def get_mbed_official_psa_release(): ) ) - return psa_targets_release_dict + return psa_targets_release_list def create_mbed_ignore(build_dir): @@ -119,20 +116,47 @@ def build_tfm_platform(target, toolchain): ]) +def build_psa_platform(target, toolchain): + if _psa_backend(options.mcu) is 'TFM': + build_tfm_platform(target, toolchain) + else: + build_mbed_spm_platform(target, toolchain) + + +def get_parser(): + parser = ArgumentParser() + parser.add_argument("-m", "--mcu", + help="build for the given MCU", + default='*', + metavar="MCU") + + return parser + + +def filter_target(mcu): + def filter_func(t): + return t[0] == mcu + + return filter_func + + def main(): + parser = get_parser() + options = parser.parse_args() build_dir = os.path.join(ROOT, 'BUILD') if os.path.exists(build_dir): shutil.rmtree(build_dir) os.makedirs(build_dir) create_mbed_ignore(build_dir) + target_filter_function = None + psa_platforms_list = get_mbed_official_psa_release() - psa_platforms_dict = get_mbed_official_psa_release() - for target, toolchain in psa_platforms_dict['MBED_SPM']: - build_mbed_spm_platform(target, toolchain) + if options.mcu is not '*': + target_filter_function = filter_target(options.mcu) - for target, toolchain in psa_platforms_dict['TFM']: - build_tfm_platform(target, toolchain) + for target, toolchain in filter(target_filter_function, psa_platforms_list): + build_psa_platform(target, toolchain) if __name__ == '__main__':