spl_nor.c 3.0 KB

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