public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH 1/1] efi_loader: fix building aarch64 EFI binaries
@ 2022-12-31 11:03 Heinrich Schuchardt
  2023-01-03 17:02 ` Simon Glass
  2023-01-04 10:08 ` Ilias Apalodimas
  0 siblings, 2 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2022-12-31 11:03 UTC (permalink / raw)
  To: Ilias Apalodimas; +Cc: u-boot, Heinrich Schuchardt

While our EFI binaries execute without problems on EDK II they crash on
a Lenovo X13s. Let our binaries look more like what EDK II produces:

* move all writable data to a .data section
* align sections to 4 KiB boundaries (matching EFI page size)

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 arch/arm/lib/crt0_aarch64_efi.S  | 35 ++++++++++++++++++++++----------
 arch/arm/lib/elf_aarch64_efi.lds |  6 ++++--
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/arch/arm/lib/crt0_aarch64_efi.S b/arch/arm/lib/crt0_aarch64_efi.S
index b4fc263adf..52b2482efe 100644
--- a/arch/arm/lib/crt0_aarch64_efi.S
+++ b/arch/arm/lib/crt0_aarch64_efi.S
@@ -25,7 +25,7 @@ pe_header:
 	.long	IMAGE_NT_SIGNATURE		/* 'PE' */
 coff_header:
 	.short	IMAGE_FILE_MACHINE_ARM64	/* AArch64 */
-	.short	2				/* nr_sections */
+	.short	3				/* nr_sections */
 	.long	0				/* TimeDateStamp */
 	.long	0				/* PointerToSymbolTable */
 	.long	0				/* NumberOfSymbols */
@@ -40,7 +40,7 @@ optional_header:
 	.short	IMAGE_NT_OPTIONAL_HDR64_MAGIC	/* PE32+ format */
 	.byte	0x02				/* MajorLinkerVersion */
 	.byte	0x14				/* MinorLinkerVersion */
-	.long	_edata - _start			/* SizeOfCode */
+	.long	_etext - _start			/* SizeOfCode */
 	.long	0				/* SizeOfInitializedData */
 	.long	0				/* SizeOfUninitializedData */
 	.long	_start - ImageBase		/* AddressOfEntryPoint */
@@ -48,7 +48,7 @@ optional_header:
 
 extra_header_fields:
 	.quad	0				/* ImageBase */
-	.long	0x200				/* SectionAlignment */
+	.long	0x1000				/* SectionAlignment */
 	.long	0x200				/* FileAlignment */
 	.short	0				/* MajorOperatingSystemVersion */
 	.short	0				/* MinorOperatingSystemVersion */
@@ -107,18 +107,31 @@ section_table:
 	.byte	0
 	.byte	0
 	.byte	0			/* end of 0 padding of section name */
-	.long	_edata - _start		/* VirtualSize */
+	.long	_etext - _start		/* VirtualSize */
 	.long	_start - ImageBase	/* VirtualAddress */
-	.long	_edata - _start		/* SizeOfRawData */
+	.long	_etext - _start		/* SizeOfRawData */
 	.long	_start - ImageBase	/* PointerToRawData */
+	.long	0			/* PointerToRelocations */
+	.long	0			/* PointerToLineNumbers */
+	.short	0			/* NumberOfRelocations */
+	.short	0			/* NumberOfLineNumbers */
+	.long	0x60000020		/* Characteristics (section flags) */
 
-	.long	0		/* PointerToRelocations (0 for executables) */
-	.long	0		/* PointerToLineNumbers (0 for executables) */
-	.short	0		/* NumberOfRelocations  (0 for executables) */
-	.short	0		/* NumberOfLineNumbers  (0 for executables) */
-	.long	0xe0500020	/* Characteristics (section flags) */
+	.ascii	".data"
+	.byte	0
+	.byte	0
+	.byte	0			/* end of 0 padding of section name */
+	.long	_data_size		/* VirtualSize */
+	.long	_data - ImageBase	/* VirtualAddress */
+	.long	_data_size		/* SizeOfRawData */
+	.long	_data - ImageBase	/* PointerToRawData */
+	.long	0			/* PointerToRelocations */
+	.long	0			/* PointerToLineNumbers */
+	.short	0			/* NumberOfRelocations */
+	.short	0			/* NumberOfLineNumbers */
+	.long	0xc0000040		/* Characteristics (section flags) */
 
-	.align		9
+	.align		12
 _start:
 	stp		x29, x30, [sp, #-32]!
 	mov		x29, sp
diff --git a/arch/arm/lib/elf_aarch64_efi.lds b/arch/arm/lib/elf_aarch64_efi.lds
index c0604dad46..ffc6f6e604 100644
--- a/arch/arm/lib/elf_aarch64_efi.lds
+++ b/arch/arm/lib/elf_aarch64_efi.lds
@@ -18,11 +18,13 @@ SECTIONS
 		*(.gnu.linkonce.t.*)
 		*(.srodata)
 		*(.rodata*)
+		. = ALIGN(16);
+		*(.dynamic);
 		. = ALIGN(512);
 	}
 	_etext = .;
 	_text_size = . - _text;
-	.dynamic  : { *(.dynamic) }
+	. = ALIGN(4096);
 	.data : {
 		_data = .;
 		*(.sdata)
@@ -48,11 +50,11 @@ SECTIONS
 		_bss_end = .;
 		_edata = .;
 	}
+	_data_size = _edata - _data;
 	.rela.dyn : { *(.rela.dyn) }
 	.rela.plt : { *(.rela.plt) }
 	.rela.got : { *(.rela.got) }
 	.rela.data : { *(.rela.data) *(.rela.data*) }
-	_data_size = . - _etext;
 
 	. = ALIGN(4096);
 	.dynsym   : { *(.dynsym) }
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] efi_loader: fix building aarch64 EFI binaries
  2022-12-31 11:03 [PATCH 1/1] efi_loader: fix building aarch64 EFI binaries Heinrich Schuchardt
@ 2023-01-03 17:02 ` Simon Glass
  2023-01-04 10:08 ` Ilias Apalodimas
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2023-01-03 17:02 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: Ilias Apalodimas, u-boot

On Sat, 31 Dec 2022 at 05:04, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> While our EFI binaries execute without problems on EDK II they crash on
> a Lenovo X13s. Let our binaries look more like what EDK II produces:
>
> * move all writable data to a .data section
> * align sections to 4 KiB boundaries (matching EFI page size)
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  arch/arm/lib/crt0_aarch64_efi.S  | 35 ++++++++++++++++++++++----------
>  arch/arm/lib/elf_aarch64_efi.lds |  6 ++++--
>  2 files changed, 28 insertions(+), 13 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] efi_loader: fix building aarch64 EFI binaries
  2022-12-31 11:03 [PATCH 1/1] efi_loader: fix building aarch64 EFI binaries Heinrich Schuchardt
  2023-01-03 17:02 ` Simon Glass
@ 2023-01-04 10:08 ` Ilias Apalodimas
  1 sibling, 0 replies; 3+ messages in thread
From: Ilias Apalodimas @ 2023-01-04 10:08 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: u-boot

Hi Heinrich 

On Sat, Dec 31, 2022 at 12:03:45PM +0100, Heinrich Schuchardt wrote:
> While our EFI binaries execute without problems on EDK II they crash on
> a Lenovo X13s. Let our binaries look more like what EDK II produces:
> 
> * move all writable data to a .data section
> * align sections to 4 KiB boundaries (matching EFI page size)
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  arch/arm/lib/crt0_aarch64_efi.S  | 35 ++++++++++++++++++++++----------
>  arch/arm/lib/elf_aarch64_efi.lds |  6 ++++--
>  2 files changed, 28 insertions(+), 13 deletions(-)
> 
> diff --git a/arch/arm/lib/crt0_aarch64_efi.S b/arch/arm/lib/crt0_aarch64_efi.S
> index b4fc263adf..52b2482efe 100644
> --- a/arch/arm/lib/crt0_aarch64_efi.S
> +++ b/arch/arm/lib/crt0_aarch64_efi.S
> @@ -25,7 +25,7 @@ pe_header:
>  	.long	IMAGE_NT_SIGNATURE		/* 'PE' */
>  coff_header:
>  	.short	IMAGE_FILE_MACHINE_ARM64	/* AArch64 */
> -	.short	2				/* nr_sections */
> +	.short	3				/* nr_sections */
>  	.long	0				/* TimeDateStamp */
>  	.long	0				/* PointerToSymbolTable */
>  	.long	0				/* NumberOfSymbols */
> @@ -40,7 +40,7 @@ optional_header:
>  	.short	IMAGE_NT_OPTIONAL_HDR64_MAGIC	/* PE32+ format */
>  	.byte	0x02				/* MajorLinkerVersion */
>  	.byte	0x14				/* MinorLinkerVersion */
> -	.long	_edata - _start			/* SizeOfCode */
> +	.long	_etext - _start			/* SizeOfCode */
>  	.long	0				/* SizeOfInitializedData */
>  	.long	0				/* SizeOfUninitializedData */
>  	.long	_start - ImageBase		/* AddressOfEntryPoint */
> @@ -48,7 +48,7 @@ optional_header:
>  
>  extra_header_fields:
>  	.quad	0				/* ImageBase */
> -	.long	0x200				/* SectionAlignment */
> +	.long	0x1000				/* SectionAlignment */
>  	.long	0x200				/* FileAlignment */
>  	.short	0				/* MajorOperatingSystemVersion */
>  	.short	0				/* MinorOperatingSystemVersion */
> @@ -107,18 +107,31 @@ section_table:
>  	.byte	0
>  	.byte	0
>  	.byte	0			/* end of 0 padding of section name */
> -	.long	_edata - _start		/* VirtualSize */
> +	.long	_etext - _start		/* VirtualSize */
>  	.long	_start - ImageBase	/* VirtualAddress */
> -	.long	_edata - _start		/* SizeOfRawData */
> +	.long	_etext - _start		/* SizeOfRawData */
>  	.long	_start - ImageBase	/* PointerToRawData */
> +	.long	0			/* PointerToRelocations */
> +	.long	0			/* PointerToLineNumbers */
> +	.short	0			/* NumberOfRelocations */
> +	.short	0			/* NumberOfLineNumbers */
> +	.long	0x60000020		/* Characteristics (section flags) */

Can we replace the 0x60000020 magic here with defines from
include/asm-generic/pe.h?

>  
> -	.long	0		/* PointerToRelocations (0 for executables) */
> -	.long	0		/* PointerToLineNumbers (0 for executables) */
> -	.short	0		/* NumberOfRelocations  (0 for executables) */
> -	.short	0		/* NumberOfLineNumbers  (0 for executables) */
> -	.long	0xe0500020	/* Characteristics (section flags) */
> +	.ascii	".data"
> +	.byte	0
> +	.byte	0
> +	.byte	0			/* end of 0 padding of section name */
> +	.long	_data_size		/* VirtualSize */
> +	.long	_data - ImageBase	/* VirtualAddress */
> +	.long	_data_size		/* SizeOfRawData */
> +	.long	_data - ImageBase	/* PointerToRawData */
> +	.long	0			/* PointerToRelocations */
> +	.long	0			/* PointerToLineNumbers */
> +	.short	0			/* NumberOfRelocations */
> +	.short	0			/* NumberOfLineNumbers */
> +	.long	0xc0000040		/* Characteristics (section flags) */

Same here

>  
> -	.align		9
> +	.align		12
>  _start:
>  	stp		x29, x30, [sp, #-32]!
>  	mov		x29, sp
> diff --git a/arch/arm/lib/elf_aarch64_efi.lds b/arch/arm/lib/elf_aarch64_efi.lds
> index c0604dad46..ffc6f6e604 100644
> --- a/arch/arm/lib/elf_aarch64_efi.lds
> +++ b/arch/arm/lib/elf_aarch64_efi.lds
> @@ -18,11 +18,13 @@ SECTIONS
>  		*(.gnu.linkonce.t.*)
>  		*(.srodata)
>  		*(.rodata*)
> +		. = ALIGN(16);
> +		*(.dynamic);
>  		. = ALIGN(512);
>  	}
>  	_etext = .;
>  	_text_size = . - _text;
> -	.dynamic  : { *(.dynamic) }
> +	. = ALIGN(4096);
>  	.data : {
>  		_data = .;
>  		*(.sdata)
> @@ -48,11 +50,11 @@ SECTIONS
>  		_bss_end = .;
>  		_edata = .;
>  	}
> +	_data_size = _edata - _data;
>  	.rela.dyn : { *(.rela.dyn) }
>  	.rela.plt : { *(.rela.plt) }
>  	.rela.got : { *(.rela.got) }
>  	.rela.data : { *(.rela.data) *(.rela.data*) }
> -	_data_size = . - _etext;
>  
>  	. = ALIGN(4096);
>  	.dynsym   : { *(.dynsym) }
> -- 
> 2.37.2
> 

Regards
/Ilias

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-04 10:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-31 11:03 [PATCH 1/1] efi_loader: fix building aarch64 EFI binaries Heinrich Schuchardt
2023-01-03 17:02 ` Simon Glass
2023-01-04 10:08 ` Ilias Apalodimas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox