1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
11 static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
12 ulong count, void *buf)
14 debug("%s: sector %lx, count %lx, buf %p\n",
15 __func__, sector, count, buf);
16 memcpy(buf, (void *)sector, count);
21 unsigned long __weak spl_nor_get_uboot_base(void)
23 return CONFIG_SYS_UBOOT_BASE;
26 static int spl_nor_load_image(struct spl_image_info *spl_image,
27 struct spl_boot_device *bootdev)
29 __maybe_unused const struct legacy_img_hdr *header;
30 __maybe_unused struct spl_load_info load;
33 * Loading of the payload to SDRAM is done with skipping of
34 * the mkimage header in this SPL NOR driver
36 spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
38 #if CONFIG_IS_ENABLED(OS_BOOT)
39 if (!spl_start_uboot()) {
41 * Load Linux from its location in NOR flash to its defined
44 header = (const struct legacy_img_hdr *)CONFIG_SYS_OS_BASE;
45 #ifdef CONFIG_SPL_LOAD_FIT
46 if (image_get_magic(header) == FDT_MAGIC) {
51 load.read = spl_nor_load_read;
53 ret = spl_load_simple_fit(spl_image, &load,
57 #if defined CONFIG_SYS_SPL_ARGS_ADDR && defined CONFIG_CMD_SPL_NOR_OFS
58 memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR,
59 (void *)CONFIG_CMD_SPL_NOR_OFS,
60 CONFIG_CMD_SPL_WRITE_SIZE);
65 if (image_get_os(header) == IH_OS_LINUX) {
66 /* happy - was a Linux */
69 ret = spl_parse_image_header(spl_image, bootdev, header);
73 memcpy((void *)spl_image->load_addr,
74 (void *)(CONFIG_SYS_OS_BASE +
75 sizeof(struct legacy_img_hdr)),
77 #ifdef CONFIG_SYS_SPL_ARGS_ADDR
78 spl_image->arg = (void *)CONFIG_SYS_SPL_ARGS_ADDR;
83 puts("The Expected Linux image was not found.\n"
84 "Please check your NOR configuration.\n"
85 "Trying to start u-boot now...\n");
91 * Load real U-Boot from its location in NOR flash to its
92 * defined location in SDRAM
94 #ifdef CONFIG_SPL_LOAD_FIT
95 header = (const struct legacy_img_hdr *)spl_nor_get_uboot_base();
96 if (image_get_magic(header) == FDT_MAGIC) {
97 debug("Found FIT format U-Boot\n");
99 load.read = spl_nor_load_read;
100 return spl_load_simple_fit(spl_image, &load,
101 spl_nor_get_uboot_base(),
105 if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
107 load.read = spl_nor_load_read;
108 return spl_load_imx_container(spl_image, &load,
109 spl_nor_get_uboot_base());
112 /* Legacy image handling */
113 if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT)) {
115 load.read = spl_nor_load_read;
116 return spl_load_legacy_img(spl_image, bootdev, &load,
117 spl_nor_get_uboot_base());
122 SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);