122802f4eSStefan Agner /*
222802f4eSStefan Agner * (C) Copyright 2016
322802f4eSStefan Agner * Xilinx, Inc.
422802f4eSStefan Agner *
522802f4eSStefan Agner * (C) Copyright 2016
622802f4eSStefan Agner * Toradex AG
722802f4eSStefan Agner *
822802f4eSStefan Agner * Michal Simek <michal.simek@xilinx.com>
922802f4eSStefan Agner * Stefan Agner <stefan.agner@toradex.com>
1022802f4eSStefan Agner *
1122802f4eSStefan Agner * SPDX-License-Identifier: GPL-2.0+
1222802f4eSStefan Agner */
1322802f4eSStefan Agner #include <common.h>
1422802f4eSStefan Agner #include <spl.h>
150e00a84cSMasahiro Yamada #include <linux/libfdt.h>
1622802f4eSStefan Agner
1722802f4eSStefan Agner #ifndef CONFIG_SPL_LOAD_FIT_ADDRESS
1822802f4eSStefan Agner # define CONFIG_SPL_LOAD_FIT_ADDRESS 0
1922802f4eSStefan Agner #endif
2022802f4eSStefan Agner
spl_ram_load_read(struct spl_load_info * load,ulong sector,ulong count,void * buf)2122802f4eSStefan Agner static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector,
2222802f4eSStefan Agner ulong count, void *buf)
2322802f4eSStefan Agner {
2422802f4eSStefan Agner debug("%s: sector %lx, count %lx, buf %lx\n",
2522802f4eSStefan Agner __func__, sector, count, (ulong)buf);
2622802f4eSStefan Agner memcpy(buf, (void *)(CONFIG_SPL_LOAD_FIT_ADDRESS + sector), count);
2722802f4eSStefan Agner return count;
2822802f4eSStefan Agner }
2922802f4eSStefan Agner
spl_ram_load_image(struct spl_image_info * spl_image,struct spl_boot_device * bootdev)3022802f4eSStefan Agner static int spl_ram_load_image(struct spl_image_info *spl_image,
3122802f4eSStefan Agner struct spl_boot_device *bootdev)
3222802f4eSStefan Agner {
3322802f4eSStefan Agner struct image_header *header;
3422802f4eSStefan Agner
3522802f4eSStefan Agner header = (struct image_header *)CONFIG_SPL_LOAD_FIT_ADDRESS;
3622802f4eSStefan Agner
3709b32b41SAndrew F. Davis #if CONFIG_IS_ENABLED(DFU)
3822802f4eSStefan Agner if (bootdev->boot_device == BOOT_DEVICE_DFU)
3922802f4eSStefan Agner spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0");
4022802f4eSStefan Agner #endif
4122802f4eSStefan Agner
42*22c7c1a8SJoseph Chen #ifdef CONFIG_SPL_FIT_IMAGE_MULTIPLE
43*22c7c1a8SJoseph Chen if ((IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
44*22c7c1a8SJoseph Chen image_get_magic(header) == FDT_MAGIC) ||
45*22c7c1a8SJoseph Chen CONFIG_SPL_FIT_IMAGE_MULTIPLE > 1) {
46*22c7c1a8SJoseph Chen #else
4722802f4eSStefan Agner if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
4822802f4eSStefan Agner image_get_magic(header) == FDT_MAGIC) {
49*22c7c1a8SJoseph Chen #endif
5022802f4eSStefan Agner struct spl_load_info load;
5122802f4eSStefan Agner
5222802f4eSStefan Agner debug("Found FIT\n");
5322802f4eSStefan Agner load.bl_len = 1;
5422802f4eSStefan Agner load.read = spl_ram_load_read;
5522802f4eSStefan Agner spl_load_simple_fit(spl_image, &load, 0, header);
5622802f4eSStefan Agner } else {
5722802f4eSStefan Agner debug("Legacy image\n");
5822802f4eSStefan Agner /*
5922802f4eSStefan Agner * Get the header. It will point to an address defined by
6022802f4eSStefan Agner * handoff which will tell where the image located inside
6122802f4eSStefan Agner * the flash. For now, it will temporary fixed to address
6222802f4eSStefan Agner * pointed by U-Boot.
6322802f4eSStefan Agner */
6422802f4eSStefan Agner header = (struct image_header *)
6522802f4eSStefan Agner (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
6622802f4eSStefan Agner
6722802f4eSStefan Agner spl_parse_image_header(spl_image, header);
6822802f4eSStefan Agner }
6922802f4eSStefan Agner
7022802f4eSStefan Agner return 0;
7122802f4eSStefan Agner }
7222802f4eSStefan Agner #if defined(CONFIG_SPL_RAM_DEVICE)
7322802f4eSStefan Agner SPL_LOAD_IMAGE_METHOD("RAM", 0, BOOT_DEVICE_RAM, spl_ram_load_image);
7422802f4eSStefan Agner #endif
7509b32b41SAndrew F. Davis #if CONFIG_IS_ENABLED(DFU)
7622802f4eSStefan Agner SPL_LOAD_IMAGE_METHOD("DFU", 0, BOOT_DEVICE_DFU, spl_ram_load_image);
7722802f4eSStefan Agner #endif
7822802f4eSStefan Agner
7922802f4eSStefan Agner
80