From: Ahmad Fatoum <[email protected]> EFI runtime services support was added before barebox proper was made an ELF and back then it proved too cumbersome to have two non-adjacent text areas for each of the boot-time and run-time portions.
Now that barebox proper is an ELF, let's move the EFI runtime data and text each into its own segment with the appropriate segment flags, so pbl_mmu_setup_from_elf() can apply the correct protections. The runtime sections are also moved between rodata and data rather than at the end of the image: sections in a PT_LOAD must be contiguous, so in the old position .bss would have had to move into the efirt_data segment, inflating its p_memsz by all of barebox's bss, which would make a BSS worth of memory unusable by the running kernel. This does not yet introduce a functional change: without ARM_MMU_PERMISSIONS, all cached mappings remain RWX. Assisted-by: Claude:fable-5 Signed-off-by: Ahmad Fatoum <[email protected]> --- arch/arm/lib32/barebox.lds.S | 12 +++++++++--- arch/arm/lib64/barebox.lds.S | 12 +++++++++--- include/asm-generic/barebox.lds.h | 6 ++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/arch/arm/lib32/barebox.lds.S b/arch/arm/lib32/barebox.lds.S index 02db3b9790b7..e5ef2d045218 100644 --- a/arch/arm/lib32/barebox.lds.S +++ b/arch/arm/lib32/barebox.lds.S @@ -13,6 +13,10 @@ PHDRS text PT_LOAD FLAGS(5); /* PF_R | PF_X */ rodata PT_LOAD FLAGS(4); /* PF_R */ dynamic PT_DYNAMIC FLAGS(4); /* PF_R */ +#ifdef CONFIG_EFI_RUNTIME + efirt_text PT_LOAD FLAGS(5); /* PF_R | PF_X */ + efirt_data PT_LOAD FLAGS(6); /* PF_R | PF_W */ +#endif data PT_LOAD FLAGS(6); /* PF_R | PF_W */ } @@ -63,6 +67,9 @@ SECTIONS __end_rodata = .; _etext = .; + + BAREBOX_EFI_RUNTIME + _sdata = .; .data : { *(.data*) } :data @@ -73,8 +80,6 @@ SECTIONS _edata = .; - BAREBOX_EFI_RUNTIME - .image_end : { *(.__image_end) } :data . = ALIGN(4); @@ -94,4 +99,5 @@ SECTIONS _barebox_image_size = __bss_start; } -NOCROSSREFS_FROM(.efi_runtime) +NOCROSSREFS_FROM(.efi_runtime.text) +NOCROSSREFS_FROM(.efi_runtime.data) diff --git a/arch/arm/lib64/barebox.lds.S b/arch/arm/lib64/barebox.lds.S index 1dddd6d1a942..a06a078d4142 100644 --- a/arch/arm/lib64/barebox.lds.S +++ b/arch/arm/lib64/barebox.lds.S @@ -12,6 +12,10 @@ PHDRS text PT_LOAD FLAGS(5); /* PF_R | PF_X */ rodata PT_LOAD FLAGS(4); /* PF_R */ dynamic PT_DYNAMIC FLAGS(4); /* PF_R */ +#ifdef CONFIG_EFI_RUNTIME + efirt_text PT_LOAD FLAGS(5); /* PF_R | PF_X */ + efirt_data PT_LOAD FLAGS(6); /* PF_R | PF_W */ +#endif data PT_LOAD FLAGS(6); /* PF_R | PF_W */ } @@ -43,14 +47,15 @@ SECTIONS __end_rodata = .; _etext = .; + + BAREBOX_EFI_RUNTIME + _sdata = .; .data : { *(.data*) } :data _edata = .; - BAREBOX_EFI_RUNTIME - .image_end : { *(.__image_end) } :data . = ALIGN(4); @@ -61,4 +66,5 @@ SECTIONS _barebox_image_size = __bss_start; } -NOCROSSREFS_FROM(.efi_runtime) +NOCROSSREFS_FROM(.efi_runtime.text) +NOCROSSREFS_FROM(.efi_runtime.data) diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h index 008217e808cb..c672894ad502 100644 --- a/include/asm-generic/barebox.lds.h +++ b/include/asm-generic/barebox.lds.h @@ -157,7 +157,7 @@ #ifdef CONFIG_EFI_RUNTIME #define BAREBOX_EFI_RUNTIME \ . = ALIGN(4096); \ - .efi_runtime : { \ + .efi_runtime.text : { \ __efi_runtime_start = .; \ __efi_runtime_text_start = .; \ *(.efi_runtime.text*) \ @@ -166,12 +166,14 @@ *(.efi_runtime.rodata*) \ __efi_runtime_rodata_stop = .; \ . = ALIGN(4096); \ + } :efirt_text \ + .efi_runtime.data : { \ __efi_runtime_data_start = .; \ *(.efi_runtime.data*) \ *(.efi_runtime.bss*) \ __efi_runtime_data_stop = .; \ __efi_runtime_stop = .; \ - } \ + } :efirt_data \ . = ALIGN(4096); #else #define BAREBOX_EFI_RUNTIME -- 2.47.3
