mirror of https://github.com/ARMmbed/mbed-os.git
Specify extra args with -x and verbose_check_call
parent
f3db129ad9
commit
400b024c30
|
@ -11,9 +11,9 @@ This document describes the following scripts:
|
||||||
|
|
||||||
## \_\_init\_\_.py
|
## \_\_init\_\_.py
|
||||||
|
|
||||||
This file holds common functions dedicated to help SiP with their postbuild logic.
|
This file holds common functions dedicated to help SiP with their post-build logic.
|
||||||
|
|
||||||
* find_secure_image - Scans a Resource object to find the correct binary of the secure image to merge with the nonsecure build.
|
* find_secure_image - Scans a Resource object to find the correct binary of the secure image to merge with the non-secure build.
|
||||||
|
|
||||||
## Code generation scripts
|
## Code generation scripts
|
||||||
|
|
||||||
|
@ -22,12 +22,12 @@ Mbed OS holds two implementations of PSA:
|
||||||
* MBED_SPM - Implementation for dual-core v7 targets.
|
* MBED_SPM - Implementation for dual-core v7 targets.
|
||||||
* TF-M - Implementation for v8 targets.
|
* TF-M - Implementation for v8 targets.
|
||||||
|
|
||||||
Each implementation requires a set of autogenerated files describing the secure partitions:
|
Each implementation requires a set of auto-generated files describing the secure partitions:
|
||||||
|
|
||||||
* `generate_partition_code.py` - Generate files for both implementations.
|
* `generate_partition_code.py` - Generate files for both implementations.
|
||||||
* `generate_mbed_spm_partition_code.py` - Generate files for MBED_SPM.
|
* `generate_mbed_spm_partition_code.py` - Generate files for MBED_SPM.
|
||||||
* `generate_tfm_partition_code.py` - Generate files for TF-M.
|
* `generate_tfm_partition_code.py` - Generate files for TF-M.
|
||||||
* `mbed_spm_tfm_common.py` - Holds common functions for both.
|
* `mbed_spm_tfm_common.py` - Holds common functions for both.
|
||||||
|
|
||||||
## Secure image generation
|
## Secure image generation
|
||||||
|
|
||||||
|
@ -35,20 +35,23 @@ Each implementation requires a set of autogenerated files describing the secure
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: release.py [-h] [-m MCU] [-d] [-q] [-l] [--commit] [--skip-tests]
|
usage: release.py [-h] [-m MCU] [-d] [-q] [-l] [--commit] [--skip-tests]
|
||||||
|
[-x ...]
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-m MCU, --mcu MCU build for the given MCU
|
-m MCU, --mcu MCU build for the given MCU
|
||||||
-d, --debug set build profile to debug
|
-d, --debug set build profile to debug
|
||||||
-q, --quiet No Build log will be printed
|
-q, --quiet No Build log will be printed
|
||||||
-l, --list Print supported PSA secure targets
|
-l, --list Print supported PSA secure targets
|
||||||
--commit create a git commit for each platform
|
--commit create a git commit for each platform
|
||||||
--skip-tests skip the test build phase
|
--skip-tests skip the test build phase
|
||||||
|
-x ..., --extra ... additional build parameters
|
||||||
```
|
```
|
||||||
|
|
||||||
* When `MCU ` is not specified, the script compiles all the images for all the targets.
|
* When `MCU ` is not specified, the script compiles all the images for all the targets.
|
||||||
* When `-d/--debug` is not specified, the script compiles the images using the release profile.
|
* When `-d/--debug` is not specified, the script compiles the images using the release profile.
|
||||||
* When `--commit` is not specified, the script will not commit the images to git.
|
* When `--commit` is not specified, the script will not commit the images to git.
|
||||||
|
* A user can specify additional commands that will be passed on to the build commands (Ex. -D for compilation defines).
|
||||||
|
|
||||||
This script should be run in following scenarios:
|
This script should be run in following scenarios:
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
import logging
|
import logging
|
||||||
from argparse import ArgumentParser
|
import argparse
|
||||||
|
|
||||||
FNULL = open(os.devnull, 'w')
|
FNULL = open(os.devnull, 'w')
|
||||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
||||||
|
@ -89,13 +89,14 @@ def _get_psa_secure_targets_list():
|
||||||
Target.get_target(t).is_PSA_secure_target]
|
Target.get_target(t).is_PSA_secure_target]
|
||||||
|
|
||||||
|
|
||||||
def _get_default_image_build_command(target, toolchain, profile):
|
def _get_default_image_build_command(target, toolchain, profile, args):
|
||||||
"""
|
"""
|
||||||
Creates a build command for a default image.
|
Creates a build command for a default image.
|
||||||
|
|
||||||
:param target: target to be built.
|
:param target: target to be built.
|
||||||
:param toolchain: toolchain to be used.
|
:param toolchain: toolchain to be used.
|
||||||
:param profile: build profile.
|
:param profile: build profile.
|
||||||
|
:param args: list of extra arguments.
|
||||||
:return: Build command in a list form.
|
:return: Build command in a list form.
|
||||||
"""
|
"""
|
||||||
cmd = [
|
cmd = [
|
||||||
|
@ -112,7 +113,22 @@ def _get_default_image_build_command(target, toolchain, profile):
|
||||||
else:
|
else:
|
||||||
cmd += ['--artifact-name', 'psa_release_1.0']
|
cmd += ['--artifact-name', 'psa_release_1.0']
|
||||||
|
|
||||||
return cmd
|
return cmd + args
|
||||||
|
|
||||||
|
|
||||||
|
def verbose_check_call(cmd, check_call=True):
|
||||||
|
"""
|
||||||
|
|
||||||
|
:param cmd: command to run as a list
|
||||||
|
:param check_call: choose subprocess method (call/check_call)
|
||||||
|
:return: return code of the executed command
|
||||||
|
"""
|
||||||
|
logger.info('Running: {}'.format(' '.join(cmd)))
|
||||||
|
if check_call:
|
||||||
|
return subprocess.check_call(cmd, stdout=subprocess_output,
|
||||||
|
stderr=subprocess_err)
|
||||||
|
|
||||||
|
return subprocess.call(cmd, stdout=subprocess_output, stderr=subprocess_err)
|
||||||
|
|
||||||
|
|
||||||
def get_mbed_official_psa_release(target=None):
|
def get_mbed_official_psa_release(target=None):
|
||||||
|
@ -143,19 +159,19 @@ def create_mbed_ignore(build_dir):
|
||||||
f.write('*\n')
|
f.write('*\n')
|
||||||
|
|
||||||
|
|
||||||
def build_tests_mbed_spm_platform(target, toolchain, profile):
|
def build_tests_mbed_spm_platform(target, toolchain, profile, args):
|
||||||
"""
|
"""
|
||||||
Builds Secure images for MBED-SPM target.
|
Builds Secure images for MBED-SPM target.
|
||||||
|
|
||||||
:param target: target to be built.
|
:param target: target to be built.
|
||||||
:param toolchain: toolchain to be used.
|
:param toolchain: toolchain to be used.
|
||||||
:param profile: build profile.
|
:param profile: build profile.
|
||||||
|
:param args: list of extra arguments.
|
||||||
"""
|
"""
|
||||||
logger.info(
|
logger.info(
|
||||||
"Building tests images({}) for {} using {} with {} profile".format(
|
"Building tests images({}) for {} using {} with {} profile".format(
|
||||||
MBED_PSA_TESTS, target, toolchain, profile))
|
MBED_PSA_TESTS, target, toolchain, profile))
|
||||||
|
cmd = [
|
||||||
subprocess.check_call([
|
|
||||||
sys.executable, TEST_PY_LOCATTION,
|
sys.executable, TEST_PY_LOCATTION,
|
||||||
'--greentea',
|
'--greentea',
|
||||||
'--profile', profile,
|
'--profile', profile,
|
||||||
|
@ -167,22 +183,22 @@ def build_tests_mbed_spm_platform(target, toolchain, profile):
|
||||||
target, 'test_spec.json'),
|
target, 'test_spec.json'),
|
||||||
'--build-data', os.path.join(ROOT, 'BUILD', 'tests',
|
'--build-data', os.path.join(ROOT, 'BUILD', 'tests',
|
||||||
target, 'build_data.json'),
|
target, 'build_data.json'),
|
||||||
'-n', MBED_PSA_TESTS
|
'-n', MBED_PSA_TESTS] + args
|
||||||
], stdout=subprocess_output, stderr=subprocess_err)
|
|
||||||
|
|
||||||
|
|
||||||
|
verbose_check_call(cmd)
|
||||||
logger.info(
|
logger.info(
|
||||||
"Finished building tests images({}) for {} successfully".format(
|
"Finished building tests images({}) for {} successfully".format(
|
||||||
MBED_PSA_TESTS, target))
|
MBED_PSA_TESTS, target))
|
||||||
|
|
||||||
|
|
||||||
def build_tests_tfm_platform(target, toolchain, profile):
|
def build_tests_tfm_platform(target, toolchain, profile, args):
|
||||||
"""
|
"""
|
||||||
Builds Secure images for TF-M target.
|
Builds Secure images for TF-M target.
|
||||||
|
|
||||||
:param target: target to be built.
|
:param target: target to be built.
|
||||||
:param toolchain: toolchain to be used.
|
:param toolchain: toolchain to be used.
|
||||||
:param profile: build profile.
|
:param profile: build profile.
|
||||||
|
:param args: list of extra arguments.
|
||||||
"""
|
"""
|
||||||
for test in TFM_TESTS.keys():
|
for test in TFM_TESTS.keys():
|
||||||
logger.info(
|
logger.info(
|
||||||
|
@ -190,7 +206,7 @@ def build_tests_tfm_platform(target, toolchain, profile):
|
||||||
test, target, toolchain, profile))
|
test, target, toolchain, profile))
|
||||||
|
|
||||||
test_defines = ['-D{}'.format(define) for define in TFM_TESTS[test]]
|
test_defines = ['-D{}'.format(define) for define in TFM_TESTS[test]]
|
||||||
subprocess.check_call([
|
cmd = [
|
||||||
sys.executable, TEST_PY_LOCATTION,
|
sys.executable, TEST_PY_LOCATTION,
|
||||||
'--greentea',
|
'--greentea',
|
||||||
'--profile', profile,
|
'--profile', profile,
|
||||||
|
@ -203,9 +219,9 @@ def build_tests_tfm_platform(target, toolchain, profile):
|
||||||
'--build-data', os.path.join(ROOT, 'BUILD', 'tests',
|
'--build-data', os.path.join(ROOT, 'BUILD', 'tests',
|
||||||
target, 'build_data.json'),
|
target, 'build_data.json'),
|
||||||
'-n', test,
|
'-n', test,
|
||||||
'--app-config', TFM_MBED_APP] + test_defines,
|
'--app-config', TFM_MBED_APP] + test_defines + args
|
||||||
stdout=subprocess_output, stderr=subprocess_err)
|
|
||||||
|
|
||||||
|
verbose_check_call(cmd)
|
||||||
logger.info(
|
logger.info(
|
||||||
"Finished Building tests image({}) for {}".format(test, target))
|
"Finished Building tests image({}) for {}".format(test, target))
|
||||||
|
|
||||||
|
@ -218,36 +234,33 @@ def commit_binaries(target, delivery_dir):
|
||||||
:param delivery_dir: Secure images should be moved to this folder
|
:param delivery_dir: Secure images should be moved to this folder
|
||||||
by the build system.
|
by the build system.
|
||||||
"""
|
"""
|
||||||
changes_made = subprocess.call([
|
changes_made = verbose_check_call([
|
||||||
'git',
|
'git',
|
||||||
'-C', ROOT,
|
'-C', ROOT,
|
||||||
'diff', '--exit-code', '--quiet',
|
'diff', '--exit-code', '--quiet',
|
||||||
delivery_dir
|
delivery_dir], check_call=False)
|
||||||
], stdout=subprocess_output, stderr=subprocess_err)
|
|
||||||
|
|
||||||
if changes_made:
|
if changes_made:
|
||||||
logger.info("Change in images for {} has been detected".format(target))
|
logger.info("Change in images for {} has been detected".format(target))
|
||||||
subprocess.check_call([
|
verbose_check_call([
|
||||||
'git',
|
'git',
|
||||||
'-C', ROOT,
|
'-C', ROOT,
|
||||||
'add', os.path.relpath(delivery_dir, ROOT)
|
'add', os.path.relpath(delivery_dir, ROOT)])
|
||||||
], stdout=subprocess_output, stderr=subprocess_err)
|
|
||||||
|
|
||||||
logger.info("Committing images for {}".format(target))
|
logger.info("Committing images for {}".format(target))
|
||||||
commit_message = '--message="Update secure binaries for {}"'.format(
|
commit_message = '--message="Update secure binaries for {}"'.format(
|
||||||
target)
|
target)
|
||||||
subprocess.check_call([
|
verbose_check_call([
|
||||||
'git',
|
'git',
|
||||||
'-C', ROOT,
|
'-C', ROOT,
|
||||||
'commit',
|
'commit',
|
||||||
commit_message
|
commit_message])
|
||||||
], stdout=subprocess_output, stderr=subprocess_err)
|
|
||||||
else:
|
else:
|
||||||
logger.info("No changes detected for {}, Skipping commit".format(target))
|
logger.info("No changes detected for {}, Skipping commit".format(target))
|
||||||
|
|
||||||
|
|
||||||
def build_psa_platform(target, toolchain, delivery_dir, debug=False,
|
def build_psa_platform(target, toolchain, delivery_dir, debug, git_commit,
|
||||||
git_commit=False, skip_tests=False):
|
skip_tests, args):
|
||||||
"""
|
"""
|
||||||
Calls the correct build function and commits if requested.
|
Calls the correct build function and commits if requested.
|
||||||
|
|
||||||
|
@ -257,21 +270,20 @@ def build_psa_platform(target, toolchain, delivery_dir, debug=False,
|
||||||
:param debug: Build with debug profile.
|
:param debug: Build with debug profile.
|
||||||
:param git_commit: Commit the changes.
|
:param git_commit: Commit the changes.
|
||||||
:param skip_tests: skip the test images build phase.
|
:param skip_tests: skip the test images build phase.
|
||||||
|
:param args: list of extra arguments.
|
||||||
"""
|
"""
|
||||||
profile = 'debug' if debug else 'release'
|
profile = 'debug' if debug else 'release'
|
||||||
if not skip_tests:
|
if not skip_tests:
|
||||||
if _psa_backend(target) is 'TFM':
|
if _psa_backend(target) is 'TFM':
|
||||||
build_tests_tfm_platform(target, toolchain, profile)
|
build_tests_tfm_platform(target, toolchain, profile, args)
|
||||||
else:
|
else:
|
||||||
build_tests_mbed_spm_platform(target, toolchain, profile)
|
build_tests_mbed_spm_platform(target, toolchain, profile, args)
|
||||||
|
|
||||||
logger.info("Building default image for {} using {} with {} profile".format(
|
logger.info("Building default image for {} using {} with {} profile".format(
|
||||||
target, toolchain, profile))
|
target, toolchain, profile))
|
||||||
|
|
||||||
subprocess.check_call(
|
cmd = _get_default_image_build_command(target, toolchain, profile, args)
|
||||||
_get_default_image_build_command(target, toolchain, profile),
|
verbose_check_call(cmd)
|
||||||
stdout=subprocess_output, stderr=subprocess_err)
|
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Finished building default image for {} successfully".format(target))
|
"Finished building default image for {} successfully".format(target))
|
||||||
|
|
||||||
|
@ -280,7 +292,7 @@ def build_psa_platform(target, toolchain, delivery_dir, debug=False,
|
||||||
|
|
||||||
|
|
||||||
def get_parser():
|
def get_parser():
|
||||||
parser = ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-m", "--mcu",
|
parser.add_argument("-m", "--mcu",
|
||||||
help="build for the given MCU",
|
help="build for the given MCU",
|
||||||
default=None,
|
default=None,
|
||||||
|
@ -312,6 +324,11 @@ def get_parser():
|
||||||
default=False,
|
default=False,
|
||||||
help="skip the test build phase")
|
help="skip the test build phase")
|
||||||
|
|
||||||
|
parser.add_argument('-x', '--extra',
|
||||||
|
dest='extra_args',
|
||||||
|
nargs=argparse.REMAINDER,
|
||||||
|
help="additional build parameters")
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
@ -339,7 +356,7 @@ def main():
|
||||||
subprocess_err = subprocess.STDOUT
|
subprocess_err = subprocess.STDOUT
|
||||||
|
|
||||||
if options.list:
|
if options.list:
|
||||||
logger.info("Avialable platforms are: {}".format(
|
logger.info("Available platforms are: {}".format(
|
||||||
', '.join([t for t in _get_psa_secure_targets_list()])))
|
', '.join([t for t in _get_psa_secure_targets_list()])))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -350,7 +367,8 @@ def main():
|
||||||
|
|
||||||
for target, tc, directory in psa_platforms_list:
|
for target, tc, directory in psa_platforms_list:
|
||||||
build_psa_platform(target, tc, directory, options.debug,
|
build_psa_platform(target, tc, directory, options.debug,
|
||||||
options.commit, options.skip_tests)
|
options.commit, options.skip_tests,
|
||||||
|
options.extra_args)
|
||||||
|
|
||||||
logger.info("Finished Updating PSA images")
|
logger.info("Finished Updating PSA images")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue