Skip to content

Commit 39c36c7

Browse files
authored
Direct access rot rebased (ARMmbed#158)
* Add direct root access functions for getting RoT from kvstore. * Use naming consistent with cloud client configs * Change configs to use kvstore
1 parent 7a4078f commit 39c36c7

13 files changed

+111
-134
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def bootloaderBuildStep(stepName,
179179
def build_test_config = [
180180
"K64F": [
181181
"mbed_app.json",
182-
"configs/internal_flash_nvstore.json",
182+
"configs/internal_flash_kvstore.json",
183183
"configs/internal_flash_fake_rot.json"],
184184
"NUCLEO_F429ZI": ["mbed_app.json"],
185185
"UBLOX_EVK_ODIN_W2": ["mbed_app.json"],

configs/block_device_fake_rot.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
],
66
"target_overrides": {
77
"*": {
8-
"target.features_remove" : ["LWIP", "STORAGE"],
98
"platform.stdio-baud-rate" : 115200,
109
"platform.stdio-flush-at-exit" : false,
1110
"update-client.firmware-header-version": "2",
1211
"target.components_add" : ["SD"],
1312
"sd.CRC_ENABLED" : 0,
14-
"mbed-bootloader.use-nvstore-rot" : 0,
13+
"mbed-bootloader.use-kvstore-rot" : 0,
1514
"update-client.storage-address" : "(1024*1024*64)",
1615
"update-client.storage-size" : "(1024*1024*2)",
1716
"update-client.storage-locations" : 1

configs/internal_flash_fake_rot.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"platform.stdio-baud-rate": 115200,
88
"platform.stdio-flush-at-exit": false,
99
"update-client.firmware-header-version": "2",
10-
"mbed-bootloader.use-nvstore-rot": 0
10+
"mbed-bootloader.use-kvstore-rot": 0
1111
},
1212
"K64F": {
1313
"update-client.application-details" : "( 40*1024)",

configs/internal_flash_nvstore.json renamed to configs/internal_flash_kvstore.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
"update-client.firmware-header-version": "2"
1010
},
1111
"K64F": {
12-
"nvstore.area_1_address" : "( 32*1024)",
13-
"nvstore.area_1_size" : "( 4*1024)",
14-
"nvstore.area_2_address" : "( 36*1024)",
15-
"nvstore.area_2_size" : "( 4*1024)",
12+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+32*1024)",
13+
"storage_filesystem.rbp_internal_size" : "(2*4*1024)",
1614
"update-client.application-details" : "( 40*1024)",
1715
"mbed-bootloader.application-start-address": "( 41*1024)",
1816
"mbed-bootloader.max-application-size" : "(MBED_CONF_UPDATE_CLIENT_STORAGE_ADDRESS-MBED_CONF_MBED_BOOTLOADER_APPLICATION_START_ADDRESS)",

configs/test_configs/header_separate_after_app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"update-client.storage-locations": 1,
1313
"update-client.firmware-header-version": "2",
1414
"sd.CRC_ENABLED": 0,
15-
"mbed-bootloader.use-nvstore-rot": 0
15+
"mbed-bootloader.use-kvstore-rot": 0
1616
},
1717
"K64F": {
1818
"update-client.application-details" : "(FLASH_START_ADDRESS+1020*1024)",

configs/test_configs/header_separate_before_app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"update-client.storage-locations": 1,
1313
"update-client.firmware-header-version": "2",
1414
"sd.CRC_ENABLED": 0,
15-
"mbed-bootloader.use-nvstore-rot": 0
15+
"mbed-bootloader.use-kvstore-rot": 0
1616
},
1717
"K64F": {
1818
"update-client.application-details" : "(FLASH_START_ADDRESS+32*1024)",

configs/test_configs/power_cut_test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"update-client.storage-locations": 1,
1414
"update-client.firmware-header-version": "2",
1515
"sd.CRC_ENABLED": 0,
16-
"mbed-bootloader.use-nvstore-rot": 0
16+
"mbed-bootloader.use-kvstore-rot": 0
1717
},
1818
"K64F": {
1919
"update-client.application-details" : "128*1024",

mbed-os.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os/#6a0a86538c0b9b2bfcc4583b1e2b7fea8f4e71e9
1+
https://github.com/ARMmbed/mbed-os/#41ecde9c30842a9f2f93a7b1542ea414709a90cb

mbed_app.json

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,24 @@
1313
"update-client.storage-locations": 1,
1414
"update-client.firmware-header-version": "2",
1515
"target.components_add": ["SD"],
16-
"sd.CRC_ENABLED": 0
16+
"sd.CRC_ENABLED": 0,
17+
"storage.storage_type": "FILESYSTEM"
1718
},
1819
"K64F": {
19-
"nvstore.area_1_address" : "(FLASH_START_ADDRESS+32*1024)",
20-
"nvstore.area_1_size" : "(4*1024)",
21-
"nvstore.area_2_address" : "(FLASH_START_ADDRESS+36*1024)",
22-
"nvstore.area_2_size" : "(4*1024)",
20+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+32*1024)",
21+
"storage_filesystem.rbp_internal_size" : "(2*4*1024)",
2322
"update-client.application-details" : "(FLASH_START_ADDRESS+40*1024)",
2423
"mbed-bootloader.application-start-address": "(FLASH_START_ADDRESS+41*1024)"
2524
},
2625
"K66F": {
27-
"nvstore.area_1_address" : "(FLASH_START_ADDRESS+32*1024)",
28-
"nvstore.area_1_size" : "(4*1024)",
29-
"nvstore.area_2_address" : "(FLASH_START_ADDRESS+36*1024)",
30-
"nvstore.area_2_size" : "(4*1024)",
26+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+32*1024)",
27+
"storage_filesystem.rbp_internal_size" : "(2*4*1024)",
3128
"update-client.application-details" : "(FLASH_START_ADDRESS+40*1024)",
3229
"mbed-bootloader.application-start-address": "(FLASH_START_ADDRESS+41*1024)"
3330
},
3431
"KW24D": {
35-
"nvstore.area_1_address" : "(FLASH_START_ADDRESS+32*1024)",
36-
"nvstore.area_1_size" : "(2*1024)",
37-
"nvstore.area_2_address" : "(FLASH_START_ADDRESS+34*1024)",
38-
"nvstore.area_2_size" : "(2*1024)",
32+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+32*1024)",
33+
"storage_filesystem.rbp_internal_size" : "(2*2*1024)",
3934
"update-client.application-details" : "(FLASH_START_ADDRESS+36*1024)",
4035
"mbed-bootloader.application-start-address": "(FLASH_START_ADDRESS+37*1024)",
4136
"sd.SPI_CS" : "PTC4",
@@ -44,34 +39,26 @@
4439
"sd.SPI_CLK" : "PTC5"
4540
},
4641
"NUCLEO_L476RG": {
47-
"nvstore.area_1_address" : "(FLASH_START_ADDRESS+32*1024)",
48-
"nvstore.area_1_size" : "(2*1024)",
49-
"nvstore.area_2_address" : "(FLASH_START_ADDRESS+34*1024)",
50-
"nvstore.area_2_size" : "(2*1024)",
42+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+32*1024)",
43+
"storage_filesystem.rbp_internal_size" : "(2*2*1024)",
5144
"update-client.application-details" : "(FLASH_START_ADDRESS+36*1024)",
5245
"mbed-bootloader.application-start-address": "(FLASH_START_ADDRESS+38*1024)"
5346
},
5447
"DISCO_L476VG": {
55-
"nvstore.area_1_address" : "(FLASH_START_ADDRESS+32*1024)",
56-
"nvstore.area_1_size" : "(2*1024)",
57-
"nvstore.area_2_address" : "(FLASH_START_ADDRESS+34*1024)",
58-
"nvstore.area_2_size" : "(2*1024)",
48+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+32*1024)",
49+
"storage_filesystem.rbp_internal_size" : "(2*2*1024)",
5950
"update-client.application-details" : "(FLASH_START_ADDRESS+36*1024)",
6051
"mbed-bootloader.application-start-address": "(FLASH_START_ADDRESS+38*1024)"
6152
},
6253
"DISCO_L475VG_IOT01A": {
63-
"nvstore.area_1_address" : "(FLASH_START_ADDRESS+32*1024)",
64-
"nvstore.area_1_size" : "(2*1024)",
65-
"nvstore.area_2_address" : "(FLASH_START_ADDRESS+34*1024)",
66-
"nvstore.area_2_size" : "(2*1024)",
54+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+32*1024)",
55+
"storage_filesystem.rbp_internal_size" : "(2*2*1024)",
6756
"update-client.application-details" : "(FLASH_START_ADDRESS+36*1024)",
6857
"mbed-bootloader.application-start-address": "(FLASH_START_ADDRESS+38*1024)"
6958
},
7059
"NUCLEO_F411RE": {
71-
"nvstore.area_1_address" : "(FLASH_START_ADDRESS+32*1024)",
72-
"nvstore.area_1_size" : "(16*1024)",
73-
"nvstore.area_2_address" : "(FLASH_START_ADDRESS+48*1024)",
74-
"nvstore.area_2_size" : "(16*1024)",
60+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+32*1024)",
61+
"storage_filesystem.rbp_internal_size" : "(2*16*1024)",
7562
"update-client.application-details" : "(FLASH_START_ADDRESS+64*1024)",
7663
"mbed-bootloader.application-start-address": "(FLASH_START_ADDRESS+65*1024)",
7764
"sd.SPI_CS" : "PB_9",
@@ -80,18 +67,14 @@
8067
"sd.SPI_CLK" : "PC_7"
8168
},
8269
"NUCLEO_F429ZI": {
83-
"nvstore.area_1_address" : "(FLASH_START_ADDRESS+32*1024)",
84-
"nvstore.area_1_size" : "(16*1024)",
85-
"nvstore.area_2_address" : "(FLASH_START_ADDRESS+48*1024)",
86-
"nvstore.area_2_size" : "(16*1024)",
70+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+32*1024)",
71+
"storage_filesystem.rbp_internal_size" : "(2*16*1024)",
8772
"update-client.application-details" : "(FLASH_START_ADDRESS+64*1024)",
8873
"mbed-bootloader.application-start-address": "(FLASH_START_ADDRESS+65*1024)"
8974
},
9075
"NUCLEO_F207ZG": {
91-
"nvstore.area_1_address" : "(FLASH_START_ADDRESS+32*1024)",
92-
"nvstore.area_1_size" : "(16*1024)",
93-
"nvstore.area_2_address" : "(FLASH_START_ADDRESS+48*1024)",
94-
"nvstore.area_2_size" : "(16*1024)",
76+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+32*1024)",
77+
"storage_filesystem.rbp_internal_size" : "(2*16*1024)",
9578
"update-client.application-details" : "(FLASH_START_ADDRESS+64*1024)",
9679
"mbed-bootloader.application-start-address": "(FLASH_START_ADDRESS+65*1024)",
9780
"sd.SPI_MOSI" : "PC_12",
@@ -101,26 +84,20 @@
10184
},
10285
"UBLOX_EVK_ODIN_W2": {
10386
"target.device_has_remove": ["EMAC"],
104-
"nvstore.area_1_address" : "(FLASH_START_ADDRESS+32*1024)",
105-
"nvstore.area_1_size" : "(16*1024)",
106-
"nvstore.area_2_address" : "(FLASH_START_ADDRESS+48*1024)",
107-
"nvstore.area_2_size" : "(16*1024)",
87+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+32*1024)",
88+
"storage_filesystem.rbp_internal_size" : "(2*16*1024)",
10889
"update-client.application-details" : "(FLASH_START_ADDRESS+64*1024)",
10990
"mbed-bootloader.application-start-address": "(FLASH_START_ADDRESS+65*1024)"
11091
},
11192
"UBLOX_C030_U201": {
112-
"nvstore.area_1_address" : "(FLASH_START_ADDRESS+32*1024)",
113-
"nvstore.area_1_size" : "(16*1024)",
114-
"nvstore.area_2_address" : "(FLASH_START_ADDRESS+48*1024)",
115-
"nvstore.area_2_size" : "(16*1024)",
93+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+32*1024)",
94+
"storage_filesystem.rbp_internal_size" : "(2*16*1024)",
11695
"update-client.application-details" : "(FLASH_START_ADDRESS+64*1024)",
11796
"mbed-bootloader.application-start-address": "(FLASH_START_ADDRESS+65*1024)"
11897
},
11998
"NRF52840_DK": {
120-
"nvstore.area_1_address" : "(FLASH_START_ADDRESS+1024*1016)",
121-
"nvstore.area_1_size" : "(4*1024)",
122-
"nvstore.area_2_address" : "(FLASH_START_ADDRESS+1024*1020)",
123-
"nvstore.area_2_size" : "(4*1024)",
99+
"storage_filesystem.internal_base_address" : "(FLASH_START_ADDRESS+1024*1016)",
100+
"storage_filesystem.rbp_internal_size" : "(2*4*1024)",
124101
"update-client.application-details" : "(FLASH_START_ADDRESS+236*1024)",
125102
"mbed-bootloader.application-start-address": "(FLASH_START_ADDRESS+237*1024)",
126103
"target.OUTPUT_EXT" : "hex",

mbed_lib.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
"value": 1,
3939
"macro_name": "SHOW_PROGRESS_BAR"
4040
},
41-
"use-nvstore-rot": {
41+
"use-kvstore-rot": {
4242
"help": "use nvstore implementation of the ROT to authenticate firmware headers",
4343
"value": 1,
44-
"macro_name": "ARM_BOOTLOADER_USE_NVSTORE_ROT"
44+
"macro_name": "ARM_BOOTLOADER_USE_KVSTORE_ROT"
4545
}
4646
},
4747
"macros": [

source/example_insecure_rot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// limitations under the License.
1717
// ----------------------------------------------------------------------------
1818

19-
#if !defined(ARM_BOOTLOADER_USE_NVSTORE_ROT) || ARM_BOOTLOADER_USE_NVSTORE_ROT == 0
19+
#if !defined(ARM_BOOTLOADER_USE_KVSTORE_ROT) || ARM_BOOTLOADER_USE_KVSTORE_ROT == 0
2020

2121
#include <inttypes.h>
2222
#include <stddef.h>
@@ -52,4 +52,4 @@ int8_t mbed_cloud_client_get_rot_128bit(uint8_t *key_buf, uint32_t length)
5252
return 0;
5353
}
5454

55-
#endif // #if !defined(ARM_BOOTLOADER_USE_NVSTORE_ROT) || ARM_BOOTLOADER_USE_NVSTORE_ROT == 0
55+
#endif // #if !defined(ARM_BOOTLOADER_USE_KVSTORE_ROT) || ARM_BOOTLOADER_USE_KVSTORE_ROT == 0

source/kvstore_rot.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// ----------------------------------------------------------------------------
2+
// Copyright 2019 ARM Ltd.
3+
//
4+
// SPDX-License-Identifier: Apache-2.0
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
// ----------------------------------------------------------------------------
18+
19+
#if defined(ARM_BOOTLOADER_USE_KVSTORE_ROT) && ARM_BOOTLOADER_USE_KVSTORE_ROT == 1
20+
21+
#include <inttypes.h>
22+
#include <stddef.h>
23+
#include "DirectAccessDevicekey.h"
24+
25+
#define DEVICE_KEY_SIZE_IN_BYTES (128/8)
26+
27+
/**
28+
* @brief Function to get the device root of trust
29+
* @details The device root of trust should be a 128 bit value. It should never leave the device.
30+
* It should be unique to the device. It should have enough entropy to avoid conventional
31+
* entropy attacks. The porter should implement the following device signature to provide
32+
* device root of trust on different platforms.
33+
*
34+
* @param key_buf buffer to be filled with the device root of trust.
35+
* @param length length of the buffer provided to make sure no overflow occurs.
36+
*
37+
* @return 0 on success, non-zero on failure.
38+
*/
39+
extern "C" int8_t mbed_cloud_client_get_rot_128bit(uint8_t *key_buf, uint32_t length)
40+
{
41+
int8_t error = 0;
42+
uint32_t tdb_start_offset = 0;
43+
uint32_t tdb_end_offset = 0;
44+
size_t actual_len_bytes = 0;
45+
46+
// Check params
47+
if (length < DEVICE_KEY_SIZE_IN_BYTES || key_buf == NULL) {
48+
error = -1;
49+
}
50+
51+
// Get TDB parameters
52+
if (error == 0) {
53+
error = get_expected_internal_TDBStore_position(&tdb_start_offset,
54+
&tdb_end_offset);
55+
}
56+
57+
// Read ROT
58+
if (error == 0) {
59+
error = direct_access_to_devicekey(tdb_start_offset,
60+
tdb_end_offset,
61+
key_buf,
62+
DEVICE_KEY_SIZE_IN_BYTES,
63+
&actual_len_bytes);
64+
if (actual_len_bytes != DEVICE_KEY_SIZE_IN_BYTES) {
65+
error = -1;
66+
}
67+
}
68+
69+
return error;
70+
}
71+
72+
#endif // #if defined(ARM_BOOTLOADER_USE_KVSTORE_ROT) && ARM_BOOTLOADER_USE_KVSTORE_ROT == 1

source/nvstore_rot.cpp

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)