xref: /kvm-unit-tests/x86/efi/README.md (revision 1399f7f7f1c3170b2337c08beb615ae875636405)
1# Build kvm-unit-tests and run under UEFI
2
3## Introduction
4
5This dir provides code to build kvm-unit-tests test cases and run them under
6QEMU and UEFI.
7
8### Install dependencies
9
10The following dependencies should be installed:
11
12- [UEFI firmware](https://github.com/tianocore/edk2): to run test cases in QEMU
13
14### Build
15
16To build:
17
18    ./configure --enable-efi
19    make
20
21### Run test cases with UEFI
22
23To run a test case with UEFI:
24
25    ./x86/efi/run ./x86/msr.efi
26
27By default the runner script loads the UEFI firmware `/usr/share/ovmf/OVMF.fd`;
28please install UEFI firmware to this path, or specify the correct path through
29the env variable `EFI_UEFI`:
30
31    EFI_UEFI=/path/to/OVMF.fd ./x86/efi/run ./x86/msr.efi
32
33## Code structure
34
35### Code from GNU-EFI
36
37This dir contains source code and linker script copied from
38[GNU-EFI](https://sourceforge.net/projects/gnu-efi/):
39   - crt0-efi-x86_64.S: startup code of an EFI application
40   - elf_x86_64_efi.lds: linker script to build an EFI application
41   - reloc_x86_64.c: position independent x86_64 ELF shared object relocator
42
43EFI application binaries should be relocatable as UEFI loads binaries to dynamic
44runtime addresses. To build such relocatable binaries, GNU-EFI utilizes the
45above-mentioned files in its build process:
46
47   1. build an ELF shared object and link it using linker script
48      `elf_x86_64_efi.lds` to organize the sections in a way UEFI recognizes
49   2. link the shared object with self-relocator `reloc_x86_64.c` that applies
50      dynamic relocations that may be present in the shared object
51   3. link the entry point code `crt0-efi-x86_64.S` that invokes self-relocator
52      and then jumps to EFI application's `efi_main()` function
53   4. convert the shared object to an EFI binary
54
55More details can be found in `GNU-EFI/README.gnuefi`, section "Building
56Relocatable Binaries".
57
58kvm-unit-tests follows a similar build process, but does not link with GNU-EFI
59library.
60### Startup code for kvm-unit-tests in UEFI
61
62This dir also contains kvm-unit-tests startup code in UEFI:
63   - efistart64.S: startup code for kvm-unit-tests in UEFI
64