config_distro_bootcmd.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. #ifndef _CONFIG_CMD_DISTRO_BOOTCMD_H
  10. #define _CONFIG_CMD_DISTRO_BOOTCMD_H
  11. /*
  12. * A note on error handling: It is possible for BOOT_TARGET_DEVICES to
  13. * reference a device that is not enabled in the U-Boot configuration, e.g.
  14. * it may include MMC in the list without CONFIG_CMD_MMC being enabled. Given
  15. * that BOOT_TARGET_DEVICES is a macro that's expanded by the C pre-processor
  16. * at compile time, it's not possible to detect and report such problems via
  17. * a simple #ifdef/#error combination. Still, the code needs to report errors.
  18. * The best way I've found to do this is to make BOOT_TARGET_DEVICES expand to
  19. * reference a non-existent symbol, and have the name of that symbol encode
  20. * the error message. Consequently, this file contains references to e.g.
  21. * BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC. Given the
  22. * prevalence of capitals here, this looks like a pre-processor macro and
  23. * hence seems like it should be all capitals, but it's really an error
  24. * message that includes some other pre-processor symbols in the text.
  25. */
  26. /* We need the part command */
  27. #define CONFIG_PARTITION_UUIDS
  28. #define CONFIG_CMD_PART
  29. #define BOOTENV_SHARED_BLKDEV_BODY(devtypel) \
  30. "if " #devtypel " dev ${devnum}; then " \
  31. "setenv devtype " #devtypel "; " \
  32. "run scan_dev_for_boot_part; " \
  33. "fi\0"
  34. #define BOOTENV_SHARED_BLKDEV(devtypel) \
  35. #devtypel "_boot=" \
  36. BOOTENV_SHARED_BLKDEV_BODY(devtypel)
  37. #define BOOTENV_DEV_BLKDEV(devtypeu, devtypel, instance) \
  38. "bootcmd_" #devtypel #instance "=" \
  39. "setenv devnum " #instance "; " \
  40. "run " #devtypel "_boot\0"
  41. #define BOOTENV_DEV_NAME_BLKDEV(devtypeu, devtypel, instance) \
  42. #devtypel #instance " "
  43. #ifdef CONFIG_SANDBOX
  44. #define BOOTENV_SHARED_HOST BOOTENV_SHARED_BLKDEV(host)
  45. #define BOOTENV_DEV_HOST BOOTENV_DEV_BLKDEV
  46. #define BOOTENV_DEV_NAME_HOST BOOTENV_DEV_NAME_BLKDEV
  47. #else
  48. #define BOOTENV_SHARED_HOST
  49. #define BOOTENV_DEV_HOST \
  50. BOOT_TARGET_DEVICES_references_HOST_without_CONFIG_SANDBOX
  51. #define BOOTENV_DEV_NAME_HOST \
  52. BOOT_TARGET_DEVICES_references_HOST_without_CONFIG_SANDBOX
  53. #endif
  54. #ifdef CONFIG_CMD_MMC
  55. #define BOOTENV_SHARED_MMC BOOTENV_SHARED_BLKDEV(mmc)
  56. #define BOOTENV_DEV_MMC BOOTENV_DEV_BLKDEV
  57. #define BOOTENV_DEV_NAME_MMC BOOTENV_DEV_NAME_BLKDEV
  58. #else
  59. #define BOOTENV_SHARED_MMC
  60. #define BOOTENV_DEV_MMC \
  61. BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC
  62. #define BOOTENV_DEV_NAME_MMC \
  63. BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC
  64. #endif
  65. #ifdef CONFIG_CMD_UBIFS
  66. #define BOOTENV_SHARED_UBIFS \
  67. "ubifs_boot=" \
  68. "if ubi part UBI && ubifsmount ubi${devnum}:boot; then " \
  69. "setenv devtype ubi; " \
  70. "setenv bootpart 0; " \
  71. "run scan_dev_for_boot; " \
  72. "fi\0"
  73. #define BOOTENV_DEV_UBIFS BOOTENV_DEV_BLKDEV
  74. #define BOOTENV_DEV_NAME_UBIFS BOOTENV_DEV_NAME_BLKDEV
  75. #else
  76. #define BOOTENV_SHARED_UBIFS
  77. #define BOOTENV_DEV_UBIFS \
  78. BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS
  79. #define BOOTENV_DEV_NAME_UBIFS \
  80. BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS
  81. #endif
  82. #ifdef CONFIG_EFI_LOADER
  83. #if defined(CONFIG_ARM64)
  84. #define BOOTEFI_NAME "bootaa64.efi"
  85. #elif defined(CONFIG_ARM)
  86. #define BOOTEFI_NAME "bootarm.efi"
  87. #endif
  88. #endif
  89. #ifdef BOOTEFI_NAME
  90. #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
  91. /*
  92. * On 32bit ARM systems there is a reasonable number of systems that follow
  93. * the $soc-$board$boardver.dtb name scheme for their device trees. Use that
  94. * scheme if we don't have an explicit fdtfile variable.
  95. */
  96. #define BOOTENV_EFI_SET_FDTFILE_FALLBACK \
  97. "if test -z \"${fdtfile}\" -a -n \"${soc}\"; then " \
  98. "setenv efi_fdtfile ${soc}-${board}${boardver}.dtb; " \
  99. "fi; "
  100. #else
  101. #define BOOTENV_EFI_SET_FDTFILE_FALLBACK
  102. #endif
  103. #define BOOTENV_SHARED_EFI \
  104. "boot_efi_binary=" \
  105. "load ${devtype} ${devnum}:${distro_bootpart} " \
  106. "${kernel_addr_r} efi/boot/"BOOTEFI_NAME"; " \
  107. "if fdt addr ${fdt_addr_r}; then " \
  108. "bootefi ${kernel_addr_r} ${fdt_addr_r};" \
  109. "else" \
  110. "bootefi ${kernel_addr_r} ${fdtcontroladdr};" \
  111. "fi\0" \
  112. \
  113. "load_efi_dtb=" \
  114. "load ${devtype} ${devnum}:${distro_bootpart} " \
  115. "${fdt_addr_r} ${prefix}${efi_fdtfile}\0" \
  116. \
  117. "efi_dtb_prefixes=/ /dtb/ /dtb/current/\0" \
  118. "scan_dev_for_efi=" \
  119. "setenv efi_fdtfile ${fdtfile}; " \
  120. BOOTENV_EFI_SET_FDTFILE_FALLBACK \
  121. "for prefix in ${efi_dtb_prefixes}; do " \
  122. "if test -e ${devtype} " \
  123. "${devnum}:${distro_bootpart} " \
  124. "${prefix}${efi_fdtfile}; then " \
  125. "run load_efi_dtb; " \
  126. "fi;" \
  127. "done;" \
  128. "if test -e ${devtype} ${devnum}:${distro_bootpart} " \
  129. "efi/boot/"BOOTEFI_NAME"; then " \
  130. "echo Found EFI removable media binary " \
  131. "efi/boot/"BOOTEFI_NAME"; " \
  132. "run boot_efi_binary; " \
  133. "echo EFI LOAD FAILED: continuing...; " \
  134. "fi; " \
  135. "setenv efi_fdtfile\0"
  136. #define SCAN_DEV_FOR_EFI "run scan_dev_for_efi;"
  137. #else
  138. #define BOOTENV_SHARED_EFI
  139. #define SCAN_DEV_FOR_EFI
  140. #endif
  141. #ifdef CONFIG_CMD_SATA
  142. #define BOOTENV_SHARED_SATA BOOTENV_SHARED_BLKDEV(sata)
  143. #define BOOTENV_DEV_SATA BOOTENV_DEV_BLKDEV
  144. #define BOOTENV_DEV_NAME_SATA BOOTENV_DEV_NAME_BLKDEV
  145. #else
  146. #define BOOTENV_SHARED_SATA
  147. #define BOOTENV_DEV_SATA \
  148. BOOT_TARGET_DEVICES_references_SATA_without_CONFIG_CMD_SATA
  149. #define BOOTENV_DEV_NAME_SATA \
  150. BOOT_TARGET_DEVICES_references_SATA_without_CONFIG_CMD_SATA
  151. #endif
  152. #ifdef CONFIG_SCSI
  153. #define BOOTENV_RUN_SCSI_INIT "run scsi_init; "
  154. #define BOOTENV_SET_SCSI_NEED_INIT "setenv scsi_need_init; "
  155. #define BOOTENV_SHARED_SCSI \
  156. "scsi_init=" \
  157. "if ${scsi_need_init}; then " \
  158. "setenv scsi_need_init false; " \
  159. "scsi scan; " \
  160. "fi\0" \
  161. \
  162. "scsi_boot=" \
  163. BOOTENV_RUN_SCSI_INIT \
  164. BOOTENV_SHARED_BLKDEV_BODY(scsi)
  165. #define BOOTENV_DEV_SCSI BOOTENV_DEV_BLKDEV
  166. #define BOOTENV_DEV_NAME_SCSI BOOTENV_DEV_NAME_BLKDEV
  167. #else
  168. #define BOOTENV_RUN_SCSI_INIT
  169. #define BOOTENV_SET_SCSI_NEED_INIT
  170. #define BOOTENV_SHARED_SCSI
  171. #define BOOTENV_DEV_SCSI \
  172. BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_SCSI
  173. #define BOOTENV_DEV_NAME_SCSI \
  174. BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_SCSI
  175. #endif
  176. #ifdef CONFIG_CMD_IDE
  177. #define BOOTENV_SHARED_IDE BOOTENV_SHARED_BLKDEV(ide)
  178. #define BOOTENV_DEV_IDE BOOTENV_DEV_BLKDEV
  179. #define BOOTENV_DEV_NAME_IDE BOOTENV_DEV_NAME_BLKDEV
  180. #else
  181. #define BOOTENV_SHARED_IDE
  182. #define BOOTENV_DEV_IDE \
  183. BOOT_TARGET_DEVICES_references_IDE_without_CONFIG_CMD_IDE
  184. #define BOOTENV_DEV_NAME_IDE \
  185. BOOT_TARGET_DEVICES_references_IDE_without_CONFIG_CMD_IDE
  186. #endif
  187. #if defined(CONFIG_CMD_PCI_ENUM) || defined(CONFIG_DM_PCI)
  188. #define BOOTENV_RUN_NET_PCI_ENUM "run boot_net_pci_enum; "
  189. #define BOOTENV_SHARED_PCI \
  190. "boot_net_pci_enum=pci enum\0"
  191. #else
  192. #define BOOTENV_RUN_NET_PCI_ENUM
  193. #define BOOTENV_SHARED_PCI
  194. #endif
  195. #ifdef CONFIG_CMD_USB
  196. #define BOOTENV_RUN_NET_USB_START "run boot_net_usb_start; "
  197. #define BOOTENV_SHARED_USB \
  198. "boot_net_usb_start=usb start\0" \
  199. "usb_boot=" \
  200. "usb start; " \
  201. BOOTENV_SHARED_BLKDEV_BODY(usb)
  202. #define BOOTENV_DEV_USB BOOTENV_DEV_BLKDEV
  203. #define BOOTENV_DEV_NAME_USB BOOTENV_DEV_NAME_BLKDEV
  204. #else
  205. #define BOOTENV_RUN_NET_USB_START
  206. #define BOOTENV_SHARED_USB
  207. #define BOOTENV_DEV_USB \
  208. BOOT_TARGET_DEVICES_references_USB_without_CONFIG_CMD_USB
  209. #define BOOTENV_DEV_NAME_USB \
  210. BOOT_TARGET_DEVICES_references_USB_without_CONFIG_CMD_USB
  211. #endif
  212. #if defined(CONFIG_CMD_DHCP)
  213. #define BOOTENV_DEV_DHCP(devtypeu, devtypel, instance) \
  214. "bootcmd_dhcp=" \
  215. BOOTENV_RUN_NET_USB_START \
  216. BOOTENV_RUN_NET_PCI_ENUM \
  217. "if dhcp ${scriptaddr} ${boot_script_dhcp}; then " \
  218. "source ${scriptaddr}; " \
  219. "fi\0"
  220. #define BOOTENV_DEV_NAME_DHCP(devtypeu, devtypel, instance) \
  221. "dhcp "
  222. #else
  223. #define BOOTENV_DEV_DHCP \
  224. BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP
  225. #define BOOTENV_DEV_NAME_DHCP \
  226. BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP
  227. #endif
  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. #define BOOTENV_DEV_NAME(devtypeu, devtypel, instance) \
  246. BOOTENV_DEV_NAME_##devtypeu(devtypeu, devtypel, instance)
  247. #define BOOTENV_BOOT_TARGETS \
  248. "boot_targets=" BOOT_TARGET_DEVICES(BOOTENV_DEV_NAME) "\0"
  249. #define BOOTENV_DEV(devtypeu, devtypel, instance) \
  250. BOOTENV_DEV_##devtypeu(devtypeu, devtypel, instance)
  251. #define BOOTENV \
  252. BOOTENV_SHARED_HOST \
  253. BOOTENV_SHARED_MMC \
  254. BOOTENV_SHARED_PCI \
  255. BOOTENV_SHARED_USB \
  256. BOOTENV_SHARED_SATA \
  257. BOOTENV_SHARED_SCSI \
  258. BOOTENV_SHARED_IDE \
  259. BOOTENV_SHARED_UBIFS \
  260. BOOTENV_SHARED_EFI \
  261. "boot_prefixes=/ /boot/\0" \
  262. "boot_scripts=boot.scr.uimg boot.scr\0" \
  263. "boot_script_dhcp=boot.scr.uimg\0" \
  264. BOOTENV_BOOT_TARGETS \
  265. \
  266. "boot_extlinux=" \
  267. "sysboot ${devtype} ${devnum}:${distro_bootpart} any " \
  268. "${scriptaddr} ${prefix}extlinux/extlinux.conf\0" \
  269. \
  270. "scan_dev_for_extlinux=" \
  271. "if test -e ${devtype} " \
  272. "${devnum}:${distro_bootpart} " \
  273. "${prefix}extlinux/extlinux.conf; then " \
  274. "echo Found ${prefix}extlinux/extlinux.conf; " \
  275. "run boot_extlinux; " \
  276. "echo SCRIPT FAILED: continuing...; " \
  277. "fi\0" \
  278. \
  279. "boot_a_script=" \
  280. "load ${devtype} ${devnum}:${distro_bootpart} " \
  281. "${scriptaddr} ${prefix}${script}; " \
  282. "source ${scriptaddr}\0" \
  283. \
  284. "scan_dev_for_scripts=" \
  285. "for script in ${boot_scripts}; do " \
  286. "if test -e ${devtype} " \
  287. "${devnum}:${distro_bootpart} " \
  288. "${prefix}${script}; then " \
  289. "echo Found U-Boot script " \
  290. "${prefix}${script}; " \
  291. "run boot_a_script; " \
  292. "echo SCRIPT FAILED: continuing...; " \
  293. "fi; " \
  294. "done\0" \
  295. \
  296. "scan_dev_for_boot=" \
  297. "echo Scanning ${devtype} " \
  298. "${devnum}:${distro_bootpart}...; " \
  299. "for prefix in ${boot_prefixes}; do " \
  300. "run scan_dev_for_extlinux; " \
  301. "run scan_dev_for_scripts; " \
  302. "done;" \
  303. SCAN_DEV_FOR_EFI \
  304. "\0" \
  305. \
  306. "scan_dev_for_boot_part=" \
  307. "part list ${devtype} ${devnum} -bootable devplist; " \
  308. "env exists devplist || setenv devplist 1; " \
  309. "for distro_bootpart in ${devplist}; do " \
  310. "if fstype ${devtype} " \
  311. "${devnum}:${distro_bootpart} " \
  312. "bootfstype; then " \
  313. "run scan_dev_for_boot; " \
  314. "fi; " \
  315. "done\0" \
  316. \
  317. BOOT_TARGET_DEVICES(BOOTENV_DEV) \
  318. \
  319. "distro_bootcmd=" BOOTENV_SET_SCSI_NEED_INIT \
  320. "for target in ${boot_targets}; do " \
  321. "run bootcmd_${target}; " \
  322. "done\0"
  323. #ifndef CONFIG_BOOTCOMMAND
  324. #define CONFIG_BOOTCOMMAND "run distro_bootcmd"
  325. #endif
  326. #endif /* _CONFIG_CMD_DISTRO_BOOTCMD_H */