From 973e0b7f2cc9ac64132b2179295c424a88b690ea Mon Sep 17 00:00:00 2001 From: Divin Raj Date: Thu, 4 Apr 2024 10:16:14 +0100 Subject: [PATCH] feat(arm): add support for loading CONFIG from BL2 This commit introduces a new ARM platform-specific build option called `ARM_FW_CONFIG_LOAD_ENABLE`. This option enables the loading of the `fw_config` device tree when resetting to the BL2 scenario. Additionally, the FW_CONFIG image reference has been added to the fdts/tbbr_cot_descriptors.dtsi file in order to use in the scenario of RESET_TO_BL2. Signed-off-by: Divin Raj Change-Id: I11de497b7dbb1386ed84d939d6fd2a11856e9e1b --- docs/plat/arm/arm-build-options.rst | 6 +++++ fdts/tbbr_cot_descriptors.dtsi | 6 +++++ include/plat/arm/common/plat_arm.h | 3 +++ plat/arm/common/arm_bl2_el3_setup.c | 41 ++++++++++++++++++++++++++++- plat/arm/common/arm_bl2_setup.c | 3 +++ plat/arm/common/arm_common.mk | 19 +++++++++++++ 6 files changed, 77 insertions(+), 1 deletion(-) diff --git a/docs/plat/arm/arm-build-options.rst b/docs/plat/arm/arm-build-options.rst index e1b3ef0e6..afbb15767 100644 --- a/docs/plat/arm/arm-build-options.rst +++ b/docs/plat/arm/arm-build-options.rst @@ -16,6 +16,12 @@ Arm Platform Build Options should match the frame used by the Non-Secure image (normally the Linux kernel). Default is true (access to the frame is allowed). +- ``ARM_FW_CONFIG_LOAD_ENABLE``: Boolean option to enable the loading of + FW_CONFIG device trees from the Firmware Image Package (FIP). When enabled, + BL2 calls the platform specific function `arm_bl2_el3_plat_config_load`. + This function is responsible for loading, parsing, and validating the + FW_CONFIG device trees from the FIP. The option depends on RESET_TO_BL2. + - ``ARM_DISABLE_TRUSTED_WDOG``: boolean option to disable the Trusted Watchdog. By default, Arm platforms use a watchdog to trigger a system reset in case an error is encountered during the boot process (for example, when an image diff --git a/fdts/tbbr_cot_descriptors.dtsi b/fdts/tbbr_cot_descriptors.dtsi index b3c0ca7a2..253297f38 100644 --- a/fdts/tbbr_cot_descriptors.dtsi +++ b/fdts/tbbr_cot_descriptors.dtsi @@ -195,6 +195,12 @@ cot { hash = <&hw_config_hash>; }; + fw_config { + image-id = ; + parent = <&trusted_boot_fw_cert>; + hash = <&fw_config_hash>; + }; + scp_bl2_image { image-id = ; parent = <&scp_fw_content_cert>; diff --git a/include/plat/arm/common/plat_arm.h b/include/plat/arm/common/plat_arm.h index 83a5cd21f..c3756bf5d 100644 --- a/include/plat/arm/common/plat_arm.h +++ b/include/plat/arm/common/plat_arm.h @@ -262,6 +262,9 @@ void arm_bl2_setup_next_ep_info(bl_mem_params_node_t *next_param_node); /* BL2 at EL3 functions */ void arm_bl2_el3_early_platform_setup(void); void arm_bl2_el3_plat_arch_setup(void); +#if ARM_FW_CONFIG_LOAD_ENABLE +void arm_bl2_el3_plat_config_load(void); +#endif /* ARM_FW_CONFIG_LOAD_ENABLE */ /* BL2U utility functions */ void arm_bl2u_early_platform_setup(struct meminfo *mem_layout, diff --git a/plat/arm/common/arm_bl2_el3_setup.c b/plat/arm/common/arm_bl2_el3_setup.c index 01e0db0bc..869830d41 100644 --- a/plat/arm/common/arm_bl2_el3_setup.c +++ b/plat/arm/common/arm_bl2_el3_setup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2023, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2017-2024, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -8,6 +8,8 @@ #include #include +#include +#include #include #include #include @@ -64,6 +66,43 @@ void bl2_el3_early_platform_setup(u_register_t arg0 __unused, generic_delay_timer_init(); } +#if ARM_FW_CONFIG_LOAD_ENABLE +/************************************************************************************* + * FW CONFIG load function for BL2 when RESET_TO_BL2=1 && ARM_FW_CONFIG_LOAD_ENABLE=1 + *************************************************************************************/ +void arm_bl2_el3_plat_config_load(void) +{ + int ret; + const struct dyn_cfg_dtb_info_t *fw_config_info; + + /* Set global DTB info for fixed fw_config information */ + set_config_info(PLAT_FW_CONFIG_BASE, ~0UL, PLAT_FW_CONFIG_MAX_SIZE, FW_CONFIG_ID); + + /* Fill the device tree information struct with the info from the config dtb */ + ret = fconf_load_config(FW_CONFIG_ID); + if (ret < 0) { + ERROR("Loading of FW_CONFIG failed %d\n", ret); + plat_error_handler(ret); + } + + /* + * FW_CONFIG loaded successfully. Check the FW_CONFIG device tree parsing + * is successful. + */ + fw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, FW_CONFIG_ID); + if (fw_config_info == NULL) { + ret = -1; + ERROR("Invalid FW_CONFIG address\n"); + plat_error_handler(ret); + } + ret = fconf_populate_dtb_registry(fw_config_info->config_addr); + if (ret < 0) { + ERROR("Parsing of FW_CONFIG failed %d\n", ret); + plat_error_handler(ret); + } +} +#endif /* ARM_FW_CONFIG_LOAD_ENABLE */ + /******************************************************************************* * Perform the very early platform specific architectural setup here. At the * moment this is only initializes the mmu in a quick and dirty way. diff --git a/plat/arm/common/arm_bl2_setup.c b/plat/arm/common/arm_bl2_setup.c index b5a7db140..d018a9500 100644 --- a/plat/arm/common/arm_bl2_setup.c +++ b/plat/arm/common/arm_bl2_setup.c @@ -140,6 +140,9 @@ void bl2_plat_preload_setup(void) arm_transfer_list_dyn_cfg_init(secure_tl); #else +#if ARM_FW_CONFIG_LOAD_ENABLE + arm_bl2_el3_plat_config_load(); +#endif /* ARM_FW_CONFIG_LOAD_ENABLE */ arm_bl2_dyn_cfg_init(); #endif diff --git a/plat/arm/common/arm_common.mk b/plat/arm/common/arm_common.mk index 0c9b94389..13694b83e 100644 --- a/plat/arm/common/arm_common.mk +++ b/plat/arm/common/arm_common.mk @@ -164,6 +164,25 @@ ifneq ($(filter 1,${RESET_TO_BL31} ${RESET_TO_SP_MIN}),) ENABLE_PIE := 1 endif +# On Arm platform, disable ARM_FW_CONFIG_LOAD_ENABLE by default. +ARM_FW_CONFIG_LOAD_ENABLE := 0 +$(eval $(call assert_boolean,ARM_FW_CONFIG_LOAD_ENABLE)) +$(eval $(call add_define,ARM_FW_CONFIG_LOAD_ENABLE)) + +# In order to enable ARM_FW_CONFIG_LOAD_ENABLE for the Arm platform, the +# platform should be reset to BL2 (RESET_TO_BL2=1), and FW_CONFIG must be +# specified. +ifeq (${ARM_FW_CONFIG_LOAD_ENABLE},1) + ifneq (${RESET_TO_BL2},1) + $(error RESET_TO_BL2 must be enabled when ARM_FW_CONFIG_LOAD_ENABLE \ + is enabled) + endif + ifeq (${FW_CONFIG},) + $(error FW_CONFIG must be specified when ARM_FW_CONFIG_LOAD_ENABLE \ + is enabled) + endif +endif + # Disable GPT parser support, use FIP image by default ARM_GPT_SUPPORT := 0 $(eval $(call assert_boolean,ARM_GPT_SUPPORT))