Qemu emulation

Run arm32 UEFI in a virtual machine.

Emulating a arm32 UEFI device is useful for developing Linux and debugging it.

In the GDB Debugging page you can find instructions on how to compile Linux for this virtual machine.

A premade ZIP with all required files can be found at the bottom.

Compile OVMF for qemu

Install required packages

Run the following commands to install the required packages.

sudo apt install python python3 python3-distutils
sudo apt install gcc-arm-none-eabi
sudo apt install uuid-dev
sudo apt install build-essential
sudo apt install bison
sudo apt install flex

You will need other stuff too, but that is probably already installed. (e.g. git)

Download source

You need the source code of edk2 and acpica.

# Go to the directory you want to work in
export WORKSPACE=$PWD

# Download edk2 and acpica
git clone https://github.com/acpica/acpica.git
git clone https://github.com/tianocore/edk2.git

# Download submodules
cd edk2
git submodule update --init
cd ..

Compile OVMF

Go to your source directory and run the following commands.

# Compile acpica tools
make -C $WORKSPACE/acpica -j$(nproc)

# Set environment variables
export GCC5_ARM_PREFIX=arm-none-eabi-
export IASL_PREFIX=$WORKSPACE/acpica/generate/unix/bin/
export PYTHON_COMMAND=/usr/bin/python3

# Configure the edk2 environment
source edk2/edksetup.sh

# Compile edk2 BaseTools
make -C edk2/BaseTools -j$(nproc)

# Compile OVMF
build -a ARM -t GCC5 -p ArmVirtPkg/ArmVirtQemu.dsc -b RELEASE -j$(nproc)

Your output OVMF firmware file for qemu is$WORKSPACE/Build/ArmVirtQemu-ARM/RELEASEGCC5/FV/QEMU_EFI.fd

Setup qemu files and run it

Create a directory, where you want your files to be in. Put your QEMU_EFI.fd firmware file in this directory, compiled in the previous section. Now run the following commands to create some disk images:

rm -f flash0.img flash1.img
dd if=/dev/zero bs=1M count=64 of=flash0.img
dd if=/dev/zero bs=1M count=64 of=flash1.img
dd if=QEMU_EFI.fd bs=1M of=flash0.img conv=notrunc

Now create a directory named boot. This will be your EFI partition. You can now easily place your EFI files in there.

Run qemu

To start your virtual machine run the following command, and make sure qemu-system-arm is installed.

qemu-system-arm \ 
    -m 1024 \
    -cpu cortex-a15 \
    -M virt \
    -pflash flash0.img \
    -pflash flash1.img \
    -nographic \
    -drive \
    file=fat:rw:boot/ \
    -smp '4'

This will run qemu with 4 virtual CPU cores. They are Coretx-A15 cores. Used because it works.

Premade files

The following ZIP includes all files setup in their proper location. In addition its EFI partition folder has a UEFI shell in it. To run it either execute the run.sh file or enter the command described in Run qemu.

References

Links where the above compiling information is from:

Last updated