fsl_espi_spl.c 2.2 KB

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