xref: /rk3399_ARM-atf/docs/plat/rpi3.rst (revision 1cd4fb650e698b6f68eea9046421d354a29d6e0e)
1*1cd4fb65SAntonio Nino DiazArm Trusted Firmware for Raspberry Pi 3
2*1cd4fb65SAntonio Nino Diaz=======================================
3*1cd4fb65SAntonio Nino Diaz
4*1cd4fb65SAntonio Nino Diaz.. section-numbering::
5*1cd4fb65SAntonio Nino Diaz    :suffix: .
6*1cd4fb65SAntonio Nino Diaz
7*1cd4fb65SAntonio Nino Diaz.. contents::
8*1cd4fb65SAntonio Nino Diaz
9*1cd4fb65SAntonio Nino DiazThe `Raspberry Pi 3`_ is an inexpensive single-board computer that contains four
10*1cd4fb65SAntonio Nino DiazCortex-A53 cores, which makes it possible to have a port of the Arm Trusted
11*1cd4fb65SAntonio Nino DiazFirmware.
12*1cd4fb65SAntonio Nino Diaz
13*1cd4fb65SAntonio Nino DiazThe following instructions explain how to use this port of the Trusted Firmware
14*1cd4fb65SAntonio Nino Diazwith the default distribution of `Raspbian`_ because that's the distribution
15*1cd4fb65SAntonio Nino Diazofficially supported by the Raspberry Pi Foundation. At the moment of writing
16*1cd4fb65SAntonio Nino Diazthis, the officially supported kernel is a AArch32 kernel. This doesn't mean
17*1cd4fb65SAntonio Nino Diazthat this port of the Trusted Firmware can't boot a AArch64 kernel. The `Linux
18*1cd4fb65SAntonio Nino Diaztree fork`_ maintained by the Foundation can be compiled for AArch64 by
19*1cd4fb65SAntonio Nino Diazfollowing the steps in `AArch64 kernel build instructions`_.
20*1cd4fb65SAntonio Nino Diaz
21*1cd4fb65SAntonio Nino Diaz**IMPORTANT NOTE**: This port isn't secure. All of the memory used is DRAM,
22*1cd4fb65SAntonio Nino Diazwhich is available from both the Non-secure and Secure worlds. This port
23*1cd4fb65SAntonio Nino Diazshouldn't be considered more than a prototype to play with and implement
24*1cd4fb65SAntonio Nino Diazelements like PSCI to support the Linux kernel.
25*1cd4fb65SAntonio Nino Diaz
26*1cd4fb65SAntonio Nino DiazDesign
27*1cd4fb65SAntonio Nino Diaz------
28*1cd4fb65SAntonio Nino Diaz
29*1cd4fb65SAntonio Nino DiazThe SoC used by the Raspberry Pi 3 is the Broadcom BCM2837. It is a SoC with a
30*1cd4fb65SAntonio Nino DiazVideoCore IV that acts as primary processor (and loads everything from the SD
31*1cd4fb65SAntonio Nino Diazcard) and is located between all Arm cores and the DRAM. Check the `Raspberry Pi
32*1cd4fb65SAntonio Nino Diaz3 documentation`_ for more information.
33*1cd4fb65SAntonio Nino Diaz
34*1cd4fb65SAntonio Nino DiazThis explains why it is possible to change the execution state (AArch64/AArch32)
35*1cd4fb65SAntonio Nino Diazdepending on a few files on the SD card. We only care about the cases in which
36*1cd4fb65SAntonio Nino Diazthe cores boot in AArch64 mode.
37*1cd4fb65SAntonio Nino Diaz
38*1cd4fb65SAntonio Nino DiazThe rules are simple:
39*1cd4fb65SAntonio Nino Diaz
40*1cd4fb65SAntonio Nino Diaz- If a file called ``kernel8.img`` is located on the ``boot`` partition of the
41*1cd4fb65SAntonio Nino Diaz  SD card, it will load it and execute in EL2 in AArch64. Basically, it executes
42*1cd4fb65SAntonio Nino Diaz  a `default AArch64 stub`_ at address **0x0** that jumps to the kernel.
43*1cd4fb65SAntonio Nino Diaz
44*1cd4fb65SAntonio Nino Diaz- If there is also a file called ``armstub8.bin``, it will load it at address
45*1cd4fb65SAntonio Nino Diaz  **0x0** (instead of the default stub) and execute it in EL3 in AArch64. All
46*1cd4fb65SAntonio Nino Diaz  the cores are powered on at the same time and start at address **0x0**.
47*1cd4fb65SAntonio Nino Diaz
48*1cd4fb65SAntonio Nino DiazThis means that we can use the default AArch32 kernel provided in the official
49*1cd4fb65SAntonio Nino Diaz`Raspbian`_ distribution by renaming it to ``kernel8.img``, while the Trusted
50*1cd4fb65SAntonio Nino DiazFirmware and anything else we need is in ``armstub8.bin``. This way we can
51*1cd4fb65SAntonio Nino Diazforget about the default bootstrap code. When using a AArch64 kernel, it is only
52*1cd4fb65SAntonio Nino Diazneeded to make sure that the name on the SD card is ``kernel8.img``.
53*1cd4fb65SAntonio Nino Diaz
54*1cd4fb65SAntonio Nino DiazIdeally, we want to load the kernel and have all cores available, which means
55*1cd4fb65SAntonio Nino Diazthat we need to make the secondary cores work in the way the kernel expects, as
56*1cd4fb65SAntonio Nino Diazexplained in `Secondary cores`_. In practice, a small bootstrap is needed
57*1cd4fb65SAntonio Nino Diazbetween the Trusted Firmware and the kernel.
58*1cd4fb65SAntonio Nino Diaz
59*1cd4fb65SAntonio Nino DiazTo get the most out of a AArch32 kernel, we want to boot it in Hypervisor mode
60*1cd4fb65SAntonio Nino Diazin AArch32. This means that BL33 can't be in EL2 in AArch64 mode. The
61*1cd4fb65SAntonio Nino Diazarchitecture specifies that AArch32 Hypervisor mode isn't present when AArch64
62*1cd4fb65SAntonio Nino Diazis used for EL2. When using a AArch64 kernel, it should simply start in EL2.
63*1cd4fb65SAntonio Nino Diaz
64*1cd4fb65SAntonio Nino DiazPlacement of images
65*1cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~~~~~~~
66*1cd4fb65SAntonio Nino Diaz
67*1cd4fb65SAntonio Nino DiazThe file ``armstub8.bin`` contains BL1 and the FIP. It is needed to add padding
68*1cd4fb65SAntonio Nino Diazbetween them so that the addresses they are loaded to match the ones specified
69*1cd4fb65SAntonio Nino Diazwhen compiling the Trusted Firmware.
70*1cd4fb65SAntonio Nino Diaz
71*1cd4fb65SAntonio Nino DiazThe device tree block is loaded by the VideoCore loader from an appropriate
72*1cd4fb65SAntonio Nino Diazfile, but we can specify the address it is loaded to in ``config.txt``.
73*1cd4fb65SAntonio Nino Diaz
74*1cd4fb65SAntonio Nino DiazThe file ``kernel8.img`` contains a kernel image that is loaded to the address
75*1cd4fb65SAntonio Nino Diazspecified in ``config.txt``. The `Linux kernel tree`_ has information about how
76*1cd4fb65SAntonio Nino Diaza AArch32 Linux kernel image is loaded in ``Documentation/arm/Booting``:
77*1cd4fb65SAntonio Nino Diaz
78*1cd4fb65SAntonio Nino Diaz::
79*1cd4fb65SAntonio Nino Diaz
80*1cd4fb65SAntonio Nino Diaz    The zImage may also be placed in system RAM and called there.  The
81*1cd4fb65SAntonio Nino Diaz    kernel should be placed in the first 128MiB of RAM.  It is recommended
82*1cd4fb65SAntonio Nino Diaz    that it is loaded above 32MiB in order to avoid the need to relocate
83*1cd4fb65SAntonio Nino Diaz    prior to decompression, which will make the boot process slightly
84*1cd4fb65SAntonio Nino Diaz    faster.
85*1cd4fb65SAntonio Nino Diaz
86*1cd4fb65SAntonio Nino DiazThere are no similar restrictions for AArch64 kernels, as specified in the file
87*1cd4fb65SAntonio Nino Diaz``Documentation/arm64/booting.txt``.
88*1cd4fb65SAntonio Nino Diaz
89*1cd4fb65SAntonio Nino DiazThis means that we need to avoid the first 128 MiB of RAM when placing the
90*1cd4fb65SAntonio Nino DiazTrusted Firmware images (and specially the first 32 MiB, as they are directly
91*1cd4fb65SAntonio Nino Diazused to place the uncompressed AArch32 kernel image. This way, both AArch32 and
92*1cd4fb65SAntonio Nino DiazAArch64 kernels can be placed at the same address.
93*1cd4fb65SAntonio Nino Diaz
94*1cd4fb65SAntonio Nino DiazIn the end, the images look like the following diagram when placed in memory.
95*1cd4fb65SAntonio Nino DiazAll addresses are Physical Addresses from the point of view of the Arm cores.
96*1cd4fb65SAntonio Nino DiazAgain, note that this is all just part of the same DRAM that goes from
97*1cd4fb65SAntonio Nino Diaz**0x00000000** to **0x3F000000**, it just has different names to simulate a real
98*1cd4fb65SAntonio Nino Diazsecure platform!
99*1cd4fb65SAntonio Nino Diaz
100*1cd4fb65SAntonio Nino Diaz::
101*1cd4fb65SAntonio Nino Diaz
102*1cd4fb65SAntonio Nino Diaz    0x00000000 +-----------------+
103*1cd4fb65SAntonio Nino Diaz               |       ROM       | BL1
104*1cd4fb65SAntonio Nino Diaz    0x00010000 +-----------------+
105*1cd4fb65SAntonio Nino Diaz               |       FIP       |
106*1cd4fb65SAntonio Nino Diaz    0x00200000 +-----------------+
107*1cd4fb65SAntonio Nino Diaz               |                 |
108*1cd4fb65SAntonio Nino Diaz               |       ...       |
109*1cd4fb65SAntonio Nino Diaz               |                 |
110*1cd4fb65SAntonio Nino Diaz    0x01000000 +-----------------+
111*1cd4fb65SAntonio Nino Diaz               |     Kernel      |
112*1cd4fb65SAntonio Nino Diaz               +-----------------+
113*1cd4fb65SAntonio Nino Diaz               |                 |
114*1cd4fb65SAntonio Nino Diaz               |       ...       |
115*1cd4fb65SAntonio Nino Diaz               |                 |
116*1cd4fb65SAntonio Nino Diaz    0x02000000 +-----------------+
117*1cd4fb65SAntonio Nino Diaz               |       DTB       |
118*1cd4fb65SAntonio Nino Diaz               +-----------------+
119*1cd4fb65SAntonio Nino Diaz               |                 |
120*1cd4fb65SAntonio Nino Diaz               |       ...       |
121*1cd4fb65SAntonio Nino Diaz               |                 |
122*1cd4fb65SAntonio Nino Diaz    0x10000000 +-----------------+
123*1cd4fb65SAntonio Nino Diaz               |   Secure SRAM   | BL2, BL31
124*1cd4fb65SAntonio Nino Diaz    0x10100000 +-----------------+
125*1cd4fb65SAntonio Nino Diaz               |   Secure DRAM   |
126*1cd4fb65SAntonio Nino Diaz    0x10300000 +-----------------+
127*1cd4fb65SAntonio Nino Diaz               | Non-secure DRAM | BL33
128*1cd4fb65SAntonio Nino Diaz    0x11000000 +-----------------+
129*1cd4fb65SAntonio Nino Diaz               |                 |
130*1cd4fb65SAntonio Nino Diaz               |       ...       |
131*1cd4fb65SAntonio Nino Diaz               |                 |
132*1cd4fb65SAntonio Nino Diaz    0x3F000000 +-----------------+
133*1cd4fb65SAntonio Nino Diaz               |       I/O       |
134*1cd4fb65SAntonio Nino Diaz    0x40000000 +-----------------+
135*1cd4fb65SAntonio Nino Diaz
136*1cd4fb65SAntonio Nino DiazThe area between **0x10000000** and **0x11000000** has to be protected so that
137*1cd4fb65SAntonio Nino Diazthe kernel doesn't use it. That is done by adding ``memmap=256M$16M`` to the
138*1cd4fb65SAntonio Nino Diazcommand line passed to the kernel. See the `Setup SD card`_ instructions to see
139*1cd4fb65SAntonio Nino Diazhow to do it.
140*1cd4fb65SAntonio Nino Diaz
141*1cd4fb65SAntonio Nino DiazThe last 16 MiB of DRAM can only be accessed by the VideoCore, that has
142*1cd4fb65SAntonio Nino Diazdifferent mappings than the Arm cores in which the I/O addresses don't overlap
143*1cd4fb65SAntonio Nino Diazthe DRAM. The memory reserved to be used by the VideoCore is always placed at
144*1cd4fb65SAntonio Nino Diazthe end of the DRAM, so this space isn't wasted.
145*1cd4fb65SAntonio Nino Diaz
146*1cd4fb65SAntonio Nino DiazConsidering the 128 MiB allocated to the GPU and the 16 MiB allocated for the
147*1cd4fb65SAntonio Nino DiazTrusted Firmware, there are 880 MiB available for Linux.
148*1cd4fb65SAntonio Nino Diaz
149*1cd4fb65SAntonio Nino DiazBoot sequence
150*1cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~
151*1cd4fb65SAntonio Nino Diaz
152*1cd4fb65SAntonio Nino DiazThe boot sequence of the Trusted Firmware is the usual one except when booting
153*1cd4fb65SAntonio Nino Diaza AArch32 kernel. In that case, BL33 is booted in AArch32 Hypervisor mode so
154*1cd4fb65SAntonio Nino Diazthat it can jump to the kernel in the same mode and let it take over that
155*1cd4fb65SAntonio Nino Diazprivilege level. If BL33 was running in EL2 in AArch64 (as in the default
156*1cd4fb65SAntonio Nino Diazbootflow of the Trusted Firmware) it could only jump to the kernel in AArch32 in
157*1cd4fb65SAntonio Nino DiazSupervisor mode.
158*1cd4fb65SAntonio Nino Diaz
159*1cd4fb65SAntonio Nino DiazThe `Linux kernel tree`_ has instructions on how to jump to the Linux kernel
160*1cd4fb65SAntonio Nino Diazin ``Documentation/arm/Booting`` and ``Documentation/arm64/booting.txt``. The
161*1cd4fb65SAntonio Nino Diazbootstrap should take care of this.
162*1cd4fb65SAntonio Nino Diaz
163*1cd4fb65SAntonio Nino DiazSecondary cores
164*1cd4fb65SAntonio Nino Diaz~~~~~~~~~~~~~~~
165*1cd4fb65SAntonio Nino Diaz
166*1cd4fb65SAntonio Nino DiazThe kernel used by `Raspbian`_ doesn't have support for PSCI, so it is needed to
167*1cd4fb65SAntonio Nino Diazuse mailboxes to trap the secondary cores until they are ready to jump to the
168*1cd4fb65SAntonio Nino Diazkernel. This mailbox is located at a different address in the AArch32 default
169*1cd4fb65SAntonio Nino Diazkernel than in the AArch64 kernel.
170*1cd4fb65SAntonio Nino Diaz
171*1cd4fb65SAntonio Nino DiazAlso, this port of the Trusted Firmware has another Trusted Mailbox in Shared BL
172*1cd4fb65SAntonio Nino DiazRAM. During cold boot, all secondary cores wait in a loop until they are given
173*1cd4fb65SAntonio Nino Diazgiven an address to jump to in this Mailbox (``bl31_warm_entrypoint``).
174*1cd4fb65SAntonio Nino Diaz
175*1cd4fb65SAntonio Nino DiazOnce BL31 has finished and the primary core has jumped to the BL33 payload, it
176*1cd4fb65SAntonio Nino Diazhas to call ``PSCI_CPU_ON`` to release the secondary CPUs from the wait loop.
177*1cd4fb65SAntonio Nino DiazThe payload then makes them wait in another waitloop listening from messages
178*1cd4fb65SAntonio Nino Diazfrom the kernel. When the primary CPU jumps into the kernel, it will send an
179*1cd4fb65SAntonio Nino Diazaddress to the mailbox so that the secondary CPUs jump to it and are recognised
180*1cd4fb65SAntonio Nino Diazby the kernel.
181*1cd4fb65SAntonio Nino Diaz
182*1cd4fb65SAntonio Nino DiazBuild Instructions
183*1cd4fb65SAntonio Nino Diaz------------------
184*1cd4fb65SAntonio Nino Diaz
185*1cd4fb65SAntonio Nino DiazTo boot a AArch64 kernel, only the AArch64 toolchain is required.
186*1cd4fb65SAntonio Nino Diaz
187*1cd4fb65SAntonio Nino DiazTo boot a AArch32 kernel, both AArch64 and AArch32 toolchains are required. The
188*1cd4fb65SAntonio Nino DiazAArch32 toolchain is needed for the AArch32 bootstrap needed to load a 32-bit
189*1cd4fb65SAntonio Nino Diazkernel.
190*1cd4fb65SAntonio Nino Diaz
191*1cd4fb65SAntonio Nino DiazFirst, clone and compile `Raspberry Pi 3 Arm Trusted Firmware bootstrap`_.
192*1cd4fb65SAntonio Nino DiazChoose the one needed for the architecture of your kernel.
193*1cd4fb65SAntonio Nino Diaz
194*1cd4fb65SAntonio Nino DiazThen compile the Arm Trusted Firmware. For a AArch32 kernel, use the following
195*1cd4fb65SAntonio Nino Diazcommand line:
196*1cd4fb65SAntonio Nino Diaz
197*1cd4fb65SAntonio Nino Diaz.. code:: shell
198*1cd4fb65SAntonio Nino Diaz
199*1cd4fb65SAntonio Nino Diaz    CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3             \
200*1cd4fb65SAntonio Nino Diaz    RPI3_BL33_IN_AARCH32=1                                      \
201*1cd4fb65SAntonio Nino Diaz    BL33=../rpi3-arm-tf-bootstrap/aarch32/el2-bootstrap.bin     \
202*1cd4fb65SAntonio Nino Diaz    all fip
203*1cd4fb65SAntonio Nino Diaz
204*1cd4fb65SAntonio Nino DiazFor a AArch64 kernel, use this other command line:
205*1cd4fb65SAntonio Nino Diaz
206*1cd4fb65SAntonio Nino Diaz.. code:: shell
207*1cd4fb65SAntonio Nino Diaz
208*1cd4fb65SAntonio Nino Diaz    CROSS_COMPILE=aarch64-linux-gnu- make PLAT=rpi3             \
209*1cd4fb65SAntonio Nino Diaz    BL33=../rpi3-arm-tf-bootstrap/aarch64/el2-bootstrap.bin     \
210*1cd4fb65SAntonio Nino Diaz    all fip
211*1cd4fb65SAntonio Nino Diaz
212*1cd4fb65SAntonio Nino DiazThen, join BL1 and the FIP with the following instructions (replace ``release``
213*1cd4fb65SAntonio Nino Diazby ``debug`` if you set the build option ``DEBUG=1``):
214*1cd4fb65SAntonio Nino Diaz
215*1cd4fb65SAntonio Nino Diaz.. code:: shell
216*1cd4fb65SAntonio Nino Diaz
217*1cd4fb65SAntonio Nino Diaz    cp build/rpi3/release/bl1.bin bl1.pad.bin
218*1cd4fb65SAntonio Nino Diaz    truncate --size=65536 bl1.pad.bin
219*1cd4fb65SAntonio Nino Diaz    cat bl1.pad.bin build/rpi3/release/fip.bin > armstub8.bin
220*1cd4fb65SAntonio Nino Diaz
221*1cd4fb65SAntonio Nino DiazThe resulting file, ``armstub8.bin``, contains BL1 and the FIP in the place they
222*1cd4fb65SAntonio Nino Diazneed to be for the Trusted Firmware to boot correctly. Now, follow the
223*1cd4fb65SAntonio Nino Diazinstructions in `Setup SD card`_.
224*1cd4fb65SAntonio Nino Diaz
225*1cd4fb65SAntonio Nino DiazThe following build options are supported:
226*1cd4fb65SAntonio Nino Diaz
227*1cd4fb65SAntonio Nino Diaz- ``PRELOADED_BL33_BASE``: Specially useful because the file ``kernel8.img`` can
228*1cd4fb65SAntonio Nino Diaz  be loaded anywhere by modifying the file ``config.txt``. It doesn't have to
229*1cd4fb65SAntonio Nino Diaz  contain a kernel, it could have any arbitrary payload.
230*1cd4fb65SAntonio Nino Diaz
231*1cd4fb65SAntonio Nino Diaz- ``RESET_TO_BL31``: Set to 1 by default. If using a 32-bit kernel like
232*1cd4fb65SAntonio Nino Diaz  `Raspbian`_, the space used by BL1 can overwritten by the kernel when it is
233*1cd4fb65SAntonio Nino Diaz  being loaded. Even when using a AArch64 kernel the region used by
234*1cd4fb65SAntonio Nino Diaz  BL1 isn't protected and the kernel could overwrite it. The space used by BL31
235*1cd4fb65SAntonio Nino Diaz  is reserved by the command line passed to the kernel.
236*1cd4fb65SAntonio Nino Diaz
237*1cd4fb65SAntonio Nino Diaz- ``RPI3_BL33_IN_AARCH32``: This port can load a AArch64 or AArch32 BL33 image.
238*1cd4fb65SAntonio Nino Diaz  By default this option is 0, which means that the Trusted Firmware will jump
239*1cd4fb65SAntonio Nino Diaz  to BL33 in EL2 in AArch64 mode. If set to 1, it will jump to BL33 in
240*1cd4fb65SAntonio Nino Diaz  Hypervisor in AArch32 mode.
241*1cd4fb65SAntonio Nino Diaz
242*1cd4fb65SAntonio Nino DiazThe following is not currently supported:
243*1cd4fb65SAntonio Nino Diaz
244*1cd4fb65SAntonio Nino Diaz- AArch32 for the Trusted Firmware itself.
245*1cd4fb65SAntonio Nino Diaz
246*1cd4fb65SAntonio Nino Diaz- ``EL3_PAYLOAD_BASE``: The reason is that you can already load anything to any
247*1cd4fb65SAntonio Nino Diaz  address by changing the file ``armstub8.bin``, so there's no point in using
248*1cd4fb65SAntonio Nino Diaz  the Trusted Firmware in this case.
249*1cd4fb65SAntonio Nino Diaz
250*1cd4fb65SAntonio Nino Diaz- ``LOAD_IMAGE_V2=0``: Only version 2 is supported.
251*1cd4fb65SAntonio Nino Diaz
252*1cd4fb65SAntonio Nino DiazAArch64 kernel build instructions
253*1cd4fb65SAntonio Nino Diaz---------------------------------
254*1cd4fb65SAntonio Nino Diaz
255*1cd4fb65SAntonio Nino DiazThe following instructions show how to install and run a AArch64 kernel by
256*1cd4fb65SAntonio Nino Diazusing a SD card with the default `Raspbian`_ install as base. Skip them if you
257*1cd4fb65SAntonio Nino Diazwant to use the default 32-bit kernel.
258*1cd4fb65SAntonio Nino Diaz
259*1cd4fb65SAntonio Nino DiazNote that this system won't be fully 64-bit because all the tools in the
260*1cd4fb65SAntonio Nino Diazfilesystem are 32-bit binaries, but it's a quick way to get it working, and it
261*1cd4fb65SAntonio Nino Diazallows the user to run 64-bit binaries in addition to 32-bit binaries.
262*1cd4fb65SAntonio Nino Diaz
263*1cd4fb65SAntonio Nino Diaz1. Clone the `Linux tree fork`_ maintained by the Raspberry Pi Foundation. To
264*1cd4fb65SAntonio Nino Diaz   speed things up, do a shallow clone of the desired branch.
265*1cd4fb65SAntonio Nino Diaz
266*1cd4fb65SAntonio Nino Diaz.. code:: shell
267*1cd4fb65SAntonio Nino Diaz
268*1cd4fb65SAntonio Nino Diaz    git clone --depth=1 -b rpi-4.14.y https://github.com/raspberrypi/linux
269*1cd4fb65SAntonio Nino Diaz    cd linux
270*1cd4fb65SAntonio Nino Diaz
271*1cd4fb65SAntonio Nino Diaz2. Configure and compile the kernel. Adapt the number after ``-j`` so that it is
272*1cd4fb65SAntonio Nino Diaz   1.5 times the number of CPUs in your computer. This may take some time to
273*1cd4fb65SAntonio Nino Diaz   finish.
274*1cd4fb65SAntonio Nino Diaz
275*1cd4fb65SAntonio Nino Diaz.. code:: shell
276*1cd4fb65SAntonio Nino Diaz
277*1cd4fb65SAntonio Nino Diaz    make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig
278*1cd4fb65SAntonio Nino Diaz    make -j 6 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
279*1cd4fb65SAntonio Nino Diaz
280*1cd4fb65SAntonio Nino Diaz3. Copy the kernel image and the device tree to the SD card. Replace the path
281*1cd4fb65SAntonio Nino Diaz   by the corresponding path in your computers to the ``boot`` partition of the
282*1cd4fb65SAntonio Nino Diaz   SD card.
283*1cd4fb65SAntonio Nino Diaz
284*1cd4fb65SAntonio Nino Diaz.. code:: shell
285*1cd4fb65SAntonio Nino Diaz
286*1cd4fb65SAntonio Nino Diaz    cp arch/arm64/boot/Image /path/to/boot/kernel8.img
287*1cd4fb65SAntonio Nino Diaz    cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b.dtb /path/to/boot/
288*1cd4fb65SAntonio Nino Diaz
289*1cd4fb65SAntonio Nino Diaz4. Install the kernel modules. Replace the path by the corresponding path to the
290*1cd4fb65SAntonio Nino Diaz   filesystem partition of the SD card on your computer.
291*1cd4fb65SAntonio Nino Diaz
292*1cd4fb65SAntonio Nino Diaz.. code:: shell
293*1cd4fb65SAntonio Nino Diaz
294*1cd4fb65SAntonio Nino Diaz    make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
295*1cd4fb65SAntonio Nino Diaz    INSTALL_MOD_PATH=/path/to/filesystem modules_install
296*1cd4fb65SAntonio Nino Diaz
297*1cd4fb65SAntonio Nino Diaz5. Follow the instructions in `Setup SD card`_ except for the step of renaming
298*1cd4fb65SAntonio Nino Diaz   the existing ``kernel7.img`` (we have already copied a AArch64 kernel).
299*1cd4fb65SAntonio Nino Diaz
300*1cd4fb65SAntonio Nino DiazSetup SD card
301*1cd4fb65SAntonio Nino Diaz-------------
302*1cd4fb65SAntonio Nino Diaz
303*1cd4fb65SAntonio Nino DiazThe instructions assume that you have an SD card with a fresh install of
304*1cd4fb65SAntonio Nino Diaz`Raspbian`_ (or that, at least, the ``boot`` partition is untouched, or nearly
305*1cd4fb65SAntonio Nino Diazuntouched). They have been tested with the image available in 2017-09-07.
306*1cd4fb65SAntonio Nino Diaz
307*1cd4fb65SAntonio Nino Diaz1. Insert the SD card and open the ``boot`` partition.
308*1cd4fb65SAntonio Nino Diaz
309*1cd4fb65SAntonio Nino Diaz2. Rename ``kernel7.img`` to ``kernel8.img``. This tricks the VideoCore
310*1cd4fb65SAntonio Nino Diaz   bootloader into booting the Arm cores in AArch64 mode, like the Trusted
311*1cd4fb65SAntonio Nino Diaz   Firmware needs, even though the kernel is not compiled for AArch64.
312*1cd4fb65SAntonio Nino Diaz
313*1cd4fb65SAntonio Nino Diaz3. Copy ``armstub8.bin`` here. When ``kernel8.img`` is available, The VideoCore
314*1cd4fb65SAntonio Nino Diaz   bootloader will look for a file called ``armstub8.bin`` and load it at
315*1cd4fb65SAntonio Nino Diaz   address **0x0** instead of a predefined one.
316*1cd4fb65SAntonio Nino Diaz
317*1cd4fb65SAntonio Nino Diaz4. Open ``cmdline.txt`` and add ``memmap=256M$16M`` to prevent the kernel from
318*1cd4fb65SAntonio Nino Diaz   using the memory needed by the Trusted Firmware. If you want to enable the
319*1cd4fb65SAntonio Nino Diaz   serial port "Mini UART", make sure that this file also contains
320*1cd4fb65SAntonio Nino Diaz   ``console=serial0,115200 console=tty1``.
321*1cd4fb65SAntonio Nino Diaz
322*1cd4fb65SAntonio Nino Diaz   Note that the 16 MiB reserved this way won't be available for Linux, the same
323*1cd4fb65SAntonio Nino Diaz   way as the memory reserved in DRAM for the GPU isn't available.
324*1cd4fb65SAntonio Nino Diaz
325*1cd4fb65SAntonio Nino Diaz5. Open ``config.txt`` and add the following lines at the end (``enable_uart=1``
326*1cd4fb65SAntonio Nino Diaz   is only needed to enable debugging through the Mini UART):
327*1cd4fb65SAntonio Nino Diaz
328*1cd4fb65SAntonio Nino Diaz::
329*1cd4fb65SAntonio Nino Diaz
330*1cd4fb65SAntonio Nino Diaz    enable_uart=1
331*1cd4fb65SAntonio Nino Diaz    kernel_address=0x01000000
332*1cd4fb65SAntonio Nino Diaz    device_tree_address=0x02000000
333*1cd4fb65SAntonio Nino Diaz
334*1cd4fb65SAntonio Nino DiazIf you connect a serial cable to the Mini UART and your computer, and connect
335*1cd4fb65SAntonio Nino Diazto it (for example, with ``screen /dev/ttyUSB0 115200``) you should see some
336*1cd4fb65SAntonio Nino Diaztext. In the case of an AArch32 kernel, you should see something like this:
337*1cd4fb65SAntonio Nino Diaz
338*1cd4fb65SAntonio Nino Diaz::
339*1cd4fb65SAntonio Nino Diaz
340*1cd4fb65SAntonio Nino Diaz    NOTICE:  Booting Trusted Firmware
341*1cd4fb65SAntonio Nino Diaz    NOTICE:  BL1: v1.4(release):v1.4-329-g61e94684-dirty
342*1cd4fb65SAntonio Nino Diaz    NOTICE:  BL1: Built : 00:09:25, Nov  6 2017
343*1cd4fb65SAntonio Nino Diaz    NOTICE:  BL1: Booting BL2
344*1cd4fb65SAntonio Nino Diaz    NOTICE:  BL2: v1.4(release):v1.4-329-g61e94684-dirty
345*1cd4fb65SAntonio Nino Diaz    NOTICE:  BL2: Built : 00:09:25, Nov  6 2017
346*1cd4fb65SAntonio Nino Diaz    NOTICE:  BL1: Booting BL31
347*1cd4fb65SAntonio Nino Diaz    NOTICE:  BL31: v1.4(release):v1.4-329-g61e94684-dirty
348*1cd4fb65SAntonio Nino Diaz    NOTICE:  BL31: Built : 00:09:25, Nov  6 2017
349*1cd4fb65SAntonio Nino Diaz    [    0.266484] bcm2835-aux-uart 3f215040.serial: could not get clk: -517
350*1cd4fb65SAntonio Nino Diaz
351*1cd4fb65SAntonio Nino Diaz    Raspbian GNU/Linux 9 raspberrypi ttyS0
352*1cd4fb65SAntonio Nino Diaz    raspberrypi login:
353*1cd4fb65SAntonio Nino Diaz
354*1cd4fb65SAntonio Nino DiazJust enter your credentials, everything should work as expected. Note that the
355*1cd4fb65SAntonio Nino DiazHDMI output won't show any text during boot.
356*1cd4fb65SAntonio Nino Diaz
357*1cd4fb65SAntonio Nino Diaz.. _default Arm stub: https://github.com/raspberrypi/tools/blob/master/armstubs/armstub7.S
358*1cd4fb65SAntonio Nino Diaz.. _default AArch64 stub: https://github.com/raspberrypi/tools/blob/master/armstubs/armstub8.S
359*1cd4fb65SAntonio Nino Diaz.. _Linux kernel tree: https://github.com/torvalds/linux
360*1cd4fb65SAntonio Nino Diaz.. _Linux tree fork: https://github.com/raspberrypi/linux
361*1cd4fb65SAntonio Nino Diaz.. _Raspberry Pi 3: https://www.raspberrypi.org/products/raspberry-pi-3-model-b/
362*1cd4fb65SAntonio Nino Diaz.. _Raspberry Pi 3 Arm Trusted Firmware bootstrap: https://github.com/AntonioND/rpi3-arm-tf-bootstrap
363*1cd4fb65SAntonio Nino Diaz.. _Raspberry Pi 3 documentation: https://www.raspberrypi.org/documentation/
364*1cd4fb65SAntonio Nino Diaz.. _Raspbian: https://www.raspberrypi.org/downloads/raspbian/
365