Search code examples
qemuuefi

Please tell me how to run my UEFI application on QEMU


My environment is Ubuntu15.10. I wrote the following source code.

#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;
}

I wrote the following Makefile and compile source code.

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) $^ $@

I store hello.efi on named RT directory and I run "qemu-system-x86_64 -bios OVMF.fd -hda fat:RT/". I run hello.efi but not execute my UEFI application. Qemu say "Error reported: Invalud Parameter".

Please help me!


Solution

  • Removing -L $(LIB) from the LDFLAGS in the Makefile helped: