请告诉我如何 运行 我在 QEMU 上的 UEFI 应用程序

Please tell me how to run my UEFI application on QEMU

我的环境是Ubuntu15.10。 我写了下面的源码。

#include "efi.h"
#include "efilib.h"

EFI_STATUS
EFIAPI
efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
    InitializeLib(ImageHandle, SystemTable);
    Print(L"HelloWorld\n");

    return EFI_SUCCESS;
}

我写了下面的Makefile并编译了源码

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
EFILIB  = /usr/lib
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) $^ $@

我将 hello.efi 存储在指定的 RT 目录中,并且我 运行 "qemu-system-x86_64 -bios OVMF.fd -hda fat:RT/"。 我 运行 hello.efi 但没有执行我的 UEFI 应用程序。 Qemu 说 "Error reported: Invalud Parameter".

请帮帮我!

你不需要 'main()' 还是 'efi_main()'?

Makefile 中的 LDFLAGS 中删除 -L $(LIB) 帮助: