spl_boot.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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-exynos/dmc.h>
  25. #include <asm/arch/clock.h>
  26. #include <asm/arch/clk.h>
  27. #include "clock_init.h"
  28. /* Index into irom ptr table */
  29. enum index {
  30. MMC_INDEX,
  31. EMMC44_INDEX,
  32. EMMC44_END_INDEX,
  33. SPI_INDEX,
  34. USB_INDEX,
  35. };
  36. /* IROM Function Pointers Table */
  37. u32 irom_ptr_table[] = {
  38. [MMC_INDEX] = 0x02020030, /* iROM Function Pointer-SDMMC boot */
  39. [EMMC44_INDEX] = 0x02020044, /* iROM Function Pointer-EMMC4.4 boot*/
  40. [EMMC44_END_INDEX] = 0x02020048,/* iROM Function Pointer
  41. -EMMC4.4 end boot operation */
  42. [SPI_INDEX] = 0x02020058, /* iROM Function Pointer-SPI boot */
  43. [USB_INDEX] = 0x02020070, /* iROM Function Pointer-USB boot*/
  44. };
  45. enum boot_mode {
  46. BOOT_MODE_MMC = 4,
  47. BOOT_MODE_SERIAL = 20,
  48. BOOT_MODE_EMMC = 8, /* EMMC4.4 */
  49. /* Boot based on Operating Mode pin settings */
  50. BOOT_MODE_OM = 32,
  51. BOOT_MODE_USB, /* Boot using USB download */
  52. };
  53. void *get_irom_func(int index)
  54. {
  55. return (void *)*(u32 *)irom_ptr_table[index];
  56. }
  57. /*
  58. * Set/clear program flow prediction and return the previous state.
  59. */
  60. static int config_branch_prediction(int set_cr_z)
  61. {
  62. unsigned int cr;
  63. /* System Control Register: 11th bit Z Branch prediction enable */
  64. cr = get_cr();
  65. set_cr(set_cr_z ? cr | CR_Z : cr & ~CR_Z);
  66. return cr & CR_Z;
  67. }
  68. /*
  69. * Copy U-boot from mmc to RAM:
  70. * COPY_BL2_FNPTR_ADDR: Address in iRAM, which Contains
  71. * Pointer to API (Data transfer from mmc to ram)
  72. */
  73. void copy_uboot_to_ram(void)
  74. {
  75. int is_cr_z_set;
  76. unsigned int sec_boot_check;
  77. enum boot_mode bootmode = BOOT_MODE_OM;
  78. u32 (*spi_copy)(u32 offset, u32 nblock, u32 dst);
  79. u32 (*copy_bl2)(u32 offset, u32 nblock, u32 dst);
  80. u32 (*copy_bl2_from_emmc)(u32 nblock, u32 dst);
  81. void (*end_bootop_from_emmc)(void);
  82. u32 (*usb_copy)(void);
  83. /* Read iRAM location to check for secondary USB boot mode */
  84. sec_boot_check = readl(EXYNOS_IRAM_SECONDARY_BASE);
  85. if (sec_boot_check == EXYNOS_USB_SECONDARY_BOOT)
  86. bootmode = BOOT_MODE_USB;
  87. if (bootmode == BOOT_MODE_OM)
  88. bootmode = readl(EXYNOS5_POWER_BASE) & OM_STAT;
  89. switch (bootmode) {
  90. case BOOT_MODE_SERIAL:
  91. spi_copy = get_irom_func(SPI_INDEX);
  92. spi_copy(SPI_FLASH_UBOOT_POS, CONFIG_BL2_SIZE,
  93. CONFIG_SYS_TEXT_BASE);
  94. break;
  95. case BOOT_MODE_MMC:
  96. copy_bl2 = get_irom_func(MMC_INDEX);
  97. copy_bl2(BL2_START_OFFSET, BL2_SIZE_BLOC_COUNT,
  98. CONFIG_SYS_TEXT_BASE);
  99. break;
  100. case BOOT_MODE_EMMC:
  101. /* Set the FSYS1 clock divisor value for EMMC boot */
  102. emmc_boot_clk_div_set();
  103. copy_bl2_from_emmc = get_irom_func(EMMC44_INDEX);
  104. end_bootop_from_emmc = get_irom_func(EMMC44_END_INDEX);
  105. copy_bl2_from_emmc(BL2_SIZE_BLOC_COUNT, CONFIG_SYS_TEXT_BASE);
  106. end_bootop_from_emmc();
  107. break;
  108. case BOOT_MODE_USB:
  109. /*
  110. * iROM needs program flow prediction to be disabled
  111. * before copy from USB device to RAM
  112. */
  113. is_cr_z_set = config_branch_prediction(0);
  114. usb_copy = get_irom_func(USB_INDEX);
  115. usb_copy();
  116. config_branch_prediction(is_cr_z_set);
  117. break;
  118. default:
  119. break;
  120. }
  121. }
  122. void board_init_f(unsigned long bootflag)
  123. {
  124. __attribute__((noreturn)) void (*uboot)(void);
  125. copy_uboot_to_ram();
  126. /* Jump to U-Boot image */
  127. uboot = (void *)CONFIG_SYS_TEXT_BASE;
  128. (*uboot)();
  129. /* Never returns Here */
  130. }
  131. /* Place Holders */
  132. void board_init_r(gd_t *id, ulong dest_addr)
  133. {
  134. /* Function attribute is no-return */
  135. /* This Function never executes */
  136. while (1)
  137. ;
  138. }
  139. void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) {}