Skip to content

Commit 3d16554

Browse files
gbrtthPatater
authored andcommitted
fix: Move _get_tfm_regression_targets() to psa_builder.py
Move _get_tfm_regression_targets() to psa_builder.py so targets can be shared across the scripts. Signed-off-by: Gabor Toth <[email protected]>
1 parent dcc8a1c commit 3d16554

File tree

3 files changed

+45
-43
lines changed

3 files changed

+45
-43
lines changed

build_tfm.py

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@
2525
import shutil
2626
import logging
2727
from psa_builder import *
28-
29-
try:
30-
import yaml
31-
except ImportError as e:
32-
print(str(e) + " To install it, type:")
33-
print("python3 -m pip install PyYAML")
34-
exit(1)
35-
3628
from tools.toolchains import TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
3729
from tools.targets import Target, TARGET_MAP, TARGET_NAMES
3830

@@ -92,37 +84,6 @@ def _clone_tfm_repo(commit):
9284
)
9385

9486

95-
def _get_tfm_secure_targets():
96-
"""
97-
Creates a list of TF-M secure targets from Mbed OS targets.json.
98-
99-
:return: List of TF-M secure targets.
100-
"""
101-
return [str(t) for t in TARGET_NAMES if Target.get_target(t).is_TFM_target]
102-
103-
104-
def _get_tfm_regression_targets():
105-
"""
106-
Creates a list of TF-M regression tests supported targets
107-
This parses the yaml file for supported target names and compares them
108-
with TF-M targets supported in Mbed OS
109-
110-
:return: List of supported TF-M regression targets.
111-
"""
112-
with open(join(dirname(__file__), "tfm_ns_import.yaml")) as ns_import:
113-
yaml_data = yaml.safe_load(ns_import)
114-
mbed_os_data = yaml_data["mbed-os"]
115-
tfm_regression_data = yaml_data["tf-m-regression"]
116-
117-
regression_targets = list(
118-
set(_get_tfm_secure_targets())
119-
& set(mbed_os_data)
120-
& set(tfm_regression_data)
121-
)
122-
123-
return regression_targets
124-
125-
12687
def _get_target_info(target, toolchain=None):
12788
"""
12889
Creates a TF-M target tuple (target name, TF-M target name, toolchain,
@@ -176,7 +137,7 @@ def _get_mbed_supported_tfm_targets():
176137
Returns a generator with every element containing a TF-M target tuple
177138
(target name, TF-M target name, toolchain, delivery directory)
178139
"""
179-
tfm_secure_targets = _get_tfm_secure_targets()
140+
tfm_secure_targets = get_tfm_secure_targets()
180141
logging.info(
181142
"Found the following TF-M targets: {}".format(
182143
", ".join(tfm_secure_targets)
@@ -572,7 +533,7 @@ def _get_parser():
572533
"--mcu",
573534
help="Build for the given MCU",
574535
default=None,
575-
choices=_get_tfm_regression_targets(),
536+
choices=get_tfm_regression_targets(),
576537
)
577538

578539
hmsg = "Build for the given toolchain (default is tfm_default_toolchain)"
@@ -641,7 +602,7 @@ def _main():
641602
if args.list:
642603
logging.info(
643604
"Supported TF-M regression targets are: {}".format(
644-
", ".join([t for t in _get_tfm_regression_targets()])
605+
", ".join([t for t in get_tfm_regression_targets()])
645606
)
646607
)
647608
return

psa_builder.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
import requests
2626
from zipfile import ZipFile
2727

28+
try:
29+
import yaml
30+
except ImportError as e:
31+
print(str(e) + " To install it, type:")
32+
print("python3 -m pip install PyYAML")
33+
exit(1)
34+
35+
2836
upstream_tfm = "https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git"
2937
mbed_tfm = "https://github.com/ARMmbed/trusted-firmware-m.git"
3038

@@ -77,6 +85,8 @@
7785
TF_M_BUILD_DIR = join(mbed_path, TF_M_RELATIVE_PATH, "TARGET_IGNORE")
7886
POPEN_INSTANCE = None
7987

88+
from tools.targets import Target, TARGET_MAP, TARGET_NAMES
89+
8090

8191
def are_dependencies_installed():
8292
def _is_cmake_installed():
@@ -224,3 +234,34 @@ def exit_gracefully(signum, frame):
224234
pass
225235

226236
sys.exit(0)
237+
238+
239+
def get_tfm_secure_targets():
240+
"""
241+
Creates a list of TF-M secure targets from Mbed OS targets.json.
242+
243+
:return: List of TF-M secure targets.
244+
"""
245+
return [str(t) for t in TARGET_NAMES if Target.get_target(t).is_TFM_target]
246+
247+
248+
def get_tfm_regression_targets():
249+
"""
250+
Creates a list of TF-M regression tests supported targets
251+
This parses the yaml file for supported target names and compares them
252+
with TF-M targets supported in Mbed OS
253+
254+
:return: List of supported TF-M regression targets.
255+
"""
256+
with open(join(dirname(__file__), "tfm_ns_import.yaml")) as ns_import:
257+
yaml_data = yaml.safe_load(ns_import)
258+
mbed_os_data = yaml_data["mbed-os"]
259+
tfm_regression_data = yaml_data["tf-m-regression"]
260+
261+
regression_targets = list(
262+
set(get_tfm_secure_targets())
263+
& set(mbed_os_data)
264+
& set(tfm_regression_data)
265+
)
266+
267+
return regression_targets

test_psa_target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def _get_parser():
272272
"--mcu",
273273
help="Build for the given MCU",
274274
required=True,
275-
choices=["ARM_MUSCA_B1", "ARM_MUSCA_S1"],
275+
choices=get_tfm_regression_targets(),
276276
default=None,
277277
)
278278

0 commit comments

Comments
 (0)