summaryrefslogtreecommitdiffstats
path: root/documentation
diff options
context:
space:
mode:
authorRegia König2022-08-16 16:20:17 +0200
committerRegia König2022-08-16 16:20:17 +0200
commitaf267979164d1bb9f412705e22fc64ab00b7d899 (patch)
tree329ab7284a09ae0c2b590eb7b4c6f10cfccc7a94 /documentation
parentMinimal working example with GNU-efi (diff)
downloadmemtest86-af267979164d1bb9f412705e22fc64ab00b7d899.tar.gz
memtest86-af267979164d1bb9f412705e22fc64ab00b7d899.tar.xz
memtest86-af267979164d1bb9f412705e22fc64ab00b7d899.zip
More documentation on GNU-efi
Diffstat (limited to 'documentation')
-rw-r--r--documentation/GNU-efi69
1 files changed, 69 insertions, 0 deletions
diff --git a/documentation/GNU-efi b/documentation/GNU-efi
index 8dddc4a..bb22b9e 100644
--- a/documentation/GNU-efi
+++ b/documentation/GNU-efi
@@ -104,3 +104,72 @@ LINKER SCRIPT:
OR
* /usr/lib/elf_x86_64_efi.lds
+COMPILATION:
+$ gcc
+ -Ignu-efi-dir/inc || set this to the efi headers directory
+
+ -fpic || UEFI PE executable must be relocatable
+
+ -ffreestanding || there's no hosted gcc environment,
+ we don't have libc
+ -fno-stack-protector =
+ -fno-stack-check || stack must be strictly used,
+ || no additional canaries or
+ || pre-allocated local variable
+ || space allowed
+ -mno-red-zone =
+
+ -fshort-wchar || It is very important that UEFI
+ || uses 16bit characters
+ || (wide-characters or wchar_t,
+ || defined as CHAR16 in efi headers
+
+ -maccumulate-outgoing-args || function calls must include the
+ || number of argumnets passed to the
+ || functions
+
+ -c main.c -o main.o
+
+LINKING:
+$ ld -shared -Bsymbolic -Lgnu-efi-dir/x86_64/lib -Lgnu-efi-dir/x86_64/gnuefi \
+ -Tgnu-efi-dir/gnuefi/elf_x86_64_efi.lds \
+ gnu-efi-dir/x86_64/gnuefi/crt0-efi-x86_64.o \
+ main.o -o main.so -lgnuefi -lefi
+
+ -shared -Bsymbolic || tell GNU ld to create so (shared library)
+
+ -L and -T || Where to find the static GNU-EFI libraries
+ || (.a) and the linker script
+
+ .o || it is important to specify crt0 as the
+ || first. Should work as the last too, but
+ || some had problems
+
+ -l || linking with gnuefi is a must, as that
+ || contains the relocation code. Linking
+ || with efi is optional, but recommended
+
+CONVERT CHARED OBJECT TO EFI EXECUTABLE
+$ objcopy -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.*
+ -j .rela.* -j .reloc --target efi-app-x86_64 --subsystem=10 main.so main.efi
+
+ -j || which sections to keep during convertion
+
+ --target efi-app-x86_64 || tells objcop to generate a PE32+ format,
+ || with architecture code 0x8664
+
+ --subsystem=10: || most important. Sets file type to UEFI
+ || executable in the PE header
+
+Now you can copy main.efi to your EFI System Partition, and after boot run it
+from the EFI Shell. Or you can rename it to EFI\BOOT\BOOTX64.EFI and it should
+be executed automatically on boot.
+
+
+
+
+
+
+
+
+