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 /* 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 29 /* We need the part command */ 30 #define CONFIG_PARTITION_UUIDS 31 #define CONFIG_CMD_PART 32 33 #define BOOTENV_SHARED_BLKDEV_BODY(devtypel) \ 34 "if " #devtypel " dev ${devnum}; then " \ 35 "setenv devtype " #devtypel "; " \ 36 "run scan_dev_for_boot_part; " \ 37 "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_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 63 #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 75 #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 93 #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} " \ 110 "${fdt_addr_r} ${prefix}${fdtfile}; " \ 111 "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} " \ 118 "${prefix}${fdtfile}; then " \ 119 "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 135 #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 148 #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) 160 #define BOOTENV_DEV_SCSI BOOTENV_DEV_BLKDEV 161 #define BOOTENV_DEV_NAME_SCSI BOOTENV_DEV_NAME_BLKDEV 162 #else 163 #define BOOTENV_RUN_SCSI_INIT 164 #define BOOTENV_SET_SCSI_NEED_INIT 165 #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 184 #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 193 #ifdef CONFIG_CMD_USB 194 #define BOOTENV_RUN_NET_USB_START "run boot_net_usb_start; " 195 #define BOOTENV_SHARED_USB \ 196 "boot_net_usb_start=usb start\0" \ 197 "usb_boot=" \ 198 "usb start; " \ 199 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 203 #define BOOTENV_RUN_NET_USB_START 204 #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=" \ 214 BOOTENV_RUN_NET_USB_START \ 215 BOOTENV_RUN_NET_PCI_ENUM \ 216 "if dhcp ${scriptaddr} ${boot_script_dhcp}; then " \ 217 "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=" \ 231 BOOTENV_RUN_NET_USB_START \ 232 BOOTENV_RUN_NET_PCI_ENUM \ 233 "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 \ 254 BOOTENV_SHARED_HOST \ 255 BOOTENV_SHARED_MMC \ 256 BOOTENV_SHARED_PCI \ 257 BOOTENV_SHARED_USB \ 258 BOOTENV_SHARED_SATA \ 259 BOOTENV_SHARED_SCSI \ 260 BOOTENV_SHARED_IDE \ 261 BOOTENV_SHARED_UBIFS \ 262 BOOTENV_SHARED_EFI \ 263 "boot_prefixes=/ /boot/\0" \ 264 "boot_scripts=boot.scr.uimg boot.scr\0" \ 265 "boot_script_dhcp=boot.scr.uimg\0" \ 266 BOOTENV_BOOT_TARGETS \ 267 \ 268 "boot_extlinux=" \ 269 "sysboot ${devtype} ${devnum}:${distro_bootpart} any " \ 270 "${scriptaddr} ${prefix}extlinux/extlinux.conf\0" \ 271 \ 272 "scan_dev_for_extlinux=" \ 273 "if test -e ${devtype} " \ 274 "${devnum}:${distro_bootpart} " \ 275 "${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=" \ 282 "load ${devtype} ${devnum}:${distro_bootpart} " \ 283 "${scriptaddr} ${prefix}${script}; " \ 284 "source ${scriptaddr}\0" \ 285 \ 286 "scan_dev_for_scripts=" \ 287 "for script in ${boot_scripts}; do " \ 288 "if test -e ${devtype} " \ 289 "${devnum}:${distro_bootpart} " \ 290 "${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=" \ 299 "echo Scanning ${devtype} " \ 300 "${devnum}:${distro_bootpart}...; " \ 301 "for prefix in ${boot_prefixes}; do " \ 302 "run scan_dev_for_extlinux; " \ 303 "run scan_dev_for_scripts; " \ 304 "done;" \ 305 SCAN_DEV_FOR_EFI \ 306 "\0" \ 307 \ 308 "scan_dev_for_boot_part=" \ 309 "part list ${devtype} ${devnum} -bootable devplist; " \ 310 "env exists devplist || setenv devplist 1; " \ 311 "for distro_bootpart in ${devplist}; do " \ 312 "if fstype ${devtype} " \ 313 "${devnum}:${distro_bootpart} " \ 314 "bootfstype; then " \ 315 "run scan_dev_for_boot; " \ 316 "fi; " \ 317 "done\0" \ 318 \ 319 BOOT_TARGET_DEVICES(BOOTENV_DEV) \ 320 \ 321 "distro_bootcmd=" BOOTENV_SET_SCSI_NEED_INIT \ 322 "for target in ${boot_targets}; do " \ 323 "run bootcmd_${target}; " \ 324 "done\0" 325 326 #ifndef CONFIG_BOOTCOMMAND 327 #define CONFIG_BOOTCOMMAND "run distro_bootcmd" 328 #endif 329 330 #endif /* _CONFIG_CMD_DISTRO_BOOTCMD_H */ 331