boot-common.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 <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. DECLARE_GLOBAL_DATA_PTR;
  18. void save_omap_boot_params(void)
  19. {
  20. u32 rom_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
  21. u8 boot_device;
  22. u32 dev_desc, dev_data;
  23. if ((rom_params < NON_SECURE_SRAM_START) ||
  24. (rom_params > NON_SECURE_SRAM_END))
  25. return;
  26. /*
  27. * rom_params can be type casted to omap_boot_parameters and
  28. * used. But it not correct to assume that romcode structure
  29. * encoding would be same as u-boot. So use the defined offsets.
  30. */
  31. gd->arch.omap_boot_params.omap_bootdevice = boot_device =
  32. *((u8 *)(rom_params + BOOT_DEVICE_OFFSET));
  33. gd->arch.omap_boot_params.ch_flags =
  34. *((u8 *)(rom_params + CH_FLAGS_OFFSET));
  35. if ((boot_device >= MMC_BOOT_DEVICES_START) &&
  36. (boot_device <= MMC_BOOT_DEVICES_END)) {
  37. #if !defined(CONFIG_AM33XX) && !defined(CONFIG_TI81XX) && \
  38. !defined(CONFIG_AM43XX)
  39. if ((omap_hw_init_context() ==
  40. OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)) {
  41. gd->arch.omap_boot_params.omap_bootmode =
  42. *((u8 *)(rom_params + BOOT_MODE_OFFSET));
  43. } else
  44. #endif
  45. {
  46. dev_desc = *((u32 *)(rom_params + DEV_DESC_PTR_OFFSET));
  47. dev_data = *((u32 *)(dev_desc + DEV_DATA_PTR_OFFSET));
  48. gd->arch.omap_boot_params.omap_bootmode =
  49. *((u32 *)(dev_data + BOOT_MODE_OFFSET));
  50. }
  51. }
  52. #if defined(CONFIG_DRA7XX) || defined(CONFIG_AM57XX)
  53. /*
  54. * We get different values for QSPI_1 and QSPI_4 being used, but
  55. * don't actually care about this difference. Rather than
  56. * mangle the later code, if we're coming in as QSPI_4 just
  57. * change to the QSPI_1 value.
  58. */
  59. if (gd->arch.omap_boot_params.omap_bootdevice == 11)
  60. gd->arch.omap_boot_params.omap_bootdevice = BOOT_DEVICE_SPI;
  61. #endif
  62. }
  63. #ifdef CONFIG_SPL_BUILD
  64. u32 spl_boot_device(void)
  65. {
  66. return (u32) (gd->arch.omap_boot_params.omap_bootdevice);
  67. }
  68. u32 spl_boot_mode(void)
  69. {
  70. u32 val = gd->arch.omap_boot_params.omap_bootmode;
  71. if (val == MMCSD_MODE_RAW)
  72. return MMCSD_MODE_RAW;
  73. else if (val == MMCSD_MODE_FS)
  74. return MMCSD_MODE_FS;
  75. else
  76. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  77. return MMCSD_MODE_EMMCBOOT;
  78. #else
  79. return MMCSD_MODE_UNDEFINED;
  80. #endif
  81. }
  82. void spl_board_init(void)
  83. {
  84. #ifdef CONFIG_SPL_NAND_SUPPORT
  85. gpmc_init();
  86. #endif
  87. #if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
  88. arch_misc_init();
  89. #endif
  90. #if defined(CONFIG_HW_WATCHDOG)
  91. hw_watchdog_init();
  92. #endif
  93. #ifdef CONFIG_AM33XX
  94. am33xx_spl_board_init();
  95. #endif
  96. }
  97. int board_mmc_init(bd_t *bis)
  98. {
  99. switch (spl_boot_device()) {
  100. case BOOT_DEVICE_MMC1:
  101. omap_mmc_init(0, 0, 0, -1, -1);
  102. break;
  103. case BOOT_DEVICE_MMC2:
  104. case BOOT_DEVICE_MMC2_2:
  105. omap_mmc_init(1, 0, 0, -1, -1);
  106. break;
  107. }
  108. return 0;
  109. }
  110. void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  111. {
  112. typedef void __noreturn (*image_entry_noargs_t)(u32 *);
  113. image_entry_noargs_t image_entry =
  114. (image_entry_noargs_t) spl_image->entry_point;
  115. debug("image entry point: 0x%X\n", spl_image->entry_point);
  116. /* Pass the saved boot_params from rom code */
  117. image_entry((u32 *)&gd->arch.omap_boot_params);
  118. }
  119. #endif