boot-common.c 5.9 KB

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