boot-common.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. 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. #if (defined(BOOT_DEVICE_UART) && !defined(CONFIG_SPL_YMODEM_SUPPORT)) || \
  59. (defined(BOOT_DEVICE_USB) && !defined(CONFIG_SPL_USB_SUPPORT)) || \
  60. (defined(BOOT_DEVICE_USBETH) && !defined(CONFIG_SPL_USBETH_SUPPORT))
  61. /*
  62. * When booting from peripheral booting, the boot device is not usable
  63. * as-is (unless there is support for it), so the boot device is instead
  64. * figured out using the SYS_BOOT pins.
  65. */
  66. switch (boot_device) {
  67. #ifdef BOOT_DEVICE_UART
  68. case BOOT_DEVICE_UART:
  69. #endif
  70. #ifdef BOOT_DEVICE_USB
  71. case BOOT_DEVICE_USB:
  72. #endif
  73. boot_device = omap_sys_boot_device();
  74. /* MMC raw mode will fallback to FS mode. */
  75. if ((boot_device >= MMC_BOOT_DEVICES_START) &&
  76. (boot_device <= MMC_BOOT_DEVICES_END))
  77. boot_mode = MMCSD_MODE_RAW;
  78. break;
  79. }
  80. #endif
  81. gd->arch.omap_boot_device = boot_device;
  82. /* Boot mode */
  83. #ifdef CONFIG_OMAP34XX
  84. if ((boot_device >= MMC_BOOT_DEVICES_START) &&
  85. (boot_device <= MMC_BOOT_DEVICES_END)) {
  86. switch (boot_device) {
  87. case BOOT_DEVICE_MMC1:
  88. boot_mode = MMCSD_MODE_FS;
  89. break;
  90. case BOOT_DEVICE_MMC2:
  91. boot_mode = MMCSD_MODE_RAW;
  92. break;
  93. }
  94. }
  95. #else
  96. /*
  97. * If the boot device was dynamically changed and doesn't match what
  98. * the bootrom initially booted, we cannot use the boot device
  99. * descriptor to figure out the boot mode.
  100. */
  101. if ((boot_device == omap_boot_params->boot_device) &&
  102. (boot_device >= MMC_BOOT_DEVICES_START) &&
  103. (boot_device <= MMC_BOOT_DEVICES_END)) {
  104. boot_params = omap_boot_params->boot_device_descriptor;
  105. if ((boot_params < NON_SECURE_SRAM_START) ||
  106. (boot_params > NON_SECURE_SRAM_END))
  107. return;
  108. boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET));
  109. if ((boot_params < NON_SECURE_SRAM_START) ||
  110. (boot_params > NON_SECURE_SRAM_END))
  111. return;
  112. boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET));
  113. if (boot_mode != MMCSD_MODE_FS &&
  114. boot_mode != MMCSD_MODE_RAW)
  115. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  116. boot_mode = MMCSD_MODE_EMMCBOOT;
  117. #else
  118. boot_mode = MMCSD_MODE_UNDEFINED;
  119. #endif
  120. }
  121. #endif
  122. gd->arch.omap_boot_mode = boot_mode;
  123. #if !defined(CONFIG_TI814X) && !defined(CONFIG_TI816X) && \
  124. !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX)
  125. /* CH flags */
  126. gd->arch.omap_ch_flags = omap_boot_params->ch_flags;
  127. #endif
  128. }
  129. #ifdef CONFIG_SPL_BUILD
  130. u32 spl_boot_device(void)
  131. {
  132. return gd->arch.omap_boot_device;
  133. }
  134. u32 spl_boot_mode(void)
  135. {
  136. return gd->arch.omap_boot_mode;
  137. }
  138. void spl_board_init(void)
  139. {
  140. /*
  141. * Save the boot parameters passed from romcode.
  142. * We cannot delay the saving further than this,
  143. * to prevent overwrites.
  144. */
  145. save_omap_boot_params();
  146. /* Prepare console output */
  147. preloader_console_init();
  148. #if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
  149. gpmc_init();
  150. #endif
  151. #ifdef CONFIG_SPL_I2C_SUPPORT
  152. i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
  153. #endif
  154. #if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
  155. arch_misc_init();
  156. #endif
  157. #if defined(CONFIG_HW_WATCHDOG)
  158. hw_watchdog_init();
  159. #endif
  160. #ifdef CONFIG_AM33XX
  161. am33xx_spl_board_init();
  162. #endif
  163. }
  164. int board_mmc_init(bd_t *bis)
  165. {
  166. switch (spl_boot_device()) {
  167. case BOOT_DEVICE_MMC1:
  168. omap_mmc_init(0, 0, 0, -1, -1);
  169. break;
  170. case BOOT_DEVICE_MMC2:
  171. case BOOT_DEVICE_MMC2_2:
  172. omap_mmc_init(1, 0, 0, -1, -1);
  173. break;
  174. }
  175. return 0;
  176. }
  177. void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  178. {
  179. typedef void __noreturn (*image_entry_noargs_t)(u32 *);
  180. image_entry_noargs_t image_entry =
  181. (image_entry_noargs_t) spl_image->entry_point;
  182. u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
  183. debug("image entry point: 0x%X\n", spl_image->entry_point);
  184. /* Pass the saved boot_params from rom code */
  185. image_entry((u32 *)boot_params);
  186. }
  187. #endif
  188. #ifdef CONFIG_SCSI_AHCI_PLAT
  189. void arch_preboot_os(void)
  190. {
  191. ahci_reset((void __iomem *)DWC_AHSATA_BASE);
  192. }
  193. #endif
  194. #if defined(CONFIG_USB_FUNCTION_FASTBOOT) && !defined(CONFIG_ENV_IS_NOWHERE)
  195. int fb_set_reboot_flag(void)
  196. {
  197. printf("Setting reboot to fastboot flag ...\n");
  198. setenv("dofastboot", "1");
  199. saveenv();
  200. return 0;
  201. }
  202. #endif