It is quite complicating to run U-Boot on qemu since we have four different builds and they must use different versions of qemu and the UEFI binaries.
Add a script to help. Signed-off-by: Simon Glass <s...@chromium.org> --- doc/develop/uefi/u-boot_on_efi.rst | 4 ++ scripts/build-efi.sh | 111 +++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100755 scripts/build-efi.sh diff --git a/doc/develop/uefi/u-boot_on_efi.rst b/doc/develop/uefi/u-boot_on_efi.rst index c9a41bc919f..59ee3885295 100644 --- a/doc/develop/uefi/u-boot_on_efi.rst +++ b/doc/develop/uefi/u-boot_on_efi.rst @@ -96,6 +96,10 @@ that EFI does not support booting a 64-bit application from a 32-bit EFI (or vice versa). Also it will often fail to print an error message if you get this wrong. +You may find the script `scripts/build-efi.sh` helpful for building and testing +U-Boot on UEFI on QEMU. It also includes links to UEFI binaries dating from +2021. + Inner workings -------------- diff --git a/scripts/build-efi.sh b/scripts/build-efi.sh new file mode 100755 index 00000000000..8770c1fb311 --- /dev/null +++ b/scripts/build-efi.sh @@ -0,0 +1,111 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0+ +# +# Script to build an EFI thing suitable for booting with qemu, possibly running +# it also. + +# This just an example. It assumes that + +# - you build U-Boot in /tmp/b/<name> where <name> is the U-Boot board config +# - /mnt/x is a directory used for mounting +# - you have access to the 'pure UEFI' builds for qemu +# +# UEFI binaries for QEMU used for testing this script: +# +# OVMF-pure-efi.i386.fd at +# https://drive.google.com/file/d/1jWzOAZfQqMmS2_dAK2G518GhIgj9r2RY/view?usp=sharing + +# OVMF-pure-efi.x64.fd at +# https://drive.google.com/file/d/1c39YI9QtpByGQ4V0UNNQtGqttEzS-eFV/view?usp=sharing + +set -e + +usage() { + echo "Usage: $0 [-a | -p]" 1>&2 + echo 1>&2 + echo " -a - Package up the app" 1>&2 + echo " -o - Use old EFI app build (before 32/64 split)" 1>&2 + echo " -p - Package up the payload" 1>&2 + echo " -r - Run qemu with the image" 1>&2 + echo " -w - Use word version (32-bit)" 1>&2 + exit 1 +} + +# 32- or 64-bit EFI +bitness=64 + +# app or payload ? +type=app + +# run the image with qemu +run= + +# before the 32/64 split of the app +old= + +while getopts "aoprw" opt; do + case "${opt}" in + a) + type=app + ;; + p) + type=payload + ;; + r) + run=1 + ;; + w) + bitness=32 + ;; + o) + old=1 + ;; + *) + usage + ;; + esac +done + +run_qemu() { + if [[ "${bitness}" = "64" ]]; then + qemu=qemu-system-x86_64 + bios=OVMF-pure-efi.x64.fd + else + qemu=qemu-system-i386 + bios=OVMF-pure-efi.i386.fd + fi + echo "Running ${qemu}" + "${qemu}" -bios "${bios}" \ + -drive id=disk,file=try.img,if=none,format=raw \ + -nic none -device ahci,id=ahci \ + -device ide-hd,drive=disk,bus=ahci.0 +} + +TMP="/tmp/efi${bitness}${type}" +MNT=/mnt/x +BUILD="efi-x86_${type}${bitness}" + +if [[ -n "${old}" && "${bitness}" = "32" ]]; then + BUILD="efi-x86_${type}" +fi + +echo "Packaging ${BUILD}" +qemu-img create try.img 24M >/dev/null +mkfs.vfat try.img >/dev/null +mkdir -p $TMP +cat >$TMP/startup.nsh <<EOF +fs0:u-boot-${type}.efi +EOF +sudo cp /tmp/b/$BUILD/u-boot-${type}.efi $TMP + +# Can copy in other files here: +#sudo cp /tmp/b/$BUILD/image.bin $TMP/chromeos.rom +#sudo cp /boot/vmlinuz-5.4.0-77-generic $TMP/vmlinuz + +sudo mount -o loop try.img $MNT +sudo cp $TMP/* $MNT +sudo umount $MNT + +if [[ -n "${run}" ]]; then + run_qemu +fi -- 2.33.0.153.gba50c8fa24-goog