1*24dba2b3SPaul BeesleyRaspberry Pi 3 2*24dba2b3SPaul Beesley============== 31cd4fb65SAntonio Nino Diaz 41cd4fb65SAntonio Nino Diaz.. contents:: 51cd4fb65SAntonio Nino Diaz 61cd4fb65SAntonio Nino DiazThe `Raspberry Pi 3`_ is an inexpensive single-board computer that contains four 75e2e024bSAntonio Nino DiazArm Cortex-A53 cores. 81cd4fb65SAntonio Nino Diaz 94def07d5SDan HandleyThe following instructions explain how to use this port of the TF-A with the 104def07d5SDan Handleydefault distribution of `Raspbian`_ because that's the distribution officially 114def07d5SDan Handleysupported by the Raspberry Pi Foundation. At the moment of writing this, the 124def07d5SDan Handleyofficially supported kernel is a AArch32 kernel. This doesn't mean that this 134def07d5SDan Handleyport of TF-A can't boot a AArch64 kernel. The `Linux tree fork`_ maintained by 144def07d5SDan Handleythe Foundation can be compiled for AArch64 by following the steps in 154def07d5SDan Handley`AArch64 kernel build instructions`_. 161cd4fb65SAntonio Nino Diaz 171cd4fb65SAntonio Nino Diaz**IMPORTANT NOTE**: This port isn't secure. All of the memory used is DRAM, 181cd4fb65SAntonio Nino Diazwhich is available from both the Non-secure and Secure worlds. This port 191cd4fb65SAntonio Nino Diazshouldn't be considered more than a prototype to play with and implement 201cd4fb65SAntonio Nino Diazelements like PSCI to support the Linux kernel. 211cd4fb65SAntonio Nino Diaz 221cd4fb65SAntonio Nino DiazDesign 231cd4fb65SAntonio Nino Diaz------ 241cd4fb65SAntonio Nino Diaz 251cd4fb65SAntonio Nino DiazThe SoC used by the Raspberry Pi 3 is the Broadcom BCM2837. It is a SoC with a 261cd4fb65SAntonio Nino DiazVideoCore IV that acts as primary processor (and loads everything from the SD 271cd4fb65SAntonio Nino Diazcard) and is located between all Arm cores and the DRAM. Check the `Raspberry Pi 281cd4fb65SAntonio Nino Diaz3 documentation`_ for more information. 291cd4fb65SAntonio Nino Diaz 301cd4fb65SAntonio Nino DiazThis explains why it is possible to change the execution state (AArch64/AArch32) 311cd4fb65SAntonio Nino Diazdepending on a few files on the SD card. We only care about the cases in which 321cd4fb65SAntonio Nino Diazthe cores boot in AArch64 mode. 331cd4fb65SAntonio Nino Diaz 341cd4fb65SAntonio Nino DiazThe rules are simple: 351cd4fb65SAntonio Nino Diaz 361cd4fb65SAntonio Nino Diaz- If a file called ``kernel8.img`` is located on the ``boot`` partition of the 371cd4fb65SAntonio Nino Diaz SD card, it will load it and execute in EL2 in AArch64. Basically, it executes 381cd4fb65SAntonio Nino Diaz a `default AArch64 stub`_ at address **0x0** that jumps to the kernel. 391cd4fb65SAntonio Nino Diaz 401cd4fb65SAntonio Nino Diaz- If there is also a file called ``armstub8.bin``, it will load it at address 411cd4fb65SAntonio Nino Diaz **0x0** (instead of the default stub) and execute it in EL3 in AArch64. All 421cd4fb65SAntonio Nino Diaz the cores are powered on at the same time and start at address **0x0**. 431cd4fb65SAntonio Nino Diaz 441cd4fb65SAntonio Nino DiazThis means that we can use the default AArch32 kernel provided in the official 454def07d5SDan Handley`Raspbian`_ distribution by renaming it to ``kernel8.img``, while TF-A and 464def07d5SDan Handleyanything else we need is in ``armstub8.bin``. This way we can forget about the 474def07d5SDan Handleydefault bootstrap code. When using a AArch64 kernel, it is only needed to make 484def07d5SDan Handleysure that the name on the SD card is ``kernel8.img``. 491cd4fb65SAntonio Nino Diaz 501cd4fb65SAntonio Nino DiazIdeally, we want to load the kernel and have all cores available, which means 511cd4fb65SAntonio Nino Diazthat we need to make the secondary cores work in the way the kernel expects, as 521cd4fb65SAntonio Nino Diazexplained in `Secondary cores`_. In practice, a small bootstrap is needed 534def07d5SDan Handleybetween TF-A and the kernel. 541cd4fb65SAntonio Nino Diaz 551cd4fb65SAntonio Nino DiazTo get the most out of a AArch32 kernel, we want to boot it in Hypervisor mode 561cd4fb65SAntonio Nino Diazin AArch32. This means that BL33 can't be in EL2 in AArch64 mode. The 571cd4fb65SAntonio Nino Diazarchitecture specifies that AArch32 Hypervisor mode isn't present when AArch64 581cd4fb65SAntonio Nino Diazis used for EL2. When using a AArch64 kernel, it should simply start in EL2. 591cd4fb65SAntonio Nino Diaz 601cd4fb65SAntonio Nino DiazPlacement of images 611cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~~~~~~~ 621cd4fb65SAntonio Nino Diaz 631cd4fb65SAntonio Nino DiazThe file ``armstub8.bin`` contains BL1 and the FIP. It is needed to add padding 641cd4fb65SAntonio Nino Diazbetween them so that the addresses they are loaded to match the ones specified 655e2e024bSAntonio Nino Diazwhen compiling TF-A. This is done automatically by the build system. 661cd4fb65SAntonio Nino Diaz 671cd4fb65SAntonio Nino DiazThe device tree block is loaded by the VideoCore loader from an appropriate 681cd4fb65SAntonio Nino Diazfile, but we can specify the address it is loaded to in ``config.txt``. 691cd4fb65SAntonio Nino Diaz 701cd4fb65SAntonio Nino DiazThe file ``kernel8.img`` contains a kernel image that is loaded to the address 711cd4fb65SAntonio Nino Diazspecified in ``config.txt``. The `Linux kernel tree`_ has information about how 721cd4fb65SAntonio Nino Diaza AArch32 Linux kernel image is loaded in ``Documentation/arm/Booting``: 731cd4fb65SAntonio Nino Diaz 741cd4fb65SAntonio Nino Diaz:: 751cd4fb65SAntonio Nino Diaz 761cd4fb65SAntonio Nino Diaz The zImage may also be placed in system RAM and called there. The 771cd4fb65SAntonio Nino Diaz kernel should be placed in the first 128MiB of RAM. It is recommended 781cd4fb65SAntonio Nino Diaz that it is loaded above 32MiB in order to avoid the need to relocate 791cd4fb65SAntonio Nino Diaz prior to decompression, which will make the boot process slightly 801cd4fb65SAntonio Nino Diaz faster. 811cd4fb65SAntonio Nino Diaz 821cd4fb65SAntonio Nino DiazThere are no similar restrictions for AArch64 kernels, as specified in the file 831cd4fb65SAntonio Nino Diaz``Documentation/arm64/booting.txt``. 841cd4fb65SAntonio Nino Diaz 851cd4fb65SAntonio Nino DiazThis means that we need to avoid the first 128 MiB of RAM when placing the 864def07d5SDan HandleyTF-A images (and specially the first 32 MiB, as they are directly used to 874def07d5SDan Handleyplace the uncompressed AArch32 kernel image. This way, both AArch32 and 881cd4fb65SAntonio Nino DiazAArch64 kernels can be placed at the same address. 891cd4fb65SAntonio Nino Diaz 901cd4fb65SAntonio Nino DiazIn the end, the images look like the following diagram when placed in memory. 911cd4fb65SAntonio Nino DiazAll addresses are Physical Addresses from the point of view of the Arm cores. 921cd4fb65SAntonio Nino DiazAgain, note that this is all just part of the same DRAM that goes from 931cd4fb65SAntonio Nino Diaz**0x00000000** to **0x3F000000**, it just has different names to simulate a real 941cd4fb65SAntonio Nino Diazsecure platform! 951cd4fb65SAntonio Nino Diaz 961cd4fb65SAntonio Nino Diaz:: 971cd4fb65SAntonio Nino Diaz 981cd4fb65SAntonio Nino Diaz 0x00000000 +-----------------+ 991cd4fb65SAntonio Nino Diaz | ROM | BL1 1006a2c3c7fSYing-Chun Liu (PaulLiu) 0x00020000 +-----------------+ 1011cd4fb65SAntonio Nino Diaz | FIP | 1021cd4fb65SAntonio Nino Diaz 0x00200000 +-----------------+ 1031cd4fb65SAntonio Nino Diaz | | 1041cd4fb65SAntonio Nino Diaz | ... | 1051cd4fb65SAntonio Nino Diaz | | 1061cd4fb65SAntonio Nino Diaz 0x01000000 +-----------------+ 10797fb05e1SAntonio Nino Diaz | DTB | (Loaded by the VideoCore) 1081cd4fb65SAntonio Nino Diaz +-----------------+ 1091cd4fb65SAntonio Nino Diaz | | 1101cd4fb65SAntonio Nino Diaz | ... | 1111cd4fb65SAntonio Nino Diaz | | 1121cd4fb65SAntonio Nino Diaz 0x02000000 +-----------------+ 11397fb05e1SAntonio Nino Diaz | Kernel | (Loaded by the VideoCore) 1141cd4fb65SAntonio Nino Diaz +-----------------+ 1151cd4fb65SAntonio Nino Diaz | | 1161cd4fb65SAntonio Nino Diaz | ... | 1171cd4fb65SAntonio Nino Diaz | | 1181cd4fb65SAntonio Nino Diaz 0x10000000 +-----------------+ 1191cd4fb65SAntonio Nino Diaz | Secure SRAM | BL2, BL31 1201cd4fb65SAntonio Nino Diaz 0x10100000 +-----------------+ 1213d464234SYing-Chun Liu (PaulLiu) | Secure DRAM | BL32 (Secure payload) 1221cd4fb65SAntonio Nino Diaz 0x11000000 +-----------------+ 123aa49bde8SAntonio Nino Diaz | Non-secure DRAM | BL33 124aa49bde8SAntonio Nino Diaz +-----------------+ 1251cd4fb65SAntonio Nino Diaz | | 1261cd4fb65SAntonio Nino Diaz | ... | 1271cd4fb65SAntonio Nino Diaz | | 1281cd4fb65SAntonio Nino Diaz 0x3F000000 +-----------------+ 1291cd4fb65SAntonio Nino Diaz | I/O | 1301cd4fb65SAntonio Nino Diaz 0x40000000 +-----------------+ 1311cd4fb65SAntonio Nino Diaz 13297fb05e1SAntonio Nino DiazThe area between **0x10000000** and **0x11000000** has to be manually protected 1335341b42eSAntonio Nino Diazso that the kernel doesn't use it. The current port tries to modify the live DTB 1345341b42eSAntonio Nino Diazto add a memreserve region that reserves the previously mentioned area. 1355341b42eSAntonio Nino Diaz 1365341b42eSAntonio Nino DiazIf this is not possible, the user may manually add ``memmap=16M$256M`` to the 1375341b42eSAntonio Nino Diazcommand line passed to the kernel in ``cmdline.txt``. See the `Setup SD card`_ 1385341b42eSAntonio Nino Diazinstructions to see how to do it. This system is strongly discouraged. 1391cd4fb65SAntonio Nino Diaz 1401cd4fb65SAntonio Nino DiazThe last 16 MiB of DRAM can only be accessed by the VideoCore, that has 1411cd4fb65SAntonio Nino Diazdifferent mappings than the Arm cores in which the I/O addresses don't overlap 1421cd4fb65SAntonio Nino Diazthe DRAM. The memory reserved to be used by the VideoCore is always placed at 1431cd4fb65SAntonio Nino Diazthe end of the DRAM, so this space isn't wasted. 1441cd4fb65SAntonio Nino Diaz 1454def07d5SDan HandleyConsidering the 128 MiB allocated to the GPU and the 16 MiB allocated for 1464def07d5SDan HandleyTF-A, there are 880 MiB available for Linux. 1471cd4fb65SAntonio Nino Diaz 1481cd4fb65SAntonio Nino DiazBoot sequence 1491cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~ 1501cd4fb65SAntonio Nino Diaz 1514def07d5SDan HandleyThe boot sequence of TF-A is the usual one except when booting an AArch32 1524def07d5SDan Handleykernel. In that case, BL33 is booted in AArch32 Hypervisor mode so that it 1534def07d5SDan Handleycan jump to the kernel in the same mode and let it take over that privilege 1544def07d5SDan Handleylevel. If BL33 was running in EL2 in AArch64 (as in the default bootflow of 1554def07d5SDan HandleyTF-A) it could only jump to the kernel in AArch32 in Supervisor mode. 1561cd4fb65SAntonio Nino Diaz 1571cd4fb65SAntonio Nino DiazThe `Linux kernel tree`_ has instructions on how to jump to the Linux kernel 1581cd4fb65SAntonio Nino Diazin ``Documentation/arm/Booting`` and ``Documentation/arm64/booting.txt``. The 1591cd4fb65SAntonio Nino Diazbootstrap should take care of this. 1601cd4fb65SAntonio Nino Diaz 1615e2e024bSAntonio Nino DiazThis port support a direct boot of the Linux kernel from the firmware (as a BL33 1625e2e024bSAntonio Nino Diazimage). Alternatively, U-Boot or other bootloaders may be used. 1635e2e024bSAntonio Nino Diaz 1641cd4fb65SAntonio Nino DiazSecondary cores 1651cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~~~ 1661cd4fb65SAntonio Nino Diaz 1675e2e024bSAntonio Nino DiazThis port of the Trusted Firmware-A supports ``PSCI_CPU_ON``, 168*24dba2b3SPaul Beesley``PSCI_SYSTEM_RESET`` and ``PSCI_SYSTEM_OFF``. The last one doesn't really turn 1695e2e024bSAntonio Nino Diazthe system off, it simply reboots it and asks the VideoCore firmware to keep it 1705e2e024bSAntonio Nino Diazin a low power mode permanently. 1715e2e024bSAntonio Nino Diaz 1721cd4fb65SAntonio Nino DiazThe kernel used by `Raspbian`_ doesn't have support for PSCI, so it is needed to 1731cd4fb65SAntonio Nino Diazuse mailboxes to trap the secondary cores until they are ready to jump to the 1741cd4fb65SAntonio Nino Diazkernel. This mailbox is located at a different address in the AArch32 default 1751cd4fb65SAntonio Nino Diazkernel than in the AArch64 kernel. 1761cd4fb65SAntonio Nino Diaz 1775e2e024bSAntonio Nino DiazKernels with PSCI support can use the PSCI calls instead for a cleaner boot. 1785e2e024bSAntonio Nino Diaz 1794def07d5SDan HandleyAlso, this port of TF-A has another Trusted Mailbox in Shared BL RAM. During 1804def07d5SDan Handleycold boot, all secondary cores wait in a loop until they are given given an 1814def07d5SDan Handleyaddress to jump to in this Mailbox (``bl31_warm_entrypoint``). 1821cd4fb65SAntonio Nino Diaz 1831cd4fb65SAntonio Nino DiazOnce BL31 has finished and the primary core has jumped to the BL33 payload, it 1841cd4fb65SAntonio Nino Diazhas to call ``PSCI_CPU_ON`` to release the secondary CPUs from the wait loop. 1851cd4fb65SAntonio Nino DiazThe payload then makes them wait in another waitloop listening from messages 1861cd4fb65SAntonio Nino Diazfrom the kernel. When the primary CPU jumps into the kernel, it will send an 1871cd4fb65SAntonio Nino Diazaddress to the mailbox so that the secondary CPUs jump to it and are recognised 1881cd4fb65SAntonio Nino Diazby the kernel. 1891cd4fb65SAntonio Nino Diaz 1901cd4fb65SAntonio Nino DiazBuild Instructions 1911cd4fb65SAntonio Nino Diaz------------------ 1921cd4fb65SAntonio Nino Diaz 1931cd4fb65SAntonio Nino DiazTo boot a AArch64 kernel, only the AArch64 toolchain is required. 1941cd4fb65SAntonio Nino Diaz 1951cd4fb65SAntonio Nino DiazTo boot a AArch32 kernel, both AArch64 and AArch32 toolchains are required. The 1961cd4fb65SAntonio Nino DiazAArch32 toolchain is needed for the AArch32 bootstrap needed to load a 32-bit 1971cd4fb65SAntonio Nino Diazkernel. 1981cd4fb65SAntonio Nino Diaz 19964fe343cSAntonio Nino DiazThe build system concatenates BL1 and the FIP so that the addresses match the 20064fe343cSAntonio Nino Diazones in the memory map. The resulting file is ``armstub8.bin``, located in the 2015e2e024bSAntonio Nino Diazbuild folder (e.g. ``build/rpi3/debug/armstub8.bin``). To know how to use this 2025e2e024bSAntonio Nino Diazfile, follow the instructions in `Setup SD card`_. 2031cd4fb65SAntonio Nino Diaz 2041cd4fb65SAntonio Nino DiazThe following build options are supported: 2051cd4fb65SAntonio Nino Diaz 2061cd4fb65SAntonio Nino Diaz- ``RPI3_BL33_IN_AARCH32``: This port can load a AArch64 or AArch32 BL33 image. 2074def07d5SDan Handley By default this option is 0, which means that TF-A will jump to BL33 in EL2 2084def07d5SDan Handley in AArch64 mode. If set to 1, it will jump to BL33 in Hypervisor in AArch32 2094def07d5SDan Handley mode. 2101cd4fb65SAntonio Nino Diaz 2115e2e024bSAntonio Nino Diaz- ``PRELOADED_BL33_BASE``: Used to specify the address of a BL33 binary that has 2125e2e024bSAntonio Nino Diaz been preloaded by any other system than using the firmware. ``BL33`` isn't 2135e2e024bSAntonio Nino Diaz needed in the build command line if this option is used. Specially useful 2145e2e024bSAntonio Nino Diaz because the file ``kernel8.img`` can be loaded anywhere by modifying the file 2155e2e024bSAntonio Nino Diaz ``config.txt``. It doesn't have to contain a kernel, it could have any 2165e2e024bSAntonio Nino Diaz arbitrary payload. 2175e2e024bSAntonio Nino Diaz 2185e2e024bSAntonio Nino Diaz- ``RPI3_DIRECT_LINUX_BOOT``: Disabled by default. Set to 1 to enable the direct 2195e2e024bSAntonio Nino Diaz boot of the Linux kernel from the firmware. Option ``RPI3_PRELOADED_DTB_BASE`` 2205e2e024bSAntonio Nino Diaz is mandatory when the direct Linux kernel boot is used. Options 2215e2e024bSAntonio Nino Diaz ``PRELOADED_BL33_BASE`` will most likely be needed as well because it is 2225e2e024bSAntonio Nino Diaz unlikely that the kernel image will fit in the space reserved for BL33 images. 2235e2e024bSAntonio Nino Diaz This option can be combined with ``RPI3_BL33_IN_AARCH32`` in order to boot a 2245e2e024bSAntonio Nino Diaz 32-bit kernel. The only thing this option does is to set the arguments in 2255e2e024bSAntonio Nino Diaz registers x0-x3 or r0-r2 as expected by the kernel. 2265e2e024bSAntonio Nino Diaz 2275e2e024bSAntonio Nino Diaz- ``RPI3_PRELOADED_DTB_BASE``: Auxiliary build option needed when using 2285e2e024bSAntonio Nino Diaz ``RPI3_DIRECT_LINUX_BOOT=1``. This option allows to specify the location of a 2295e2e024bSAntonio Nino Diaz DTB in memory. 2305e2e024bSAntonio Nino Diaz 2316d5c61deSPete Batard- ``RPI3_RUNTIME_UART``: Indicates whether the UART should be used at runtime 2326d5c61deSPete Batard or disabled. ``-1`` (default) disables the runtime UART. Any other value 2336d5c61deSPete Batard enables the default UART (currently UART1) for runtime messages. 2346d5c61deSPete Batard 2354dcf1fadSPete Batard- ``RPI3_USE_UEFI_MAP``: Set to 1 to build ATF with the altername memory 2364dcf1fadSPete Batard mapping required for an UEFI firmware payload. These changes are needed 2374dcf1fadSPete Batard to be able to run Windows on ARM64. This option, which is disabled by 2384dcf1fadSPete Batard default, results in the following memory mappings: 2394dcf1fadSPete Batard 2404dcf1fadSPete Batard:: 2414dcf1fadSPete Batard 2424dcf1fadSPete Batard 0x00000000 +-----------------+ 2434dcf1fadSPete Batard | ROM | BL1 2444dcf1fadSPete Batard 0x00010000 +-----------------+ 2454dcf1fadSPete Batard | DTB | (Loaded by the VideoCore) 2464dcf1fadSPete Batard 0x00020000 +-----------------+ 2474dcf1fadSPete Batard | FIP | 2484dcf1fadSPete Batard 0x00030000 +-----------------+ 2494dcf1fadSPete Batard | | 2504dcf1fadSPete Batard | UEFI PAYLOAD | 2514dcf1fadSPete Batard | | 2524dcf1fadSPete Batard 0x00200000 +-----------------+ 2534dcf1fadSPete Batard | Secure SRAM | BL2, BL31 2544dcf1fadSPete Batard 0x00300000 +-----------------+ 2554dcf1fadSPete Batard | Secure DRAM | BL32 (Secure payload) 2564dcf1fadSPete Batard 0x00400000 +-----------------+ 2574dcf1fadSPete Batard | | 2584dcf1fadSPete Batard | | 2594dcf1fadSPete Batard | Non-secure DRAM | BL33 2604dcf1fadSPete Batard | | 2614dcf1fadSPete Batard | | 2624dcf1fadSPete Batard 0x01000000 +-----------------+ 2634dcf1fadSPete Batard | | 2644dcf1fadSPete Batard | ... | 2654dcf1fadSPete Batard | | 2664dcf1fadSPete Batard 0x3F000000 +-----------------+ 2674dcf1fadSPete Batard | I/O | 2684dcf1fadSPete Batard 2693d464234SYing-Chun Liu (PaulLiu)- ``BL32``: This port can load and run OP-TEE. The OP-TEE image is optional. 2703d464234SYing-Chun Liu (PaulLiu) Please use the code from `here <https://github.com/OP-TEE/optee_os>`__. 2713d464234SYing-Chun Liu (PaulLiu) Build the Trusted Firmware with option ``BL32=tee-header_v2.bin 2723d464234SYing-Chun Liu (PaulLiu) BL32_EXTRA1=tee-pager_v2.bin BL32_EXTRA2=tee-pageable_v2.bin`` 2733d464234SYing-Chun Liu (PaulLiu) to put the binaries into the FIP. 2743d464234SYing-Chun Liu (PaulLiu) 275d35de55eSAntonio Nino Diaz Note: If OP-TEE is used it may be needed to add the following options to the 276d35de55eSAntonio Nino Diaz Linux command line so that the USB driver doesn't use FIQs: 277d35de55eSAntonio Nino Diaz ``dwc_otg.fiq_enable=0 dwc_otg.fiq_fsm_enable=0 dwc_otg.nak_holdoff=0``. 278d35de55eSAntonio Nino Diaz This will unfortunately reduce the performance of the USB driver. It is needed 279d35de55eSAntonio Nino Diaz when using Raspbian, for example. 280d35de55eSAntonio Nino Diaz 2815e2e024bSAntonio Nino Diaz- ``TRUSTED_BOARD_BOOT``: This port supports TBB. Set this option to 1 to enable 2825e2e024bSAntonio Nino Diaz it. In order to use TBB, you might want to set ``GENERATE_COT=1`` to let the 2835e2e024bSAntonio Nino Diaz contents of the FIP automatically signed by the build process. The ROT key 2845e2e024bSAntonio Nino Diaz will be generated and output to ``rot_key.pem`` in the build directory. It is 2855e2e024bSAntonio Nino Diaz able to set ROT_KEY to your own key in PEM format. Also in order to build, 2865e2e024bSAntonio Nino Diaz you need to clone mbed TLS from `here <https://github.com/ARMmbed/mbedtls>`__. 2875e2e024bSAntonio Nino Diaz ``MBEDTLS_DIR`` must point at the mbed TLS source directory. 2885e2e024bSAntonio Nino Diaz 2895e2e024bSAntonio Nino Diaz- ``ENABLE_STACK_PROTECTOR``: Disabled by default. It uses the hardware RNG of 2905e2e024bSAntonio Nino Diaz the board. 291ebbdbb1fSYing-Chun Liu (PaulLiu) 2921cd4fb65SAntonio Nino DiazThe following is not currently supported: 2931cd4fb65SAntonio Nino Diaz 2944def07d5SDan Handley- AArch32 for TF-A itself. 2951cd4fb65SAntonio Nino Diaz 2961cd4fb65SAntonio Nino Diaz- ``EL3_PAYLOAD_BASE``: The reason is that you can already load anything to any 2971cd4fb65SAntonio Nino Diaz address by changing the file ``armstub8.bin``, so there's no point in using 2984def07d5SDan Handley TF-A in this case. 2991cd4fb65SAntonio Nino Diaz 300e0f21f62SAntonio Nino Diaz- ``MULTI_CONSOLE_API=0``: The multi console API must be enabled. Note that the 301e0f21f62SAntonio Nino Diaz crash console uses the internal 16550 driver functions directly in order to be 302e0f21f62SAntonio Nino Diaz able to print error messages during early crashes before setting up the 303e0f21f62SAntonio Nino Diaz multi console API. 304e0f21f62SAntonio Nino Diaz 3055e2e024bSAntonio Nino DiazBuilding the firmware for kernels that don't support PSCI 3065e2e024bSAntonio Nino Diaz~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3075e2e024bSAntonio Nino Diaz 3085e2e024bSAntonio Nino DiazThis is the case for the 32-bit image of Raspbian, for example. 64-bit kernels 3095e2e024bSAntonio Nino Diazalways support PSCI, but they may not know that the system understands PSCI due 3105e2e024bSAntonio Nino Diazto an incorrect DTB file. 3115e2e024bSAntonio Nino Diaz 3125e2e024bSAntonio Nino DiazFirst, clone and compile the 32-bit version of the `Raspberry Pi 3 TF-A 3135e2e024bSAntonio Nino Diazbootstrap`_. Choose the one needed for the architecture of your kernel. 3145e2e024bSAntonio Nino Diaz 3155e2e024bSAntonio Nino DiazThen compile TF-A. For a 32-bit kernel, use the following command line: 3165e2e024bSAntonio Nino Diaz 3175e2e024bSAntonio Nino Diaz.. code:: shell 3185e2e024bSAntonio Nino Diaz 3195e2e024bSAntonio Nino Diaz CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 3205e2e024bSAntonio Nino Diaz RPI3_BL33_IN_AARCH32=1 \ 3215e2e024bSAntonio Nino Diaz BL33=../rpi3-arm-tf-bootstrap/aarch32/el2-bootstrap.bin 3225e2e024bSAntonio Nino Diaz 3235e2e024bSAntonio Nino DiazFor a 64-bit kernel, use this other command line: 3245e2e024bSAntonio Nino Diaz 3255e2e024bSAntonio Nino Diaz.. code:: shell 3265e2e024bSAntonio Nino Diaz 3275e2e024bSAntonio Nino Diaz CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 3285e2e024bSAntonio Nino Diaz BL33=../rpi3-arm-tf-bootstrap/aarch64/el2-bootstrap.bin 3295e2e024bSAntonio Nino Diaz 3305e2e024bSAntonio Nino DiazHowever, enabling PSCI support in a 64-bit kernel is really easy. In the 3315e2e024bSAntonio Nino Diazrepository `Raspberry Pi 3 TF-A bootstrap`_ there is a patch that can be applied 3325e2e024bSAntonio Nino Diazto the Linux kernel tree maintained by the Raspberry Pi foundation. It modifes 3335e2e024bSAntonio Nino Diazthe DTS to tell the kernel to use PSCI. Once this patch is applied, follow the 3345e2e024bSAntonio Nino Diazinstructions in `AArch64 kernel build instructions`_ to get a working 64-bit 3355e2e024bSAntonio Nino Diazkernel image and supporting files. 3365e2e024bSAntonio Nino Diaz 3375e2e024bSAntonio Nino DiazBuilding the firmware for kernels that support PSCI 3385e2e024bSAntonio Nino Diaz~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3395e2e024bSAntonio Nino Diaz 3405e2e024bSAntonio Nino DiazFor a 64-bit kernel: 3415e2e024bSAntonio Nino Diaz 3425e2e024bSAntonio Nino Diaz.. code:: shell 3435e2e024bSAntonio Nino Diaz 3445e2e024bSAntonio Nino Diaz CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 34597fb05e1SAntonio Nino Diaz PRELOADED_BL33_BASE=0x02000000 \ 34697fb05e1SAntonio Nino Diaz RPI3_PRELOADED_DTB_BASE=0x01000000 \ 3475e2e024bSAntonio Nino Diaz RPI3_DIRECT_LINUX_BOOT=1 3485e2e024bSAntonio Nino Diaz 3495e2e024bSAntonio Nino DiazFor a 32-bit kernel: 3505e2e024bSAntonio Nino Diaz 3515e2e024bSAntonio Nino Diaz.. code:: shell 3525e2e024bSAntonio Nino Diaz 3535e2e024bSAntonio Nino Diaz CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 35497fb05e1SAntonio Nino Diaz PRELOADED_BL33_BASE=0x02000000 \ 35597fb05e1SAntonio Nino Diaz RPI3_PRELOADED_DTB_BASE=0x01000000 \ 3565e2e024bSAntonio Nino Diaz RPI3_DIRECT_LINUX_BOOT=1 \ 3575e2e024bSAntonio Nino Diaz RPI3_BL33_IN_AARCH32=1 3585e2e024bSAntonio Nino Diaz 3591cd4fb65SAntonio Nino DiazAArch64 kernel build instructions 3601cd4fb65SAntonio Nino Diaz--------------------------------- 3611cd4fb65SAntonio Nino Diaz 3621cd4fb65SAntonio Nino DiazThe following instructions show how to install and run a AArch64 kernel by 3631cd4fb65SAntonio Nino Diazusing a SD card with the default `Raspbian`_ install as base. Skip them if you 3641cd4fb65SAntonio Nino Diazwant to use the default 32-bit kernel. 3651cd4fb65SAntonio Nino Diaz 3661cd4fb65SAntonio Nino DiazNote that this system won't be fully 64-bit because all the tools in the 3671cd4fb65SAntonio Nino Diazfilesystem are 32-bit binaries, but it's a quick way to get it working, and it 3681cd4fb65SAntonio Nino Diazallows the user to run 64-bit binaries in addition to 32-bit binaries. 3691cd4fb65SAntonio Nino Diaz 3701cd4fb65SAntonio Nino Diaz1. Clone the `Linux tree fork`_ maintained by the Raspberry Pi Foundation. To 3711cd4fb65SAntonio Nino Diaz speed things up, do a shallow clone of the desired branch. 3721cd4fb65SAntonio Nino Diaz 3731cd4fb65SAntonio Nino Diaz.. code:: shell 3741cd4fb65SAntonio Nino Diaz 3755e2e024bSAntonio Nino Diaz git clone --depth=1 -b rpi-4.18.y https://github.com/raspberrypi/linux 3761cd4fb65SAntonio Nino Diaz cd linux 3771cd4fb65SAntonio Nino Diaz 3781cd4fb65SAntonio Nino Diaz2. Configure and compile the kernel. Adapt the number after ``-j`` so that it is 3791cd4fb65SAntonio Nino Diaz 1.5 times the number of CPUs in your computer. This may take some time to 3801cd4fb65SAntonio Nino Diaz finish. 3811cd4fb65SAntonio Nino Diaz 3821cd4fb65SAntonio Nino Diaz.. code:: shell 3831cd4fb65SAntonio Nino Diaz 3841cd4fb65SAntonio Nino Diaz make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig 3851cd4fb65SAntonio Nino Diaz make -j 6 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- 3861cd4fb65SAntonio Nino Diaz 3871cd4fb65SAntonio Nino Diaz3. Copy the kernel image and the device tree to the SD card. Replace the path 3881cd4fb65SAntonio Nino Diaz by the corresponding path in your computers to the ``boot`` partition of the 3891cd4fb65SAntonio Nino Diaz SD card. 3901cd4fb65SAntonio Nino Diaz 3911cd4fb65SAntonio Nino Diaz.. code:: shell 3921cd4fb65SAntonio Nino Diaz 3931cd4fb65SAntonio Nino Diaz cp arch/arm64/boot/Image /path/to/boot/kernel8.img 3941cd4fb65SAntonio Nino Diaz cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b.dtb /path/to/boot/ 3955e2e024bSAntonio Nino Diaz cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b-plus.dtb /path/to/boot/ 3961cd4fb65SAntonio Nino Diaz 3971cd4fb65SAntonio Nino Diaz4. Install the kernel modules. Replace the path by the corresponding path to the 3981cd4fb65SAntonio Nino Diaz filesystem partition of the SD card on your computer. 3991cd4fb65SAntonio Nino Diaz 4001cd4fb65SAntonio Nino Diaz.. code:: shell 4011cd4fb65SAntonio Nino Diaz 4021cd4fb65SAntonio Nino Diaz make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \ 4031cd4fb65SAntonio Nino Diaz INSTALL_MOD_PATH=/path/to/filesystem modules_install 4041cd4fb65SAntonio Nino Diaz 4051cd4fb65SAntonio Nino Diaz5. Follow the instructions in `Setup SD card`_ except for the step of renaming 4061cd4fb65SAntonio Nino Diaz the existing ``kernel7.img`` (we have already copied a AArch64 kernel). 4071cd4fb65SAntonio Nino Diaz 4081cd4fb65SAntonio Nino DiazSetup SD card 4091cd4fb65SAntonio Nino Diaz------------- 4101cd4fb65SAntonio Nino Diaz 4111cd4fb65SAntonio Nino DiazThe instructions assume that you have an SD card with a fresh install of 4121cd4fb65SAntonio Nino Diaz`Raspbian`_ (or that, at least, the ``boot`` partition is untouched, or nearly 413e0f21f62SAntonio Nino Diazuntouched). They have been tested with the image available in 2018-03-13. 4141cd4fb65SAntonio Nino Diaz 4151cd4fb65SAntonio Nino Diaz1. Insert the SD card and open the ``boot`` partition. 4161cd4fb65SAntonio Nino Diaz 4171cd4fb65SAntonio Nino Diaz2. Rename ``kernel7.img`` to ``kernel8.img``. This tricks the VideoCore 4184def07d5SDan Handley bootloader into booting the Arm cores in AArch64 mode, like TF-A needs, 4194def07d5SDan Handley even though the kernel is not compiled for AArch64. 4201cd4fb65SAntonio Nino Diaz 4211cd4fb65SAntonio Nino Diaz3. Copy ``armstub8.bin`` here. When ``kernel8.img`` is available, The VideoCore 4221cd4fb65SAntonio Nino Diaz bootloader will look for a file called ``armstub8.bin`` and load it at 4231cd4fb65SAntonio Nino Diaz address **0x0** instead of a predefined one. 4241cd4fb65SAntonio Nino Diaz 4255341b42eSAntonio Nino Diaz4. To enable the serial port "Mini UART" in Linux, open ``cmdline.txt`` and add 4261cd4fb65SAntonio Nino Diaz ``console=serial0,115200 console=tty1``. 4271cd4fb65SAntonio Nino Diaz 4281cd4fb65SAntonio Nino Diaz5. Open ``config.txt`` and add the following lines at the end (``enable_uart=1`` 4291cd4fb65SAntonio Nino Diaz is only needed to enable debugging through the Mini UART): 4301cd4fb65SAntonio Nino Diaz 4311cd4fb65SAntonio Nino Diaz:: 4321cd4fb65SAntonio Nino Diaz 4331cd4fb65SAntonio Nino Diaz enable_uart=1 43497fb05e1SAntonio Nino Diaz kernel_address=0x02000000 43597fb05e1SAntonio Nino Diaz device_tree_address=0x01000000 4361cd4fb65SAntonio Nino Diaz 4371cd4fb65SAntonio Nino DiazIf you connect a serial cable to the Mini UART and your computer, and connect 4381cd4fb65SAntonio Nino Diazto it (for example, with ``screen /dev/ttyUSB0 115200``) you should see some 4391cd4fb65SAntonio Nino Diaztext. In the case of an AArch32 kernel, you should see something like this: 4401cd4fb65SAntonio Nino Diaz 4411cd4fb65SAntonio Nino Diaz:: 4421cd4fb65SAntonio Nino Diaz 4431cd4fb65SAntonio Nino Diaz NOTICE: Booting Trusted Firmware 4441cd4fb65SAntonio Nino Diaz NOTICE: BL1: v1.4(release):v1.4-329-g61e94684-dirty 4451cd4fb65SAntonio Nino Diaz NOTICE: BL1: Built : 00:09:25, Nov 6 2017 4461cd4fb65SAntonio Nino Diaz NOTICE: BL1: Booting BL2 4471cd4fb65SAntonio Nino Diaz NOTICE: BL2: v1.4(release):v1.4-329-g61e94684-dirty 4481cd4fb65SAntonio Nino Diaz NOTICE: BL2: Built : 00:09:25, Nov 6 2017 4491cd4fb65SAntonio Nino Diaz NOTICE: BL1: Booting BL31 4501cd4fb65SAntonio Nino Diaz NOTICE: BL31: v1.4(release):v1.4-329-g61e94684-dirty 4511cd4fb65SAntonio Nino Diaz NOTICE: BL31: Built : 00:09:25, Nov 6 2017 4521cd4fb65SAntonio Nino Diaz [ 0.266484] bcm2835-aux-uart 3f215040.serial: could not get clk: -517 4531cd4fb65SAntonio Nino Diaz 4541cd4fb65SAntonio Nino Diaz Raspbian GNU/Linux 9 raspberrypi ttyS0 4551cd4fb65SAntonio Nino Diaz raspberrypi login: 4561cd4fb65SAntonio Nino Diaz 4571cd4fb65SAntonio Nino DiazJust enter your credentials, everything should work as expected. Note that the 4581cd4fb65SAntonio Nino DiazHDMI output won't show any text during boot. 4591cd4fb65SAntonio Nino Diaz 4601cd4fb65SAntonio Nino Diaz.. _default Arm stub: https://github.com/raspberrypi/tools/blob/master/armstubs/armstub7.S 4611cd4fb65SAntonio Nino Diaz.. _default AArch64 stub: https://github.com/raspberrypi/tools/blob/master/armstubs/armstub8.S 4621cd4fb65SAntonio Nino Diaz.. _Linux kernel tree: https://github.com/torvalds/linux 4631cd4fb65SAntonio Nino Diaz.. _Linux tree fork: https://github.com/raspberrypi/linux 4641cd4fb65SAntonio Nino Diaz.. _Raspberry Pi 3: https://www.raspberrypi.org/products/raspberry-pi-3-model-b/ 4654def07d5SDan Handley.. _Raspberry Pi 3 TF-A bootstrap: https://github.com/AntonioND/rpi3-arm-tf-bootstrap 4661cd4fb65SAntonio Nino Diaz.. _Raspberry Pi 3 documentation: https://www.raspberrypi.org/documentation/ 4671cd4fb65SAntonio Nino Diaz.. _Raspbian: https://www.raspberrypi.org/downloads/raspbian/ 468