config_distro_bootcmd.h 15 KB

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