1# Generic Bootloader Library 2 3This directory hosts the Generic Bootloader Library project. A Bazel 4workspace is setup for building the library as well as an EFI executable that 5can be loaded directly from the firmware. 6 7## Build 8 9The GBL project are intended to be built from the 10[Android UEFI Manifest](https://android.googlesource.com/kernel/manifest/+/refs/heads/uefi-gbl-mainline/default.xml) 11checkout. 12 13To build the EFI application: 14 15``` 16./tools/bazel run //bootable/libbootloader:gbl_efi_dist --extra_toolchains=@gbl//toolchain:all 17``` 18The above builds the EFI application for all of `x86_64`, `x86_32`, `aarch64` 19and `riscv64` platforms. 20 21To run the set of unit tests: 22 23``` 24./tools/bazel test @gbl//tests --extra_toolchains=@gbl//toolchain:all 25``` 26 27## Run the EFI application 28 29### Boot Android on Cuttlefish 30 31If you have a main AOSP checkout and is setup to run 32[Cuttlefish](https://source.android.com/docs/setup/create/cuttlefish), you can 33run the EFI image directly with: 34 35``` 36launch_cvd --android_efi_loader=<path to the EFI image> ... 37``` 38 39The above uses the same setting as a normal `launch_cvd` run, except that 40insted of booting Android directly, the emulator first hands off to the EFI 41application, which will take over booting android. 42 43Note: For x86 platform, use the EFI image built for `x86_32`. 44 45### Boot Fuchsia on Vim3 46 47Booting Fuchsia on a Vim3 development board is supported. To run the 48application: 49 501. Complete all 51[bootstrap steps](https://fuchsia.dev/fuchsia-src/development/hardware/khadas-vim3?hl=en) 52to setup Vim3 as a Fuchsia device. 532. Reboot the device into fastboot mode. 543. Run fastboot command: 55``` 56fastboot stage <path to the EFI binary> && fastboot oem run-staged-efi 57``` 58 59### Run on standalone QEMU 60 61If you want to test the EFI image directly on QEMU with your custom 62configurations: 63 641. Install EDK, QEMU and u-boot prebuilts 65 66 ``` 67 sudo apt-get install qemu-system ovmf u-boot-qemu 68 ``` 69 701. Depending on the target achitecture you want to run: 71 72 For `x86_64`: 73 ``` 74 mkdir -p /tmp/esp/EFI/BOOT && \ 75 cp <path to EFI image> /tmp/esp/EFI/BOOT/bootx64.efi && \ 76 qemu-system-x86_64 -nographic \ 77 -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE.fd \ 78 -drive format=raw,file=fat:rw:/tmp/esp 79 ``` 80 81 For `aarch64`: 82 ``` 83 mkdir -p /tmp/esp/EFI/BOOT && \ 84 cp <path to EFI image> /tmp/esp/EFI/BOOT/bootaa64.efi && \ 85 qemu-system-aarch64 -nographic -machine virt -m 1G -cpu cortex-a57 \ 86 -drive if=pflash,format=raw,readonly=on,file=/usr/share/AAVMF/AAVMF_CODE.fd \ 87 -drive format=raw,file=fat:rw:/tmp/esp 88 ``` 89 90 For `riscv64`: 91 ``` 92 mkdir -p /tmp/esp/EFI/BOOT && \ 93 cp <path to EFI image> /tmp/esp/EFI/BOOT/bootriscv64.efi && \ 94 qemu-system-riscv64 -nographic -machine virt -m 256M \ 95 -bios /usr/lib/u-boot/qemu-riscv64/u-boot.bin \ 96 -drive format=raw,file=fat:rw:/tmp/esp,id=blk0 \ 97 -device virtio-blk-device,drive=blk0 98 ``` 99 100## EFI Protocols 101 102List of EFI protocols used by GBL and a brief description of each [here](./docs/efi_protocols.md). 103