Skip to content

Commit 4e6ed2b

Browse files
author
Oren Cohen
committed
[trusted-firmware-m]: Updated to 0101fd37
1 parent 4e720fd commit 4e6ed2b

37 files changed

+1189
-358
lines changed

components/TARGET_PSA/TARGET_TFM/COMPONENT_NSPE/interface/src/tfm_ns_lock_rtx.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
/*
2-
* Copyright (c) 2017-2018, Arm Limited. All rights reserved.
2+
* Copyright (c) 2017-2019, Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*
66
*/
77
#include <stdint.h>
88
#include <stdbool.h>
99

10-
#include "cmsis.h"
11-
#include "rtx_os.h"
1210
#include "cmsis_os2.h"
1311

1412
#include "tfm_api.h"
@@ -31,14 +29,9 @@ static struct ns_lock_state ns_lock = {.init=false, .id=NULL};
3129
/**
3230
* \brief Mutex properties, NS lock
3331
*/
34-
35-
static osRtxMutex_t ns_lock_cb = { 0 };
36-
3732
static const osMutexAttr_t ns_lock_attrib = {
3833
.name = "ns_lock",
39-
.attr_bits = osMutexPrioInherit,
40-
.cb_mem = &ns_lock_cb,
41-
.cb_size = sizeof(ns_lock_cb)
34+
.attr_bits = osMutexPrioInherit
4235
};
4336

4437
/**

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/bl2/include/boot_record.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Arm Limited. All rights reserved.
2+
* Copyright (c) 2018-2019, Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*
@@ -11,6 +11,8 @@
1111
#include <stdint.h>
1212
#include <stddef.h>
1313
#include <limits.h>
14+
#include "../ext/mcuboot/bootutil/include/bootutil/image.h"
15+
#include "../ext/mcuboot/include/flash_map/flash_map.h"
1416

1517
#ifdef __cplusplus
1618
extern "C" {
@@ -30,6 +32,16 @@ enum shared_memory_err_t {
3032
TLV_TYPE_MAX = INT_MAX
3133
};
3234

35+
/*!
36+
* \enum boot_status_err_t
37+
*
38+
* \brief Return values for saving boot status information to shared memory are
39+
*/
40+
enum boot_status_err_t {
41+
BOOT_STATUS_OK,
42+
BOOT_STATUS_ERROR,
43+
};
44+
3345
/*!
3446
* \brief Add a data item to the shared data area between bootloader and
3547
* runtime SW
@@ -43,10 +55,25 @@ enum shared_memory_err_t {
4355
*/
4456
enum shared_memory_err_t
4557
boot_add_data_to_shared_area(uint8_t major_type,
46-
uint8_t minor_type,
58+
uint16_t minor_type,
4759
size_t size,
4860
const uint8_t *data);
4961

62+
/*!
63+
* \brief Add an image's all boot status information to the shared data area
64+
* between bootloader and runtime SW
65+
*
66+
* \param[in] sw_module Identifier of the SW component
67+
* \param[in] hdr Pointer to the image header stored in RAM
68+
* \param[in] fap Pointer to the flash area where image is stored
69+
*
70+
* \return Returns error code as specified in \ref boot_status_err_t
71+
*/
72+
enum boot_status_err_t
73+
boot_save_boot_status(uint8_t sw_module,
74+
const struct image_header *hdr,
75+
const struct flash_area *fap);
76+
5077
#ifdef __cplusplus
5178
}
5279
#endif

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/bl2/include/tfm_boot_status.h

Lines changed: 159 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Arm Limited. All rights reserved.
2+
* Copyright (c) 2018-2019, Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*
@@ -16,43 +16,165 @@
1616
extern "C" {
1717
#endif
1818

19-
/* Major numbers to identify the consumer of shared data in runtime SW */
20-
#define TLV_MAJOR_CORE 0x0
21-
#define TLV_MAJOR_IAS 0x1
22-
23-
/* PSA Root of Trust */
24-
#define TLV_MINOR_IAS_PRoT_SHA256 0x00
25-
#define TLV_MINOR_IAS_PRoT_SW_VERSION 0x01
26-
#define TLV_MINOR_IAS_PRoT_EPOCH 0x02
27-
28-
/* Application Root of Trust */
29-
#define TLV_MINOR_IAS_ARoT_SHA256 0x03
30-
#define TLV_MINOR_IAS_ARoT_SW_VERSION 0x04
31-
#define TLV_MINOR_IAS_ARoT_EPOCH 0x05
32-
33-
/* Non-secure processing environment: single non-secure image */
34-
#define TLV_MINOR_IAS_NSPE_SHA256 0x06
35-
#define TLV_MINOR_IAS_NSPE_SW_VERSION 0x07
36-
#define TLV_MINOR_IAS_NSPE_EPOCH 0x08
37-
38-
/* ARoT + PRoT: single secure image */
39-
#define TLV_MINOR_IAS_S_SHA256 0x09
40-
#define TLV_MINOR_IAS_S_SW_VERSION 0x0a
41-
#define TLV_MINOR_IAS_S_EPOCH 0x0b
19+
/* Major numbers (4 bit) to identify
20+
* the consumer of shared data in runtime SW
21+
*/
22+
#define TLV_MAJOR_CORE 0x0
23+
#define TLV_MAJOR_IAS 0x1
4224

43-
/* S + NS: combined secure and non-secure image */
44-
#define TLV_MINOR_IAS_S_NS_SHA256 0x0c
45-
#define TLV_MINOR_IAS_S_NS_SW_VERSION 0x0d
46-
#define TLV_MINOR_IAS_S_NS_EPOCH 0x0e
25+
/**
26+
* The shared data between boot loader and runtime SW is TLV encoded. The
27+
* shared data is stored in a well known location in secure memory and this is
28+
* a contract between boot loader and runtime SW.
29+
*
30+
* The structure of shared data must be the following:
31+
* - At the beginning there must be a header: struct shared_data_tlv_header
32+
* This contains a magic number and a size field which covers the entire
33+
* size of the shared data area including this header.
34+
* - After the header there come the entries which are composed from an entry
35+
* header structure: struct shared_data_tlv_entry and the data. In the entry
36+
* header is a type field (tly_type) which identify the consumer of the
37+
* entry in the runtime SW and specify the subtype of that data item. There
38+
* is a size field (tlv_len) which covers the size of the entry header and
39+
* the data. After this structure comes the actual data.
40+
* - Arbitrary number and size of data entry can be in the shared memory area.
41+
*
42+
* This table gives of overview about the tlv_type field in the entry header.
43+
* The tlv_type always composed from a major and minor number. Major number
44+
* identifies the addressee in runtime SW, who should process the data entry.
45+
* Minor number used to encode more info about the data entry. The actual
46+
* definition of minor number could change per major number. In case of boot
47+
* status data, which is going to be processed by initial attestation service
48+
* the minor number is split further to two part: sw_module and claim. The
49+
* sw_module identifies the SW component in the system which the data item
50+
* belongs to and the claim part identifies the exact type of the data.
51+
*
52+
* |---------------------------------------|
53+
* | tlv_type (16) |
54+
* |---------------------------------------|
55+
* | tlv_major(4)| tlv_minor(12) |
56+
* |---------------------------------------|
57+
* | MAJOR_IAS | sw_module(6) | claim(6) |
58+
* |---------------------------------------|
59+
* | MAJOR_CORE | TBD |
60+
* |---------------------------------------|
61+
*/
4762

63+
/* Initial attestation: SW components / SW modules
64+
* This list is intended to be adjusted per device. It contains more SW
65+
* components than currently available in TF-M project. It serves as an example,
66+
* what kind of SW components might be available.
67+
*/
68+
#define SW_GENERAL 0x00
69+
#define SW_BL2 0x01
70+
#define SW_PROT 0x02
71+
#define SW_AROT 0x03
72+
#define SW_SPE 0x04
73+
#define SW_NSPE 0x05
74+
#define SW_S_NS 0x06
75+
#define SW_MAX 0x07
76+
77+
/* Initial attestation: Claim per SW components / SW modules */
78+
/* Bits: 0-2 */
79+
#define SW_VERSION 0x00
80+
#define SW_SIGNER_ID 0x01
81+
#define SW_EPOCH 0x02
82+
#define SW_TYPE 0x03
83+
/* Bits: 3-5 */
84+
#define SW_MEASURE_VALUE 0x08
85+
#define SW_MEASURE_TYPE 0x09
86+
87+
/* Initial attestation: General claim does not belong any particular SW
88+
* component. But they might be part of the boot status.
89+
*/
90+
#define BOOT_SEED 0x00
91+
#define HW_VERSION 0x01
92+
#define SECURITY_LIFECYCLE 0x02
93+
94+
/* Minor numbers (12 bit) to identify attestation service related data */
95+
#define TLV_MINOR_IAS_BOOT_SEED ((SW_GENERAL << 6) | BOOT_SEED)
96+
#define TLV_MINOR_IAS_HW_VERSION ((SW_GENERAL << 6) | HW_VERSION)
97+
#define TLV_MINOR_IAS_SLC ((SW_GENERAL << 6) | SECURITY_LIFECYCLE)
98+
99+
/* Bootloader - It can be more stage */
100+
#define TLV_MINOR_IAS_BL2_MEASURE_VALUE ((SW_BL2 << 6) | SW_MEASURE_VALUE)
101+
#define TLV_MINOR_IAS_BL2_MEASURE_TYPE ((SW_BL2 << 6) | SW_MEASURE_TYPE)
102+
#define TLV_MINOR_IAS_BL2_VERSION ((SW_BL2 << 6) | SW_VERSION)
103+
#define TLV_MINOR_IAS_BL2_SIGNER_ID ((SW_BL2 << 6) | SW_SIGNER_ID)
104+
#define TLV_MINOR_IAS_BL2_EPOCH ((SW_BL2 << 6) | SW_EPOCH)
105+
#define TLV_MINOR_IAS_BL2_TYPE ((SW_BL2 << 6) | SW_TYPE)
106+
107+
/* PROT: PSA Root of Trust */
108+
#define TLV_MINOR_IAS_PROT_MEASURE_VALUE ((SW_PROT << 6) | SW_MEASURE_VALUE)
109+
#define TLV_MINOR_IAS_PROT_MEASURE_TYPE ((SW_PROT << 6) | SW_MEASURE_TYPE)
110+
#define TLV_MINOR_IAS_PROT_VERSION ((SW_PROT << 6) | SW_VERSION)
111+
#define TLV_MINOR_IAS_PROT_SIGNER_ID ((SW_PROT << 6) | SW_SIGNER_ID)
112+
#define TLV_MINOR_IAS_PROT_EPOCH ((SW_PROT << 6) | SW_EPOCH)
113+
#define TLV_MINOR_IAS_PROT_TYPE ((SW_PROT << 6) | SW_TYPE)
114+
115+
/* AROT: Application Root of Trust */
116+
#define TLV_MINOR_IAS_AROT_MEASURE_VALUE ((SW_AROT << 6) | SW_MEASURE_VALUE)
117+
#define TLV_MINOR_IAS_AROT_MEASURE_TYPE ((SW_AROT << 6) | SW_MEASURE_TYPE)
118+
#define TLV_MINOR_IAS_AROT_VERSION ((SW_AROT << 6) | SW_VERSION)
119+
#define TLV_MINOR_IAS_AROT_SIGNER_ID ((SW_AROT << 6) | SW_SIGNER_ID)
120+
#define TLV_MINOR_IAS_AROT_EPOCH ((SW_AROT << 6) | SW_EPOCH)
121+
#define TLV_MINOR_IAS_AROT_TYPE ((SW_AROT << 6) | SW_TYPE)
122+
123+
/* Non-secure processing environment - single non-secure image */
124+
#define TLV_MINOR_IAS_NSPE_MEASURE_VALUE ((SW_NSPE << 6) | SW_MEASURE_VALUE)
125+
#define TLV_MINOR_IAS_NSPE_MEASURE_TYPE ((SW_NSPE << 6) | SW_MEASURE_TYPE)
126+
#define TLV_MINOR_IAS_NSPE_VERSION ((SW_NSPE << 6) | SW_VERSION)
127+
#define TLV_MINOR_IAS_NSPE_SIGNER_ID ((SW_NSPE << 6) | SW_SIGNER_ID)
128+
#define TLV_MINOR_IAS_NSPE_EPOCH ((SW_NSPE << 6) | SW_EPOCH)
129+
#define TLV_MINOR_IAS_NSPE_TYPE ((SW_NSPE << 6) | SW_TYPE)
130+
131+
/* Secure processing environment (ARoT + PRoT) - single secure image */
132+
#define TLV_MINOR_IAS_SPE_MEASURE_VALUE ((SW_SPE << 6) | SW_MEASURE_VALUE)
133+
#define TLV_MINOR_IAS_SPE_MEASURE_TYPE ((SW_SPE << 6) | SW_MEASURE_TYPE)
134+
#define TLV_MINOR_IAS_SPE_VERSION ((SW_SPE << 6) | SW_VERSION)
135+
#define TLV_MINOR_IAS_SPE_SIGNER_ID ((SW_SPE << 6) | SW_SIGNER_ID)
136+
#define TLV_MINOR_IAS_SPE_EPOCH ((SW_SPE << 6) | SW_EPOCH)
137+
#define TLV_MINOR_IAS_SPE_TYPE ((SW_SPE << 6) | SW_TYPE)
138+
139+
/* SPE + NSPE - combined secure and non-secure image */
140+
#define TLV_MINOR_IAS_S_NS_MEASURE_VALUE ((SW_S_NS << 6) | SW_MEASURE_VALUE)
141+
#define TLV_MINOR_IAS_S_NS_MEASURE_TYPE ((SW_S_NS << 6) | SW_MEASURE_TYPE)
142+
#define TLV_MINOR_IAS_S_NS_VERSION ((SW_S_NS << 6) | SW_VERSION)
143+
#define TLV_MINOR_IAS_S_NS_SIGNER_ID ((SW_S_NS << 6) | SW_SIGNER_ID)
144+
#define TLV_MINOR_IAS_S_NS_EPOCH ((SW_S_NS << 6) | SW_EPOCH)
145+
#define TLV_MINOR_IAS_S_NS_TYPE ((SW_S_NS << 6) | SW_TYPE)
146+
147+
/* General macros to handle TLV type */
148+
#define MAJOR_MASK 0xF /* 4 bit */
149+
#define MAJOR_POS 12 /* 12 bit */
150+
#define MINOR_MASK 0xFFF /* 12 bit */
151+
152+
#define SET_TLV_TYPE(major, minor) \
153+
((((major) & MAJOR_MASK) << MAJOR_POS) | ((minor) & MINOR_MASK))
154+
#define GET_MAJOR(tlv_type) ((tlv_type) >> MAJOR_POS)
155+
#define GET_MINOR(tlv_type) ((tlv_type) & MINOR_MASK)
156+
157+
/* Initial attestation specific macros */
158+
#define MODULE_POS 6 /* 6 bit */
159+
#define CLAIM_MASK 0x3F /* 6 bit */
160+
#define MEASUREMENT_CLAIM_POS 3 /* 3 bit */
161+
162+
#define GET_IAS_MODULE(tlv_type) (GET_MINOR(tlv_type) >> MODULE_POS)
163+
#define GET_IAS_CLAIM(tlv_type) (GET_MINOR(tlv_type) & CLAIM_MASK)
164+
#define SET_IAS_MINOR(sw_module, claim) (((sw_module) << 6) | (claim))
165+
166+
#define GET_IAS_MEASUREMENT_CLAIM(ias_claim) ((ias_claim) >> \
167+
MEASUREMENT_CLAIM_POS)
168+
169+
/* Magic value which marks the beginning of shared data area in memory */
48170
#define SHARED_DATA_TLV_INFO_MAGIC 0x2016
49171

50172
/**
51173
* Shared data TLV header. All fields in little endian.
52174
*
53-
* ---------------------------
54-
* | tlv_magic | tlv_tot_len |
55-
* ---------------------------
175+
* -----------------------------------
176+
* | tlv_magic(16) | tlv_tot_len(16) |
177+
* -----------------------------------
56178
*/
57179
struct shared_data_tlv_header {
58180
uint16_t tlv_magic;
@@ -64,15 +186,14 @@ struct shared_data_tlv_header {
64186
/**
65187
* Shared data TLV entry header format. All fields in little endian.
66188
*
67-
* ---------------------------------------------
68-
* | tlv_major_type | tlv_minor_type | tlv_len |
69-
* ---------------------------------------------
70-
* | Raw data |
71-
* ---------------------------------------------
189+
* -------------------------------
190+
* | tlv_type(16) | tlv_len(16) |
191+
* -------------------------------
192+
* | Raw data |
193+
* -------------------------------
72194
*/
73195
struct shared_data_tlv_entry {
74-
uint8_t tlv_major_type;
75-
uint8_t tlv_minor_type;
196+
uint16_t tlv_type;
76197
uint16_t tlv_len; /* size of single TLV entry (including this header). */
77198
};
78199

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#-------------------------------------------------------------------------------
2+
# Copyright (c) 2017-2018, Arm Limited. All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
#
6+
#-------------------------------------------------------------------------------
7+
8+
#Definitions to compile the "core" module.
9+
#This file assumes it will be included from a project specific cmakefile, and
10+
#will not create a library or executable.
11+
#Inputs:
12+
# TFM_ROOT_DIR - directory where secure FW sourec is located.
13+
#
14+
#Outputs:
15+
# Will modify include directories to make the source compile.
16+
# ALL_SRC_C: C source files to be compiled will be added to this list.
17+
# This shall be added to your add_executable or add_library command.
18+
# ALL_SRC_CXX: C++ source files to be compiled will be added to this list.
19+
# This shall be added to your add_executable or add_library command.
20+
# ALL_SRC_ASM: assembly source files to be compiled will be added to this
21+
# list. This shall be added to your add_executable or add_library
22+
# command.
23+
# Include directories will be modified by using the include_directories()
24+
# commands as needed.
25+
26+
#Get the current directory where this file is located.
27+
set(SS_CORE_DIR ${CMAKE_CURRENT_LIST_DIR})
28+
if(NOT DEFINED TFM_ROOT_DIR)
29+
message(FATAL_ERROR
30+
"Please set TFM_ROOT_DIR before including this file.")
31+
endif()
32+
33+
set (SS_CORE_C_SRC
34+
"${SS_CORE_DIR}/tfm_core.c"
35+
"${SS_CORE_DIR}/tfm_handler.c"
36+
"${SS_CORE_DIR}/tfm_secure_api.c"
37+
"${SS_CORE_DIR}/tfm_spm_services.c"
38+
"${SS_CORE_DIR}/tfm_nspm.c"
39+
"${SS_CORE_DIR}/tfm_boot_data.c"
40+
)
41+
42+
#Append all our source files to global lists.
43+
list(APPEND ALL_SRC_C ${SS_CORE_C_SRC})
44+
unset(SS_CORE_C_SRC)
45+
46+
#Setting include directories
47+
embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
48+
embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
49+
embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE)
50+
embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE)
51+
52+
set(BUILD_CMSIS_CORE Off)
53+
set(BUILD_RETARGET Off)
54+
set(BUILD_NATIVE_DRIVERS Off)
55+
set(BUILD_STARTUP Off)
56+
set(BUILD_TARGET_CFG Off)
57+
set(BUILD_TARGET_HARDWARE_KEYS Off)
58+
set(BUILD_TARGET_NV_COUNTERS Off)
59+
set(BUILD_CMSIS_DRIVERS Off)
60+
set(BUILD_TIME Off)
61+
set(BUILD_UART_STDOUT Off)
62+
set(BUILD_FLASH Off)
63+
set(BUILD_BOOT_SEED Off)
64+
set(BUILD_DEVICE_ID Off)
65+
if(NOT DEFINED PLATFORM_CMAKE_FILE)
66+
message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
67+
elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
68+
message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
69+
else()
70+
include(${PLATFORM_CMAKE_FILE})
71+
endif()

0 commit comments

Comments
 (0)