1*91f16700SchasingluluQEMU virt Armv8-A 2*91f16700Schasinglulu================= 3*91f16700Schasinglulu 4*91f16700SchasingluluTrusted Firmware-A (TF-A) implements the EL3 firmware layer for QEMU virt 5*91f16700SchasingluluArmv8-A. BL1 is used as the BootROM, supplied with the -bios argument. 6*91f16700SchasingluluWhen QEMU starts all CPUs are released simultaneously, BL1 selects a 7*91f16700Schasingluluprimary CPU to handle the boot and the secondaries are placed in a polling 8*91f16700Schasinglululoop to be released by normal world via PSCI. 9*91f16700Schasinglulu 10*91f16700SchasingluluBL2 edits the Flattened Device Tree, FDT, generated by QEMU at run-time to 11*91f16700Schasingluluadd a node describing PSCI and also enable methods for the CPUs. 12*91f16700Schasinglulu 13*91f16700SchasingluluIf ``ARM_LINUX_KERNEL_AS_BL33`` is set to 1 then this FDT will be passed to BL33 14*91f16700Schasingluluvia register x0, as expected by a Linux kernel. This allows a Linux kernel image 15*91f16700Schasingluluto be booted directly as BL33 rather than using a bootloader. 16*91f16700Schasinglulu 17*91f16700SchasingluluAn ARM64 defconfig v5.5 Linux kernel is known to boot, FDT doesn't need to be 18*91f16700Schasingluluprovided as it's generated by QEMU. 19*91f16700Schasinglulu 20*91f16700SchasingluluCurrent limitations: 21*91f16700Schasinglulu 22*91f16700Schasinglulu- Only cold boot is supported 23*91f16700Schasinglulu 24*91f16700SchasingluluGetting non-TF images 25*91f16700Schasinglulu--------------------- 26*91f16700Schasinglulu 27*91f16700Schasinglulu``QEMU_EFI.fd`` can be downloaded from 28*91f16700Schasingluluhttp://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-KERNEL-AARCH64/RELEASE_GCC5/QEMU_EFI.fd 29*91f16700Schasinglulu 30*91f16700Schasingluluor, can be built as follows: 31*91f16700Schasinglulu 32*91f16700Schasinglulu.. code:: shell 33*91f16700Schasinglulu 34*91f16700Schasinglulu git clone https://github.com/tianocore/edk2.git 35*91f16700Schasinglulu cd edk2 36*91f16700Schasinglulu git submodule update --init 37*91f16700Schasinglulu make -C BaseTools 38*91f16700Schasinglulu source edksetup.sh 39*91f16700Schasinglulu export GCC5_AARCH64_PREFIX=aarch64-linux-gnu- 40*91f16700Schasinglulu build -a AARCH64 -t GCC5 -p ArmVirtPkg/ArmVirtQemuKernel.dsc 41*91f16700Schasinglulu 42*91f16700Schasinglulu```` 43*91f16700Schasinglulu 44*91f16700SchasingluluThen, you will get ``Build/ArmVirtQemuKernel-AARCH64/DEBUG_GCC5/FV/QEMU_EFI.fd`` 45*91f16700Schasinglulu 46*91f16700SchasingluluPlease note you do not need to use GCC 5 in spite of the environment variable 47*91f16700Schasinglulu``GCC5_AARCH64_PREFIX``. 48*91f16700Schasinglulu 49*91f16700SchasingluluThe rootfs can be built by using Buildroot as follows: 50*91f16700Schasinglulu 51*91f16700Schasinglulu.. code:: shell 52*91f16700Schasinglulu 53*91f16700Schasinglulu git clone git://git.buildroot.net/buildroot.git 54*91f16700Schasinglulu cd buildroot 55*91f16700Schasinglulu make qemu_aarch64_virt_defconfig 56*91f16700Schasinglulu utils/config -e BR2_TARGET_ROOTFS_CPIO 57*91f16700Schasinglulu utils/config -e BR2_TARGET_ROOTFS_CPIO_GZIP 58*91f16700Schasinglulu make olddefconfig 59*91f16700Schasinglulu make 60*91f16700Schasinglulu 61*91f16700SchasingluluThen, you will get ``output/images/rootfs.cpio.gz``. 62*91f16700Schasinglulu 63*91f16700SchasingluluBooting via semi-hosting option 64*91f16700Schasinglulu------------------------------- 65*91f16700Schasinglulu 66*91f16700SchasingluluBoot binaries, except BL1, are primarily loaded via semi-hosting so all 67*91f16700Schasinglulubinaries has to reside in the same directory as QEMU is started from. This 68*91f16700Schasingluluis conveniently achieved with symlinks the local names as: 69*91f16700Schasinglulu 70*91f16700Schasinglulu- ``bl2.bin`` -> BL2 71*91f16700Schasinglulu- ``bl31.bin`` -> BL31 72*91f16700Schasinglulu- ``bl33.bin`` -> BL33 (``QEMU_EFI.fd``) 73*91f16700Schasinglulu- ``Image`` -> linux/arch/arm64/boot/Image 74*91f16700Schasinglulu 75*91f16700SchasingluluTo build: 76*91f16700Schasinglulu 77*91f16700Schasinglulu.. code:: shell 78*91f16700Schasinglulu 79*91f16700Schasinglulu make CROSS_COMPILE=aarch64-none-elf- PLAT=qemu 80*91f16700Schasinglulu 81*91f16700SchasingluluTo start (QEMU v5.0.0): 82*91f16700Schasinglulu 83*91f16700Schasinglulu.. code:: shell 84*91f16700Schasinglulu 85*91f16700Schasinglulu qemu-system-aarch64 -nographic -machine virt,secure=on -cpu cortex-a57 \ 86*91f16700Schasinglulu -kernel Image \ 87*91f16700Schasinglulu -append "console=ttyAMA0,38400 keep_bootcon" \ 88*91f16700Schasinglulu -initrd rootfs.cpio.gz -smp 2 -m 1024 -bios bl1.bin \ 89*91f16700Schasinglulu -d unimp -semihosting-config enable,target=native 90*91f16700Schasinglulu 91*91f16700SchasingluluBooting via flash based firmware 92*91f16700Schasinglulu-------------------------------- 93*91f16700Schasinglulu 94*91f16700SchasingluluAn alternate approach to deploy a full system stack on QEMU is to load the 95*91f16700Schasinglulufirmware via a secure flash device. This involves concatenating ``bl1.bin`` and 96*91f16700Schasinglulu``fip.bin`` to create a boot ROM that is flashed onto secure FLASH0 with the 97*91f16700Schasinglulu``-bios`` option. 98*91f16700Schasinglulu 99*91f16700SchasingluluFor example, to test the following firmware stack: 100*91f16700Schasinglulu 101*91f16700Schasinglulu 102*91f16700Schasinglulu- BL32 - ``bl32.bin`` -> ``tee-header_v2.bin`` 103*91f16700Schasinglulu- BL32 Extra1 - ``bl32_extra1.bin`` -> ``tee-pager_v2.bin`` 104*91f16700Schasinglulu- BL32 Extra2 - ``bl32_extra2.bin`` -> ``tee-pageable_v2.bin`` 105*91f16700Schasinglulu- BL33 - ``bl33.bin`` -> ``QEMU_EFI.fd`` (EDK II) 106*91f16700Schasinglulu- ``Image`` -> linux/arch/arm64/boot/Image 107*91f16700Schasinglulu 108*91f16700Schasinglulu 109*91f16700Schasinglulu1. Compile TF-A 110*91f16700Schasinglulu 111*91f16700Schasinglulu .. code:: shell 112*91f16700Schasinglulu 113*91f16700Schasinglulu make CROSS_COMPILE=aarch64-linux-gnu- PLAT=qemu BL32=bl32.bin \ 114*91f16700Schasinglulu BL32_EXTRA1=bl32_extra1.bin BL32_EXTRA2=bl32_extra2.bin \ 115*91f16700Schasinglulu BL33=bl33.bin BL32_RAM_LOCATION=tdram SPD=opteed all fip 116*91f16700Schasinglulu 117*91f16700Schasinglulu Or, alternatively, to build with TBBR enabled, as well as, BL31 and BL32 encrypted with 118*91f16700Schasinglulu test key: 119*91f16700Schasinglulu 120*91f16700Schasinglulu .. code:: shell 121*91f16700Schasinglulu 122*91f16700Schasinglulu make CROSS_COMPILE=aarch64-linux-gnu- PLAT=qemu BL32=bl32.bin \ 123*91f16700Schasinglulu BL32_EXTRA1=bl32_extra1.bin BL32_EXTRA2=bl32_extra2.bin \ 124*91f16700Schasinglulu BL33=bl33.bin BL32_RAM_LOCATION=tdram SPD=opteed all fip \ 125*91f16700Schasinglulu MBEDTLS_DIR=<path-to-mbedtls-repo> TRUSTED_BOARD_BOOT=1 \ 126*91f16700Schasinglulu GENERATE_COT=1 DECRYPTION_SUPPORT=aes_gcm FW_ENC_STATUS=0 \ 127*91f16700Schasinglulu ENCRYPT_BL31=1 ENCRYPT_BL32=1 128*91f16700Schasinglulu 129*91f16700Schasinglulu2. Concatenate ``bl1.bin`` and ``fip.bin`` to create the boot ROM 130*91f16700Schasinglulu 131*91f16700Schasinglulu .. code:: shell 132*91f16700Schasinglulu 133*91f16700Schasinglulu dd if=build/qemu/release/bl1.bin of=flash.bin bs=4096 conv=notrunc 134*91f16700Schasinglulu dd if=build/qemu/release/fip.bin of=flash.bin seek=64 bs=4096 conv=notrunc 135*91f16700Schasinglulu 136*91f16700Schasinglulu3. Launch QEMU 137*91f16700Schasinglulu 138*91f16700Schasinglulu .. code:: shell 139*91f16700Schasinglulu 140*91f16700Schasinglulu qemu-system-aarch64 -nographic -machine virt,secure=on 141*91f16700Schasinglulu -cpu cortex-a57 -kernel Image \ 142*91f16700Schasinglulu -append 'console=ttyAMA0,38400 keep_bootcon' \ 143*91f16700Schasinglulu -initrd rootfs.cpio.gz -smp 2 -m 1024 -bios flash.bin \ 144*91f16700Schasinglulu -d unimp 145*91f16700Schasinglulu 146*91f16700SchasingluluThe ``-bios`` option abstracts the loading of raw bare metal binaries into flash 147*91f16700Schasingluluor ROM memory. QEMU loads the binary into the region corresponding to 148*91f16700Schasingluluthe hardware's entrypoint, from which the binary is executed upon a platform 149*91f16700Schasinglulu"reset". In addition to this, it places the information about the kernel 150*91f16700Schasingluluprovided with option ``-kernel``, and the RamDisk provided with ``-initrd``, 151*91f16700Schasingluluinto the firmware configuration ``fw_cfg``. In this setup, EDK II is responsible 152*91f16700Schasinglulufor extracting and launching these from ``fw_cfg``. 153*91f16700Schasinglulu 154*91f16700Schasinglulu.. note:: 155*91f16700Schasinglulu QEMU may be launched with or without ACPI (``-acpi``/``-no-acpi``). In 156*91f16700Schasinglulu either case, ensure that the kernel build options are aligned with the 157*91f16700Schasinglulu parameters passed to QEMU. 158*91f16700Schasinglulu 159*91f16700SchasingluluRunning QEMU in OpenCI 160*91f16700Schasinglulu----------------------- 161*91f16700Schasinglulu 162*91f16700SchasingluluLinaro's continuous integration platform OpenCI supports running emulated tests 163*91f16700Schasingluluon QEMU. The tests are kicked off on Jenkins and deployed through the Linaro 164*91f16700SchasingluluAutomation and Validation Architecture `LAVA`_. 165*91f16700Schasinglulu 166*91f16700SchasingluluThere are a set of Linux boot tests provided in OpenCI. They rely on prebuilt 167*91f16700Schasinglulu`binaries`_ for UEFI, the kernel, root file system, as well as, any other TF-A 168*91f16700Schasingluludependencies, and are run as part of the OpenCI TF-A `daily job`_. To run them 169*91f16700Schasinglulumanually, a `builder`_ job may be triggered with the test configuration 170*91f16700Schasinglulu``qemu-boot-tests``. 171*91f16700Schasinglulu 172*91f16700Schasinglulu 173*91f16700SchasingluluYou may see the following warning repeated several times in the boot logs: 174*91f16700Schasinglulu 175*91f16700Schasinglulu.. code:: shell 176*91f16700Schasinglulu 177*91f16700Schasinglulu pflash_write: Write to buffer emulation is flawed 178*91f16700Schasinglulu 179*91f16700SchasingluluPlease ignore this as it is an unresolved `issue in QEMU`_, it is an internal 180*91f16700SchasingluluQEMU warning that logs flawed use of "write to buffer". 181*91f16700Schasinglulu 182*91f16700Schasinglulu.. note:: 183*91f16700Schasinglulu For more information on how to trigger jobs in OpenCI, please refer to 184*91f16700Schasinglulu Linaro's CI documentation, which explains how to trigger a `manual job`_. 185*91f16700Schasinglulu 186*91f16700Schasinglulu.. _binaries: https://downloads.trustedfirmware.org/tf-a/linux_boot/ 187*91f16700Schasinglulu.. _daily job: https://ci.trustedfirmware.org/view/TF-A/job/tf-a-main/ 188*91f16700Schasinglulu.. _builder: https://ci.trustedfirmware.org/view/TF-A/job/tf-a-builder/ 189*91f16700Schasinglulu.. _LAVA: https://tf.validation.linaro.org/ 190*91f16700Schasinglulu.. _manual job: https://tf-ci-users-guide.readthedocs.io/en/latest/#manual-job-trigger 191*91f16700Schasinglulu.. _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