1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
9 static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
10 ulong count, void *buf)
12 debug("%s: sector %lx, count %lx, buf %p\n",
13 __func__, sector, count, buf);
14 memcpy(buf, (void *)sector, count);
19 unsigned long __weak spl_nor_get_uboot_base(void)
21 return CONFIG_SYS_UBOOT_BASE;
24 static int spl_nor_load_image(struct spl_image_info *spl_image,
25 struct spl_boot_device *bootdev)
27 __maybe_unused const struct image_header *header;
28 __maybe_unused struct spl_load_info load;
31 * Loading of the payload to SDRAM is done with skipping of
32 * the mkimage header in this SPL NOR driver
34 spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
36 #ifdef CONFIG_SPL_OS_BOOT
37 if (!spl_start_uboot()) {
39 * Load Linux from its location in NOR flash to its defined
42 header = (const struct image_header *)CONFIG_SYS_OS_BASE;
43 #ifdef CONFIG_SPL_LOAD_FIT
44 if (image_get_magic(header) == FDT_MAGIC) {
49 load.read = spl_nor_load_read;
51 ret = spl_load_simple_fit(spl_image, &load,
55 #if defined CONFIG_SYS_SPL_ARGS_ADDR && defined CONFIG_CMD_SPL_NOR_OFS
56 memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR,
57 (void *)CONFIG_CMD_SPL_NOR_OFS,
58 CONFIG_CMD_SPL_WRITE_SIZE);
63 if (image_get_os(header) == IH_OS_LINUX) {
64 /* happy - was a Linux */
67 ret = spl_parse_image_header(spl_image, header);
71 memcpy((void *)spl_image->load_addr,
72 (void *)(CONFIG_SYS_OS_BASE +
73 sizeof(struct image_header)),
75 #ifdef CONFIG_SYS_FDT_BASE
76 spl_image->arg = (void *)CONFIG_SYS_FDT_BASE;
81 puts("The Expected Linux image was not found.\n"
82 "Please check your NOR configuration.\n"
83 "Trying to start u-boot now...\n");
89 * Load real U-Boot from its location in NOR flash to its
90 * defined location in SDRAM
92 #ifdef CONFIG_SPL_LOAD_FIT
93 header = (const struct image_header *)spl_nor_get_uboot_base();
94 if (image_get_magic(header) == FDT_MAGIC) {
95 debug("Found FIT format U-Boot\n");
97 load.read = spl_nor_load_read;
98 return spl_load_simple_fit(spl_image, &load,
99 spl_nor_get_uboot_base(),
103 if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
105 load.read = spl_nor_load_read;
106 return spl_load_imx_container(spl_image, &load,
107 spl_nor_get_uboot_base());
110 /* Legacy image handling */
111 if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_SUPPORT)) {
113 load.read = spl_nor_load_read;
114 return spl_load_legacy_img(spl_image, &load,
115 spl_nor_get_uboot_base());
120 SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);