Skip to content

Commit 6b56ea3

Browse files
authored
Merge pull request ARMmbed#82 from ARMmbed/new_sotp
FEATURE: Added SOTP
2 parents 0520d03 + cca2417 commit 6b56ea3

File tree

7 files changed

+126
-4
lines changed

7 files changed

+126
-4
lines changed

.mbedignore

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ mbed-os/rtos/*
33
mbed-os/events/*
44
mbed-os/features/FEATURE_LWIP/*
55
mbed-os/features/FEATURE_BLE/*
6-
mbed-os/features/FEATURE_COMMON_PAL/*
6+
mbed-os/features/FEATURE_COMMON_PAL/mbed-client-randlib/*
7+
mbed-os/features/FEATURE_COMMON_PAL/mbed-coap/*
8+
mbed-os/features/FEATURE_COMMON_PAL/nanostack-hal-mbed-cmsis-rtos/*
9+
mbed-os/features/FEATURE_COMMON_PAL/sal-stack-nanostack-eventloop/*
10+
mbed-os/features/FEATURE_COMMON_PAL/mbed-trace/source/*
11+
mbed-os/features/FEATURE_COMMON_PAL/mbed-trace/test/*
12+
mbed-os/features/FEATURE_COMMON_PAL/nanostack-libservice/source/*
13+
mbed-os/features/FEATURE_COMMON_PAL/nanostack-libservice/test/*
714
mbed-os/features/FEATURE_UVISOR/*
815
mbed-os/features/nanostack/*
916
mbed-os/features/netsocket/*
@@ -26,4 +33,26 @@ update-client-hub/modules/pal-filesystem/*
2633
update-client-hub/modules/pal-target-specific/*
2734
update-client-hub/modules/source-http/*
2835
update-client-hub/modules/source-manager/*
29-
update-client-hub/modules/common/source/arm_uc_scheduler.c
36+
update-client-hub/modules/common/source/arm_uc_scheduler.c
37+
mbed-client-pal/Test/*
38+
mbed-client-pal/Utils/*
39+
mbed-client-pal/Examples/*
40+
mbed-client-pal/Source/PAL-Impl/pal_init.c
41+
mbed-client-pal/Source/PAL-Impl/Modules/Crypto/*
42+
mbed-client-pal/Source/PAL-Impl/Modules/Networking/*
43+
mbed-client-pal/Source/PAL-Impl/Modules/RTOS/*
44+
mbed-client-pal/Source/PAL-Impl/Modules/TLS/*
45+
mbed-client-pal/Source/PAL-Impl/Modules/Update/*
46+
mbed-client-pal/Source/PAL-Impl/Modules/Storage/FileSystem/*
47+
mbed-client-pal/Source/Port/Reference-Impl/Lib_Specific/*
48+
mbed-client-pal/Source/Port/Reference-Impl/OS_Specific/FreeRTOS/*
49+
mbed-client-pal/Source/Port/Reference-Impl/OS_Specific/Linux/*
50+
mbed-client-pal/Source/Port/Reference-Impl/OS_Specific/mbedOS/Networking/*
51+
mbed-client-pal/Source/Port/Reference-Impl/OS_Specific/mbedOS/RTOS/*
52+
mbed-client-pal/Source/Port/Reference-Impl/OS_Specific/mbedOS/Update/*
53+
mbed-client-pal/Source/Port/Reference-Impl/OS_Specific/mbedOS/Storage/FileSystem/*
54+
mbed-client-esfs/Test/*
55+
mbed-client-esfs/Tools/*
56+
mbed-client-esfs/source/esfs.c
57+
mbed-client-esfs/source/esfs_file_name.c
58+
mbed-client-esfs/source/esfs_performance.c

mbed-client-esfs.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-client-esfs/#2b1c9bf3752307eb32eea6f502aede7b086e7649

mbed-client-pal.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-client-pal/#874ed03ef1be14a25191f3abb0fb566ffa4c3961

mbed_app.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"MAX_BOOT_RETRIES=3",
99
"ARM_UC_USE_PAL_CRYPTO=0",
1010
"Mutex=PlatformMutex",
11-
"ARM_UC_USE_PAL_BLOCKDEVICE"
11+
"ARM_UC_USE_PAL_BLOCKDEVICE=1",
12+
"PAL_USE_INTERNAL_FLASH=1",
13+
"PAL_THREAD_SAFETY=0",
14+
"ARM_UC_USE_SOTP=1"
1215
],
1316
"config": {
1417
"firmware_metadata_header_address": {

power_cut_test/test_mbed_app.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"ARM_UC_USE_PAL_CRYPTO=0",
1010
"BOOTLOADER_POWER_CUT_TEST=1",
1111
"Mutex=PlatformMutex",
12-
"ARM_UC_USE_PAL_BLOCKDEVICE"
12+
"ARM_UC_USE_PAL_BLOCKDEVICE=1",
13+
"PAL_USE_INTERNAL_FLASH=1",
14+
"PAL_THREAD_SAFETY=0"
1315
],
1416
"config": {
1517
"firmware_metadata_header_address": {

source/example_insecure_rot.c

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

19+
#if !defined(ARM_UC_USE_SOTP) || ARM_UC_USE_SOTP == 0
20+
1921
#include <inttypes.h>
2022
#include <stddef.h>
2123

@@ -51,3 +53,5 @@ int8_t mbed_cloud_client_get_rot_128bit(uint8_t *key_buf, uint32_t length)
5153

5254
return 0;
5355
}
56+
57+
#endif // #if !defined(ARM_UC_USE_SOTP) || ARM_UC_USE_SOTP == 0

source/sotp_rot.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// ----------------------------------------------------------------------------
2+
// Copyright 2016-2017 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_UC_USE_SOTP) && ARM_UC_USE_SOTP == 1
20+
21+
#include <inttypes.h>
22+
#include <stddef.h>
23+
#include <string.h>
24+
#include "pal.h"
25+
#include "sotp.h"
26+
27+
#define DEVICE_KEY_SIZE_IN_BYTES (128/8)
28+
29+
/* We can get the RoT from SOTP using either sotp_probe (when ARM_UC_SOTP_PROBE_ONLY is defined to 1)
30+
* or the "regular" sotp_get function (when ARM_UC_SOTP_PROBE_ONLY is not defined or is defined to 0)
31+
*/
32+
#if defined(ARM_UC_SOTP_PROBE_ONLY) && ARM_UC_SOTP_PROBE_ONLY == 1
33+
#define SOTP_GET_FUNCTION sotp_probe
34+
#else
35+
#define SOTP_GET_FUNCTION sotp_get
36+
#endif
37+
38+
/**
39+
* @brief Function to get the device root of trust
40+
* @details The device root of trust should be a 128 bit value. It should never leave the device.
41+
* It should be unique to the device. It should have enough entropy to avoid contentional
42+
* entropy attacks. The porter should implement the following device signature to provide
43+
* device root of trust on different platforms.
44+
*
45+
* @param key_buf buffer to be filled with the device root of trust.
46+
* @param length length of the buffer provided to make sure no overflow occurs.
47+
*
48+
* @return 0 on success, non-zero on failure.
49+
*/
50+
51+
int8_t mbed_cloud_client_get_rot_128bit(uint8_t *key_buf, uint32_t length)
52+
{
53+
static bool initialized = false;
54+
uint32_t rot[DEVICE_KEY_SIZE_IN_BYTES / sizeof(uint32_t)];
55+
uint16_t actual_len_bytes = 0;
56+
sotp_result_e status = SOTP_NOT_FOUND;
57+
58+
if (length < DEVICE_KEY_SIZE_IN_BYTES || key_buf == NULL)
59+
{
60+
return -1;
61+
}
62+
63+
if (!initialized)
64+
{
65+
#if !defined(ARM_UC_SOTP_PROBE_ONLY) || ARM_UC_SOTP_PROBE_ONLY == 0 // sotp_probe doesn't need sotp_init()
66+
if (pal_internalFlashInit() != PAL_SUCCESS)
67+
{
68+
return -1;
69+
}
70+
#endif
71+
initialized = true;
72+
}
73+
status = SOTP_GET_FUNCTION(SOTP_TYPE_ROT, DEVICE_KEY_SIZE_IN_BYTES, rot, &actual_len_bytes);
74+
if (status != SOTP_SUCCESS || actual_len_bytes != DEVICE_KEY_SIZE_IN_BYTES)
75+
{
76+
return -1;
77+
}
78+
memcpy(key_buf, rot, DEVICE_KEY_SIZE_IN_BYTES);
79+
return 0;
80+
}
81+
82+
#endif // #if defined(ARM_UC_USE_SOTP) && ARM_UC_USE_SOTP == 1

0 commit comments

Comments
 (0)