spl_ram.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * (C) Copyright 2016
  3. * Xilinx, Inc.
  4. *
  5. * (C) Copyright 2016
  6. * Toradex AG
  7. *
  8. * Michal Simek <michal.simek@xilinx.com>
  9. * Stefan Agner <stefan.agner@toradex.com>
  10. *
  11. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. #include <common.h>
  14. #include <spl.h>
  15. #include <libfdt.h>
  16. #ifndef CONFIG_SPL_LOAD_FIT_ADDRESS
  17. # define CONFIG_SPL_LOAD_FIT_ADDRESS 0
  18. #endif
  19. static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector,
  20. ulong count, void *buf)
  21. {
  22. debug("%s: sector %lx, count %lx, buf %lx\n",
  23. __func__, sector, count, (ulong)buf);
  24. memcpy(buf, (void *)(CONFIG_SPL_LOAD_FIT_ADDRESS + sector), count);
  25. return count;
  26. }
  27. static int spl_ram_load_image(struct spl_image_info *spl_image,
  28. struct spl_boot_device *bootdev)
  29. {
  30. struct image_header *header;
  31. header = (struct image_header *)CONFIG_SPL_LOAD_FIT_ADDRESS;
  32. #if defined(CONFIG_SPL_DFU_SUPPORT)
  33. if (bootdev->boot_device == BOOT_DEVICE_DFU)
  34. spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0");
  35. #endif
  36. if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
  37. image_get_magic(header) == FDT_MAGIC) {
  38. struct spl_load_info load;
  39. debug("Found FIT\n");
  40. load.bl_len = 1;
  41. load.read = spl_ram_load_read;
  42. spl_load_simple_fit(spl_image, &load, 0, header);
  43. } else {
  44. debug("Legacy image\n");
  45. /*
  46. * Get the header. It will point to an address defined by
  47. * handoff which will tell where the image located inside
  48. * the flash. For now, it will temporary fixed to address
  49. * pointed by U-Boot.
  50. */
  51. header = (struct image_header *)
  52. (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
  53. spl_parse_image_header(spl_image, header);
  54. }
  55. return 0;
  56. }
  57. #if defined(CONFIG_SPL_RAM_DEVICE)
  58. SPL_LOAD_IMAGE_METHOD("RAM", 0, BOOT_DEVICE_RAM, spl_ram_load_image);
  59. #endif
  60. #if defined(CONFIG_SPL_DFU_SUPPORT)
  61. SPL_LOAD_IMAGE_METHOD("DFU", 0, BOOT_DEVICE_DFU, spl_ram_load_image);
  62. #endif