mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-07 21:33:54 +00:00
refactor(bl1): clean up bl2 layout calculation
Layout calculation is spread out between core BL1 logic and common platform code. Relocate these into common platform code so they are organised logically. Change-Id: I8b05403e41b800957a0367316cecd373d10bb1a4 Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
This commit is contained in:
parent
a5566f65fd
commit
6a4da29058
7 changed files with 52 additions and 69 deletions
|
@ -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.
|
||||
******************************************************************************/
|
||||
|
|
|
@ -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]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
******************************************************************************/
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue