qemu.rst 6.8 KB

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