spl_boot.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <image.h>
  11. #include <linux/compiler.h>
  12. #include <asm/io.h>
  13. #include <asm/arch/spr_defs.h>
  14. #include <linux/mtd/st_smi.h>
  15. static const char kernel_name[] = "Linux";
  16. static const char loader_name[] = "U-Boot";
  17. int image_check_header(image_header_t *hdr, const char *name)
  18. {
  19. if (image_check_magic(hdr) &&
  20. (!strncmp(image_get_name(hdr), name, strlen(name))) &&
  21. image_check_hcrc(hdr)) {
  22. return 1;
  23. }
  24. return 0;
  25. }
  26. int image_check_data(image_header_t *hdr)
  27. {
  28. if (image_check_dcrc(hdr))
  29. return 1;
  30. return 0;
  31. }
  32. /*
  33. * SNOR (Serial NOR flash) related functions
  34. */
  35. void snor_init(void)
  36. {
  37. struct smi_regs *const smicntl =
  38. (struct smi_regs * const)CONFIG_SYS_SMI_BASE;
  39. /* Setting the fast mode values. SMI working at 166/4 = 41.5 MHz */
  40. writel(HOLD1 | FAST_MODE | BANK_EN | DSEL_TIME | PRESCAL4,
  41. &smicntl->smi_cr1);
  42. }
  43. static int snor_image_load(u8 *load_addr, void (**image_p)(void),
  44. const char *image_name)
  45. {
  46. image_header_t *header;
  47. /*
  48. * Since calculating the crc in the SNOR flash does not
  49. * work, we copy the image to the destination address
  50. * minus the header size. And point the header to this
  51. * new destination. This will not work for address 0
  52. * of course.
  53. */
  54. header = (image_header_t *)load_addr;
  55. memcpy((ulong *)(image_get_load(header) - sizeof(image_header_t)),
  56. (const ulong *)load_addr,
  57. image_get_data_size(header) + sizeof(image_header_t));
  58. header = (image_header_t *)(image_get_load(header) -
  59. sizeof(image_header_t));
  60. if (image_check_header(header, image_name)) {
  61. if (image_check_data(header)) {
  62. /* Jump to boot image */
  63. *image_p = (void *)image_get_load(header);
  64. return 1;
  65. }
  66. }
  67. return 0;
  68. }
  69. static void boot_image(void (*image)(void))
  70. {
  71. void (*funcp)(void) __noreturn = (void *)image;
  72. (*funcp)();
  73. }
  74. /*
  75. * spl_boot:
  76. *
  77. * All supported booting types of all supported SoCs are listed here.
  78. * Generic readback APIs are provided for each supported booting type
  79. * eg. nand_read_skip_bad
  80. */
  81. u32 spl_boot(void)
  82. {
  83. void (*image)(void);
  84. #ifdef CONFIG_SPEAR_USBTTY
  85. plat_late_init();
  86. return 1;
  87. #endif
  88. /*
  89. * All the supported booting devices are listed here. Each of
  90. * the booting type supported by the platform would define the
  91. * macro xxx_BOOT_SUPPORTED to true.
  92. */
  93. if (SNOR_BOOT_SUPPORTED && snor_boot_selected()) {
  94. /* SNOR-SMI initialization */
  95. snor_init();
  96. serial_puts("Booting via SNOR\n");
  97. /* Serial NOR booting */
  98. if (1 == snor_image_load((u8 *)CONFIG_SYS_UBOOT_BASE,
  99. &image, loader_name)) {
  100. /* Platform related late initialasations */
  101. plat_late_init();
  102. /* Jump to boot image */
  103. serial_puts("Jumping to U-Boot\n");
  104. boot_image(image);
  105. return 1;
  106. }
  107. }
  108. if (NAND_BOOT_SUPPORTED && nand_boot_selected()) {
  109. /* NAND booting */
  110. /* Not ported from XLoader to SPL yet */
  111. return 0;
  112. }
  113. if (PNOR_BOOT_SUPPORTED && pnor_boot_selected()) {
  114. /* PNOR booting */
  115. /* Not ported from XLoader to SPL yet */
  116. return 0;
  117. }
  118. if (MMC_BOOT_SUPPORTED && mmc_boot_selected()) {
  119. /* MMC booting */
  120. /* Not ported from XLoader to SPL yet */
  121. return 0;
  122. }
  123. if (SPI_BOOT_SUPPORTED && spi_boot_selected()) {
  124. /* SPI booting */
  125. /* Not supported for any platform as of now */
  126. return 0;
  127. }
  128. if (I2C_BOOT_SUPPORTED && i2c_boot_selected()) {
  129. /* I2C booting */
  130. /* Not supported for any platform as of now */
  131. return 0;
  132. }
  133. /*
  134. * All booting types without memory are listed as below
  135. * Control has to be returned to BootROM in case of all
  136. * the following booting scenarios
  137. */
  138. if (USB_BOOT_SUPPORTED && usb_boot_selected()) {
  139. plat_late_init();
  140. return 1;
  141. }
  142. if (TFTP_BOOT_SUPPORTED && tftp_boot_selected()) {
  143. plat_late_init();
  144. return 1;
  145. }
  146. if (UART_BOOT_SUPPORTED && uart_boot_selected()) {
  147. plat_late_init();
  148. return 1;
  149. }
  150. /* Ideally, the control should not reach here. */
  151. hang();
  152. }