xref: /rk3399_ARM-atf/docs/plat/qemu.rst (revision a66f0309e5ac56c8223414542874a657768eec03)
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
24*a66f0309SMasahiro YamadaGetting non-TF images
25*a66f0309SMasahiro Yamada---------------------
26*a66f0309SMasahiro Yamada
27*a66f0309SMasahiro 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
30*a66f0309SMasahiro Yamadaor, can be built as follows:
31*a66f0309SMasahiro Yamada
32*a66f0309SMasahiro Yamada.. code:: shell
33*a66f0309SMasahiro Yamada
34*a66f0309SMasahiro Yamada    git clone https://github.com/tianocore/edk2.git
35*a66f0309SMasahiro Yamada    cd edk2
36*a66f0309SMasahiro Yamada    git submodule update --init
37*a66f0309SMasahiro Yamada    make -C BaseTools
38*a66f0309SMasahiro Yamada    source edksetup.sh
39*a66f0309SMasahiro Yamada    export GCC5_AARCH64_PREFIX=aarch64-linux-gnu-
40*a66f0309SMasahiro Yamada    build -a AARCH64 -t GCC5 -p ArmVirtPkg/ArmVirtQemuKernel.dsc
41*a66f0309SMasahiro Yamada
42*a66f0309SMasahiro Yamada````
43*a66f0309SMasahiro Yamada
44*a66f0309SMasahiro YamadaThen, you will get ``Build/ArmVirtQemuKernel-AARCH64/DEBUG_GCC5/FV/QEMU_EFI.fd``
45*a66f0309SMasahiro Yamada
46*a66f0309SMasahiro YamadaPlease note you do not need to use GCC 5 in spite of the environment variable
47*a66f0309SMasahiro Yamada``GCC5_AARCH64_PREFIX``
48*a66f0309SMasahiro Yamada
49*a66f0309SMasahiro YamadaThe rootfs can be built by using Buildroot as follows:
50*a66f0309SMasahiro Yamada
51*a66f0309SMasahiro Yamada.. code:: shell
52*a66f0309SMasahiro Yamada
53*a66f0309SMasahiro Yamada    git clone git://git.buildroot.net/buildroot.git
54*a66f0309SMasahiro Yamada    cd buildroot
55*a66f0309SMasahiro Yamada    make qemu_aarch64_virt_defconfig
56*a66f0309SMasahiro Yamada    utils/config -e BR2_TARGET_ROOTFS_CPIO
57*a66f0309SMasahiro Yamada    utils/config -e BR2_TARGET_ROOTFS_CPIO_GZIP
58*a66f0309SMasahiro Yamada    make olddefconfig
59*a66f0309SMasahiro Yamada    make
60*a66f0309SMasahiro Yamada
61*a66f0309SMasahiro YamadaThen, you will get ``output/images/rootfs.cpio.gz``.
62*a66f0309SMasahiro 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
8162038be7SMasahiro YamadaTo start (QEMU v4.1.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                           \
8762038be7SMasahiro Yamada        -append "console=ttyAMA0,38400 keep_bootcon root=/dev/vda2"   \
88*a66f0309SMasahiro Yamada        -initrd rootfs.cpio.gz -smp 2 -m 1024 -bios bl1.bin   \
896f625747SDouglas Raillard        -d unimp -semihosting-config enable,target=native
904ebbea95SSumit Garg
914ebbea95SSumit GargBooting via flash based firmwares
924ebbea95SSumit Garg---------------------------------
934ebbea95SSumit Garg
944ebbea95SSumit GargBoot firmwares are loaded via secure FLASH0 device so ``bl1.bin`` and
954ebbea95SSumit Garg``fip.bin`` should be concatenated to create a ``flash.bin`` that is flashed
964ebbea95SSumit Gargonto secure FLASH0.
974ebbea95SSumit Garg
984ebbea95SSumit Garg-  ``bl32.bin`` -> BL32 (``tee-header_v2.bin``)
994ebbea95SSumit Garg-  ``bl32_extra1.bin`` -> BL32 Extra1 (``tee-pager_v2.bin``)
1004ebbea95SSumit Garg-  ``bl32_extra2.bin`` -> BL32 Extra2 (``tee-pageable_v2.bin``)
1014ebbea95SSumit Garg-  ``bl33.bin`` -> BL33 (``QEMU_EFI.fd``)
1024ebbea95SSumit Garg-  ``Image`` -> linux/arch/arm64/boot/Image
1034ebbea95SSumit Garg
1044ebbea95SSumit GargTo build:
1054ebbea95SSumit Garg
1064ebbea95SSumit Garg.. code:: shell
1074ebbea95SSumit Garg
1084ebbea95SSumit Garg    make CROSS_COMPILE=aarch64-linux-gnu- PLAT=qemu BL32=bl32.bin \
1094ebbea95SSumit Garg        BL32_EXTRA1=bl32_extra1.bin BL32_EXTRA2=bl32_extra2.bin \
1104ebbea95SSumit Garg        BL33=bl33.bin BL32_RAM_LOCATION=tdram SPD=opteed all fip
1114ebbea95SSumit Garg
1124ebbea95SSumit GargTo build with TBBR enabled, BL31 and BL32 encrypted with test key:
1134ebbea95SSumit Garg
1144ebbea95SSumit Garg.. code:: shell
1154ebbea95SSumit Garg
1164ebbea95SSumit Garg    make CROSS_COMPILE=aarch64-linux-gnu- PLAT=qemu BL32=bl32.bin \
1174ebbea95SSumit Garg        BL32_EXTRA1=bl32_extra1.bin BL32_EXTRA2=bl32_extra2.bin \
1184ebbea95SSumit Garg        BL33=bl33.bin BL32_RAM_LOCATION=tdram SPD=opteed all fip \
1194ebbea95SSumit Garg        MBEDTLS_DIR=<path-to-mbedtls-repo> TRUSTED_BOARD_BOOT=1 \
1204ebbea95SSumit Garg        GENERATE_COT=1 DECRYPTION_SUPPORT=aes_gcm FW_ENC_STATUS=0 \
1214ebbea95SSumit Garg        ENCRYPT_BL31=1 ENCRYPT_BL32=1
1224ebbea95SSumit Garg
1234ebbea95SSumit GargTo build flash.bin:
1244ebbea95SSumit Garg
1254ebbea95SSumit Garg.. code:: shell
1264ebbea95SSumit Garg
1274ebbea95SSumit Garg    dd if=build/qemu/release/bl1.bin of=flash.bin bs=4096 conv=notrunc
1284ebbea95SSumit Garg    dd if=build/qemu/release/fip.bin of=flash.bin seek=64 bs=4096 conv=notrunc
1294ebbea95SSumit Garg
1304ebbea95SSumit GargTo start (QEMU v2.6.0):
1314ebbea95SSumit Garg
1324ebbea95SSumit Garg.. code:: shell
1334ebbea95SSumit Garg
1344ebbea95SSumit Garg    qemu-system-aarch64 -nographic -machine virt,secure=on -cpu cortex-a57  \
1354ebbea95SSumit Garg        -kernel Image -no-acpi                     \
1364ebbea95SSumit Garg        -append 'console=ttyAMA0,38400 keep_bootcon root=/dev/vda2'  \
137*a66f0309SMasahiro Yamada        -initrd rootfs.cpio.gz -smp 2 -m 1024 -bios flash.bin   \
1384ebbea95SSumit Garg        -d unimp
139