From 7a37ec94fbdf6a4a058f4094b9326387786e19b3 Mon Sep 17 00:00:00 2001 From: Regia König Date: Tue, 16 Aug 2022 12:03:17 +0200 Subject: Start new project: Create a HelloWorld.efi with GNU-efi --- GNU_efi_HelloWorld/Makefile | 31 +++++++++++++++++++++++++++++++ GNU_efi_HelloWorld/hello.c | 11 +++++++++++ GNU_efi_HelloWorld/hello.o | Bin 0 -> 1696 bytes 3 files changed, 42 insertions(+) create mode 100644 GNU_efi_HelloWorld/Makefile create mode 100644 GNU_efi_HelloWorld/hello.c create mode 100644 GNU_efi_HelloWorld/hello.o diff --git a/GNU_efi_HelloWorld/Makefile b/GNU_efi_HelloWorld/Makefile new file mode 100644 index 0000000..4f00d4a --- /dev/null +++ b/GNU_efi_HelloWorld/Makefile @@ -0,0 +1,31 @@ +ARCH = $(shell uname -m | sed s,i[3456789]86,ia32,) + +OBJS = main.o +TARGET = hello.efi + +EFIINC = /usr/include/efi +EFFINCS = -I$(EFFINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol +LIB = /usr/lib64 +EFILIB = /usr/lib64/gnuefi +EFI_CRT_OBJS = $(EFILIB)/crt0-efi-$(ARCH).o +EFI_LDS = $(EFILIB)/elf_$(ARCH)_efi.lds + +CFLAGS = $(EFFINCS) -fno-stack-protector -fpic \ + -fshort-wchar -mno-red-zone -Wall + +ifeq ($(ARCH),x86_64) + CFLAGS += -DEFI_FUNCTION_WRAPPER +endif + +LDFLAGS = -nostdlib -znocombreloc -T $(EFI_LDS) -shared \ + -Bsymbolic -L $(EFILIB) -L $(LIB) $(EFI_CRT_OBJS) + +all: $(TARGET) + +hello.so: $(OBJS) + ld $(LDFLAGS) $(OBJS) -o $@ -lefi -lgnuefi + +%.efi: %.so + objcopy -j .text -j .sdata -j .data -j .dynamic \ + -j .dynsym -j .rel -j .rela -j .reloc \ + --target=efi-app-$(ARCH) $^ $@ diff --git a/GNU_efi_HelloWorld/hello.c b/GNU_efi_HelloWorld/hello.c new file mode 100644 index 0000000..26cbd42 --- /dev/null +++ b/GNU_efi_HelloWorld/hello.c @@ -0,0 +1,11 @@ +#include +#include + +EFI_STATUS +EFIAPI +efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { + InitializeLib(ImageHandle, SystemTable); + Print(L"Hello, world!\n"); + + return EFI_SUCCESS; +} diff --git a/GNU_efi_HelloWorld/hello.o b/GNU_efi_HelloWorld/hello.o new file mode 100644 index 0000000..6e14a71 Binary files /dev/null and b/GNU_efi_HelloWorld/hello.o differ -- cgit v1.2.3-55-g7522