1 .. SPDX-License-Identifier: GPL-2.0+
3 Generic Distro Configuration Concept
4 ====================================
6 Linux distributions are faced with supporting a variety of boot mechanisms,
7 environments or bootloaders (PC BIOS, EFI, U-Boot, Barebox, ...). This makes
8 life complicated. Worse, bootloaders such as U-Boot have a configurable set
9 of features, and each board chooses to enable a different set of features.
10 Hence, distros typically need to have board-specific knowledge in order to
11 set up a bootable system.
13 This document defines a common set of U-Boot features that are required for
14 a distro to support the board in a generic fashion. Any board wishing to
15 allow distros to install and boot in an out-of-the-box fashion should enable
16 all these features. Linux distros can then create a single set of boot
17 support/install logic that targets these features. This will allow distros
18 to install on many boards without the need for board-specific logic.
20 In fact, some of these features can be implemented by any bootloader, thus
21 decoupling distro install/boot logic from any knowledge of the bootloader.
23 This model assumes that boards will load boot configuration files from a
24 regular storage mechanism (eMMC, SD card, USB Disk, SATA disk, etc.) with
25 a standard partitioning scheme (MBR, GPT). Boards that cannot support this
26 storage model are outside the scope of this document, and may still need
27 board-specific installer/boot-configuration support in a distro.
29 To some extent, this model assumes that a board has a separate boot flash
30 that contains U-Boot, and that the user has somehow installed U-Boot to this
31 flash before running the distro installer. Even on boards that do not conform
32 to this aspect of the model, the extent of the board-specific support in the
33 distro installer logic would be to install a board-specific U-Boot package to
34 the boot partition during installation. This distro-supplied U-Boot can still
35 implement the same features as on any other board, and hence the distro's boot
36 configuration file generation logic can still be board-agnostic.
38 Locating Bootable Disks
39 -----------------------
41 Typical desktop/server PCs search all (or a user-defined subset of) attached
42 storage devices for a bootable partition, then load the bootloader or boot
43 configuration files from there. A U-Boot board port that enables the features
44 mentioned in this document will search for boot configuration files in the
47 Thus, distros do not need to manipulate any kind of bootloader-specific
48 configuration data to indicate which storage device the system should boot
51 Distros simply need to install the boot configuration files (see next
52 section) in an ext2/3/4 or FAT partition, mark the partition bootable (via
53 the MBR bootable flag, or GPT legacy_bios_bootable attribute), and U-Boot (or
54 any other bootloader) will find those boot files and execute them. This is
55 conceptually identical to creating a grub2 configuration file on a desktop
58 Note that in the absence of any partition that is explicitly marked bootable,
59 U-Boot falls back to searching the first valid partition of a disk for boot
60 configuration files. Other bootloaders are recommended to do the same, since
61 I believe that partition table bootable flags aren't so commonly used outside
64 U-Boot can also search for boot configuration files from a TFTP server.
66 Boot Configuration Files
67 ------------------------
69 The standard format for boot configuration files is that of extlinux.conf, as
70 handled by U-Boot's "syslinux" (disk) or "pxe boot" (network). This is roughly
71 as specified at BootLoaderSpec_:
74 ... with the exceptions that the BootLoaderSpec document:
76 * Prescribes a separate configuration per boot menu option, whereas U-Boot
77 lumps all options into a single extlinux.conf file. Hence, U-Boot searches
78 for /extlinux/extlinux.conf then /boot/extlinux/extlinux.conf on disk, or
79 pxelinux.cfg/default over the network.
81 * Does not document the fdtdir option, which automatically selects the DTB to
84 One example extlinux.conf generated by the Fedora installer is::
86 # extlinux.conf generated by anaconda
90 menu autoboot Welcome to Fedora. Automatic boot in # second{,s}. Press a key for options.
91 menu title Fedora Boot Options.
97 default Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae) 22 (Rawhide)
99 label Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl) 22 (Rawhide)
100 kernel /boot/vmlinuz-3.17.0-0.rc4.git2.1.fc22.armv7hl
101 append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 console=ttyS0,115200n8 LANG=en_US.UTF-8 drm.debug=0xf
102 fdtdir /boot/dtb-3.17.0-0.rc4.git2.1.fc22.armv7hl
103 initrd /boot/initramfs-3.17.0-0.rc4.git2.1.fc22.armv7hl.img
105 label Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae) 22 (Rawhide)
106 kernel /boot/vmlinuz-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae
107 append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 console=ttyS0,115200n8 LANG=en_US.UTF-8 drm.debug=0xf
108 fdtdir /boot/dtb-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae
109 initrd /boot/initramfs-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae.img
111 label Fedora-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc (0-rescue-8f6ba7b039524e0eb957d2c9203f04bc)
112 kernel /boot/vmlinuz-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc
113 initrd /boot/initramfs-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc.img
114 append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 console=ttyS0,115200n8
115 fdtdir /boot/dtb-3.16.0-0.rc6.git1.1.fc22.armv7hl+lpae
118 Another hand-crafted network boot configuration file is::
122 MENU TITLE TFTP boot options
124 LABEL jetson-tk1-emmc
125 MENU LABEL ../zImage root on Jetson TK1 eMMC
128 APPEND console=ttyS0,115200n8 console=tty1 loglevel=8 rootwait rw earlyprintk root=PARTUUID=80a5a8e9-c744-491a-93c1-4f4194fd690b
131 MENU LABEL ../zImage root on Venice2 eMMC
134 APPEND console=ttyS0,115200n8 console=tty1 loglevel=8 rootwait rw earlyprintk root=PARTUUID=5f71e06f-be08-48ed-b1ef-ee4800cc860f
137 MENU LABEL ../zImage, root on 2GB sdcard
140 APPEND console=ttyS0,115200n8 console=tty1 loglevel=8 rootwait rw earlyprintk root=PARTUUID=b2f82cda-2535-4779-b467-094a210fbae7
142 LABEL fedora-installer-fk
143 MENU LABEL Fedora installer w/ Fedora kernel
144 LINUX fedora-installer/vmlinuz
145 INITRD fedora-installer/initrd.img.orig
146 FDTDIR fedora-installer/dtb
147 APPEND loglevel=8 ip=dhcp inst.repo=http://10.0.0.2/mirrors/fedora/linux/development/rawhide/armhfp/os/ rd.shell cma=64M
149 U-Boot Implementation
150 =====================
152 Enabling the distro options
153 ---------------------------
155 In your board's defconfig, enable the DISTRO_DEFAULTS option by adding
156 a line with "CONFIG_DISTRO_DEFAULTS=y". If you want to enable this
157 from Kconfig itself, for e.g. all boards using a specific SoC then
158 add a "imply DISTRO_DEFAULTS" to your SoC CONFIG option.
163 In your board configuration file, include the following::
165 #ifndef CONFIG_SPL_BUILD
166 #include <config_distro_bootcmd.h>
169 The first of those headers primarily enables a core set of U-Boot features,
170 such as support for MBR and GPT partitions, ext* and FAT filesystems, booting
171 raw zImage and initrd (rather than FIT- or uImage-wrapped files), etc. Network
172 boot support is also enabled here, which is useful in order to boot distro
173 installers given that distros do not commonly distribute bootable install
174 media for non-PC targets at present.
176 Finally, a few options that are mostly relevant only when using U-Boot-
177 specific boot.scr scripts are enabled. This enables distros to generate a
178 U-Boot-specific boot.scr script rather than extlinux.conf as the boot
179 configuration file. While doing so is fully supported, and
180 CONFIG_DISTRO_DEFAULTS exposes enough parameterization to boot.scr to
181 allow for board-agnostic boot.scr content, this document recommends that
182 distros generate extlinux.conf rather than boot.scr. extlinux.conf is intended
183 to work across multiple bootloaders, whereas boot.scr will only work with
184 U-Boot. TODO: document the contract between U-Boot and boot.scr re: which
185 environment variables a generic boot.scr may rely upon.
187 The second of those headers sets up the default environment so that $bootcmd
188 is defined in a way that searches attached disks for boot configuration files,
189 and executes them if found.
191 Required Environment Variables
192 ------------------------------
194 The U-Boot "syslinux" and "pxe boot" commands require a number of environment
195 variables be set. Default values for these variables are often hard-coded into
196 CONFIG_EXTRA_ENV_SETTINGS in the board's U-Boot configuration file, so that
197 the user doesn't have to configure them.
200 Mandatory for any system that provides the DTB in HW (e.g. ROM) and wishes
201 to pass that DTB to Linux, rather than loading a DTB from the boot
202 filesystem. Prohibited for any other system.
204 If specified a DTB to boot the system must be available at the given
208 Mandatory. The location in RAM where the DTB will be loaded or copied to when
209 processing the fdtdir/devicetreedir or fdt/devicetree options in
212 This is mandatory even when fdt_addr is provided, since extlinux.conf must
213 always be able to provide a DTB which overrides any copy provided by the HW.
215 A size of 1MB for the FDT/DTB seems reasonable.
218 Mandatory. the name of the DTB file for the specific board for instance
219 the espressobin v5 board the value is "marvell/armada-3720-espressobin.dtb"
220 while on a clearfog pro it is "armada-388-clearfog-pro.dtb" in the case of
221 a board providing its firmware based DTB this value can be used to override
222 the DTB with a different DTB. fdtfile will automatically be set for you if
223 it matches the format ${soc}-${board}.dtb which covers most 32 bit use cases.
224 AArch64 generally does not match as the Linux kernel put the dtb files under
225 SoC vendor directories.
228 Mandatory. The location in RAM where the initial ramdisk will be loaded to
229 when processing the initrd option in extlinux.conf.
231 It is recommended that this location be highest in RAM out of fdt_addr_r,
232 kernel_addr_r, and ramdisk_addr_r, so that the RAM disk can vary in size
233 and use any available RAM.
236 Mandatory. The location in RAM where the kernel will be loaded to when
237 processing the kernel option in the extlinux.conf.
239 The kernel should be located within the first 128M of RAM in order for the
240 kernel CONFIG_AUTO_ZRELADDR option to work, which is likely enabled on any
241 distro kernel. Since the kernel will decompress itself to 0x8000 after the
242 start of RAM, kernel_addr_r should not overlap that area, or the kernel will
243 have to copy itself somewhere else first before decompression.
245 A size of 16MB for the kernel is likely adequate.
248 Optional. This is only required if user wants to boot Linux from a compressed
249 Image(.gz, .bz2, .lzma, .lzo) using the booti command. It represents the
250 location in RAM where the compressed Image will be decompressed temporarily.
251 Once the decompression is complete, the decompressed data will be moved to
252 kernel_addr_r for booting.
255 Optional. This is only required if user wants to boot Linux from a compressed
256 Image using booti command. It represents the size of the compressed file. The
257 size has to at least the size of loaded image for decompression to succeed.
260 Mandatory. The location in RAM where extlinux.conf will be loaded to prior
263 A size of 1MB for extlinux.conf is more than adequate.
266 Mandatory, if the boot script is boot.scr rather than extlinux.conf. The
267 location in RAM where boot.scr will be loaded to prior to execution.
269 A size of 1MB for extlinux.conf is more than adequate.
271 For suggestions on memory locations for ARM systems, you must follow the
272 guidelines specified in Documentation/arm/Booting in the Linux kernel tree.
274 For a commented example of setting these values, please see the definition of
275 MEM_LAYOUT_ENV_SETTINGS in include/configs/tegra124-common.h.
277 Boot Target Configuration
278 -------------------------
280 The `config_distro_bootcmd.h` file defines $bootcmd and many helper command
281 variables that automatically search attached disks for boot configuration files
282 and execute them. Boards must provide configure <config_distro_bootcmd.h> so
283 that it supports the correct set of possible boot device types. To provide this
284 configuration, simply define macro BOOT_TARGET_DEVICES prior to including
285 <config_distro_bootcmd.h>. For example::
287 #ifndef CONFIG_SPL_BUILD
288 #define BOOT_TARGET_DEVICES(func) \
294 #include <config_distro_bootcmd.h>
297 Each entry in the macro defines a single boot device (e.g. a specific eMMC
298 device or SD card) or type of boot device (e.g. USB disk). The parameters to
299 the func macro (passed in by the internal implementation of the header) are:
301 - Upper-case disk type (DHCP, HOST, IDE, MMC, NVME, PXE, SATA, SCSI, UBIFS, USB,
303 - Lower-case disk type (same options as above).
304 - ID of the specific disk (MMC only) or ignored for other types.
309 Once the user has installed U-Boot, it is expected that the environment will
310 be reset to the default values in order to enable $bootcmd and friends, as set
311 up by <config_distro_bootcmd.h>. After this, various environment variables may
312 be altered to influence the boot process:
315 The list of boot locations searched.
317 Example: mmc0, mmc1, usb, pxe
319 Entries may be removed or re-ordered in this list to affect the boot order.
322 For disk-based booting, the list of directories within a partition that are
323 searched for boot configuration files (extlinux.conf, boot.scr).
327 Entries may be removed or re-ordered in this list to affect the set of
328 directories which are searched.
331 The name of U-Boot style boot.scr files that $bootcmd searches for.
333 Example: boot.scr.uimg boot.scr
335 (Typically we expect extlinux.conf to be used, but execution of boot.scr is
336 maintained for backwards-compatibility.)
338 Entries may be removed or re-ordered in this list to affect the set of
339 filenames which are supported.
341 scan_dev_for_extlinux:
342 If you want to disable extlinux.conf on all disks, set the value to something
343 innocuous, e.g. setenv scan_dev_for_extlinux true.
345 scan_dev_for_scripts:
346 If you want to disable boot.scr on all disks, set the value to something
347 innocuous, e.g. setenv scan_dev_for_scripts true.
350 If you want to prevent USB enumeration by distro boot commands which execute
351 network operations, set the value to something innocuous, e.g. setenv
352 boot_net_usb_start true. This would be useful if you know your Ethernet
353 device is not attached to USB, and you wish to increase boot speed by
354 avoiding unnecessary actions.
357 If you want to prevent PCI enumeration by distro boot commands which execute
358 network operations, set the value to something innocuous, e.g. setenv
359 boot_net_pci_enum true. This would be useful if you know your Ethernet
360 device is not attached to PCI, and you wish to increase boot speed by
361 avoiding unnecessary actions.
363 Interactively booting from a specific device at the u-boot prompt
364 =================================================================
366 For interactively booting from a user-selected device at the u-boot command
367 prompt, the environment provides predefined bootcmd_<target> variables for
368 every target defined in boot_targets, which can be run be the user.
370 If the target is a storage device, the format of the target is always
371 <device type><device number>, e.g. mmc0. Specifying the device number is
372 mandatory for storage devices, even if only support for a single instance
373 of the storage device is actually implemented.
375 For network targets (dhcp, pxe), only the device type gets specified;
376 they do not have a device number.
381 boots from the first USB mass storage device
384 boots from the second MMC device
387 boots by tftp using a pxelinux.cfg
389 The list of possible targets consists of:
396 - storage targets (to which a device number must be appended)
405 Other *boot* variables than the ones defined above are only for internal use
406 of the boot environment and are not guaranteed to exist or work in the same
407 way in future u-boot versions. In particular the <device type>_boot
408 variables (e.g. mmc_boot, usb_boot) are a strictly internal implementation
409 detail and must not be used as a public interface.
411 .. _BootLoaderSpec: http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/
413 .. sectionauthor:: (C) Copyright 2014 Red Hat Inc.
414 .. sectionauthor:: Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
415 .. sectionauthor:: Copyright (C) 2015 K. Merker <merker@debian.org>