1*4882a593SmuzhiyunU-Boot Falcon Mode 2*4882a593Smuzhiyun==================== 3*4882a593Smuzhiyun 4*4882a593SmuzhiyunIntroduction 5*4882a593Smuzhiyun------------ 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunThis document provides an overview of how to add support for Falcon Mode 8*4882a593Smuzhiyunto a board. 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunFalcon Mode is introduced to speed up the booting process, allowing 11*4882a593Smuzhiyunto boot a Linux kernel (or whatever image) without a full blown U-Boot. 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunFalcon Mode relies on the SPL framework. In fact, to make booting faster, 14*4882a593SmuzhiyunU-Boot is split into two parts: the SPL (Secondary Program Loader) and U-Boot 15*4882a593Smuzhiyunimage. In most implementations, SPL is used to start U-Boot when booting from 16*4882a593Smuzhiyuna mass storage, such as NAND or SD-Card. SPL has now support for other media, 17*4882a593Smuzhiyunand can generally be seen as a way to start an image performing the minimum 18*4882a593Smuzhiyunrequired initialization. SPL mainly initializes the RAM controller, and then 19*4882a593Smuzhiyuncopies U-Boot image into the memory. 20*4882a593Smuzhiyun 21*4882a593SmuzhiyunThe Falcon Mode extends this way allowing to start the Linux kernel directly 22*4882a593Smuzhiyunfrom SPL. A new command is added to U-Boot to prepare the parameters that SPL 23*4882a593Smuzhiyunmust pass to the kernel, using ATAGS or Device Tree. 24*4882a593Smuzhiyun 25*4882a593SmuzhiyunIn normal mode, these parameters are generated each time before 26*4882a593Smuzhiyunloading the kernel, passing to Linux the address in memory where 27*4882a593Smuzhiyunthe parameters can be read. 28*4882a593SmuzhiyunWith Falcon Mode, this snapshot can be saved into persistent storage and SPL is 29*4882a593Smuzhiyuninformed to load it before running the kernel. 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunTo boot the kernel, these steps under a Falcon-aware U-Boot are required: 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun1. Boot the board into U-Boot. 34*4882a593SmuzhiyunAfter loading the desired legacy-format kernel image into memory (and DT as 35*4882a593Smuzhiyunwell, if used), use the "spl export" command to generate the kernel parameters 36*4882a593Smuzhiyunarea or the DT. U-Boot runs as when it boots the kernel, but stops before 37*4882a593Smuzhiyunpassing the control to the kernel. 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun2. Save the prepared snapshot into persistent media. 40*4882a593SmuzhiyunThe address where to save it must be configured into board configuration 41*4882a593Smuzhiyunfile (CONFIG_CMD_SPL_NAND_OFS for NAND). 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun3. Boot the board into Falcon Mode. SPL will load the kernel and copy 44*4882a593Smuzhiyunthe parameters which are saved in the persistent area to the required address. 45*4882a593SmuzhiyunIf a valid uImage is not found at the defined location, U-Boot will be 46*4882a593Smuzhiyunbooted instead. 47*4882a593Smuzhiyun 48*4882a593SmuzhiyunIt is required to implement a custom mechanism to select if SPL loads U-Boot 49*4882a593Smuzhiyunor another image. 50*4882a593Smuzhiyun 51*4882a593SmuzhiyunThe value of a GPIO is a simple way to operate the selection, as well as 52*4882a593Smuzhiyunreading a character from the SPL console if CONFIG_SPL_CONSOLE is set. 53*4882a593Smuzhiyun 54*4882a593SmuzhiyunFalcon Mode is generally activated by setting CONFIG_SPL_OS_BOOT. This tells 55*4882a593SmuzhiyunSPL that U-Boot is not the only available image that SPL is able to start. 56*4882a593Smuzhiyun 57*4882a593SmuzhiyunConfiguration 58*4882a593Smuzhiyun---------------------------- 59*4882a593SmuzhiyunCONFIG_CMD_SPL Enable the "spl export" command. 60*4882a593Smuzhiyun The command "spl export" is then available in U-Boot 61*4882a593Smuzhiyun mode 62*4882a593SmuzhiyunCONFIG_SYS_SPL_ARGS_ADDR Address in RAM where the parameters must be 63*4882a593Smuzhiyun copied by SPL. 64*4882a593Smuzhiyun In most cases, it is <start_of_ram> + 0x100 65*4882a593Smuzhiyun 66*4882a593SmuzhiyunCONFIG_SYS_NAND_SPL_KERNEL_OFFS Offset in NAND where the kernel is stored 67*4882a593Smuzhiyun 68*4882a593SmuzhiyunCONFIG_CMD_SPL_NAND_OFS Offset in NAND where the parameters area was saved. 69*4882a593Smuzhiyun 70*4882a593SmuzhiyunCONFIG_CMD_SPL_WRITE_SIZE Size of the parameters area to be copied 71*4882a593Smuzhiyun 72*4882a593SmuzhiyunCONFIG_SPL_OS_BOOT Activate Falcon Mode. 73*4882a593Smuzhiyun 74*4882a593SmuzhiyunFunction that a board must implement 75*4882a593Smuzhiyun------------------------------------ 76*4882a593Smuzhiyun 77*4882a593Smuzhiyunvoid spl_board_prepare_for_linux(void) : optional 78*4882a593Smuzhiyun Called from SPL before starting the kernel 79*4882a593Smuzhiyun 80*4882a593Smuzhiyunspl_start_uboot() : required 81*4882a593Smuzhiyun Returns "0" if SPL should start the kernel, "1" if U-Boot 82*4882a593Smuzhiyun must be started. 83*4882a593Smuzhiyun 84*4882a593SmuzhiyunEnvironment variables 85*4882a593Smuzhiyun--------------------- 86*4882a593Smuzhiyun 87*4882a593SmuzhiyunA board may chose to look at the environment for decisions about falcon 88*4882a593Smuzhiyunmode. In this case the following variables may be supported: 89*4882a593Smuzhiyun 90*4882a593Smuzhiyunboot_os : Set to yes/Yes/true/True/1 to enable booting to OS, 91*4882a593Smuzhiyun any other value to fall back to U-Boot (including 92*4882a593Smuzhiyun unset) 93*4882a593Smuzhiyunfalcon_args_file : Filename to load as the 'args' portion of falcon mode 94*4882a593Smuzhiyun rather than the hard-coded value. 95*4882a593Smuzhiyunfalcon_image_file : Filename to load as the OS image portion of falcon 96*4882a593Smuzhiyun mode rather than the hard-coded value. 97*4882a593Smuzhiyun 98*4882a593SmuzhiyunUsing spl command 99*4882a593Smuzhiyun----------------- 100*4882a593Smuzhiyun 101*4882a593Smuzhiyunspl - SPL configuration 102*4882a593Smuzhiyun 103*4882a593SmuzhiyunUsage: 104*4882a593Smuzhiyun 105*4882a593Smuzhiyunspl export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr ] 106*4882a593Smuzhiyun 107*4882a593Smuzhiyunimg : "atags" or "fdt" 108*4882a593Smuzhiyunkernel_addr : kernel is loaded as part of the boot process, but it is not started. 109*4882a593Smuzhiyun This is the address where a kernel image is stored. 110*4882a593Smuzhiyuninitrd_addr : Address of initial ramdisk 111*4882a593Smuzhiyun can be set to "-" if fdt_addr without initrd_addr is used 112*4882a593Smuzhiyunfdt_addr : in case of fdt, the address of the device tree. 113*4882a593Smuzhiyun 114*4882a593SmuzhiyunThe spl export command does not write to a storage media. The user is 115*4882a593Smuzhiyunresponsible to transfer the gathered information (assembled ATAGS list 116*4882a593Smuzhiyunor prepared FDT) from temporary storage in RAM into persistant storage 117*4882a593Smuzhiyunafter each run of 'spl export'. Unfortunately the position of temporary 118*4882a593Smuzhiyunstorage can not be predicted nor provided at commandline, it depends 119*4882a593Smuzhiyunhighly on your system setup and your provided data (ATAGS or FDT). 120*4882a593SmuzhiyunHowever at the end of an succesful 'spl export' run it will print the 121*4882a593SmuzhiyunRAM address of temporary storage. The RAM address of FDT will also be 122*4882a593Smuzhiyunset in the environment variable 'fdtargsaddr', the new length of the 123*4882a593Smuzhiyunprepared FDT will be set in the environment variable 'fdtargslen'. 124*4882a593SmuzhiyunThese environment variables can be used in scripts for writing updated 125*4882a593SmuzhiyunFDT to persistent storage. 126*4882a593Smuzhiyun 127*4882a593SmuzhiyunNow the user have to save the generated BLOB from that printed address 128*4882a593Smuzhiyunto the pre-defined address in persistent storage 129*4882a593Smuzhiyun(CONFIG_CMD_SPL_NAND_OFS in case of NAND). 130*4882a593SmuzhiyunThe following example shows how to prepare the data for Falcon Mode on 131*4882a593Smuzhiyuntwister board with ATAGS BLOB. 132*4882a593Smuzhiyun 133*4882a593SmuzhiyunThe "spl export" command is prepared to work with ATAGS and FDT. However, 134*4882a593Smuzhiyunusing FDT is at the moment untested. The ppc port (see a3m071 example 135*4882a593Smuzhiyunlater) prepares the fdt blob with the fdt command instead. 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun 138*4882a593SmuzhiyunUsage on the twister board: 139*4882a593Smuzhiyun-------------------------------- 140*4882a593Smuzhiyun 141*4882a593SmuzhiyunUsing mtd names with the following (default) configuration 142*4882a593Smuzhiyunfor mtdparts: 143*4882a593Smuzhiyun 144*4882a593Smuzhiyundevice nand0 <omap2-nand.0>, # parts = 9 145*4882a593Smuzhiyun #: name size offset mask_flags 146*4882a593Smuzhiyun 0: MLO 0x00080000 0x00000000 0 147*4882a593Smuzhiyun 1: u-boot 0x00100000 0x00080000 0 148*4882a593Smuzhiyun 2: env1 0x00040000 0x00180000 0 149*4882a593Smuzhiyun 3: env2 0x00040000 0x001c0000 0 150*4882a593Smuzhiyun 4: kernel 0x00600000 0x00200000 0 151*4882a593Smuzhiyun 5: bootparms 0x00040000 0x00800000 0 152*4882a593Smuzhiyun 6: splashimg 0x00200000 0x00840000 0 153*4882a593Smuzhiyun 7: mini 0x02800000 0x00a40000 0 154*4882a593Smuzhiyun 8: rootfs 0x1cdc0000 0x03240000 0 155*4882a593Smuzhiyun 156*4882a593Smuzhiyun 157*4882a593Smuzhiyuntwister => nand read 82000000 kernel 158*4882a593Smuzhiyun 159*4882a593SmuzhiyunNAND read: device 0 offset 0x200000, size 0x600000 160*4882a593Smuzhiyun 6291456 bytes read: OK 161*4882a593Smuzhiyun 162*4882a593SmuzhiyunNow the kernel is in RAM at address 0x82000000 163*4882a593Smuzhiyun 164*4882a593Smuzhiyuntwister => spl export atags 0x82000000 165*4882a593Smuzhiyun## Booting kernel from Legacy Image at 82000000 ... 166*4882a593Smuzhiyun Image Name: Linux-3.5.0-rc4-14089-gda0b7f4 167*4882a593Smuzhiyun Image Type: ARM Linux Kernel Image (uncompressed) 168*4882a593Smuzhiyun Data Size: 3654808 Bytes = 3.5 MiB 169*4882a593Smuzhiyun Load Address: 80008000 170*4882a593Smuzhiyun Entry Point: 80008000 171*4882a593Smuzhiyun Verifying Checksum ... OK 172*4882a593Smuzhiyun Loading Kernel Image ... OK 173*4882a593SmuzhiyunOK 174*4882a593Smuzhiyuncmdline subcommand not supported 175*4882a593Smuzhiyunbdt subcommand not supported 176*4882a593SmuzhiyunArgument image is now in RAM at: 0x80000100 177*4882a593Smuzhiyun 178*4882a593SmuzhiyunThe result can be checked at address 0x80000100: 179*4882a593Smuzhiyun 180*4882a593Smuzhiyuntwister => md 0x80000100 181*4882a593Smuzhiyun80000100: 00000005 54410001 00000000 00000000 ......AT........ 182*4882a593Smuzhiyun80000110: 00000000 00000067 54410009 746f6f72 ....g.....ATroot 183*4882a593Smuzhiyun80000120: 65642f3d 666e2f76 77722073 73666e20 =/dev/nfs rw nfs 184*4882a593Smuzhiyun 185*4882a593SmuzhiyunThe parameters generated with this step can be saved into NAND at the offset 186*4882a593Smuzhiyun0x800000 (value for twister for CONFIG_CMD_SPL_NAND_OFS) 187*4882a593Smuzhiyun 188*4882a593Smuzhiyunnand erase.part bootparms 189*4882a593Smuzhiyunnand write 0x80000100 bootparms 0x4000 190*4882a593Smuzhiyun 191*4882a593SmuzhiyunNow the parameters are stored into the NAND flash at the address 192*4882a593SmuzhiyunCONFIG_CMD_SPL_NAND_OFS (=0x800000). 193*4882a593Smuzhiyun 194*4882a593SmuzhiyunNext time, the board can be started into Falcon Mode moving the 195*4882a593Smuzhiyunsetting the gpio (on twister gpio 55 is used) to kernel mode. 196*4882a593Smuzhiyun 197*4882a593SmuzhiyunThe kernel is loaded directly by the SPL without passing through U-Boot. 198*4882a593Smuzhiyun 199*4882a593SmuzhiyunExample with FDT: a3m071 board 200*4882a593Smuzhiyun------------------------------- 201*4882a593Smuzhiyun 202*4882a593SmuzhiyunTo boot the Linux kernel from the SPL, the DT blob (fdt) needs to get 203*4882a593Smuzhiyunprepard/patched first. U-Boot usually inserts some dynamic values into 204*4882a593Smuzhiyunthe DT binary (blob), e.g. autodetected memory size, MAC addresses, 205*4882a593Smuzhiyunclocks speeds etc. To generate this patched DT blob, you can use 206*4882a593Smuzhiyunthe following command: 207*4882a593Smuzhiyun 208*4882a593Smuzhiyun1. Load fdt blob to SDRAM: 209*4882a593Smuzhiyun=> tftp 1800000 a3m071/a3m071.dtb 210*4882a593Smuzhiyun 211*4882a593Smuzhiyun2. Set bootargs as desired for Linux booting (e.g. flash_mtd): 212*4882a593Smuzhiyun=> run mtdargs addip2 addtty 213*4882a593Smuzhiyun 214*4882a593Smuzhiyun3. Use "fdt" commands to patch the DT blob: 215*4882a593Smuzhiyun=> fdt addr 1800000 216*4882a593Smuzhiyun=> fdt boardsetup 217*4882a593Smuzhiyun=> fdt chosen 218*4882a593Smuzhiyun 219*4882a593Smuzhiyun4. Display patched DT blob (optional): 220*4882a593Smuzhiyun=> fdt print 221*4882a593Smuzhiyun 222*4882a593Smuzhiyun5. Save fdt to NOR flash: 223*4882a593Smuzhiyun=> erase fc060000 fc07ffff 224*4882a593Smuzhiyun=> cp.b 1800000 fc060000 10000 225*4882a593Smuzhiyun... 226*4882a593Smuzhiyun 227*4882a593Smuzhiyun 228*4882a593SmuzhiyunFalcon Mode was presented at the RMLL 2012. Slides are available at: 229*4882a593Smuzhiyun 230*4882a593Smuzhiyunhttp://schedule2012.rmll.info/IMG/pdf/LSM2012_UbootFalconMode_Babic.pdf 231