spl_ram.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2016
  4. * Xilinx, Inc.
  5. *
  6. * (C) Copyright 2016
  7. * Toradex AG
  8. *
  9. * Michal Simek <michal.simek@amd.com>
  10. * Stefan Agner <stefan.agner@toradex.com>
  11. */
  12. #include <common.h>
  13. #include <binman_sym.h>
  14. #include <image.h>
  15. #include <log.h>
  16. #include <mapmem.h>
  17. #include <spl.h>
  18. #include <linux/libfdt.h>
  19. static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector,
  20. ulong count, void *buf)
  21. {
  22. ulong addr;
  23. debug("%s: sector %lx, count %lx, buf %lx\n",
  24. __func__, sector, count, (ulong)buf);
  25. addr = (ulong)CONFIG_SPL_LOAD_FIT_ADDRESS + sector;
  26. if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD))
  27. addr += image_load_offset;
  28. memcpy(buf, (void *)addr, count);
  29. return count;
  30. }
  31. static int spl_ram_load_image(struct spl_image_info *spl_image,
  32. struct spl_boot_device *bootdev)
  33. {
  34. struct legacy_img_hdr *header;
  35. int ret;
  36. header = (struct legacy_img_hdr *)CONFIG_SPL_LOAD_FIT_ADDRESS;
  37. if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD)) {
  38. unsigned long addr = (unsigned long)header;
  39. ret = image_pre_load(addr);
  40. if (ret)
  41. return ret;
  42. addr += image_load_offset;
  43. header = (struct legacy_img_hdr *)addr;
  44. }
  45. #if CONFIG_IS_ENABLED(DFU)
  46. if (bootdev->boot_device == BOOT_DEVICE_DFU)
  47. spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0");
  48. #endif
  49. if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
  50. image_get_magic(header) == FDT_MAGIC) {
  51. struct spl_load_info load;
  52. debug("Found FIT\n");
  53. load.bl_len = 1;
  54. load.read = spl_ram_load_read;
  55. ret = spl_load_simple_fit(spl_image, &load, 0, header);
  56. } else {
  57. ulong u_boot_pos = spl_get_image_pos();
  58. debug("Legacy image\n");
  59. /*
  60. * Get the header. It will point to an address defined by
  61. * handoff which will tell where the image located inside
  62. * the flash.
  63. */
  64. debug("u_boot_pos = %lx\n", u_boot_pos);
  65. if (u_boot_pos == BINMAN_SYM_MISSING) {
  66. /*
  67. * No binman support or no information. For now, fix it
  68. * to the address pointed to by U-Boot.
  69. */
  70. u_boot_pos = (ulong)spl_get_load_buffer(-sizeof(*header),
  71. sizeof(*header));
  72. }
  73. header = (struct legacy_img_hdr *)map_sysmem(u_boot_pos, 0);
  74. ret = spl_parse_image_header(spl_image, bootdev, header);
  75. }
  76. return ret;
  77. }
  78. #if CONFIG_IS_ENABLED(RAM_DEVICE)
  79. SPL_LOAD_IMAGE_METHOD("RAM", 0, BOOT_DEVICE_RAM, spl_ram_load_image);
  80. #endif
  81. #if CONFIG_IS_ENABLED(DFU)
  82. SPL_LOAD_IMAGE_METHOD("DFU", 0, BOOT_DEVICE_DFU, spl_ram_load_image);
  83. #endif