fsl_espi_spl.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2013 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <spi_flash.h>
  8. #include <malloc.h>
  9. #define ESPI_BOOT_IMAGE_SIZE 0x48
  10. #define ESPI_BOOT_IMAGE_ADDR 0x50
  11. #define CONFIG_CFG_DATA_SECTOR 0
  12. void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst)
  13. {
  14. struct spi_flash *flash;
  15. flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
  16. CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
  17. if (flash == NULL) {
  18. puts("\nspi_flash_probe failed");
  19. hang();
  20. }
  21. spi_flash_read(flash, offs, size, vdst);
  22. }
  23. /*
  24. * The main entry for SPI booting. It's necessary that SDRAM is already
  25. * configured and available since this code loads the main U-Boot image
  26. * from SPI into SDRAM and starts it from there.
  27. */
  28. void spi_boot(void)
  29. {
  30. void (*uboot)(void) __noreturn;
  31. u32 offset, code_len, copy_len = 0;
  32. #ifndef CONFIG_FSL_CORENET
  33. unsigned char *buf = NULL;
  34. #endif
  35. struct spi_flash *flash;
  36. flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
  37. CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
  38. if (flash == NULL) {
  39. puts("\nspi_flash_probe failed");
  40. hang();
  41. }
  42. #ifdef CONFIG_FSL_CORENET
  43. offset = CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
  44. code_len = CONFIG_SYS_SPI_FLASH_U_BOOT_SIZE;
  45. #else
  46. /*
  47. * Load U-Boot image from SPI flash into RAM
  48. */
  49. buf = malloc(flash->page_size);
  50. if (buf == NULL) {
  51. puts("\nmalloc failed");
  52. hang();
  53. }
  54. memset(buf, 0, flash->page_size);
  55. spi_flash_read(flash, CONFIG_CFG_DATA_SECTOR,
  56. flash->page_size, (void *)buf);
  57. offset = *(u32 *)(buf + ESPI_BOOT_IMAGE_ADDR);
  58. /* Skip spl code */
  59. offset += CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
  60. /* Get the code size from offset 0x48 */
  61. code_len = *(u32 *)(buf + ESPI_BOOT_IMAGE_SIZE);
  62. /* Skip spl code */
  63. code_len = code_len - CONFIG_SPL_MAX_SIZE;
  64. #endif
  65. /* copy code to DDR */
  66. printf("Loading second stage boot loader ");
  67. while (copy_len <= code_len) {
  68. spi_flash_read(flash, offset + copy_len, 0x2000,
  69. (void *)(CONFIG_SYS_SPI_FLASH_U_BOOT_DST
  70. + copy_len));
  71. copy_len = copy_len + 0x2000;
  72. putc('.');
  73. }
  74. /*
  75. * Jump to U-Boot image
  76. */
  77. flush_cache(CONFIG_SYS_SPI_FLASH_U_BOOT_DST, code_len);
  78. uboot = (void *)CONFIG_SYS_SPI_FLASH_U_BOOT_START;
  79. (*uboot)();
  80. }