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 104def07d5SDan HandleyArm Cortex-A53 cores, which makes it possible to have a port of Trusted 114def07d5SDan HandleyFirmware-A (TF-A). 121cd4fb65SAntonio Nino Diaz 134def07d5SDan HandleyThe following instructions explain how to use this port of the TF-A with the 144def07d5SDan Handleydefault distribution of `Raspbian`_ because that's the distribution officially 154def07d5SDan Handleysupported by the Raspberry Pi Foundation. At the moment of writing this, the 164def07d5SDan Handleyofficially supported kernel is a AArch32 kernel. This doesn't mean that this 174def07d5SDan Handleyport of TF-A can't boot a AArch64 kernel. The `Linux tree fork`_ maintained by 184def07d5SDan Handleythe Foundation can be compiled for AArch64 by following the steps in 194def07d5SDan 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 494def07d5SDan Handley`Raspbian`_ distribution by renaming it to ``kernel8.img``, while TF-A and 504def07d5SDan Handleyanything else we need is in ``armstub8.bin``. This way we can forget about the 514def07d5SDan Handleydefault bootstrap code. When using a AArch64 kernel, it is only needed to make 524def07d5SDan 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 574def07d5SDan 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 694def07d5SDan 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 904def07d5SDan HandleyTF-A images (and specially the first 32 MiB, as they are directly used to 914def07d5SDan 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 1046a2c3c7fSYing-Chun Liu (PaulLiu) 0x00020000 +-----------------+ 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 +-----------------+ 1253d464234SYing-Chun Liu (PaulLiu) | Secure DRAM | BL32 (Secure payload) 1268ebf806fSYing-Chun Liu (PaulLiu) 0x10C00000 +-----------------+ 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 1372d8f831fSAntonio Nino Diazthe kernel doesn't use it. That is done by adding ``memmap=16M$256M`` 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 1464def07d5SDan HandleyConsidering the 128 MiB allocated to the GPU and the 16 MiB allocated for 1474def07d5SDan HandleyTF-A, there are 880 MiB available for Linux. 1481cd4fb65SAntonio Nino Diaz 1491cd4fb65SAntonio Nino DiazBoot sequence 1501cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~ 1511cd4fb65SAntonio Nino Diaz 1524def07d5SDan HandleyThe boot sequence of TF-A is the usual one except when booting an AArch32 1534def07d5SDan Handleykernel. In that case, BL33 is booted in AArch32 Hypervisor mode so that it 1544def07d5SDan Handleycan jump to the kernel in the same mode and let it take over that privilege 1554def07d5SDan Handleylevel. If BL33 was running in EL2 in AArch64 (as in the default bootflow of 1564def07d5SDan 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 1704def07d5SDan HandleyAlso, this port of TF-A has another Trusted Mailbox in Shared BL RAM. During 1714def07d5SDan Handleycold boot, all secondary cores wait in a loop until they are given given an 1724def07d5SDan 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 1904def07d5SDan HandleyFirst, clone and compile `Raspberry Pi 3 TF-A bootstrap`_. Choose the one 1914def07d5SDan Handleyneeded for the architecture of your kernel. 1921cd4fb65SAntonio Nino Diaz 1934def07d5SDan 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 \ 199*64fe343cSAntonio Nino Diaz BL33=../rpi3-arm-tf-bootstrap/aarch32/el2-bootstrap.bin 2001cd4fb65SAntonio Nino Diaz 2011cd4fb65SAntonio Nino DiazFor a AArch64 kernel, use this other command line: 2021cd4fb65SAntonio Nino Diaz 2031cd4fb65SAntonio Nino Diaz.. code:: shell 2041cd4fb65SAntonio Nino Diaz 2051cd4fb65SAntonio Nino Diaz CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 206*64fe343cSAntonio Nino Diaz BL33=../rpi3-arm-tf-bootstrap/aarch64/el2-bootstrap.bin 2071cd4fb65SAntonio Nino Diaz 208*64fe343cSAntonio Nino DiazThe build system concatenates BL1 and the FIP so that the addresses match the 209*64fe343cSAntonio Nino Diazones in the memory map. The resulting file is ``armstub8.bin``, located in the 210*64fe343cSAntonio Nino Diazbuild folder (e.g. ``build/rpi3/debug/armstub8.bin``). Now, follow the 211*64fe343cSAntonio Nino Diazinstructions in `Setup SD card`_. 2121cd4fb65SAntonio Nino Diaz 2131cd4fb65SAntonio Nino DiazThe following build options are supported: 2141cd4fb65SAntonio Nino Diaz 2151cd4fb65SAntonio Nino Diaz- ``PRELOADED_BL33_BASE``: Specially useful because the file ``kernel8.img`` can 2161cd4fb65SAntonio Nino Diaz be loaded anywhere by modifying the file ``config.txt``. It doesn't have to 2171cd4fb65SAntonio Nino Diaz contain a kernel, it could have any arbitrary payload. 2181cd4fb65SAntonio Nino Diaz 2191cd4fb65SAntonio Nino Diaz- ``RESET_TO_BL31``: Set to 1 by default. If using a 32-bit kernel like 2201cd4fb65SAntonio Nino Diaz `Raspbian`_, the space used by BL1 can overwritten by the kernel when it is 2211cd4fb65SAntonio Nino Diaz being loaded. Even when using a AArch64 kernel the region used by 2221cd4fb65SAntonio Nino Diaz BL1 isn't protected and the kernel could overwrite it. The space used by BL31 2231cd4fb65SAntonio Nino Diaz is reserved by the command line passed to the kernel. 2241cd4fb65SAntonio Nino Diaz 2251cd4fb65SAntonio Nino Diaz- ``RPI3_BL33_IN_AARCH32``: This port can load a AArch64 or AArch32 BL33 image. 2264def07d5SDan Handley By default this option is 0, which means that TF-A will jump to BL33 in EL2 2274def07d5SDan Handley in AArch64 mode. If set to 1, it will jump to BL33 in Hypervisor in AArch32 2284def07d5SDan Handley mode. 2291cd4fb65SAntonio Nino Diaz 2303d464234SYing-Chun Liu (PaulLiu)- ``BL32``: This port can load and run OP-TEE. The OP-TEE image is optional. 2313d464234SYing-Chun Liu (PaulLiu) Please use the code from `here <https://github.com/OP-TEE/optee_os>`__. 2323d464234SYing-Chun Liu (PaulLiu) Build the Trusted Firmware with option ``BL32=tee-header_v2.bin 2333d464234SYing-Chun Liu (PaulLiu) BL32_EXTRA1=tee-pager_v2.bin BL32_EXTRA2=tee-pageable_v2.bin`` 2343d464234SYing-Chun Liu (PaulLiu) to put the binaries into the FIP. 2353d464234SYing-Chun Liu (PaulLiu) 236d35de55eSAntonio Nino Diaz Note: If OP-TEE is used it may be needed to add the following options to the 237d35de55eSAntonio Nino Diaz Linux command line so that the USB driver doesn't use FIQs: 238d35de55eSAntonio Nino Diaz ``dwc_otg.fiq_enable=0 dwc_otg.fiq_fsm_enable=0 dwc_otg.nak_holdoff=0``. 239d35de55eSAntonio Nino Diaz This will unfortunately reduce the performance of the USB driver. It is needed 240d35de55eSAntonio Nino Diaz when using Raspbian, for example. 241d35de55eSAntonio Nino Diaz 242ebbdbb1fSYing-Chun Liu (PaulLiu)- ``TRUSTED_BOARD_BOOT``: This port supports TBB. Set this option 243ebbdbb1fSYing-Chun Liu (PaulLiu) ``TRUSTED_BOARD_BOOT=1`` to enable it. In order to use TBB, you might 244ebbdbb1fSYing-Chun Liu (PaulLiu) want to set ``GENERATE_COT=1`` to let the contents of the FIP automatically 245ebbdbb1fSYing-Chun Liu (PaulLiu) signed by the build process. The ROT key will be generated and output to 246ebbdbb1fSYing-Chun Liu (PaulLiu) ``rot_key.pem`` in the build directory. It is able to set ROT_KEY to 247ebbdbb1fSYing-Chun Liu (PaulLiu) your own key in PEM format. 248ebbdbb1fSYing-Chun Liu (PaulLiu) Also in order to build, you need to clone mbedtls from 249ebbdbb1fSYing-Chun Liu (PaulLiu) `here <https://github.com/ARMmbed/mbedtls>`__. 250ebbdbb1fSYing-Chun Liu (PaulLiu) And set MBEDTLS_DIR to mbedtls source directory. 251ebbdbb1fSYing-Chun Liu (PaulLiu) 2521cd4fb65SAntonio Nino DiazThe following is not currently supported: 2531cd4fb65SAntonio Nino Diaz 2544def07d5SDan Handley- AArch32 for TF-A itself. 2551cd4fb65SAntonio Nino Diaz 2561cd4fb65SAntonio Nino Diaz- ``EL3_PAYLOAD_BASE``: The reason is that you can already load anything to any 2571cd4fb65SAntonio Nino Diaz address by changing the file ``armstub8.bin``, so there's no point in using 2584def07d5SDan Handley TF-A in this case. 2591cd4fb65SAntonio Nino Diaz 2601cd4fb65SAntonio Nino Diaz- ``LOAD_IMAGE_V2=0``: Only version 2 is supported. 2611cd4fb65SAntonio Nino Diaz 262e0f21f62SAntonio Nino Diaz- ``MULTI_CONSOLE_API=0``: The multi console API must be enabled. Note that the 263e0f21f62SAntonio Nino Diaz crash console uses the internal 16550 driver functions directly in order to be 264e0f21f62SAntonio Nino Diaz able to print error messages during early crashes before setting up the 265e0f21f62SAntonio Nino Diaz multi console API. 266e0f21f62SAntonio Nino Diaz 2671cd4fb65SAntonio Nino DiazAArch64 kernel build instructions 2681cd4fb65SAntonio Nino Diaz--------------------------------- 2691cd4fb65SAntonio Nino Diaz 2701cd4fb65SAntonio Nino DiazThe following instructions show how to install and run a AArch64 kernel by 2711cd4fb65SAntonio Nino Diazusing a SD card with the default `Raspbian`_ install as base. Skip them if you 2721cd4fb65SAntonio Nino Diazwant to use the default 32-bit kernel. 2731cd4fb65SAntonio Nino Diaz 2741cd4fb65SAntonio Nino DiazNote that this system won't be fully 64-bit because all the tools in the 2751cd4fb65SAntonio Nino Diazfilesystem are 32-bit binaries, but it's a quick way to get it working, and it 2761cd4fb65SAntonio Nino Diazallows the user to run 64-bit binaries in addition to 32-bit binaries. 2771cd4fb65SAntonio Nino Diaz 2781cd4fb65SAntonio Nino Diaz1. Clone the `Linux tree fork`_ maintained by the Raspberry Pi Foundation. To 2791cd4fb65SAntonio Nino Diaz speed things up, do a shallow clone of the desired branch. 2801cd4fb65SAntonio Nino Diaz 2811cd4fb65SAntonio Nino Diaz.. code:: shell 2821cd4fb65SAntonio Nino Diaz 2831cd4fb65SAntonio Nino Diaz git clone --depth=1 -b rpi-4.14.y https://github.com/raspberrypi/linux 2841cd4fb65SAntonio Nino Diaz cd linux 2851cd4fb65SAntonio Nino Diaz 2861cd4fb65SAntonio Nino Diaz2. Configure and compile the kernel. Adapt the number after ``-j`` so that it is 2871cd4fb65SAntonio Nino Diaz 1.5 times the number of CPUs in your computer. This may take some time to 2881cd4fb65SAntonio Nino Diaz finish. 2891cd4fb65SAntonio Nino Diaz 2901cd4fb65SAntonio Nino Diaz.. code:: shell 2911cd4fb65SAntonio Nino Diaz 2921cd4fb65SAntonio Nino Diaz make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig 2931cd4fb65SAntonio Nino Diaz make -j 6 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- 2941cd4fb65SAntonio Nino Diaz 2951cd4fb65SAntonio Nino Diaz3. Copy the kernel image and the device tree to the SD card. Replace the path 2961cd4fb65SAntonio Nino Diaz by the corresponding path in your computers to the ``boot`` partition of the 2971cd4fb65SAntonio Nino Diaz SD card. 2981cd4fb65SAntonio Nino Diaz 2991cd4fb65SAntonio Nino Diaz.. code:: shell 3001cd4fb65SAntonio Nino Diaz 3011cd4fb65SAntonio Nino Diaz cp arch/arm64/boot/Image /path/to/boot/kernel8.img 3021cd4fb65SAntonio Nino Diaz cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b.dtb /path/to/boot/ 3031cd4fb65SAntonio Nino Diaz 3041cd4fb65SAntonio Nino Diaz4. Install the kernel modules. Replace the path by the corresponding path to the 3051cd4fb65SAntonio Nino Diaz filesystem partition of the SD card on your computer. 3061cd4fb65SAntonio Nino Diaz 3071cd4fb65SAntonio Nino Diaz.. code:: shell 3081cd4fb65SAntonio Nino Diaz 3091cd4fb65SAntonio Nino Diaz make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \ 3101cd4fb65SAntonio Nino Diaz INSTALL_MOD_PATH=/path/to/filesystem modules_install 3111cd4fb65SAntonio Nino Diaz 3121cd4fb65SAntonio Nino Diaz5. Follow the instructions in `Setup SD card`_ except for the step of renaming 3131cd4fb65SAntonio Nino Diaz the existing ``kernel7.img`` (we have already copied a AArch64 kernel). 3141cd4fb65SAntonio Nino Diaz 3151cd4fb65SAntonio Nino DiazSetup SD card 3161cd4fb65SAntonio Nino Diaz------------- 3171cd4fb65SAntonio Nino Diaz 3181cd4fb65SAntonio Nino DiazThe instructions assume that you have an SD card with a fresh install of 3191cd4fb65SAntonio Nino Diaz`Raspbian`_ (or that, at least, the ``boot`` partition is untouched, or nearly 320e0f21f62SAntonio Nino Diazuntouched). They have been tested with the image available in 2018-03-13. 3211cd4fb65SAntonio Nino Diaz 3221cd4fb65SAntonio Nino Diaz1. Insert the SD card and open the ``boot`` partition. 3231cd4fb65SAntonio Nino Diaz 3241cd4fb65SAntonio Nino Diaz2. Rename ``kernel7.img`` to ``kernel8.img``. This tricks the VideoCore 3254def07d5SDan Handley bootloader into booting the Arm cores in AArch64 mode, like TF-A needs, 3264def07d5SDan Handley even though the kernel is not compiled for AArch64. 3271cd4fb65SAntonio Nino Diaz 3281cd4fb65SAntonio Nino Diaz3. Copy ``armstub8.bin`` here. When ``kernel8.img`` is available, The VideoCore 3291cd4fb65SAntonio Nino Diaz bootloader will look for a file called ``armstub8.bin`` and load it at 3301cd4fb65SAntonio Nino Diaz address **0x0** instead of a predefined one. 3311cd4fb65SAntonio Nino Diaz 3322d8f831fSAntonio Nino Diaz4. Open ``cmdline.txt`` and add ``memmap=16M$256M`` to prevent the kernel from 3334def07d5SDan Handley using the memory needed by TF-A. If you want to enable the serial port 3344def07d5SDan Handley "Mini UART", make sure that this file also contains 3351cd4fb65SAntonio Nino Diaz ``console=serial0,115200 console=tty1``. 3361cd4fb65SAntonio Nino Diaz 3371cd4fb65SAntonio Nino Diaz Note that the 16 MiB reserved this way won't be available for Linux, the same 3381cd4fb65SAntonio Nino Diaz way as the memory reserved in DRAM for the GPU isn't available. 3391cd4fb65SAntonio Nino Diaz 3401cd4fb65SAntonio Nino Diaz5. Open ``config.txt`` and add the following lines at the end (``enable_uart=1`` 3411cd4fb65SAntonio Nino Diaz is only needed to enable debugging through the Mini UART): 3421cd4fb65SAntonio Nino Diaz 3431cd4fb65SAntonio Nino Diaz:: 3441cd4fb65SAntonio Nino Diaz 3451cd4fb65SAntonio Nino Diaz enable_uart=1 3461cd4fb65SAntonio Nino Diaz kernel_address=0x01000000 3471cd4fb65SAntonio Nino Diaz device_tree_address=0x02000000 3481cd4fb65SAntonio Nino Diaz 3491cd4fb65SAntonio Nino DiazIf you connect a serial cable to the Mini UART and your computer, and connect 3501cd4fb65SAntonio Nino Diazto it (for example, with ``screen /dev/ttyUSB0 115200``) you should see some 3511cd4fb65SAntonio Nino Diaztext. In the case of an AArch32 kernel, you should see something like this: 3521cd4fb65SAntonio Nino Diaz 3531cd4fb65SAntonio Nino Diaz:: 3541cd4fb65SAntonio Nino Diaz 3551cd4fb65SAntonio Nino Diaz NOTICE: Booting Trusted Firmware 3561cd4fb65SAntonio Nino Diaz NOTICE: BL1: v1.4(release):v1.4-329-g61e94684-dirty 3571cd4fb65SAntonio Nino Diaz NOTICE: BL1: Built : 00:09:25, Nov 6 2017 3581cd4fb65SAntonio Nino Diaz NOTICE: BL1: Booting BL2 3591cd4fb65SAntonio Nino Diaz NOTICE: BL2: v1.4(release):v1.4-329-g61e94684-dirty 3601cd4fb65SAntonio Nino Diaz NOTICE: BL2: Built : 00:09:25, Nov 6 2017 3611cd4fb65SAntonio Nino Diaz NOTICE: BL1: Booting BL31 3621cd4fb65SAntonio Nino Diaz NOTICE: BL31: v1.4(release):v1.4-329-g61e94684-dirty 3631cd4fb65SAntonio Nino Diaz NOTICE: BL31: Built : 00:09:25, Nov 6 2017 3641cd4fb65SAntonio Nino Diaz [ 0.266484] bcm2835-aux-uart 3f215040.serial: could not get clk: -517 3651cd4fb65SAntonio Nino Diaz 3661cd4fb65SAntonio Nino Diaz Raspbian GNU/Linux 9 raspberrypi ttyS0 3671cd4fb65SAntonio Nino Diaz raspberrypi login: 3681cd4fb65SAntonio Nino Diaz 3691cd4fb65SAntonio Nino DiazJust enter your credentials, everything should work as expected. Note that the 3701cd4fb65SAntonio Nino DiazHDMI output won't show any text during boot. 3711cd4fb65SAntonio Nino Diaz 3721cd4fb65SAntonio Nino Diaz.. _default Arm stub: https://github.com/raspberrypi/tools/blob/master/armstubs/armstub7.S 3731cd4fb65SAntonio Nino Diaz.. _default AArch64 stub: https://github.com/raspberrypi/tools/blob/master/armstubs/armstub8.S 3741cd4fb65SAntonio Nino Diaz.. _Linux kernel tree: https://github.com/torvalds/linux 3751cd4fb65SAntonio Nino Diaz.. _Linux tree fork: https://github.com/raspberrypi/linux 3761cd4fb65SAntonio Nino Diaz.. _Raspberry Pi 3: https://www.raspberrypi.org/products/raspberry-pi-3-model-b/ 3774def07d5SDan Handley.. _Raspberry Pi 3 TF-A bootstrap: https://github.com/AntonioND/rpi3-arm-tf-bootstrap 3781cd4fb65SAntonio Nino Diaz.. _Raspberry Pi 3 documentation: https://www.raspberrypi.org/documentation/ 3791cd4fb65SAntonio Nino Diaz.. _Raspbian: https://www.raspberrypi.org/downloads/raspbian/ 380