opdenacker-understanding-u-boot-falcon-mode
opdenacker-understanding-u-boot-falcon-mode
Understanding U-Boot
Falcon Mode
Michael Opdenacker
[email protected]
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 1/28
Michael Opdenacker
https://elixir.bootlin.com
▶ Co-author of Bootlin’s freely available embedded Linux Identifier
search
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 2/28
Goal: boot faster!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 3/28
Example: booting on Microchip SAMA5D36
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 4/28
Normal and Falcon boot on Microchip SAMA5D3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 5/28
Falcon mode advantages and drawbacks
▶ Main advantage: since Linux and U-Boot are both loaded to RAM,
U-Boot’s Falcon Mode mainly saves time by directly loading Linux from the SPL
instead of loading and executing the full U-Boot first.
▶ Drawback: you lose the flexibility brought by the full U-Boot. You have to follow
a special procedure to update the kernel binary, DTB and kernel command line
parameters.
▶ Advantage: the interactivity offered by the full U-Boot is not necessary on a
production device. Falcon boot works in the same way on all SoCs on which
U-Boot SPL is supported. This makes it easier to apply this technique on all your
projects!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 6/28
What U-Boot does (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/28
What U-Boot does (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 8/28
Falcon mode usage overview (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 9/28
Falcon mode usage overview (2)
Continued...
▶ Have U-Boot execute the preprocessing before booting Linux, but stop right
before doing it:
spl export fdt <kernel-addr> <initramfs-addr> <dtb-addr>
▶ Save the exported data (ARGS) from RAM to storage, in Flattened Device Tree
form, so that the SPL can load it and directly pass it to the Linux kernel. The
below environment variables will help:
▶ fdtargsaddr: location of ARGS in RAM
▶ fdtargslen: size of ARGS in RAM
▶ If supported by your board (code explanations given later), set your boot_os
environment variable to yes/Yes/true/True/1 to enable direct OS booting.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 10/28
spl export example output
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 11/28
How to create the uImage file
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 12/28
U-Boot code changes to support a new board (1)
Your board/<vendor>/<board>/<board>.c file must at least
implement the spl_start_uboot() function.
Here’s the most typical example:
#ifdef CONFIG_SPL_OS_BOOT
int spl_start_uboot(void)
{
if (CONFIG_IS_ENABLED(SPL_SERIAL_SUPPORT) && serial_tstc() && serial_getc() == 'c')
/* break into full u-boot on 'c' */
return 1;
if (CONFIG_IS_ENABLED(SPL_ENV_SUPPORT)) {
env_init();
env_load();
if (env_get_yesno("boot_os") != 1)
return 1;
}
return 0;
}
#endif
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 13/28
U-Boot code changes to support a new board (2)
return 0;
}
#endif
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 14/28
U-Boot code changes to support a new board (3)
#ifdef CONFIG_SPL_OS_BOOT
int spl_start_uboot(void)
{
return 0;
}
#endif
You may also need extra defines to be set, but you will find which ones are missing at
compile time.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 15/28
How to fall back to U-Boot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 16/28
Booting from raw MMC - Proposed storage layout
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 17/28
Booting from raw MMC - Configuration
include/configs/sama5d3_xplained.h
#define CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR 0x100 /* 256 KiB */
#define CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS (CONFIG_CMD_SPL_WRITE_SIZE / 512)
#define CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR 0x1000 /* 2 MiB */
#define CONFIG_SYS_SPL_ARGS_ADDR 0x22000000
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 18/28
Booting from Raw MMC - Writing to raw storage
On your U-Boot target,
after spl export:
▶ Select the right MMC
device for mmc write:
=> mmc list
On your GNU/Linux host: Atmel mci: 0 (SD)
▶ Write U-Boot (using the same block size as Atmel mci: 1
sector size, to get the same offsets):
sudo dd if=u-boot.img of=/dev/sdc bs=512\ => mmc dev 0
seek=512 conv=sync switch to partitions #0, OK
mmc0 is current device
▶ Write uImage:
▶ Check the size of ARGS
sudo dd if=uImage of=/dev/sdc bs=512 \
seek=4096 conv=sync => printenv fdtargslen
▶ Reminder: in our case (SAMA5D36), the SPL is ▶ Divide it by the sector size (512), and convert it
copied to boot.bin in a FAT partition. to hexadecimal (round it up), and use the value
to save the ARGS to raw MMC:
=> mmc write ${fdtargsaddr} 0x100 0x67
▶ Caution: the last argument of mmc write is a
number of sectors. If you pass a number of
bytes, you’ll erase your FAT partition!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 19/28
Booting from Raw MMC - Results and notes
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 20/28
Booting from raw NAND - Configuration
U-Boot configuration
Proposed NAND layout
CONFIG_SPL_OS_BOOT=y
For use on Microchip SAMA5D3 Xplained
SPL_SIZE_LIMIT=0x10000
CONFIG_ENV_OFFSET=0x160000
Offset Size Contents CONFIG_ENV_OFFSET_REDUND=0x140000
0x0 256 KiB SPL (spl/u-boot-spl.bin) CONFIG_SPL_LEGACY_IMAGE_SUPPORT=y
0x40000 1 MiB U-Boot (u-boot.bin)
CONFIG_SPL_NAND_SUPPORT=y
0x140000 128 KiB U-Boot redundant environment
CONFIG_SPL_NAND_DRIVERS=y
0x160000 128 KiB U-Boot environment
0x180000 128 KiB Original DTB or CMD
CONFIG_SPL_NAND_BASE=y
0x1a0000 6.375 MiB uImage CONFIG_CMD_SPL_WRITE_SIZE=0x7000
0x800000 Other partitions CONFIG_CMD_SPL_NAND_OFS=0x180000
(starting from
sama5d3_xplained_nandflash_defconfig)
Notes:
▶ Only the SPL offset is hardcoded include/configs/sama5d3_xplained.h
▶ All others can be configured differently /* Generic settings */
#define CONFIG_SYS_NAND_U_BOOT_OFFS 0x40000
▶ Offsets must be a multiple of the erase block
/* Falcon boot support on raw NAND */
size (128 KiB) #define CONFIG_SYS_NAND_SPL_KERNEL_OFFS 0x1a0000
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 21/28
Booting from raw NAND - Results and notes
▶ Reference test
▶ To be fair, using a zero bootdelay and the exact zImage and dtb size:
setenv bootdelay 0
setenv bootcmd 'nand read 0x21000000 0x1a0000 0x53ac00; nand read
0x22000000 0x180000 0x6c93; bootz 0x21000000 - 0x22000000'
▶ Best result (using grabserial):
[4.320618 0.000470] Please press Enter to activate this console.
▶ Falcon boot test
▶ Best result (using grabserial):
[3.768543 0.000125] Please press Enter to activate this console.
▶ We saved 552 ms!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 22/28
U-Boot code and debugging Falcon Mode
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 23/28
Issues and lessons learned (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 24/28
Issues and lessons learned (2)
▶ Limited automation: while the uImage file can be updated automatically in the
storage image, any change in the kernel command line or Device Tree must go
through the spl export command on the board. The FDT fixups done by
U-Boot are not trivial to reproduce. This makes it difficult to prepare production
images without a manual step in U-Boot.
▶ No decompression: U-Boot currently doesn’t seem to support decompression in
the SPL. If your architecture doesn’t support kernel self-decompression and relies
on the bootloader (e.g. arm64 or riscv), Falcon mode won’t be available.
▶ Side note: Found that U-Boot’s bootm was noticeably slower than bootz (+170
ms)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 25/28
Further work
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 26/28
References
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 27/28
This Is How You Win the Time War
Questions?
Suggestions?
Comments?
Michael Opdenacker
[email protected]
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 28/28