spl_boot.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include<common.h>
  23. #include<config.h>
  24. #include <asm/arch/clock.h>
  25. #include <asm/arch/clk.h>
  26. #include <asm/arch/dmc.h>
  27. #include <asm/arch/power.h>
  28. #include <asm/arch/spl.h>
  29. #include "common_setup.h"
  30. #include "clock_init.h"
  31. DECLARE_GLOBAL_DATA_PTR;
  32. #define OM_STAT (0x1f << 1)
  33. /* Index into irom ptr table */
  34. enum index {
  35. MMC_INDEX,
  36. EMMC44_INDEX,
  37. EMMC44_END_INDEX,
  38. SPI_INDEX,
  39. USB_INDEX,
  40. };
  41. /* IROM Function Pointers Table */
  42. u32 irom_ptr_table[] = {
  43. [MMC_INDEX] = 0x02020030, /* iROM Function Pointer-SDMMC boot */
  44. [EMMC44_INDEX] = 0x02020044, /* iROM Function Pointer-EMMC4.4 boot*/
  45. [EMMC44_END_INDEX] = 0x02020048,/* iROM Function Pointer
  46. -EMMC4.4 end boot operation */
  47. [SPI_INDEX] = 0x02020058, /* iROM Function Pointer-SPI boot */
  48. [USB_INDEX] = 0x02020070, /* iROM Function Pointer-USB boot*/
  49. };
  50. void *get_irom_func(int index)
  51. {
  52. return (void *)*(u32 *)irom_ptr_table[index];
  53. }
  54. #ifdef CONFIG_USB_BOOTING
  55. /*
  56. * Set/clear program flow prediction and return the previous state.
  57. */
  58. static int config_branch_prediction(int set_cr_z)
  59. {
  60. unsigned int cr;
  61. /* System Control Register: 11th bit Z Branch prediction enable */
  62. cr = get_cr();
  63. set_cr(set_cr_z ? cr | CR_Z : cr & ~CR_Z);
  64. return cr & CR_Z;
  65. }
  66. #endif
  67. /*
  68. * Copy U-boot from mmc to RAM:
  69. * COPY_BL2_FNPTR_ADDR: Address in iRAM, which Contains
  70. * Pointer to API (Data transfer from mmc to ram)
  71. */
  72. void copy_uboot_to_ram(void)
  73. {
  74. enum boot_mode bootmode = BOOT_MODE_OM;
  75. u32 (*copy_bl2)(u32 offset, u32 nblock, u32 dst) = NULL;
  76. u32 offset = 0, size = 0;
  77. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  78. u32 (*copy_bl2_from_emmc)(u32 nblock, u32 dst);
  79. void (*end_bootop_from_emmc)(void);
  80. #endif
  81. #ifdef CONFIG_USB_BOOTING
  82. u32 (*usb_copy)(void);
  83. int is_cr_z_set;
  84. unsigned int sec_boot_check;
  85. /* Read iRAM location to check for secondary USB boot mode */
  86. sec_boot_check = readl(EXYNOS_IRAM_SECONDARY_BASE);
  87. if (sec_boot_check == EXYNOS_USB_SECONDARY_BOOT)
  88. bootmode = BOOT_MODE_USB;
  89. #endif
  90. if (bootmode == BOOT_MODE_OM)
  91. bootmode = readl(samsung_get_base_power()) & OM_STAT;
  92. switch (bootmode) {
  93. #ifdef CONFIG_SPI_BOOTING
  94. case BOOT_MODE_SERIAL:
  95. offset = SPI_FLASH_UBOOT_POS;
  96. size = CONFIG_BL2_SIZE;
  97. copy_bl2 = get_irom_func(SPI_INDEX);
  98. break;
  99. #endif
  100. case BOOT_MODE_MMC:
  101. offset = BL2_START_OFFSET;
  102. size = BL2_SIZE_BLOC_COUNT;
  103. copy_bl2 = get_irom_func(MMC_INDEX);
  104. break;
  105. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  106. case BOOT_MODE_EMMC:
  107. /* Set the FSYS1 clock divisor value for EMMC boot */
  108. emmc_boot_clk_div_set();
  109. copy_bl2_from_emmc = get_irom_func(EMMC44_INDEX);
  110. end_bootop_from_emmc = get_irom_func(EMMC44_END_INDEX);
  111. copy_bl2_from_emmc(BL2_SIZE_BLOC_COUNT, CONFIG_SYS_TEXT_BASE);
  112. end_bootop_from_emmc();
  113. break;
  114. #endif
  115. #ifdef CONFIG_USB_BOOTING
  116. case BOOT_MODE_USB:
  117. /*
  118. * iROM needs program flow prediction to be disabled
  119. * before copy from USB device to RAM
  120. */
  121. is_cr_z_set = config_branch_prediction(0);
  122. usb_copy = get_irom_func(USB_INDEX);
  123. usb_copy();
  124. config_branch_prediction(is_cr_z_set);
  125. break;
  126. #endif
  127. default:
  128. break;
  129. }
  130. if (copy_bl2)
  131. copy_bl2(offset, size, CONFIG_SYS_TEXT_BASE);
  132. }
  133. void memzero(void *s, size_t n)
  134. {
  135. char *ptr = s;
  136. size_t i;
  137. for (i = 0; i < n; i++)
  138. *ptr++ = '\0';
  139. }
  140. /**
  141. * Set up the U-Boot global_data pointer
  142. *
  143. * This sets the address of the global data, and sets up basic values.
  144. *
  145. * @param gdp Value to give to gd
  146. */
  147. static void setup_global_data(gd_t *gdp)
  148. {
  149. gd = gdp;
  150. memzero((void *)gd, sizeof(gd_t));
  151. gd->flags |= GD_FLG_RELOC;
  152. gd->baudrate = CONFIG_BAUDRATE;
  153. gd->have_console = 1;
  154. }
  155. void board_init_f(unsigned long bootflag)
  156. {
  157. __aligned(8) gd_t local_gd;
  158. __attribute__((noreturn)) void (*uboot)(void);
  159. setup_global_data(&local_gd);
  160. if (do_lowlevel_init())
  161. power_exit_wakeup();
  162. copy_uboot_to_ram();
  163. /* Jump to U-Boot image */
  164. uboot = (void *)CONFIG_SYS_TEXT_BASE;
  165. (*uboot)();
  166. /* Never returns Here */
  167. }
  168. /* Place Holders */
  169. void board_init_r(gd_t *id, ulong dest_addr)
  170. {
  171. /* Function attribute is no-return */
  172. /* This Function never executes */
  173. while (1)
  174. ;
  175. }
  176. void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) {}