]> Git Repo - J-u-boot.git/blame - doc/develop/distro.rst
Merge patch series "net: ksz9477: add support for KSZ GbE switches using SPI bus"
[J-u-boot.git] / doc / develop / distro.rst
CommitLineData
37c5195d 1.. SPDX-License-Identifier: GPL-2.0+
ffb4f6f9
DG
2
3Generic Distro Configuration Concept
4====================================
5
6Linux distributions are faced with supporting a variety of boot mechanisms,
7environments or bootloaders (PC BIOS, EFI, U-Boot, Barebox, ...). This makes
8life complicated. Worse, bootloaders such as U-Boot have a configurable set
9of features, and each board chooses to enable a different set of features.
10Hence, distros typically need to have board-specific knowledge in order to
11set up a bootable system.
12
13This document defines a common set of U-Boot features that are required for
14a distro to support the board in a generic fashion. Any board wishing to
15allow distros to install and boot in an out-of-the-box fashion should enable
16all these features. Linux distros can then create a single set of boot
17support/install logic that targets these features. This will allow distros
18to install on many boards without the need for board-specific logic.
19
20In fact, some of these features can be implemented by any bootloader, thus
21decoupling distro install/boot logic from any knowledge of the bootloader.
22
23This model assumes that boards will load boot configuration files from a
24regular storage mechanism (eMMC, SD card, USB Disk, SATA disk, etc.) with
28fd00b7 25a standard partitioning scheme (MBR, GPT). Boards that cannot support this
ffb4f6f9
DG
26storage model are outside the scope of this document, and may still need
27board-specific installer/boot-configuration support in a distro.
28
29To some extent, this model assumes that a board has a separate boot flash
30that contains U-Boot, and that the user has somehow installed U-Boot to this
31flash before running the distro installer. Even on boards that do not conform
32to this aspect of the model, the extent of the board-specific support in the
33distro installer logic would be to install a board-specific U-Boot package to
28fd00b7
MY
34the boot partition during installation. This distro-supplied U-Boot can still
35implement the same features as on any other board, and hence the distro's boot
36configuration file generation logic can still be board-agnostic.
ffb4f6f9
DG
37
38Locating Bootable Disks
39-----------------------
40
41Typical desktop/server PCs search all (or a user-defined subset of) attached
42storage devices for a bootable partition, then load the bootloader or boot
43configuration files from there. A U-Boot board port that enables the features
44mentioned in this document will search for boot configuration files in the
45same way.
46
47Thus, distros do not need to manipulate any kind of bootloader-specific
48configuration data to indicate which storage device the system should boot
49from.
50
51Distros simply need to install the boot configuration files (see next
52section) in an ext2/3/4 or FAT partition, mark the partition bootable (via
53the MBR bootable flag, or GPT legacy_bios_bootable attribute), and U-Boot (or
54any other bootloader) will find those boot files and execute them. This is
55conceptually identical to creating a grub2 configuration file on a desktop
56PC.
57
28fd00b7 58Note that in the absence of any partition that is explicitly marked bootable,
ffb4f6f9
DG
59U-Boot falls back to searching the first valid partition of a disk for boot
60configuration files. Other bootloaders are recommended to do the same, since
61I believe that partition table bootable flags aren't so commonly used outside
62the realm of x86 PCs.
63
64U-Boot can also search for boot configuration files from a TFTP server.
65
66Boot Configuration Files
67------------------------
68
69The standard format for boot configuration files is that of extlinux.conf, as
70handled by U-Boot's "syslinux" (disk) or "pxe boot" (network). This is roughly
35821a25 71as specified at `Boot Loader Specification`_:
ffb4f6f9 72
ffb4f6f9 73
35821a25 74... with the exceptions that the Boot Loader Specification document:
ffb4f6f9
DG
75
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.
80
81* Does not document the fdtdir option, which automatically selects the DTB to
82 pass to the kernel.
83
c95e9488
SR
84* If no fdt/fdtdir is provided, the U-Boot will pass its own currently used
85 device tree.
86
87* If ``-`` is passed as fdt argument and ``CONFIG_SUPPORT_PASSING_ATAGS`` is
88 enabled, then no device tree will be used (legacy booting / pre-dtb kernel).
89
35821a25
ET
90See also doc/README.pxe under 'pxe file format'.
91
37c5195d 92One example extlinux.conf generated by the Fedora installer is::
ffb4f6f9 93
37c5195d 94 # extlinux.conf generated by anaconda
ffb4f6f9 95
37c5195d 96 ui menu.c32
ffb4f6f9 97
37c5195d
SG
98 menu autoboot Welcome to Fedora. Automatic boot in # second{,s}. Press a key for options.
99 menu title Fedora Boot Options.
100 menu hidden
ffb4f6f9 101
37c5195d
SG
102 timeout 50
103 #totaltimeout 9000
ffb4f6f9 104
37c5195d 105 default Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae) 22 (Rawhide)
ffb4f6f9 106
37c5195d
SG
107 label Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl) 22 (Rawhide)
108 kernel /boot/vmlinuz-3.17.0-0.rc4.git2.1.fc22.armv7hl
109 append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 console=ttyS0,115200n8 LANG=en_US.UTF-8 drm.debug=0xf
110 fdtdir /boot/dtb-3.17.0-0.rc4.git2.1.fc22.armv7hl
111 initrd /boot/initramfs-3.17.0-0.rc4.git2.1.fc22.armv7hl.img
ffb4f6f9 112
37c5195d
SG
113 label Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae) 22 (Rawhide)
114 kernel /boot/vmlinuz-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae
115 append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 console=ttyS0,115200n8 LANG=en_US.UTF-8 drm.debug=0xf
116 fdtdir /boot/dtb-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae
117 initrd /boot/initramfs-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae.img
ffb4f6f9 118
37c5195d
SG
119 label Fedora-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc (0-rescue-8f6ba7b039524e0eb957d2c9203f04bc)
120 kernel /boot/vmlinuz-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc
121 initrd /boot/initramfs-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc.img
122 append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 console=ttyS0,115200n8
123 fdtdir /boot/dtb-3.16.0-0.rc6.git1.1.fc22.armv7hl+lpae
ffb4f6f9 124
ffb4f6f9 125
35821a25
ET
126One example of hand-crafted extlinux.conf::
127
128 menu title Select kernel
129 timeout 100
130
131 label Arch with uart devicetree overlay
132 kernel /arch/Image.gz
133 initrd /arch/initramfs-linux.img
134 fdt /dtbs/arch/board.dtb
135 fdtoverlays /dtbs/arch/overlay/uart0-gpio0-1.dtbo
136 append console=ttyS0,115200 console=tty1 rw root=UUID=fc0d0284-ca84-4194-bf8a-4b9da8d66908
137
138 label Arch with uart devicetree overlay but with Boot Loader Specification keys
139 kernel /arch/Image.gz
140 initrd /arch/initramfs-linux.img
141 devicetree /dtbs/arch/board.dtb
142 devicetree-overlay /dtbs/arch/overlay/uart0-gpio0-1.dtbo
143 append console=ttyS0,115200 console=tty1 rw root=UUID=fc0d0284-ca84-4194-bf8a-4b9da8d66908
144
37c5195d 145Another hand-crafted network boot configuration file is::
ffb4f6f9 146
37c5195d 147 TIMEOUT 100
ffb4f6f9 148
37c5195d 149 MENU TITLE TFTP boot options
ffb4f6f9 150
37c5195d
SG
151 LABEL jetson-tk1-emmc
152 MENU LABEL ../zImage root on Jetson TK1 eMMC
153 LINUX ../zImage
154 FDTDIR ../
155 APPEND console=ttyS0,115200n8 console=tty1 loglevel=8 rootwait rw earlyprintk root=PARTUUID=80a5a8e9-c744-491a-93c1-4f4194fd690b
ffb4f6f9 156
37c5195d
SG
157 LABEL venice2-emmc
158 MENU LABEL ../zImage root on Venice2 eMMC
159 LINUX ../zImage
160 FDTDIR ../
161 APPEND console=ttyS0,115200n8 console=tty1 loglevel=8 rootwait rw earlyprintk root=PARTUUID=5f71e06f-be08-48ed-b1ef-ee4800cc860f
ffb4f6f9 162
37c5195d
SG
163 LABEL sdcard
164 MENU LABEL ../zImage, root on 2GB sdcard
165 LINUX ../zImage
166 FDTDIR ../
167 APPEND console=ttyS0,115200n8 console=tty1 loglevel=8 rootwait rw earlyprintk root=PARTUUID=b2f82cda-2535-4779-b467-094a210fbae7
168
169 LABEL fedora-installer-fk
170 MENU LABEL Fedora installer w/ Fedora kernel
171 LINUX fedora-installer/vmlinuz
172 INITRD fedora-installer/initrd.img.orig
173 FDTDIR fedora-installer/dtb
174 APPEND loglevel=8 ip=dhcp inst.repo=http://10.0.0.2/mirrors/fedora/linux/development/rawhide/armhfp/os/ rd.shell cma=64M
ffb4f6f9
DG
175
176U-Boot Implementation
177=====================
178
179Enabling the distro options
180---------------------------
181
9f823615
HG
182In your board's defconfig, enable the DISTRO_DEFAULTS option by adding
183a line with "CONFIG_DISTRO_DEFAULTS=y". If you want to enable this
184from Kconfig itself, for e.g. all boards using a specific SoC then
7325f6cf 185add a "imply DISTRO_DEFAULTS" to your SoC CONFIG option.
9f823615 186
e7b2ce19
SG
187
188TO BE UPDATED:
189
37c5195d 190In your board configuration file, include the following::
ffb4f6f9 191
1d6132e2 192 #ifndef CONFIG_XPL_BUILD
37c5195d
SG
193 #include <config_distro_bootcmd.h>
194 #endif
ffb4f6f9
DG
195
196The first of those headers primarily enables a core set of U-Boot features,
197such as support for MBR and GPT partitions, ext* and FAT filesystems, booting
198raw zImage and initrd (rather than FIT- or uImage-wrapped files), etc. Network
199boot support is also enabled here, which is useful in order to boot distro
200installers given that distros do not commonly distribute bootable install
201media for non-PC targets at present.
202
203Finally, a few options that are mostly relevant only when using U-Boot-
204specific boot.scr scripts are enabled. This enables distros to generate a
205U-Boot-specific boot.scr script rather than extlinux.conf as the boot
206configuration file. While doing so is fully supported, and
ba8bf948 207CONFIG_DISTRO_DEFAULTS exposes enough parameterization to boot.scr to
ffb4f6f9
DG
208allow for board-agnostic boot.scr content, this document recommends that
209distros generate extlinux.conf rather than boot.scr. extlinux.conf is intended
210to work across multiple bootloaders, whereas boot.scr will only work with
211U-Boot. TODO: document the contract between U-Boot and boot.scr re: which
212environment variables a generic boot.scr may rely upon.
213
214The second of those headers sets up the default environment so that $bootcmd
215is defined in a way that searches attached disks for boot configuration files,
216and executes them if found.
217
218Required Environment Variables
219------------------------------
220
221The U-Boot "syslinux" and "pxe boot" commands require a number of environment
222variables be set. Default values for these variables are often hard-coded into
0613c36a 223CFG_EXTRA_ENV_SETTINGS in the board's U-Boot configuration file, so that
ffb4f6f9
DG
224the user doesn't have to configure them.
225
226fdt_addr:
ffb4f6f9
DG
227 Mandatory for any system that provides the DTB in HW (e.g. ROM) and wishes
228 to pass that DTB to Linux, rather than loading a DTB from the boot
229 filesystem. Prohibited for any other system.
230
231 If specified a DTB to boot the system must be available at the given
232 address.
233
234fdt_addr_r:
ffb4f6f9
DG
235 Mandatory. The location in RAM where the DTB will be loaded or copied to when
236 processing the fdtdir/devicetreedir or fdt/devicetree options in
237 extlinux.conf.
238
239 This is mandatory even when fdt_addr is provided, since extlinux.conf must
240 always be able to provide a DTB which overrides any copy provided by the HW.
241
242 A size of 1MB for the FDT/DTB seems reasonable.
243
35821a25
ET
244fdtoverlay_addr_r:
245 Mandatory. The location in RAM where DTB overlays will be temporarily
246 stored and then applied in the load order to the fdt blob stored at the
247 address indicated in the fdt_addr_r environment variable.
248
74f8977e 249fdtfile:
74f8977e
DG
250 Mandatory. the name of the DTB file for the specific board for instance
251 the espressobin v5 board the value is "marvell/armada-3720-espressobin.dtb"
252 while on a clearfog pro it is "armada-388-clearfog-pro.dtb" in the case of
253 a board providing its firmware based DTB this value can be used to override
254 the DTB with a different DTB. fdtfile will automatically be set for you if
255 it matches the format ${soc}-${board}.dtb which covers most 32 bit use cases.
256 AArch64 generally does not match as the Linux kernel put the dtb files under
0a50b3c9 257 SoC vendor directories.
74f8977e 258
ffb4f6f9 259ramdisk_addr_r:
ffb4f6f9
DG
260 Mandatory. The location in RAM where the initial ramdisk will be loaded to
261 when processing the initrd option in extlinux.conf.
262
37c5195d 263 It is recommended that this location be highest in RAM out of fdt_addr_r,
ffb4f6f9
DG
264 kernel_addr_r, and ramdisk_addr_r, so that the RAM disk can vary in size
265 and use any available RAM.
266
267kernel_addr_r:
ffb4f6f9
DG
268 Mandatory. The location in RAM where the kernel will be loaded to when
269 processing the kernel option in the extlinux.conf.
270
271 The kernel should be located within the first 128M of RAM in order for the
272 kernel CONFIG_AUTO_ZRELADDR option to work, which is likely enabled on any
273 distro kernel. Since the kernel will decompress itself to 0x8000 after the
28fd00b7 274 start of RAM, kernel_addr_r should not overlap that area, or the kernel will
ffb4f6f9
DG
275 have to copy itself somewhere else first before decompression.
276
277 A size of 16MB for the kernel is likely adequate.
278
414c34ed
AP
279kernel_comp_addr_r:
280 Optional. This is only required if user wants to boot Linux from a compressed
3af8d1c4
HS
281 Image(.gz, .bz2, .lzma, .lzo) using the booti command. It represents the
282 location in RAM where the compressed Image will be decompressed temporarily.
283 Once the decompression is complete, the decompressed data will be moved to
284 kernel_addr_r for booting.
414c34ed
AP
285
286kernel_comp_size:
287 Optional. This is only required if user wants to boot Linux from a compressed
288 Image using booti command. It represents the size of the compressed file. The
289 size has to at least the size of loaded image for decompression to succeed.
290
7101c4ce 291pxefile_addr_r:
ffb4f6f9
DG
292 Mandatory. The location in RAM where extlinux.conf will be loaded to prior
293 to processing.
294
295 A size of 1MB for extlinux.conf is more than adequate.
296
297scriptaddr:
ffb4f6f9
DG
298 Mandatory, if the boot script is boot.scr rather than extlinux.conf. The
299 location in RAM where boot.scr will be loaded to prior to execution.
300
301 A size of 1MB for extlinux.conf is more than adequate.
302
303For suggestions on memory locations for ARM systems, you must follow the
304guidelines specified in Documentation/arm/Booting in the Linux kernel tree.
305
306For a commented example of setting these values, please see the definition of
307MEM_LAYOUT_ENV_SETTINGS in include/configs/tegra124-common.h.
308
309Boot Target Configuration
310-------------------------
311
37c5195d
SG
312The `config_distro_bootcmd.h` file defines $bootcmd and many helper command
313variables that automatically search attached disks for boot configuration files
314and execute them. Boards must provide configure <config_distro_bootcmd.h> so
315that it supports the correct set of possible boot device types. To provide this
ffb4f6f9 316configuration, simply define macro BOOT_TARGET_DEVICES prior to including
37c5195d
SG
317<config_distro_bootcmd.h>. For example::
318
1d6132e2 319 #ifndef CONFIG_XPL_BUILD
37c5195d
SG
320 #define BOOT_TARGET_DEVICES(func) \
321 func(MMC, mmc, 1) \
322 func(MMC, mmc, 0) \
323 func(USB, usb, 0) \
324 func(PXE, pxe, na) \
325 func(DHCP, dhcp, na)
326 #include <config_distro_bootcmd.h>
327 #endif
ffb4f6f9
DG
328
329Each entry in the macro defines a single boot device (e.g. a specific eMMC
330device or SD card) or type of boot device (e.g. USB disk). The parameters to
331the func macro (passed in by the internal implementation of the header) are:
332
2f5c9ad3
T
333- Upper-case disk type (DHCP, HOST, IDE, MMC, NVME, PXE, SATA, SCSI, UBIFS, USB,
334 VIRTIO).
ffb4f6f9
DG
335- Lower-case disk type (same options as above).
336- ID of the specific disk (MMC only) or ignored for other types.
337
338User Configuration
339==================
340
341Once the user has installed U-Boot, it is expected that the environment will
342be reset to the default values in order to enable $bootcmd and friends, as set
343up by <config_distro_bootcmd.h>. After this, various environment variables may
344be altered to influence the boot process:
345
346boot_targets:
ffb4f6f9
DG
347 The list of boot locations searched.
348
349 Example: mmc0, mmc1, usb, pxe
350
351 Entries may be removed or re-ordered in this list to affect the boot order.
352
353boot_prefixes:
ffb4f6f9
DG
354 For disk-based booting, the list of directories within a partition that are
355 searched for boot configuration files (extlinux.conf, boot.scr).
356
357 Example: / /boot/
358
359 Entries may be removed or re-ordered in this list to affect the set of
360 directories which are searched.
361
362boot_scripts:
ffb4f6f9
DG
363 The name of U-Boot style boot.scr files that $bootcmd searches for.
364
365 Example: boot.scr.uimg boot.scr
366
367 (Typically we expect extlinux.conf to be used, but execution of boot.scr is
368 maintained for backwards-compatibility.)
369
370 Entries may be removed or re-ordered in this list to affect the set of
371 filenames which are supported.
372
373scan_dev_for_extlinux:
ffb4f6f9
DG
374 If you want to disable extlinux.conf on all disks, set the value to something
375 innocuous, e.g. setenv scan_dev_for_extlinux true.
376
377scan_dev_for_scripts:
ffb4f6f9
DG
378 If you want to disable boot.scr on all disks, set the value to something
379 innocuous, e.g. setenv scan_dev_for_scripts true.
8c249290 380
3483b75d 381boot_net_usb_start:
3483b75d
SW
382 If you want to prevent USB enumeration by distro boot commands which execute
383 network operations, set the value to something innocuous, e.g. setenv
384 boot_net_usb_start true. This would be useful if you know your Ethernet
385 device is not attached to USB, and you wish to increase boot speed by
386 avoiding unnecessary actions.
8c249290 387
986691fb 388boot_net_pci_enum:
986691fb
SW
389 If you want to prevent PCI enumeration by distro boot commands which execute
390 network operations, set the value to something innocuous, e.g. setenv
391 boot_net_pci_enum true. This would be useful if you know your Ethernet
392 device is not attached to PCI, and you wish to increase boot speed by
393 avoiding unnecessary actions.
394
8c249290
KM
395Interactively booting from a specific device at the u-boot prompt
396=================================================================
397
398For interactively booting from a user-selected device at the u-boot command
399prompt, the environment provides predefined bootcmd_<target> variables for
400every target defined in boot_targets, which can be run be the user.
401
402If the target is a storage device, the format of the target is always
403<device type><device number>, e.g. mmc0. Specifying the device number is
404mandatory for storage devices, even if only support for a single instance
405of the storage device is actually implemented.
406
407For network targets (dhcp, pxe), only the device type gets specified;
408they do not have a device number.
409
410Examples:
411
412 - run bootcmd_usb0
413 boots from the first USB mass storage device
414
415 - run bootcmd_mmc1
416 boots from the second MMC device
417
418 - run bootcmd_pxe
419 boots by tftp using a pxelinux.cfg
420
421The list of possible targets consists of:
422
423- network targets
37c5195d 424
8c249290
KM
425 * dhcp
426 * pxe
427
428- storage targets (to which a device number must be appended)
37c5195d 429
8c249290
KM
430 * mmc
431 * sata
432 * scsi
433 * ide
434 * usb
a8da9ff4 435 * virtio
8c249290
KM
436
437Other *boot* variables than the ones defined above are only for internal use
438of the boot environment and are not guaranteed to exist or work in the same
439way in future u-boot versions. In particular the <device type>_boot
440variables (e.g. mmc_boot, usb_boot) are a strictly internal implementation
441detail and must not be used as a public interface.
37c5195d 442
35821a25 443.. _`Boot Loader Specification`: https://systemd.io/BOOT_LOADER_SPECIFICATION/
37c5195d
SG
444
445.. sectionauthor:: (C) Copyright 2014 Red Hat Inc.
446.. sectionauthor:: Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
447.. sectionauthor:: Copyright (C) 2015 K. Merker <[email protected]>
This page took 0.434091 seconds and 4 git commands to generate.