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