xref: /openbmc/u-boot/common/spl/spl_nor.c (revision 2d2811c2)
1 /*
2  * Copyright (C) 2012 Stefan Roese <sr@denx.de>
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <spl.h>
9 
10 int spl_nor_load_image(void)
11 {
12 	int ret;
13 	/*
14 	 * Loading of the payload to SDRAM is done with skipping of
15 	 * the mkimage header in this SPL NOR driver
16 	 */
17 	spl_image.flags |= SPL_COPY_PAYLOAD_ONLY;
18 
19 #ifdef CONFIG_SPL_OS_BOOT
20 	if (!spl_start_uboot()) {
21 		const struct image_header *header;
22 
23 		/*
24 		 * Load Linux from its location in NOR flash to its defined
25 		 * location in SDRAM
26 		 */
27 		header = (const struct image_header *)CONFIG_SYS_OS_BASE;
28 
29 		if (image_get_os(header) == IH_OS_LINUX) {
30 			/* happy - was a Linux */
31 
32 			ret = spl_parse_image_header(header);
33 			if (ret)
34 				return ret;
35 
36 			memcpy((void *)spl_image.load_addr,
37 			       (void *)(CONFIG_SYS_OS_BASE +
38 					sizeof(struct image_header)),
39 			       spl_image.size);
40 
41 			/*
42 			 * Copy DT blob (fdt) to SDRAM. Passing pointer to
43 			 * flash doesn't work
44 			 */
45 			memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR,
46 			       (void *)(CONFIG_SYS_FDT_BASE),
47 			       CONFIG_SYS_FDT_SIZE);
48 
49 			return 0;
50 		} else {
51 			puts("The Expected Linux image was not found.\n"
52 			     "Please check your NOR configuration.\n"
53 			     "Trying to start u-boot now...\n");
54 		}
55 	}
56 #endif
57 
58 	/*
59 	 * Load real U-Boot from its location in NOR flash to its
60 	 * defined location in SDRAM
61 	 */
62 	ret = spl_parse_image_header(
63 			(const struct image_header *)CONFIG_SYS_UBOOT_BASE);
64 	if (ret)
65 		return ret;
66 
67 	memcpy((void *)(unsigned long)spl_image.load_addr,
68 	       (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
69 	       spl_image.size);
70 
71 	return 0;
72 }
73