From 1cf3e2f0a8eb0d6324ce3db68dd5c78bdb690a8a Mon Sep 17 00:00:00 2001 From: Manish V Badarkhe Date: Mon, 20 Mar 2023 14:58:06 +0000 Subject: [PATCH] feat(fvp): add Event Log maximum size property in DT Updated the code to get and set the 'tpm_event_log_max_size' property in the event_log.dtsi. In this change, the maximum Event Log buffer size allocated by BL1 is passed to BL2, rather than both relying on the maximum Event Log buffer size macro. Change-Id: I7aa6256390872171e362b6f166f3f7335aa6e425 Signed-off-by: Manish V Badarkhe --- docs/components/measured_boot/event_log.rst | 8 +++++ include/plat/arm/common/plat_arm.h | 8 +++-- plat/arm/board/fvp/fdts/event_log.dtsi | 1 + plat/arm/board/fvp/fvp_bl1_measured_boot.c | 3 +- plat/arm/board/fvp/fvp_bl2_measured_boot.c | 6 ++-- plat/arm/common/arm_dyn_cfg_helpers.c | 39 +++++++++++++++++---- 6 files changed, 53 insertions(+), 12 deletions(-) diff --git a/docs/components/measured_boot/event_log.rst b/docs/components/measured_boot/event_log.rst index 088124825..c102bea96 100644 --- a/docs/components/measured_boot/event_log.rst +++ b/docs/components/measured_boot/event_log.rst @@ -33,3 +33,11 @@ and this property should be removed when this feature is supported. - tpm_event_log_size [mandatory] - value type: - Event Log size. + +- tpm_event_log_max_size [mandatory] + - value type: + - Event Log maximum size. + +-------------- + +*Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.* diff --git a/include/plat/arm/common/plat_arm.h b/include/plat/arm/common/plat_arm.h index 34f913bed..ffbd4ca13 100644 --- a/include/plat/arm/common/plat_arm.h +++ b/include/plat/arm/common/plat_arm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2022, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -267,8 +267,10 @@ int arm_set_nt_fw_info( uintptr_t log_addr, #endif size_t log_size, uintptr_t *ns_log_addr); -int arm_set_tb_fw_info(uintptr_t log_addr, size_t log_size); -int arm_get_tb_fw_info(uint64_t *log_addr, size_t *log_size); +int arm_set_tb_fw_info(uintptr_t log_addr, size_t log_size, + size_t log_max_size); +int arm_get_tb_fw_info(uint64_t *log_addr, size_t *log_size, + size_t *log_max_size); #endif /* MEASURED_BOOT */ /* diff --git a/plat/arm/board/fvp/fdts/event_log.dtsi b/plat/arm/board/fvp/fdts/event_log.dtsi index 47af672df..8e2654209 100644 --- a/plat/arm/board/fvp/fdts/event_log.dtsi +++ b/plat/arm/board/fvp/fdts/event_log.dtsi @@ -9,4 +9,5 @@ event_log: tpm_event_log { compatible = "arm,tpm_event_log"; tpm_event_log_addr = <0x0 0x0>; tpm_event_log_size = <0x0>; + tpm_event_log_max_size = <0x0>; }; diff --git a/plat/arm/board/fvp/fvp_bl1_measured_boot.c b/plat/arm/board/fvp/fvp_bl1_measured_boot.c index 76cd91824..72fdfef89 100644 --- a/plat/arm/board/fvp/fvp_bl1_measured_boot.c +++ b/plat/arm/board/fvp/fvp_bl1_measured_boot.c @@ -63,7 +63,8 @@ void bl1_plat_mboot_finish(void) event_log_cur_size = event_log_get_cur_size(event_log); int rc = arm_set_tb_fw_info((uintptr_t)event_log, - event_log_cur_size); + event_log_cur_size, + PLAT_ARM_EVENT_LOG_MAX_SIZE); if (rc != 0) { /* * It is a fatal error because on FVP platform, BL2 software diff --git a/plat/arm/board/fvp/fvp_bl2_measured_boot.c b/plat/arm/board/fvp/fvp_bl2_measured_boot.c index 7b0673a14..e6b919282 100644 --- a/plat/arm/board/fvp/fvp_bl2_measured_boot.c +++ b/plat/arm/board/fvp/fvp_bl2_measured_boot.c @@ -90,9 +90,11 @@ void bl2_plat_mboot_init(void) uint8_t *event_log_start; uint8_t *event_log_finish; size_t bl1_event_log_size; + size_t event_log_max_size; int rc; - rc = arm_get_tb_fw_info(&event_log_base, &bl1_event_log_size); + rc = arm_get_tb_fw_info(&event_log_base, &bl1_event_log_size, + &event_log_max_size); if (rc != 0) { ERROR("%s(): Unable to get Event Log info from TB_FW_CONFIG\n", __func__); @@ -111,7 +113,7 @@ void bl2_plat_mboot_init(void) event_log_start = (uint8_t *)((uintptr_t)event_log_base + bl1_event_log_size); event_log_finish = (uint8_t *)((uintptr_t)event_log_base + - PLAT_ARM_EVENT_LOG_MAX_SIZE); + event_log_max_size); event_log_init((uint8_t *)event_log_start, event_log_finish); diff --git a/plat/arm/common/arm_dyn_cfg_helpers.c b/plat/arm/common/arm_dyn_cfg_helpers.c index e88ea657f..5dc11151d 100644 --- a/plat/arm/common/arm_dyn_cfg_helpers.c +++ b/plat/arm/common/arm_dyn_cfg_helpers.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2018-2023, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -28,12 +28,15 @@ * Currently OP-TEE does not support reading DTBs from Secure memory * and this property should be removed when this feature is supported. */ -#define DTB_PROP_HW_SM_LOG_ADDR "tpm_event_log_sm_addr" +#define DTB_PROP_HW_SM_LOG_ADDR "tpm_event_log_sm_addr" #endif /* SPD_opteed */ -#define DTB_PROP_HW_LOG_ADDR "tpm_event_log_addr" -#define DTB_PROP_HW_LOG_SIZE "tpm_event_log_size" +#define DTB_PROP_HW_LOG_ADDR "tpm_event_log_addr" +#define DTB_PROP_HW_LOG_SIZE "tpm_event_log_size" +#define DTB_PROP_HW_LOG_MAX_SIZE "tpm_event_log_max_size" #endif /* MEASURED_BOOT */ +static size_t event_log_max_size __unused; + /******************************************************************************* * Validate the tb_fw_config is a valid DTB file and returns the node offset * to "arm,tb_fw" property. @@ -180,6 +183,16 @@ static int arm_set_event_log_info(uintptr_t config_base, return err; } + assert(event_log_max_size != 0U); + err = fdtw_write_inplace_cells(dtb, node, + DTB_PROP_HW_LOG_MAX_SIZE, 1, + &event_log_max_size); + if (err < 0) { + ERROR("%sDTB property '%s'\n", + "Unable to write ", DTB_PROP_HW_LOG_MAX_SIZE); + return err; + } + err = fdtw_write_inplace_cells(dtb, node, DTB_PROP_HW_LOG_SIZE, 1, &log_size); if (err < 0) { @@ -294,7 +307,7 @@ int arm_set_nt_fw_info( * 0 = success * < 0 = error */ -int arm_set_tb_fw_info(uintptr_t log_addr, size_t log_size) +int arm_set_tb_fw_info(uintptr_t log_addr, size_t log_size, size_t log_max_size) { /* * Read tb_fw_config device tree for Event Log properties @@ -309,6 +322,8 @@ int arm_set_tb_fw_info(uintptr_t log_addr, size_t log_size) tb_fw_cfg_dtb = tb_fw_config_info->config_addr; + event_log_max_size = log_max_size; + err = arm_set_event_log_info(tb_fw_cfg_dtb, #ifdef SPD_opteed 0UL, @@ -329,7 +344,8 @@ int arm_set_tb_fw_info(uintptr_t log_addr, size_t log_size) * Alongside returns Event Log address and its size. */ -int arm_get_tb_fw_info(uint64_t *log_addr, size_t *log_size) +int arm_get_tb_fw_info(uint64_t *log_addr, size_t *log_size, + size_t *log_max_size) { /* As libfdt uses void *, we can't avoid this cast */ const struct dyn_cfg_dtb_info_t *tb_fw_config_info; @@ -362,6 +378,17 @@ int arm_get_tb_fw_info(uint64_t *log_addr, size_t *log_size) if (rc != 0) { ERROR("%s%s", DTB_PROP_HW_LOG_SIZE, " not specified in TB_FW config.\n"); + return rc; + } + + rc = fdt_read_uint32(dtb, node, DTB_PROP_HW_LOG_MAX_SIZE, + (uint32_t *)log_max_size); + if (rc != 0) { + ERROR("%s%s", DTB_PROP_HW_LOG_MAX_SIZE, + " not specified in TB_FW config.\n"); + return rc; + } else { + event_log_max_size = *log_max_size; } return rc; -- 2.39.5