boot-common.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. #if defined(BOOT_DEVICE_DFU) && !defined(CONFIG_SPL_DFU_SUPPORT)
  86. case BOOT_DEVICE_DFU:
  87. sys_boot_device = 1;
  88. break;
  89. #endif
  90. }
  91. if (sys_boot_device) {
  92. boot_device = omap_sys_boot_device();
  93. /* MMC raw mode will fallback to FS mode. */
  94. if ((boot_device >= MMC_BOOT_DEVICES_START) &&
  95. (boot_device <= MMC_BOOT_DEVICES_END))
  96. boot_mode = MMCSD_MODE_RAW;
  97. }
  98. gd->arch.omap_boot_device = boot_device;
  99. /* Boot mode */
  100. #ifdef CONFIG_OMAP34XX
  101. if ((boot_device >= MMC_BOOT_DEVICES_START) &&
  102. (boot_device <= MMC_BOOT_DEVICES_END)) {
  103. switch (boot_device) {
  104. case BOOT_DEVICE_MMC1:
  105. boot_mode = MMCSD_MODE_FS;
  106. break;
  107. case BOOT_DEVICE_MMC2:
  108. boot_mode = MMCSD_MODE_RAW;
  109. break;
  110. }
  111. }
  112. #else
  113. /*
  114. * If the boot device was dynamically changed and doesn't match what
  115. * the bootrom initially booted, we cannot use the boot device
  116. * descriptor to figure out the boot mode.
  117. */
  118. if ((boot_device == omap_boot_params->boot_device) &&
  119. (boot_device >= MMC_BOOT_DEVICES_START) &&
  120. (boot_device <= MMC_BOOT_DEVICES_END)) {
  121. boot_params = omap_boot_params->boot_device_descriptor;
  122. if ((boot_params < NON_SECURE_SRAM_START) ||
  123. (boot_params > NON_SECURE_SRAM_END))
  124. return;
  125. boot_params = *((u32 *)(boot_params + DEVICE_DATA_OFFSET));
  126. if ((boot_params < NON_SECURE_SRAM_START) ||
  127. (boot_params > NON_SECURE_SRAM_END))
  128. return;
  129. boot_mode = *((u32 *)(boot_params + BOOT_MODE_OFFSET));
  130. if (boot_mode != MMCSD_MODE_FS &&
  131. boot_mode != MMCSD_MODE_RAW)
  132. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  133. boot_mode = MMCSD_MODE_EMMCBOOT;
  134. #else
  135. boot_mode = MMCSD_MODE_UNDEFINED;
  136. #endif
  137. }
  138. #endif
  139. gd->arch.omap_boot_mode = boot_mode;
  140. #if !defined(CONFIG_TI814X) && !defined(CONFIG_TI816X) && \
  141. !defined(CONFIG_AM33XX) && !defined(CONFIG_AM43XX)
  142. /* CH flags */
  143. gd->arch.omap_ch_flags = omap_boot_params->ch_flags;
  144. #endif
  145. }
  146. #ifdef CONFIG_SPL_BUILD
  147. u32 spl_boot_device(void)
  148. {
  149. return gd->arch.omap_boot_device;
  150. }
  151. u32 spl_boot_mode(const u32 boot_device)
  152. {
  153. return gd->arch.omap_boot_mode;
  154. }
  155. void spl_board_init(void)
  156. {
  157. /* Prepare console output */
  158. preloader_console_init();
  159. #if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
  160. gpmc_init();
  161. #endif
  162. #ifdef CONFIG_SPL_I2C_SUPPORT
  163. i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
  164. #endif
  165. #if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
  166. arch_misc_init();
  167. #endif
  168. #if defined(CONFIG_HW_WATCHDOG)
  169. hw_watchdog_init();
  170. #endif
  171. #ifdef CONFIG_AM33XX
  172. am33xx_spl_board_init();
  173. #endif
  174. }
  175. void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  176. {
  177. typedef void __noreturn (*image_entry_noargs_t)(u32 *);
  178. image_entry_noargs_t image_entry =
  179. (image_entry_noargs_t) spl_image->entry_point;
  180. u32 boot_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
  181. debug("image entry point: 0x%X\n", spl_image->entry_point);
  182. /* Pass the saved boot_params from rom code */
  183. image_entry((u32 *)boot_params);
  184. }
  185. #endif
  186. #ifdef CONFIG_SCSI_AHCI_PLAT
  187. void arch_preboot_os(void)
  188. {
  189. ahci_reset((void __iomem *)DWC_AHSATA_BASE);
  190. }
  191. #endif
  192. #if defined(CONFIG_USB_FUNCTION_FASTBOOT) && !defined(CONFIG_ENV_IS_NOWHERE)
  193. int fb_set_reboot_flag(void)
  194. {
  195. printf("Setting reboot to fastboot flag ...\n");
  196. setenv("dofastboot", "1");
  197. saveenv();
  198. return 0;
  199. }
  200. #endif