gpt4 book ai didi

uefi - 如何使用 gnu-efi 编译 uefi 应用程序?

转载 作者:行者123 更新时间:2023-12-03 22:45:06 26 4
gpt4 key购买 nike

我尝试使用 gnu-efi 编译 uefi 代码。但是我不明白如何编译我的 uefi 应用程序代码。

我得到 gnu-efi 3.0.2,解压并输入 make && make install。我写了 Hello World 代码:

#include <efi.h>
#include <efilib.h>

EFI_STATUS efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
InitializeLib(ImageHandle, SystemTable);
Print(L"Hello, world!\n");

return EFI_SUCCESS;
}

我的操作系统是 Ubuntu 15.04。

最佳答案

  1. 包含 gnu-efi 文件

    #include <efi.h> 
    #include <efilib.h>

    看起来你的包含被 SO 删除了

  2. 创建make文件;

If you were building a "Hello, World" program for Linux in a Linux environment, you could compile it without a Makefile. Building the program in Linux for EFI, though, is essentially a cross-compilation operation. As such, it necessitates using unusual compilation and linker options, as well as a post-linking operation to convert the program into a form that the EFI will accept. Although you could type all the relevant commands by hand, a Makefile helps a lot.

ARCH            = $(shell uname -m | sed s,i[3456789]86,ia32,)

OBJS = main.o
TARGET = hello.efi

EFIINC = /usr/include/efi
EFIINCS = -I$(EFIINC) -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 = $(EFIINCS) -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) $^ $@

引用:

http://www.rodsbooks.com/efi-programming/hello.html

关于uefi - 如何使用 gnu-efi 编译 uefi 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31514866/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com