blob: d71e58dae1e54e98141fa941aa14e804ffbb89e2 [file] [log] [blame]
Dennis Gilmore2a432012014-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 Warren90b7caa2015-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 Goedeaf21f2f2015-02-07 13:38:19 +010029/* We need the part command */
30#define CONFIG_PARTITION_UUIDS
31#define CONFIG_CMD_PART
32
Dennis Gilmore2a432012014-07-30 16:37:14 -060033#define BOOTENV_SHARED_BLKDEV_BODY(devtypel) \
34 "if " #devtypel " dev ${devnum}; then " \
35 "setenv devtype " #devtypel "; " \
Sjoerd Simons735b1cf2015-01-05 18:13:38 +010036 "run scan_dev_for_boot_part; " \
Dennis Gilmore2a432012014-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
51#ifdef CONFIG_CMD_MMC
52#define BOOTENV_SHARED_MMC BOOTENV_SHARED_BLKDEV(mmc)
53#define BOOTENV_DEV_MMC BOOTENV_DEV_BLKDEV
54#define BOOTENV_DEV_NAME_MMC BOOTENV_DEV_NAME_BLKDEV
55#else
56#define BOOTENV_SHARED_MMC
57#define BOOTENV_DEV_MMC \
58 BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC
59#define BOOTENV_DEV_NAME_MMC \
60 BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC
61#endif
62
63#ifdef CONFIG_CMD_SATA
64#define BOOTENV_SHARED_SATA BOOTENV_SHARED_BLKDEV(sata)
65#define BOOTENV_DEV_SATA BOOTENV_DEV_BLKDEV
66#define BOOTENV_DEV_NAME_SATA BOOTENV_DEV_NAME_BLKDEV
67#else
68#define BOOTENV_SHARED_SATA
69#define BOOTENV_DEV_SATA \
70 BOOT_TARGET_DEVICES_references_SATA_without_CONFIG_CMD_SATA
71#define BOOTENV_DEV_NAME_SATA \
72 BOOT_TARGET_DEVICES_references_SATA_without_CONFIG_CMD_SATA
73#endif
74
75#ifdef CONFIG_CMD_SCSI
Hans de Goedea03bdaa2014-09-16 09:26:23 +020076#define BOOTENV_RUN_SCSI_INIT "run scsi_init; "
77#define BOOTENV_SET_SCSI_NEED_INIT "setenv scsi_need_init; "
78#define BOOTENV_SHARED_SCSI \
79 "scsi_init=" \
80 "if ${scsi_need_init}; then " \
81 "setenv scsi_need_init false; " \
82 "scsi scan; " \
83 "fi\0" \
84 \
85 "scsi_boot=" \
86 BOOTENV_RUN_SCSI_INIT \
87 BOOTENV_SHARED_BLKDEV_BODY(scsi)
Dennis Gilmore2a432012014-07-30 16:37:14 -060088#define BOOTENV_DEV_SCSI BOOTENV_DEV_BLKDEV
89#define BOOTENV_DEV_NAME_SCSI BOOTENV_DEV_NAME_BLKDEV
90#else
Hans de Goedea03bdaa2014-09-16 09:26:23 +020091#define BOOTENV_RUN_SCSI_INIT
92#define BOOTENV_SET_SCSI_NEED_INIT
Dennis Gilmore2a432012014-07-30 16:37:14 -060093#define BOOTENV_SHARED_SCSI
94#define BOOTENV_DEV_SCSI \
95 BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_CMD_SCSI
96#define BOOTENV_DEV_NAME_SCSI \
97 BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_CMD_SCSI
98#endif
99
100#ifdef CONFIG_CMD_IDE
101#define BOOTENV_SHARED_IDE BOOTENV_SHARED_BLKDEV(ide)
102#define BOOTENV_DEV_IDE BOOTENV_DEV_BLKDEV
103#define BOOTENV_DEV_NAME_IDE BOOTENV_DEV_NAME_BLKDEV
104#else
105#define BOOTENV_SHARED_IDE
106#define BOOTENV_DEV_IDE \
107 BOOT_TARGET_DEVICES_references_IDE_without_CONFIG_CMD_IDE
108#define BOOTENV_DEV_NAME_IDE \
109 BOOT_TARGET_DEVICES_references_IDE_without_CONFIG_CMD_IDE
110#endif
111
112#ifdef CONFIG_CMD_USB
Hans de Goedea1d31072015-01-06 14:27:42 +0100113#define BOOTENV_RUN_USB_INIT "usb start; "
Dennis Gilmore2a432012014-07-30 16:37:14 -0600114#define BOOTENV_SHARED_USB \
Dennis Gilmore2a432012014-07-30 16:37:14 -0600115 "usb_boot=" \
116 BOOTENV_RUN_USB_INIT \
117 BOOTENV_SHARED_BLKDEV_BODY(usb)
118#define BOOTENV_DEV_USB BOOTENV_DEV_BLKDEV
119#define BOOTENV_DEV_NAME_USB BOOTENV_DEV_NAME_BLKDEV
120#else
121#define BOOTENV_RUN_USB_INIT
Dennis Gilmore2a432012014-07-30 16:37:14 -0600122#define BOOTENV_SHARED_USB
123#define BOOTENV_DEV_USB \
124 BOOT_TARGET_DEVICES_references_USB_without_CONFIG_CMD_USB
125#define BOOTENV_DEV_NAME_USB \
126 BOOT_TARGET_DEVICES_references_USB_without_CONFIG_CMD_USB
127#endif
128
129#if defined(CONFIG_CMD_DHCP)
130#define BOOTENV_DEV_DHCP(devtypeu, devtypel, instance) \
131 "bootcmd_dhcp=" \
132 BOOTENV_RUN_USB_INIT \
Stephen Warrencc11b392015-01-19 16:39:11 -0700133 "if dhcp ${scriptaddr} ${boot_script_dhcp}; then " \
Dennis Gilmore2a432012014-07-30 16:37:14 -0600134 "source ${scriptaddr}; " \
135 "fi\0"
136#define BOOTENV_DEV_NAME_DHCP(devtypeu, devtypel, instance) \
137 "dhcp "
138#else
139#define BOOTENV_DEV_DHCP \
140 BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP
141#define BOOTENV_DEV_NAME_DHCP \
142 BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP
143#endif
144
145#if defined(CONFIG_CMD_DHCP) && defined(CONFIG_CMD_PXE)
146#define BOOTENV_DEV_PXE(devtypeu, devtypel, instance) \
147 "bootcmd_pxe=" \
148 BOOTENV_RUN_USB_INIT \
149 "dhcp; " \
150 "if pxe get; then " \
151 "pxe boot; " \
152 "fi\0"
153#define BOOTENV_DEV_NAME_PXE(devtypeu, devtypel, instance) \
154 "pxe "
155#else
156#define BOOTENV_DEV_PXE \
157 BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE
158#define BOOTENV_DEV_NAME_PXE \
159 BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE
160#endif
161
162#define BOOTENV_DEV_NAME(devtypeu, devtypel, instance) \
163 BOOTENV_DEV_NAME_##devtypeu(devtypeu, devtypel, instance)
164#define BOOTENV_BOOT_TARGETS \
165 "boot_targets=" BOOT_TARGET_DEVICES(BOOTENV_DEV_NAME) "\0"
166
167#define BOOTENV_DEV(devtypeu, devtypel, instance) \
168 BOOTENV_DEV_##devtypeu(devtypeu, devtypel, instance)
169#define BOOTENV \
170 BOOTENV_SHARED_MMC \
171 BOOTENV_SHARED_USB \
172 BOOTENV_SHARED_SATA \
173 BOOTENV_SHARED_SCSI \
174 BOOTENV_SHARED_IDE \
175 "boot_prefixes=/ /boot/\0" \
176 "boot_scripts=boot.scr.uimg boot.scr\0" \
Stephen Warrencc11b392015-01-19 16:39:11 -0700177 "boot_script_dhcp=boot.scr.uimg\0" \
Dennis Gilmore2a432012014-07-30 16:37:14 -0600178 BOOTENV_BOOT_TARGETS \
Dennis Gilmore2a432012014-07-30 16:37:14 -0600179 \
180 "boot_extlinux=" \
181 "sysboot ${devtype} ${devnum}:${bootpart} any " \
182 "${scriptaddr} ${prefix}extlinux/extlinux.conf\0" \
183 \
184 "scan_dev_for_extlinux=" \
185 "if test -e ${devtype} ${devnum}:${bootpart} " \
186 "${prefix}extlinux/extlinux.conf; then " \
187 "echo Found ${prefix}extlinux/extlinux.conf; " \
188 "run boot_extlinux; " \
189 "echo SCRIPT FAILED: continuing...; " \
190 "fi\0" \
191 \
192 "boot_a_script=" \
193 "load ${devtype} ${devnum}:${bootpart} " \
194 "${scriptaddr} ${prefix}${script}; " \
195 "source ${scriptaddr}\0" \
196 \
197 "scan_dev_for_scripts=" \
198 "for script in ${boot_scripts}; do " \
199 "if test -e ${devtype} ${devnum}:${bootpart} " \
200 "${prefix}${script}; then " \
201 "echo Found U-Boot script " \
202 "${prefix}${script}; " \
203 "run boot_a_script; " \
204 "echo SCRIPT FAILED: continuing...; " \
205 "fi; " \
206 "done\0" \
207 \
208 "scan_dev_for_boot=" \
Sjoerd Simons735b1cf2015-01-05 18:13:38 +0100209 "echo Scanning ${devtype} ${devnum}:${bootpart}...; " \
Dennis Gilmore2a432012014-07-30 16:37:14 -0600210 "for prefix in ${boot_prefixes}; do " \
211 "run scan_dev_for_extlinux; " \
212 "run scan_dev_for_scripts; " \
213 "done\0" \
214 \
Sjoerd Simons735b1cf2015-01-05 18:13:38 +0100215 "scan_dev_for_boot_part=" \
Sjoerd Simonsf643d922015-02-25 23:23:52 +0100216 "part list ${devtype} ${devnum} -bootable devplist; " \
217 "env exists devplist || setenv devplist 1; " \
Sjoerd Simons735b1cf2015-01-05 18:13:38 +0100218 "for bootpart in ${devplist}; do " \
219 "if fstype ${devtype} ${devnum}:${bootpart} " \
220 "bootfstype; then " \
221 "run scan_dev_for_boot; " \
222 "fi; " \
223 "done\0" \
224 \
Dennis Gilmore2a432012014-07-30 16:37:14 -0600225 BOOT_TARGET_DEVICES(BOOTENV_DEV) \
226 \
Sjoerd Simons453c6cc2015-01-05 18:13:39 +0100227 "distro_bootcmd=" BOOTENV_SET_SCSI_NEED_INIT \
Dennis Gilmore2a432012014-07-30 16:37:14 -0600228 "for target in ${boot_targets}; do " \
229 "run bootcmd_${target}; " \
230 "done\0"
231
Sjoerd Simons453c6cc2015-01-05 18:13:39 +0100232#ifndef CONFIG_BOOTCOMMAND
233#define CONFIG_BOOTCOMMAND "run distro_bootcmd"
234#endif
235
Dennis Gilmore2a432012014-07-30 16:37:14 -0600236#endif /* _CONFIG_CMD_DISTRO_BOOTCMD_H */