spl_ram.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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@xilinx.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. #ifndef CONFIG_SPL_LOAD_FIT_ADDRESS
  20. # define CONFIG_SPL_LOAD_FIT_ADDRESS 0
  21. #endif
  22. static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector,
  23. ulong count, void *buf)
  24. {
  25. debug("%s: sector %lx, count %lx, buf %lx\n",
  26. __func__, sector, count, (ulong)buf);
  27. memcpy(buf, (void *)(CONFIG_SPL_LOAD_FIT_ADDRESS + sector), count);
  28. return count;
  29. }
  30. static int spl_ram_load_image(struct spl_image_info *spl_image,
  31. struct spl_boot_device *bootdev)
  32. {
  33. struct image_header *header;
  34. header = (struct image_header *)CONFIG_SPL_LOAD_FIT_ADDRESS;
  35. #if CONFIG_IS_ENABLED(DFU)
  36. if (bootdev->boot_device == BOOT_DEVICE_DFU)
  37. spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0");
  38. #endif
  39. if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
  40. image_get_magic(header) == FDT_MAGIC) {
  41. struct spl_load_info load;
  42. debug("Found FIT\n");
  43. load.bl_len = 1;
  44. load.read = spl_ram_load_read;
  45. spl_load_simple_fit(spl_image, &load, 0, header);
  46. } else {
  47. ulong u_boot_pos = binman_sym(ulong, u_boot_any, image_pos);
  48. debug("Legacy image\n");
  49. /*
  50. * Get the header. It will point to an address defined by
  51. * handoff which will tell where the image located inside
  52. * the flash.
  53. */
  54. debug("u_boot_pos = %lx\n", u_boot_pos);
  55. if (u_boot_pos == BINMAN_SYM_MISSING) {
  56. /*
  57. * No binman support or no information. For now, fix it
  58. * to the address pointed to by U-Boot.
  59. */
  60. u_boot_pos = (ulong)spl_get_load_buffer(-sizeof(*header),
  61. sizeof(*header));
  62. }
  63. header = (struct image_header *)map_sysmem(u_boot_pos, 0);
  64. spl_parse_image_header(spl_image, header);
  65. }
  66. return 0;
  67. }
  68. #if CONFIG_IS_ENABLED(RAM_DEVICE)
  69. SPL_LOAD_IMAGE_METHOD("RAM", 0, BOOT_DEVICE_RAM, spl_ram_load_image);
  70. #endif
  71. #if CONFIG_IS_ENABLED(DFU)
  72. SPL_LOAD_IMAGE_METHOD("DFU", 0, BOOT_DEVICE_DFU, spl_ram_load_image);
  73. #endif