efi: payload: early-mem: add memory type on early mem allocation
PATCH 1/1 efi: payload: early-mem: add memory type on early mem allocation
From: Chali Anis <[email protected]>
Add the ability to specify the memory type which mendatory for the recent efi versions that have MMU, this will fix a permission fault on second level when trying to relocate the barebox or even execting the memory code. see the snapshot error log below.
SP 0x000000007C6CFF80 ELR 0x000000006C6EA4FC SPSR 0x60000205 FPSR 0x00000000
ESR 0x8600000E FAR 0x000000006C6EA4FC
ESR : EC 0x21 IL 0x1 ISS 0x0000000E
Instruction abort: Permission fault, second level
--- efi/payload/early-mem.c | 4 ++-- efi/payload/entry-multi.c | 2 +- efi/payload/entry-single.c | 2 +- include/efi/efi-payload.h | 4 +++- 4 files changed, 7 insertions(+), 5 deletions(-)
efi/payload/early-mem.c +2 -2
@@ -6,7 +6,7 @@#include <efi/efi-payload.h> void *efi_earlymem_alloc (const struct efi_system_table *sys_table, -size_t *memsize) +size_t *memsize,enum efi_memory_type mem_type) {struct efi_boot_services *bs = sys_table->boottime;enum efi_allocate_type alloc_type =EFI_ALLOCATE_ANY_PAGES ;
@@ -20,7 +20,7 @@ void *efi_earlymem_alloc(const struct efi_system_table *sys_table, }for (*memsize =SZ_256M ; *memsize >=SZ_8M ; *memsize /=2 ) { - efiret = bs->allocate_pages (alloc_type,EFI_LOADER_DATA , + efiret = bs->allocate_pages (alloc_type, mem_type, *memsize /EFI_PAGE_SIZE , &mem);if (!EFI_ERROR (efiret) || efiret !=EFI_OUT_OF_RESOURCES )break ;
efi/payload/entry-multi.c +1 -1
@@ -37,7 +37,7 @@ void __efistub_efi_pe_entry(void *image, struct efi_system_table *sys_table)handoff_data_add (HANDOFF_DATA_EFI , &efidata,sizeof (efidata)); - mem =efi_earlymem_alloc (sys_table, &memsize); + mem =efi_earlymem_alloc (sys_table, &memsize,EFI_LOADER_CODE );barebox_pbl_entry ((uintptr_t )mem, memsize,NULL ); }
efi/payload/entry-single.c +1 -1
@@ -37,7 +37,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)BS ->handle_protocol (efi_loaded_image->device_handle, &efi_device_path_protocol_guid, (void **)&efi_device_path); - mem =efi_earlymem_alloc (sys_table, &memsize); + mem =efi_earlymem_alloc (sys_table, &memsize,EFI_LOADER_CODE );mem_malloc_init (mem, mem + memsize -1 );
include/efi/efi-payload.h +3 -1
@@ -4,6 +4,7 @@#include <efi/types.h> #include <efi/efi-util.h> +#include <efi/memtype.h> struct efi_system_table ;struct efi_loaded_image ;
@@ -30,6 +31,7 @@ int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes, void *buf, size_t size);int efi_set_variable_usec (char *name,efi_guid_t *vendor,uint64_t usec); -void *efi_earlymem_alloc (const struct efi_system_table *sys_table,size_t *memsize); +void *efi_earlymem_alloc (const struct efi_system_table *sys_table, +size_t *memsize,enum efi_memory_type mem_type);#endif
Signature · 1 line
2.34.1
Sascha Hauer
AppliedQuoted 11 lines · On Fri, 22 Aug 2025 01:37:17 -0400, [email protected] wrote:
Add the ability to specify the memory type which mendatory for the recent efi versions that have MMU, this will fix a permission fault on second level when trying to relocate the barebox or even execting the memory code. see the snapshot error log below.
SP
0x000000007C6CFF80ELR0x000000006C6EA4FCSPSR0x60000205FPSR0x00000000
ESR0x8600000EFAR0x000000006C6EA4FC
ESR : EC0x21IL0x1ISS0x0000000E
Instruction abort: Permission fault, second level[...]
Applied, thanks!
[1/1] efi: payload: early-mem: add memory type on early mem allocation
https://git.pengutronix.de/cgit/barebox/commit/?id=7497c86c5032 (link may not be stable)
Best regards,
Signature · 1 line
Sascha Hauer <[email protected]>