config_distro_bootcmd.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2014
  4. * NVIDIA Corporation <www.nvidia.com>
  5. *
  6. * Copyright 2014 Red Hat, Inc.
  7. */
  8. #ifndef _CONFIG_CMD_DISTRO_BOOTCMD_H
  9. #define _CONFIG_CMD_DISTRO_BOOTCMD_H
  10. /*
  11. * A note on error handling: It is possible for BOOT_TARGET_DEVICES to
  12. * reference a device that is not enabled in the U-Boot configuration, e.g.
  13. * it may include MMC in the list without CONFIG_CMD_MMC being enabled. Given
  14. * that BOOT_TARGET_DEVICES is a macro that's expanded by the C pre-processor
  15. * at compile time, it's not possible to detect and report such problems via
  16. * a simple #ifdef/#error combination. Still, the code needs to report errors.
  17. * The best way I've found to do this is to make BOOT_TARGET_DEVICES expand to
  18. * reference a non-existent symbol, and have the name of that symbol encode
  19. * the error message. Consequently, this file contains references to e.g.
  20. * BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC. Given the
  21. * prevalence of capitals here, this looks like a pre-processor macro and
  22. * hence seems like it should be all capitals, but it's really an error
  23. * message that includes some other pre-processor symbols in the text.
  24. */
  25. #define BOOTENV_SHARED_BLKDEV_BODY(devtypel) \
  26. "if " #devtypel " dev ${devnum}; then " \
  27. "setenv devtype " #devtypel "; " \
  28. "run scan_dev_for_boot_part; " \
  29. "fi\0"
  30. #define BOOTENV_SHARED_BLKDEV(devtypel) \
  31. #devtypel "_boot=" \
  32. BOOTENV_SHARED_BLKDEV_BODY(devtypel)
  33. #define BOOTENV_DEV_BLKDEV(devtypeu, devtypel, instance) \
  34. "bootcmd_" #devtypel #instance "=" \
  35. "setenv devnum " #instance "; " \
  36. "run " #devtypel "_boot\0"
  37. #define BOOTENV_DEV_NAME_BLKDEV(devtypeu, devtypel, instance) \
  38. #devtypel #instance " "
  39. #ifdef CONFIG_SANDBOX
  40. #define BOOTENV_SHARED_HOST BOOTENV_SHARED_BLKDEV(host)
  41. #define BOOTENV_DEV_HOST BOOTENV_DEV_BLKDEV
  42. #define BOOTENV_DEV_NAME_HOST BOOTENV_DEV_NAME_BLKDEV
  43. #else
  44. #define BOOTENV_SHARED_HOST
  45. #define BOOTENV_DEV_HOST \
  46. BOOT_TARGET_DEVICES_references_HOST_without_CONFIG_SANDBOX
  47. #define BOOTENV_DEV_NAME_HOST \
  48. BOOT_TARGET_DEVICES_references_HOST_without_CONFIG_SANDBOX
  49. #endif
  50. #ifdef CONFIG_CMD_MMC
  51. #define BOOTENV_SHARED_MMC BOOTENV_SHARED_BLKDEV(mmc)
  52. #define BOOTENV_DEV_MMC BOOTENV_DEV_BLKDEV
  53. #define BOOTENV_DEV_NAME_MMC BOOTENV_DEV_NAME_BLKDEV
  54. #else
  55. #define BOOTENV_SHARED_MMC
  56. #define BOOTENV_DEV_MMC \
  57. BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC
  58. #define BOOTENV_DEV_NAME_MMC \
  59. BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC
  60. #endif
  61. #ifdef CONFIG_CMD_UBIFS
  62. #define BOOTENV_SHARED_UBIFS \
  63. "ubifs_boot=" \
  64. "env exists bootubipart || " \
  65. "env set bootubipart UBI; " \
  66. "env exists bootubivol || " \
  67. "env set bootubivol boot; " \
  68. "if ubi part ${bootubipart} && " \
  69. "ubifsmount ubi${devnum}:${bootubivol}; " \
  70. "then " \
  71. "setenv devtype ubi; " \
  72. "run scan_dev_for_boot; " \
  73. "fi\0"
  74. #define BOOTENV_DEV_UBIFS BOOTENV_DEV_BLKDEV
  75. #define BOOTENV_DEV_NAME_UBIFS BOOTENV_DEV_NAME_BLKDEV
  76. #else
  77. #define BOOTENV_SHARED_UBIFS
  78. #define BOOTENV_DEV_UBIFS \
  79. BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS
  80. #define BOOTENV_DEV_NAME_UBIFS \
  81. BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS
  82. #endif
  83. #ifdef CONFIG_EFI_LOADER
  84. #if defined(CONFIG_ARM64)
  85. #define BOOTEFI_NAME "bootaa64.efi"
  86. #elif defined(CONFIG_ARM)
  87. #define BOOTEFI_NAME "bootarm.efi"
  88. #elif defined(CONFIG_X86_RUN_32BIT)
  89. #define BOOTEFI_NAME "bootia32.efi"
  90. #elif defined(CONFIG_X86_RUN_64BIT)
  91. #define BOOTEFI_NAME "bootx64.efi"
  92. #endif
  93. #endif
  94. #ifdef BOOTEFI_NAME
  95. #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
  96. /*
  97. * On 32bit ARM systems there is a reasonable number of systems that follow
  98. * the $soc-$board$boardver.dtb name scheme for their device trees. Use that
  99. * scheme if we don't have an explicit fdtfile variable.
  100. */
  101. #define BOOTENV_EFI_SET_FDTFILE_FALLBACK \
  102. "if test -z \"${fdtfile}\" -a -n \"${soc}\"; then " \
  103. "setenv efi_fdtfile ${soc}-${board}${boardver}.dtb; " \
  104. "fi; "
  105. #else
  106. #define BOOTENV_EFI_SET_FDTFILE_FALLBACK
  107. #endif
  108. #define BOOTENV_SHARED_EFI \
  109. "boot_efi_binary=" \
  110. "if fdt addr ${fdt_addr_r}; then " \
  111. "bootefi bootmgr ${fdt_addr_r};" \
  112. "else " \
  113. "bootefi bootmgr ${fdtcontroladdr};" \
  114. "fi;" \
  115. "load ${devtype} ${devnum}:${distro_bootpart} " \
  116. "${kernel_addr_r} efi/boot/"BOOTEFI_NAME"; " \
  117. "if fdt addr ${fdt_addr_r}; then " \
  118. "bootefi ${kernel_addr_r} ${fdt_addr_r};" \
  119. "else " \
  120. "bootefi ${kernel_addr_r} ${fdtcontroladdr};" \
  121. "fi\0" \
  122. \
  123. "load_efi_dtb=" \
  124. "load ${devtype} ${devnum}:${distro_bootpart} " \
  125. "${fdt_addr_r} ${prefix}${efi_fdtfile}\0" \
  126. \
  127. "efi_dtb_prefixes=/ /dtb/ /dtb/current/\0" \
  128. "scan_dev_for_efi=" \
  129. "setenv efi_fdtfile ${fdtfile}; " \
  130. BOOTENV_EFI_SET_FDTFILE_FALLBACK \
  131. "for prefix in ${efi_dtb_prefixes}; do " \
  132. "if test -e ${devtype} " \
  133. "${devnum}:${distro_bootpart} " \
  134. "${prefix}${efi_fdtfile}; then " \
  135. "run load_efi_dtb; " \
  136. "fi;" \
  137. "done;" \
  138. "if test -e ${devtype} ${devnum}:${distro_bootpart} " \
  139. "efi/boot/"BOOTEFI_NAME"; then " \
  140. "echo Found EFI removable media binary " \
  141. "efi/boot/"BOOTEFI_NAME"; " \
  142. "run boot_efi_binary; " \
  143. "echo EFI LOAD FAILED: continuing...; " \
  144. "fi; " \
  145. "setenv efi_fdtfile\0"
  146. #define SCAN_DEV_FOR_EFI "run scan_dev_for_efi;"
  147. #else
  148. #define BOOTENV_SHARED_EFI
  149. #define SCAN_DEV_FOR_EFI
  150. #endif
  151. #ifdef CONFIG_SATA
  152. #define BOOTENV_SHARED_SATA BOOTENV_SHARED_BLKDEV(sata)
  153. #define BOOTENV_DEV_SATA BOOTENV_DEV_BLKDEV
  154. #define BOOTENV_DEV_NAME_SATA BOOTENV_DEV_NAME_BLKDEV
  155. #else
  156. #define BOOTENV_SHARED_SATA
  157. #define BOOTENV_DEV_SATA \
  158. BOOT_TARGET_DEVICES_references_SATA_without_CONFIG_SATA
  159. #define BOOTENV_DEV_NAME_SATA \
  160. BOOT_TARGET_DEVICES_references_SATA_without_CONFIG_SATA
  161. #endif
  162. #ifdef CONFIG_SCSI
  163. #define BOOTENV_RUN_SCSI_INIT "run scsi_init; "
  164. #define BOOTENV_SET_SCSI_NEED_INIT "setenv scsi_need_init; "
  165. #define BOOTENV_SHARED_SCSI \
  166. "scsi_init=" \
  167. "if ${scsi_need_init}; then " \
  168. "setenv scsi_need_init false; " \
  169. "scsi scan; " \
  170. "fi\0" \
  171. \
  172. "scsi_boot=" \
  173. BOOTENV_RUN_SCSI_INIT \
  174. BOOTENV_SHARED_BLKDEV_BODY(scsi)
  175. #define BOOTENV_DEV_SCSI BOOTENV_DEV_BLKDEV
  176. #define BOOTENV_DEV_NAME_SCSI BOOTENV_DEV_NAME_BLKDEV
  177. #else
  178. #define BOOTENV_RUN_SCSI_INIT
  179. #define BOOTENV_SET_SCSI_NEED_INIT
  180. #define BOOTENV_SHARED_SCSI
  181. #define BOOTENV_DEV_SCSI \
  182. BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_SCSI
  183. #define BOOTENV_DEV_NAME_SCSI \
  184. BOOT_TARGET_DEVICES_references_SCSI_without_CONFIG_SCSI
  185. #endif
  186. #ifdef CONFIG_IDE
  187. #define BOOTENV_SHARED_IDE BOOTENV_SHARED_BLKDEV(ide)
  188. #define BOOTENV_DEV_IDE BOOTENV_DEV_BLKDEV
  189. #define BOOTENV_DEV_NAME_IDE BOOTENV_DEV_NAME_BLKDEV
  190. #else
  191. #define BOOTENV_SHARED_IDE
  192. #define BOOTENV_DEV_IDE \
  193. BOOT_TARGET_DEVICES_references_IDE_without_CONFIG_IDE
  194. #define BOOTENV_DEV_NAME_IDE \
  195. BOOT_TARGET_DEVICES_references_IDE_without_CONFIG_IDE
  196. #endif
  197. #if defined(CONFIG_DM_PCI)
  198. #define BOOTENV_RUN_NET_PCI_ENUM "run boot_net_pci_enum; "
  199. #define BOOTENV_SHARED_PCI \
  200. "boot_net_pci_enum=pci enum\0"
  201. #else
  202. #define BOOTENV_RUN_NET_PCI_ENUM
  203. #define BOOTENV_SHARED_PCI
  204. #endif
  205. #ifdef CONFIG_CMD_USB
  206. #define BOOTENV_RUN_NET_USB_START "run boot_net_usb_start; "
  207. #define BOOTENV_SHARED_USB \
  208. "boot_net_usb_start=usb start\0" \
  209. "usb_boot=" \
  210. "usb start; " \
  211. BOOTENV_SHARED_BLKDEV_BODY(usb)
  212. #define BOOTENV_DEV_USB BOOTENV_DEV_BLKDEV
  213. #define BOOTENV_DEV_NAME_USB BOOTENV_DEV_NAME_BLKDEV
  214. #else
  215. #define BOOTENV_RUN_NET_USB_START
  216. #define BOOTENV_SHARED_USB
  217. #define BOOTENV_DEV_USB \
  218. BOOT_TARGET_DEVICES_references_USB_without_CONFIG_CMD_USB
  219. #define BOOTENV_DEV_NAME_USB \
  220. BOOT_TARGET_DEVICES_references_USB_without_CONFIG_CMD_USB
  221. #endif
  222. #if defined(CONFIG_CMD_DHCP)
  223. #if defined(CONFIG_EFI_LOADER)
  224. #if defined(CONFIG_ARM64)
  225. #define BOOTENV_EFI_PXE_ARCH "0xb"
  226. #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00011:UNDI:003000"
  227. #elif defined(CONFIG_ARM)
  228. #define BOOTENV_EFI_PXE_ARCH "0xa"
  229. #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00010:UNDI:003000"
  230. #elif defined(CONFIG_X86)
  231. /* Always assume we're running 64bit */
  232. #define BOOTENV_EFI_PXE_ARCH "0x7"
  233. #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00007:UNDI:003000"
  234. #else
  235. #error Please specify an EFI client identifier
  236. #endif
  237. /*
  238. * Ask the dhcp server for an EFI binary. If we get one, check for a
  239. * device tree in the same folder. Then boot everything. If the file was
  240. * not an EFI binary, we just return from the bootefi command and continue.
  241. */
  242. #define BOOTENV_EFI_RUN_DHCP \
  243. "setenv efi_fdtfile ${fdtfile}; " \
  244. BOOTENV_EFI_SET_FDTFILE_FALLBACK \
  245. "setenv efi_old_vci ${bootp_vci};" \
  246. "setenv efi_old_arch ${bootp_arch};" \
  247. "setenv bootp_vci " BOOTENV_EFI_PXE_VCI ";" \
  248. "setenv bootp_arch " BOOTENV_EFI_PXE_ARCH ";" \
  249. "if dhcp ${kernel_addr_r}; then " \
  250. "tftpboot ${fdt_addr_r} dtb/${efi_fdtfile};" \
  251. "if fdt addr ${fdt_addr_r}; then " \
  252. "bootefi ${kernel_addr_r} ${fdt_addr_r}; " \
  253. "else " \
  254. "bootefi ${kernel_addr_r} ${fdtcontroladdr};" \
  255. "fi;" \
  256. "fi;" \
  257. "setenv bootp_vci ${efi_old_vci};" \
  258. "setenv bootp_arch ${efi_old_arch};" \
  259. "setenv efi_fdtfile;" \
  260. "setenv efi_old_arch;" \
  261. "setenv efi_old_vci;"
  262. #else
  263. #define BOOTENV_EFI_RUN_DHCP
  264. #endif
  265. #define BOOTENV_DEV_DHCP(devtypeu, devtypel, instance) \
  266. "bootcmd_dhcp=" \
  267. BOOTENV_RUN_NET_USB_START \
  268. BOOTENV_RUN_NET_PCI_ENUM \
  269. "if dhcp ${scriptaddr} ${boot_script_dhcp}; then " \
  270. "source ${scriptaddr}; " \
  271. "fi;" \
  272. BOOTENV_EFI_RUN_DHCP \
  273. "\0"
  274. #define BOOTENV_DEV_NAME_DHCP(devtypeu, devtypel, instance) \
  275. "dhcp "
  276. #else
  277. #define BOOTENV_DEV_DHCP \
  278. BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP
  279. #define BOOTENV_DEV_NAME_DHCP \
  280. BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP
  281. #endif
  282. #if defined(CONFIG_CMD_DHCP) && defined(CONFIG_CMD_PXE)
  283. #define BOOTENV_DEV_PXE(devtypeu, devtypel, instance) \
  284. "bootcmd_pxe=" \
  285. BOOTENV_RUN_NET_USB_START \
  286. BOOTENV_RUN_NET_PCI_ENUM \
  287. "dhcp; " \
  288. "if pxe get; then " \
  289. "pxe boot; " \
  290. "fi\0"
  291. #define BOOTENV_DEV_NAME_PXE(devtypeu, devtypel, instance) \
  292. "pxe "
  293. #else
  294. #define BOOTENV_DEV_PXE \
  295. BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE
  296. #define BOOTENV_DEV_NAME_PXE \
  297. BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE
  298. #endif
  299. #define BOOTENV_DEV_NAME(devtypeu, devtypel, instance) \
  300. BOOTENV_DEV_NAME_##devtypeu(devtypeu, devtypel, instance)
  301. #define BOOTENV_BOOT_TARGETS \
  302. "boot_targets=" BOOT_TARGET_DEVICES(BOOTENV_DEV_NAME) "\0"
  303. #define BOOTENV_DEV(devtypeu, devtypel, instance) \
  304. BOOTENV_DEV_##devtypeu(devtypeu, devtypel, instance)
  305. #define BOOTENV \
  306. BOOTENV_SHARED_HOST \
  307. BOOTENV_SHARED_MMC \
  308. BOOTENV_SHARED_PCI \
  309. BOOTENV_SHARED_USB \
  310. BOOTENV_SHARED_SATA \
  311. BOOTENV_SHARED_SCSI \
  312. BOOTENV_SHARED_IDE \
  313. BOOTENV_SHARED_UBIFS \
  314. BOOTENV_SHARED_EFI \
  315. "boot_prefixes=/ /boot/\0" \
  316. "boot_scripts=boot.scr.uimg boot.scr\0" \
  317. "boot_script_dhcp=boot.scr.uimg\0" \
  318. BOOTENV_BOOT_TARGETS \
  319. \
  320. "boot_extlinux=" \
  321. "sysboot ${devtype} ${devnum}:${distro_bootpart} any " \
  322. "${scriptaddr} ${prefix}extlinux/extlinux.conf\0" \
  323. \
  324. "scan_dev_for_extlinux=" \
  325. "if test -e ${devtype} " \
  326. "${devnum}:${distro_bootpart} " \
  327. "${prefix}extlinux/extlinux.conf; then " \
  328. "echo Found ${prefix}extlinux/extlinux.conf; " \
  329. "run boot_extlinux; " \
  330. "echo SCRIPT FAILED: continuing...; " \
  331. "fi\0" \
  332. \
  333. "boot_a_script=" \
  334. "load ${devtype} ${devnum}:${distro_bootpart} " \
  335. "${scriptaddr} ${prefix}${script}; " \
  336. "source ${scriptaddr}\0" \
  337. \
  338. "scan_dev_for_scripts=" \
  339. "for script in ${boot_scripts}; do " \
  340. "if test -e ${devtype} " \
  341. "${devnum}:${distro_bootpart} " \
  342. "${prefix}${script}; then " \
  343. "echo Found U-Boot script " \
  344. "${prefix}${script}; " \
  345. "run boot_a_script; " \
  346. "echo SCRIPT FAILED: continuing...; " \
  347. "fi; " \
  348. "done\0" \
  349. \
  350. "scan_dev_for_boot=" \
  351. "echo Scanning ${devtype} " \
  352. "${devnum}:${distro_bootpart}...; " \
  353. "for prefix in ${boot_prefixes}; do " \
  354. "run scan_dev_for_extlinux; " \
  355. "run scan_dev_for_scripts; " \
  356. "done;" \
  357. SCAN_DEV_FOR_EFI \
  358. "\0" \
  359. \
  360. "scan_dev_for_boot_part=" \
  361. "part list ${devtype} ${devnum} -bootable devplist; " \
  362. "env exists devplist || setenv devplist 1; " \
  363. "for distro_bootpart in ${devplist}; do " \
  364. "if fstype ${devtype} " \
  365. "${devnum}:${distro_bootpart} " \
  366. "bootfstype; then " \
  367. "run scan_dev_for_boot; " \
  368. "fi; " \
  369. "done\0" \
  370. \
  371. BOOT_TARGET_DEVICES(BOOTENV_DEV) \
  372. \
  373. "distro_bootcmd=" BOOTENV_SET_SCSI_NEED_INIT \
  374. "for target in ${boot_targets}; do " \
  375. "run bootcmd_${target}; " \
  376. "done\0"
  377. #ifndef CONFIG_BOOTCOMMAND
  378. #define CONFIG_BOOTCOMMAND "run distro_bootcmd"
  379. #endif
  380. #endif /* _CONFIG_CMD_DISTRO_BOOTCMD_H */