1 /*
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 
13 /* We need the part command */
14 #define CONFIG_PARTITION_UUIDS
15 #define CONFIG_CMD_PART
16 
17 #define BOOTENV_SHARED_BLKDEV_BODY(devtypel) \
18 		"if " #devtypel " dev ${devnum}; then " \
19 			"setenv devtype " #devtypel "; " \
20 			"run scan_dev_for_boot_part; " \
21 		"fi\0"
22 
23 #define BOOTENV_SHARED_BLKDEV(devtypel) \
24 	#devtypel "_boot=" \
25 	BOOTENV_SHARED_BLKDEV_BODY(devtypel)
26 
27 #define BOOTENV_DEV_BLKDEV(devtypeu, devtypel, instance) \
28 	"bootcmd_" #devtypel #instance "=" \
29 		"setenv devnum " #instance "; " \
30 		"run " #devtypel "_boot\0"
31 
32 #define BOOTENV_DEV_NAME_BLKDEV(devtypeu, devtypel, instance) \
33 	#devtypel #instance " "
34 
35 #ifdef CONFIG_CMD_MMC
36 #define BOOTENV_SHARED_MMC	BOOTENV_SHARED_BLKDEV(mmc)
37 #define BOOTENV_DEV_MMC		BOOTENV_DEV_BLKDEV
38 #define BOOTENV_DEV_NAME_MMC	BOOTENV_DEV_NAME_BLKDEV
39 #else
40 #define BOOTENV_SHARED_MMC
41 #define BOOTENV_DEV_MMC \
42 	BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC
43 #define BOOTENV_DEV_NAME_MMC \
44 	BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC
45 #endif
46 
47 #ifdef CONFIG_CMD_SATA
48 #define BOOTENV_SHARED_SATA	BOOTENV_SHARED_BLKDEV(sata)
49 #define BOOTENV_DEV_SATA	BOOTENV_DEV_BLKDEV
50 #define BOOTENV_DEV_NAME_SATA	BOOTENV_DEV_NAME_BLKDEV
51 #else
52 #define BOOTENV_SHARED_SATA
53 #define BOOTENV_DEV_SATA \
54 	BOOT_TARGET_DEVICES_references_SATA_without_CONFIG_CMD_SATA
55 #define BOOTENV_DEV_NAME_SATA \
56 	BOOT_TARGET_DEVICES_references_SATA_without_CONFIG_CMD_SATA
57 #endif
58 
59 #ifdef CONFIG_CMD_SCSI
60 #define BOOTENV_RUN_SCSI_INIT "run scsi_init; "
61 #define BOOTENV_SET_SCSI_NEED_INIT "setenv scsi_need_init; "
62 #define BOOTENV_SHARED_SCSI \
63 	"scsi_init=" \
64 		"if ${scsi_need_init}; then " \
65 			"setenv scsi_need_init false; " \
66 			"scsi scan; " \
67 		"fi\0" \
68 	\
69 	"scsi_boot=" \
70 		BOOTENV_RUN_SCSI_INIT \
71 		BOOTENV_SHARED_BLKDEV_BODY(scsi)
72 #define BOOTENV_DEV_SCSI	BOOTENV_DEV_BLKDEV
73 #define BOOTENV_DEV_NAME_SCSI	BOOTENV_DEV_NAME_BLKDEV
74 #else
75 #define BOOTENV_RUN_SCSI_INIT
76 #define BOOTENV_SET_SCSI_NEED_INIT
77 #define BOOTENV_SHARED_SCSI
78 #define BOOTENV_DEV_SCSI \
79 	BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_CMD_SCSI
80 #define BOOTENV_DEV_NAME_SCSI \
81 	BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_CMD_SCSI
82 #endif
83 
84 #ifdef CONFIG_CMD_IDE
85 #define BOOTENV_SHARED_IDE	BOOTENV_SHARED_BLKDEV(ide)
86 #define BOOTENV_DEV_IDE		BOOTENV_DEV_BLKDEV
87 #define BOOTENV_DEV_NAME_IDE	BOOTENV_DEV_NAME_BLKDEV
88 #else
89 #define BOOTENV_SHARED_IDE
90 #define BOOTENV_DEV_IDE \
91 	BOOT_TARGET_DEVICES_references_IDE_without_CONFIG_CMD_IDE
92 #define BOOTENV_DEV_NAME_IDE \
93 	BOOT_TARGET_DEVICES_references_IDE_without_CONFIG_CMD_IDE
94 #endif
95 
96 #ifdef CONFIG_CMD_USB
97 #define BOOTENV_RUN_USB_INIT "usb start; "
98 #define BOOTENV_SHARED_USB \
99 	"usb_boot=" \
100 		BOOTENV_RUN_USB_INIT \
101 		BOOTENV_SHARED_BLKDEV_BODY(usb)
102 #define BOOTENV_DEV_USB		BOOTENV_DEV_BLKDEV
103 #define BOOTENV_DEV_NAME_USB	BOOTENV_DEV_NAME_BLKDEV
104 #else
105 #define BOOTENV_RUN_USB_INIT
106 #define BOOTENV_SHARED_USB
107 #define BOOTENV_DEV_USB \
108 	BOOT_TARGET_DEVICES_references_USB_without_CONFIG_CMD_USB
109 #define BOOTENV_DEV_NAME_USB \
110 	BOOT_TARGET_DEVICES_references_USB_without_CONFIG_CMD_USB
111 #endif
112 
113 #if defined(CONFIG_CMD_DHCP)
114 #define BOOTENV_DEV_DHCP(devtypeu, devtypel, instance) \
115 	"bootcmd_dhcp=" \
116 		BOOTENV_RUN_USB_INIT \
117 		"if dhcp ${scriptaddr} ${boot_script_dhcp}; then " \
118 			"source ${scriptaddr}; " \
119 		"fi\0"
120 #define BOOTENV_DEV_NAME_DHCP(devtypeu, devtypel, instance) \
121 	"dhcp "
122 #else
123 #define BOOTENV_DEV_DHCP \
124 	BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP
125 #define BOOTENV_DEV_NAME_DHCP \
126 	BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP
127 #endif
128 
129 #if defined(CONFIG_CMD_DHCP) && defined(CONFIG_CMD_PXE)
130 #define BOOTENV_DEV_PXE(devtypeu, devtypel, instance) \
131 	"bootcmd_pxe=" \
132 		BOOTENV_RUN_USB_INIT \
133 		"dhcp; " \
134 		"if pxe get; then " \
135 			"pxe boot; " \
136 		"fi\0"
137 #define BOOTENV_DEV_NAME_PXE(devtypeu, devtypel, instance) \
138 	"pxe "
139 #else
140 #define BOOTENV_DEV_PXE \
141 	BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE
142 #define BOOTENV_DEV_NAME_PXE \
143 	BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE
144 #endif
145 
146 #define BOOTENV_DEV_NAME(devtypeu, devtypel, instance) \
147 	BOOTENV_DEV_NAME_##devtypeu(devtypeu, devtypel, instance)
148 #define BOOTENV_BOOT_TARGETS \
149 	"boot_targets=" BOOT_TARGET_DEVICES(BOOTENV_DEV_NAME) "\0"
150 
151 #define BOOTENV_DEV(devtypeu, devtypel, instance) \
152 	BOOTENV_DEV_##devtypeu(devtypeu, devtypel, instance)
153 #define BOOTENV \
154 	BOOTENV_SHARED_MMC \
155 	BOOTENV_SHARED_USB \
156 	BOOTENV_SHARED_SATA \
157 	BOOTENV_SHARED_SCSI \
158 	BOOTENV_SHARED_IDE \
159 	"boot_prefixes=/ /boot/\0" \
160 	"boot_scripts=boot.scr.uimg boot.scr\0" \
161 	"boot_script_dhcp=boot.scr.uimg\0" \
162 	BOOTENV_BOOT_TARGETS \
163 	\
164 	"boot_extlinux="                                                  \
165 		"sysboot ${devtype} ${devnum}:${bootpart} any "           \
166 			"${scriptaddr} ${prefix}extlinux/extlinux.conf\0" \
167 	\
168 	"scan_dev_for_extlinux="                                          \
169 		"if test -e ${devtype} ${devnum}:${bootpart} "            \
170 				"${prefix}extlinux/extlinux.conf; then "  \
171 			"echo Found ${prefix}extlinux/extlinux.conf; "    \
172 			"run boot_extlinux; "                             \
173 			"echo SCRIPT FAILED: continuing...; "             \
174 		"fi\0"                                                    \
175 	\
176 	"boot_a_script="                                                  \
177 		"load ${devtype} ${devnum}:${bootpart} "                  \
178 			"${scriptaddr} ${prefix}${script}; "              \
179 		"source ${scriptaddr}\0"                                  \
180 	\
181 	"scan_dev_for_scripts="                                           \
182 		"for script in ${boot_scripts}; do "                      \
183 			"if test -e ${devtype} ${devnum}:${bootpart} "    \
184 					"${prefix}${script}; then "       \
185 				"echo Found U-Boot script "               \
186 					"${prefix}${script}; "            \
187 				"run boot_a_script; "                     \
188 				"echo SCRIPT FAILED: continuing...; "     \
189 			"fi; "                                            \
190 		"done\0"                                                  \
191 	\
192 	"scan_dev_for_boot="                                              \
193 		"echo Scanning ${devtype} ${devnum}:${bootpart}...; "     \
194 		"for prefix in ${boot_prefixes}; do "                     \
195 			"run scan_dev_for_extlinux; "                     \
196 			"run scan_dev_for_scripts; "                      \
197 		"done\0"                                                  \
198 	\
199 	"scan_dev_for_boot_part="                                         \
200 		"part list ${devtype} ${devnum} devplist; "               \
201 		"for bootpart in ${devplist}; do "                        \
202 			"if fstype ${devtype} ${devnum}:${bootpart} "     \
203 					"bootfstype; then "               \
204 				"run scan_dev_for_boot; "                 \
205 			"fi; "                                            \
206 		"done\0"                                                  \
207 	\
208 	BOOT_TARGET_DEVICES(BOOTENV_DEV)                                  \
209 	\
210 	"distro_bootcmd=" BOOTENV_SET_SCSI_NEED_INIT                      \
211 		"for target in ${boot_targets}; do "                      \
212 			"run bootcmd_${target}; "                         \
213 		"done\0"
214 
215 #ifndef CONFIG_BOOTCOMMAND
216 #define CONFIG_BOOTCOMMAND "run distro_bootcmd"
217 #endif
218 
219 #endif  /* _CONFIG_CMD_DISTRO_BOOTCMD_H */
220