spl_ram.c 2.1 KB

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