12a43201aSDennis Gilmore /* 22a43201aSDennis Gilmore * (C) Copyright 2014 32a43201aSDennis Gilmore * NVIDIA Corporation <www.nvidia.com> 42a43201aSDennis Gilmore * 52a43201aSDennis Gilmore * Copyright 2014 Red Hat, Inc. 62a43201aSDennis Gilmore * 72a43201aSDennis Gilmore * SPDX-License-Identifier: GPL-2.0+ 82a43201aSDennis Gilmore */ 92a43201aSDennis Gilmore 102a43201aSDennis Gilmore #ifndef _CONFIG_CMD_DISTRO_BOOTCMD_H 112a43201aSDennis Gilmore #define _CONFIG_CMD_DISTRO_BOOTCMD_H 122a43201aSDennis Gilmore 1390b7caafSStephen Warren /* 1490b7caafSStephen Warren * A note on error handling: It is possible for BOOT_TARGET_DEVICES to 1590b7caafSStephen Warren * reference a device that is not enabled in the U-Boot configuration, e.g. 1690b7caafSStephen Warren * it may include MMC in the list without CONFIG_CMD_MMC being enabled. Given 1790b7caafSStephen Warren * that BOOT_TARGET_DEVICES is a macro that's expanded by the C pre-processor 1890b7caafSStephen Warren * at compile time, it's not possible to detect and report such problems via 1990b7caafSStephen Warren * a simple #ifdef/#error combination. Still, the code needs to report errors. 2090b7caafSStephen Warren * The best way I've found to do this is to make BOOT_TARGET_DEVICES expand to 2190b7caafSStephen Warren * reference a non-existent symbol, and have the name of that symbol encode 2290b7caafSStephen Warren * the error message. Consequently, this file contains references to e.g. 2390b7caafSStephen Warren * BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC. Given the 2490b7caafSStephen Warren * prevalence of capitals here, this looks like a pre-processor macro and 2590b7caafSStephen Warren * hence seems like it should be all capitals, but it's really an error 2690b7caafSStephen Warren * message that includes some other pre-processor symbols in the text. 2790b7caafSStephen Warren */ 2890b7caafSStephen Warren 29af21f2fbSHans de Goede /* We need the part command */ 30af21f2fbSHans de Goede #define CONFIG_PARTITION_UUIDS 31af21f2fbSHans de Goede #define CONFIG_CMD_PART 32af21f2fbSHans de Goede 332a43201aSDennis Gilmore #define BOOTENV_SHARED_BLKDEV_BODY(devtypel) \ 342a43201aSDennis Gilmore "if " #devtypel " dev ${devnum}; then " \ 352a43201aSDennis Gilmore "setenv devtype " #devtypel "; " \ 36735b1cfeSSjoerd Simons "run scan_dev_for_boot_part; " \ 372a43201aSDennis Gilmore "fi\0" 382a43201aSDennis Gilmore 392a43201aSDennis Gilmore #define BOOTENV_SHARED_BLKDEV(devtypel) \ 402a43201aSDennis Gilmore #devtypel "_boot=" \ 412a43201aSDennis Gilmore BOOTENV_SHARED_BLKDEV_BODY(devtypel) 422a43201aSDennis Gilmore 432a43201aSDennis Gilmore #define BOOTENV_DEV_BLKDEV(devtypeu, devtypel, instance) \ 442a43201aSDennis Gilmore "bootcmd_" #devtypel #instance "=" \ 452a43201aSDennis Gilmore "setenv devnum " #instance "; " \ 462a43201aSDennis Gilmore "run " #devtypel "_boot\0" 472a43201aSDennis Gilmore 482a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_BLKDEV(devtypeu, devtypel, instance) \ 492a43201aSDennis Gilmore #devtypel #instance " " 502a43201aSDennis Gilmore 51d0bce0d1SSjoerd Simons #ifdef CONFIG_SANDBOX 52d0bce0d1SSjoerd Simons #define BOOTENV_SHARED_HOST BOOTENV_SHARED_BLKDEV(host) 53d0bce0d1SSjoerd Simons #define BOOTENV_DEV_HOST BOOTENV_DEV_BLKDEV 54d0bce0d1SSjoerd Simons #define BOOTENV_DEV_NAME_HOST BOOTENV_DEV_NAME_BLKDEV 55d0bce0d1SSjoerd Simons #else 56d0bce0d1SSjoerd Simons #define BOOTENV_SHARED_HOST 57d0bce0d1SSjoerd Simons #define BOOTENV_DEV_HOST \ 58d0bce0d1SSjoerd Simons BOOT_TARGET_DEVICES_references_HOST_without_CONFIG_SANDBOX 59d0bce0d1SSjoerd Simons #define BOOTENV_DEV_NAME_HOST \ 60d0bce0d1SSjoerd Simons BOOT_TARGET_DEVICES_references_HOST_without_CONFIG_SANDBOX 61d0bce0d1SSjoerd Simons #endif 62d0bce0d1SSjoerd Simons 632a43201aSDennis Gilmore #ifdef CONFIG_CMD_MMC 642a43201aSDennis Gilmore #define BOOTENV_SHARED_MMC BOOTENV_SHARED_BLKDEV(mmc) 652a43201aSDennis Gilmore #define BOOTENV_DEV_MMC BOOTENV_DEV_BLKDEV 662a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_MMC BOOTENV_DEV_NAME_BLKDEV 672a43201aSDennis Gilmore #else 682a43201aSDennis Gilmore #define BOOTENV_SHARED_MMC 692a43201aSDennis Gilmore #define BOOTENV_DEV_MMC \ 702a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC 712a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_MMC \ 722a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC 732a43201aSDennis Gilmore #endif 742a43201aSDennis Gilmore 7540d21547SRoy Spliet #ifdef CONFIG_CMD_UBIFS 7640d21547SRoy Spliet #define BOOTENV_SHARED_UBIFS \ 7740d21547SRoy Spliet "ubifs_boot=" \ 7840d21547SRoy Spliet "if ubi part UBI && ubifsmount ubi${devnum}:boot; then " \ 7940d21547SRoy Spliet "setenv devtype ubi; " \ 8040d21547SRoy Spliet "setenv bootpart 0; " \ 8140d21547SRoy Spliet "run scan_dev_for_boot; " \ 8240d21547SRoy Spliet "fi\0" 8340d21547SRoy Spliet #define BOOTENV_DEV_UBIFS BOOTENV_DEV_BLKDEV 8440d21547SRoy Spliet #define BOOTENV_DEV_NAME_UBIFS BOOTENV_DEV_NAME_BLKDEV 8540d21547SRoy Spliet #else 8640d21547SRoy Spliet #define BOOTENV_SHARED_UBIFS 8740d21547SRoy Spliet #define BOOTENV_DEV_UBIFS \ 8840d21547SRoy Spliet BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS 8940d21547SRoy Spliet #define BOOTENV_DEV_NAME_UBIFS \ 9040d21547SRoy Spliet BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS 9140d21547SRoy Spliet #endif 9240d21547SRoy Spliet 932a43201aSDennis Gilmore #ifdef CONFIG_CMD_SATA 942a43201aSDennis Gilmore #define BOOTENV_SHARED_SATA BOOTENV_SHARED_BLKDEV(sata) 952a43201aSDennis Gilmore #define BOOTENV_DEV_SATA BOOTENV_DEV_BLKDEV 962a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_SATA BOOTENV_DEV_NAME_BLKDEV 972a43201aSDennis Gilmore #else 982a43201aSDennis Gilmore #define BOOTENV_SHARED_SATA 992a43201aSDennis Gilmore #define BOOTENV_DEV_SATA \ 1002a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_SATA_without_CONFIG_CMD_SATA 1012a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_SATA \ 1022a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_SATA_without_CONFIG_CMD_SATA 1032a43201aSDennis Gilmore #endif 1042a43201aSDennis Gilmore 1052a43201aSDennis Gilmore #ifdef CONFIG_CMD_SCSI 106a03bdaa1SHans de Goede #define BOOTENV_RUN_SCSI_INIT "run scsi_init; " 107a03bdaa1SHans de Goede #define BOOTENV_SET_SCSI_NEED_INIT "setenv scsi_need_init; " 108a03bdaa1SHans de Goede #define BOOTENV_SHARED_SCSI \ 109a03bdaa1SHans de Goede "scsi_init=" \ 110a03bdaa1SHans de Goede "if ${scsi_need_init}; then " \ 111a03bdaa1SHans de Goede "setenv scsi_need_init false; " \ 112a03bdaa1SHans de Goede "scsi scan; " \ 113a03bdaa1SHans de Goede "fi\0" \ 114a03bdaa1SHans de Goede \ 115a03bdaa1SHans de Goede "scsi_boot=" \ 116a03bdaa1SHans de Goede BOOTENV_RUN_SCSI_INIT \ 117a03bdaa1SHans de Goede BOOTENV_SHARED_BLKDEV_BODY(scsi) 1182a43201aSDennis Gilmore #define BOOTENV_DEV_SCSI BOOTENV_DEV_BLKDEV 1192a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_SCSI BOOTENV_DEV_NAME_BLKDEV 1202a43201aSDennis Gilmore #else 121a03bdaa1SHans de Goede #define BOOTENV_RUN_SCSI_INIT 122a03bdaa1SHans de Goede #define BOOTENV_SET_SCSI_NEED_INIT 1232a43201aSDennis Gilmore #define BOOTENV_SHARED_SCSI 1242a43201aSDennis Gilmore #define BOOTENV_DEV_SCSI \ 1252a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_CMD_SCSI 1262a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_SCSI \ 1272a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_CMD_SCSI 1282a43201aSDennis Gilmore #endif 1292a43201aSDennis Gilmore 1302a43201aSDennis Gilmore #ifdef CONFIG_CMD_IDE 1312a43201aSDennis Gilmore #define BOOTENV_SHARED_IDE BOOTENV_SHARED_BLKDEV(ide) 1322a43201aSDennis Gilmore #define BOOTENV_DEV_IDE BOOTENV_DEV_BLKDEV 1332a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_IDE BOOTENV_DEV_NAME_BLKDEV 1342a43201aSDennis Gilmore #else 1352a43201aSDennis Gilmore #define BOOTENV_SHARED_IDE 1362a43201aSDennis Gilmore #define BOOTENV_DEV_IDE \ 1372a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_IDE_without_CONFIG_CMD_IDE 1382a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_IDE \ 1392a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_IDE_without_CONFIG_CMD_IDE 1402a43201aSDennis Gilmore #endif 1412a43201aSDennis Gilmore 142*986691fbSStephen Warren #if defined(CONFIG_CMD_PCI_ENUM) || defined(CONFIG_DM_PCI) 143*986691fbSStephen Warren #define BOOTENV_RUN_NET_PCI_ENUM "run boot_net_pci_enum; " 144*986691fbSStephen Warren #define BOOTENV_SHARED_PCI \ 145*986691fbSStephen Warren "boot_net_pci_enum=pci enum\0" 146*986691fbSStephen Warren #else 147*986691fbSStephen Warren #define BOOTENV_RUN_NET_PCI_ENUM 148*986691fbSStephen Warren #define BOOTENV_SHARED_PCI 149*986691fbSStephen Warren #endif 150*986691fbSStephen Warren 1512a43201aSDennis Gilmore #ifdef CONFIG_CMD_USB 1523483b75dSStephen Warren #define BOOTENV_RUN_NET_USB_START "run boot_net_usb_start; " 1532a43201aSDennis Gilmore #define BOOTENV_SHARED_USB \ 1543483b75dSStephen Warren "boot_net_usb_start=usb start\0" \ 1552a43201aSDennis Gilmore "usb_boot=" \ 1563483b75dSStephen Warren "usb start; " \ 1572a43201aSDennis Gilmore BOOTENV_SHARED_BLKDEV_BODY(usb) 1582a43201aSDennis Gilmore #define BOOTENV_DEV_USB BOOTENV_DEV_BLKDEV 1592a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_USB BOOTENV_DEV_NAME_BLKDEV 1602a43201aSDennis Gilmore #else 1613483b75dSStephen Warren #define BOOTENV_RUN_NET_USB_START 1622a43201aSDennis Gilmore #define BOOTENV_SHARED_USB 1632a43201aSDennis Gilmore #define BOOTENV_DEV_USB \ 1642a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_USB_without_CONFIG_CMD_USB 1652a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_USB \ 1662a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_USB_without_CONFIG_CMD_USB 1672a43201aSDennis Gilmore #endif 1682a43201aSDennis Gilmore 1692a43201aSDennis Gilmore #if defined(CONFIG_CMD_DHCP) 1702a43201aSDennis Gilmore #define BOOTENV_DEV_DHCP(devtypeu, devtypel, instance) \ 1712a43201aSDennis Gilmore "bootcmd_dhcp=" \ 1723483b75dSStephen Warren BOOTENV_RUN_NET_USB_START \ 173*986691fbSStephen Warren BOOTENV_RUN_NET_PCI_ENUM \ 174cc11b392SStephen Warren "if dhcp ${scriptaddr} ${boot_script_dhcp}; then " \ 1752a43201aSDennis Gilmore "source ${scriptaddr}; " \ 1762a43201aSDennis Gilmore "fi\0" 1772a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_DHCP(devtypeu, devtypel, instance) \ 1782a43201aSDennis Gilmore "dhcp " 1792a43201aSDennis Gilmore #else 1802a43201aSDennis Gilmore #define BOOTENV_DEV_DHCP \ 1812a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP 1822a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_DHCP \ 1832a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP 1842a43201aSDennis Gilmore #endif 1852a43201aSDennis Gilmore 1862a43201aSDennis Gilmore #if defined(CONFIG_CMD_DHCP) && defined(CONFIG_CMD_PXE) 1872a43201aSDennis Gilmore #define BOOTENV_DEV_PXE(devtypeu, devtypel, instance) \ 1882a43201aSDennis Gilmore "bootcmd_pxe=" \ 1893483b75dSStephen Warren BOOTENV_RUN_NET_USB_START \ 190*986691fbSStephen Warren BOOTENV_RUN_NET_PCI_ENUM \ 1912a43201aSDennis Gilmore "dhcp; " \ 1922a43201aSDennis Gilmore "if pxe get; then " \ 1932a43201aSDennis Gilmore "pxe boot; " \ 1942a43201aSDennis Gilmore "fi\0" 1952a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_PXE(devtypeu, devtypel, instance) \ 1962a43201aSDennis Gilmore "pxe " 1972a43201aSDennis Gilmore #else 1982a43201aSDennis Gilmore #define BOOTENV_DEV_PXE \ 1992a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE 2002a43201aSDennis Gilmore #define BOOTENV_DEV_NAME_PXE \ 2012a43201aSDennis Gilmore BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE 2022a43201aSDennis Gilmore #endif 2032a43201aSDennis Gilmore 2042a43201aSDennis Gilmore #define BOOTENV_DEV_NAME(devtypeu, devtypel, instance) \ 2052a43201aSDennis Gilmore BOOTENV_DEV_NAME_##devtypeu(devtypeu, devtypel, instance) 2062a43201aSDennis Gilmore #define BOOTENV_BOOT_TARGETS \ 2072a43201aSDennis Gilmore "boot_targets=" BOOT_TARGET_DEVICES(BOOTENV_DEV_NAME) "\0" 2082a43201aSDennis Gilmore 2092a43201aSDennis Gilmore #define BOOTENV_DEV(devtypeu, devtypel, instance) \ 2102a43201aSDennis Gilmore BOOTENV_DEV_##devtypeu(devtypeu, devtypel, instance) 2112a43201aSDennis Gilmore #define BOOTENV \ 212d0bce0d1SSjoerd Simons BOOTENV_SHARED_HOST \ 2132a43201aSDennis Gilmore BOOTENV_SHARED_MMC \ 214*986691fbSStephen Warren BOOTENV_SHARED_PCI \ 2152a43201aSDennis Gilmore BOOTENV_SHARED_USB \ 2162a43201aSDennis Gilmore BOOTENV_SHARED_SATA \ 2172a43201aSDennis Gilmore BOOTENV_SHARED_SCSI \ 2182a43201aSDennis Gilmore BOOTENV_SHARED_IDE \ 21940d21547SRoy Spliet BOOTENV_SHARED_UBIFS \ 2202a43201aSDennis Gilmore "boot_prefixes=/ /boot/\0" \ 2212a43201aSDennis Gilmore "boot_scripts=boot.scr.uimg boot.scr\0" \ 222cc11b392SStephen Warren "boot_script_dhcp=boot.scr.uimg\0" \ 2232a43201aSDennis Gilmore BOOTENV_BOOT_TARGETS \ 2242a43201aSDennis Gilmore \ 2252a43201aSDennis Gilmore "boot_extlinux=" \ 22659d03cb3SSjoerd Simons "sysboot ${devtype} ${devnum}:${distro_bootpart} any " \ 2272a43201aSDennis Gilmore "${scriptaddr} ${prefix}extlinux/extlinux.conf\0" \ 2282a43201aSDennis Gilmore \ 2292a43201aSDennis Gilmore "scan_dev_for_extlinux=" \ 23059d03cb3SSjoerd Simons "if test -e ${devtype} " \ 23159d03cb3SSjoerd Simons "${devnum}:${distro_bootpart} " \ 2322a43201aSDennis Gilmore "${prefix}extlinux/extlinux.conf; then " \ 2332a43201aSDennis Gilmore "echo Found ${prefix}extlinux/extlinux.conf; " \ 2342a43201aSDennis Gilmore "run boot_extlinux; " \ 2352a43201aSDennis Gilmore "echo SCRIPT FAILED: continuing...; " \ 2362a43201aSDennis Gilmore "fi\0" \ 2372a43201aSDennis Gilmore \ 2382a43201aSDennis Gilmore "boot_a_script=" \ 23959d03cb3SSjoerd Simons "load ${devtype} ${devnum}:${distro_bootpart} " \ 2402a43201aSDennis Gilmore "${scriptaddr} ${prefix}${script}; " \ 2412a43201aSDennis Gilmore "source ${scriptaddr}\0" \ 2422a43201aSDennis Gilmore \ 2432a43201aSDennis Gilmore "scan_dev_for_scripts=" \ 2442a43201aSDennis Gilmore "for script in ${boot_scripts}; do " \ 24559d03cb3SSjoerd Simons "if test -e ${devtype} " \ 24659d03cb3SSjoerd Simons "${devnum}:${distro_bootpart} " \ 2472a43201aSDennis Gilmore "${prefix}${script}; then " \ 2482a43201aSDennis Gilmore "echo Found U-Boot script " \ 2492a43201aSDennis Gilmore "${prefix}${script}; " \ 2502a43201aSDennis Gilmore "run boot_a_script; " \ 2512a43201aSDennis Gilmore "echo SCRIPT FAILED: continuing...; " \ 2522a43201aSDennis Gilmore "fi; " \ 2532a43201aSDennis Gilmore "done\0" \ 2542a43201aSDennis Gilmore \ 2552a43201aSDennis Gilmore "scan_dev_for_boot=" \ 25659d03cb3SSjoerd Simons "echo Scanning ${devtype} " \ 25759d03cb3SSjoerd Simons "${devnum}:${distro_bootpart}...; " \ 2582a43201aSDennis Gilmore "for prefix in ${boot_prefixes}; do " \ 2592a43201aSDennis Gilmore "run scan_dev_for_extlinux; " \ 2602a43201aSDennis Gilmore "run scan_dev_for_scripts; " \ 2612a43201aSDennis Gilmore "done\0" \ 2622a43201aSDennis Gilmore \ 263735b1cfeSSjoerd Simons "scan_dev_for_boot_part=" \ 264f643d929SSjoerd Simons "part list ${devtype} ${devnum} -bootable devplist; " \ 265f643d929SSjoerd Simons "env exists devplist || setenv devplist 1; " \ 26659d03cb3SSjoerd Simons "for distro_bootpart in ${devplist}; do " \ 26759d03cb3SSjoerd Simons "if fstype ${devtype} " \ 26859d03cb3SSjoerd Simons "${devnum}:${distro_bootpart} " \ 269735b1cfeSSjoerd Simons "bootfstype; then " \ 270735b1cfeSSjoerd Simons "run scan_dev_for_boot; " \ 271735b1cfeSSjoerd Simons "fi; " \ 272735b1cfeSSjoerd Simons "done\0" \ 273735b1cfeSSjoerd Simons \ 2742a43201aSDennis Gilmore BOOT_TARGET_DEVICES(BOOTENV_DEV) \ 2752a43201aSDennis Gilmore \ 276453c6cc1SSjoerd Simons "distro_bootcmd=" BOOTENV_SET_SCSI_NEED_INIT \ 2772a43201aSDennis Gilmore "for target in ${boot_targets}; do " \ 2782a43201aSDennis Gilmore "run bootcmd_${target}; " \ 2792a43201aSDennis Gilmore "done\0" 2802a43201aSDennis Gilmore 281453c6cc1SSjoerd Simons #ifndef CONFIG_BOOTCOMMAND 282453c6cc1SSjoerd Simons #define CONFIG_BOOTCOMMAND "run distro_bootcmd" 283453c6cc1SSjoerd Simons #endif 284453c6cc1SSjoerd Simons 2852a43201aSDennis Gilmore #endif /* _CONFIG_CMD_DISTRO_BOOTCMD_H */ 286