summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/spl/Kconfig15
-rw-r--r--common/spl/Makefile1
-rw-r--r--common/spl/spl.c4
-rw-r--r--common/spl/spl_blk_fs.c6
-rw-r--r--common/spl/spl_ext.c4
-rw-r--r--common/spl/spl_fat.c16
-rw-r--r--common/spl/spl_fit.c42
-rw-r--r--common/spl/spl_imx_container.c160
-rw-r--r--common/spl/spl_legacy.c8
-rw-r--r--common/spl/spl_mmc.c18
-rw-r--r--common/spl/spl_nand.c4
-rw-r--r--common/spl/spl_net.c10
-rw-r--r--common/spl/spl_nor.c18
-rw-r--r--common/spl/spl_opensbi.c31
-rw-r--r--common/spl/spl_spi.c18
15 files changed, 296 insertions, 59 deletions
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 46323597942..6bc4066fad7 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -330,6 +330,20 @@ config SPL_LEGACY_IMAGE_CRC_CHECK
If disabled, Legacy images are booted if the image magic and size
are correct, without further integrity checks.
+config SPL_LOAD_IMX_CONTAINER
+ bool "Enable SPL loading and booting of i.MX8 Containers"
+ depends on SPL
+ help
+ Support booting U-Boot from an i.MX8 container image. If you are not
+ using i.MX8, say 'n'.
+
+config IMX_CONTAINER_CFG
+ string "i.MX8 Container config file"
+ depends on SPL && SPL_LOAD_IMX_CONTAINER
+ help
+ Specify the cfg file for generating the container image which will be
+ loaded by SPL.
+
config SPL_SYS_MALLOC_SIMPLE
bool "Only use malloc_simple functions in the SPL"
help
@@ -643,6 +657,7 @@ config SPL_ETH
config SPL_FS_EXT4
bool "Support EXT filesystems"
+ select SPL_CRC16 if EXT4_WRITE
help
Enable support for EXT2/3/4 filesystems with SPL. This permits
U-Boot (or Linux in Falcon mode) to be loaded from an EXT
diff --git a/common/spl/Makefile b/common/spl/Makefile
index bad2bbf6cf1..4f8eb2ec0ca 100644
--- a/common/spl/Makefile
+++ b/common/spl/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_$(SPL_TPL_)OPENSBI) += spl_opensbi.o
obj-$(CONFIG_$(SPL_TPL_)USB_STORAGE) += spl_usb.o
obj-$(CONFIG_$(SPL_TPL_)FS_FAT) += spl_fat.o
obj-$(CONFIG_$(SPL_TPL_)FS_EXT4) += spl_ext.o
+obj-$(CONFIG_$(SPL_TPL_)LOAD_IMX_CONTAINER) += spl_imx_container.o
obj-$(CONFIG_$(SPL_TPL_)SATA) += spl_sata.o
obj-$(CONFIG_$(SPL_TPL_)NVME) += spl_nvme.o
obj-$(CONFIG_$(SPL_TPL_)SEMIHOSTING) += spl_semihosting.o
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 66eeea41a34..732d90d39e6 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -653,7 +653,9 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
spl_set_bd();
if (IS_ENABLED(CONFIG_SPL_SYS_MALLOC)) {
- mem_malloc_init(SPL_SYS_MALLOC_START, SPL_SYS_MALLOC_SIZE);
+ mem_malloc_init((ulong)map_sysmem(SPL_SYS_MALLOC_START,
+ SPL_SYS_MALLOC_SIZE),
+ SPL_SYS_MALLOC_SIZE);
gd->flags |= GD_FLG_FULL_MALLOC_INIT;
}
if (!(gd->flags & GD_FLG_SPL_INIT)) {
diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
index ea5d1a51d9f..63825d620d1 100644
--- a/common/spl/spl_blk_fs.c
+++ b/common/spl/spl_blk_fs.c
@@ -9,6 +9,7 @@
#include <spl.h>
#include <image.h>
#include <fs.h>
+#include <asm/io.h>
struct blk_dev {
const char *ifname;
@@ -29,7 +30,8 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
return ret;
}
- ret = fs_read(load->filename, (ulong)buf, file_offset, size, &actlen);
+ ret = fs_read(load->filename, virt_to_phys(buf), file_offset, size,
+ &actlen);
if (ret < 0) {
printf("spl: error reading image %s. Err - %d\n",
load->filename, ret);
@@ -69,7 +71,7 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
goto out;
}
- ret = fs_read(filename, (ulong)header, 0,
+ ret = fs_read(filename, virt_to_phys(header), 0,
sizeof(struct legacy_img_hdr), &actlen);
if (ret) {
printf("spl: unable to read file %s. Err - %d\n", filename,
diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c
index 902564a6077..af836ca15b8 100644
--- a/common/spl/spl_ext.c
+++ b/common/spl/spl_ext.c
@@ -2,6 +2,7 @@
#include <common.h>
#include <env.h>
+#include <mapmem.h>
#include <part.h>
#include <spl.h>
#include <asm/u-boot.h>
@@ -53,7 +54,8 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
goto end;
}
- err = ext4fs_read((char *)spl_image->load_addr, 0, filelen, &actlen);
+ err = ext4fs_read(map_sysmem(spl_image->load_addr, filelen), 0, filelen,
+ &actlen);
end:
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index c6e2526ade1..014074f85be 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -11,6 +11,7 @@
#include <common.h>
#include <env.h>
#include <log.h>
+#include <mapmem.h>
#include <spl.h>
#include <asm/u-boot.h>
#include <fat.h>
@@ -20,6 +21,11 @@
static int fat_registered;
+void spl_fat_force_reregister(void)
+{
+ fat_registered = 0;
+}
+
static int spl_register_fat_device(struct blk_desc *block_dev, int partition)
{
int err = 0;
@@ -74,11 +80,13 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
image_get_magic(header) == FDT_MAGIC) {
- err = file_fat_read(filename, (void *)CONFIG_SYS_LOAD_ADDR, 0);
+ err = file_fat_read(filename,
+ map_sysmem(CONFIG_SYS_LOAD_ADDR, 0), 0);
if (err <= 0)
goto end;
err = spl_parse_image_header(spl_image, bootdev,
- (struct legacy_img_hdr *)CONFIG_SYS_LOAD_ADDR);
+ map_sysmem(CONFIG_SYS_LOAD_ADDR,
+ err));
if (err == -EAGAIN)
return err;
if (err == 0)
@@ -99,8 +107,8 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
if (err)
goto end;
- err = file_fat_read(filename,
- (u8 *)(uintptr_t)spl_image->load_addr, 0);
+ err = file_fat_read(filename, map_sysmem(spl_image->load_addr,
+ spl_image->size), 0);
}
end:
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 1409b926372..70d8d5942d9 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -16,6 +16,7 @@
#include <sysinfo.h>
#include <asm/cache.h>
#include <asm/global_data.h>
+#include <asm/io.h>
#include <linux/libfdt.h>
#include <linux/printk.h>
@@ -366,7 +367,8 @@ static bool os_takes_devicetree(uint8_t os)
case IH_OS_U_BOOT:
return true;
case IH_OS_LINUX:
- return IS_ENABLED(CONFIG_SPL_OS_BOOT);
+ return IS_ENABLED(CONFIG_SPL_OS_BOOT) ||
+ IS_ENABLED(CONFIG_SPL_OPENSBI);
default:
return false;
}
@@ -393,25 +395,32 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
/* Figure out which device tree the board wants to use */
node = spl_fit_get_image_node(ctx, FIT_FDT_PROP, index++);
if (node < 0) {
+ size_t size;
+
debug("%s: cannot find FDT node\n", __func__);
/*
* U-Boot did not find a device tree inside the FIT image. Use
* the U-Boot device tree instead.
*/
- if (gd->fdt_blob)
- memcpy((void *)image_info.load_addr, gd->fdt_blob,
- fdt_totalsize(gd->fdt_blob));
- else
+ if (!gd->fdt_blob)
return node;
+
+ /*
+ * Make the load-address of the FDT available for the SPL
+ * framework
+ */
+ size = fdt_totalsize(gd->fdt_blob);
+ spl_image->fdt_addr = map_sysmem(image_info.load_addr, size);
+ memcpy(spl_image->fdt_addr, gd->fdt_blob, size);
} else {
ret = load_simple_fit(info, sector, ctx, node, &image_info);
if (ret < 0)
return ret;
+
+ spl_image->fdt_addr = phys_to_virt(image_info.load_addr);
}
- /* Make the load-address of the FDT available for the SPL framework */
- spl_image->fdt_addr = map_sysmem(image_info.load_addr, 0);
if (CONFIG_IS_ENABLED(FIT_IMAGE_TINY))
return 0;
@@ -876,7 +885,7 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
#ifdef CONFIG_SPL_FIT_SIGNATURE
images.verify = 1;
#endif
- ret = fit_image_load(&images, (ulong)header,
+ ret = fit_image_load(&images, virt_to_phys((void *)header),
NULL, &fit_uname_config,
IH_ARCH_DEFAULT, IH_TYPE_STANDALONE, -1,
FIT_LOAD_OPTIONAL, &fw_data, &fw_len);
@@ -884,15 +893,15 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
printf("DEPRECATED: 'standalone = ' property.");
printf("Please use either 'firmware =' or 'kernel ='\n");
} else {
- ret = fit_image_load(&images, (ulong)header, NULL,
- &fit_uname_config, IH_ARCH_DEFAULT,
+ ret = fit_image_load(&images, virt_to_phys((void *)header),
+ NULL, &fit_uname_config, IH_ARCH_DEFAULT,
IH_TYPE_FIRMWARE, -1, FIT_LOAD_OPTIONAL,
&fw_data, &fw_len);
}
if (ret < 0) {
- ret = fit_image_load(&images, (ulong)header, NULL,
- &fit_uname_config, IH_ARCH_DEFAULT,
+ ret = fit_image_load(&images, virt_to_phys((void *)header),
+ NULL, &fit_uname_config, IH_ARCH_DEFAULT,
IH_TYPE_KERNEL, -1, FIT_LOAD_OPTIONAL,
&fw_data, &fw_len);
}
@@ -901,8 +910,9 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
return ret;
spl_image->size = fw_len;
- spl_image->entry_point = fw_data;
spl_image->load_addr = fw_data;
+ if (fit_image_get_entry(header, ret, &spl_image->entry_point))
+ spl_image->entry_point = fw_data;
if (fit_image_get_os(header, ret, &spl_image->os))
spl_image->os = IH_OS_INVALID;
spl_image->name = genimg_get_os_name(spl_image->os);
@@ -913,9 +923,9 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
#ifdef CONFIG_SPL_FIT_SIGNATURE
images.verify = 1;
#endif
- ret = fit_image_load(&images, (ulong)header, NULL, &fit_uname_config,
- IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1,
- FIT_LOAD_OPTIONAL, &dt_data, &dt_len);
+ ret = fit_image_load(&images, virt_to_phys((void *)header), NULL,
+ &fit_uname_config, IH_ARCH_DEFAULT, IH_TYPE_FLATDT,
+ -1, FIT_LOAD_OPTIONAL, &dt_data, &dt_len);
if (ret >= 0) {
spl_image->fdt_addr = (void *)dt_data;
diff --git a/common/spl/spl_imx_container.c b/common/spl/spl_imx_container.c
new file mode 100644
index 00000000000..127802f5cb7
--- /dev/null
+++ b/common/spl/spl_imx_container.c
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018-2021 NXP
+ */
+
+#define LOG_CATEGORY LOGC_ARCH
+#include <common.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <imx_container.h>
+#include <log.h>
+#include <mapmem.h>
+#include <spl.h>
+#ifdef CONFIG_AHAB_BOOT
+#include <asm/mach-imx/ahab.h>
+#endif
+
+static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image,
+ struct spl_load_info *info,
+ struct container_hdr *container,
+ int image_index,
+ u32 container_sector)
+{
+ struct boot_img_t *images;
+ ulong sector;
+ u32 sectors;
+
+ if (image_index > container->num_images) {
+ debug("Invalid image number\n");
+ return NULL;
+ }
+
+ images = (struct boot_img_t *)((u8 *)container +
+ sizeof(struct container_hdr));
+
+ if (images[image_index].offset % info->bl_len) {
+ printf("%s: image%d offset not aligned to %u\n",
+ __func__, image_index, info->bl_len);
+ return NULL;
+ }
+
+ sectors = roundup(images[image_index].size, info->bl_len) /
+ info->bl_len;
+ sector = images[image_index].offset / info->bl_len +
+ container_sector;
+
+ debug("%s: container: %p sector: %lu sectors: %u\n", __func__,
+ container, sector, sectors);
+ if (info->read(info, sector, sectors,
+ map_sysmem(images[image_index].dst,
+ images[image_index].size)) != sectors) {
+ printf("%s wrong\n", __func__);
+ return NULL;
+ }
+
+#ifdef CONFIG_AHAB_BOOT
+ if (ahab_verify_cntr_image(&images[image_index], image_index))
+ return NULL;
+#endif
+
+ return &images[image_index];
+}
+
+static int read_auth_container(struct spl_image_info *spl_image,
+ struct spl_load_info *info, ulong sector)
+{
+ struct container_hdr *container = NULL;
+ u16 length;
+ u32 sectors;
+ int i, size, ret = 0;
+
+ size = roundup(CONTAINER_HDR_ALIGNMENT, info->bl_len);
+ sectors = size / info->bl_len;
+
+ /*
+ * It will not override the ATF code, so safe to use it here,
+ * no need malloc
+ */
+ container = malloc(size);
+ if (!container)
+ return -ENOMEM;
+
+ debug("%s: container: %p sector: %lu sectors: %u\n", __func__,
+ container, sector, sectors);
+ if (info->read(info, sector, sectors, container) != sectors) {
+ ret = -EIO;
+ goto end;
+ }
+
+ if (!valid_container_hdr(container)) {
+ log_err("Wrong container header\n");
+ ret = -ENOENT;
+ goto end;
+ }
+
+ if (!container->num_images) {
+ log_err("Wrong container, no image found\n");
+ ret = -ENOENT;
+ goto end;
+ }
+
+ length = container->length_lsb + (container->length_msb << 8);
+ debug("Container length %u\n", length);
+
+ if (length > CONTAINER_HDR_ALIGNMENT) {
+ size = roundup(length, info->bl_len);
+ sectors = size / info->bl_len;
+
+ free(container);
+ container = malloc(size);
+ if (!container)
+ return -ENOMEM;
+
+ debug("%s: container: %p sector: %lu sectors: %u\n",
+ __func__, container, sector, sectors);
+ if (info->read(info, sector, sectors, container) !=
+ sectors) {
+ ret = -EIO;
+ goto end;
+ }
+ }
+
+#ifdef CONFIG_AHAB_BOOT
+ ret = ahab_auth_cntr_hdr(container, length);
+ if (ret)
+ goto end_auth;
+#endif
+
+ for (i = 0; i < container->num_images; i++) {
+ struct boot_img_t *image = read_auth_image(spl_image, info,
+ container, i,
+ sector);
+
+ if (!image) {
+ ret = -EINVAL;
+ goto end_auth;
+ }
+
+ if (i == 0) {
+ spl_image->load_addr = image->dst;
+ spl_image->entry_point = image->entry;
+ }
+ }
+
+end_auth:
+#ifdef CONFIG_AHAB_BOOT
+ ahab_auth_release();
+#endif
+
+end:
+ free(container);
+
+ return ret;
+}
+
+int spl_load_imx_container(struct spl_image_info *spl_image,
+ struct spl_load_info *info, ulong sector)
+{
+ return read_auth_container(spl_image, info, sector);
+}
diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
index 095443c63d8..51656fb9617 100644
--- a/common/spl/spl_legacy.c
+++ b/common/spl/spl_legacy.c
@@ -7,6 +7,7 @@
#include <image.h>
#include <log.h>
#include <malloc.h>
+#include <mapmem.h>
#include <asm/sections.h>
#include <spl.h>
@@ -19,7 +20,7 @@
static void spl_parse_legacy_validate(uintptr_t start, uintptr_t size)
{
uintptr_t spl_start = (uintptr_t)_start;
- uintptr_t spl_end = (uintptr_t)_image_binary_end;
+ uintptr_t spl_end = (uintptr_t)&_image_binary_end;
uintptr_t end = start + size;
if ((start >= spl_start && start < spl_end) ||
@@ -129,7 +130,7 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
dataptr += sizeof(*hdr);
load->read(load, dataptr, spl_image->size,
- (void *)(unsigned long)spl_image->load_addr);
+ map_sysmem(spl_image->load_addr, spl_image->size));
break;
case IH_COMP_LZMA:
@@ -148,7 +149,8 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
}
load->read(load, dataptr, spl_image->size, src);
- ret = lzmaBuffToBuffDecompress((void *)spl_image->load_addr,
+ ret = lzmaBuffToBuffDecompress(map_sysmem(spl_image->load_addr,
+ spl_image->size),
&lzma_len, src, spl_image->size);
if (ret) {
printf("LZMA decompression error: %d\n", ret);
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 0ab85d2168c..0b01368d9de 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -8,6 +8,7 @@
#include <common.h>
#include <dm.h>
#include <log.h>
+#include <mapmem.h>
#include <part.h>
#include <spl.h>
#include <linux/compiler.h>
@@ -16,6 +17,7 @@
#include <errno.h>
#include <mmc.h>
#include <image.h>
+#include <imx_container.h>
static int mmc_load_legacy(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev,
@@ -45,7 +47,8 @@ static int mmc_load_legacy(struct spl_image_info *spl_image,
count = blk_dread(mmc_get_blk_desc(mmc),
sector + image_offset_sectors,
image_size_sectors,
- (void *)(ulong)spl_image->load_addr);
+ map_sysmem(spl_image->load_addr,
+ image_size_sectors * mmc->read_bl_len));
debug("read %x sectors to %lx\n", image_size_sectors,
spl_image->load_addr);
if (count != image_size_sectors)
@@ -108,7 +111,8 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
load.bl_len = mmc->read_bl_len;
load.read = h_spl_load_read;
ret = spl_load_simple_fit(spl_image, &load, sector, header);
- } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+ } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+ valid_container_hdr((void *)header)) {
struct spl_load_info load;
load.dev = mmc;
@@ -396,18 +400,24 @@ static int spl_mmc_get_mmc_devnum(struct mmc *mmc)
#if !CONFIG_IS_ENABLED(BLK)
block_dev = &mmc->block_dev;
#else
- block_dev = dev_get_uclass_plat(mmc->dev);
+ block_dev = mmc_get_blk_desc(mmc);
#endif
return block_dev->devnum;
}
+static struct mmc *mmc;
+
+void spl_mmc_clear_cache(void)
+{
+ mmc = NULL;
+}
+
int spl_mmc_load(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev,
const char *filename,
int raw_part,
unsigned long raw_sect)
{
- static struct mmc *mmc;
u32 boot_mode;
int err = 0;
__maybe_unused int part = 0;
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 6cc34004f49..07916bedbb9 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -7,6 +7,7 @@
#include <config.h>
#include <fdt_support.h>
#include <image.h>
+#include <imx_container.h>
#include <log.h>
#include <spl.h>
#include <asm/io.h>
@@ -99,7 +100,8 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
load.bl_len = bl_len;
load.read = spl_nand_fit_read;
return spl_load_simple_fit(spl_image, &load, offset / bl_len, header);
- } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+ } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+ valid_container_hdr((void *)header)) {
struct spl_load_info load;
load.dev = NULL;
diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c
index b2c901b554b..f01d4df8bc6 100644
--- a/common/spl/spl_net.c
+++ b/common/spl/spl_net.c
@@ -11,6 +11,7 @@
#include <errno.h>
#include <image.h>
#include <log.h>
+#include <mapmem.h>
#include <spl.h>
#include <net.h>
#include <linux/libfdt.h>
@@ -21,14 +22,15 @@ static ulong spl_net_load_read(struct spl_load_info *load, ulong sector,
{
debug("%s: sector %lx, count %lx, buf %lx\n",
__func__, sector, count, (ulong)buf);
- memcpy(buf, (void *)(image_load_addr + sector), count);
+ memcpy(buf, map_sysmem(image_load_addr + sector, count), count);
return count;
}
static int spl_net_load_image(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev)
{
- struct legacy_img_hdr *header = (struct legacy_img_hdr *)image_load_addr;
+ struct legacy_img_hdr *header = map_sysmem(image_load_addr,
+ sizeof(*header));
int rv;
env_init();
@@ -62,7 +64,9 @@ static int spl_net_load_image(struct spl_image_info *spl_image,
if (rv)
return rv;
- memcpy((void *)spl_image->load_addr, header, spl_image->size);
+ memcpy(map_sysmem(spl_image->load_addr, spl_image->size),
+ map_sysmem(image_load_addr, spl_image->size),
+ spl_image->size);
}
return rv;
diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c
index 79d4f1d7aa8..236b0718283 100644
--- a/common/spl/spl_nor.c
+++ b/common/spl/spl_nor.c
@@ -5,7 +5,9 @@
#include <common.h>
#include <image.h>
+#include <imx_container.h>
#include <log.h>
+#include <mapmem.h>
#include <spl.h>
static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
@@ -13,7 +15,7 @@ static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
{
debug("%s: sector %lx, count %lx, buf %p\n",
__func__, sector, count, buf);
- memcpy(buf, (void *)sector, count);
+ memcpy(buf, map_sysmem(sector, count), count);
return count;
}
@@ -26,7 +28,7 @@ unsigned long __weak spl_nor_get_uboot_base(void)
static int spl_nor_load_image(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev)
{
- __maybe_unused const struct legacy_img_hdr *header;
+ struct legacy_img_hdr *header;
__maybe_unused struct spl_load_info load;
/*
@@ -41,7 +43,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
* Load Linux from its location in NOR flash to its defined
* location in SDRAM
*/
- header = (const struct legacy_img_hdr *)CONFIG_SYS_OS_BASE;
+ header = (void *)CONFIG_SYS_OS_BASE;
#ifdef CONFIG_SPL_LOAD_FIT
if (image_get_magic(header) == FDT_MAGIC) {
int ret;
@@ -91,8 +93,8 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
* Load real U-Boot from its location in NOR flash to its
* defined location in SDRAM
*/
+ header = map_sysmem(spl_nor_get_uboot_base(), sizeof(*header));
#ifdef CONFIG_SPL_LOAD_FIT
- header = (const struct legacy_img_hdr *)spl_nor_get_uboot_base();
if (image_get_magic(header) == FDT_MAGIC) {
debug("Found FIT format U-Boot\n");
load.bl_len = 1;
@@ -102,7 +104,8 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
(void *)header);
}
#endif
- if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+ if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+ valid_container_hdr((void *)header)) {
load.bl_len = 1;
load.read = spl_nor_load_read;
return spl_load_imx_container(spl_image, &load,
@@ -111,14 +114,11 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
/* Legacy image handling */
if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT)) {
- struct legacy_img_hdr hdr;
-
load.bl_len = 1;
load.read = spl_nor_load_read;
- spl_nor_load_read(&load, spl_nor_get_uboot_base(), sizeof(hdr), &hdr);
return spl_load_legacy_img(spl_image, bootdev, &load,
spl_nor_get_uboot_base(),
- &hdr);
+ header);
}
return -EINVAL;
diff --git a/common/spl/spl_opensbi.c b/common/spl/spl_opensbi.c
index 0df611623ae..9801d38c0b3 100644
--- a/common/spl/spl_opensbi.c
+++ b/common/spl/spl_opensbi.c
@@ -21,7 +21,7 @@ DECLARE_GLOBAL_DATA_PTR;
struct fw_dynamic_info opensbi_info;
-static int spl_opensbi_find_uboot_node(void *blob, int *uboot_node)
+static int spl_opensbi_find_os_node(void *blob, int *uboot_node, int os_type)
{
int fit_images_node, node;
const char *fit_os;
@@ -35,7 +35,7 @@ static int spl_opensbi_find_uboot_node(void *blob, int *uboot_node)
if (!fit_os)
continue;
- if (genimg_get_os_id(fit_os) == IH_OS_U_BOOT) {
+ if (genimg_get_os_id(fit_os) == os_type) {
*uboot_node = node;
return 0;
}
@@ -46,8 +46,9 @@ static int spl_opensbi_find_uboot_node(void *blob, int *uboot_node)
void __noreturn spl_invoke_opensbi(struct spl_image_info *spl_image)
{
- int ret, uboot_node;
- ulong uboot_entry;
+ int ret, os_node;
+ ulong os_entry;
+ int os_type;
typedef void __noreturn (*opensbi_entry_t)(ulong hartid, ulong dtb, ulong info);
opensbi_entry_t opensbi_entry;
@@ -56,22 +57,32 @@ void __noreturn spl_invoke_opensbi(struct spl_image_info *spl_image)
hang();
}
- /* Find U-Boot image in /fit-images */
- ret = spl_opensbi_find_uboot_node(spl_image->fdt_addr, &uboot_node);
+ /*
+ * Find next os image in /fit-images
+ * The next os image default is u-boot proper, once enable
+ * OpenSBI OS boot mode, the OS image should be linux.
+ */
+ if (CONFIG_IS_ENABLED(LOAD_FIT_OPENSBI_OS_BOOT))
+ os_type = IH_OS_LINUX;
+ else
+ os_type = IH_OS_U_BOOT;
+
+ ret = spl_opensbi_find_os_node(spl_image->fdt_addr, &os_node, os_type);
if (ret) {
- pr_err("Can't find U-Boot node, %d\n", ret);
+ pr_err("Can't find %s node for opensbi, %d\n",
+ genimg_get_os_name(os_type), ret);
hang();
}
/* Get U-Boot entry point */
- ret = fit_image_get_entry(spl_image->fdt_addr, uboot_node, &uboot_entry);
+ ret = fit_image_get_entry(spl_image->fdt_addr, os_node, &os_entry);
if (ret)
- ret = fit_image_get_load(spl_image->fdt_addr, uboot_node, &uboot_entry);
+ ret = fit_image_get_load(spl_image->fdt_addr, os_node, &os_entry);
/* Prepare opensbi_info object */
opensbi_info.magic = FW_DYNAMIC_INFO_MAGIC_VALUE;
opensbi_info.version = FW_DYNAMIC_INFO_VERSION;
- opensbi_info.next_addr = uboot_entry;
+ opensbi_info.next_addr = os_entry;
opensbi_info.next_mode = FW_DYNAMIC_INFO_NEXT_MODE_S;
opensbi_info.options = CONFIG_SPL_OPENSBI_SCRATCH_OPTIONS;
opensbi_info.boot_hart = gd->arch.boot_hart;
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index d69069a75bf..3ac4b1b5091 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -10,12 +10,15 @@
#include <common.h>
#include <image.h>
+#include <imx_container.h>
#include <log.h>
+#include <mapmem.h>
#include <spi.h>
#include <spi_flash.h>
#include <errno.h>
#include <spl.h>
#include <asm/global_data.h>
+#include <asm/io.h>
#include <dm/ofnode.h>
#if CONFIG_IS_ENABLED(OS_BOOT)
@@ -133,13 +136,16 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
image_get_magic(header) == FDT_MAGIC) {
+ u32 size = roundup(fdt_totalsize(header), 4);
+
err = spi_flash_read(flash, payload_offs,
- roundup(fdt_totalsize(header), 4),
- (void *)CONFIG_SYS_LOAD_ADDR);
+ size,
+ map_sysmem(CONFIG_SYS_LOAD_ADDR,
+ size));
if (err)
return err;
err = spl_parse_image_header(spl_image, bootdev,
- (struct legacy_img_hdr *)CONFIG_SYS_LOAD_ADDR);
+ phys_to_virt(CONFIG_SYS_LOAD_ADDR));
} else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
image_get_magic(header) == FDT_MAGIC) {
struct spl_load_info load;
@@ -153,7 +159,8 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
err = spl_load_simple_fit(spl_image, &load,
payload_offs,
header);
- } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+ } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+ valid_container_hdr((void *)header)) {
struct spl_load_info load;
load.dev = flash;
@@ -170,7 +177,8 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
return err;
err = spi_flash_read(flash, payload_offs + spl_image->offset,
spl_image->size,
- (void *)spl_image->load_addr);
+ map_sysmem(spl_image->load_addr,
+ spl_image->size));
}
if (IS_ENABLED(CONFIG_SPI_FLASH_SOFT_RESET)) {
err = spi_nor_remove(flash);