boot-common.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * boot-common.c
  4. *
  5. * Common bootmode functions for omap based boards
  6. *
  7. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  8. */
  9. #include <common.h>
  10. #include <ahci.h>
  11. #include <spl.h>
  12. #include <asm/omap_common.h>
  13. #include <asm/arch/omap.h>
  14. #include <asm/arch/mmc_host_def.h>
  15. #include <asm/arch/sys_proto.h>
  16. #include <watchdog.h>
  17. #include <scsi.h>
  18. #include <i2c.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. __weak u32 omap_sys_boot_device(void)
  21. {
  22. return BOOT_DEVICE_NONE;
  23. }
  24. void save_omap_boot_params(void)
  25. {
  26. u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
  27. struct omap_boot_parameters *omap_boot_params;
  28. int sys_boot_device = 0;
  29. u32 boot_device;
  30. u32 boot_mode;
  31. if ((boot_params < NON_SECURE_SRAM_START) ||
  32. (boot_params > NON_SECURE_SRAM_END))
  33. return;
  34. omap_boot_params = (struct omap_boot_parameters *)boot_params;
  35. boot_device = omap_boot_params->boot_device;
  36. boot_mode = MMCSD_MODE_UNDEFINED;
  37. /* Boot device */
  38. #ifdef BOOT_DEVICE_NAND_I2C
  39. /*
  40. * Re-map NAND&I2C boot-device to the "normal" NAND boot-device.
  41. * Otherwise the SPL boot IF can't handle this device correctly.
  42. * Somehow booting with Hynix 4GBit NAND H27U4G8 on Siemens
  43. * Draco leads to this boot-device passed to SPL from the BootROM.
  44. */
  45. if (boot_device == BOOT_DEVICE_NAND_I2C)
  46. boot_device = BOOT_DEVICE_NAND;
  47. #endif
  48. #ifdef BOOT_DEVICE_QSPI_4
  49. /*
  50. * We get different values for QSPI_1 and QSPI_4 being used, but
  51. * don't actually care about this difference. Rather than
  52. * mangle the later code, if we're coming in as QSPI_4 just
  53. * change to the QSPI_1 value.
  54. */
  55. if (boot_device == BOOT_DEVICE_QSPI_4)
  56. boot_device = BOOT_DEVICE_SPI;
  57. #endif
  58. #ifdef CONFIG_TI816X
  59. /*
  60. * On PG2.0 and later TI816x the values we get when booting are not the
  61. * same as on PG1.0, which is what the defines are based on. Update
  62. * them as needed.
  63. */
  64. if (get_cpu_rev() != 1) {
  65. if (boot_device == 0x05) {
  66. omap_boot_params->boot_device = BOOT_DEVICE_NAND;
  67. boot_device = BOOT_DEVICE_NAND;
  68. }
  69. if (boot_device == 0x08) {
  70. omap_boot_params->boot_device = BOOT_DEVICE_MMC1;
  71. boot_device = BOOT_DEVICE_MMC1;
  72. }
  73. }
  74. #endif
  75. /*
  76. * When booting from peripheral booting, the boot device is not usable
  77. * as-is (unless there is support for it), so the boot device is instead
  78. * figured out using the SYS_BOOT pins.
  79. */
  80. switch (boot_device) {
  81. #if defined(BOOT_DEVICE_UART) && !defined(CONFIG_SPL_YMODEM_SUPPORT)
  82. case BOOT_DEVICE_UART:
  83. sys_boot_device = 1;
  84. break;
  85. #endif
  86. #if defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_STORAGE)
  87. case BOOT_DEVICE_USB:
  88. sys_boot_device = 1;
  89. break;
  90. #endif
  91. #if defined(BOOT_DEVICE_USBETH) && !defined(CONFIG_SPL_USB_ETHER)
  92. case BOOT_DEVICE_USBETH:
  93. sys_boot_device = 1;
  94. break;
  95. #endif
  96. #if defined(BOOT_DEVICE_CPGMAC) && !defined(CONFIG_SPL_ETH_SUPPORT)
  97. case BOOT_DEVICE_CPGMAC:
  98. sys_boot_device = 1;
  99. break;
  100. #endif
  101. #if defined(BOOT_DEVICE_DFU) && !defined(CONFIG_SPL_DFU)
  102. case BOOT_DEVICE_DFU:
  103. sys_boot_device = 1;
  104. break;
  105. #endif
  106. }
  107. if (sys_boot_device) {
  108. boot_device = omap_sys_boot_device();
  109. /* MMC raw mode will fallback to FS mode. */
  110. if ((boot_device >= MMC_BOOT_DEVICES_START) &&
  111. (boot_device <= MMC_BOOT_DEVICES_END))
  112. boot_mode = MMCSD_MODE_RAW;
  113. }
  114. gd->arch.omap_boot_device = boot_device;
  115. /* Boot mode */
  116. #ifdef CONFIG_OMAP34XX
  117. if ((boot_device >= MMC_BOOT_DEVICES_START) &&
  118. (boot_device <= MMC_BOOT_DEVICES_END)) {
  119. switch (boot_device) {
  120. case BOOT_DEVICE_MMC1:
  121. boot_mode = MMCSD_MODE_FS;
  122. break;
  123. case BOOT_DEVICE_MMC2:
  124. boot_mode = MMCSD_MODE_RAW;
  125. break;
  126. }
  127. }
  128. #else
  129. /*
  130. * If the boot device was dynamically changed and doesn't match what
  131. * the bootrom initially booted, we cannot use the boot device
  132. * descriptor to figure out the boot mode.
  133. */
  134. if ((boot_device == omap_boot_params->boot_device) &&
  135. (boot_device >= MMC_BOOT_DEVICES_START) &&
  136. (boot_device <= MMC_BOOT_DEVICES_END)) {
  137. boot_params = omap_boot_params->boot_device_descriptor;
  138. if ((boot_params < NON_SECURE_SRAM_START) ||
  139. (boot_params > NON_SECURE_SRAM_END))
  140. return;
  141. boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET));
  142. if ((boot_params < NON_SECURE_SRAM_START) ||
  143. (boot_params > NON_SECURE_SRAM_END))
  144. return;
  145. boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET));
  146. if (boot_mode != MMCSD_MODE_FS &&
  147. boot_mode != MMCSD_MODE_RAW)
  148. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  149. boot_mode = MMCSD_MODE_EMMCBOOT;
  150. #else
  151. boot_mode = MMCSD_MODE_UNDEFINED;
  152. #endif
  153. }
  154. #endif
  155. gd->arch.omap_boot_mode = boot_mode;
  156. #if !defined(CONFIG_TI814X) && !defined(CONFIG_TI816X) && \
  157. !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX)
  158. /* CH flags */
  159. gd->arch.omap_ch_flags = omap_boot_params->ch_flags;
  160. #endif
  161. }
  162. #ifdef CONFIG_SPL_BUILD
  163. u32 spl_boot_device(void)
  164. {
  165. return gd->arch.omap_boot_device;
  166. }
  167. u32 spl_boot_mode(const u32 boot_device)
  168. {
  169. return gd->arch.omap_boot_mode;
  170. }
  171. void spl_board_init(void)
  172. {
  173. #ifdef CONFIG_SPL_SERIAL_SUPPORT
  174. /* Prepare console output */
  175. preloader_console_init();
  176. #endif
  177. #if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
  178. gpmc_init();
  179. #endif
  180. #if defined(CONFIG_SPL_I2C_SUPPORT) && !defined(CONFIG_DM_I2C)
  181. i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
  182. #endif
  183. #if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
  184. arch_misc_init();
  185. #endif
  186. #if defined(CONFIG_HW_WATCHDOG)
  187. hw_watchdog_init();
  188. #endif
  189. #ifdef CONFIG_AM33XX
  190. am33xx_spl_board_init();
  191. #endif
  192. }
  193. void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  194. {
  195. typedef void __noreturn (*image_entry_noargs_t)(u32 *);
  196. image_entry_noargs_t image_entry =
  197. (image_entry_noargs_t) spl_image->entry_point;
  198. u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
  199. debug("image entry point: 0x%lX\n", spl_image->entry_point);
  200. /* Pass the saved boot_params from rom code */
  201. image_entry((u32 *)boot_params);
  202. }
  203. #endif
  204. #ifdef CONFIG_SCSI_AHCI_PLAT
  205. void arch_preboot_os(void)
  206. {
  207. ahci_reset((void __iomem *)DWC_AHSATA_BASE);
  208. }
  209. #endif