refactor(st): update test for closed chip

The function stm32mp_is_closed_device() is replaced with
stm32mp_check_closed_device(), which return an uint32_t, either
STM32MP_CHIP_SEC_OPEN or STM32MP_CHIP_SEC_CLOSED.

Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
Change-Id: Ie0790cdc36c4b6522083bc1f0e7c38e8061e6adf
This commit is contained in:
Yann Gautier 2023-02-01 15:04:30 +01:00 committed by Yann Gautier
parent c706104507
commit 9cd784db55
6 changed files with 29 additions and 19 deletions

View file

@ -824,7 +824,7 @@ uint32_t bsec_get_secure_state(void)
result = BSEC_STATE_INVALID; result = BSEC_STATE_INVALID;
} else { } else {
if ((status & BSEC_OTP_STATUS_SECURE) != 0U) { if ((status & BSEC_OTP_STATUS_SECURE) != 0U) {
if (stm32mp_is_closed_device()) { if (stm32mp_check_closed_device() == STM32MP_CHIP_SEC_CLOSED) {
result = BSEC_STATE_SEC_CLOSED; result = BSEC_STATE_SEC_CLOSED;
} else { } else {
result = BSEC_STATE_SEC_OPEN; result = BSEC_STATE_SEC_OPEN;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018-2023, STMicroelectronics - All Rights Reserved * Copyright (C) 2018-2024, STMicroelectronics - All Rights Reserved
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
@ -14,6 +14,9 @@
#define JEDEC_ST_BKID U(0x0) #define JEDEC_ST_BKID U(0x0)
#define JEDEC_ST_MFID U(0x20) #define JEDEC_ST_MFID U(0x20)
#define STM32MP_CHIP_SEC_CLOSED U(0x34D9CCC5)
#define STM32MP_CHIP_SEC_OPEN U(0xA764D182)
/* FWU configuration (max supported value is 15) */ /* FWU configuration (max supported value is 15) */
#define FWU_MAX_TRIAL_REBOOT U(3) #define FWU_MAX_TRIAL_REBOOT U(3)
@ -23,8 +26,8 @@ uintptr_t stm32mp_get_boot_ctx_address(void);
uint16_t stm32mp_get_boot_itf_selected(void); uint16_t stm32mp_get_boot_itf_selected(void);
bool stm32mp_is_single_core(void); bool stm32mp_is_single_core(void);
bool stm32mp_is_closed_device(void);
bool stm32mp_is_auth_supported(void); bool stm32mp_is_auth_supported(void);
uint32_t stm32mp_check_closed_device(void);
/* Return the base address of the DDR controller */ /* Return the base address of the DDR controller */
uintptr_t stm32mp_ddrctrl_base(void); uintptr_t stm32mp_ddrctrl_base(void);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022-2023, STMicroelectronics - All Rights Reserved * Copyright (c) 2022-2024, STMicroelectronics - All Rights Reserved
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
@ -58,7 +58,8 @@ static void crypto_lib_init(void)
panic(); panic();
} }
if (stm32mp_is_closed_device() || stm32mp_is_auth_supported()) { if ((stm32mp_check_closed_device() == STM32MP_CHIP_SEC_CLOSED) ||
stm32mp_is_auth_supported()) {
#if STM32MP_CRYPTO_ROM_LIB #if STM32MP_CRYPTO_ROM_LIB
boot_context = (boot_api_context_t *)stm32mp_get_boot_ctx_address(); boot_context = (boot_api_context_t *)stm32mp_get_boot_ctx_address();
auth_ops.verify_signature = boot_context->bootrom_ecdsa_verify_signature; auth_ops.verify_signature = boot_context->bootrom_ecdsa_verify_signature;
@ -322,7 +323,8 @@ static int crypto_verify_signature(void *data_ptr, unsigned int data_len,
size_t bignum_len = sizeof(sig) / 2U; size_t bignum_len = sizeof(sig) / 2U;
unsigned int seq_num = 0U; unsigned int seq_num = 0U;
if (!stm32mp_is_closed_device() && !stm32mp_is_auth_supported()) { if ((stm32mp_check_closed_device() == STM32MP_CHIP_SEC_OPEN) &&
!stm32mp_is_auth_supported()) {
return CRYPTO_SUCCESS; return CRYPTO_SUCCESS;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022, STMicroelectronics - All Rights Reserved * Copyright (c) 2022-2024, STMicroelectronics - All Rights Reserved
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
@ -67,14 +67,14 @@ static int copy_hash_from_otp(const char *otp_name, uint8_t *hash, size_t len)
* Check if key hash values in OTP are 0 or 0xFFFFFFFFF * Check if key hash values in OTP are 0 or 0xFFFFFFFFF
* programmed : Invalid Key * programmed : Invalid Key
*/ */
if (!stm32mp_is_closed_device() && !valid) { if ((stm32mp_check_closed_device() == STM32MP_CHIP_SEC_OPEN) && !valid) {
if ((tmp != 0U) && (tmp != 0xFFFFFFFFU) && (tmp != first)) { if ((tmp != 0U) && (tmp != 0xFFFFFFFFU) && (tmp != first)) {
valid = true; valid = true;
} }
} }
} }
if (!stm32mp_is_closed_device() && !valid) { if ((stm32mp_check_closed_device() == STM32MP_CHIP_SEC_OPEN) && !valid) {
return 0; return 0;
} }
@ -163,7 +163,7 @@ int plat_get_rotpk_info(void *cookie, void **key_ptr, unsigned int *key_len,
*key_ptr = &root_pk_hash; *key_ptr = &root_pk_hash;
*flags = ROTPK_IS_HASH; *flags = ROTPK_IS_HASH;
if ((res == 0) && !stm32mp_is_closed_device()) { if ((res == 0) && (stm32mp_check_closed_device() == STM32MP_CHIP_SEC_OPEN)) {
*flags |= ROTPK_NOT_DEPLOYED; *flags |= ROTPK_NOT_DEPLOYED;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
@ -318,7 +318,7 @@ void bl2_el3_plat_arch_setup(void)
skip_console_init: skip_console_init:
#if !TRUSTED_BOARD_BOOT #if !TRUSTED_BOARD_BOOT
if (stm32mp_is_closed_device()) { if (stm32mp_check_closed_device() == STM32MP_CHIP_SEC_CLOSED) {
/* Closed chip mandates authentication */ /* Closed chip mandates authentication */
ERROR("Secure chip: TRUSTED_BOARD_BOOT must be enabled\n"); ERROR("Secure chip: TRUSTED_BOARD_BOOT must be enabled\n");
panic(); panic();
@ -347,7 +347,7 @@ skip_console_init:
stm32_iwdg_refresh(); stm32_iwdg_refresh();
if (bsec_read_debug_conf() != 0U) { if (bsec_read_debug_conf() != 0U) {
if (stm32mp_is_closed_device()) { if (stm32mp_check_closed_device() == STM32MP_CHIP_SEC_CLOSED) {
#if DEBUG #if DEBUG
WARN("\n%s", debug_msg); WARN("\n%s", debug_msg);
#else #else

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
@ -531,12 +531,12 @@ bool stm32mp_is_single_core(void)
} }
/* Return true when device is in closed state */ /* Return true when device is in closed state */
bool stm32mp_is_closed_device(void) uint32_t stm32mp_check_closed_device(void)
{ {
uint32_t value; uint32_t value;
if (stm32_get_otp_value(CFG0_OTP, &value) != 0) { if (stm32_get_otp_value(CFG0_OTP, &value) != 0) {
return true; return STM32MP_CHIP_SEC_CLOSED;
} }
#if STM32MP13 #if STM32MP13
@ -544,17 +544,22 @@ bool stm32mp_is_closed_device(void)
switch (value) { switch (value) {
case CFG0_OPEN_DEVICE: case CFG0_OPEN_DEVICE:
return false; return STM32MP_CHIP_SEC_OPEN;
case CFG0_CLOSED_DEVICE: case CFG0_CLOSED_DEVICE:
case CFG0_CLOSED_DEVICE_NO_BOUNDARY_SCAN: case CFG0_CLOSED_DEVICE_NO_BOUNDARY_SCAN:
case CFG0_CLOSED_DEVICE_NO_JTAG: case CFG0_CLOSED_DEVICE_NO_JTAG:
return true; return STM32MP_CHIP_SEC_CLOSED;
default: default:
panic(); panic();
} }
#endif #endif
#if STM32MP15 #if STM32MP15
return (value & CFG0_CLOSED_DEVICE) == CFG0_CLOSED_DEVICE; if ((value & CFG0_CLOSED_DEVICE) == CFG0_CLOSED_DEVICE) {
return STM32MP_CHIP_SEC_CLOSED;
} else {
return STM32MP_CHIP_SEC_OPEN;
}
#endif #endif
} }