spl_boot.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * (C) Copyright 2000-2009
  3. * Vipin Kumar, ST Microelectronics, vipin.kumar@st.com
  4. *
  5. * Copyright (C) 2012 Stefan Roese <sr@denx.de>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <image.h>
  27. #include <linux/compiler.h>
  28. #include <asm/io.h>
  29. #include <asm/arch/spr_defs.h>
  30. #include <linux/mtd/st_smi.h>
  31. static const char kernel_name[] = "Linux";
  32. static const char loader_name[] = "U-Boot";
  33. int image_check_header(image_header_t *hdr, const char *name)
  34. {
  35. if (image_check_magic(hdr) &&
  36. (!strncmp(image_get_name(hdr), name, strlen(name))) &&
  37. image_check_hcrc(hdr)) {
  38. return 1;
  39. }
  40. return 0;
  41. }
  42. int image_check_data(image_header_t *hdr)
  43. {
  44. if (image_check_dcrc(hdr))
  45. return 1;
  46. return 0;
  47. }
  48. /*
  49. * SNOR (Serial NOR flash) related functions
  50. */
  51. void snor_init(void)
  52. {
  53. struct smi_regs *const smicntl =
  54. (struct smi_regs * const)CONFIG_SYS_SMI_BASE;
  55. /* Setting the fast mode values. SMI working at 166/4 = 41.5 MHz */
  56. writel(HOLD1 | FAST_MODE | BANK_EN | DSEL_TIME | PRESCAL4,
  57. &smicntl->smi_cr1);
  58. }
  59. static int snor_image_load(u8 *load_addr, void (**image_p)(void),
  60. const char *image_name)
  61. {
  62. image_header_t *header;
  63. /*
  64. * Since calculating the crc in the SNOR flash does not
  65. * work, we copy the image to the destination address
  66. * minus the header size. And point the header to this
  67. * new destination. This will not work for address 0
  68. * of course.
  69. */
  70. header = (image_header_t *)load_addr;
  71. memcpy((ulong *)(image_get_load(header) - sizeof(image_header_t)),
  72. (const ulong *)load_addr,
  73. image_get_data_size(header) + sizeof(image_header_t));
  74. header = (image_header_t *)(image_get_load(header) -
  75. sizeof(image_header_t));
  76. if (image_check_header(header, image_name)) {
  77. if (image_check_data(header)) {
  78. /* Jump to boot image */
  79. *image_p = (void *)image_get_load(header);
  80. return 1;
  81. }
  82. }
  83. return 0;
  84. }
  85. static void boot_image(void (*image)(void))
  86. {
  87. void (*funcp)(void) __noreturn = (void *)image;
  88. (*funcp)();
  89. }
  90. /*
  91. * spl_boot:
  92. *
  93. * All supported booting types of all supported SoCs are listed here.
  94. * Generic readback APIs are provided for each supported booting type
  95. * eg. nand_read_skip_bad
  96. */
  97. u32 spl_boot(void)
  98. {
  99. void (*image)(void);
  100. #ifdef CONFIG_SPEAR_USBTTY
  101. plat_late_init();
  102. return 1;
  103. #endif
  104. /*
  105. * All the supported booting devices are listed here. Each of
  106. * the booting type supported by the platform would define the
  107. * macro xxx_BOOT_SUPPORTED to true.
  108. */
  109. if (SNOR_BOOT_SUPPORTED && snor_boot_selected()) {
  110. /* SNOR-SMI initialization */
  111. snor_init();
  112. serial_puts("Booting via SNOR\n");
  113. /* Serial NOR booting */
  114. if (1 == snor_image_load((u8 *)CONFIG_SYS_UBOOT_BASE,
  115. &image, loader_name)) {
  116. /* Platform related late initialasations */
  117. plat_late_init();
  118. /* Jump to boot image */
  119. serial_puts("Jumping to U-Boot\n");
  120. boot_image(image);
  121. return 1;
  122. }
  123. }
  124. if (NAND_BOOT_SUPPORTED && nand_boot_selected()) {
  125. /* NAND booting */
  126. /* Not ported from XLoader to SPL yet */
  127. return 0;
  128. }
  129. if (PNOR_BOOT_SUPPORTED && pnor_boot_selected()) {
  130. /* PNOR booting */
  131. /* Not ported from XLoader to SPL yet */
  132. return 0;
  133. }
  134. if (MMC_BOOT_SUPPORTED && mmc_boot_selected()) {
  135. /* MMC booting */
  136. /* Not ported from XLoader to SPL yet */
  137. return 0;
  138. }
  139. if (SPI_BOOT_SUPPORTED && spi_boot_selected()) {
  140. /* SPI booting */
  141. /* Not supported for any platform as of now */
  142. return 0;
  143. }
  144. if (I2C_BOOT_SUPPORTED && i2c_boot_selected()) {
  145. /* I2C booting */
  146. /* Not supported for any platform as of now */
  147. return 0;
  148. }
  149. /*
  150. * All booting types without memory are listed as below
  151. * Control has to be returned to BootROM in case of all
  152. * the following booting scenarios
  153. */
  154. if (USB_BOOT_SUPPORTED && usb_boot_selected()) {
  155. plat_late_init();
  156. return 1;
  157. }
  158. if (TFTP_BOOT_SUPPORTED && tftp_boot_selected()) {
  159. plat_late_init();
  160. return 1;
  161. }
  162. if (UART_BOOT_SUPPORTED && uart_boot_selected()) {
  163. plat_late_init();
  164. return 1;
  165. }
  166. /* Ideally, the control should not reach here. */
  167. hang();
  168. }