2015-07-20 166 views
1

我試圖用gnu-efi來編譯uefi代碼。但我不明白如何編譯我的uefi應用程序代碼。如何使用gnu-efi編譯uefi應用程序?

我得到gnu-efi 3.0.2,解壓縮並輸入make && make install。我寫你好世界代碼:

#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。

回答

3
  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 [email protected] -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) $^ [email protected] 

參考:

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

+0

我編譯成功!謝謝! –

+0

@ Thecoffee17thcup你可以讓我知道我如何在Ubuntu中構建它?我一直有「致命的錯誤:efi.h:沒有這樣的文件或目錄」 – Sam

+0

這是一個容易的。您的編譯器無法看到'efi.h',請檢查您的'make'文件; 'EFIINC =/usr/include/efi'應該指向所需的gnu-efi頭文件。 – Pat

相關問題