Skip to content

Commit 567c3fd

Browse files
Yann-lmsspasdeloup
authored andcommitted
feat(st): lock the encryption key at the end of BL2
At the end of BL2, the FIP encryption key should not be accessible, if DECRYPTION_SUPPORT flag is set. The shadow registers are then set to 0, and a sticky read lock is set to prevent the OTP fuse to be reloaded. Signed-off-by: Yann Gautier <yann.gautier@foss.st.com> Change-Id: I8b7dd68dc9562f54bfc2a0a7ac236baab2b552a5 Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/tf-a/+/306795 ACI: CITOOLS <MDG-smet-aci-reviews@list.st.com> ACI: CIBUILD <MDG-smet-aci-builds@list.st.com> Domain-Review: Lionel DEBIEVE <lionel.debieve@foss.st.com>
1 parent 4d04df5 commit 567c3fd

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

plat/st/common/include/stm32mp_common.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2022, STMicroelectronics - All Rights Reserved
2+
* Copyright (C) 2018-2023, STMicroelectronics - All Rights Reserved
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
@@ -50,6 +50,7 @@ int stm32_get_otp_index(const char *otp_name, uint32_t *otp_idx,
5050
uint32_t *otp_len);
5151
int stm32_get_otp_value(const char *otp_name, uint32_t *otp_val);
5252
int stm32_get_otp_value_from_idx(const uint32_t otp_idx, uint32_t *otp_val);
53+
int stm32_lock_enc_key_otp(void);
5354

5455
/* Get IWDG platform instance ID from peripheral IO memory base address */
5556
uint32_t stm32_iwdg_get_instance(uintptr_t base);

plat/st/common/stm32mp_common.c

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015-2022, ARM Limited and Contributors. All rights reserved.
2+
* Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
@@ -201,6 +201,32 @@ int stm32_get_otp_value_from_idx(const uint32_t otp_idx, uint32_t *otp_val)
201201
return 0;
202202
}
203203

204+
int stm32_lock_enc_key_otp(void)
205+
{
206+
uint32_t otp_idx;
207+
uint32_t otp_len;
208+
uint32_t i;
209+
210+
if (stm32_get_otp_index(ENCKEY_OTP, &otp_idx, &otp_len) != 0) {
211+
return -1;
212+
}
213+
214+
for (i = 0U; i < otp_len / CHAR_BIT / sizeof(uint32_t); i++) {
215+
uint32_t ret = bsec_write_otp(0U, otp_idx + i);
216+
217+
if (ret != BSEC_OK) {
218+
return -1;
219+
}
220+
221+
ret = bsec_set_sr_lock(otp_idx + i);
222+
if (ret != BSEC_OK) {
223+
return -1;
224+
}
225+
}
226+
227+
return 0;
228+
}
229+
204230
#if defined(IMAGE_BL2)
205231
static void reset_uart(uint32_t reset)
206232
{

plat/st/stm32mp1/bl2_plat_setup.c

+6
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,12 @@ void bl2_el3_plat_prepare_exit(void)
665665
flush_dcache_range(DATA_START, DATA_END - DATA_START);
666666
#endif
667667

668+
#if !defined(DECRYPTION_SUPPORT_none)
669+
if (stm32_lock_enc_key_otp() != 0) {
670+
panic();
671+
}
672+
#endif
673+
668674
stm32mp1_security_setup();
669675

670676
/* end of boot mode */

0 commit comments

Comments
 (0)