spl_ram.c 2.1 KB

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