xref: /OK3568_Linux_fs/u-boot/common/spl/spl_ram.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 <spl.h>
15 #include <linux/libfdt.h>
16 
17 #ifndef CONFIG_SPL_LOAD_FIT_ADDRESS
18 # define CONFIG_SPL_LOAD_FIT_ADDRESS	0
19 #endif
20 
spl_ram_load_read(struct spl_load_info * load,ulong sector,ulong count,void * buf)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 
spl_ram_load_image(struct spl_image_info * spl_image,struct spl_boot_device * bootdev)30 static 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 CONFIG_IS_ENABLED(DFU)
38 	if (bootdev->boot_device == BOOT_DEVICE_DFU)
39 		spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0");
40 #endif
41 
42 #ifdef CONFIG_SPL_FIT_IMAGE_MULTIPLE
43 	if ((IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
44 	     image_get_magic(header) == FDT_MAGIC) ||
45 	     CONFIG_SPL_FIT_IMAGE_MULTIPLE > 1) {
46 #else
47 	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
48 	    image_get_magic(header) == FDT_MAGIC) {
49 #endif
50 		struct spl_load_info load;
51 
52 		debug("Found FIT\n");
53 		load.bl_len = 1;
54 		load.read = spl_ram_load_read;
55 		spl_load_simple_fit(spl_image, &load, 0, header);
56 	} else {
57 		debug("Legacy image\n");
58 		/*
59 		 * Get the header.  It will point to an address defined by
60 		 * handoff which will tell where the image located inside
61 		 * the flash. For now, it will temporary fixed to address
62 		 * pointed by U-Boot.
63 		 */
64 		header = (struct image_header *)
65 			(CONFIG_SYS_TEXT_BASE -	sizeof(struct image_header));
66 
67 		spl_parse_image_header(spl_image, header);
68 	}
69 
70 	return 0;
71 }
72 #if defined(CONFIG_SPL_RAM_DEVICE)
73 SPL_LOAD_IMAGE_METHOD("RAM", 0, BOOT_DEVICE_RAM, spl_ram_load_image);
74 #endif
75 #if CONFIG_IS_ENABLED(DFU)
76 SPL_LOAD_IMAGE_METHOD("DFU", 0, BOOT_DEVICE_DFU, spl_ram_load_image);
77 #endif
78 
79 
80