boot-common.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. }
  53. #ifdef CONFIG_SPL_BUILD
  54. u32 spl_boot_device(void)
  55. {
  56. return (u32) (gd->arch.omap_boot_params.omap_bootdevice);
  57. }
  58. u32 spl_boot_mode(void)
  59. {
  60. u32 val = gd->arch.omap_boot_params.omap_bootmode;
  61. if (val == MMCSD_MODE_RAW)
  62. return MMCSD_MODE_RAW;
  63. else if (val == MMCSD_MODE_FAT)
  64. return MMCSD_MODE_FAT;
  65. else
  66. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  67. return MMCSD_MODE_EMMCBOOT;
  68. #else
  69. return MMCSD_MODE_UNDEFINED;
  70. #endif
  71. }
  72. void spl_board_init(void)
  73. {
  74. #ifdef CONFIG_SPL_NAND_SUPPORT
  75. gpmc_init();
  76. #endif
  77. #if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
  78. arch_misc_init();
  79. #endif
  80. #if defined(CONFIG_HW_WATCHDOG)
  81. hw_watchdog_init();
  82. #endif
  83. #ifdef CONFIG_AM33XX
  84. am33xx_spl_board_init();
  85. #endif
  86. }
  87. int board_mmc_init(bd_t *bis)
  88. {
  89. switch (spl_boot_device()) {
  90. case BOOT_DEVICE_MMC1:
  91. omap_mmc_init(0, 0, 0, -1, -1);
  92. break;
  93. case BOOT_DEVICE_MMC2:
  94. case BOOT_DEVICE_MMC2_2:
  95. omap_mmc_init(1, 0, 0, -1, -1);
  96. break;
  97. }
  98. return 0;
  99. }
  100. void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  101. {
  102. typedef void __noreturn (*image_entry_noargs_t)(u32 *);
  103. image_entry_noargs_t image_entry =
  104. (image_entry_noargs_t) spl_image->entry_point;
  105. debug("image entry point: 0x%X\n", spl_image->entry_point);
  106. /* Pass the saved boot_params from rom code */
  107. image_entry((u32 *)&gd->arch.omap_boot_params);
  108. }
  109. #endif