14def07d5SDan HandleyTrusted Firmware-A for Raspberry Pi 3 24def07d5SDan Handley===================================== 31cd4fb65SAntonio Nino Diaz 41cd4fb65SAntonio Nino Diaz.. section-numbering:: 51cd4fb65SAntonio Nino Diaz :suffix: . 61cd4fb65SAntonio Nino Diaz 71cd4fb65SAntonio Nino Diaz.. contents:: 81cd4fb65SAntonio Nino Diaz 91cd4fb65SAntonio Nino DiazThe `Raspberry Pi 3`_ is an inexpensive single-board computer that contains four 105e2e024bSAntonio Nino DiazArm Cortex-A53 cores. 111cd4fb65SAntonio Nino Diaz 124def07d5SDan HandleyThe following instructions explain how to use this port of the TF-A with the 134def07d5SDan Handleydefault distribution of `Raspbian`_ because that's the distribution officially 144def07d5SDan Handleysupported by the Raspberry Pi Foundation. At the moment of writing this, the 154def07d5SDan Handleyofficially supported kernel is a AArch32 kernel. This doesn't mean that this 164def07d5SDan Handleyport of TF-A can't boot a AArch64 kernel. The `Linux tree fork`_ maintained by 174def07d5SDan Handleythe Foundation can be compiled for AArch64 by following the steps in 184def07d5SDan Handley`AArch64 kernel build instructions`_. 191cd4fb65SAntonio Nino Diaz 201cd4fb65SAntonio Nino Diaz**IMPORTANT NOTE**: This port isn't secure. All of the memory used is DRAM, 211cd4fb65SAntonio Nino Diazwhich is available from both the Non-secure and Secure worlds. This port 221cd4fb65SAntonio Nino Diazshouldn't be considered more than a prototype to play with and implement 231cd4fb65SAntonio Nino Diazelements like PSCI to support the Linux kernel. 241cd4fb65SAntonio Nino Diaz 251cd4fb65SAntonio Nino DiazDesign 261cd4fb65SAntonio Nino Diaz------ 271cd4fb65SAntonio Nino Diaz 281cd4fb65SAntonio Nino DiazThe SoC used by the Raspberry Pi 3 is the Broadcom BCM2837. It is a SoC with a 291cd4fb65SAntonio Nino DiazVideoCore IV that acts as primary processor (and loads everything from the SD 301cd4fb65SAntonio Nino Diazcard) and is located between all Arm cores and the DRAM. Check the `Raspberry Pi 311cd4fb65SAntonio Nino Diaz3 documentation`_ for more information. 321cd4fb65SAntonio Nino Diaz 331cd4fb65SAntonio Nino DiazThis explains why it is possible to change the execution state (AArch64/AArch32) 341cd4fb65SAntonio Nino Diazdepending on a few files on the SD card. We only care about the cases in which 351cd4fb65SAntonio Nino Diazthe cores boot in AArch64 mode. 361cd4fb65SAntonio Nino Diaz 371cd4fb65SAntonio Nino DiazThe rules are simple: 381cd4fb65SAntonio Nino Diaz 391cd4fb65SAntonio Nino Diaz- If a file called ``kernel8.img`` is located on the ``boot`` partition of the 401cd4fb65SAntonio Nino Diaz SD card, it will load it and execute in EL2 in AArch64. Basically, it executes 411cd4fb65SAntonio Nino Diaz a `default AArch64 stub`_ at address **0x0** that jumps to the kernel. 421cd4fb65SAntonio Nino Diaz 431cd4fb65SAntonio Nino Diaz- If there is also a file called ``armstub8.bin``, it will load it at address 441cd4fb65SAntonio Nino Diaz **0x0** (instead of the default stub) and execute it in EL3 in AArch64. All 451cd4fb65SAntonio Nino Diaz the cores are powered on at the same time and start at address **0x0**. 461cd4fb65SAntonio Nino Diaz 471cd4fb65SAntonio Nino DiazThis means that we can use the default AArch32 kernel provided in the official 484def07d5SDan Handley`Raspbian`_ distribution by renaming it to ``kernel8.img``, while TF-A and 494def07d5SDan Handleyanything else we need is in ``armstub8.bin``. This way we can forget about the 504def07d5SDan Handleydefault bootstrap code. When using a AArch64 kernel, it is only needed to make 514def07d5SDan Handleysure that the name on the SD card is ``kernel8.img``. 521cd4fb65SAntonio Nino Diaz 531cd4fb65SAntonio Nino DiazIdeally, we want to load the kernel and have all cores available, which means 541cd4fb65SAntonio Nino Diazthat we need to make the secondary cores work in the way the kernel expects, as 551cd4fb65SAntonio Nino Diazexplained in `Secondary cores`_. In practice, a small bootstrap is needed 564def07d5SDan Handleybetween TF-A and the kernel. 571cd4fb65SAntonio Nino Diaz 581cd4fb65SAntonio Nino DiazTo get the most out of a AArch32 kernel, we want to boot it in Hypervisor mode 591cd4fb65SAntonio Nino Diazin AArch32. This means that BL33 can't be in EL2 in AArch64 mode. The 601cd4fb65SAntonio Nino Diazarchitecture specifies that AArch32 Hypervisor mode isn't present when AArch64 611cd4fb65SAntonio Nino Diazis used for EL2. When using a AArch64 kernel, it should simply start in EL2. 621cd4fb65SAntonio Nino Diaz 631cd4fb65SAntonio Nino DiazPlacement of images 641cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~~~~~~~ 651cd4fb65SAntonio Nino Diaz 661cd4fb65SAntonio Nino DiazThe file ``armstub8.bin`` contains BL1 and the FIP. It is needed to add padding 671cd4fb65SAntonio Nino Diazbetween them so that the addresses they are loaded to match the ones specified 685e2e024bSAntonio Nino Diazwhen compiling TF-A. This is done automatically by the build system. 691cd4fb65SAntonio Nino Diaz 701cd4fb65SAntonio Nino DiazThe device tree block is loaded by the VideoCore loader from an appropriate 711cd4fb65SAntonio Nino Diazfile, but we can specify the address it is loaded to in ``config.txt``. 721cd4fb65SAntonio Nino Diaz 731cd4fb65SAntonio Nino DiazThe file ``kernel8.img`` contains a kernel image that is loaded to the address 741cd4fb65SAntonio Nino Diazspecified in ``config.txt``. The `Linux kernel tree`_ has information about how 751cd4fb65SAntonio Nino Diaza AArch32 Linux kernel image is loaded in ``Documentation/arm/Booting``: 761cd4fb65SAntonio Nino Diaz 771cd4fb65SAntonio Nino Diaz:: 781cd4fb65SAntonio Nino Diaz 791cd4fb65SAntonio Nino Diaz The zImage may also be placed in system RAM and called there. The 801cd4fb65SAntonio Nino Diaz kernel should be placed in the first 128MiB of RAM. It is recommended 811cd4fb65SAntonio Nino Diaz that it is loaded above 32MiB in order to avoid the need to relocate 821cd4fb65SAntonio Nino Diaz prior to decompression, which will make the boot process slightly 831cd4fb65SAntonio Nino Diaz faster. 841cd4fb65SAntonio Nino Diaz 851cd4fb65SAntonio Nino DiazThere are no similar restrictions for AArch64 kernels, as specified in the file 861cd4fb65SAntonio Nino Diaz``Documentation/arm64/booting.txt``. 871cd4fb65SAntonio Nino Diaz 881cd4fb65SAntonio Nino DiazThis means that we need to avoid the first 128 MiB of RAM when placing the 894def07d5SDan HandleyTF-A images (and specially the first 32 MiB, as they are directly used to 904def07d5SDan Handleyplace the uncompressed AArch32 kernel image. This way, both AArch32 and 911cd4fb65SAntonio Nino DiazAArch64 kernels can be placed at the same address. 921cd4fb65SAntonio Nino Diaz 931cd4fb65SAntonio Nino DiazIn the end, the images look like the following diagram when placed in memory. 941cd4fb65SAntonio Nino DiazAll addresses are Physical Addresses from the point of view of the Arm cores. 951cd4fb65SAntonio Nino DiazAgain, note that this is all just part of the same DRAM that goes from 961cd4fb65SAntonio Nino Diaz**0x00000000** to **0x3F000000**, it just has different names to simulate a real 971cd4fb65SAntonio Nino Diazsecure platform! 981cd4fb65SAntonio Nino Diaz 991cd4fb65SAntonio Nino Diaz:: 1001cd4fb65SAntonio Nino Diaz 1011cd4fb65SAntonio Nino Diaz 0x00000000 +-----------------+ 1021cd4fb65SAntonio Nino Diaz | ROM | BL1 1036a2c3c7fSYing-Chun Liu (PaulLiu) 0x00020000 +-----------------+ 1041cd4fb65SAntonio Nino Diaz | FIP | 1051cd4fb65SAntonio Nino Diaz 0x00200000 +-----------------+ 1061cd4fb65SAntonio Nino Diaz | | 1071cd4fb65SAntonio Nino Diaz | ... | 1081cd4fb65SAntonio Nino Diaz | | 1091cd4fb65SAntonio Nino Diaz 0x01000000 +-----------------+ 11097fb05e1SAntonio Nino Diaz | DTB | (Loaded by the VideoCore) 1111cd4fb65SAntonio Nino Diaz +-----------------+ 1121cd4fb65SAntonio Nino Diaz | | 1131cd4fb65SAntonio Nino Diaz | ... | 1141cd4fb65SAntonio Nino Diaz | | 1151cd4fb65SAntonio Nino Diaz 0x02000000 +-----------------+ 11697fb05e1SAntonio Nino Diaz | Kernel | (Loaded by the VideoCore) 1171cd4fb65SAntonio Nino Diaz +-----------------+ 1181cd4fb65SAntonio Nino Diaz | | 1191cd4fb65SAntonio Nino Diaz | ... | 1201cd4fb65SAntonio Nino Diaz | | 1211cd4fb65SAntonio Nino Diaz 0x10000000 +-----------------+ 1221cd4fb65SAntonio Nino Diaz | Secure SRAM | BL2, BL31 1231cd4fb65SAntonio Nino Diaz 0x10100000 +-----------------+ 1243d464234SYing-Chun Liu (PaulLiu) | Secure DRAM | BL32 (Secure payload) 1251cd4fb65SAntonio Nino Diaz 0x11000000 +-----------------+ 126aa49bde8SAntonio Nino Diaz | Non-secure DRAM | BL33 127aa49bde8SAntonio Nino Diaz +-----------------+ 1281cd4fb65SAntonio Nino Diaz | | 1291cd4fb65SAntonio Nino Diaz | ... | 1301cd4fb65SAntonio Nino Diaz | | 1311cd4fb65SAntonio Nino Diaz 0x3F000000 +-----------------+ 1321cd4fb65SAntonio Nino Diaz | I/O | 1331cd4fb65SAntonio Nino Diaz 0x40000000 +-----------------+ 1341cd4fb65SAntonio Nino Diaz 13597fb05e1SAntonio Nino DiazThe area between **0x10000000** and **0x11000000** has to be manually protected 1365341b42eSAntonio Nino Diazso that the kernel doesn't use it. The current port tries to modify the live DTB 1375341b42eSAntonio Nino Diazto add a memreserve region that reserves the previously mentioned area. 1385341b42eSAntonio Nino Diaz 1395341b42eSAntonio Nino DiazIf this is not possible, the user may manually add ``memmap=16M$256M`` to the 1405341b42eSAntonio Nino Diazcommand line passed to the kernel in ``cmdline.txt``. See the `Setup SD card`_ 1415341b42eSAntonio Nino Diazinstructions to see how to do it. This system is strongly discouraged. 1421cd4fb65SAntonio Nino Diaz 1431cd4fb65SAntonio Nino DiazThe last 16 MiB of DRAM can only be accessed by the VideoCore, that has 1441cd4fb65SAntonio Nino Diazdifferent mappings than the Arm cores in which the I/O addresses don't overlap 1451cd4fb65SAntonio Nino Diazthe DRAM. The memory reserved to be used by the VideoCore is always placed at 1461cd4fb65SAntonio Nino Diazthe end of the DRAM, so this space isn't wasted. 1471cd4fb65SAntonio Nino Diaz 1484def07d5SDan HandleyConsidering the 128 MiB allocated to the GPU and the 16 MiB allocated for 1494def07d5SDan HandleyTF-A, there are 880 MiB available for Linux. 1501cd4fb65SAntonio Nino Diaz 1511cd4fb65SAntonio Nino DiazBoot sequence 1521cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~ 1531cd4fb65SAntonio Nino Diaz 1544def07d5SDan HandleyThe boot sequence of TF-A is the usual one except when booting an AArch32 1554def07d5SDan Handleykernel. In that case, BL33 is booted in AArch32 Hypervisor mode so that it 1564def07d5SDan Handleycan jump to the kernel in the same mode and let it take over that privilege 1574def07d5SDan Handleylevel. If BL33 was running in EL2 in AArch64 (as in the default bootflow of 1584def07d5SDan HandleyTF-A) it could only jump to the kernel in AArch32 in Supervisor mode. 1591cd4fb65SAntonio Nino Diaz 1601cd4fb65SAntonio Nino DiazThe `Linux kernel tree`_ has instructions on how to jump to the Linux kernel 1611cd4fb65SAntonio Nino Diazin ``Documentation/arm/Booting`` and ``Documentation/arm64/booting.txt``. The 1621cd4fb65SAntonio Nino Diazbootstrap should take care of this. 1631cd4fb65SAntonio Nino Diaz 1645e2e024bSAntonio Nino DiazThis port support a direct boot of the Linux kernel from the firmware (as a BL33 1655e2e024bSAntonio Nino Diazimage). Alternatively, U-Boot or other bootloaders may be used. 1665e2e024bSAntonio Nino Diaz 1671cd4fb65SAntonio Nino DiazSecondary cores 1681cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~~~ 1691cd4fb65SAntonio Nino Diaz 1705e2e024bSAntonio Nino DiazThis port of the Trusted Firmware-A supports ``PSCI_CPU_ON``, 1715e2e024bSAntonio Nino Diaz`PSCI_SYSTEM_RESET`` and ``PSCI_SYSTEM_OFF``. The last one doesn't really turn 1725e2e024bSAntonio Nino Diazthe system off, it simply reboots it and asks the VideoCore firmware to keep it 1735e2e024bSAntonio Nino Diazin a low power mode permanently. 1745e2e024bSAntonio Nino Diaz 1751cd4fb65SAntonio Nino DiazThe kernel used by `Raspbian`_ doesn't have support for PSCI, so it is needed to 1761cd4fb65SAntonio Nino Diazuse mailboxes to trap the secondary cores until they are ready to jump to the 1771cd4fb65SAntonio Nino Diazkernel. This mailbox is located at a different address in the AArch32 default 1781cd4fb65SAntonio Nino Diazkernel than in the AArch64 kernel. 1791cd4fb65SAntonio Nino Diaz 1805e2e024bSAntonio Nino DiazKernels with PSCI support can use the PSCI calls instead for a cleaner boot. 1815e2e024bSAntonio Nino Diaz 1824def07d5SDan HandleyAlso, this port of TF-A has another Trusted Mailbox in Shared BL RAM. During 1834def07d5SDan Handleycold boot, all secondary cores wait in a loop until they are given given an 1844def07d5SDan Handleyaddress to jump to in this Mailbox (``bl31_warm_entrypoint``). 1851cd4fb65SAntonio Nino Diaz 1861cd4fb65SAntonio Nino DiazOnce BL31 has finished and the primary core has jumped to the BL33 payload, it 1871cd4fb65SAntonio Nino Diazhas to call ``PSCI_CPU_ON`` to release the secondary CPUs from the wait loop. 1881cd4fb65SAntonio Nino DiazThe payload then makes them wait in another waitloop listening from messages 1891cd4fb65SAntonio Nino Diazfrom the kernel. When the primary CPU jumps into the kernel, it will send an 1901cd4fb65SAntonio Nino Diazaddress to the mailbox so that the secondary CPUs jump to it and are recognised 1911cd4fb65SAntonio Nino Diazby the kernel. 1921cd4fb65SAntonio Nino Diaz 1931cd4fb65SAntonio Nino DiazBuild Instructions 1941cd4fb65SAntonio Nino Diaz------------------ 1951cd4fb65SAntonio Nino Diaz 1961cd4fb65SAntonio Nino DiazTo boot a AArch64 kernel, only the AArch64 toolchain is required. 1971cd4fb65SAntonio Nino Diaz 1981cd4fb65SAntonio Nino DiazTo boot a AArch32 kernel, both AArch64 and AArch32 toolchains are required. The 1991cd4fb65SAntonio Nino DiazAArch32 toolchain is needed for the AArch32 bootstrap needed to load a 32-bit 2001cd4fb65SAntonio Nino Diazkernel. 2011cd4fb65SAntonio Nino Diaz 20264fe343cSAntonio Nino DiazThe build system concatenates BL1 and the FIP so that the addresses match the 20364fe343cSAntonio Nino Diazones in the memory map. The resulting file is ``armstub8.bin``, located in the 2045e2e024bSAntonio Nino Diazbuild folder (e.g. ``build/rpi3/debug/armstub8.bin``). To know how to use this 2055e2e024bSAntonio Nino Diazfile, follow the instructions in `Setup SD card`_. 2061cd4fb65SAntonio Nino Diaz 2071cd4fb65SAntonio Nino DiazThe following build options are supported: 2081cd4fb65SAntonio Nino Diaz 2091cd4fb65SAntonio Nino Diaz- ``RPI3_BL33_IN_AARCH32``: This port can load a AArch64 or AArch32 BL33 image. 2104def07d5SDan Handley By default this option is 0, which means that TF-A will jump to BL33 in EL2 2114def07d5SDan Handley in AArch64 mode. If set to 1, it will jump to BL33 in Hypervisor in AArch32 2124def07d5SDan Handley mode. 2131cd4fb65SAntonio Nino Diaz 2145e2e024bSAntonio Nino Diaz- ``PRELOADED_BL33_BASE``: Used to specify the address of a BL33 binary that has 2155e2e024bSAntonio Nino Diaz been preloaded by any other system than using the firmware. ``BL33`` isn't 2165e2e024bSAntonio Nino Diaz needed in the build command line if this option is used. Specially useful 2175e2e024bSAntonio Nino Diaz because the file ``kernel8.img`` can be loaded anywhere by modifying the file 2185e2e024bSAntonio Nino Diaz ``config.txt``. It doesn't have to contain a kernel, it could have any 2195e2e024bSAntonio Nino Diaz arbitrary payload. 2205e2e024bSAntonio Nino Diaz 2215e2e024bSAntonio Nino Diaz- ``RPI3_DIRECT_LINUX_BOOT``: Disabled by default. Set to 1 to enable the direct 2225e2e024bSAntonio Nino Diaz boot of the Linux kernel from the firmware. Option ``RPI3_PRELOADED_DTB_BASE`` 2235e2e024bSAntonio Nino Diaz is mandatory when the direct Linux kernel boot is used. Options 2245e2e024bSAntonio Nino Diaz ``PRELOADED_BL33_BASE`` will most likely be needed as well because it is 2255e2e024bSAntonio Nino Diaz unlikely that the kernel image will fit in the space reserved for BL33 images. 2265e2e024bSAntonio Nino Diaz This option can be combined with ``RPI3_BL33_IN_AARCH32`` in order to boot a 2275e2e024bSAntonio Nino Diaz 32-bit kernel. The only thing this option does is to set the arguments in 2285e2e024bSAntonio Nino Diaz registers x0-x3 or r0-r2 as expected by the kernel. 2295e2e024bSAntonio Nino Diaz 2305e2e024bSAntonio Nino Diaz- ``RPI3_PRELOADED_DTB_BASE``: Auxiliary build option needed when using 2315e2e024bSAntonio Nino Diaz ``RPI3_DIRECT_LINUX_BOOT=1``. This option allows to specify the location of a 2325e2e024bSAntonio Nino Diaz DTB in memory. 2335e2e024bSAntonio Nino Diaz 2346d5c61deSPete Batard- ``RPI3_RUNTIME_UART``: Indicates whether the UART should be used at runtime 2356d5c61deSPete Batard or disabled. ``-1`` (default) disables the runtime UART. Any other value 2366d5c61deSPete Batard enables the default UART (currently UART1) for runtime messages. 2376d5c61deSPete Batard 238*4dcf1fadSPete Batard- ``RPI3_USE_UEFI_MAP``: Set to 1 to build ATF with the altername memory 239*4dcf1fadSPete Batard mapping required for an UEFI firmware payload. These changes are needed 240*4dcf1fadSPete Batard to be able to run Windows on ARM64. This option, which is disabled by 241*4dcf1fadSPete Batard default, results in the following memory mappings: 242*4dcf1fadSPete Batard 243*4dcf1fadSPete Batard:: 244*4dcf1fadSPete Batard 245*4dcf1fadSPete Batard 0x00000000 +-----------------+ 246*4dcf1fadSPete Batard | ROM | BL1 247*4dcf1fadSPete Batard 0x00010000 +-----------------+ 248*4dcf1fadSPete Batard | DTB | (Loaded by the VideoCore) 249*4dcf1fadSPete Batard 0x00020000 +-----------------+ 250*4dcf1fadSPete Batard | FIP | 251*4dcf1fadSPete Batard 0x00030000 +-----------------+ 252*4dcf1fadSPete Batard | | 253*4dcf1fadSPete Batard | UEFI PAYLOAD | 254*4dcf1fadSPete Batard | | 255*4dcf1fadSPete Batard 0x00200000 +-----------------+ 256*4dcf1fadSPete Batard | Secure SRAM | BL2, BL31 257*4dcf1fadSPete Batard 0x00300000 +-----------------+ 258*4dcf1fadSPete Batard | Secure DRAM | BL32 (Secure payload) 259*4dcf1fadSPete Batard 0x00400000 +-----------------+ 260*4dcf1fadSPete Batard | | 261*4dcf1fadSPete Batard | | 262*4dcf1fadSPete Batard | Non-secure DRAM | BL33 263*4dcf1fadSPete Batard | | 264*4dcf1fadSPete Batard | | 265*4dcf1fadSPete Batard 0x01000000 +-----------------+ 266*4dcf1fadSPete Batard | | 267*4dcf1fadSPete Batard | ... | 268*4dcf1fadSPete Batard | | 269*4dcf1fadSPete Batard 0x3F000000 +-----------------+ 270*4dcf1fadSPete Batard | I/O | 271*4dcf1fadSPete Batard 272*4dcf1fadSPete Batard 2733d464234SYing-Chun Liu (PaulLiu)- ``BL32``: This port can load and run OP-TEE. The OP-TEE image is optional. 2743d464234SYing-Chun Liu (PaulLiu) Please use the code from `here <https://github.com/OP-TEE/optee_os>`__. 2753d464234SYing-Chun Liu (PaulLiu) Build the Trusted Firmware with option ``BL32=tee-header_v2.bin 2763d464234SYing-Chun Liu (PaulLiu) BL32_EXTRA1=tee-pager_v2.bin BL32_EXTRA2=tee-pageable_v2.bin`` 2773d464234SYing-Chun Liu (PaulLiu) to put the binaries into the FIP. 2783d464234SYing-Chun Liu (PaulLiu) 279d35de55eSAntonio Nino Diaz Note: If OP-TEE is used it may be needed to add the following options to the 280d35de55eSAntonio Nino Diaz Linux command line so that the USB driver doesn't use FIQs: 281d35de55eSAntonio Nino Diaz ``dwc_otg.fiq_enable=0 dwc_otg.fiq_fsm_enable=0 dwc_otg.nak_holdoff=0``. 282d35de55eSAntonio Nino Diaz This will unfortunately reduce the performance of the USB driver. It is needed 283d35de55eSAntonio Nino Diaz when using Raspbian, for example. 284d35de55eSAntonio Nino Diaz 2855e2e024bSAntonio Nino Diaz- ``TRUSTED_BOARD_BOOT``: This port supports TBB. Set this option to 1 to enable 2865e2e024bSAntonio Nino Diaz it. In order to use TBB, you might want to set ``GENERATE_COT=1`` to let the 2875e2e024bSAntonio Nino Diaz contents of the FIP automatically signed by the build process. The ROT key 2885e2e024bSAntonio Nino Diaz will be generated and output to ``rot_key.pem`` in the build directory. It is 2895e2e024bSAntonio Nino Diaz able to set ROT_KEY to your own key in PEM format. Also in order to build, 2905e2e024bSAntonio Nino Diaz you need to clone mbed TLS from `here <https://github.com/ARMmbed/mbedtls>`__. 2915e2e024bSAntonio Nino Diaz ``MBEDTLS_DIR`` must point at the mbed TLS source directory. 2925e2e024bSAntonio Nino Diaz 2935e2e024bSAntonio Nino Diaz- ``ENABLE_STACK_PROTECTOR``: Disabled by default. It uses the hardware RNG of 2945e2e024bSAntonio Nino Diaz the board. 295ebbdbb1fSYing-Chun Liu (PaulLiu) 2961cd4fb65SAntonio Nino DiazThe following is not currently supported: 2971cd4fb65SAntonio Nino Diaz 2984def07d5SDan Handley- AArch32 for TF-A itself. 2991cd4fb65SAntonio Nino Diaz 3001cd4fb65SAntonio Nino Diaz- ``EL3_PAYLOAD_BASE``: The reason is that you can already load anything to any 3011cd4fb65SAntonio Nino Diaz address by changing the file ``armstub8.bin``, so there's no point in using 3024def07d5SDan Handley TF-A in this case. 3031cd4fb65SAntonio Nino Diaz 304e0f21f62SAntonio Nino Diaz- ``MULTI_CONSOLE_API=0``: The multi console API must be enabled. Note that the 305e0f21f62SAntonio Nino Diaz crash console uses the internal 16550 driver functions directly in order to be 306e0f21f62SAntonio Nino Diaz able to print error messages during early crashes before setting up the 307e0f21f62SAntonio Nino Diaz multi console API. 308e0f21f62SAntonio Nino Diaz 3095e2e024bSAntonio Nino DiazBuilding the firmware for kernels that don't support PSCI 3105e2e024bSAntonio Nino Diaz~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3115e2e024bSAntonio Nino Diaz 3125e2e024bSAntonio Nino DiazThis is the case for the 32-bit image of Raspbian, for example. 64-bit kernels 3135e2e024bSAntonio Nino Diazalways support PSCI, but they may not know that the system understands PSCI due 3145e2e024bSAntonio Nino Diazto an incorrect DTB file. 3155e2e024bSAntonio Nino Diaz 3165e2e024bSAntonio Nino DiazFirst, clone and compile the 32-bit version of the `Raspberry Pi 3 TF-A 3175e2e024bSAntonio Nino Diazbootstrap`_. Choose the one needed for the architecture of your kernel. 3185e2e024bSAntonio Nino Diaz 3195e2e024bSAntonio Nino DiazThen compile TF-A. For a 32-bit kernel, use the following command line: 3205e2e024bSAntonio Nino Diaz 3215e2e024bSAntonio Nino Diaz.. code:: shell 3225e2e024bSAntonio Nino Diaz 3235e2e024bSAntonio Nino Diaz CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 3245e2e024bSAntonio Nino Diaz RPI3_BL33_IN_AARCH32=1 \ 3255e2e024bSAntonio Nino Diaz BL33=../rpi3-arm-tf-bootstrap/aarch32/el2-bootstrap.bin 3265e2e024bSAntonio Nino Diaz 3275e2e024bSAntonio Nino DiazFor a 64-bit kernel, use this other command line: 3285e2e024bSAntonio Nino Diaz 3295e2e024bSAntonio Nino Diaz.. code:: shell 3305e2e024bSAntonio Nino Diaz 3315e2e024bSAntonio Nino Diaz CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 3325e2e024bSAntonio Nino Diaz BL33=../rpi3-arm-tf-bootstrap/aarch64/el2-bootstrap.bin 3335e2e024bSAntonio Nino Diaz 3345e2e024bSAntonio Nino DiazHowever, enabling PSCI support in a 64-bit kernel is really easy. In the 3355e2e024bSAntonio Nino Diazrepository `Raspberry Pi 3 TF-A bootstrap`_ there is a patch that can be applied 3365e2e024bSAntonio Nino Diazto the Linux kernel tree maintained by the Raspberry Pi foundation. It modifes 3375e2e024bSAntonio Nino Diazthe DTS to tell the kernel to use PSCI. Once this patch is applied, follow the 3385e2e024bSAntonio Nino Diazinstructions in `AArch64 kernel build instructions`_ to get a working 64-bit 3395e2e024bSAntonio Nino Diazkernel image and supporting files. 3405e2e024bSAntonio Nino Diaz 3415e2e024bSAntonio Nino DiazBuilding the firmware for kernels that support PSCI 3425e2e024bSAntonio Nino Diaz~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3435e2e024bSAntonio Nino Diaz 3445e2e024bSAntonio Nino DiazFor a 64-bit kernel: 3455e2e024bSAntonio Nino Diaz 3465e2e024bSAntonio Nino Diaz.. code:: shell 3475e2e024bSAntonio Nino Diaz 3485e2e024bSAntonio Nino Diaz CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 34997fb05e1SAntonio Nino Diaz PRELOADED_BL33_BASE=0x02000000 \ 35097fb05e1SAntonio Nino Diaz RPI3_PRELOADED_DTB_BASE=0x01000000 \ 3515e2e024bSAntonio Nino Diaz RPI3_DIRECT_LINUX_BOOT=1 3525e2e024bSAntonio Nino Diaz 3535e2e024bSAntonio Nino DiazFor a 32-bit kernel: 3545e2e024bSAntonio Nino Diaz 3555e2e024bSAntonio Nino Diaz.. code:: shell 3565e2e024bSAntonio Nino Diaz 3575e2e024bSAntonio Nino Diaz CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 35897fb05e1SAntonio Nino Diaz PRELOADED_BL33_BASE=0x02000000 \ 35997fb05e1SAntonio Nino Diaz RPI3_PRELOADED_DTB_BASE=0x01000000 \ 3605e2e024bSAntonio Nino Diaz RPI3_DIRECT_LINUX_BOOT=1 \ 3615e2e024bSAntonio Nino Diaz RPI3_BL33_IN_AARCH32=1 3625e2e024bSAntonio Nino Diaz 3631cd4fb65SAntonio Nino DiazAArch64 kernel build instructions 3641cd4fb65SAntonio Nino Diaz--------------------------------- 3651cd4fb65SAntonio Nino Diaz 3661cd4fb65SAntonio Nino DiazThe following instructions show how to install and run a AArch64 kernel by 3671cd4fb65SAntonio Nino Diazusing a SD card with the default `Raspbian`_ install as base. Skip them if you 3681cd4fb65SAntonio Nino Diazwant to use the default 32-bit kernel. 3691cd4fb65SAntonio Nino Diaz 3701cd4fb65SAntonio Nino DiazNote that this system won't be fully 64-bit because all the tools in the 3711cd4fb65SAntonio Nino Diazfilesystem are 32-bit binaries, but it's a quick way to get it working, and it 3721cd4fb65SAntonio Nino Diazallows the user to run 64-bit binaries in addition to 32-bit binaries. 3731cd4fb65SAntonio Nino Diaz 3741cd4fb65SAntonio Nino Diaz1. Clone the `Linux tree fork`_ maintained by the Raspberry Pi Foundation. To 3751cd4fb65SAntonio Nino Diaz speed things up, do a shallow clone of the desired branch. 3761cd4fb65SAntonio Nino Diaz 3771cd4fb65SAntonio Nino Diaz.. code:: shell 3781cd4fb65SAntonio Nino Diaz 3795e2e024bSAntonio Nino Diaz git clone --depth=1 -b rpi-4.18.y https://github.com/raspberrypi/linux 3801cd4fb65SAntonio Nino Diaz cd linux 3811cd4fb65SAntonio Nino Diaz 3821cd4fb65SAntonio Nino Diaz2. Configure and compile the kernel. Adapt the number after ``-j`` so that it is 3831cd4fb65SAntonio Nino Diaz 1.5 times the number of CPUs in your computer. This may take some time to 3841cd4fb65SAntonio Nino Diaz finish. 3851cd4fb65SAntonio Nino Diaz 3861cd4fb65SAntonio Nino Diaz.. code:: shell 3871cd4fb65SAntonio Nino Diaz 3881cd4fb65SAntonio Nino Diaz make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig 3891cd4fb65SAntonio Nino Diaz make -j 6 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- 3901cd4fb65SAntonio Nino Diaz 3911cd4fb65SAntonio Nino Diaz3. Copy the kernel image and the device tree to the SD card. Replace the path 3921cd4fb65SAntonio Nino Diaz by the corresponding path in your computers to the ``boot`` partition of the 3931cd4fb65SAntonio Nino Diaz SD card. 3941cd4fb65SAntonio Nino Diaz 3951cd4fb65SAntonio Nino Diaz.. code:: shell 3961cd4fb65SAntonio Nino Diaz 3971cd4fb65SAntonio Nino Diaz cp arch/arm64/boot/Image /path/to/boot/kernel8.img 3981cd4fb65SAntonio Nino Diaz cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b.dtb /path/to/boot/ 3995e2e024bSAntonio Nino Diaz cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b-plus.dtb /path/to/boot/ 4001cd4fb65SAntonio Nino Diaz 4011cd4fb65SAntonio Nino Diaz4. Install the kernel modules. Replace the path by the corresponding path to the 4021cd4fb65SAntonio Nino Diaz filesystem partition of the SD card on your computer. 4031cd4fb65SAntonio Nino Diaz 4041cd4fb65SAntonio Nino Diaz.. code:: shell 4051cd4fb65SAntonio Nino Diaz 4061cd4fb65SAntonio Nino Diaz make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \ 4071cd4fb65SAntonio Nino Diaz INSTALL_MOD_PATH=/path/to/filesystem modules_install 4081cd4fb65SAntonio Nino Diaz 4091cd4fb65SAntonio Nino Diaz5. Follow the instructions in `Setup SD card`_ except for the step of renaming 4101cd4fb65SAntonio Nino Diaz the existing ``kernel7.img`` (we have already copied a AArch64 kernel). 4111cd4fb65SAntonio Nino Diaz 4121cd4fb65SAntonio Nino DiazSetup SD card 4131cd4fb65SAntonio Nino Diaz------------- 4141cd4fb65SAntonio Nino Diaz 4151cd4fb65SAntonio Nino DiazThe instructions assume that you have an SD card with a fresh install of 4161cd4fb65SAntonio Nino Diaz`Raspbian`_ (or that, at least, the ``boot`` partition is untouched, or nearly 417e0f21f62SAntonio Nino Diazuntouched). They have been tested with the image available in 2018-03-13. 4181cd4fb65SAntonio Nino Diaz 4191cd4fb65SAntonio Nino Diaz1. Insert the SD card and open the ``boot`` partition. 4201cd4fb65SAntonio Nino Diaz 4211cd4fb65SAntonio Nino Diaz2. Rename ``kernel7.img`` to ``kernel8.img``. This tricks the VideoCore 4224def07d5SDan Handley bootloader into booting the Arm cores in AArch64 mode, like TF-A needs, 4234def07d5SDan Handley even though the kernel is not compiled for AArch64. 4241cd4fb65SAntonio Nino Diaz 4251cd4fb65SAntonio Nino Diaz3. Copy ``armstub8.bin`` here. When ``kernel8.img`` is available, The VideoCore 4261cd4fb65SAntonio Nino Diaz bootloader will look for a file called ``armstub8.bin`` and load it at 4271cd4fb65SAntonio Nino Diaz address **0x0** instead of a predefined one. 4281cd4fb65SAntonio Nino Diaz 4295341b42eSAntonio Nino Diaz4. To enable the serial port "Mini UART" in Linux, open ``cmdline.txt`` and add 4301cd4fb65SAntonio Nino Diaz ``console=serial0,115200 console=tty1``. 4311cd4fb65SAntonio Nino Diaz 4321cd4fb65SAntonio Nino Diaz5. Open ``config.txt`` and add the following lines at the end (``enable_uart=1`` 4331cd4fb65SAntonio Nino Diaz is only needed to enable debugging through the Mini UART): 4341cd4fb65SAntonio Nino Diaz 4351cd4fb65SAntonio Nino Diaz:: 4361cd4fb65SAntonio Nino Diaz 4371cd4fb65SAntonio Nino Diaz enable_uart=1 43897fb05e1SAntonio Nino Diaz kernel_address=0x02000000 43997fb05e1SAntonio Nino Diaz device_tree_address=0x01000000 4401cd4fb65SAntonio Nino Diaz 4411cd4fb65SAntonio Nino DiazIf you connect a serial cable to the Mini UART and your computer, and connect 4421cd4fb65SAntonio Nino Diazto it (for example, with ``screen /dev/ttyUSB0 115200``) you should see some 4431cd4fb65SAntonio Nino Diaztext. In the case of an AArch32 kernel, you should see something like this: 4441cd4fb65SAntonio Nino Diaz 4451cd4fb65SAntonio Nino Diaz:: 4461cd4fb65SAntonio Nino Diaz 4471cd4fb65SAntonio Nino Diaz NOTICE: Booting Trusted Firmware 4481cd4fb65SAntonio Nino Diaz NOTICE: BL1: v1.4(release):v1.4-329-g61e94684-dirty 4491cd4fb65SAntonio Nino Diaz NOTICE: BL1: Built : 00:09:25, Nov 6 2017 4501cd4fb65SAntonio Nino Diaz NOTICE: BL1: Booting BL2 4511cd4fb65SAntonio Nino Diaz NOTICE: BL2: v1.4(release):v1.4-329-g61e94684-dirty 4521cd4fb65SAntonio Nino Diaz NOTICE: BL2: Built : 00:09:25, Nov 6 2017 4531cd4fb65SAntonio Nino Diaz NOTICE: BL1: Booting BL31 4541cd4fb65SAntonio Nino Diaz NOTICE: BL31: v1.4(release):v1.4-329-g61e94684-dirty 4551cd4fb65SAntonio Nino Diaz NOTICE: BL31: Built : 00:09:25, Nov 6 2017 4561cd4fb65SAntonio Nino Diaz [ 0.266484] bcm2835-aux-uart 3f215040.serial: could not get clk: -517 4571cd4fb65SAntonio Nino Diaz 4581cd4fb65SAntonio Nino Diaz Raspbian GNU/Linux 9 raspberrypi ttyS0 4591cd4fb65SAntonio Nino Diaz raspberrypi login: 4601cd4fb65SAntonio Nino Diaz 4611cd4fb65SAntonio Nino DiazJust enter your credentials, everything should work as expected. Note that the 4621cd4fb65SAntonio Nino DiazHDMI output won't show any text during boot. 4631cd4fb65SAntonio Nino Diaz 4641cd4fb65SAntonio Nino Diaz.. _default Arm stub: https://github.com/raspberrypi/tools/blob/master/armstubs/armstub7.S 4651cd4fb65SAntonio Nino Diaz.. _default AArch64 stub: https://github.com/raspberrypi/tools/blob/master/armstubs/armstub8.S 4661cd4fb65SAntonio Nino Diaz.. _Linux kernel tree: https://github.com/torvalds/linux 4671cd4fb65SAntonio Nino Diaz.. _Linux tree fork: https://github.com/raspberrypi/linux 4681cd4fb65SAntonio Nino Diaz.. _Raspberry Pi 3: https://www.raspberrypi.org/products/raspberry-pi-3-model-b/ 4694def07d5SDan Handley.. _Raspberry Pi 3 TF-A bootstrap: https://github.com/AntonioND/rpi3-arm-tf-bootstrap 4701cd4fb65SAntonio Nino Diaz.. _Raspberry Pi 3 documentation: https://www.raspberrypi.org/documentation/ 4711cd4fb65SAntonio Nino Diaz.. _Raspbian: https://www.raspberrypi.org/downloads/raspbian/ 472