spl_nor.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. __maybe_unused const struct image_header *header;
  23. __maybe_unused struct spl_load_info load;
  24. /*
  25. * Loading of the payload to SDRAM is done with skipping of
  26. * the mkimage header in this SPL NOR driver
  27. */
  28. spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
  29. #ifdef CONFIG_SPL_OS_BOOT
  30. if (!spl_start_uboot()) {
  31. /*
  32. * Load Linux from its location in NOR flash to its defined
  33. * location in SDRAM
  34. */
  35. header = (const struct image_header *)CONFIG_SYS_OS_BASE;
  36. #ifdef CONFIG_SPL_LOAD_FIT
  37. if (image_get_magic(header) == FDT_MAGIC) {
  38. int ret;
  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. int ret;
  56. ret = spl_parse_image_header(spl_image, header);
  57. if (ret)
  58. return ret;
  59. memcpy((void *)spl_image->load_addr,
  60. (void *)(CONFIG_SYS_OS_BASE +
  61. sizeof(struct image_header)),
  62. spl_image->size);
  63. #ifdef CONFIG_SYS_FDT_BASE
  64. spl_image->arg = (void *)CONFIG_SYS_FDT_BASE;
  65. #endif
  66. return 0;
  67. } else {
  68. puts("The Expected Linux image was not found.\n"
  69. "Please check your NOR configuration.\n"
  70. "Trying to start u-boot now...\n");
  71. }
  72. }
  73. #endif
  74. /*
  75. * Load real U-Boot from its location in NOR flash to its
  76. * defined location in SDRAM
  77. */
  78. #ifdef CONFIG_SPL_LOAD_FIT
  79. header = (const struct image_header *)spl_nor_get_uboot_base();
  80. if (image_get_magic(header) == FDT_MAGIC) {
  81. debug("Found FIT format U-Boot\n");
  82. load.bl_len = 1;
  83. load.read = spl_nor_load_read;
  84. return spl_load_simple_fit(spl_image, &load,
  85. spl_nor_get_uboot_base(),
  86. (void *)header);
  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. /* Legacy image handling */
  96. if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_SUPPORT)) {
  97. load.bl_len = 1;
  98. load.read = spl_nor_load_read;
  99. return spl_load_legacy_img(spl_image, &load,
  100. spl_nor_get_uboot_base());
  101. }
  102. return 0;
  103. }
  104. SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);