Skip to content

Commit 7763a47

Browse files
RcColesDavid Hu
authored and
David Hu
committed
RSS: Enable SIC and XIP mode
Change-Id: I19222bc4b668ccc41e087927f822ae25757e33bd Signed-off-by: Raef Coles <[email protected]>
1 parent a0cfa7e commit 7763a47

21 files changed

+841
-14
lines changed

bl2/ext/mcuboot/bl2_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ __asm(" .global __ARM_use_no_argv\n");
4848

4949
/* Static buffer to be used by mbedtls for memory allocation */
5050
static uint8_t mbedtls_mem_buf[BL2_MBEDTLS_MEM_BUF_LEN];
51+
struct boot_rsp rsp;
5152

5253
static void do_boot(struct boot_rsp *rsp)
5354
{
@@ -88,7 +89,6 @@ static void do_boot(struct boot_rsp *rsp)
8889

8990
int main(void)
9091
{
91-
struct boot_rsp rsp;
9292
fih_int fih_rc = FIH_FAILURE;
9393
enum tfm_plat_err_t plat_err;
9494
int32_t image_id;

docs/platform/arm/rss/readme.rst

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,32 @@ run the following ``srec_cat`` commands::
9797
<SCP BL1 image> -Binary -offset 0x320000 \
9898
-o flash.bin -Binary
9999

100+
If XIP mode is enabled, the following ``srec_cat`` command should be run to
101+
create the flash image::
102+
103+
srec_cat \
104+
bl2_signed.bin -Binary -offset 0x0 \
105+
bl2_signed.bin -Binary -offset 0x10000 \
106+
tfm_s.bin -Binary -offset 0x020000 \
107+
tfm_ns.bin -Binary -offset 0x080000 \
108+
tfm_s.bin -Binary -offset 0x0E0000 \
109+
tfm_ns.bin -Binary -offset 0x140000 \
110+
<Host AP BL1 image> -Binary -offset 0x1A0000 \
111+
<SCP BL1 image> -Binary -offset 0x220000 \
112+
<Host AP BL1 image> -Binary -offset 0x2A0000 \
113+
<SCP BL1 image> -Binary -offset 0x320000 \
114+
tfm_s_sic_tables_signed.bin -Binary -offset 0x3A0000 \
115+
tfm_ns_sic_tables_signed.bin -Binary -offset 0x3AA000 \
116+
tfm_s_sic_tables_signed.bin -Binary -offset 0x3B4000 \
117+
tfm_ns_sic_tables_signed.bin -Binary -offset 0x3BE000 \
118+
-o flash.bin -Binary
100119

101120
Once the flash image is created, it can be combined with the host FIP to create
102121
a combined host flash image::
103122

104123
srec_cat \
105124
fip-tc.bin -Binary -offset 0x0\
106-
flash.bin -Binary -offset 0x00400000 \
125+
flash.bin -Binary -offset 0x02200000 \
107126
-o host_flash.bin -Binary
108127

109128
For development purposes, the OTP image is included as a provisioning bundle in
@@ -114,8 +133,8 @@ with the higher version number.
114133

115134
The ROM binary should be placed in RSS ROM at ``0x11000000`` and the host flash
116135
binary should be placed at the base of the host flash. For the TC platform,
117-
this is at ``0x84000000``.
136+
this is at ``0x08000000``.
118137

119138
--------------
120139

121-
*Copyright (c) 2022, Arm Limited. All rights reserved.*
140+
*Copyright (c) 2022-2023, Arm Limited. All rights reserved.*

platform/ext/target/arm/rss/common/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ target_include_directories(platform_region_defs
1818
cc312
1919
)
2020

21+
target_compile_definitions(platform_region_defs
22+
INTERFACE
23+
$<$<BOOL:${RSS_XIP}>:RSS_XIP>
24+
)
25+
2126
#========================= Platform common defs ===============================#
2227

2328
# Specify the location of platform specific build dependencies.

platform/ext/target/arm/rss/common/bl2/provisioning.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ __PACKED_STRUCT bl2_assembly_and_test_provisioning_data_t {
2323
uint8_t bl2_rotpk_1[32];
2424
uint8_t bl2_rotpk_2[32];
2525
uint8_t bl2_rotpk_3[32];
26+
uint8_t s_image_encryption_key[32];
27+
uint8_t ns_image_encryption_key[32];
2628

2729
#ifdef PLATFORM_PSA_ADAC_SECURE_DEBUG
2830
uint8_t secure_debug_pk[32];
@@ -94,6 +96,21 @@ static const struct bl2_assembly_and_test_provisioning_data_t bl2_assembly_and_t
9496
#error "No public key available for given signing algorithm."
9597
#endif /* MCUBOOT_SIGN_RSA_LEN */
9698

99+
/* Secure image encryption key; */
100+
{
101+
0xfc, 0x57, 0x01, 0xdc, 0x61, 0x35, 0xe1, 0x32,
102+
0x38, 0x47, 0xbd, 0xc4, 0x0f, 0x04, 0xd2, 0xe5,
103+
0xbe, 0xe5, 0x83, 0x3b, 0x23, 0xc2, 0x9f, 0x93,
104+
0x59, 0x3d, 0x00, 0x01, 0x8c, 0xfa, 0x99, 0x94,
105+
},
106+
/* Non-secure image encryption key; */
107+
{
108+
0xfc, 0x57, 0x01, 0xdc, 0x61, 0x35, 0xe1, 0x32,
109+
0x38, 0x47, 0xbd, 0xc4, 0x0f, 0x04, 0xd2, 0xe5,
110+
0xbe, 0xe5, 0x83, 0x3b, 0x23, 0xc2, 0x9f, 0x93,
111+
0x59, 0x3d, 0x00, 0x01, 0x8c, 0xfa, 0x99, 0x94,
112+
},
113+
97114
#ifdef PLATFORM_PSA_ADAC_SECURE_DEBUG
98115
{
99116
0xf4, 0x0c, 0x8f, 0xbf, 0x12, 0xdb, 0x78, 0x2a,
@@ -167,6 +184,19 @@ enum tfm_plat_err_t provision_assembly_and_test(void)
167184
return err;
168185
}
169186

187+
err = tfm_plat_otp_write(PLAT_OTP_ID_KEY_SECURE_ENCRYPTION,
188+
sizeof(bl2_assembly_and_test_prov_data.s_image_encryption_key),
189+
bl2_assembly_and_test_prov_data.s_image_encryption_key);
190+
if (err != TFM_PLAT_ERR_SUCCESS && err != TFM_PLAT_ERR_UNSUPPORTED) {
191+
return err;
192+
}
193+
err = tfm_plat_otp_write(PLAT_OTP_ID_KEY_NON_SECURE_ENCRYPTION,
194+
sizeof(bl2_assembly_and_test_prov_data.ns_image_encryption_key),
195+
bl2_assembly_and_test_prov_data.ns_image_encryption_key);
196+
if (err != TFM_PLAT_ERR_SUCCESS && err != TFM_PLAT_ERR_UNSUPPORTED) {
197+
return err;
198+
}
199+
170200
#ifdef PLATFORM_PSA_ADAC_SECURE_DEBUG
171201
err = tfm_plat_otp_write(PLAT_OTP_ID_SECURE_DEBUG_PK,
172202
sizeof(bl2_assembly_and_test_prov_data.secure_debug_pk),

platform/ext/target/arm/rss/common/otp_lcm.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ __PACKED_STRUCT plat_user_area_layout_t {
2626
uint32_t iak_id_zero_bits;
2727
uint32_t bl2_rotpk_zero_bits[3];
2828
uint32_t bl2_encryption_key_zero_bits;
29+
uint32_t s_image_encryption_key_zero_bits;
30+
uint32_t ns_image_encryption_key_zero_bits;
2931
uint32_t bl1_2_image_hash_zero_bits;
3032
uint32_t bl2_image_hash_zero_bits;
3133
uint32_t bl1_rotpk_0_zero_bits;
@@ -49,6 +51,9 @@ __PACKED_STRUCT plat_user_area_layout_t {
4951
uint32_t bl2_nv_counter[4][128];
5052

5153
uint32_t bl2_encryption_key[8];
54+
uint32_t s_image_encryption_key[8];
55+
uint32_t ns_image_encryption_key[8];
56+
5257
uint32_t bl1_2_image_hash[8];
5358
uint32_t bl2_image_hash[8];
5459
uint32_t bl1_nv_counter[128];
@@ -233,6 +238,19 @@ static enum tfm_plat_err_t check_keys_for_tampering(void)
233238
}
234239
}
235240

241+
err = verify_zero_bits_count(USER_AREA_OFFSET(s_image_encryption_key),
242+
USER_AREA_SIZE(s_image_encryption_key),
243+
USER_AREA_OFFSET(s_image_encryption_key_zero_bits));
244+
if (err != TFM_PLAT_ERR_SUCCESS) {
245+
return err;
246+
}
247+
err = verify_zero_bits_count(USER_AREA_OFFSET(ns_image_encryption_key),
248+
USER_AREA_SIZE(ns_image_encryption_key),
249+
USER_AREA_OFFSET(ns_image_encryption_key_zero_bits));
250+
if (err != TFM_PLAT_ERR_SUCCESS) {
251+
return err;
252+
}
253+
236254
#ifdef BL1
237255
err = verify_zero_bits_count(USER_AREA_OFFSET(bl2_encryption_key),
238256
USER_AREA_SIZE(bl2_encryption_key),
@@ -480,6 +498,12 @@ enum tfm_plat_err_t tfm_plat_otp_read(enum tfm_otp_element_id_t id,
480498
return otp_read(USER_AREA_OFFSET(host_nv_counter[2]),
481499
USER_AREA_SIZE(host_nv_counter[2]), out_len, out);
482500

501+
case PLAT_OTP_ID_KEY_SECURE_ENCRYPTION:
502+
return otp_read(USER_AREA_OFFSET(s_image_encryption_key),
503+
USER_AREA_SIZE(s_image_encryption_key), out_len, out);
504+
case PLAT_OTP_ID_KEY_NON_SECURE_ENCRYPTION:
505+
return otp_read(USER_AREA_OFFSET(ns_image_encryption_key),
506+
USER_AREA_SIZE(ns_image_encryption_key), out_len, out);
483507
#ifdef BL1
484508
case PLAT_OTP_ID_KEY_BL2_ENCRYPTION:
485509
return otp_read(USER_AREA_OFFSET(bl2_encryption_key),
@@ -624,6 +648,14 @@ enum tfm_plat_err_t tfm_plat_otp_write(enum tfm_otp_element_id_t id,
624648
return otp_write(USER_AREA_OFFSET(host_nv_counter[2]),
625649
USER_AREA_SIZE(host_nv_counter[2]), in_len, in, 0);
626650

651+
case PLAT_OTP_ID_KEY_SECURE_ENCRYPTION:
652+
return otp_write(USER_AREA_OFFSET(s_image_encryption_key),
653+
USER_AREA_SIZE(s_image_encryption_key), in_len, in,
654+
USER_AREA_OFFSET(s_image_encryption_key_zero_bits));
655+
case PLAT_OTP_ID_KEY_NON_SECURE_ENCRYPTION:
656+
return otp_write(USER_AREA_OFFSET(ns_image_encryption_key),
657+
USER_AREA_SIZE(ns_image_encryption_key), in_len, in,
658+
USER_AREA_OFFSET(ns_image_encryption_key_zero_bits));
627659
#ifdef BL1
628660
case PLAT_OTP_ID_KEY_BL2_ENCRYPTION:
629661
return otp_write(USER_AREA_OFFSET(bl2_encryption_key),
@@ -749,6 +781,12 @@ enum tfm_plat_err_t tfm_plat_otp_get_size(enum tfm_otp_element_id_t id,
749781
*size = USER_AREA_SIZE(host_nv_counter[2]);
750782
break;
751783

784+
case PLAT_OTP_ID_KEY_SECURE_ENCRYPTION:
785+
*size = USER_AREA_SIZE(s_image_encryption_key);
786+
break;
787+
case PLAT_OTP_ID_KEY_NON_SECURE_ENCRYPTION:
788+
*size = USER_AREA_SIZE(ns_image_encryption_key);
789+
break;
752790
#ifdef BL1
753791
case PLAT_OTP_ID_KEY_BL2_ENCRYPTION:
754792
*size = USER_AREA_SIZE(bl2_encryption_key);

platform/ext/target/arm/rss/common/partition/platform_base_address.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@
145145
#define FWU_HOST_IMAGE_BASE_S (HOST_ACCESS_BASE_S + 0x000000) /* Region to allow writing new RSS FW images */
146146
#define HOST_COMMS_MAPPABLE_BASE_S (HOST_ACCESS_BASE_S + 0x100000) /* Region into which to map host comms pointers */
147147

148+
/* SIC regions open in BL2 and runtime */
149+
#define RSS_RUNTIME_S_XIP_BASE_S SIC_HOST_BASE_S /* RSS runtime secure image XIP secure address */
150+
#define RSS_RUNTIME_NS_XIP_BASE_S (SIC_HOST_BASE_S + 0x060000) /* RSS runtime non-secure image XIP secure address */
151+
152+
#define RSS_RUNTIME_NS_XIP_BASE_NS (SIC_HOST_BASE_NS + 0x060000) /* RSS runtime non-secure image XIP non-secure address */
153+
148154
/* Memory map addresses exempt from memory attribution by both the SAU and IDAU */
149155
#define RSS_EWIC_BASE 0xE0047000 /* External Wakeup Interrupt Controller
150156
* Access from Non-secure software is only allowed

platform/ext/target/arm/rss/common/partition/region_defs.h

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2022 Arm Limited. All rights reserved.
2+
* Copyright (c) 2019-2023 Arm Limited. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -107,9 +107,14 @@
107107
(FLASH_NS_PARTITION_SIZE - BL2_HEADER_SIZE - BL2_TRAILER_SIZE)
108108

109109
/* Secure regions */
110-
/* Secure Code executes from VM0 */
110+
/* Secure Code executes from VM0, or XIP from flash via the SIC */
111+
#ifdef RSS_XIP
112+
#define S_CODE_START (RSS_RUNTIME_S_XIP_BASE_S)
113+
#define S_CODE_SIZE (FLASH_S_PARTITION_SIZE)
114+
#else
111115
#define S_CODE_START (S_IMAGE_LOAD_ADDRESS + BL2_HEADER_SIZE)
112116
#define S_CODE_SIZE (IMAGE_S_CODE_SIZE)
117+
#endif /* RSS_XIP */
113118
#define S_CODE_LIMIT (S_CODE_START + S_CODE_SIZE - 1)
114119

115120
/* Secure Data stored in VM0. Size defined in flash layout */
@@ -120,19 +125,31 @@
120125
#define S_CODE_VECTOR_TABLE_SIZE (0x1C0)
121126

122127
/* Non-secure regions */
123-
/* Non-Secure Code executes from VM1 */
128+
/* Non-Secure Code executes from VM1, or XIP from flash via the SIC */
129+
#ifdef RSS_XIP
130+
#define NS_CODE_START (RSS_RUNTIME_NS_XIP_BASE_NS)
131+
#define NS_CODE_SIZE (FLASH_NS_PARTITION_SIZE)
132+
#else
124133
#define NS_CODE_START (VM1_BASE_NS + NS_DATA_SIZE + BL2_HEADER_SIZE)
125134
#define NS_CODE_SIZE (IMAGE_NS_CODE_SIZE)
135+
#endif /* RSS_XIP */
126136
#define NS_CODE_LIMIT (NS_CODE_START + NS_CODE_SIZE - 1)
127137

128-
/* Non-Secure Data stored in VM1. */
138+
/* Non-Secure Data stored after secure data, or in VM1. */
139+
#ifdef RSS_XIP
140+
#define NS_DATA_START (VM0_BASE_NS + S_DATA_SIZE)
141+
#else
129142
#define NS_DATA_START (VM1_BASE_NS)
143+
#endif
130144
#define NS_DATA_LIMIT (NS_DATA_START + NS_DATA_SIZE - 1)
131145

132146
/* NS partition information is used for MPC and SAU configuration */
147+
#ifdef RSS_XIP
148+
#define NS_PARTITION_START RSS_RUNTIME_NS_XIP_BASE_NS
149+
#else
133150
#define NS_PARTITION_START (NS_CODE_START)
134-
#define NS_PARTITION_SIZE (FLASH_NS_PARTITION_SIZE - BL2_HEADER_SIZE \
135-
- BL2_TRAILER_SIZE)
151+
#endif /* RSS_XIP */
152+
#define NS_PARTITION_SIZE (NS_CODE_SIZE)
136153

137154
#define SECONDARY_PARTITION_START (FWU_HOST_IMAGE_BASE_S)
138155
#define SECONDARY_PARTITION_SIZE (0x100000)

platform/ext/target/arm/rss/common/platform_otp_ids.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ enum tfm_otp_element_id_t {
4444
PLAT_OTP_ID_NV_COUNTER_NS_2,
4545

4646
PLAT_OTP_ID_KEY_BL2_ENCRYPTION,
47+
PLAT_OTP_ID_KEY_SECURE_ENCRYPTION,
48+
PLAT_OTP_ID_KEY_NON_SECURE_ENCRYPTION,
49+
4750
PLAT_OTP_ID_BL1_2_IMAGE,
4851
PLAT_OTP_ID_BL1_2_IMAGE_HASH,
4952
PLAT_OTP_ID_BL2_IMAGE_HASH,

platform/ext/target/arm/rss/common/rss_comms/rss_comms_atu_hal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
#ifndef __RSS_COMMS_ATU_HAL_H__
99
#define __RSS_COMMS_ATU_HAL_H__
1010

11+
#ifndef RSS_XIP
1112
#define RSS_COMMS_ATU_REGION_MIN 0
13+
#else
14+
#define RSS_COMMS_ATU_REGION_MIN 2
15+
#endif /* !RSS_XIP */
16+
1217
#define RSS_COMMS_ATU_REGION_MAX 15
1318
/* There must be at least one region */
1419
#define RSS_COMMS_ATU_REGION_AM (RSS_COMMS_ATU_REGION_MAX - \

platform/ext/target/arm/rss/common/target_cfg.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ enum tfm_plat_err_t mpc_init_cfg(void)
338338
if (ret != ARM_DRIVER_OK) {
339339
return TFM_PLAT_ERR_SYSTEM_ERR;
340340
}
341+
#ifdef RSS_XIP
342+
ret = Driver_SIC_MPC.Initialize();
343+
if (ret != ARM_DRIVER_OK) {
344+
return TFM_PLAT_ERR_SYSTEM_ERR;
345+
}
346+
#endif /* RSS_XIP */
341347

342348
/* Configuring primary non-secure partition.
343349
* It is ensured in flash_layout.h that these memory regions are located in
@@ -349,9 +355,16 @@ enum tfm_plat_err_t mpc_init_cfg(void)
349355
if (ret != ARM_DRIVER_OK) {
350356
return TFM_PLAT_ERR_SYSTEM_ERR;
351357
}
358+
359+
#ifdef RSS_XIP
360+
ret = Driver_SIC_MPC.ConfigRegion(memory_regions.non_secure_partition_base,
361+
memory_regions.non_secure_partition_limit,
362+
ARM_MPC_ATTR_NONSECURE);
363+
#else
352364
ret = Driver_VM1_MPC.ConfigRegion(memory_regions.non_secure_partition_base,
353365
memory_regions.non_secure_partition_limit,
354366
ARM_MPC_ATTR_NONSECURE);
367+
#endif /* !RSS_XIP */
355368
if (ret != ARM_DRIVER_OK) {
356369
return TFM_PLAT_ERR_SYSTEM_ERR;
357370
}
@@ -366,6 +379,12 @@ enum tfm_plat_err_t mpc_init_cfg(void)
366379
if (ret != ARM_DRIVER_OK) {
367380
return ret;
368381
}
382+
#ifdef RSS_XIP
383+
ret = Driver_SIC_MPC.LockDown();
384+
if (ret != ARM_DRIVER_OK) {
385+
return ret;
386+
}
387+
#endif /* RSS_XIP */
369388

370389
/* Add barriers to assure the MPC configuration is done before continue
371390
* the execution.
@@ -380,6 +399,9 @@ void mpc_clear_irq(void)
380399
{
381400
Driver_VM0_MPC.ClearInterrupt();
382401
Driver_VM1_MPC.ClearInterrupt();
402+
#ifdef RSS_XIP
403+
Driver_SIC_MPC.ClearInterrupt();
404+
#endif /* RSS_XIP */
383405
}
384406

385407
/*------------------- PPC configuration functions -------------------------*/

0 commit comments

Comments
 (0)