1*4def07d5SDan HandleyTrusted Firmware-A for Raspberry Pi 3 2*4def07d5SDan 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 10*4def07d5SDan HandleyArm Cortex-A53 cores, which makes it possible to have a port of Trusted 11*4def07d5SDan HandleyFirmware-A (TF-A). 121cd4fb65SAntonio Nino Diaz 13*4def07d5SDan HandleyThe following instructions explain how to use this port of the TF-A with the 14*4def07d5SDan Handleydefault distribution of `Raspbian`_ because that's the distribution officially 15*4def07d5SDan Handleysupported by the Raspberry Pi Foundation. At the moment of writing this, the 16*4def07d5SDan Handleyofficially supported kernel is a AArch32 kernel. This doesn't mean that this 17*4def07d5SDan Handleyport of TF-A can't boot a AArch64 kernel. The `Linux tree fork`_ maintained by 18*4def07d5SDan Handleythe Foundation can be compiled for AArch64 by following the steps in 19*4def07d5SDan Handley`AArch64 kernel build instructions`_. 201cd4fb65SAntonio Nino Diaz 211cd4fb65SAntonio Nino Diaz**IMPORTANT NOTE**: This port isn't secure. All of the memory used is DRAM, 221cd4fb65SAntonio Nino Diazwhich is available from both the Non-secure and Secure worlds. This port 231cd4fb65SAntonio Nino Diazshouldn't be considered more than a prototype to play with and implement 241cd4fb65SAntonio Nino Diazelements like PSCI to support the Linux kernel. 251cd4fb65SAntonio Nino Diaz 261cd4fb65SAntonio Nino DiazDesign 271cd4fb65SAntonio Nino Diaz------ 281cd4fb65SAntonio Nino Diaz 291cd4fb65SAntonio Nino DiazThe SoC used by the Raspberry Pi 3 is the Broadcom BCM2837. It is a SoC with a 301cd4fb65SAntonio Nino DiazVideoCore IV that acts as primary processor (and loads everything from the SD 311cd4fb65SAntonio Nino Diazcard) and is located between all Arm cores and the DRAM. Check the `Raspberry Pi 321cd4fb65SAntonio Nino Diaz3 documentation`_ for more information. 331cd4fb65SAntonio Nino Diaz 341cd4fb65SAntonio Nino DiazThis explains why it is possible to change the execution state (AArch64/AArch32) 351cd4fb65SAntonio Nino Diazdepending on a few files on the SD card. We only care about the cases in which 361cd4fb65SAntonio Nino Diazthe cores boot in AArch64 mode. 371cd4fb65SAntonio Nino Diaz 381cd4fb65SAntonio Nino DiazThe rules are simple: 391cd4fb65SAntonio Nino Diaz 401cd4fb65SAntonio Nino Diaz- If a file called ``kernel8.img`` is located on the ``boot`` partition of the 411cd4fb65SAntonio Nino Diaz SD card, it will load it and execute in EL2 in AArch64. Basically, it executes 421cd4fb65SAntonio Nino Diaz a `default AArch64 stub`_ at address **0x0** that jumps to the kernel. 431cd4fb65SAntonio Nino Diaz 441cd4fb65SAntonio Nino Diaz- If there is also a file called ``armstub8.bin``, it will load it at address 451cd4fb65SAntonio Nino Diaz **0x0** (instead of the default stub) and execute it in EL3 in AArch64. All 461cd4fb65SAntonio Nino Diaz the cores are powered on at the same time and start at address **0x0**. 471cd4fb65SAntonio Nino Diaz 481cd4fb65SAntonio Nino DiazThis means that we can use the default AArch32 kernel provided in the official 49*4def07d5SDan Handley`Raspbian`_ distribution by renaming it to ``kernel8.img``, while TF-A and 50*4def07d5SDan Handleyanything else we need is in ``armstub8.bin``. This way we can forget about the 51*4def07d5SDan Handleydefault bootstrap code. When using a AArch64 kernel, it is only needed to make 52*4def07d5SDan Handleysure that the name on the SD card is ``kernel8.img``. 531cd4fb65SAntonio Nino Diaz 541cd4fb65SAntonio Nino DiazIdeally, we want to load the kernel and have all cores available, which means 551cd4fb65SAntonio Nino Diazthat we need to make the secondary cores work in the way the kernel expects, as 561cd4fb65SAntonio Nino Diazexplained in `Secondary cores`_. In practice, a small bootstrap is needed 57*4def07d5SDan Handleybetween TF-A and the kernel. 581cd4fb65SAntonio Nino Diaz 591cd4fb65SAntonio Nino DiazTo get the most out of a AArch32 kernel, we want to boot it in Hypervisor mode 601cd4fb65SAntonio Nino Diazin AArch32. This means that BL33 can't be in EL2 in AArch64 mode. The 611cd4fb65SAntonio Nino Diazarchitecture specifies that AArch32 Hypervisor mode isn't present when AArch64 621cd4fb65SAntonio Nino Diazis used for EL2. When using a AArch64 kernel, it should simply start in EL2. 631cd4fb65SAntonio Nino Diaz 641cd4fb65SAntonio Nino DiazPlacement of images 651cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~~~~~~~ 661cd4fb65SAntonio Nino Diaz 671cd4fb65SAntonio Nino DiazThe file ``armstub8.bin`` contains BL1 and the FIP. It is needed to add padding 681cd4fb65SAntonio Nino Diazbetween them so that the addresses they are loaded to match the ones specified 69*4def07d5SDan Handleywhen compiling TF-A. 701cd4fb65SAntonio Nino Diaz 711cd4fb65SAntonio Nino DiazThe device tree block is loaded by the VideoCore loader from an appropriate 721cd4fb65SAntonio Nino Diazfile, but we can specify the address it is loaded to in ``config.txt``. 731cd4fb65SAntonio Nino Diaz 741cd4fb65SAntonio Nino DiazThe file ``kernel8.img`` contains a kernel image that is loaded to the address 751cd4fb65SAntonio Nino Diazspecified in ``config.txt``. The `Linux kernel tree`_ has information about how 761cd4fb65SAntonio Nino Diaza AArch32 Linux kernel image is loaded in ``Documentation/arm/Booting``: 771cd4fb65SAntonio Nino Diaz 781cd4fb65SAntonio Nino Diaz:: 791cd4fb65SAntonio Nino Diaz 801cd4fb65SAntonio Nino Diaz The zImage may also be placed in system RAM and called there. The 811cd4fb65SAntonio Nino Diaz kernel should be placed in the first 128MiB of RAM. It is recommended 821cd4fb65SAntonio Nino Diaz that it is loaded above 32MiB in order to avoid the need to relocate 831cd4fb65SAntonio Nino Diaz prior to decompression, which will make the boot process slightly 841cd4fb65SAntonio Nino Diaz faster. 851cd4fb65SAntonio Nino Diaz 861cd4fb65SAntonio Nino DiazThere are no similar restrictions for AArch64 kernels, as specified in the file 871cd4fb65SAntonio Nino Diaz``Documentation/arm64/booting.txt``. 881cd4fb65SAntonio Nino Diaz 891cd4fb65SAntonio Nino DiazThis means that we need to avoid the first 128 MiB of RAM when placing the 90*4def07d5SDan HandleyTF-A images (and specially the first 32 MiB, as they are directly used to 91*4def07d5SDan Handleyplace the uncompressed AArch32 kernel image. This way, both AArch32 and 921cd4fb65SAntonio Nino DiazAArch64 kernels can be placed at the same address. 931cd4fb65SAntonio Nino Diaz 941cd4fb65SAntonio Nino DiazIn the end, the images look like the following diagram when placed in memory. 951cd4fb65SAntonio Nino DiazAll addresses are Physical Addresses from the point of view of the Arm cores. 961cd4fb65SAntonio Nino DiazAgain, note that this is all just part of the same DRAM that goes from 971cd4fb65SAntonio Nino Diaz**0x00000000** to **0x3F000000**, it just has different names to simulate a real 981cd4fb65SAntonio Nino Diazsecure platform! 991cd4fb65SAntonio Nino Diaz 1001cd4fb65SAntonio Nino Diaz:: 1011cd4fb65SAntonio Nino Diaz 1021cd4fb65SAntonio Nino Diaz 0x00000000 +-----------------+ 1031cd4fb65SAntonio Nino Diaz | ROM | BL1 1041cd4fb65SAntonio Nino Diaz 0x00010000 +-----------------+ 1051cd4fb65SAntonio Nino Diaz | FIP | 1061cd4fb65SAntonio Nino Diaz 0x00200000 +-----------------+ 1071cd4fb65SAntonio Nino Diaz | | 1081cd4fb65SAntonio Nino Diaz | ... | 1091cd4fb65SAntonio Nino Diaz | | 1101cd4fb65SAntonio Nino Diaz 0x01000000 +-----------------+ 1111cd4fb65SAntonio Nino Diaz | Kernel | 1121cd4fb65SAntonio Nino Diaz +-----------------+ 1131cd4fb65SAntonio Nino Diaz | | 1141cd4fb65SAntonio Nino Diaz | ... | 1151cd4fb65SAntonio Nino Diaz | | 1161cd4fb65SAntonio Nino Diaz 0x02000000 +-----------------+ 1171cd4fb65SAntonio Nino Diaz | DTB | 1181cd4fb65SAntonio Nino Diaz +-----------------+ 1191cd4fb65SAntonio Nino Diaz | | 1201cd4fb65SAntonio Nino Diaz | ... | 1211cd4fb65SAntonio Nino Diaz | | 1221cd4fb65SAntonio Nino Diaz 0x10000000 +-----------------+ 1231cd4fb65SAntonio Nino Diaz | Secure SRAM | BL2, BL31 1241cd4fb65SAntonio Nino Diaz 0x10100000 +-----------------+ 1251cd4fb65SAntonio Nino Diaz | Secure DRAM | 1261cd4fb65SAntonio Nino Diaz 0x10300000 +-----------------+ 1271cd4fb65SAntonio Nino Diaz | Non-secure DRAM | BL33 1281cd4fb65SAntonio Nino Diaz 0x11000000 +-----------------+ 1291cd4fb65SAntonio Nino Diaz | | 1301cd4fb65SAntonio Nino Diaz | ... | 1311cd4fb65SAntonio Nino Diaz | | 1321cd4fb65SAntonio Nino Diaz 0x3F000000 +-----------------+ 1331cd4fb65SAntonio Nino Diaz | I/O | 1341cd4fb65SAntonio Nino Diaz 0x40000000 +-----------------+ 1351cd4fb65SAntonio Nino Diaz 1361cd4fb65SAntonio Nino DiazThe area between **0x10000000** and **0x11000000** has to be protected so that 1371cd4fb65SAntonio Nino Diazthe kernel doesn't use it. That is done by adding ``memmap=256M$16M`` to the 1381cd4fb65SAntonio Nino Diazcommand line passed to the kernel. See the `Setup SD card`_ instructions to see 1391cd4fb65SAntonio Nino Diazhow to do it. 1401cd4fb65SAntonio Nino Diaz 1411cd4fb65SAntonio Nino DiazThe last 16 MiB of DRAM can only be accessed by the VideoCore, that has 1421cd4fb65SAntonio Nino Diazdifferent mappings than the Arm cores in which the I/O addresses don't overlap 1431cd4fb65SAntonio Nino Diazthe DRAM. The memory reserved to be used by the VideoCore is always placed at 1441cd4fb65SAntonio Nino Diazthe end of the DRAM, so this space isn't wasted. 1451cd4fb65SAntonio Nino Diaz 146*4def07d5SDan HandleyConsidering the 128 MiB allocated to the GPU and the 16 MiB allocated for 147*4def07d5SDan HandleyTF-A, there are 880 MiB available for Linux. 1481cd4fb65SAntonio Nino Diaz 1491cd4fb65SAntonio Nino DiazBoot sequence 1501cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~ 1511cd4fb65SAntonio Nino Diaz 152*4def07d5SDan HandleyThe boot sequence of TF-A is the usual one except when booting an AArch32 153*4def07d5SDan Handleykernel. In that case, BL33 is booted in AArch32 Hypervisor mode so that it 154*4def07d5SDan Handleycan jump to the kernel in the same mode and let it take over that privilege 155*4def07d5SDan Handleylevel. If BL33 was running in EL2 in AArch64 (as in the default bootflow of 156*4def07d5SDan HandleyTF-A) it could only jump to the kernel in AArch32 in Supervisor mode. 1571cd4fb65SAntonio Nino Diaz 1581cd4fb65SAntonio Nino DiazThe `Linux kernel tree`_ has instructions on how to jump to the Linux kernel 1591cd4fb65SAntonio Nino Diazin ``Documentation/arm/Booting`` and ``Documentation/arm64/booting.txt``. The 1601cd4fb65SAntonio Nino Diazbootstrap should take care of this. 1611cd4fb65SAntonio Nino Diaz 1621cd4fb65SAntonio Nino DiazSecondary cores 1631cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~~~ 1641cd4fb65SAntonio Nino Diaz 1651cd4fb65SAntonio Nino DiazThe kernel used by `Raspbian`_ doesn't have support for PSCI, so it is needed to 1661cd4fb65SAntonio Nino Diazuse mailboxes to trap the secondary cores until they are ready to jump to the 1671cd4fb65SAntonio Nino Diazkernel. This mailbox is located at a different address in the AArch32 default 1681cd4fb65SAntonio Nino Diazkernel than in the AArch64 kernel. 1691cd4fb65SAntonio Nino Diaz 170*4def07d5SDan HandleyAlso, this port of TF-A has another Trusted Mailbox in Shared BL RAM. During 171*4def07d5SDan Handleycold boot, all secondary cores wait in a loop until they are given given an 172*4def07d5SDan Handleyaddress to jump to in this Mailbox (``bl31_warm_entrypoint``). 1731cd4fb65SAntonio Nino Diaz 1741cd4fb65SAntonio Nino DiazOnce BL31 has finished and the primary core has jumped to the BL33 payload, it 1751cd4fb65SAntonio Nino Diazhas to call ``PSCI_CPU_ON`` to release the secondary CPUs from the wait loop. 1761cd4fb65SAntonio Nino DiazThe payload then makes them wait in another waitloop listening from messages 1771cd4fb65SAntonio Nino Diazfrom the kernel. When the primary CPU jumps into the kernel, it will send an 1781cd4fb65SAntonio Nino Diazaddress to the mailbox so that the secondary CPUs jump to it and are recognised 1791cd4fb65SAntonio Nino Diazby the kernel. 1801cd4fb65SAntonio Nino Diaz 1811cd4fb65SAntonio Nino DiazBuild Instructions 1821cd4fb65SAntonio Nino Diaz------------------ 1831cd4fb65SAntonio Nino Diaz 1841cd4fb65SAntonio Nino DiazTo boot a AArch64 kernel, only the AArch64 toolchain is required. 1851cd4fb65SAntonio Nino Diaz 1861cd4fb65SAntonio Nino DiazTo boot a AArch32 kernel, both AArch64 and AArch32 toolchains are required. The 1871cd4fb65SAntonio Nino DiazAArch32 toolchain is needed for the AArch32 bootstrap needed to load a 32-bit 1881cd4fb65SAntonio Nino Diazkernel. 1891cd4fb65SAntonio Nino Diaz 190*4def07d5SDan HandleyFirst, clone and compile `Raspberry Pi 3 TF-A bootstrap`_. Choose the one 191*4def07d5SDan Handleyneeded for the architecture of your kernel. 1921cd4fb65SAntonio Nino Diaz 193*4def07d5SDan HandleyThen compile TF-A. For a AArch32 kernel, use the following command line: 1941cd4fb65SAntonio Nino Diaz 1951cd4fb65SAntonio Nino Diaz.. code:: shell 1961cd4fb65SAntonio Nino Diaz 1971cd4fb65SAntonio Nino Diaz CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 1981cd4fb65SAntonio Nino Diaz RPI3_BL33_IN_AARCH32=1 \ 1991cd4fb65SAntonio Nino Diaz BL33=../rpi3-arm-tf-bootstrap/aarch32/el2-bootstrap.bin \ 2001cd4fb65SAntonio Nino Diaz all fip 2011cd4fb65SAntonio Nino Diaz 2021cd4fb65SAntonio Nino DiazFor a AArch64 kernel, use this other command line: 2031cd4fb65SAntonio Nino Diaz 2041cd4fb65SAntonio Nino Diaz.. code:: shell 2051cd4fb65SAntonio Nino Diaz 2061cd4fb65SAntonio Nino Diaz CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 2071cd4fb65SAntonio Nino Diaz BL33=../rpi3-arm-tf-bootstrap/aarch64/el2-bootstrap.bin \ 2081cd4fb65SAntonio Nino Diaz all fip 2091cd4fb65SAntonio Nino Diaz 2101cd4fb65SAntonio Nino DiazThen, join BL1 and the FIP with the following instructions (replace ``release`` 2111cd4fb65SAntonio Nino Diazby ``debug`` if you set the build option ``DEBUG=1``): 2121cd4fb65SAntonio Nino Diaz 2131cd4fb65SAntonio Nino Diaz.. code:: shell 2141cd4fb65SAntonio Nino Diaz 2151cd4fb65SAntonio Nino Diaz cp build/rpi3/release/bl1.bin bl1.pad.bin 2161cd4fb65SAntonio Nino Diaz truncate --size=65536 bl1.pad.bin 2171cd4fb65SAntonio Nino Diaz cat bl1.pad.bin build/rpi3/release/fip.bin > armstub8.bin 2181cd4fb65SAntonio Nino Diaz 2191cd4fb65SAntonio Nino DiazThe resulting file, ``armstub8.bin``, contains BL1 and the FIP in the place they 220*4def07d5SDan Handleyneed to be for TF-A to boot correctly. Now, follow the instructions in 221*4def07d5SDan Handley`Setup SD card`_. 2221cd4fb65SAntonio Nino Diaz 2231cd4fb65SAntonio Nino DiazThe following build options are supported: 2241cd4fb65SAntonio Nino Diaz 2251cd4fb65SAntonio Nino Diaz- ``PRELOADED_BL33_BASE``: Specially useful because the file ``kernel8.img`` can 2261cd4fb65SAntonio Nino Diaz be loaded anywhere by modifying the file ``config.txt``. It doesn't have to 2271cd4fb65SAntonio Nino Diaz contain a kernel, it could have any arbitrary payload. 2281cd4fb65SAntonio Nino Diaz 2291cd4fb65SAntonio Nino Diaz- ``RESET_TO_BL31``: Set to 1 by default. If using a 32-bit kernel like 2301cd4fb65SAntonio Nino Diaz `Raspbian`_, the space used by BL1 can overwritten by the kernel when it is 2311cd4fb65SAntonio Nino Diaz being loaded. Even when using a AArch64 kernel the region used by 2321cd4fb65SAntonio Nino Diaz BL1 isn't protected and the kernel could overwrite it. The space used by BL31 2331cd4fb65SAntonio Nino Diaz is reserved by the command line passed to the kernel. 2341cd4fb65SAntonio Nino Diaz 2351cd4fb65SAntonio Nino Diaz- ``RPI3_BL33_IN_AARCH32``: This port can load a AArch64 or AArch32 BL33 image. 236*4def07d5SDan Handley By default this option is 0, which means that TF-A will jump to BL33 in EL2 237*4def07d5SDan Handley in AArch64 mode. If set to 1, it will jump to BL33 in Hypervisor in AArch32 238*4def07d5SDan Handley mode. 2391cd4fb65SAntonio Nino Diaz 2401cd4fb65SAntonio Nino DiazThe following is not currently supported: 2411cd4fb65SAntonio Nino Diaz 242*4def07d5SDan Handley- AArch32 for TF-A itself. 2431cd4fb65SAntonio Nino Diaz 2441cd4fb65SAntonio Nino Diaz- ``EL3_PAYLOAD_BASE``: The reason is that you can already load anything to any 2451cd4fb65SAntonio Nino Diaz address by changing the file ``armstub8.bin``, so there's no point in using 246*4def07d5SDan Handley TF-A in this case. 2471cd4fb65SAntonio Nino Diaz 2481cd4fb65SAntonio Nino Diaz- ``LOAD_IMAGE_V2=0``: Only version 2 is supported. 2491cd4fb65SAntonio Nino Diaz 2501cd4fb65SAntonio Nino DiazAArch64 kernel build instructions 2511cd4fb65SAntonio Nino Diaz--------------------------------- 2521cd4fb65SAntonio Nino Diaz 2531cd4fb65SAntonio Nino DiazThe following instructions show how to install and run a AArch64 kernel by 2541cd4fb65SAntonio Nino Diazusing a SD card with the default `Raspbian`_ install as base. Skip them if you 2551cd4fb65SAntonio Nino Diazwant to use the default 32-bit kernel. 2561cd4fb65SAntonio Nino Diaz 2571cd4fb65SAntonio Nino DiazNote that this system won't be fully 64-bit because all the tools in the 2581cd4fb65SAntonio Nino Diazfilesystem are 32-bit binaries, but it's a quick way to get it working, and it 2591cd4fb65SAntonio Nino Diazallows the user to run 64-bit binaries in addition to 32-bit binaries. 2601cd4fb65SAntonio Nino Diaz 2611cd4fb65SAntonio Nino Diaz1. Clone the `Linux tree fork`_ maintained by the Raspberry Pi Foundation. To 2621cd4fb65SAntonio Nino Diaz speed things up, do a shallow clone of the desired branch. 2631cd4fb65SAntonio Nino Diaz 2641cd4fb65SAntonio Nino Diaz.. code:: shell 2651cd4fb65SAntonio Nino Diaz 2661cd4fb65SAntonio Nino Diaz git clone --depth=1 -b rpi-4.14.y https://github.com/raspberrypi/linux 2671cd4fb65SAntonio Nino Diaz cd linux 2681cd4fb65SAntonio Nino Diaz 2691cd4fb65SAntonio Nino Diaz2. Configure and compile the kernel. Adapt the number after ``-j`` so that it is 2701cd4fb65SAntonio Nino Diaz 1.5 times the number of CPUs in your computer. This may take some time to 2711cd4fb65SAntonio Nino Diaz finish. 2721cd4fb65SAntonio Nino Diaz 2731cd4fb65SAntonio Nino Diaz.. code:: shell 2741cd4fb65SAntonio Nino Diaz 2751cd4fb65SAntonio Nino Diaz make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig 2761cd4fb65SAntonio Nino Diaz make -j 6 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- 2771cd4fb65SAntonio Nino Diaz 2781cd4fb65SAntonio Nino Diaz3. Copy the kernel image and the device tree to the SD card. Replace the path 2791cd4fb65SAntonio Nino Diaz by the corresponding path in your computers to the ``boot`` partition of the 2801cd4fb65SAntonio Nino Diaz SD card. 2811cd4fb65SAntonio Nino Diaz 2821cd4fb65SAntonio Nino Diaz.. code:: shell 2831cd4fb65SAntonio Nino Diaz 2841cd4fb65SAntonio Nino Diaz cp arch/arm64/boot/Image /path/to/boot/kernel8.img 2851cd4fb65SAntonio Nino Diaz cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b.dtb /path/to/boot/ 2861cd4fb65SAntonio Nino Diaz 2871cd4fb65SAntonio Nino Diaz4. Install the kernel modules. Replace the path by the corresponding path to the 2881cd4fb65SAntonio Nino Diaz filesystem partition of the SD card on your computer. 2891cd4fb65SAntonio Nino Diaz 2901cd4fb65SAntonio Nino Diaz.. code:: shell 2911cd4fb65SAntonio Nino Diaz 2921cd4fb65SAntonio Nino Diaz make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \ 2931cd4fb65SAntonio Nino Diaz INSTALL_MOD_PATH=/path/to/filesystem modules_install 2941cd4fb65SAntonio Nino Diaz 2951cd4fb65SAntonio Nino Diaz5. Follow the instructions in `Setup SD card`_ except for the step of renaming 2961cd4fb65SAntonio Nino Diaz the existing ``kernel7.img`` (we have already copied a AArch64 kernel). 2971cd4fb65SAntonio Nino Diaz 2981cd4fb65SAntonio Nino DiazSetup SD card 2991cd4fb65SAntonio Nino Diaz------------- 3001cd4fb65SAntonio Nino Diaz 3011cd4fb65SAntonio Nino DiazThe instructions assume that you have an SD card with a fresh install of 3021cd4fb65SAntonio Nino Diaz`Raspbian`_ (or that, at least, the ``boot`` partition is untouched, or nearly 3031cd4fb65SAntonio Nino Diazuntouched). They have been tested with the image available in 2017-09-07. 3041cd4fb65SAntonio Nino Diaz 3051cd4fb65SAntonio Nino Diaz1. Insert the SD card and open the ``boot`` partition. 3061cd4fb65SAntonio Nino Diaz 3071cd4fb65SAntonio Nino Diaz2. Rename ``kernel7.img`` to ``kernel8.img``. This tricks the VideoCore 308*4def07d5SDan Handley bootloader into booting the Arm cores in AArch64 mode, like TF-A needs, 309*4def07d5SDan Handley even though the kernel is not compiled for AArch64. 3101cd4fb65SAntonio Nino Diaz 3111cd4fb65SAntonio Nino Diaz3. Copy ``armstub8.bin`` here. When ``kernel8.img`` is available, The VideoCore 3121cd4fb65SAntonio Nino Diaz bootloader will look for a file called ``armstub8.bin`` and load it at 3131cd4fb65SAntonio Nino Diaz address **0x0** instead of a predefined one. 3141cd4fb65SAntonio Nino Diaz 3151cd4fb65SAntonio Nino Diaz4. Open ``cmdline.txt`` and add ``memmap=256M$16M`` to prevent the kernel from 316*4def07d5SDan Handley using the memory needed by TF-A. If you want to enable the serial port 317*4def07d5SDan Handley "Mini UART", make sure that this file also contains 3181cd4fb65SAntonio Nino Diaz ``console=serial0,115200 console=tty1``. 3191cd4fb65SAntonio Nino Diaz 3201cd4fb65SAntonio Nino Diaz Note that the 16 MiB reserved this way won't be available for Linux, the same 3211cd4fb65SAntonio Nino Diaz way as the memory reserved in DRAM for the GPU isn't available. 3221cd4fb65SAntonio Nino Diaz 3231cd4fb65SAntonio Nino Diaz5. Open ``config.txt`` and add the following lines at the end (``enable_uart=1`` 3241cd4fb65SAntonio Nino Diaz is only needed to enable debugging through the Mini UART): 3251cd4fb65SAntonio Nino Diaz 3261cd4fb65SAntonio Nino Diaz:: 3271cd4fb65SAntonio Nino Diaz 3281cd4fb65SAntonio Nino Diaz enable_uart=1 3291cd4fb65SAntonio Nino Diaz kernel_address=0x01000000 3301cd4fb65SAntonio Nino Diaz device_tree_address=0x02000000 3311cd4fb65SAntonio Nino Diaz 3321cd4fb65SAntonio Nino DiazIf you connect a serial cable to the Mini UART and your computer, and connect 3331cd4fb65SAntonio Nino Diazto it (for example, with ``screen /dev/ttyUSB0 115200``) you should see some 3341cd4fb65SAntonio Nino Diaztext. In the case of an AArch32 kernel, you should see something like this: 3351cd4fb65SAntonio Nino Diaz 3361cd4fb65SAntonio Nino Diaz:: 3371cd4fb65SAntonio Nino Diaz 3381cd4fb65SAntonio Nino Diaz NOTICE: Booting Trusted Firmware 3391cd4fb65SAntonio Nino Diaz NOTICE: BL1: v1.4(release):v1.4-329-g61e94684-dirty 3401cd4fb65SAntonio Nino Diaz NOTICE: BL1: Built : 00:09:25, Nov 6 2017 3411cd4fb65SAntonio Nino Diaz NOTICE: BL1: Booting BL2 3421cd4fb65SAntonio Nino Diaz NOTICE: BL2: v1.4(release):v1.4-329-g61e94684-dirty 3431cd4fb65SAntonio Nino Diaz NOTICE: BL2: Built : 00:09:25, Nov 6 2017 3441cd4fb65SAntonio Nino Diaz NOTICE: BL1: Booting BL31 3451cd4fb65SAntonio Nino Diaz NOTICE: BL31: v1.4(release):v1.4-329-g61e94684-dirty 3461cd4fb65SAntonio Nino Diaz NOTICE: BL31: Built : 00:09:25, Nov 6 2017 3471cd4fb65SAntonio Nino Diaz [ 0.266484] bcm2835-aux-uart 3f215040.serial: could not get clk: -517 3481cd4fb65SAntonio Nino Diaz 3491cd4fb65SAntonio Nino Diaz Raspbian GNU/Linux 9 raspberrypi ttyS0 3501cd4fb65SAntonio Nino Diaz raspberrypi login: 3511cd4fb65SAntonio Nino Diaz 3521cd4fb65SAntonio Nino DiazJust enter your credentials, everything should work as expected. Note that the 3531cd4fb65SAntonio Nino DiazHDMI output won't show any text during boot. 3541cd4fb65SAntonio Nino Diaz 3551cd4fb65SAntonio Nino Diaz.. _default Arm stub: https://github.com/raspberrypi/tools/blob/master/armstubs/armstub7.S 3561cd4fb65SAntonio Nino Diaz.. _default AArch64 stub: https://github.com/raspberrypi/tools/blob/master/armstubs/armstub8.S 3571cd4fb65SAntonio Nino Diaz.. _Linux kernel tree: https://github.com/torvalds/linux 3581cd4fb65SAntonio Nino Diaz.. _Linux tree fork: https://github.com/raspberrypi/linux 3591cd4fb65SAntonio Nino Diaz.. _Raspberry Pi 3: https://www.raspberrypi.org/products/raspberry-pi-3-model-b/ 360*4def07d5SDan Handley.. _Raspberry Pi 3 TF-A bootstrap: https://github.com/AntonioND/rpi3-arm-tf-bootstrap 3611cd4fb65SAntonio Nino Diaz.. _Raspberry Pi 3 documentation: https://www.raspberrypi.org/documentation/ 3621cd4fb65SAntonio Nino Diaz.. _Raspbian: https://www.raspberrypi.org/downloads/raspbian/ 363