Difference between revisions of "U-Boot"
| (11 intermediate revisions by the same user not shown) | |||
| Line 12: | Line 12: | ||
* ITB {{Todo|???}} | * ITB {{Todo|???}} | ||
* FIT (Flat Image Tree) {{Todo|Enhance}} | * FIT (Flat Image Tree) {{Todo|Enhance}} | ||
| + | |||
| + | === Boot sequence === | ||
| + | |||
| + | # Device's built-in boot code is executed (BootROM) | ||
| + | ## It searches connected storage devices for a bootloader signature at a predefined address | ||
| + | ## If found it loads the bootloader into SRAM and executes it | ||
| + | # TPL does minimal initialization, loads and executes SPL | ||
| + | # SPL does more extended initialization, loads and executes U-Boot | ||
| + | # U-Boot finishes initialization, provides a command prompt / searches for OS images / boots them | ||
| + | {{Todo|Verify TPL vs SPL}} | ||
| + | |||
| + | === Distro Boot === | ||
| + | Source: [https://gitlab.denx.de/u-boot/u-boot/-/blob/master/doc/README.distro README.distro] [https://developer.toradex.com/knowledge-base/distro-boot-linux] | ||
| + | |||
| + | Standardized way of booting a [[Linux distribution]] from U-Boot, without needing to build the distribution specifically for the target device. A distribution needs to provide its own generic bootloader, e.g. [[syslinux]] (extlinux). | ||
| + | |||
| + | Enabled by: <code>CONFIG_DISTRO_DEFAULTS=y</code> | ||
| + | |||
| + | ==== Devices order ==== | ||
| + | # Internal flash storage (e.g. eMMC) | ||
| + | # External flash storage (e.g. SD card) | ||
| + | # USB storage | ||
| + | # Network storage obtained from DHCP | ||
| + | |||
| + | Note that the first two might be swapped, depending on the configuration. Often it makes more sense to give priority to a removable media before booting from the internal storage. | ||
| + | |||
| + | For each of these devices, U-Boot will search in the first partition marked with a bootable flag (via the MBR bootable flag, or GPT legacy_bios_bootable attribute). In its absence, it will fall back to looking at the first valid partition. Disto Boot recognizes FAT and ext2/3/4 filesystems. | ||
| + | |||
| + | ==== Boot configuration file ==== | ||
| + | U-Boot searches for {{code|/extlinux/extlinux.conf}} then {{code|/boot/extlinux/extlinux.conf}} on disk, or {{code|pxelinux.cfg/default}} over the network. The content is as recognized by [[syslinux]] (extlinux). It also supports its own {{code|bootcmd}} format in {{code|boot.scr}} file. | ||
| + | |||
| + | After U-Boot has found a {{code|boot.scr}} (in absence of an {{code|extlinux.conf}}), it will simply execute its contents in the U-Boot shell. This means that you can (and should only) use any U-Boot command to customize your boot process. This is specially convenient if you want to circumvent the limitations of the {{code|extlinux.conf}} approach. | ||
| + | |||
| + | U-Boot boot scripts {{code|boot.scr}} are created via {{code|mkimage}} command from a {{code|boot.cmd}} file. | ||
| + | |||
| + | ===== Examples ===== | ||
| + | {{code|/boot/extlinux/extlinux.conf}} | ||
| + | <pre class="wm-collapsible wm-collapsed"> | ||
| + | ui menu.c32 | ||
| + | |||
| + | menu autoboot Arch Boot. Automatic boot in # second{,s}. Press a key for options. | ||
| + | menu title Arch Boot Options. | ||
| + | menu hidden | ||
| + | |||
| + | timeout 50 | ||
| + | |||
| + | default Arch | ||
| + | |||
| + | label Arch | ||
| + | kernel /zImage | ||
| + | append root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait consoleblank=0 no_console_suspend=1 console=ttymxc0,115200n8 | ||
| + | fdtdir /dtbs | ||
| + | initrd /initramfs-linux.img | ||
| + | </pre> | ||
| + | |||
| + | {{code|boot.cmd}} | ||
| + | <pre class="wm-collapsible wm-collapsed"> | ||
| + | setenv bootargs console=ttymxc0,115200 quiet video=mxcfb0:dev=hdmi,640x480@60,if=RGB24 video=mxcfb1:dev=lcd,640x480@60,if=RGB666 rootfstype=squashfs root=/dev/ram autoinstall ${teziargs} | ||
| + | |||
| + | # Reenable fdt relocation since in place fdt edits corrupt the ramdisk | ||
| + | # in a FIT image... | ||
| + | setenv fdt_high | ||
| + | |||
| + | # Load FIT image from location as detected by distroboot | ||
| + | load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} ${prefix}tezi.itb | ||
| + | |||
| + | bootm ${ramdisk_addr_r} | ||
| + | </pre> | ||
| + | |||
| + | {{code|boot.scr}} is generated via e.g.: {{code|mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Distro Boot Script" -d boot.cmd boot.scr}} | ||
== Related == | == Related == | ||
| Line 18: | Line 88: | ||
== External == | == External == | ||
| + | * Repository: [https://gitlab.denx.de/u-boot/u-boot/] | ||
| + | ** Distro boot doc [https://gitlab.denx.de/u-boot/u-boot/-/blob/master/doc/README.distro] | ||
* Presentation of U-Boot and porting to devices [https://bootlin.com/pub/conferences/2015/captronic/captronic-porting-linux-on-arm.pdf] | * Presentation of U-Boot and porting to devices [https://bootlin.com/pub/conferences/2015/captronic/captronic-porting-linux-on-arm.pdf] | ||
* Get More out of U-Boot (introduction, partitioning, etc.) [https://github.com/umiddelb/armhf/wiki/Get-more-out-of-%22Das-U-Boot%22] | * Get More out of U-Boot (introduction, partitioning, etc.) [https://github.com/umiddelb/armhf/wiki/Get-more-out-of-%22Das-U-Boot%22] | ||
* Presentation on TPL: SPL loading SPL (and what is SPL?) [http://www.denx.de/wiki/pub/U-Boot/MiniSummitELCE2013/tpl-presentation.pdf] | * Presentation on TPL: SPL loading SPL (and what is SPL?) [http://www.denx.de/wiki/pub/U-Boot/MiniSummitELCE2013/tpl-presentation.pdf] | ||
| + | * Distro boot Linux: [https://developer.toradex.com/knowledge-base/distro-boot-linux] | ||
| + | * Syslinux/Extlinux [https://wiki.syslinux.org/wiki/index.php?title=SYSLINUX] | ||
| + | ** menu.c32 [https://wiki.syslinux.org/wiki/index.php?title=Comboot/menu.c32] | ||
Latest revision as of 20:47, 28 March 2020
Linux friendly bootloader. Used in various ARM devices like PinePhone and Orange Pi.
Contents
Boot process
Definitions
General
- SPL (Secondary Program Loader) is a small binary, generated from U-Boot source, that fits in the SRAM and loads the main U-Boot into system RAM. [1]
- TPL (Tertiary Program Loader) is a tiny SPL which loads moderate-sized middle layer called TPL and that loads the full U-Boot into RAM.
Board-specific
- ATF (ARM Trusted Firmware)
Device Tree
- DTB (Device Tree Blob) TODO: Enhance
- ITB TODO: ???
- FIT (Flat Image Tree) TODO: Enhance
Boot sequence
- Device's built-in boot code is executed (BootROM)
- It searches connected storage devices for a bootloader signature at a predefined address
- If found it loads the bootloader into SRAM and executes it
- TPL does minimal initialization, loads and executes SPL
- SPL does more extended initialization, loads and executes U-Boot
- U-Boot finishes initialization, provides a command prompt / searches for OS images / boots them
TODO: Verify TPL vs SPL
Distro Boot
Source: README.distro [2]
Standardized way of booting a Linux distribution from U-Boot, without needing to build the distribution specifically for the target device. A distribution needs to provide its own generic bootloader, e.g. syslinux (extlinux).
Enabled by: CONFIG_DISTRO_DEFAULTS=y
Devices order
- Internal flash storage (e.g. eMMC)
- External flash storage (e.g. SD card)
- USB storage
- Network storage obtained from DHCP
Note that the first two might be swapped, depending on the configuration. Often it makes more sense to give priority to a removable media before booting from the internal storage.
For each of these devices, U-Boot will search in the first partition marked with a bootable flag (via the MBR bootable flag, or GPT legacy_bios_bootable attribute). In its absence, it will fall back to looking at the first valid partition. Disto Boot recognizes FAT and ext2/3/4 filesystems.
Boot configuration file
U-Boot searches for /extlinux/extlinux.conf then /boot/extlinux/extlinux.conf on disk, or pxelinux.cfg/default over the network. The content is as recognized by syslinux (extlinux). It also supports its own bootcmd format in boot.scr file.
After U-Boot has found a boot.scr (in absence of an extlinux.conf), it will simply execute its contents in the U-Boot shell. This means that you can (and should only) use any U-Boot command to customize your boot process. This is specially convenient if you want to circumvent the limitations of the extlinux.conf approach.
U-Boot boot scripts boot.scr are created via mkimage command from a boot.cmd file.
Examples
/boot/extlinux/extlinux.conf
ui menu.c32
menu autoboot Arch Boot. Automatic boot in # second{,s}. Press a key for options.
menu title Arch Boot Options.
menu hidden
timeout 50
default Arch
label Arch
kernel /zImage
append root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait consoleblank=0 no_console_suspend=1 console=ttymxc0,115200n8
fdtdir /dtbs
initrd /initramfs-linux.img
boot.cmd
setenv bootargs console=ttymxc0,115200 quiet video=mxcfb0:dev=hdmi,640x480@60,if=RGB24 video=mxcfb1:dev=lcd,640x480@60,if=RGB666 rootfstype=squashfs root=/dev/ram autoinstall ${teziargs}
# Reenable fdt relocation since in place fdt edits corrupt the ramdisk
# in a FIT image...
setenv fdt_high
# Load FIT image from location as detected by distroboot
load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} ${prefix}tezi.itb
bootm ${ramdisk_addr_r}
boot.scr is generated via e.g.: mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Distro Boot Script" -d boot.cmd boot.scr