blob: 8a46c0efa18b3c834201d21c265b6e69a4ce819f [file] [log] [blame]
Heinrich Schuchardt4b91bc52023-07-28 22:37:40 +02001.. SPDX-License-Identifier: GPL-2.0-or-later
2
3Falcon Mode
4===========
5
6Introduction
7------------
8
9This document provides an overview of how to add support for Falcon Mode
10to a board.
11
12Falcon Mode is introduced to speed up the booting process, allowing
13to boot a Linux kernel (or whatever image) without a full blown U-Boot.
14
15Falcon Mode relies on the SPL framework. In fact, to make booting faster,
16U-Boot is split into two parts: the SPL (Secondary Program Loader) and U-Boot
17image. In most implementations, SPL is used to start U-Boot when booting from
18a mass storage, such as NAND or SD-Card. SPL has now support for other media,
19and can generally be seen as a way to start an image performing the minimum
20required initialization. SPL mainly initializes the RAM controller, and then
21copies U-Boot image into the memory.
22
23The Falcon Mode extends this way allowing to start the Linux kernel directly
24from SPL. A new command is added to U-Boot to prepare the parameters that SPL
25must pass to the kernel, using ATAGS or Device Tree.
26
27In normal mode, these parameters are generated each time before
28loading the kernel, passing to Linux the address in memory where
29the parameters can be read.
30With Falcon Mode, this snapshot can be saved into persistent storage and SPL is
31informed to load it before running the kernel.
32
33To boot the kernel, these steps under a Falcon-aware U-Boot are required:
34
351. Boot the board into U-Boot.
36 After loading the desired legacy-format kernel image into memory (and DT as
37 well, if used), use the "spl export" command to generate the kernel
38 parameters area or the DT. U-Boot runs as when it boots the kernel, but
39 stops before passing the control to the kernel.
40
412. Save the prepared snapshot into persistent media.
42 The address where to save it must be configured into board configuration
43 file (CONFIG_CMD_SPL_NAND_OFS for NAND).
44
453. Boot the board into Falcon Mode. SPL will load the kernel and copy
46 the parameters which are saved in the persistent area to the required
47 address. If a valid uImage is not found at the defined location, U-Boot
48 will be booted instead.
49
50It is required to implement a custom mechanism to select if SPL loads U-Boot
51or another image.
52
53The value of a GPIO is a simple way to operate the selection, as well as
54reading a character from the SPL console if CONFIG_SPL_CONSOLE is set.
55
56Falcon Mode is generally activated by setting CONFIG_SPL_OS_BOOT. This tells
57SPL that U-Boot is not the only available image that SPL is able to start.
58
59Configuration
60-------------
61
62CONFIG_CMD_SPL
63 Enable the "spl export" command.
64 The command "spl export" is then available in U-Boot mode.
65
Simon Glass259cdb42023-09-26 08:14:17 -060066CONFIG_SPL_PAYLOAD_ARGS_ADDR
Heinrich Schuchardt4b91bc52023-07-28 22:37:40 +020067 Address in RAM where the parameters must be copied by SPL.
68 In most cases, it is <start_of_ram> + 0x100.
69
70CONFIG_SYS_NAND_SPL_KERNEL_OFFS
71 Offset in NAND where the kernel is stored
72
73CONFIG_CMD_SPL_NAND_OFS
74 Offset in NAND where the parameters area was saved.
75
76CONFIG_CMD_SPL_NOR_OFS
77 Offset in NOR where the parameters area was saved.
78
79CONFIG_CMD_SPL_WRITE_SIZE
80 Size of the parameters area to be copied
81
82CONFIG_SPL_OS_BOOT
83 Activate Falcon Mode.
84
85Function that a board must implement
86------------------------------------
87
88void spl_board_prepare_for_linux(void)
89 optional, called from SPL before starting the kernel
90
91spl_start_uboot()
92 required, returns "0" if SPL should start the kernel, "1" if U-Boot
93 must be started.
94
95Environment variables
96---------------------
97
98A board may chose to look at the environment for decisions about falcon
99mode. In this case the following variables may be supported:
100
101boot_os
102 Set to yes/Yes/true/True/1 to enable booting to OS,
103 any other value to fall back to U-Boot (including unset)
104
105falcon_args_file
106 Filename to load as the 'args' portion of falcon mode rather than the
107 hard-coded value.
108
109falcon_image_file
110 Filename to load as the OS image portion of falcon mode rather than the
111 hard-coded value.
112
113Using spl command
114-----------------
115
116spl - SPL configuration
117
118Usage::
119
120 spl export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr ]
121
122img
123 "atags" or "fdt"
124
125kernel_addr
126 kernel is loaded as part of the boot process, but it is not started.
127 This is the address where a kernel image is stored.
128
129initrd_addr
130 Address of initial ramdisk
131 can be set to "-" if fdt_addr without initrd_addr is used
132
133fdt_addr
134 in case of fdt, the address of the device tree.
135
136The *spl export* command does not write to a storage media. The user is
137responsible to transfer the gathered information (assembled ATAGS list
138or prepared FDT) from temporary storage in RAM into persistent storage
139after each run of *spl export*. Unfortunately the position of temporary
140storage can not be predicted nor provided at command line, it depends
141highly on your system setup and your provided data (ATAGS or FDT).
142However at the end of an successful *spl export* run it will print the
143RAM address of temporary storage. The RAM address of FDT will also be
144set in the environment variable *fdtargsaddr*, the new length of the
145prepared FDT will be set in the environment variable *fdtargslen*.
146These environment variables can be used in scripts for writing updated
147FDT to persistent storage.
148
149Now the user have to save the generated BLOB from that printed address
150to the pre-defined address in persistent storage
151(CONFIG_CMD_SPL_NAND_OFS in case of NAND).
152The following example shows how to prepare the data for Falcon Mode on
153twister board with ATAGS BLOB.
154
155The *spl export* command is prepared to work with ATAGS and FDT. However,
156using FDT is at the moment untested. The ppc port (see a3m071 example
157later) prepares the fdt blob with the fdt command instead.
158
159
160Usage on the twister board
161--------------------------
162
163Using mtd names with the following (default) configuration
164for mtdparts::
165
166 device nand0 <omap2-nand.0>, # parts = 9
167 #: name size offset mask_flags
168 0: MLO 0x00080000 0x00000000 0
169 1: u-boot 0x00100000 0x00080000 0
170 2: env1 0x00040000 0x00180000 0
171 3: env2 0x00040000 0x001c0000 0
172 4: kernel 0x00600000 0x00200000 0
173 5: bootparms 0x00040000 0x00800000 0
174 6: splashimg 0x00200000 0x00840000 0
175 7: mini 0x02800000 0x00a40000 0
176 8: rootfs 0x1cdc0000 0x03240000 0
177
178::
179
180 twister => nand read 82000000 kernel
181
182 NAND read: device 0 offset 0x200000, size 0x600000
183 6291456 bytes read: OK
184
185Now the kernel is in RAM at address 0x82000000::
186
187 twister => spl export atags 0x82000000
188 ## Booting kernel from Legacy Image at 82000000 ...
189 Image Name: Linux-3.5.0-rc4-14089-gda0b7f4
190 Image Type: ARM Linux Kernel Image (uncompressed)
191 Data Size: 3654808 Bytes = 3.5 MiB
192 Load Address: 80008000
193 Entry Point: 80008000
194 Verifying Checksum ... OK
195 Loading Kernel Image ... OK
196 OK
197 cmdline subcommand not supported
198 bdt subcommand not supported
199 Argument image is now in RAM at: 0x80000100
200
201The result can be checked at address 0x80000100::
202
203 twister => md 0x80000100
204 80000100: 00000005 54410001 00000000 00000000 ......AT........
205 80000110: 00000000 00000067 54410009 746f6f72 ....g.....ATroot
206 80000120: 65642f3d 666e2f76 77722073 73666e20 =/dev/nfs rw nfs
207
208The parameters generated with this step can be saved into NAND at the offset
2090x800000 (value for twister for CONFIG_CMD_SPL_NAND_OFS)::
210
211 nand erase.part bootparms
212 nand write 0x80000100 bootparms 0x4000
213
214Now the parameters are stored into the NAND flash at the address
215CONFIG_CMD_SPL_NAND_OFS (=0x800000).
216
217Next time, the board can be started into Falcon Mode moving the
218setting the GPIO (on twister GPIO 55 is used) to kernel mode.
219
220The kernel is loaded directly by the SPL without passing through U-Boot.
221
222Example with FDT: a3m071 board
Heinrich Schuchardtb72160b2023-10-28 11:59:32 +0200223------------------------------
Heinrich Schuchardt4b91bc52023-07-28 22:37:40 +0200224
225To boot the Linux kernel from the SPL, the DT blob (fdt) needs to get
226prepared/patched first. U-Boot usually inserts some dynamic values into
227the DT binary (blob), e.g. autodetected memory size, MAC addresses,
228clocks speeds etc. To generate this patched DT blob, you can use
229the following command:
230
2311. Load fdt blob to SDRAM::
232
233 => tftp 1800000 a3m071/a3m071.dtb
234
2352. Set bootargs as desired for Linux booting (e.g. flash_mtd)::
236
237 => run mtdargs addip2 addtty
238
2393. Use "fdt" commands to patch the DT blob::
240
241 => fdt addr 1800000
242 => fdt boardsetup
243 => fdt chosen
244
2454. Display patched DT blob (optional)::
246
247 => fdt print
248
2495. Save fdt to NOR flash::
250
251 => erase fc060000 fc07ffff
252 => cp.b 1800000 fc060000 10000
253 ...
254
255
256Falcon Mode was presented at the RMLL 2012. Slides are available at:
257
258http://schedule2012.rmll.info/IMG/pdf/LSM2012_UbootFalconMode_Babic.pdf