config_distro_bootcmd.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. #if defined(CONFIG_EFI_LOADER)
  214. #if defined(CONFIG_ARM64)
  215. #define BOOTENV_EFI_PXE_ARCH "0xb"
  216. #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00011:UNDI:003000"
  217. #elif defined(CONFIG_ARM)
  218. #define BOOTENV_EFI_PXE_ARCH "0xa"
  219. #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00010:UNDI:003000"
  220. #elif defined(CONFIG_X86)
  221. /* Always assume we're running 64bit */
  222. #define BOOTENV_EFI_PXE_ARCH "0x7"
  223. #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00007:UNDI:003000"
  224. #else
  225. #error Please specify an EFI client identifier
  226. #endif
  227. /*
  228. * Ask the dhcp server for an EFI binary. If we get one, check for a
  229. * device tree in the same folder. Then boot everything. If the file was
  230. * not an EFI binary, we just return from the bootefi command and continue.
  231. */
  232. #define BOOTENV_EFI_RUN_DHCP \
  233. "setenv efi_fdtfile ${fdtfile}; " \
  234. BOOTENV_EFI_SET_FDTFILE_FALLBACK \
  235. "setenv efi_old_vci ${bootp_vci};" \
  236. "setenv efi_old_arch ${bootp_arch};" \
  237. "setenv bootp_vci " BOOTENV_EFI_PXE_VCI ";" \
  238. "setenv bootp_arch " BOOTENV_EFI_PXE_ARCH ";" \
  239. "if dhcp ${kernel_addr_r}; then " \
  240. "tftpboot ${fdt_addr_r} dtb/${efi_fdtfile};" \
  241. "if fdt addr ${fdt_addr_r}; then " \
  242. "bootefi ${kernel_addr_r} ${fdt_addr_r}; " \
  243. "else " \
  244. "bootefi ${kernel_addr_r} ${fdtcontroladdr};" \
  245. "fi;" \
  246. "fi;" \
  247. "setenv bootp_vci ${efi_old_vci};" \
  248. "setenv bootp_arch ${efi_old_arch};" \
  249. "setenv efi_fdtfile;" \
  250. "setenv efi_old_arch;" \
  251. "setenv efi_old_vci;"
  252. #else
  253. #define BOOTENV_EFI_RUN_DHCP
  254. #endif
  255. #define BOOTENV_DEV_DHCP(devtypeu, devtypel, instance) \
  256. "bootcmd_dhcp=" \
  257. BOOTENV_RUN_NET_USB_START \
  258. BOOTENV_RUN_NET_PCI_ENUM \
  259. "if dhcp ${scriptaddr} ${boot_script_dhcp}; then " \
  260. "source ${scriptaddr}; " \
  261. "fi;" \
  262. BOOTENV_EFI_RUN_DHCP \
  263. "\0"
  264. #define BOOTENV_DEV_NAME_DHCP(devtypeu, devtypel, instance) \
  265. "dhcp "
  266. #else
  267. #define BOOTENV_DEV_DHCP \
  268. BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP
  269. #define BOOTENV_DEV_NAME_DHCP \
  270. BOOT_TARGET_DEVICES_references_DHCP_without_CONFIG_CMD_DHCP
  271. #endif
  272. #if defined(CONFIG_CMD_DHCP) && defined(CONFIG_CMD_PXE)
  273. #define BOOTENV_DEV_PXE(devtypeu, devtypel, instance) \
  274. "bootcmd_pxe=" \
  275. BOOTENV_RUN_NET_USB_START \
  276. BOOTENV_RUN_NET_PCI_ENUM \
  277. "dhcp; " \
  278. "if pxe get; then " \
  279. "pxe boot; " \
  280. "fi\0"
  281. #define BOOTENV_DEV_NAME_PXE(devtypeu, devtypel, instance) \
  282. "pxe "
  283. #else
  284. #define BOOTENV_DEV_PXE \
  285. BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE
  286. #define BOOTENV_DEV_NAME_PXE \
  287. BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE
  288. #endif
  289. #define BOOTENV_DEV_NAME(devtypeu, devtypel, instance) \
  290. BOOTENV_DEV_NAME_##devtypeu(devtypeu, devtypel, instance)
  291. #define BOOTENV_BOOT_TARGETS \
  292. "boot_targets=" BOOT_TARGET_DEVICES(BOOTENV_DEV_NAME) "\0"
  293. #define BOOTENV_DEV(devtypeu, devtypel, instance) \
  294. BOOTENV_DEV_##devtypeu(devtypeu, devtypel, instance)
  295. #define BOOTENV \
  296. BOOTENV_SHARED_HOST \
  297. BOOTENV_SHARED_MMC \
  298. BOOTENV_SHARED_PCI \
  299. BOOTENV_SHARED_USB \
  300. BOOTENV_SHARED_SATA \
  301. BOOTENV_SHARED_SCSI \
  302. BOOTENV_SHARED_IDE \
  303. BOOTENV_SHARED_UBIFS \
  304. BOOTENV_SHARED_EFI \
  305. "boot_prefixes=/ /boot/\0" \
  306. "boot_scripts=boot.scr.uimg boot.scr\0" \
  307. "boot_script_dhcp=boot.scr.uimg\0" \
  308. BOOTENV_BOOT_TARGETS \
  309. \
  310. "boot_extlinux=" \
  311. "sysboot ${devtype} ${devnum}:${distro_bootpart} any " \
  312. "${scriptaddr} ${prefix}extlinux/extlinux.conf\0" \
  313. \
  314. "scan_dev_for_extlinux=" \
  315. "if test -e ${devtype} " \
  316. "${devnum}:${distro_bootpart} " \
  317. "${prefix}extlinux/extlinux.conf; then " \
  318. "echo Found ${prefix}extlinux/extlinux.conf; " \
  319. "run boot_extlinux; " \
  320. "echo SCRIPT FAILED: continuing...; " \
  321. "fi\0" \
  322. \
  323. "boot_a_script=" \
  324. "load ${devtype} ${devnum}:${distro_bootpart} " \
  325. "${scriptaddr} ${prefix}${script}; " \
  326. "source ${scriptaddr}\0" \
  327. \
  328. "scan_dev_for_scripts=" \
  329. "for script in ${boot_scripts}; do " \
  330. "if test -e ${devtype} " \
  331. "${devnum}:${distro_bootpart} " \
  332. "${prefix}${script}; then " \
  333. "echo Found U-Boot script " \
  334. "${prefix}${script}; " \
  335. "run boot_a_script; " \
  336. "echo SCRIPT FAILED: continuing...; " \
  337. "fi; " \
  338. "done\0" \
  339. \
  340. "scan_dev_for_boot=" \
  341. "echo Scanning ${devtype} " \
  342. "${devnum}:${distro_bootpart}...; " \
  343. "for prefix in ${boot_prefixes}; do " \
  344. "run scan_dev_for_extlinux; " \
  345. "run scan_dev_for_scripts; " \
  346. "done;" \
  347. SCAN_DEV_FOR_EFI \
  348. "\0" \
  349. \
  350. "scan_dev_for_boot_part=" \
  351. "part list ${devtype} ${devnum} -bootable devplist; " \
  352. "env exists devplist || setenv devplist 1; " \
  353. "for distro_bootpart in ${devplist}; do " \
  354. "if fstype ${devtype} " \
  355. "${devnum}:${distro_bootpart} " \
  356. "bootfstype; then " \
  357. "run scan_dev_for_boot; " \
  358. "fi; " \
  359. "done\0" \
  360. \
  361. BOOT_TARGET_DEVICES(BOOTENV_DEV) \
  362. \
  363. "distro_bootcmd=" BOOTENV_SET_SCSI_NEED_INIT \
  364. "for target in ${boot_targets}; do " \
  365. "run bootcmd_${target}; " \
  366. "done\0"
  367. #ifndef CONFIG_BOOTCOMMAND
  368. #define CONFIG_BOOTCOMMAND "run distro_bootcmd"
  369. #endif
  370. #endif /* _CONFIG_CMD_DISTRO_BOOTCMD_H */