spl_nor.c 2.6 KB

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