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