mirror of https://github.com/ARMmbed/mbed-os.git
Change the location of tf-m build folder
Use the folder `features/FEATURE_PSA/TARGET_TFM/TARGET_IGNORE` as the build folder to clone and build tf-m. Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>pull/12402/head
parent
fe759b1a12
commit
50d6b58b6c
|
@ -98,5 +98,5 @@ test_suite.json
|
||||||
# default delivery dir
|
# default delivery dir
|
||||||
DELIVERY/
|
DELIVERY/
|
||||||
|
|
||||||
# Directory hosting PSA autogenerated source files
|
# Directory used to clone and build tf-m
|
||||||
PSA_AUTOGEN/
|
features/FEATURE_PSA/TARGET_TFM/TARGET_IGNORE/
|
||||||
|
|
|
@ -225,7 +225,7 @@ python3 tools/psa/build_tfm.py
|
||||||
Supported options:
|
Supported options:
|
||||||
```console
|
```console
|
||||||
usage: build_tfm.py [-h] [-m {CY8CPROTO_064_SB_S}] [-t {ARMCLANG,GNUARM}] [-d]
|
usage: build_tfm.py [-h] [-m {CY8CPROTO_064_SB_S}] [-t {ARMCLANG,GNUARM}] [-d]
|
||||||
[-l] [--commit] [--develop] [--clean-build] [-v]
|
[-l] [--commit]
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
@ -237,10 +237,6 @@ optional arguments:
|
||||||
-d, --debug Set build profile to debug
|
-d, --debug Set build profile to debug
|
||||||
-l, --list Print supported TF-M secure targets
|
-l, --list Print supported TF-M secure targets
|
||||||
--commit Create a git commit for each platform
|
--commit Create a git commit for each platform
|
||||||
--develop Use this option for development. A new folder
|
|
||||||
(tfm_build_dir) under the parent folder of Mbed OS is
|
|
||||||
used as tf-m build folder. By default, temporary
|
|
||||||
folder provided by tempfile.mkdtemp() is used.
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If the python script is invoked without any options then TF-M will be built for all the supported targets and the binary will be copied to predefined location defined by attribute `delivery_dir`.
|
If the python script is invoked without any options then TF-M will be built for all the supported targets and the binary will be copied to predefined location defined by attribute `delivery_dir`.
|
||||||
|
|
|
@ -37,9 +37,8 @@ logging.basicConfig(level=logging.INFO,
|
||||||
datefmt='%H:%M:%S')
|
datefmt='%H:%M:%S')
|
||||||
logger = logging.getLogger('Build-TF-M')
|
logger = logging.getLogger('Build-TF-M')
|
||||||
|
|
||||||
TF_M_BUILD_DIR = None
|
|
||||||
USING_TEMP_DIR = None
|
|
||||||
POPEN_INSTANCE = None
|
POPEN_INSTANCE = None
|
||||||
|
TF_M_BUILD_DIR = join(ROOT, 'features/FEATURE_PSA/TARGET_TFM/TARGET_IGNORE')
|
||||||
VERSION_FILE_PATH = join(ROOT, 'features/FEATURE_PSA/TARGET_TFM')
|
VERSION_FILE_PATH = join(ROOT, 'features/FEATURE_PSA/TARGET_TFM')
|
||||||
|
|
||||||
dependencies = {
|
dependencies = {
|
||||||
|
@ -115,21 +114,17 @@ def _run_cmd_and_return(command, output=False):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
global POPEN_INSTANCE
|
global POPEN_INSTANCE
|
||||||
if output:
|
with open(os.devnull, 'w') as fnull:
|
||||||
POPEN_INSTANCE = subprocess.Popen(command, stdout=subprocess.PIPE,
|
POPEN_INSTANCE = subprocess.Popen(command, stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=fnull)
|
||||||
|
|
||||||
std_out, std_err = POPEN_INSTANCE.communicate()
|
|
||||||
|
|
||||||
|
std_out, __ = POPEN_INSTANCE.communicate()
|
||||||
|
retcode = POPEN_INSTANCE.returncode
|
||||||
POPEN_INSTANCE = None
|
POPEN_INSTANCE = None
|
||||||
return std_out.decode("utf-8")
|
|
||||||
else:
|
if output:
|
||||||
with open(os.devnull, 'w') as fnull:
|
return std_out.decode("utf-8")
|
||||||
POPEN_INSTANCE = subprocess.Popen(command, stdout=subprocess.PIPE,
|
else:
|
||||||
stderr=fnull)
|
|
||||||
POPEN_INSTANCE.communicate()
|
|
||||||
retcode = POPEN_INSTANCE.returncode
|
|
||||||
POPEN_INSTANCE = None
|
|
||||||
return retcode
|
return retcode
|
||||||
|
|
||||||
def _detect_and_write_tfm_version(tfm_dir, commit):
|
def _detect_and_write_tfm_version(tfm_dir, commit):
|
||||||
|
@ -370,34 +365,45 @@ def _build_tfm(args):
|
||||||
'cmake_build')
|
'cmake_build')
|
||||||
if not isdir(cmake_build_dir):
|
if not isdir(cmake_build_dir):
|
||||||
os.mkdir(cmake_build_dir)
|
os.mkdir(cmake_build_dir)
|
||||||
|
else:
|
||||||
|
shutil.rmtree(cmake_build_dir)
|
||||||
|
os.mkdir(cmake_build_dir)
|
||||||
|
|
||||||
if args.mcu:
|
if args.mcu:
|
||||||
tgt = None
|
tgt = None
|
||||||
if args.toolchain:
|
if args.toolchain:
|
||||||
msg = "Building TF-M for target %s using toolchain %s" % (
|
if args.debug:
|
||||||
args.mcu, args.toolchain)
|
msg = "Building TF-M for target %s using toolchain %s in DEBUG mode" % (
|
||||||
|
args.mcu, args.toolchain)
|
||||||
|
else:
|
||||||
|
msg = "Building TF-M for target %s using toolchain %s" % (
|
||||||
|
args.mcu, args.toolchain)
|
||||||
logger.info(msg)
|
logger.info(msg)
|
||||||
tgt = _get_target_info(args.mcu, args.toolchain)
|
tgt = _get_target_info(args.mcu, args.toolchain)
|
||||||
else:
|
else:
|
||||||
tgt = _get_target_info(args.mcu)
|
tgt = _get_target_info(args.mcu)
|
||||||
msg = "Building TF-M for target %s using default toolchain %s" % (
|
if args.debug:
|
||||||
|
msg = "Building TF-M for target %s using default toolchain %s in DEBUG mode " % (
|
||||||
args.mcu, tgt[2])
|
args.mcu, tgt[2])
|
||||||
|
else:
|
||||||
|
msg = "Building TF-M for target %s using default toolchain %s" % (
|
||||||
|
args.mcu, args.toolchain)
|
||||||
logger.info(msg)
|
logger.info(msg)
|
||||||
|
|
||||||
retcode = _run_cmake_build(True, cmake_build_dir, tgt[4],
|
retcode = _run_cmake_build(True, cmake_build_dir, tgt[4],
|
||||||
tgt[1], tgt[2], args.debug)
|
tgt[1], tgt[2], args.debug)
|
||||||
if retcode:
|
if retcode:
|
||||||
msg = "Cmake configure failed for target %s using toolchain %s" % (
|
msg = "Cmake configure failed for target %s using toolchain %s" % (
|
||||||
tgt[0], tgt[2])
|
tgt[0], tgt[2])
|
||||||
logger.critical(msg)
|
logger.critical(msg)
|
||||||
_cleanup(cmake_build_dir, True)
|
sys.exit(1)
|
||||||
|
|
||||||
retcode = _run_cmake_build(False, cmake_build_dir)
|
retcode = _run_cmake_build(False, cmake_build_dir)
|
||||||
if retcode:
|
if retcode:
|
||||||
msg = "Cmake build failed for target %s using toolchain %s" % (
|
msg = "Cmake build failed for target %s using toolchain %s" % (
|
||||||
tgt[0], tgt[2])
|
tgt[0], tgt[2])
|
||||||
logger.critical(msg)
|
logger.critical(msg)
|
||||||
_cleanup(cmake_build_dir, True)
|
sys.exit(1)
|
||||||
|
|
||||||
_copy_binaries(tgt[1], cmake_build_dir, tgt[3])
|
_copy_binaries(tgt[1], cmake_build_dir, tgt[3])
|
||||||
|
|
||||||
|
@ -405,46 +411,41 @@ def _build_tfm(args):
|
||||||
_commit_changes(tgt[3], tgt[0], tgt[2])
|
_commit_changes(tgt[3], tgt[0], tgt[2])
|
||||||
else:
|
else:
|
||||||
for tgt in _get_mbed_supported_tfm_targets():
|
for tgt in _get_mbed_supported_tfm_targets():
|
||||||
msg = "Building TF-M for target %s using default toolchain %s" % (
|
if args.debug:
|
||||||
tgt[0], tgt[2])
|
msg = "Building TF-M for target %s using default toolchain %s in DEBUG mode" % (
|
||||||
|
tgt[0], tgt[2])
|
||||||
|
else:
|
||||||
|
msg = "Building TF-M for target %s using default toolchain %s" % (
|
||||||
|
tgt[0], tgt[2])
|
||||||
logger.info(msg)
|
logger.info(msg)
|
||||||
|
|
||||||
retcode = _run_cmake_build(True, cmake_build_dir, tgt[4],
|
retcode = _run_cmake_build(True, cmake_build_dir, tgt[4],
|
||||||
tgt[1], tgt[2], args.debug)
|
tgt[1], tgt[2], args.debug)
|
||||||
if retcode:
|
if retcode:
|
||||||
msg = "Cmake configure failed for target %s with toolchain %s" % (
|
msg = "Cmake configure failed for target %s with toolchain %s" % (
|
||||||
tgt[0], tgt[2])
|
tgt[0], tgt[2])
|
||||||
logger.critical(msg)
|
logger.critical(msg)
|
||||||
_cleanup(cmake_build_dir, True)
|
sys.exit(1)
|
||||||
|
|
||||||
retcode = _run_cmake_build(False, cmake_build_dir)
|
retcode = _run_cmake_build(False, cmake_build_dir)
|
||||||
if retcode:
|
if retcode:
|
||||||
msg = "Cmake build failed for target %s using toolchain %s" % (
|
msg = "Cmake build failed for target %s using toolchain %s" % (
|
||||||
tgt[0], tgt[2])
|
tgt[0], tgt[2])
|
||||||
logger.critical(msg)
|
logger.critical(msg)
|
||||||
_cleanup(cmake_build_dir, True)
|
sys.exit(1)
|
||||||
|
|
||||||
_copy_binaries(tgt[1], cmake_build_dir, tgt[3])
|
_copy_binaries(tgt[1], cmake_build_dir, tgt[3])
|
||||||
|
|
||||||
if args.commit:
|
if args.commit:
|
||||||
_commit_changes(tgt[3], tgt[0], tgt[2])
|
_commit_changes(tgt[3], tgt[0], tgt[2])
|
||||||
|
|
||||||
def _cleanup(path, build_dir=False):
|
def _exit_gracefully(signum, frame):
|
||||||
"""
|
"""
|
||||||
Clean up in case of cloning errors or keyboard interrupt
|
Crtl+C signal handler to exit gracefully
|
||||||
:param path: The path that should be removed
|
:param signum: Signal number
|
||||||
:build_dir: Set to true if only cmake build folder should be removed
|
:param frame: Current stack frame object
|
||||||
"""
|
"""
|
||||||
def handle_readonly_folders(function, path, excinfo):
|
logger.info("Received signal %s, exiting..." % signum)
|
||||||
os.chmod(path, stat.S_IWRITE)
|
|
||||||
try:
|
|
||||||
function(path)
|
|
||||||
except OSError as e:
|
|
||||||
msg = 'Unable to cleanup folder "%s", %s error occurred' % (
|
|
||||||
os.path.realpath(path), e.strerror)
|
|
||||||
logger.error(msg)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
global POPEN_INSTANCE
|
global POPEN_INSTANCE
|
||||||
try:
|
try:
|
||||||
if POPEN_INSTANCE:
|
if POPEN_INSTANCE:
|
||||||
|
@ -454,27 +455,8 @@ def _cleanup(path, build_dir=False):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if isdir(path):
|
|
||||||
shutil.rmtree(os.path.realpath(path), onerror=handle_readonly_folders)
|
|
||||||
if build_dir:
|
|
||||||
logger.info("Removed Cmake build folder %s" % relpath(path))
|
|
||||||
else:
|
|
||||||
logger.info("Removed folder %s" % os.path.realpath(path))
|
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def _exit_gracefully(signum, frame):
|
|
||||||
"""
|
|
||||||
Crtl+C signal handler to exit gracefully
|
|
||||||
:param signum: Signal number
|
|
||||||
:param frame: Current stack frame object
|
|
||||||
"""
|
|
||||||
logger.info("Received signal %s, cleaning up and then exiting..." % signum)
|
|
||||||
if USING_TEMP_DIR and TF_M_BUILD_DIR is not None:
|
|
||||||
_cleanup(TF_M_BUILD_DIR)
|
|
||||||
else:
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
def _get_parser():
|
def _get_parser():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
@ -503,16 +485,6 @@ def _get_parser():
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False)
|
default=False)
|
||||||
|
|
||||||
parser.add_argument("--develop",
|
|
||||||
help="""Use this option for development. A new folder
|
|
||||||
(tfm_build_dir) under the parent folder of Mbed OS is
|
|
||||||
used as tf-m build folder.
|
|
||||||
By default, temporary folder provided by
|
|
||||||
tempfile.mkdtemp() is used.
|
|
||||||
""",
|
|
||||||
action="store_true",
|
|
||||||
default=False)
|
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def _main():
|
def _main():
|
||||||
|
@ -521,7 +493,6 @@ def _main():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
global TF_M_BUILD_DIR
|
global TF_M_BUILD_DIR
|
||||||
global USING_TEMP_DIR
|
|
||||||
signal.signal(signal.SIGINT, _exit_gracefully)
|
signal.signal(signal.SIGINT, _exit_gracefully)
|
||||||
parser = _get_parser()
|
parser = _get_parser()
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -531,26 +502,11 @@ def _main():
|
||||||
', '.join([t for t in _get_tfm_secure_targets()])))
|
', '.join([t for t in _get_tfm_secure_targets()])))
|
||||||
return
|
return
|
||||||
|
|
||||||
if not args.develop:
|
if not isdir(TF_M_BUILD_DIR):
|
||||||
TF_M_BUILD_DIR = tempfile.mkdtemp()
|
os.mkdir(TF_M_BUILD_DIR)
|
||||||
USING_TEMP_DIR = True
|
|
||||||
logger.info("Using temporary folder %s" % TF_M_BUILD_DIR)
|
|
||||||
_build_tfm(args)
|
|
||||||
logger.info("Removing temporary folder %s" %
|
|
||||||
os.path.realpath(TF_M_BUILD_DIR))
|
|
||||||
_cleanup(TF_M_BUILD_DIR)
|
|
||||||
else:
|
|
||||||
TF_M_BUILD_DIR = abspath(join(ROOT, os.pardir, 'tfm_build_dir'))
|
|
||||||
if not isdir(TF_M_BUILD_DIR):
|
|
||||||
os.mkdir(TF_M_BUILD_DIR)
|
|
||||||
|
|
||||||
if TF_M_BUILD_DIR is not None:
|
logger.info("Using folder %s" % TF_M_BUILD_DIR)
|
||||||
cmake_build_dir = join(TF_M_BUILD_DIR, 'trusted-firmware-m',
|
_build_tfm(args)
|
||||||
'cmake_build')
|
|
||||||
if isdir(cmake_build_dir):
|
|
||||||
shutil.rmtree(cmake_build_dir)
|
|
||||||
|
|
||||||
_build_tfm(args)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if _are_dependencies_installed() != 0:
|
if _are_dependencies_installed() != 0:
|
||||||
|
|
Loading…
Reference in New Issue