spl_nor.c 1.6 KB
Newer Older
1 2 3
/*
 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
 *
4
 * SPDX-License-Identifier:	GPL-2.0+
5 6 7 8 9
 */

#include <common.h>
#include <spl.h>

10
int spl_nor_load_image(void)
11
{
12
	int ret;
13 14 15 16 17 18
	/*
	 * Loading of the payload to SDRAM is done with skipping of
	 * the mkimage header in this SPL NOR driver
	 */
	spl_image.flags |= SPL_COPY_PAYLOAD_ONLY;

19 20
#ifdef CONFIG_SPL_OS_BOOT
	if (!spl_start_uboot()) {
21
		const struct image_header *header;
22 23 24 25 26

		/*
		 * Load Linux from its location in NOR flash to its defined
		 * location in SDRAM
		 */
27
		header = (const struct image_header *)CONFIG_SYS_OS_BASE;
28

29 30
		if (image_get_os(header) == IH_OS_LINUX) {
			/* happy - was a Linux */
31

32 33 34
			ret = spl_parse_image_header(header);
			if (ret)
				return ret;
35 36 37 38 39 40 41 42

			memcpy((void *)spl_image.load_addr,
			       (void *)(CONFIG_SYS_OS_BASE +
					sizeof(struct image_header)),
			       spl_image.size);

			/*
			 * Copy DT blob (fdt) to SDRAM. Passing pointer to
43
			 * flash doesn't work
44 45 46
			 */
			memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR,
			       (void *)(CONFIG_SYS_FDT_BASE),
47
			       CONFIG_SYS_FDT_SIZE);
48

49
			return 0;
50 51 52 53 54
		} else {
			puts("The Expected Linux image was not found.\n"
			     "Please check your NOR configuration.\n"
			     "Trying to start u-boot now...\n");
		}
55
	}
56 57 58 59 60 61
#endif

	/*
	 * Load real U-Boot from its location in NOR flash to its
	 * defined location in SDRAM
	 */
62
	ret = spl_parse_image_header(
63
			(const struct image_header *)CONFIG_SYS_UBOOT_BASE);
64 65
	if (ret)
		return ret;
66

67
	memcpy((void *)(unsigned long)spl_image.load_addr,
68 69
	       (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
	       spl_image.size);
70 71

	return 0;
72
}