Skip to content

Commit 2179cf5

Browse files
committed
Support Mbed CLI 2
This commit adds `CMakeLists.txt` to support Mbed CLI 2, updates `README.md` to document this and adds an option `--cli=2` to `test_psa_target.py`. Note that the Arm toolchain name has been changed from ARMC6 to ARM because `mbed-tools` does not recognise `-t ARMC6`. However, the existing toolchain checking TOOLCHAIN_CLASSES["ARM"].check_executable() still assumes "ARM" to be Arm Compiler 5 and reports a failure, so we have to remove the check and rely on the TF-M and Mbed OS build systems to do the check.
1 parent 328ea8e commit 2179cf5

File tree

5 files changed

+182
-21
lines changed

5 files changed

+182
-21
lines changed

CMakeLists.txt

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
5+
6+
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "")
7+
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
8+
set(APP_TARGET mbed-os-tf-m-regression-tests)
9+
10+
include(${MBED_PATH}/tools/cmake/app.cmake)
11+
12+
add_subdirectory(${MBED_PATH})
13+
14+
add_executable(${APP_TARGET})
15+
16+
project(${APP_TARGET})
17+
18+
target_sources(${APP_TARGET}
19+
PRIVATE
20+
main.cpp
21+
)
22+
23+
# Note: This is needed because TARGET_** is part of a list instead
24+
# of a standalone variable, and it controls the path visibility
25+
# for Mbed CLI 1. Once Mbed CLI 1 is deprecated, we can simplify
26+
# the path to tfm/targets/${APP_TARGET}/device.
27+
if(${MBED_TARGET} STREQUAL "ARM_MUSCA_B1")
28+
set(TFM_TARGET_INCLUDE tfm/targets/TARGET_ARM_SSG/TARGET_MUSCA_B1/device)
29+
elseif(${MBED_TARGET} STREQUAL "ARM_MUSCA_S1")
30+
set(TFM_TARGET_INCLUDE tfm/targets/TARGET_ARM_SSG/TARGET_MUSCA_S1/device)
31+
else()
32+
message(FATAL_ERROR "Unsupported target ${MBED_TARGET}")
33+
endif()
34+
35+
target_include_directories(${APP_TARGET}
36+
PRIVATE
37+
tfm/platform/include
38+
${TFM_TARGET_INCLUDE}
39+
test/inc
40+
)
41+
42+
target_link_libraries(${APP_TARGET}
43+
PRIVATE
44+
mbed-os
45+
mbed-psa
46+
mbed-greentea
47+
)
48+
49+
if ("${MBED_CONFIG_DEFINITIONS}" MATCHES "MBED_CONF_APP_REGRESSION_TEST=1")
50+
set(TEST_LIBS
51+
# Note: To link successfully the order is important and reflects dependency.
52+
# In general: test entry point -> suites -> platform -> utilities.
53+
tfm_test_suite_core_ns
54+
tfm_test_suite_attestation_ns
55+
tfm_test_suite_crypto_ns
56+
tfm_test_suite_ipc_ns
57+
tfm_test_suite_its_ns
58+
tfm_test_suite_platform_ns
59+
tfm_test_suite_ps_ns
60+
tfm_test_suite_qcbor_ns
61+
tfm_test_suite_t_cose_ns
62+
tfm_qcbor_test
63+
tfm_t_cose_test
64+
platform_ns
65+
psa_api_ns
66+
tfm_ns_integration_test
67+
tfm_qcbor
68+
tfm_t_cose
69+
)
70+
elseif ("${MBED_CONFIG_DEFINITIONS}" MATCHES "MBED_CONF_APP_PSA_COMPLIANCE_TEST=1")
71+
set(TEST_LIBS
72+
val_nspe
73+
pal_nspe
74+
test_combine
75+
)
76+
else()
77+
message(FATAL_ERROR "No test enabled in mbed_app.json")
78+
endif()
79+
80+
# Note: The path transformation is required because `.ar` is not
81+
# recognized by `-l<name>` of either toolchains. This extension
82+
# is a legacy of Mbed CLI 1. In the future we should use `.a` for
83+
# both toolchains, and take advantage of target_link_directories()
84+
# so each `lib<name>.a` simply becomes `<name>` in target_link_libraries().
85+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
86+
set(LIB_SUFFIX ".a")
87+
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
88+
set(LIB_SUFFIX ".ar")
89+
else()
90+
message(FATAL_ERROR "Unsupported toolchain ${MBED_TOOLCHAIN}")
91+
endif()
92+
93+
list(TRANSFORM TEST_LIBS
94+
PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/test/lib/TOOLCHAIN_${MBED_TOOLCHAIN}/lib"
95+
)
96+
97+
list(TRANSFORM TEST_LIBS
98+
APPEND "${LIB_SUFFIX}"
99+
)
100+
101+
target_link_libraries(${APP_TARGET}
102+
PUBLIC
103+
${TEST_LIBS}
104+
)
105+
106+
mbed_set_post_build(${APP_TARGET})
107+
108+
option(VERBOSE_BUILD "Have a verbose build process")
109+
if(VERBOSE_BUILD)
110+
set(CMAKE_VERBOSE_MAKEFILE ON)
111+
endif()

README.md

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,35 @@ for **TF-M v1.2** integrated with the **Mbed OS**.
66

77
## Prerequisites
88

9-
### Development environment
10-
119
We have provided a ready-to-use Vagrant virtual machine for building
1210
TF-M tests, see [`vagrant/README.md`](vagrant/README.md) for instructions.
1311

1412
If you prefer to build and run the tests directly on your host machine,
15-
ensure you have the following installed:
13+
please have the following set up.
14+
15+
### TF-M build environment
16+
17+
The following tools are needed for building TF-M:
1618
* Commands: see [`vagrant/bootstrap.sh`](./vagrant/bootstrap.sh) for Linux,
1719
or install equivalent packages for your operating system.
1820
* Python environment: see [`vagrant/bootstrap-user.sh`](./vagrant/bootstrap-user.sh).
1921
* One of the supported compilers: see "Compiler versions" on
2022
[Arm Mbed tools](https://os.mbed.com/docs/mbed-os/v6.7/build-tools/index.html).
2123
Make sure the compiler has been added to the `PATH` of your environment.
2224

25+
### Mbed OS build tools
26+
27+
#### Mbed CLI 2
28+
Starting with version 6.5, Mbed OS uses Mbed CLI 2. It uses Ninja as a build system, and CMake to generate the build environment and manage the build process in a compiler-independent manner. If you are working with Mbed OS version prior to 6.5 then check the section [Mbed CLI 1](#mbed-cli-1).
29+
1. [Install Mbed CLI 2](https://os.mbed.com/docs/mbed-os/latest/build-tools/install-or-upgrade.html).
30+
1. From the command-line, import the example: `mbed-tools import mbed-os-tf-m-regression-tests`
31+
1. Change the current directory to where the project was imported.
32+
33+
#### Mbed CLI 1
34+
1. [Install Mbed CLI 1](https://os.mbed.com/docs/mbed-os/latest/quick-start/offline-with-mbed-cli.html).
35+
1. From the command-line, import the example: `mbed import mbed-os-tf-m-regression-tests`
36+
1. Change the current directory to where the project was imported.
37+
2338
### Mbed initialization
2439

2540
Run `mbed deploy` to obtain Mbed OS for this application. Then run
@@ -92,14 +107,28 @@ Configure an appropriate test in the `config` section of `mbed_app.json`. If you
92107
*flash and run tests manually*, please set `wait-for-sync` to 0 so that tests start without
93108
waiting.
94109

95-
```
96-
mbed compile -m ARM_MUSCA_B1 -t GCC_ARM
97-
```
110+
Run one of the following commands to build the application
111+
112+
* Mbed CLI 2
113+
114+
```
115+
$ mbed-tools compile -m <TARGET> -t <TOOLCHAIN>
116+
```
117+
118+
* Mbed CLI 1
119+
120+
```bash
121+
$ mbed compile -m <TARGET> -t <TOOLCHAIN>
122+
```
123+
124+
The binary is located at:
125+
* **Mbed CLI 2** - `./cmake_build/<TARGET>/<PROFILE>/<TOOLCHAIN>/mbed-os-tf-m-regression-tests.bin`</br>
126+
* **Mbed CLI 1** - `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-tf-m-regression-tests.bin`
98127
99128
## Running the Mbed OS application manually
100129
101130
1. Connect your Mbed Enabled device to the computer over USB.
102-
1. Copy the binary or hex file to the Mbed device. The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-tf-m-regression-tests.[bin|hex]`.
131+
1. Copy the binary or hex file to the Mbed device.
103132
1. Connect to the Mbed Device using a serial client application of your choice.
104133
1. Press the reset button on the Mbed device to run the program.
105134
@@ -110,9 +139,17 @@ mbed compile -m ARM_MUSCA_B1 -t GCC_ARM
110139
This will build and execute TF-M regression and PSA compliance tests with
111140
Mbed OS application, using the [Greentea](https://os.mbed.com/docs/mbed-os/v6.7/debug-test/greentea-for-testing-applications.html) test tool. Make sure the device is connected to your local machine.
112141
113-
```
114-
python3 test_psa_target.py -t GNUARM -m ARM_MUSCA_B1
115-
```
142+
* Mbed CLI 2
143+
144+
```
145+
python3 test_psa_target.py -t GNUARM -m ARM_MUSCA_B1 --cli=2
146+
```
147+
148+
* Mbed CLI 1
149+
150+
```
151+
python3 test_psa_target.py -t GNUARM -m ARM_MUSCA_B1
152+
```
116153
117154
**Notes**:
118155
* The tests cannot be run in the Vagrant

build_tfm.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import shutil
2626
import logging
2727
from psa_builder import *
28-
from tools.toolchains import TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
29-
from tools.targets import Target, TARGET_MAP, TARGET_NAMES
28+
from tools.toolchains import TOOLCHAIN_PATHS
29+
from tools.targets import TARGET_MAP
3030

3131
logging.basicConfig(
3232
level=logging.INFO,
@@ -109,11 +109,6 @@ def _get_target_info(target, toolchain=None):
109109
else:
110110
tc = TARGET_MAP[target].tfm_default_toolchain
111111

112-
global TC_DICT
113-
if not TOOLCHAIN_CLASSES[TC_DICT.get(tc)].check_executable():
114-
msg = "Toolchain %s was not found in PATH" % tc
115-
raise Exception(msg)
116-
117112
delivery_dir = join(
118113
mbed_path, "targets", TARGET_MAP[target].tfm_delivery_dir
119114
)

psa_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
},
7373
}
7474

75-
TC_DICT = {"ARMCLANG": "ARMC6", "GNUARM": "GCC_ARM"}
75+
TC_DICT = {"ARMCLANG": "ARM", "GNUARM": "GCC_ARM"}
7676

7777
SUPPORTED_TFM_PSA_CONFIGS = ["PsaApiTestIPC"]
7878
SUPPORTED_TFM_CONFIGS = [

test_psa_target.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ def _build_mbed_os(args):
7070
Build Mbed OS
7171
:param args: Command-line arguments
7272
"""
73+
build_tool = "mbed" if args.cli == 1 else "mbedtools"
7374
cmd = [
74-
"mbed",
75+
build_tool,
7576
"compile",
7677
"-m",
7778
args.mcu,
@@ -126,7 +127,11 @@ def _erase_flash_storage(args, suite):
126127
:param suite: Test suite
127128
:return: return binary name generated
128129
"""
129-
mbed_os_dir = join(ROOT, "BUILD", args.mcu, TC_DICT.get(args.toolchain))
130+
if args.cli == 1:
131+
mbed_os_dir = join(ROOT, "BUILD", args.mcu, TC_DICT.get(args.toolchain))
132+
else:
133+
mbed_os_dir = join(ROOT, "cmake_build", args.mcu, "develop", TC_DICT.get(args.toolchain))
134+
130135
cmd = []
131136

132137
binary_name = "mbed-os-tf-m-regression-tests-reset-flash-{}.hex".format(
@@ -242,12 +247,17 @@ def _get_test_spec(args, suite, binary_name):
242247
toolchain = TC_DICT.get(args.toolchain)
243248
log_path = join("test", "logs", target, "{}.log".format(suite))
244249

250+
if args.cli == 1:
251+
image_path = join(ROOT, "BUILD", target, toolchain, binary_name)
252+
else:
253+
image_path = join(ROOT, "cmake_build", target, "develop", toolchain, binary_name)
254+
245255
return {
246256
"binaries": [
247257
{
248258
"binary_type": "bootable",
249259
"path": normpath(
250-
join("BUILD/{}/{}".format(target, toolchain), binary_name)
260+
image_path
251261
),
252262
"compare_log": log_path,
253263
}
@@ -373,6 +383,14 @@ def _get_parser():
373383
default=False,
374384
)
375385

386+
parser.add_argument(
387+
"--cli",
388+
help="Build with the specified version of Mbed CLI",
389+
type=int,
390+
default=1,
391+
choices=[1, 2],
392+
)
393+
376394
return parser
377395

378396

0 commit comments

Comments
 (0)