diff --git a/bl1/bl1_main.c b/bl1/bl1_main.c index 6fe551188..1dfdc459b 100644 --- a/bl1/bl1_main.c +++ b/bl1/bl1_main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -38,27 +38,6 @@ uint64_t bl1_apiakey[2]; BL_TOTAL_IDS, PMF_DUMP_ENABLE) #endif -/******************************************************************************* - * Helper utility to calculate the BL2 memory layout taking into consideration - * the BL1 RW data assuming that it is at the top of the memory layout. - ******************************************************************************/ -void bl1_calc_bl2_mem_layout(const meminfo_t *bl1_mem_layout, - meminfo_t *bl2_mem_layout) -{ - assert(bl1_mem_layout != NULL); - assert(bl2_mem_layout != NULL); - - /* - * Remove BL1 RW data from the scope of memory visible to BL2. - * This is assuming BL1 RW data is at the top of bl1_mem_layout. - */ - assert(BL1_RW_BASE > bl1_mem_layout->total_base); - bl2_mem_layout->total_base = bl1_mem_layout->total_base; - bl2_mem_layout->total_size = BL1_RW_BASE - bl1_mem_layout->total_base; - - flush_dcache_range((uintptr_t)bl2_mem_layout, sizeof(meminfo_t)); -} - /******************************************************************************* * Setup function for BL1. ******************************************************************************/ diff --git a/docs/porting-guide.rst b/docs/porting-guide.rst index 7c66d1118..5d9840aab 100644 --- a/docs/porting-guide.rst +++ b/docs/porting-guide.rst @@ -1712,6 +1712,18 @@ This function can be used by the platforms to update/use image information corresponding to ``image_id``. This function is invoked in BL1, both in cold boot and FWU code path, before loading the image. +Function : bl1_plat_calc_bl2_layout() [optional] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +:: + + Argument : const meminfo_t *bl1_mem_layout, meminfo_t *bl2_mem_layout + Return : void + +This utility function calculates the memory layout of BL2, representing it in a +`meminfo_t` structure. The default implementation derives this layout from the +positioning of BL1’s RW data at the top of the memory layout. + Function : bl1_plat_handle_post_image_load() [optional] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/bl1/bl1.h b/include/bl1/bl1.h index 7cd7e727c..3ab88de96 100644 --- a/include/bl1/bl1.h +++ b/include/bl1/bl1.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -94,9 +94,5 @@ CASSERT(FWU_NUM_SMC_CALLS == (FWU_SMC_FID_END - FWU_SMC_FID_START + 1), assert_FWU_NUM_SMC_CALLS_mismatch); -/* Utility functions */ -void bl1_calc_bl2_mem_layout(const meminfo_t *bl1_mem_layout, - meminfo_t *bl2_mem_layout); - #endif /* __ASSEMBLER__ */ #endif /* BL1_H */ diff --git a/include/plat/common/platform.h b/include/plat/common/platform.h index 4fe362005..2af49a93e 100644 --- a/include/plat/common/platform.h +++ b/include/plat/common/platform.h @@ -243,7 +243,11 @@ __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved); int bl1_plat_handle_pre_image_load(unsigned int image_id); int bl1_plat_handle_post_image_load(unsigned int image_id); -#if (MEASURED_BOOT || DICE_PROTECTION_ENVIRONMENT) +/* Utility functions */ +void bl1_plat_calc_bl2_layout(const meminfo_t *bl1_mem_layout, + meminfo_t *bl2_mem_layout); + +#if MEASURED_BOOT void bl1_plat_mboot_init(void); void bl1_plat_mboot_finish(void); #else diff --git a/plat/arm/board/fvp_r/fvp_r_bl1_main.c b/plat/arm/board/fvp_r/fvp_r_bl1_main.c index 252fc31fb..29495cfcb 100644 --- a/plat/arm/board/fvp_r/fvp_r_bl1_main.c +++ b/plat/arm/board/fvp_r/fvp_r_bl1_main.c @@ -91,27 +91,6 @@ void bl1_load_bl33(void) NOTICE("BL1: Booting BL33\n"); } -/******************************************************************************* - * Helper utility to calculate the BL2 memory layout taking into consideration - * the BL1 RW data assuming that it is at the top of the memory layout. - ******************************************************************************/ -void bl1_calc_bl2_mem_layout(const meminfo_t *bl1_mem_layout, - meminfo_t *bl2_mem_layout) -{ - assert(bl1_mem_layout != NULL); - assert(bl2_mem_layout != NULL); - - /* - * Remove BL1 RW data from the scope of memory visible to BL2. - * This is assuming BL1 RW data is at the top of bl1_mem_layout. - */ - assert(bl1_mem_layout->total_base < BL1_RW_BASE); - bl2_mem_layout->total_base = bl1_mem_layout->total_base; - bl2_mem_layout->total_size = BL1_RW_BASE - bl1_mem_layout->total_base; - - flush_dcache_range((uintptr_t)bl2_mem_layout, sizeof(meminfo_t)); -} - /******************************************************************************* * This function prepares for entry to BL33 ******************************************************************************/ diff --git a/plat/arm/board/fvp_r/fvp_r_bl1_setup.c b/plat/arm/board/fvp_r/fvp_r_bl1_setup.c index 6a7c0c808..dcf5e0465 100644 --- a/plat/arm/board/fvp_r/fvp_r_bl1_setup.c +++ b/plat/arm/board/fvp_r/fvp_r_bl1_setup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2021-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -235,7 +235,7 @@ int bl1_plat_handle_post_image_load(unsigned int image_id) */ bl33_secram_layout = (meminfo_t *) bl1_secram_layout->total_base; - bl1_calc_bl2_mem_layout(bl1_secram_layout, bl33_secram_layout); + bl1_plat_calc_bl2_layout(bl1_secram_layout, bl33_secram_layout); ep_info->args.arg1 = (uintptr_t)bl33_secram_layout; diff --git a/plat/common/plat_bl1_common.c b/plat/common/plat_bl1_common.c index bcf9f8956..ff0e0828c 100644 --- a/plat/common/plat_bl1_common.c +++ b/plat/common/plat_bl1_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2021, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -80,10 +80,8 @@ int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size, */ int bl1_plat_handle_post_image_load(unsigned int image_id) { - meminfo_t *bl2_secram_layout; - meminfo_t *bl1_secram_layout; + meminfo_t *bl1_tzram_layout; image_desc_t *image_desc; - entry_point_info_t *ep_info; if (image_id != BL2_IMAGE_ID) return 0; @@ -92,26 +90,41 @@ int bl1_plat_handle_post_image_load(unsigned int image_id) image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); assert(image_desc != NULL); - /* Get the entry point info */ - ep_info = &image_desc->ep_info; - /* Find out how much free trusted ram remains after BL1 load */ - bl1_secram_layout = bl1_plat_sec_mem_layout(); + bl1_tzram_layout = bl1_plat_sec_mem_layout(); /* - * Create a new layout of memory for BL2 as seen by BL1 i.e. - * tell it the amount of total and free memory available. - * This layout is created at the first free address visible - * to BL2. BL2 will read the memory layout before using its - * memory for other purposes. + * Convey this information to BL2 by storing the layout at the first free + * address visible to BL2. */ - bl2_secram_layout = (meminfo_t *) bl1_secram_layout->total_base; + bl1_plat_calc_bl2_layout(bl1_tzram_layout, + (meminfo_t *)bl1_tzram_layout->total_base); - bl1_calc_bl2_mem_layout(bl1_secram_layout, bl2_secram_layout); - - ep_info->args.arg1 = (uintptr_t)bl2_secram_layout; + image_desc->ep_info.args.arg1 = (uintptr_t)bl1_tzram_layout->total_base; VERBOSE("BL1: BL2 memory layout address = %p\n", - (void *) bl2_secram_layout); + (void *)image_desc->ep_info.args.arg1); + return 0; } + +/******************************************************************************* + * Helper utility to calculate the BL2 memory layout taking into consideration + * the BL1 RW data assuming that it is at the top of the memory layout. + ******************************************************************************/ +void bl1_plat_calc_bl2_layout(const meminfo_t *bl1_mem_layout, + meminfo_t *bl2_mem_layout) +{ + assert(bl1_mem_layout != NULL); + assert(bl2_mem_layout != NULL); + + /* + * Remove BL1 RW data from the scope of memory visible to BL2. + * This is assuming BL1 RW data is at the top of bl1_mem_layout. + */ + assert(BL1_RW_BASE > bl1_mem_layout->total_base); + bl2_mem_layout->total_base = bl1_mem_layout->total_base; + bl2_mem_layout->total_size = BL1_RW_BASE - bl1_mem_layout->total_base; + + flush_dcache_range((uintptr_t)bl2_mem_layout, sizeof(meminfo_t)); +}