如何使用gnu-efi编译uefi应用程序? [英] How to compile uefi application using gnu-efi?
问题描述
我尝试使用gnu-efi
编译uefi代码.但是我不明白如何编译我的uefi应用程序代码.
I tried to compile uefi code using gnu-efi
. But I don't understand how to compile my uefi application code.
我得到gnu-efi
3.0.2,解压缩并键入make && make install
.我写你好世界代码:
I get gnu-efi
3.0.2, decompress and type make && make install
. I write hello world code:
#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.
My OS is Ubuntu 15.04.
推荐答案
-
包括gnu-efi文件
Include the gnu-efi files
#include <efi.h>
#include <efilib.h>
似乎您的包含文件已被SO删除
it looks like your includes where removed by SO
创建make文件;
如果要在Linux中为Linux构建"Hello,World"程序 环境,您可以在没有Makefile的情况下进行编译.建立 但是,Linux中的EFI程序本质上是交叉编译 手术.因此,有必要使用不寻常的编译和 链接器选项,以及用于转换 编程为EFI可以接受的形式.虽然您可以输入 手动执行所有相关命令,Makefile会很有帮助.
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
这篇关于如何使用gnu-efi编译uefi应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!