Running Bare Metal Applications on QEMU

This page shows you how to run a simple baremetal application on QEMU.



Let's run your first bare metal application "Hello World"

We will build and run a simple example that runs directly on the A53 out of the OCM memory of the Zynq Ultrascale+™ MPSoC. Click here to check the source code for this example. This example simply prints the line "Hello World on Xilinx's QEMU for ZCU102" and then it quits. Below is a code snippet of this example:

/* Main loop. */
int main(int argc, char* argv[]){

    SetUpPsUart0();

    outString("Hello World on Xilinx's QEMU for ZCU102\n");

    return(0);
}

Compile the bare metal example

  1. Download and extract the AArch64 bare-metal (aarch64-none-elf) toolchain from here or use the PetaLinux installed toolchain.

  2. Go to Xilinx UG 1169 example page and clone the repository. Examples for building bare metal applications are located under BareMetal_examples folder. For this hello-application, we will use build_bare_metal_zcu102 example.
  3. Run below commands on your terminal:

    cd build_bare_metal_zcu102
    
    # If you extraced the compiler to a folder.
    make PATH=<path to extracted folder>/bin
    
    #If you installed aarch64-none-elf-gcc. Installation path can be found using which aarch64-none-elf-gcc.
    make PATH=<installation path>

    If you have installed Xilinx Petalinux, Yocto and Vitis tools, this compiler can be found at: <install directory>/gnu/aarch64/lin/aarch64/bin/aarch64-none-elf-gcc.

Run it on QEMU

We will use DTBs created in building dtbs section.

qemu-system-aarch64 -nographic -M arm-generic-fdt \
    -dtb /PATH_TO_DTB_REPOSITORY/LATEST/SINGLE_ARCH/zcu102-arm.dtb \
    -device loader,file=./hello_world,cpu-num=0 \
    -device loader,addr=0xfd1a0104,data=0x8000000e,data-len=4

Running Bare Metal Applications

Below are a few more examples for running a bare metal application on different CPUs.

For more information on what the commands do, see the QEMU options section.

Running a bare metal application on Versal Adaptive SoC A72

qemu-system-aarch64 \
-M arm-generic-fdt \
-serial null -serial null -serial mon:stdio \
-device loader,file=<baremetal_for_versal_a72.elf>,cpu-num=0 \
-device loader,addr=0xFD1A0300,data=0x8000000e,data-len=4 \
-hw-dtb <device tree binary for Versal> \
-m <DDR memory size> \
-display none

To quit the emulation, press CTRL+A followed by X. To switch between the serial port and the monitor, use CTRL+A followed by C.

Running a bare-metal application on Versal Adaptive SoC R5

qemu-system-aarch64 \
-M arm-generic-fdt \
-serial null -serial null -serial mon:stdio \
-device loader,file=<baremetal_for_versal_r5.elf>,cpu-num=2 \
-device loader,addr=0xff5e0300,data=0x16,data-len=4 \
-device loader,addr=0xff9a0100,data=0x1,data-len=4 \
-device loader,addr=0xff9a0000,data=0x48,data-len=4 \
-hw-dtb <device tree binary for Versal> \
-m <DDR memory size> \
-display none

Running a bare-metal application on Zynq Ultrascale+ MPSoC A53

qemu-system-aarch64 \
-M arm-generic-fdt \
-serial mon:stdio \
-device loader,file=<baremetal_for_zynqmp_a53.elf>,cpu-num=0 \
-device loader,addr=0xfd1a0104,data=0x8000000e,data-len=4 \
-hw-dtb <device tree binary for ZynqMP> \
-m <DDR memory size> \
-display none

Running a bare-metal application on Zynq Ultrascale+ MPSoC r5

qemu-system-aarch64 \
-M arm-generic-fdt \
-serial mon:stdio \
-device loader,file=<baremetal_for_zynqmp_r5.elf>,cpu-num=4 \
-device loader,addr=0XFF5E023C,data=0x80088fde,data-len=4 \
-device loader,addr=0xff9a0000,data=0x80000218,data-len=4 \
-hw-dtb <device tree binary for Versal> \
-m <DDR memory size> \
-display none

Running a bare-metal application on Zynq7000

Zynq7000 DTBs are not included in the QEMU DTB repository, but can be found in a Zynq7000 PetaLinux project.

qemu-system-aarch64 \
-M arm-generic-fdt-7series \
-machine linux=on \
-serial /dev/null -serial mon:stdio \
-display none \
-kernel <guest image path> \
-dtb <Zynq7000 DTB path> \
-m <DDR memory size> \
-device loader,addr=0xf8000008,data=0xDF0D,data-len=4 \
-device loader,addr=0xf8000140,data=0x00500801,data-len=4 \
-device loader,addr=0xf800012c,data=0x1ed044d,data-len=4 \
-device loader,addr=0xf8000108,data=0x0001e008,data-len=4 \
-device loader,addr=0xf8000910,data=0x0000000F,data-len=4

Running a bare-metal application on MicroBlaze

MicroBlaze DTBs are not included in the QEMU DTB repository, but can be found in a MicroBlaze PetaLinux project.

qemu-system-microblazeel \
-M microblaze-fdt-plnx \
-m <ram_size> \
-serial mon:stdio \
-display none \
-kernel <guest image path> \
-m <DDR memory size> \
-dtb <MicroBlaze DTB path>


© Copyright 2019 - 2022 Xilinx Inc. Privacy Policy