Skip to content

Commit 498db1c

Browse files
authored
Merge pull request #72 from LDong-Arm/generate_rot
Generate DeviceKey Root of Trust, update Mbed CLI 2 support
2 parents 0fb9be3 + f3c52be commit 498db1c

File tree

4 files changed

+64
-32
lines changed

4 files changed

+64
-32
lines changed

.travis.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,11 @@ matrix:
7474
# version, we must instead delete the Travis copy of CMake.
7575
- sudo rm -rf /usr/local/cmake*
7676
- pip install --upgrade mbed-tools
77-
- pip install prettytable==0.7.2
78-
- pip install future==0.16.0
79-
- pip install "Jinja2>=2.10.1,<2.11"
80-
- pip install "intelhex>=1.3,<=2.2.1"
77+
- mbedtools deploy
78+
- pip install -r mbed-os/tools/cmake/requirements.txt
8179
script:
82-
- mbedtools checkout
83-
- echo mbedtools build -t GCC_ARM -m ${TARGET_NAME} -b ${PROFILE}
84-
- mbedtools build -t GCC_ARM -m ${TARGET_NAME} -b ${PROFILE}
80+
- echo mbedtools compile -t GCC_ARM -m ${TARGET_NAME} -b ${PROFILE}
81+
- mbedtools compile -t GCC_ARM -m ${TARGET_NAME} -b ${PROFILE}
8582
- ccache -s
8683

8784
- <<: *cmake-build-test

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ add_subdirectory(${MBED_PATH})
1313

1414
add_executable(${APP_TARGET})
1515

16-
mbed_configure_app_target(${APP_TARGET})
17-
1816
project(${APP_TARGET})
1917

2018
target_sources(${APP_TARGET}

README.md

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,62 @@ The application injects a dummy root of trust (ROT) if true random number genera
1212
* An mbed-os supported development board.
1313
* A micro-USB cable.
1414

15-
**NOTE:** Currently this application defines settings only for K66F board. Please refer to [Storage Configuration](https://os.mbed.com/docs/mbed-os/latest/reference/storage.html) from Mbed OS documentation as the DeviceKey requires KVStore to be configured.
15+
## Mbed OS build tools
1616

17-
## Getting started ##
17+
### Mbed CLI 2
18+
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).
19+
1. [Install Mbed CLI 2](https://os.mbed.com/docs/mbed-os/latest/build-tools/install-or-upgrade.html).
20+
1. From the command-line, import the example: `mbed-tools import mbed-os-example-devicekey`
21+
1. Change the current directory to where the project was imported.
1822

19-
1. Import the example.
23+
### Mbed CLI 1
24+
1. [Install Mbed CLI 1](https://os.mbed.com/docs/mbed-os/latest/quick-start/offline-with-mbed-cli.html).
25+
1. From the command-line, import the example: `mbed import mbed-os-example-devicekey`
26+
1. Change the current directory to where the project was imported.
2027

21-
```
22-
mbed import mbed-os-example-devicekey
23-
cd mbed-os-example-devicekey
24-
```
28+
## Building and running
2529

26-
2. Compile and generate binary.
30+
1. Connect a USB cable between the USB port on the target and the host computer.
31+
1. Run the following command to build the example project and program the microcontroller flash memory:
2732

28-
For example, for `GCC`:
33+
* Mbed CLI 2
2934

35+
```bash
36+
$ mbed-tools compile -m <TARGET> -t <TOOLCHAIN> --flash --sterm
3037
```
31-
mbed compile -t GCC_ARM -m <your device>
38+
39+
* Mbed CLI 1
40+
41+
```bash
42+
$ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash --sterm
3243
```
33-
34-
3. Open a serial console session with the target platform using the following parameters:
3544

36-
* **Baud rate:** 9600
37-
* **Data bits:** 8
38-
* **Stop bits:** 1
39-
* **Parity:** None
45+
Your PC may take a few minutes to compile your code.
46+
47+
The binary is located at:
48+
49+
* **Mbed CLI 2** -
50+
`./cmake_build/<TARGET>/develop/<TOOLCHAIN>/mbed-os-example-devicekey.bin`
4051

41-
5. Copy the application `mbed-os-example-devicekey.bin` in the folder `mbed-os-example-devicekey/BUILD/<TARGET NAME>/<PLATFORM NAME>` onto the target board.
52+
* **Mbed CLI 1** - `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-devicekey.bin`.
4253

43-
6. Press the **RESET** button on the board to run the program
54+
You can manually copy the binary to the target, which gets mounted on the host
55+
computer through USB, rather than using the `--flash` option.
56+
57+
You can also open a serial terminal separately, rather than using the `--sterm`
58+
option, with the following command:
59+
60+
* Mbed CLI 2
61+
```bash
62+
$ mbed-tools sterm
63+
```
64+
65+
* Mbed CLI 1
66+
```bash
67+
$ mbed sterm
68+
```
4469

45-
7. The serial console should now display a series of results.
70+
The expected log can be found in [`tests/devicekey.log`](tests/devicekey.log).
4671

4772
## Troubleshooting
4873

main.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,27 @@ int main()
5656
//If TRNG is not available it is a must to inject the ROT before the first call to derive key method.
5757
printf("\n--- No TRNG support for this device. injecting ROT. ---\n");
5858
ret = inject_rot_key();
59-
if (DEVICEKEY_SUCCESS != ret && DEVICEKEY_ALREADY_EXIST != ret) {
60-
printf("\n--- Error, injection of ROT key has failed with status %d ---\n", ret);
59+
if (DEVICEKEY_ALREADY_EXIST == ret) {
60+
printf("\n--- ROT Key already exists in the persistent memory. ---\n", ret);
61+
} else if (DEVICEKEY_SUCCESS == ret) {
62+
printf("\n--- ROT Key injected and stored in persistent memory. ---\n", ret);
63+
} else {
64+
printf("--- Error, injection of RoT key failed with error code %d ---\n", ret);
6165
return -1;
6266
}
6367

64-
if ( DEVICEKEY_ALREADY_EXIST == ret ) {
68+
#else
69+
70+
// The ROT must be present before the first call to derive key method.
71+
printf("\n--- Generating ROT. ---\n");
72+
ret = devkey.generate_root_of_trust();
73+
if (DEVICEKEY_ALREADY_EXIST == ret) {
6574
printf("\n--- ROT Key already exists in the persistent memory. ---\n", ret);
75+
} else if (DEVICEKEY_SUCCESS == ret) {
76+
printf("\n--- ROT Key generated and stored in persistent memory. ---\n", ret);
6677
} else {
67-
printf("\n--- ROT Key injected and stored in persistent memory. ---\n", ret);
78+
printf("--- Error, generation of RoT key failed with error code %d ---\n", ret);
79+
return -1;
6880
}
6981

7082
#endif

0 commit comments

Comments
 (0)