1 // SPDX-License-Identifier: GPL-2.0+
9 * Michal Simek <michal.simek@xilinx.com>
10 * Stefan Agner <stefan.agner@toradex.com>
13 #include <binman_sym.h>
18 #include <linux/libfdt.h>
20 #ifndef CONFIG_SPL_LOAD_FIT_ADDRESS
21 # define CONFIG_SPL_LOAD_FIT_ADDRESS 0
24 static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector,
25 ulong count, void *buf)
29 debug("%s: sector %lx, count %lx, buf %lx\n",
30 __func__, sector, count, (ulong)buf);
32 addr = (ulong)CONFIG_SPL_LOAD_FIT_ADDRESS + sector;
33 if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD))
34 addr += image_load_offset;
36 memcpy(buf, (void *)addr, count);
41 static int spl_ram_load_image(struct spl_image_info *spl_image,
42 struct spl_boot_device *bootdev)
44 struct image_header *header;
46 header = (struct image_header *)CONFIG_SPL_LOAD_FIT_ADDRESS;
48 if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD)) {
49 unsigned long addr = (unsigned long)header;
50 int ret = image_pre_load(addr);
55 addr += image_load_offset;
56 header = (struct image_header *)addr;
59 #if CONFIG_IS_ENABLED(DFU)
60 if (bootdev->boot_device == BOOT_DEVICE_DFU)
61 spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0");
64 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
65 image_get_magic(header) == FDT_MAGIC) {
66 struct spl_load_info load;
70 load.read = spl_ram_load_read;
71 spl_load_simple_fit(spl_image, &load, 0, header);
73 ulong u_boot_pos = binman_sym(ulong, u_boot_any, image_pos);
75 debug("Legacy image\n");
77 * Get the header. It will point to an address defined by
78 * handoff which will tell where the image located inside
81 debug("u_boot_pos = %lx\n", u_boot_pos);
82 if (u_boot_pos == BINMAN_SYM_MISSING) {
84 * No binman support or no information. For now, fix it
85 * to the address pointed to by U-Boot.
87 u_boot_pos = (ulong)spl_get_load_buffer(-sizeof(*header),
90 header = (struct image_header *)map_sysmem(u_boot_pos, 0);
92 spl_parse_image_header(spl_image, bootdev, header);
97 #if CONFIG_IS_ENABLED(RAM_DEVICE)
98 SPL_LOAD_IMAGE_METHOD("RAM", 0, BOOT_DEVICE_RAM, spl_ram_load_image);
100 #if CONFIG_IS_ENABLED(DFU)
101 SPL_LOAD_IMAGE_METHOD("DFU", 0, BOOT_DEVICE_DFU, spl_ram_load_image);