124dba2b3SPaul BeesleyQEMU virt Armv8-A 224dba2b3SPaul Beesley================= 36f625747SDouglas Raillard 44def07d5SDan HandleyTrusted Firmware-A (TF-A) implements the EL3 firmware layer for QEMU virt 54def07d5SDan HandleyArmv8-A. BL1 is used as the BootROM, supplied with the -bios argument. 66f625747SDouglas RaillardWhen QEMU starts all CPUs are released simultaneously, BL1 selects a 76f625747SDouglas Raillardprimary CPU to handle the boot and the secondaries are placed in a polling 86f625747SDouglas Raillardloop to be released by normal world via PSCI. 96f625747SDouglas Raillard 106f625747SDouglas RaillardBL2 edits the Flattened Device Tree, FDT, generated by QEMU at run-time to 116f625747SDouglas Raillardadd a node describing PSCI and also enable methods for the CPUs. 126f625747SDouglas Raillard 1374464d5bSAndrew WalbranIf ``ARM_LINUX_KERNEL_AS_BL33`` is set to 1 then this FDT will be passed to BL33 1474464d5bSAndrew Walbranvia register x0, as expected by a Linux kernel. This allows a Linux kernel image 1574464d5bSAndrew Walbranto be booted directly as BL33 rather than using a bootloader. 1674464d5bSAndrew Walbran 1762038be7SMasahiro YamadaAn ARM64 defconfig v5.5 Linux kernel is known to boot, FDT doesn't need to be 186f625747SDouglas Raillardprovided as it's generated by QEMU. 196f625747SDouglas Raillard 206f625747SDouglas RaillardCurrent limitations: 216f625747SDouglas Raillard 226f625747SDouglas Raillard- Only cold boot is supported 236f625747SDouglas Raillard 24a66f0309SMasahiro YamadaGetting non-TF images 25a66f0309SMasahiro Yamada--------------------- 26a66f0309SMasahiro Yamada 27a66f0309SMasahiro Yamada``QEMU_EFI.fd`` can be downloaded from 2862038be7SMasahiro Yamadahttp://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-KERNEL-AARCH64/RELEASE_GCC5/QEMU_EFI.fd 296f625747SDouglas Raillard 30a66f0309SMasahiro Yamadaor, can be built as follows: 31a66f0309SMasahiro Yamada 32a66f0309SMasahiro Yamada.. code:: shell 33a66f0309SMasahiro Yamada 34a66f0309SMasahiro Yamada git clone https://github.com/tianocore/edk2.git 35a66f0309SMasahiro Yamada cd edk2 36a66f0309SMasahiro Yamada git submodule update --init 37a66f0309SMasahiro Yamada make -C BaseTools 38a66f0309SMasahiro Yamada source edksetup.sh 39a66f0309SMasahiro Yamada export GCC5_AARCH64_PREFIX=aarch64-linux-gnu- 40a66f0309SMasahiro Yamada build -a AARCH64 -t GCC5 -p ArmVirtPkg/ArmVirtQemuKernel.dsc 41a66f0309SMasahiro Yamada 42a66f0309SMasahiro Yamada```` 43a66f0309SMasahiro Yamada 44a66f0309SMasahiro YamadaThen, you will get ``Build/ArmVirtQemuKernel-AARCH64/DEBUG_GCC5/FV/QEMU_EFI.fd`` 45a66f0309SMasahiro Yamada 46a66f0309SMasahiro YamadaPlease note you do not need to use GCC 5 in spite of the environment variable 47*d9bd35e3SHarrison Mutai``GCC5_AARCH64_PREFIX``. 48a66f0309SMasahiro Yamada 49a66f0309SMasahiro YamadaThe rootfs can be built by using Buildroot as follows: 50a66f0309SMasahiro Yamada 51a66f0309SMasahiro Yamada.. code:: shell 52a66f0309SMasahiro Yamada 53a66f0309SMasahiro Yamada git clone git://git.buildroot.net/buildroot.git 54a66f0309SMasahiro Yamada cd buildroot 55a66f0309SMasahiro Yamada make qemu_aarch64_virt_defconfig 56a66f0309SMasahiro Yamada utils/config -e BR2_TARGET_ROOTFS_CPIO 57a66f0309SMasahiro Yamada utils/config -e BR2_TARGET_ROOTFS_CPIO_GZIP 58a66f0309SMasahiro Yamada make olddefconfig 59a66f0309SMasahiro Yamada make 60a66f0309SMasahiro Yamada 61a66f0309SMasahiro YamadaThen, you will get ``output/images/rootfs.cpio.gz``. 62a66f0309SMasahiro Yamada 634ebbea95SSumit GargBooting via semi-hosting option 644ebbea95SSumit Garg------------------------------- 654ebbea95SSumit Garg 666f625747SDouglas RaillardBoot binaries, except BL1, are primarily loaded via semi-hosting so all 676f625747SDouglas Raillardbinaries has to reside in the same directory as QEMU is started from. This 686f625747SDouglas Raillardis conveniently achieved with symlinks the local names as: 696f625747SDouglas Raillard 706f625747SDouglas Raillard- ``bl2.bin`` -> BL2 716f625747SDouglas Raillard- ``bl31.bin`` -> BL31 726f625747SDouglas Raillard- ``bl33.bin`` -> BL33 (``QEMU_EFI.fd``) 7362038be7SMasahiro Yamada- ``Image`` -> linux/arch/arm64/boot/Image 746f625747SDouglas Raillard 756f625747SDouglas RaillardTo build: 766f625747SDouglas Raillard 7729c02529SPaul Beesley.. code:: shell 786f625747SDouglas Raillard 796f625747SDouglas Raillard make CROSS_COMPILE=aarch64-none-elf- PLAT=qemu 806f625747SDouglas Raillard 81231d0b35SMasahiro YamadaTo start (QEMU v5.0.0): 826f625747SDouglas Raillard 8329c02529SPaul Beesley.. code:: shell 846f625747SDouglas Raillard 856f625747SDouglas Raillard qemu-system-aarch64 -nographic -machine virt,secure=on -cpu cortex-a57 \ 866f625747SDouglas Raillard -kernel Image \ 87624120e0SMasahiro Yamada -append "console=ttyAMA0,38400 keep_bootcon" \ 88a66f0309SMasahiro Yamada -initrd rootfs.cpio.gz -smp 2 -m 1024 -bios bl1.bin \ 896f625747SDouglas Raillard -d unimp -semihosting-config enable,target=native 904ebbea95SSumit Garg 91*d9bd35e3SHarrison MutaiBooting via flash based firmware 92*d9bd35e3SHarrison Mutai-------------------------------- 934ebbea95SSumit Garg 94*d9bd35e3SHarrison MutaiAn alternate approach to deploy a full system stack on QEMU is to load the 95*d9bd35e3SHarrison Mutaifirmware via a secure flash device. This involves concatenating ``bl1.bin`` and 96*d9bd35e3SHarrison Mutai``fip.bin`` to create a boot ROM that is flashed onto secure FLASH0 with the 97*d9bd35e3SHarrison Mutai``-bios`` option. 984ebbea95SSumit Garg 99*d9bd35e3SHarrison MutaiFor example, to test the following firmware stack: 100*d9bd35e3SHarrison Mutai 101*d9bd35e3SHarrison Mutai 102*d9bd35e3SHarrison Mutai- BL32 - ``bl32.bin`` -> ``tee-header_v2.bin`` 103*d9bd35e3SHarrison Mutai- BL32 Extra1 - ``bl32_extra1.bin`` -> ``tee-pager_v2.bin`` 104*d9bd35e3SHarrison Mutai- BL32 Extra2 - ``bl32_extra2.bin`` -> ``tee-pageable_v2.bin`` 105*d9bd35e3SHarrison Mutai- BL33 - ``bl33.bin`` -> ``QEMU_EFI.fd`` (EDK II) 1064ebbea95SSumit Garg- ``Image`` -> linux/arch/arm64/boot/Image 1074ebbea95SSumit Garg 108*d9bd35e3SHarrison Mutai 109*d9bd35e3SHarrison Mutai1. Compile TF-A 1104ebbea95SSumit Garg 1114ebbea95SSumit Garg .. code:: shell 1124ebbea95SSumit Garg 1134ebbea95SSumit Garg make CROSS_COMPILE=aarch64-linux-gnu- PLAT=qemu BL32=bl32.bin \ 1144ebbea95SSumit Garg BL32_EXTRA1=bl32_extra1.bin BL32_EXTRA2=bl32_extra2.bin \ 1154ebbea95SSumit Garg BL33=bl33.bin BL32_RAM_LOCATION=tdram SPD=opteed all fip 1164ebbea95SSumit Garg 117*d9bd35e3SHarrison Mutai Or, alternatively, to build with TBBR enabled, as well as, BL31 and BL32 encrypted with 118*d9bd35e3SHarrison Mutai test key: 1194ebbea95SSumit Garg 1204ebbea95SSumit Garg .. code:: shell 1214ebbea95SSumit Garg 1224ebbea95SSumit Garg make CROSS_COMPILE=aarch64-linux-gnu- PLAT=qemu BL32=bl32.bin \ 1234ebbea95SSumit Garg BL32_EXTRA1=bl32_extra1.bin BL32_EXTRA2=bl32_extra2.bin \ 1244ebbea95SSumit Garg BL33=bl33.bin BL32_RAM_LOCATION=tdram SPD=opteed all fip \ 1254ebbea95SSumit Garg MBEDTLS_DIR=<path-to-mbedtls-repo> TRUSTED_BOARD_BOOT=1 \ 1264ebbea95SSumit Garg GENERATE_COT=1 DECRYPTION_SUPPORT=aes_gcm FW_ENC_STATUS=0 \ 1274ebbea95SSumit Garg ENCRYPT_BL31=1 ENCRYPT_BL32=1 1284ebbea95SSumit Garg 129*d9bd35e3SHarrison Mutai2. Concatenate ``bl1.bin`` and ``fip.bin`` to create the boot ROM 1304ebbea95SSumit Garg 1314ebbea95SSumit Garg .. code:: shell 1324ebbea95SSumit Garg 1334ebbea95SSumit Garg dd if=build/qemu/release/bl1.bin of=flash.bin bs=4096 conv=notrunc 1344ebbea95SSumit Garg dd if=build/qemu/release/fip.bin of=flash.bin seek=64 bs=4096 conv=notrunc 1354ebbea95SSumit Garg 136*d9bd35e3SHarrison Mutai3. Launch QEMU 1374ebbea95SSumit Garg 1384ebbea95SSumit Garg .. code:: shell 1394ebbea95SSumit Garg 140*d9bd35e3SHarrison Mutai qemu-system-aarch64 -nographic -machine virt,secure=on 141*d9bd35e3SHarrison Mutai -cpu cortex-a57 -kernel Image \ 142624120e0SMasahiro Yamada -append 'console=ttyAMA0,38400 keep_bootcon' \ 143a66f0309SMasahiro Yamada -initrd rootfs.cpio.gz -smp 2 -m 1024 -bios flash.bin \ 1444ebbea95SSumit Garg -d unimp 145a5667be0SHarrison Mutai 146*d9bd35e3SHarrison MutaiThe ``-bios`` option abstracts the loading of raw bare metal binaries into flash 147*d9bd35e3SHarrison Mutaior ROM memory. QEMU loads the binary into the region corresponding to 148*d9bd35e3SHarrison Mutaithe hardware's entrypoint, from which the binary is executed upon a platform 149*d9bd35e3SHarrison Mutai"reset". In addition to this, it places the information about the kernel 150*d9bd35e3SHarrison Mutaiprovided with option ``-kernel``, and the RamDisk provided with ``-initrd``, 151*d9bd35e3SHarrison Mutaiinto the firmware configuration ``fw_cfg``. In this setup, EDK II is responsible 152*d9bd35e3SHarrison Mutaifor extracting and launching these from ``fw_cfg``. 153*d9bd35e3SHarrison Mutai 154*d9bd35e3SHarrison Mutai.. note:: 155*d9bd35e3SHarrison Mutai QEMU may be launched with or without ACPI (``-acpi``/``-no-acpi``). In 156*d9bd35e3SHarrison Mutai either case, ensure that the kernel build options are aligned with the 157*d9bd35e3SHarrison Mutai parameters passed to QEMU. 158*d9bd35e3SHarrison Mutai 159a5667be0SHarrison MutaiRunning QEMU in OpenCI 160a5667be0SHarrison Mutai----------------------- 161a5667be0SHarrison Mutai 162a5667be0SHarrison MutaiLinaro's continuous integration platform OpenCI supports running emulated tests 163a5667be0SHarrison Mutaion QEMU. The tests are kicked off on Jenkins and deployed through the Linaro 164a5667be0SHarrison MutaiAutomation and Validation Architecture `LAVA`_. 165a5667be0SHarrison Mutai 166a5667be0SHarrison MutaiThere are a set of Linux boot tests provided in OpenCI. They rely on prebuilt 167a5667be0SHarrison Mutai`binaries`_ for UEFI, the kernel, root file system, as well as, any other TF-A 168a5667be0SHarrison Mutaidependencies, and are run as part of the OpenCI TF-A `daily job`_. To run them 169a5667be0SHarrison Mutaimanually, a `builder`_ job may be triggered with the test configuration 170a5667be0SHarrison Mutai``qemu-boot-tests``. 171a5667be0SHarrison Mutai 172a5667be0SHarrison Mutai 173a5667be0SHarrison MutaiYou may see the following warning repeated several times in the boot logs: 174a5667be0SHarrison Mutai 175a5667be0SHarrison Mutai.. code:: shell 176a5667be0SHarrison Mutai 177a5667be0SHarrison Mutai pflash_write: Write to buffer emulation is flawed 178a5667be0SHarrison Mutai 179a5667be0SHarrison MutaiPlease ignore this as it is an unresolved `issue in QEMU`_, it is an internal 180a5667be0SHarrison MutaiQEMU warning that logs flawed use of "write to buffer". 181a5667be0SHarrison Mutai 182a5667be0SHarrison Mutai.. note:: 183a5667be0SHarrison Mutai For more information on how to trigger jobs in OpenCI, please refer to 184a5667be0SHarrison Mutai Linaro's CI documentation, which explains how to trigger a `manual job`_. 185a5667be0SHarrison Mutai 186a5667be0SHarrison Mutai.. _binaries: https://downloads.trustedfirmware.org/tf-a/linux_boot/ 187a5667be0SHarrison Mutai.. _daily job: https://ci.trustedfirmware.org/view/TF-A/job/tf-a-main/ 188a5667be0SHarrison Mutai.. _builder: https://ci.trustedfirmware.org/view/TF-A/job/tf-a-builder/ 189a5667be0SHarrison Mutai.. _LAVA: https://tf.validation.linaro.org/ 190a5667be0SHarrison Mutai.. _manual job: https://tf-ci-users-guide.readthedocs.io/en/latest/#manual-job-trigger 191a5667be0SHarrison Mutai.. _issue in QEMU: https://git.qemu.org/?p=qemu.git;a=blob;f=hw/block/pflash_cfi01.c;h=0cbc2fb4cbf62c9a033b8dd89012374ff74ed610;hb=refs/heads/master#l500 192