1*54fd6939SJiyong ParkRaspberry Pi 3 2*54fd6939SJiyong Park============== 3*54fd6939SJiyong Park 4*54fd6939SJiyong ParkThe `Raspberry Pi 3`_ is an inexpensive single-board computer that contains four 5*54fd6939SJiyong ParkArm Cortex-A53 cores. 6*54fd6939SJiyong Park 7*54fd6939SJiyong ParkThe following instructions explain how to use this port of the TF-A with the 8*54fd6939SJiyong Parkdefault distribution of `Raspbian`_ because that's the distribution officially 9*54fd6939SJiyong Parksupported by the Raspberry Pi Foundation. At the moment of writing this, the 10*54fd6939SJiyong Parkofficially supported kernel is a AArch32 kernel. This doesn't mean that this 11*54fd6939SJiyong Parkport of TF-A can't boot a AArch64 kernel. The `Linux tree fork`_ maintained by 12*54fd6939SJiyong Parkthe Foundation can be compiled for AArch64 by following the steps in 13*54fd6939SJiyong Park`AArch64 kernel build instructions`_. 14*54fd6939SJiyong Park 15*54fd6939SJiyong Park**IMPORTANT NOTE**: This port isn't secure. All of the memory used is DRAM, 16*54fd6939SJiyong Parkwhich is available from both the Non-secure and Secure worlds. This port 17*54fd6939SJiyong Parkshouldn't be considered more than a prototype to play with and implement 18*54fd6939SJiyong Parkelements like PSCI to support the Linux kernel. 19*54fd6939SJiyong Park 20*54fd6939SJiyong ParkDesign 21*54fd6939SJiyong Park------ 22*54fd6939SJiyong Park 23*54fd6939SJiyong ParkThe SoC used by the Raspberry Pi 3 is the Broadcom BCM2837. It is a SoC with a 24*54fd6939SJiyong ParkVideoCore IV that acts as primary processor (and loads everything from the SD 25*54fd6939SJiyong Parkcard) and is located between all Arm cores and the DRAM. Check the `Raspberry Pi 26*54fd6939SJiyong Park3 documentation`_ for more information. 27*54fd6939SJiyong Park 28*54fd6939SJiyong ParkThis explains why it is possible to change the execution state (AArch64/AArch32) 29*54fd6939SJiyong Parkdepending on a few files on the SD card. We only care about the cases in which 30*54fd6939SJiyong Parkthe cores boot in AArch64 mode. 31*54fd6939SJiyong Park 32*54fd6939SJiyong ParkThe rules are simple: 33*54fd6939SJiyong Park 34*54fd6939SJiyong Park- If a file called ``kernel8.img`` is located on the ``boot`` partition of the 35*54fd6939SJiyong Park SD card, it will load it and execute in EL2 in AArch64. Basically, it executes 36*54fd6939SJiyong Park a `default AArch64 stub`_ at address **0x0** that jumps to the kernel. 37*54fd6939SJiyong Park 38*54fd6939SJiyong Park- If there is also a file called ``armstub8.bin``, it will load it at address 39*54fd6939SJiyong Park **0x0** (instead of the default stub) and execute it in EL3 in AArch64. All 40*54fd6939SJiyong Park the cores are powered on at the same time and start at address **0x0**. 41*54fd6939SJiyong Park 42*54fd6939SJiyong ParkThis means that we can use the default AArch32 kernel provided in the official 43*54fd6939SJiyong Park`Raspbian`_ distribution by renaming it to ``kernel8.img``, while TF-A and 44*54fd6939SJiyong Parkanything else we need is in ``armstub8.bin``. This way we can forget about the 45*54fd6939SJiyong Parkdefault bootstrap code. When using a AArch64 kernel, it is only needed to make 46*54fd6939SJiyong Parksure that the name on the SD card is ``kernel8.img``. 47*54fd6939SJiyong Park 48*54fd6939SJiyong ParkIdeally, we want to load the kernel and have all cores available, which means 49*54fd6939SJiyong Parkthat we need to make the secondary cores work in the way the kernel expects, as 50*54fd6939SJiyong Parkexplained in `Secondary cores`_. In practice, a small bootstrap is needed 51*54fd6939SJiyong Parkbetween TF-A and the kernel. 52*54fd6939SJiyong Park 53*54fd6939SJiyong ParkTo get the most out of a AArch32 kernel, we want to boot it in Hypervisor mode 54*54fd6939SJiyong Parkin AArch32. This means that BL33 can't be in EL2 in AArch64 mode. The 55*54fd6939SJiyong Parkarchitecture specifies that AArch32 Hypervisor mode isn't present when AArch64 56*54fd6939SJiyong Parkis used for EL2. When using a AArch64 kernel, it should simply start in EL2. 57*54fd6939SJiyong Park 58*54fd6939SJiyong ParkPlacement of images 59*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~ 60*54fd6939SJiyong Park 61*54fd6939SJiyong ParkThe file ``armstub8.bin`` contains BL1 and the FIP. It is needed to add padding 62*54fd6939SJiyong Parkbetween them so that the addresses they are loaded to match the ones specified 63*54fd6939SJiyong Parkwhen compiling TF-A. This is done automatically by the build system. 64*54fd6939SJiyong Park 65*54fd6939SJiyong ParkThe device tree block is loaded by the VideoCore loader from an appropriate 66*54fd6939SJiyong Parkfile, but we can specify the address it is loaded to in ``config.txt``. 67*54fd6939SJiyong Park 68*54fd6939SJiyong ParkThe file ``kernel8.img`` contains a kernel image that is loaded to the address 69*54fd6939SJiyong Parkspecified in ``config.txt``. The `Linux kernel tree`_ has information about how 70*54fd6939SJiyong Parka AArch32 Linux kernel image is loaded in ``Documentation/arm/Booting``: 71*54fd6939SJiyong Park 72*54fd6939SJiyong Park:: 73*54fd6939SJiyong Park 74*54fd6939SJiyong Park The zImage may also be placed in system RAM and called there. The 75*54fd6939SJiyong Park kernel should be placed in the first 128MiB of RAM. It is recommended 76*54fd6939SJiyong Park that it is loaded above 32MiB in order to avoid the need to relocate 77*54fd6939SJiyong Park prior to decompression, which will make the boot process slightly 78*54fd6939SJiyong Park faster. 79*54fd6939SJiyong Park 80*54fd6939SJiyong ParkThere are no similar restrictions for AArch64 kernels, as specified in the file 81*54fd6939SJiyong Park``Documentation/arm64/booting.txt``. 82*54fd6939SJiyong Park 83*54fd6939SJiyong ParkThis means that we need to avoid the first 128 MiB of RAM when placing the 84*54fd6939SJiyong ParkTF-A images (and specially the first 32 MiB, as they are directly used to 85*54fd6939SJiyong Parkplace the uncompressed AArch32 kernel image. This way, both AArch32 and 86*54fd6939SJiyong ParkAArch64 kernels can be placed at the same address. 87*54fd6939SJiyong Park 88*54fd6939SJiyong ParkIn the end, the images look like the following diagram when placed in memory. 89*54fd6939SJiyong ParkAll addresses are Physical Addresses from the point of view of the Arm cores. 90*54fd6939SJiyong ParkAgain, note that this is all just part of the same DRAM that goes from 91*54fd6939SJiyong Park**0x00000000** to **0x3F000000**, it just has different names to simulate a real 92*54fd6939SJiyong Parksecure platform! 93*54fd6939SJiyong Park 94*54fd6939SJiyong Park:: 95*54fd6939SJiyong Park 96*54fd6939SJiyong Park 0x00000000 +-----------------+ 97*54fd6939SJiyong Park | ROM | BL1 98*54fd6939SJiyong Park 0x00020000 +-----------------+ 99*54fd6939SJiyong Park | FIP | 100*54fd6939SJiyong Park 0x00200000 +-----------------+ 101*54fd6939SJiyong Park | | 102*54fd6939SJiyong Park | ... | 103*54fd6939SJiyong Park | | 104*54fd6939SJiyong Park 0x01000000 +-----------------+ 105*54fd6939SJiyong Park | DTB | (Loaded by the VideoCore) 106*54fd6939SJiyong Park +-----------------+ 107*54fd6939SJiyong Park | | 108*54fd6939SJiyong Park | ... | 109*54fd6939SJiyong Park | | 110*54fd6939SJiyong Park 0x02000000 +-----------------+ 111*54fd6939SJiyong Park | Kernel | (Loaded by the VideoCore) 112*54fd6939SJiyong Park +-----------------+ 113*54fd6939SJiyong Park | | 114*54fd6939SJiyong Park | ... | 115*54fd6939SJiyong Park | | 116*54fd6939SJiyong Park 0x10000000 +-----------------+ 117*54fd6939SJiyong Park | Secure SRAM | BL2, BL31 118*54fd6939SJiyong Park 0x10100000 +-----------------+ 119*54fd6939SJiyong Park | Secure DRAM | BL32 (Secure payload) 120*54fd6939SJiyong Park 0x11000000 +-----------------+ 121*54fd6939SJiyong Park | Non-secure DRAM | BL33 122*54fd6939SJiyong Park +-----------------+ 123*54fd6939SJiyong Park | | 124*54fd6939SJiyong Park | ... | 125*54fd6939SJiyong Park | | 126*54fd6939SJiyong Park 0x3F000000 +-----------------+ 127*54fd6939SJiyong Park | I/O | 128*54fd6939SJiyong Park 0x40000000 +-----------------+ 129*54fd6939SJiyong Park 130*54fd6939SJiyong ParkThe area between **0x10000000** and **0x11000000** has to be manually protected 131*54fd6939SJiyong Parkso that the kernel doesn't use it. The current port tries to modify the live DTB 132*54fd6939SJiyong Parkto add a memreserve region that reserves the previously mentioned area. 133*54fd6939SJiyong Park 134*54fd6939SJiyong ParkIf this is not possible, the user may manually add ``memmap=16M$256M`` to the 135*54fd6939SJiyong Parkcommand line passed to the kernel in ``cmdline.txt``. See the `Setup SD card`_ 136*54fd6939SJiyong Parkinstructions to see how to do it. This system is strongly discouraged. 137*54fd6939SJiyong Park 138*54fd6939SJiyong ParkThe last 16 MiB of DRAM can only be accessed by the VideoCore, that has 139*54fd6939SJiyong Parkdifferent mappings than the Arm cores in which the I/O addresses don't overlap 140*54fd6939SJiyong Parkthe DRAM. The memory reserved to be used by the VideoCore is always placed at 141*54fd6939SJiyong Parkthe end of the DRAM, so this space isn't wasted. 142*54fd6939SJiyong Park 143*54fd6939SJiyong ParkConsidering the 128 MiB allocated to the GPU and the 16 MiB allocated for 144*54fd6939SJiyong ParkTF-A, there are 880 MiB available for Linux. 145*54fd6939SJiyong Park 146*54fd6939SJiyong ParkBoot sequence 147*54fd6939SJiyong Park~~~~~~~~~~~~~ 148*54fd6939SJiyong Park 149*54fd6939SJiyong ParkThe boot sequence of TF-A is the usual one except when booting an AArch32 150*54fd6939SJiyong Parkkernel. In that case, BL33 is booted in AArch32 Hypervisor mode so that it 151*54fd6939SJiyong Parkcan jump to the kernel in the same mode and let it take over that privilege 152*54fd6939SJiyong Parklevel. If BL33 was running in EL2 in AArch64 (as in the default bootflow of 153*54fd6939SJiyong ParkTF-A) it could only jump to the kernel in AArch32 in Supervisor mode. 154*54fd6939SJiyong Park 155*54fd6939SJiyong ParkThe `Linux kernel tree`_ has instructions on how to jump to the Linux kernel 156*54fd6939SJiyong Parkin ``Documentation/arm/Booting`` and ``Documentation/arm64/booting.txt``. The 157*54fd6939SJiyong Parkbootstrap should take care of this. 158*54fd6939SJiyong Park 159*54fd6939SJiyong ParkThis port support a direct boot of the Linux kernel from the firmware (as a BL33 160*54fd6939SJiyong Parkimage). Alternatively, U-Boot or other bootloaders may be used. 161*54fd6939SJiyong Park 162*54fd6939SJiyong ParkSecondary cores 163*54fd6939SJiyong Park~~~~~~~~~~~~~~~ 164*54fd6939SJiyong Park 165*54fd6939SJiyong ParkThis port of the Trusted Firmware-A supports ``PSCI_CPU_ON``, 166*54fd6939SJiyong Park``PSCI_SYSTEM_RESET`` and ``PSCI_SYSTEM_OFF``. The last one doesn't really turn 167*54fd6939SJiyong Parkthe system off, it simply reboots it and asks the VideoCore firmware to keep it 168*54fd6939SJiyong Parkin a low power mode permanently. 169*54fd6939SJiyong Park 170*54fd6939SJiyong ParkThe kernel used by `Raspbian`_ doesn't have support for PSCI, so it is needed to 171*54fd6939SJiyong Parkuse mailboxes to trap the secondary cores until they are ready to jump to the 172*54fd6939SJiyong Parkkernel. This mailbox is located at a different address in the AArch32 default 173*54fd6939SJiyong Parkkernel than in the AArch64 kernel. 174*54fd6939SJiyong Park 175*54fd6939SJiyong ParkKernels with PSCI support can use the PSCI calls instead for a cleaner boot. 176*54fd6939SJiyong Park 177*54fd6939SJiyong ParkAlso, this port of TF-A has another Trusted Mailbox in Shared BL RAM. During 178*54fd6939SJiyong Parkcold boot, all secondary cores wait in a loop until they are given given an 179*54fd6939SJiyong Parkaddress to jump to in this Mailbox (``bl31_warm_entrypoint``). 180*54fd6939SJiyong Park 181*54fd6939SJiyong ParkOnce BL31 has finished and the primary core has jumped to the BL33 payload, it 182*54fd6939SJiyong Parkhas to call ``PSCI_CPU_ON`` to release the secondary CPUs from the wait loop. 183*54fd6939SJiyong ParkThe payload then makes them wait in another waitloop listening from messages 184*54fd6939SJiyong Parkfrom the kernel. When the primary CPU jumps into the kernel, it will send an 185*54fd6939SJiyong Parkaddress to the mailbox so that the secondary CPUs jump to it and are recognised 186*54fd6939SJiyong Parkby the kernel. 187*54fd6939SJiyong Park 188*54fd6939SJiyong ParkBuild Instructions 189*54fd6939SJiyong Park------------------ 190*54fd6939SJiyong Park 191*54fd6939SJiyong ParkTo boot a AArch64 kernel, only the AArch64 toolchain is required. 192*54fd6939SJiyong Park 193*54fd6939SJiyong ParkTo boot a AArch32 kernel, both AArch64 and AArch32 toolchains are required. The 194*54fd6939SJiyong ParkAArch32 toolchain is needed for the AArch32 bootstrap needed to load a 32-bit 195*54fd6939SJiyong Parkkernel. 196*54fd6939SJiyong Park 197*54fd6939SJiyong ParkThe build system concatenates BL1 and the FIP so that the addresses match the 198*54fd6939SJiyong Parkones in the memory map. The resulting file is ``armstub8.bin``, located in the 199*54fd6939SJiyong Parkbuild folder (e.g. ``build/rpi3/debug/armstub8.bin``). To know how to use this 200*54fd6939SJiyong Parkfile, follow the instructions in `Setup SD card`_. 201*54fd6939SJiyong Park 202*54fd6939SJiyong ParkThe following build options are supported: 203*54fd6939SJiyong Park 204*54fd6939SJiyong Park- ``RPI3_BL33_IN_AARCH32``: This port can load a AArch64 or AArch32 BL33 image. 205*54fd6939SJiyong Park By default this option is 0, which means that TF-A will jump to BL33 in EL2 206*54fd6939SJiyong Park in AArch64 mode. If set to 1, it will jump to BL33 in Hypervisor in AArch32 207*54fd6939SJiyong Park mode. 208*54fd6939SJiyong Park 209*54fd6939SJiyong Park- ``PRELOADED_BL33_BASE``: Used to specify the address of a BL33 binary that has 210*54fd6939SJiyong Park been preloaded by any other system than using the firmware. ``BL33`` isn't 211*54fd6939SJiyong Park needed in the build command line if this option is used. Specially useful 212*54fd6939SJiyong Park because the file ``kernel8.img`` can be loaded anywhere by modifying the file 213*54fd6939SJiyong Park ``config.txt``. It doesn't have to contain a kernel, it could have any 214*54fd6939SJiyong Park arbitrary payload. 215*54fd6939SJiyong Park 216*54fd6939SJiyong Park- ``RPI3_DIRECT_LINUX_BOOT``: Disabled by default. Set to 1 to enable the direct 217*54fd6939SJiyong Park boot of the Linux kernel from the firmware. Option ``RPI3_PRELOADED_DTB_BASE`` 218*54fd6939SJiyong Park is mandatory when the direct Linux kernel boot is used. Options 219*54fd6939SJiyong Park ``PRELOADED_BL33_BASE`` will most likely be needed as well because it is 220*54fd6939SJiyong Park unlikely that the kernel image will fit in the space reserved for BL33 images. 221*54fd6939SJiyong Park This option can be combined with ``RPI3_BL33_IN_AARCH32`` in order to boot a 222*54fd6939SJiyong Park 32-bit kernel. The only thing this option does is to set the arguments in 223*54fd6939SJiyong Park registers x0-x3 or r0-r2 as expected by the kernel. 224*54fd6939SJiyong Park 225*54fd6939SJiyong Park- ``RPI3_PRELOADED_DTB_BASE``: Auxiliary build option needed when using 226*54fd6939SJiyong Park ``RPI3_DIRECT_LINUX_BOOT=1``. This option allows to specify the location of a 227*54fd6939SJiyong Park DTB in memory. 228*54fd6939SJiyong Park 229*54fd6939SJiyong Park- ``RPI3_RUNTIME_UART``: Indicates whether the UART should be used at runtime 230*54fd6939SJiyong Park or disabled. ``-1`` (default) disables the runtime UART. Any other value 231*54fd6939SJiyong Park enables the default UART (currently UART1) for runtime messages. 232*54fd6939SJiyong Park 233*54fd6939SJiyong Park- ``RPI3_USE_UEFI_MAP``: Set to 1 to build ATF with the altername memory 234*54fd6939SJiyong Park mapping required for an UEFI firmware payload. These changes are needed 235*54fd6939SJiyong Park to be able to run Windows on ARM64. This option, which is disabled by 236*54fd6939SJiyong Park default, results in the following memory mappings: 237*54fd6939SJiyong Park 238*54fd6939SJiyong Park:: 239*54fd6939SJiyong Park 240*54fd6939SJiyong Park 0x00000000 +-----------------+ 241*54fd6939SJiyong Park | ROM | BL1 242*54fd6939SJiyong Park 0x00010000 +-----------------+ 243*54fd6939SJiyong Park | DTB | (Loaded by the VideoCore) 244*54fd6939SJiyong Park 0x00020000 +-----------------+ 245*54fd6939SJiyong Park | FIP | 246*54fd6939SJiyong Park 0x00030000 +-----------------+ 247*54fd6939SJiyong Park | | 248*54fd6939SJiyong Park | UEFI PAYLOAD | 249*54fd6939SJiyong Park | | 250*54fd6939SJiyong Park 0x00200000 +-----------------+ 251*54fd6939SJiyong Park | Secure SRAM | BL2, BL31 252*54fd6939SJiyong Park 0x00300000 +-----------------+ 253*54fd6939SJiyong Park | Secure DRAM | BL32 (Secure payload) 254*54fd6939SJiyong Park 0x00400000 +-----------------+ 255*54fd6939SJiyong Park | | 256*54fd6939SJiyong Park | | 257*54fd6939SJiyong Park | Non-secure DRAM | BL33 258*54fd6939SJiyong Park | | 259*54fd6939SJiyong Park | | 260*54fd6939SJiyong Park 0x01000000 +-----------------+ 261*54fd6939SJiyong Park | | 262*54fd6939SJiyong Park | ... | 263*54fd6939SJiyong Park | | 264*54fd6939SJiyong Park 0x3F000000 +-----------------+ 265*54fd6939SJiyong Park | I/O | 266*54fd6939SJiyong Park 267*54fd6939SJiyong Park- ``BL32``: This port can load and run OP-TEE. The OP-TEE image is optional. 268*54fd6939SJiyong Park Please use the code from `here <https://github.com/OP-TEE/optee_os>`__. 269*54fd6939SJiyong Park Build the Trusted Firmware with option ``BL32=tee-header_v2.bin 270*54fd6939SJiyong Park BL32_EXTRA1=tee-pager_v2.bin BL32_EXTRA2=tee-pageable_v2.bin`` 271*54fd6939SJiyong Park to put the binaries into the FIP. 272*54fd6939SJiyong Park 273*54fd6939SJiyong Park .. warning:: 274*54fd6939SJiyong Park If OP-TEE is used it may be needed to add the following options to the 275*54fd6939SJiyong Park Linux command line so that the USB driver doesn't use FIQs: 276*54fd6939SJiyong Park ``dwc_otg.fiq_enable=0 dwc_otg.fiq_fsm_enable=0 dwc_otg.nak_holdoff=0``. 277*54fd6939SJiyong Park This will unfortunately reduce the performance of the USB driver. It is 278*54fd6939SJiyong Park needed when using Raspbian, for example. 279*54fd6939SJiyong Park 280*54fd6939SJiyong Park- ``TRUSTED_BOARD_BOOT``: This port supports TBB. Set this option to 1 to enable 281*54fd6939SJiyong Park it. In order to use TBB, you might want to set ``GENERATE_COT=1`` to let the 282*54fd6939SJiyong Park contents of the FIP automatically signed by the build process. The ROT key 283*54fd6939SJiyong Park will be generated and output to ``rot_key.pem`` in the build directory. It is 284*54fd6939SJiyong Park able to set ROT_KEY to your own key in PEM format. Also in order to build, 285*54fd6939SJiyong Park you need to clone mbed TLS from `here <https://github.com/ARMmbed/mbedtls>`__. 286*54fd6939SJiyong Park ``MBEDTLS_DIR`` must point at the mbed TLS source directory. 287*54fd6939SJiyong Park 288*54fd6939SJiyong Park- ``ENABLE_STACK_PROTECTOR``: Disabled by default. It uses the hardware RNG of 289*54fd6939SJiyong Park the board. 290*54fd6939SJiyong Park 291*54fd6939SJiyong ParkThe following is not currently supported: 292*54fd6939SJiyong Park 293*54fd6939SJiyong Park- AArch32 for TF-A itself. 294*54fd6939SJiyong Park 295*54fd6939SJiyong Park- ``EL3_PAYLOAD_BASE``: The reason is that you can already load anything to any 296*54fd6939SJiyong Park address by changing the file ``armstub8.bin``, so there's no point in using 297*54fd6939SJiyong Park TF-A in this case. 298*54fd6939SJiyong Park 299*54fd6939SJiyong Park- ``MULTI_CONSOLE_API=0``: The multi console API must be enabled. Note that the 300*54fd6939SJiyong Park crash console uses the internal 16550 driver functions directly in order to be 301*54fd6939SJiyong Park able to print error messages during early crashes before setting up the 302*54fd6939SJiyong Park multi console API. 303*54fd6939SJiyong Park 304*54fd6939SJiyong ParkBuilding the firmware for kernels that don't support PSCI 305*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 306*54fd6939SJiyong Park 307*54fd6939SJiyong ParkThis is the case for the 32-bit image of Raspbian, for example. 64-bit kernels 308*54fd6939SJiyong Parkalways support PSCI, but they may not know that the system understands PSCI due 309*54fd6939SJiyong Parkto an incorrect DTB file. 310*54fd6939SJiyong Park 311*54fd6939SJiyong ParkFirst, clone and compile the 32-bit version of the `Raspberry Pi 3 TF-A 312*54fd6939SJiyong Parkbootstrap`_. Choose the one needed for the architecture of your kernel. 313*54fd6939SJiyong Park 314*54fd6939SJiyong ParkThen compile TF-A. For a 32-bit kernel, use the following command line: 315*54fd6939SJiyong Park 316*54fd6939SJiyong Park.. code:: shell 317*54fd6939SJiyong Park 318*54fd6939SJiyong Park CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 319*54fd6939SJiyong Park RPI3_BL33_IN_AARCH32=1 \ 320*54fd6939SJiyong Park BL33=../rpi3-arm-tf-bootstrap/aarch32/el2-bootstrap.bin 321*54fd6939SJiyong Park 322*54fd6939SJiyong ParkFor a 64-bit kernel, use this other command line: 323*54fd6939SJiyong Park 324*54fd6939SJiyong Park.. code:: shell 325*54fd6939SJiyong Park 326*54fd6939SJiyong Park CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 327*54fd6939SJiyong Park BL33=../rpi3-arm-tf-bootstrap/aarch64/el2-bootstrap.bin 328*54fd6939SJiyong Park 329*54fd6939SJiyong ParkHowever, enabling PSCI support in a 64-bit kernel is really easy. In the 330*54fd6939SJiyong Parkrepository `Raspberry Pi 3 TF-A bootstrap`_ there is a patch that can be applied 331*54fd6939SJiyong Parkto the Linux kernel tree maintained by the Raspberry Pi foundation. It modifes 332*54fd6939SJiyong Parkthe DTS to tell the kernel to use PSCI. Once this patch is applied, follow the 333*54fd6939SJiyong Parkinstructions in `AArch64 kernel build instructions`_ to get a working 64-bit 334*54fd6939SJiyong Parkkernel image and supporting files. 335*54fd6939SJiyong Park 336*54fd6939SJiyong ParkBuilding the firmware for kernels that support PSCI 337*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 338*54fd6939SJiyong Park 339*54fd6939SJiyong ParkFor a 64-bit kernel: 340*54fd6939SJiyong Park 341*54fd6939SJiyong Park.. code:: shell 342*54fd6939SJiyong Park 343*54fd6939SJiyong Park CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 344*54fd6939SJiyong Park PRELOADED_BL33_BASE=0x02000000 \ 345*54fd6939SJiyong Park RPI3_PRELOADED_DTB_BASE=0x01000000 \ 346*54fd6939SJiyong Park RPI3_DIRECT_LINUX_BOOT=1 347*54fd6939SJiyong Park 348*54fd6939SJiyong ParkFor a 32-bit kernel: 349*54fd6939SJiyong Park 350*54fd6939SJiyong Park.. code:: shell 351*54fd6939SJiyong Park 352*54fd6939SJiyong Park CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3 \ 353*54fd6939SJiyong Park PRELOADED_BL33_BASE=0x02000000 \ 354*54fd6939SJiyong Park RPI3_PRELOADED_DTB_BASE=0x01000000 \ 355*54fd6939SJiyong Park RPI3_DIRECT_LINUX_BOOT=1 \ 356*54fd6939SJiyong Park RPI3_BL33_IN_AARCH32=1 357*54fd6939SJiyong Park 358*54fd6939SJiyong ParkAArch64 kernel build instructions 359*54fd6939SJiyong Park--------------------------------- 360*54fd6939SJiyong Park 361*54fd6939SJiyong ParkThe following instructions show how to install and run a AArch64 kernel by 362*54fd6939SJiyong Parkusing a SD card with the default `Raspbian`_ install as base. Skip them if you 363*54fd6939SJiyong Parkwant to use the default 32-bit kernel. 364*54fd6939SJiyong Park 365*54fd6939SJiyong ParkNote that this system won't be fully 64-bit because all the tools in the 366*54fd6939SJiyong Parkfilesystem are 32-bit binaries, but it's a quick way to get it working, and it 367*54fd6939SJiyong Parkallows the user to run 64-bit binaries in addition to 32-bit binaries. 368*54fd6939SJiyong Park 369*54fd6939SJiyong Park1. Clone the `Linux tree fork`_ maintained by the Raspberry Pi Foundation. To 370*54fd6939SJiyong Park speed things up, do a shallow clone of the desired branch. 371*54fd6939SJiyong Park 372*54fd6939SJiyong Park.. code:: shell 373*54fd6939SJiyong Park 374*54fd6939SJiyong Park git clone --depth=1 -b rpi-4.18.y https://github.com/raspberrypi/linux 375*54fd6939SJiyong Park cd linux 376*54fd6939SJiyong Park 377*54fd6939SJiyong Park2. Configure and compile the kernel. Adapt the number after ``-j`` so that it is 378*54fd6939SJiyong Park 1.5 times the number of CPUs in your computer. This may take some time to 379*54fd6939SJiyong Park finish. 380*54fd6939SJiyong Park 381*54fd6939SJiyong Park.. code:: shell 382*54fd6939SJiyong Park 383*54fd6939SJiyong Park make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig 384*54fd6939SJiyong Park make -j 6 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- 385*54fd6939SJiyong Park 386*54fd6939SJiyong Park3. Copy the kernel image and the device tree to the SD card. Replace the path 387*54fd6939SJiyong Park by the corresponding path in your computers to the ``boot`` partition of the 388*54fd6939SJiyong Park SD card. 389*54fd6939SJiyong Park 390*54fd6939SJiyong Park.. code:: shell 391*54fd6939SJiyong Park 392*54fd6939SJiyong Park cp arch/arm64/boot/Image /path/to/boot/kernel8.img 393*54fd6939SJiyong Park cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b.dtb /path/to/boot/ 394*54fd6939SJiyong Park cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b-plus.dtb /path/to/boot/ 395*54fd6939SJiyong Park 396*54fd6939SJiyong Park4. Install the kernel modules. Replace the path by the corresponding path to the 397*54fd6939SJiyong Park filesystem partition of the SD card on your computer. 398*54fd6939SJiyong Park 399*54fd6939SJiyong Park.. code:: shell 400*54fd6939SJiyong Park 401*54fd6939SJiyong Park make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \ 402*54fd6939SJiyong Park INSTALL_MOD_PATH=/path/to/filesystem modules_install 403*54fd6939SJiyong Park 404*54fd6939SJiyong Park5. Follow the instructions in `Setup SD card`_ except for the step of renaming 405*54fd6939SJiyong Park the existing ``kernel7.img`` (we have already copied a AArch64 kernel). 406*54fd6939SJiyong Park 407*54fd6939SJiyong ParkSetup SD card 408*54fd6939SJiyong Park------------- 409*54fd6939SJiyong Park 410*54fd6939SJiyong ParkThe instructions assume that you have an SD card with a fresh install of 411*54fd6939SJiyong Park`Raspbian`_ (or that, at least, the ``boot`` partition is untouched, or nearly 412*54fd6939SJiyong Parkuntouched). They have been tested with the image available in 2018-03-13. 413*54fd6939SJiyong Park 414*54fd6939SJiyong Park1. Insert the SD card and open the ``boot`` partition. 415*54fd6939SJiyong Park 416*54fd6939SJiyong Park2. Rename ``kernel7.img`` to ``kernel8.img``. This tricks the VideoCore 417*54fd6939SJiyong Park bootloader into booting the Arm cores in AArch64 mode, like TF-A needs, 418*54fd6939SJiyong Park even though the kernel is not compiled for AArch64. 419*54fd6939SJiyong Park 420*54fd6939SJiyong Park3. Copy ``armstub8.bin`` here. When ``kernel8.img`` is available, The VideoCore 421*54fd6939SJiyong Park bootloader will look for a file called ``armstub8.bin`` and load it at 422*54fd6939SJiyong Park address **0x0** instead of a predefined one. 423*54fd6939SJiyong Park 424*54fd6939SJiyong Park4. To enable the serial port "Mini UART" in Linux, open ``cmdline.txt`` and add 425*54fd6939SJiyong Park ``console=serial0,115200 console=tty1``. 426*54fd6939SJiyong Park 427*54fd6939SJiyong Park5. Open ``config.txt`` and add the following lines at the end (``enable_uart=1`` 428*54fd6939SJiyong Park is only needed to enable debugging through the Mini UART): 429*54fd6939SJiyong Park 430*54fd6939SJiyong Park:: 431*54fd6939SJiyong Park 432*54fd6939SJiyong Park enable_uart=1 433*54fd6939SJiyong Park kernel_address=0x02000000 434*54fd6939SJiyong Park device_tree_address=0x01000000 435*54fd6939SJiyong Park 436*54fd6939SJiyong ParkIf you connect a serial cable to the Mini UART and your computer, and connect 437*54fd6939SJiyong Parkto it (for example, with ``screen /dev/ttyUSB0 115200``) you should see some 438*54fd6939SJiyong Parktext. In the case of an AArch32 kernel, you should see something like this: 439*54fd6939SJiyong Park 440*54fd6939SJiyong Park:: 441*54fd6939SJiyong Park 442*54fd6939SJiyong Park NOTICE: Booting Trusted Firmware 443*54fd6939SJiyong Park NOTICE: BL1: v1.4(release):v1.4-329-g61e94684-dirty 444*54fd6939SJiyong Park NOTICE: BL1: Built : 00:09:25, Nov 6 2017 445*54fd6939SJiyong Park NOTICE: BL1: Booting BL2 446*54fd6939SJiyong Park NOTICE: BL2: v1.4(release):v1.4-329-g61e94684-dirty 447*54fd6939SJiyong Park NOTICE: BL2: Built : 00:09:25, Nov 6 2017 448*54fd6939SJiyong Park NOTICE: BL1: Booting BL31 449*54fd6939SJiyong Park NOTICE: BL31: v1.4(release):v1.4-329-g61e94684-dirty 450*54fd6939SJiyong Park NOTICE: BL31: Built : 00:09:25, Nov 6 2017 451*54fd6939SJiyong Park [ 0.266484] bcm2835-aux-uart 3f215040.serial: could not get clk: -517 452*54fd6939SJiyong Park 453*54fd6939SJiyong Park Raspbian GNU/Linux 9 raspberrypi ttyS0 454*54fd6939SJiyong Park raspberrypi login: 455*54fd6939SJiyong Park 456*54fd6939SJiyong ParkJust enter your credentials, everything should work as expected. Note that the 457*54fd6939SJiyong ParkHDMI output won't show any text during boot. 458*54fd6939SJiyong Park 459*54fd6939SJiyong Park.. _default Arm stub: https://github.com/raspberrypi/tools/blob/master/armstubs/armstub7.S 460*54fd6939SJiyong Park.. _default AArch64 stub: https://github.com/raspberrypi/tools/blob/master/armstubs/armstub8.S 461*54fd6939SJiyong Park.. _Linux kernel tree: https://github.com/torvalds/linux 462*54fd6939SJiyong Park.. _Linux tree fork: https://github.com/raspberrypi/linux 463*54fd6939SJiyong Park.. _Raspberry Pi 3: https://www.raspberrypi.org/products/raspberry-pi-3-model-b/ 464*54fd6939SJiyong Park.. _Raspberry Pi 3 TF-A bootstrap: https://github.com/AntonioND/rpi3-arm-tf-bootstrap 465*54fd6939SJiyong Park.. _Raspberry Pi 3 documentation: https://www.raspberrypi.org/documentation/ 466*54fd6939SJiyong Park.. _Raspbian: https://www.raspberrypi.org/downloads/raspbian/ 467