blob: ad9045e4f0f3b64b92684cd2671fe1b699911412 [file] [log] [blame]
Dennis Gilmore5d7c3372014-07-30 16:37:14 -06001/*
2 * (C) Copyright 2014
3 * NVIDIA Corporation <www.nvidia.com>
4 *
5 * Copyright 2014 Red Hat, Inc.
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#ifndef _CONFIG_CMD_DISTRO_BOOTCMD_H
11#define _CONFIG_CMD_DISTRO_BOOTCMD_H
12
Stephen Warrena2baeef2015-03-10 15:40:58 -060013/*
14 * A note on error handling: It is possible for BOOT_TARGET_DEVICES to
15 * reference a device that is not enabled in the U-Boot configuration, e.g.
16 * it may include MMC in the list without CONFIG_CMD_MMC being enabled. Given
17 * that BOOT_TARGET_DEVICES is a macro that's expanded by the C pre-processor
18 * at compile time, it's not possible to detect and report such problems via
19 * a simple #ifdef/#error combination. Still, the code needs to report errors.
20 * The best way I've found to do this is to make BOOT_TARGET_DEVICES expand to
21 * reference a non-existent symbol, and have the name of that symbol encode
22 * the error message. Consequently, this file contains references to e.g.
23 * BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC. Given the
24 * prevalence of capitals here, this looks like a pre-processor macro and
25 * hence seems like it should be all capitals, but it's really an error
26 * message that includes some other pre-processor symbols in the text.
27 */
28
Hans de Goedead53cd52015-02-07 13:38:19 +010029/* We need the part command */
30#define CONFIG_PARTITION_UUIDS
31#define CONFIG_CMD_PART
32
Dennis Gilmore5d7c3372014-07-30 16:37:14 -060033#define BOOTENV_SHARED_BLKDEV_BODY(devtypel) \
34 "if " #devtypel " dev ${devnum}; then " \
35 "setenv devtype " #devtypel "; " \
Sjoerd Simons275537b2015-01-05 18:13:38 +010036 "run scan_dev_for_boot_part; " \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -060037 "fi\0"
38
39#define BOOTENV_SHARED_BLKDEV(devtypel) \
40 #devtypel "_boot=" \
41 BOOTENV_SHARED_BLKDEV_BODY(devtypel)
42
43#define BOOTENV_DEV_BLKDEV(devtypeu, devtypel, instance) \
44 "bootcmd_" #devtypel #instance "=" \
45 "setenv devnum " #instance "; " \
46 "run " #devtypel "_boot\0"
47
48#define BOOTENV_DEV_NAME_BLKDEV(devtypeu, devtypel, instance) \
49 #devtypel #instance " "
50
Sjoerd Simons1d854d62015-04-13 22:54:24 +020051#ifdef CONFIG_SANDBOX
52#define BOOTENV_SHARED_HOST BOOTENV_SHARED_BLKDEV(host)
53#define BOOTENV_DEV_HOST BOOTENV_DEV_BLKDEV
54#define BOOTENV_DEV_NAME_HOST BOOTENV_DEV_NAME_BLKDEV
55#else
56#define BOOTENV_SHARED_HOST
57#define BOOTENV_DEV_HOST \
58 BOOT_TARGET_DEVICES_references_HOST_without_CONFIG_SANDBOX
59#define BOOTENV_DEV_NAME_HOST \
60 BOOT_TARGET_DEVICES_references_HOST_without_CONFIG_SANDBOX
61#endif
62
Dennis Gilmore5d7c3372014-07-30 16:37:14 -060063#ifdef CONFIG_CMD_MMC
64#define BOOTENV_SHARED_MMC BOOTENV_SHARED_BLKDEV(mmc)
65#define BOOTENV_DEV_MMC BOOTENV_DEV_BLKDEV
66#define BOOTENV_DEV_NAME_MMC BOOTENV_DEV_NAME_BLKDEV
67#else
68#define BOOTENV_SHARED_MMC
69#define BOOTENV_DEV_MMC \
70 BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC
71#define BOOTENV_DEV_NAME_MMC \
72 BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC
73#endif
74
Roy Splietb97c6262015-09-17 18:46:59 -040075#ifdef CONFIG_CMD_UBIFS
76#define BOOTENV_SHARED_UBIFS \
77 "ubifs_boot=" \
78 "if ubi part UBI && ubifsmount ubi${devnum}:boot; then " \
79 "setenv devtype ubi; " \
80 "setenv bootpart 0; " \
81 "run scan_dev_for_boot; " \
82 "fi\0"
83#define BOOTENV_DEV_UBIFS BOOTENV_DEV_BLKDEV
84#define BOOTENV_DEV_NAME_UBIFS BOOTENV_DEV_NAME_BLKDEV
85#else
86#define BOOTENV_SHARED_UBIFS
87#define BOOTENV_DEV_UBIFS \
88 BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS
89#define BOOTENV_DEV_NAME_UBIFS \
90 BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS
91#endif
92
Alexander Graf41ee3162016-03-10 00:26:15 +010093#ifdef CONFIG_EFI_LOADER
94#if defined(CONFIG_ARM64)
95#define BOOTEFI_NAME "bootaa64.efi"
96#elif defined(CONFIG_ARM)
97#define BOOTEFI_NAME "bootarm.efi"
98#endif
99#endif
100
101#ifdef BOOTEFI_NAME
102#define BOOTENV_SHARED_EFI \
103 "boot_efi_binary=" \
104 "load ${devtype} ${devnum}:${distro_bootpart} " \
105 "${kernel_addr_r} efi/boot/"BOOTEFI_NAME"; " \
106 "bootefi ${kernel_addr_r}\0" \
107 \
108 "load_efi_dtb=" \
109 "load ${devtype} ${devnum}:${distro_bootpart} " \
Alexander Grafaf684802016-03-04 01:10:11 +0100110 "${fdt_addr_r} ${prefix}${fdtfile}; " \
Alexander Graf41ee3162016-03-10 00:26:15 +0100111 "fdt addr ${fdt_addr_r}\0" \
112 \
113 "efi_dtb_prefixes=/ /dtb/ /dtb/current/\0" \
114 "scan_dev_for_efi=" \
115 "for prefix in ${efi_dtb_prefixes}; do " \
116 "if test -e ${devtype} " \
117 "${devnum}:${distro_bootpart} " \
Alexander Grafaf684802016-03-04 01:10:11 +0100118 "${prefix}${fdtfile}; then " \
Alexander Graf41ee3162016-03-10 00:26:15 +0100119 "run load_efi_dtb; " \
120 "fi;" \
121 "done;" \
122 "if test -e ${devtype} ${devnum}:${distro_bootpart} " \
123 "efi/boot/"BOOTEFI_NAME"; then " \
124 "echo Found EFI removable media binary " \
125 "efi/boot/"BOOTEFI_NAME"; " \
126 "run boot_efi_binary; " \
127 "echo EFI LOAD FAILED: continuing...; " \
128 "fi; \0"
129#define SCAN_DEV_FOR_EFI "run scan_dev_for_efi;"
130#else
131#define BOOTENV_SHARED_EFI
132#define SCAN_DEV_FOR_EFI
133#endif
134
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600135#ifdef CONFIG_CMD_SATA
136#define BOOTENV_SHARED_SATA BOOTENV_SHARED_BLKDEV(sata)
137#define BOOTENV_DEV_SATA BOOTENV_DEV_BLKDEV
138#define BOOTENV_DEV_NAME_SATA BOOTENV_DEV_NAME_BLKDEV
139#else
140#define BOOTENV_SHARED_SATA
141#define BOOTENV_DEV_SATA \
142 BOOT_TARGET_DEVICES_references_SATA_without_CONFIG_CMD_SATA
143#define BOOTENV_DEV_NAME_SATA \
144 BOOT_TARGET_DEVICES_references_SATA_without_CONFIG_CMD_SATA
145#endif
146
147#ifdef CONFIG_CMD_SCSI
Hans de Goededd5355e2014-09-16 09:26:23 +0200148#define BOOTENV_RUN_SCSI_INIT "run scsi_init; "
149#define BOOTENV_SET_SCSI_NEED_INIT "setenv scsi_need_init; "
150#define BOOTENV_SHARED_SCSI \
151 "scsi_init=" \
152 "if ${scsi_need_init}; then " \
153 "setenv scsi_need_init false; " \
154 "scsi scan; " \
155 "fi\0" \
156 \
157 "scsi_boot=" \
158 BOOTENV_RUN_SCSI_INIT \
159 BOOTENV_SHARED_BLKDEV_BODY(scsi)
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600160#define BOOTENV_DEV_SCSI BOOTENV_DEV_BLKDEV
161#define BOOTENV_DEV_NAME_SCSI BOOTENV_DEV_NAME_BLKDEV
162#else
Hans de Goededd5355e2014-09-16 09:26:23 +0200163#define BOOTENV_RUN_SCSI_INIT
164#define BOOTENV_SET_SCSI_NEED_INIT
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600165#define BOOTENV_SHARED_SCSI
166#define BOOTENV_DEV_SCSI \
167 BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_CMD_SCSI
168#define BOOTENV_DEV_NAME_SCSI \
169 BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_CMD_SCSI
170#endif
171
172#ifdef CONFIG_CMD_IDE
173#define BOOTENV_SHARED_IDE BOOTENV_SHARED_BLKDEV(ide)
174#define BOOTENV_DEV_IDE BOOTENV_DEV_BLKDEV
175#define BOOTENV_DEV_NAME_IDE BOOTENV_DEV_NAME_BLKDEV
176#else
177#define BOOTENV_SHARED_IDE
178#define BOOTENV_DEV_IDE \
179 BOOT_TARGET_DEVICES_references_IDE_without_CONFIG_CMD_IDE
180#define BOOTENV_DEV_NAME_IDE \
181 BOOT_TARGET_DEVICES_references_IDE_without_CONFIG_CMD_IDE
182#endif
183
Stephen Warren3a74c642016-01-26 11:10:13 -0700184#if defined(CONFIG_CMD_PCI_ENUM) || defined(CONFIG_DM_PCI)
185#define BOOTENV_RUN_NET_PCI_ENUM "run boot_net_pci_enum; "
186#define BOOTENV_SHARED_PCI \
187 "boot_net_pci_enum=pci enum\0"
188#else
189#define BOOTENV_RUN_NET_PCI_ENUM
190#define BOOTENV_SHARED_PCI
191#endif
192
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600193#ifdef CONFIG_CMD_USB
Stephen Warren4c739fb2016-01-26 11:10:12 -0700194#define BOOTENV_RUN_NET_USB_START "run boot_net_usb_start; "
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600195#define BOOTENV_SHARED_USB \
Stephen Warren4c739fb2016-01-26 11:10:12 -0700196 "boot_net_usb_start=usb start\0" \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600197 "usb_boot=" \
Stephen Warren4c739fb2016-01-26 11:10:12 -0700198 "usb start; " \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600199 BOOTENV_SHARED_BLKDEV_BODY(usb)
200#define BOOTENV_DEV_USB BOOTENV_DEV_BLKDEV
201#define BOOTENV_DEV_NAME_USB BOOTENV_DEV_NAME_BLKDEV
202#else
Stephen Warren4c739fb2016-01-26 11:10:12 -0700203#define BOOTENV_RUN_NET_USB_START
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600204#define BOOTENV_SHARED_USB
205#define BOOTENV_DEV_USB \
206 BOOT_TARGET_DEVICES_references_USB_without_CONFIG_CMD_USB
207#define BOOTENV_DEV_NAME_USB \
208 BOOT_TARGET_DEVICES_references_USB_without_CONFIG_CMD_USB
209#endif
210
211#if defined(CONFIG_CMD_DHCP)
212#define BOOTENV_DEV_DHCP(devtypeu, devtypel, instance) \
213 "bootcmd_dhcp=" \
Stephen Warren4c739fb2016-01-26 11:10:12 -0700214 BOOTENV_RUN_NET_USB_START \
Stephen Warren3a74c642016-01-26 11:10:13 -0700215 BOOTENV_RUN_NET_PCI_ENUM \
Stephen Warrened05d342015-01-19 16:39:11 -0700216 "if dhcp ${scriptaddr} ${boot_script_dhcp}; then " \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600217 "source ${scriptaddr}; " \
218 "fi\0"
219#define BOOTENV_DEV_NAME_DHCP(devtypeu, devtypel, instance) \
220 "dhcp "
221#else
222#define BOOTENV_DEV_DHCP \
223 BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP
224#define BOOTENV_DEV_NAME_DHCP \
225 BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP
226#endif
227
228#if defined(CONFIG_CMD_DHCP) && defined(CONFIG_CMD_PXE)
229#define BOOTENV_DEV_PXE(devtypeu, devtypel, instance) \
230 "bootcmd_pxe=" \
Stephen Warren4c739fb2016-01-26 11:10:12 -0700231 BOOTENV_RUN_NET_USB_START \
Stephen Warren3a74c642016-01-26 11:10:13 -0700232 BOOTENV_RUN_NET_PCI_ENUM \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600233 "dhcp; " \
234 "if pxe get; then " \
235 "pxe boot; " \
236 "fi\0"
237#define BOOTENV_DEV_NAME_PXE(devtypeu, devtypel, instance) \
238 "pxe "
239#else
240#define BOOTENV_DEV_PXE \
241 BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE
242#define BOOTENV_DEV_NAME_PXE \
243 BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE
244#endif
245
246#define BOOTENV_DEV_NAME(devtypeu, devtypel, instance) \
247 BOOTENV_DEV_NAME_##devtypeu(devtypeu, devtypel, instance)
248#define BOOTENV_BOOT_TARGETS \
249 "boot_targets=" BOOT_TARGET_DEVICES(BOOTENV_DEV_NAME) "\0"
250
251#define BOOTENV_DEV(devtypeu, devtypel, instance) \
252 BOOTENV_DEV_##devtypeu(devtypeu, devtypel, instance)
253#define BOOTENV \
Sjoerd Simons1d854d62015-04-13 22:54:24 +0200254 BOOTENV_SHARED_HOST \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600255 BOOTENV_SHARED_MMC \
Stephen Warren3a74c642016-01-26 11:10:13 -0700256 BOOTENV_SHARED_PCI \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600257 BOOTENV_SHARED_USB \
258 BOOTENV_SHARED_SATA \
259 BOOTENV_SHARED_SCSI \
260 BOOTENV_SHARED_IDE \
Roy Splietb97c6262015-09-17 18:46:59 -0400261 BOOTENV_SHARED_UBIFS \
Alexander Graf41ee3162016-03-10 00:26:15 +0100262 BOOTENV_SHARED_EFI \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600263 "boot_prefixes=/ /boot/\0" \
264 "boot_scripts=boot.scr.uimg boot.scr\0" \
Stephen Warrened05d342015-01-19 16:39:11 -0700265 "boot_script_dhcp=boot.scr.uimg\0" \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600266 BOOTENV_BOOT_TARGETS \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600267 \
268 "boot_extlinux=" \
Sjoerd Simonsa92f11c2015-08-28 15:01:54 +0200269 "sysboot ${devtype} ${devnum}:${distro_bootpart} any " \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600270 "${scriptaddr} ${prefix}extlinux/extlinux.conf\0" \
271 \
272 "scan_dev_for_extlinux=" \
Sjoerd Simonsa92f11c2015-08-28 15:01:54 +0200273 "if test -e ${devtype} " \
274 "${devnum}:${distro_bootpart} " \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600275 "${prefix}extlinux/extlinux.conf; then " \
276 "echo Found ${prefix}extlinux/extlinux.conf; " \
277 "run boot_extlinux; " \
278 "echo SCRIPT FAILED: continuing...; " \
279 "fi\0" \
280 \
281 "boot_a_script=" \
Sjoerd Simonsa92f11c2015-08-28 15:01:54 +0200282 "load ${devtype} ${devnum}:${distro_bootpart} " \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600283 "${scriptaddr} ${prefix}${script}; " \
284 "source ${scriptaddr}\0" \
285 \
286 "scan_dev_for_scripts=" \
287 "for script in ${boot_scripts}; do " \
Sjoerd Simonsa92f11c2015-08-28 15:01:54 +0200288 "if test -e ${devtype} " \
289 "${devnum}:${distro_bootpart} " \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600290 "${prefix}${script}; then " \
291 "echo Found U-Boot script " \
292 "${prefix}${script}; " \
293 "run boot_a_script; " \
294 "echo SCRIPT FAILED: continuing...; " \
295 "fi; " \
296 "done\0" \
297 \
298 "scan_dev_for_boot=" \
Sjoerd Simonsa92f11c2015-08-28 15:01:54 +0200299 "echo Scanning ${devtype} " \
300 "${devnum}:${distro_bootpart}...; " \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600301 "for prefix in ${boot_prefixes}; do " \
302 "run scan_dev_for_extlinux; " \
303 "run scan_dev_for_scripts; " \
Alexander Graf41ee3162016-03-10 00:26:15 +0100304 "done;" \
305 SCAN_DEV_FOR_EFI \
306 "\0" \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600307 \
Sjoerd Simons275537b2015-01-05 18:13:38 +0100308 "scan_dev_for_boot_part=" \
Sjoerd Simons5849a1e2015-02-25 23:23:52 +0100309 "part list ${devtype} ${devnum} -bootable devplist; " \
310 "env exists devplist || setenv devplist 1; " \
Sjoerd Simonsa92f11c2015-08-28 15:01:54 +0200311 "for distro_bootpart in ${devplist}; do " \
312 "if fstype ${devtype} " \
313 "${devnum}:${distro_bootpart} " \
Sjoerd Simons275537b2015-01-05 18:13:38 +0100314 "bootfstype; then " \
315 "run scan_dev_for_boot; " \
316 "fi; " \
317 "done\0" \
318 \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600319 BOOT_TARGET_DEVICES(BOOTENV_DEV) \
320 \
Sjoerd Simonsb85bbc32015-01-05 18:13:39 +0100321 "distro_bootcmd=" BOOTENV_SET_SCSI_NEED_INIT \
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600322 "for target in ${boot_targets}; do " \
323 "run bootcmd_${target}; " \
324 "done\0"
325
Sjoerd Simonsb85bbc32015-01-05 18:13:39 +0100326#ifndef CONFIG_BOOTCOMMAND
327#define CONFIG_BOOTCOMMAND "run distro_bootcmd"
328#endif
329
Dennis Gilmore5d7c3372014-07-30 16:37:14 -0600330#endif /* _CONFIG_CMD_DISTRO_BOOTCMD_H */