spl_nor.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2012 Stefan Roese <sr@denx.de>
  4. */
  5. #include <common.h>
  6. #include <spl.h>
  7. static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
  8. ulong count, void *buf)
  9. {
  10. debug("%s: sector %lx, count %lx, buf %p\n",
  11. __func__, sector, count, buf);
  12. memcpy(buf, (void *)sector, count);
  13. return count;
  14. }
  15. unsigned long __weak spl_nor_get_uboot_base(void)
  16. {
  17. return CONFIG_SYS_UBOOT_BASE;
  18. }
  19. static int spl_nor_load_image(struct spl_image_info *spl_image,
  20. struct spl_boot_device *bootdev)
  21. {
  22. int ret;
  23. __maybe_unused const struct image_header *header;
  24. __maybe_unused struct spl_load_info load;
  25. /*
  26. * Loading of the payload to SDRAM is done with skipping of
  27. * the mkimage header in this SPL NOR driver
  28. */
  29. spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
  30. #ifdef CONFIG_SPL_OS_BOOT
  31. if (!spl_start_uboot()) {
  32. /*
  33. * Load Linux from its location in NOR flash to its defined
  34. * location in SDRAM
  35. */
  36. header = (const struct image_header *)CONFIG_SYS_OS_BASE;
  37. #ifdef CONFIG_SPL_LOAD_FIT
  38. if (image_get_magic(header) == FDT_MAGIC) {
  39. debug("Found FIT\n");
  40. load.bl_len = 1;
  41. load.read = spl_nor_load_read;
  42. ret = spl_load_simple_fit(spl_image, &load,
  43. CONFIG_SYS_OS_BASE,
  44. (void *)header);
  45. #if defined CONFIG_SYS_SPL_ARGS_ADDR && defined CONFIG_CMD_SPL_NOR_OFS
  46. memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR,
  47. (void *)CONFIG_CMD_SPL_NOR_OFS,
  48. CONFIG_CMD_SPL_WRITE_SIZE);
  49. #endif
  50. return ret;
  51. }
  52. #endif
  53. if (image_get_os(header) == IH_OS_LINUX) {
  54. /* happy - was a Linux */
  55. ret = spl_parse_image_header(spl_image, header);
  56. if (ret)
  57. return ret;
  58. memcpy((void *)spl_image->load_addr,
  59. (void *)(CONFIG_SYS_OS_BASE +
  60. sizeof(struct image_header)),
  61. spl_image->size);
  62. #ifdef CONFIG_SYS_FDT_BASE
  63. spl_image->arg = (void *)CONFIG_SYS_FDT_BASE;
  64. #endif
  65. return 0;
  66. } else {
  67. puts("The Expected Linux image was not found.\n"
  68. "Please check your NOR configuration.\n"
  69. "Trying to start u-boot now...\n");
  70. }
  71. }
  72. #endif
  73. /*
  74. * Load real U-Boot from its location in NOR flash to its
  75. * defined location in SDRAM
  76. */
  77. #ifdef CONFIG_SPL_LOAD_FIT
  78. header = (const struct image_header *)spl_nor_get_uboot_base();
  79. if (image_get_magic(header) == FDT_MAGIC) {
  80. debug("Found FIT format U-Boot\n");
  81. load.bl_len = 1;
  82. load.read = spl_nor_load_read;
  83. ret = spl_load_simple_fit(spl_image, &load,
  84. spl_nor_get_uboot_base(),
  85. (void *)header);
  86. return ret;
  87. }
  88. #endif
  89. if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
  90. load.bl_len = 1;
  91. load.read = spl_nor_load_read;
  92. return spl_load_imx_container(spl_image, &load,
  93. spl_nor_get_uboot_base());
  94. }
  95. ret = spl_parse_image_header(spl_image,
  96. (const struct image_header *)spl_nor_get_uboot_base());
  97. if (ret)
  98. return ret;
  99. memcpy((void *)(unsigned long)spl_image->load_addr,
  100. (void *)(spl_nor_get_uboot_base() + sizeof(struct image_header)),
  101. spl_image->size);
  102. return 0;
  103. }
  104. SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);