blob: b2645a194806c8ad9b43afaa5239316da3d8bc83 [file] [log] [blame]
Stefan Agner22802f42016-12-23 07:51:53 +01001/*
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
17#ifndef CONFIG_SPL_LOAD_FIT_ADDRESS
18# define CONFIG_SPL_LOAD_FIT_ADDRESS 0
19#endif
20
21static 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
30static int spl_ram_load_image(struct spl_image_info *spl_image,
31 struct spl_boot_device *bootdev)
32{
33 struct image_header *header;
34
35 header = (struct image_header *)CONFIG_SPL_LOAD_FIT_ADDRESS;
36
37#if defined(CONFIG_SPL_DFU_SUPPORT)
38 if (bootdev->boot_device == BOOT_DEVICE_DFU)
39 spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0");
40#endif
41
42 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
43 image_get_magic(header) == FDT_MAGIC) {
44 struct spl_load_info load;
45
46 debug("Found FIT\n");
47 load.bl_len = 1;
48 load.read = spl_ram_load_read;
49 spl_load_simple_fit(spl_image, &load, 0, header);
50 } else {
51 debug("Legacy image\n");
52 /*
53 * Get the header. It will point to an address defined by
54 * handoff which will tell where the image located inside
55 * the flash. For now, it will temporary fixed to address
56 * pointed by U-Boot.
57 */
58 header = (struct image_header *)
59 (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
60
61 spl_parse_image_header(spl_image, header);
62 }
63
64 return 0;
65}
66#if defined(CONFIG_SPL_RAM_DEVICE)
67SPL_LOAD_IMAGE_METHOD("RAM", 0, BOOT_DEVICE_RAM, spl_ram_load_image);
68#endif
69#if defined(CONFIG_SPL_DFU_SUPPORT)
70SPL_LOAD_IMAGE_METHOD("DFU", 0, BOOT_DEVICE_DFU, spl_ram_load_image);
71#endif
72
73