feat(arm): migrate heap info to fw handoff

Mbed-TLS requires platforms to allocate it a heap for it's own internal
usage. This heap is typically between shared by BL1 and BL2 to conserve
memory.The base address and size of the heap are conveyed from BL1 to
BL2 through the config TB_FW_CONFIG.

This slightly awkward approach necessitates declaring a placeholder node
in the DTS. At runtime, this node is populated with the actual values of
the heap information. Instead, since this is dynamic information, and
simple to represent through C structures, transmit it to later stages
using the firmware handoff framework.

With this migration, remove references to TB_FW_CONFIG when firmware
handoff is enabled, as it is no longer needed. The setup code now relies
solely on TL structures to configure the TB firmware

Change-Id: Iff00dc742924a055b8bd304f15eec03ce3c6d1ef
Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
This commit is contained in:
Harrison Mutai 2024-05-28 14:35:41 +00:00
parent 24da55eef7
commit ada4e59d16
6 changed files with 69 additions and 37 deletions

View file

@ -288,6 +288,11 @@ void arm_bl31_plat_arch_setup(void);
void arm_transfer_list_dyn_cfg_init(struct transfer_list_header *secure_tl); void arm_transfer_list_dyn_cfg_init(struct transfer_list_header *secure_tl);
void arm_transfer_list_populate_ep_info(bl_mem_params_node_t *next_param_node, void arm_transfer_list_populate_ep_info(bl_mem_params_node_t *next_param_node,
struct transfer_list_header *secure_tl); struct transfer_list_header *secure_tl);
void arm_transfer_list_copy_hw_config(struct transfer_list_header *secure_tl,
struct transfer_list_header *ns_tl);
struct transfer_list_entry *
arm_transfer_list_set_heap_info(struct transfer_list_header *tl);
void arm_transfer_list_get_heap_info(void **heap_addr, size_t *heap_size);
/* TSP utility functions */ /* TSP utility functions */
void arm_tsp_early_platform_setup(void); void arm_tsp_early_platform_setup(void);

View file

@ -338,17 +338,12 @@ endif
# Add the FDT_SOURCES and options for Dynamic Config (only for Unix env) # Add the FDT_SOURCES and options for Dynamic Config (only for Unix env)
ifdef UNIX_MK ifdef UNIX_MK
FVP_TB_FW_CONFIG := ${BUILD_PLAT}/fdts/${PLAT}_tb_fw_config.dtb
FVP_HW_CONFIG_DTS := fdts/${FVP_DT_PREFIX}.dts FVP_HW_CONFIG_DTS := fdts/${FVP_DT_PREFIX}.dts
FDT_SOURCES += ${FVP_HW_CONFIG_DTS} FDT_SOURCES += ${FVP_HW_CONFIG_DTS}
$(eval FVP_HW_CONFIG := ${BUILD_PLAT}/$(patsubst %.dts,%.dtb,$(FVP_HW_CONFIG_DTS))) $(eval FVP_HW_CONFIG := ${BUILD_PLAT}/$(patsubst %.dts,%.dtb,$(FVP_HW_CONFIG_DTS)))
ifeq (${TRANSFER_LIST}, 1) ifeq (${TRANSFER_LIST}, 0)
FDT_SOURCES += $(addprefix plat/arm/board/fvp/fdts/, \
${PLAT}_tb_fw_config.dts \
)
else
FDT_SOURCES += $(addprefix plat/arm/board/fvp/fdts/, \ FDT_SOURCES += $(addprefix plat/arm/board/fvp/fdts/, \
${PLAT}_fw_config.dts \ ${PLAT}_fw_config.dts \
${PLAT}_tb_fw_config.dts \ ${PLAT}_tb_fw_config.dts \
@ -356,6 +351,7 @@ FDT_SOURCES += $(addprefix plat/arm/board/fvp/fdts/, \
${PLAT}_nt_fw_config.dts \ ${PLAT}_nt_fw_config.dts \
) )
FVP_TB_FW_CONFIG := ${BUILD_PLAT}/fdts/${PLAT}_tb_fw_config.dtb
FVP_FW_CONFIG := ${BUILD_PLAT}/fdts/${PLAT}_fw_config.dtb FVP_FW_CONFIG := ${BUILD_PLAT}/fdts/${PLAT}_fw_config.dtb
FVP_SOC_FW_CONFIG := ${BUILD_PLAT}/fdts/${PLAT}_soc_fw_config.dtb FVP_SOC_FW_CONFIG := ${BUILD_PLAT}/fdts/${PLAT}_soc_fw_config.dtb
FVP_NT_FW_CONFIG := ${BUILD_PLAT}/fdts/${PLAT}_nt_fw_config.dtb FVP_NT_FW_CONFIG := ${BUILD_PLAT}/fdts/${PLAT}_nt_fw_config.dtb
@ -387,10 +383,10 @@ $(eval $(call TOOL_ADD_PAYLOAD,${FVP_FW_CONFIG},--fw-config,${FVP_FW_CONFIG}))
$(eval $(call TOOL_ADD_PAYLOAD,${FVP_SOC_FW_CONFIG},--soc-fw-config,${FVP_SOC_FW_CONFIG})) $(eval $(call TOOL_ADD_PAYLOAD,${FVP_SOC_FW_CONFIG},--soc-fw-config,${FVP_SOC_FW_CONFIG}))
# Add the NT_FW_CONFIG to FIP and specify the same to certtool # Add the NT_FW_CONFIG to FIP and specify the same to certtool
$(eval $(call TOOL_ADD_PAYLOAD,${FVP_NT_FW_CONFIG},--nt-fw-config,${FVP_NT_FW_CONFIG})) $(eval $(call TOOL_ADD_PAYLOAD,${FVP_NT_FW_CONFIG},--nt-fw-config,${FVP_NT_FW_CONFIG}))
endif
# Add the TB_FW_CONFIG to FIP and specify the same to certtool # Add the TB_FW_CONFIG to FIP and specify the same to certtool
$(eval $(call TOOL_ADD_PAYLOAD,${FVP_TB_FW_CONFIG},--tb-fw-config,${FVP_TB_FW_CONFIG})) $(eval $(call TOOL_ADD_PAYLOAD,${FVP_TB_FW_CONFIG},--tb-fw-config,${FVP_TB_FW_CONFIG}))
endif
# Add the HW_CONFIG to FIP and specify the same to certtool # Add the HW_CONFIG to FIP and specify the same to certtool
$(eval $(call TOOL_ADD_PAYLOAD,${FVP_HW_CONFIG},--hw-config,${FVP_HW_CONFIG})) $(eval $(call TOOL_ADD_PAYLOAD,${FVP_HW_CONFIG},--hw-config,${FVP_HW_CONFIG}))
endif endif

View file

@ -162,7 +162,7 @@ void arm_bl1_platform_setup(void)
image_desc_t *desc; image_desc_t *desc;
int err = -1; int err __unused = 1;
/* Initialise the IO layer and register platform IO devices */ /* Initialise the IO layer and register platform IO devices */
plat_arm_io_setup(); plat_arm_io_setup();
@ -175,27 +175,24 @@ void arm_bl1_platform_setup(void)
} }
#if TRANSFER_LIST #if TRANSFER_LIST
te = transfer_list_add(secure_tl, TL_TAG_TB_FW_CONFIG, #if CRYPTO_SUPPORT
ARM_TB_FW_CONFIG_MAX_SIZE, NULL); te = transfer_list_add(secure_tl, TL_TAG_MBEDTLS_HEAP_INFO,
sizeof(struct crypto_heap_info), NULL);
assert(te != NULL); assert(te != NULL);
struct crypto_heap_info *heap_info =
(struct crypto_heap_info *)transfer_list_entry_data(te);
arm_get_mbedtls_heap(&heap_info->addr, &heap_info->size);
#endif /* CRYPTO_SUPPORT */
desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
/* /*
* Set the load address of TB_FW_CONFIG in the data section of the TE just * The event log might have been updated prior to this, make sure we have an
* allocated in the secure transfer list. * up to date tl before setting the handoff arguments.
*/ */
SET_PARAM_HEAD(&config_image_info, PARAM_IMAGE_BINARY, VERSION_2, 0);
config_image_info.image_base = (uintptr_t)transfer_list_entry_data(te);
config_image_info.image_max_size = te->data_size;
VERBOSE("FCONF: Loading config with image ID: %u\n", TB_FW_CONFIG_ID);
err = load_auth_image(TB_FW_CONFIG_ID, &config_image_info);
if (err != 0) {
VERBOSE("Failed to load config %u\n", TB_FW_CONFIG_ID);
plat_error_handler(err);
}
transfer_list_update_checksum(secure_tl); transfer_list_update_checksum(secure_tl);
fconf_populate("TB_FW", (uintptr_t)transfer_list_entry_data(te)); transfer_list_set_handoff_args(secure_tl, &desc->ep_info);
#else #else
/* Set global DTB info for fixed fw_config information */ /* Set global DTB info for fixed fw_config information */
fw_config_max_size = ARM_FW_CONFIG_LIMIT - ARM_FW_CONFIG_BASE; fw_config_max_size = ARM_FW_CONFIG_LIMIT - ARM_FW_CONFIG_BASE;
@ -230,22 +227,18 @@ void arm_bl1_platform_setup(void)
ERROR("Invalid FW_CONFIG address\n"); ERROR("Invalid FW_CONFIG address\n");
plat_error_handler(err); plat_error_handler(err);
} }
#endif /* TRANSFER_LIST */
desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
#if TRANSFER_LIST
transfer_list_set_handoff_args(secure_tl, &desc->ep_info);
#else
/* The BL2 ep_info arg0 is modified to point to FW_CONFIG */ /* The BL2 ep_info arg0 is modified to point to FW_CONFIG */
assert(desc != NULL); assert(desc != NULL);
desc->ep_info.args.arg0 = config_info->config_addr; desc->ep_info.args.arg0 = config_info->config_addr;
#endif /* TRANSFER_LIST */
#if CRYPTO_SUPPORT #if CRYPTO_SUPPORT
/* Share the Mbed TLS heap info with other images */ /* Share the Mbed TLS heap info with other images */
arm_bl1_set_mbedtls_heap(); arm_bl1_set_mbedtls_heap();
#endif /* CRYPTO_SUPPORT */ #endif /* CRYPTO_SUPPORT */
#endif /* TRANSFER_LIST */
/* /*
* Allow access to the System counter timer module and program * Allow access to the System counter timer module and program

View file

@ -230,11 +230,10 @@ void bl2_plat_arch_setup(void)
arm_bl2_plat_arch_setup(); arm_bl2_plat_arch_setup();
#if TRANSFER_LIST #if TRANSFER_LIST
te = transfer_list_find(secure_tl, TL_TAG_TB_FW_CONFIG); #if CRYPTO_SUPPORT
assert(te != NULL); te = arm_transfer_list_set_heap_info(secure_tl);
fconf_populate("TB_FW", (uintptr_t)transfer_list_entry_data(te));
transfer_list_rem(secure_tl, te); transfer_list_rem(secure_tl, te);
#endif /* CRYPTO_SUPPORT */
#else #else
/* Fill the properties struct with the info from the config dtb */ /* Fill the properties struct with the info from the config dtb */
fconf_populate("FW_CONFIG", config_base); fconf_populate("FW_CONFIG", config_base);
@ -244,7 +243,7 @@ void bl2_plat_arch_setup(void)
assert(tb_fw_config_info != NULL); assert(tb_fw_config_info != NULL);
fconf_populate("TB_FW", tb_fw_config_info->config_addr); fconf_populate("TB_FW", tb_fw_config_info->config_addr);
#endif #endif /* TRANSFER_LIST */
} }
int arm_bl2_handle_post_image_load(unsigned int image_id) int arm_bl2_handle_post_image_load(unsigned int image_id)

View file

@ -23,7 +23,7 @@
#include <plat/arm/common/plat_arm.h> #include <plat/arm/common/plat_arm.h>
#include <platform_def.h> #include <platform_def.h>
#if CRYPTO_SUPPORT #if CRYPTO_SUPPORT && !TRANSFER_LIST
static void *mbedtls_heap_addr; static void *mbedtls_heap_addr;
static size_t mbedtls_heap_size; static size_t mbedtls_heap_size;
@ -118,7 +118,7 @@ void arm_bl1_set_mbedtls_heap(void)
#endif /* !MEASURED_BOOT */ #endif /* !MEASURED_BOOT */
} }
} }
#endif /* CRYPTO_SUPPORT */ #endif /* CRYPTO_SUPPORT && !TRANSFER_LIST */
#if IMAGE_BL2 #if IMAGE_BL2
/* /*

View file

@ -4,9 +4,48 @@
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#if CRYPTO_SUPPORT
#include <mbedtls/version.h>
#endif /* CRYPTO_SUPPORT */
#include <plat/arm/common/plat_arm.h> #include <plat/arm/common/plat_arm.h>
#include <platform_def.h> #include <platform_def.h>
#if CRYPTO_SUPPORT
#if defined(IMAGE_BL1) || RESET_TO_BL2 || defined(IMAGE_BL31)
static unsigned char heap[TF_MBEDTLS_HEAP_SIZE];
#define MBEDTLS_HEAP_ADDR heap
#define MBEDTLS_HEAP_SIZE sizeof(heap)
#else
static struct crypto_heap_info heap_info;
#define MBEDTLS_HEAP_ADDR heap_info.addr
#define MBEDTLS_HEAP_SIZE heap_info.size
struct transfer_list_entry *
arm_transfer_list_set_heap_info(struct transfer_list_header *tl)
{
struct transfer_list_entry *te =
transfer_list_find(tl, TL_TAG_MBEDTLS_HEAP_INFO);
assert(te != NULL);
heap_info = *(struct crypto_heap_info *)transfer_list_entry_data(te);
return te;
}
#endif /* defined(IMAGE_BL1) || RESET_TO_BL2 || defined(IMAGE_BL31) */
int __init arm_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
{
assert(heap_addr != NULL);
assert(heap_size != NULL);
*heap_addr = MBEDTLS_HEAP_ADDR;
*heap_size = MBEDTLS_HEAP_SIZE;
return 0;
}
#endif /* CRYPTO_SUPPORT */
void arm_transfer_list_dyn_cfg_init(struct transfer_list_header *tl) void arm_transfer_list_dyn_cfg_init(struct transfer_list_header *tl)
{ {
struct transfer_list_entry *te; struct transfer_list_entry *te;