2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-08-27 10:50:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Stefan Roese <sr@denx.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <image.h>
|
arm: imx: Check header before calling spl_load_imx_container
Make sure we have an IMX header before calling spl_load_imx_container,
since if we don't it will fail with -ENOENT. This allows us to fall back to
legacy/raw images if they are also enabled.
This is a functional change, one which likely should have been in place
from the start, but a functional change nonetheless. Previously, all
non-IMX8 images (except FITs without FIT_FULL) would be optimized out if
the only image load method enabled supported IMX8 images. With this change,
support for other image types now has an effect.
There are seven boards with SPL_LOAD_IMX_CONTAINER enabled: three with
SPL_BOOTROM_SUPPORT:
imx93_11x11_evk_ld imx93_11x11_evk imx8ulp_evk
and four with SPL_MMC:
deneb imx8qxp_mek giedi imx8qm_mek
All of these boards also have SPL_RAW_IMAGE_SUPPORT and
SPL_LEGACY_IMAGE_FORMAT enabled as well. However, none have FIT support
enabled. Of the six load methods affected by this patch, only SPL_MMC and
SPL_BOOTROM_SUPPORT are enabled with SPL_LOAD_IMX_CONTAINER.
spl_romapi_load_image_seekable does not support legacy or raw images, so
there is no growth. However, mmc_load_image_raw_sector does support loading
legacy/raw images. Since these images could not have been booted before, I
have disabled support for legacy/raw images on these four boards. This
reduces bloat from around 800 bytes to around 200.
There are no in-tree boards with SPL_LOAD_IMX_CONTAINER and AHAB_BOOT both
enabled, so we do not need to worry about potentially falling back to
legacy images in a secure boot scenario.
Future work could include merging imx_container.h with imx8image.h, since
they appear to define mostly the same structures.
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-10-14 20:47:44 +00:00
|
|
|
#include <imx_container.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2023-10-14 20:47:55 +00:00
|
|
|
#include <mapmem.h>
|
2012-08-27 10:50:59 +00:00
|
|
|
#include <spl.h>
|
|
|
|
|
2018-06-26 17:10:03 +00:00
|
|
|
static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
|
|
|
|
ulong count, void *buf)
|
|
|
|
{
|
|
|
|
debug("%s: sector %lx, count %lx, buf %p\n",
|
|
|
|
__func__, sector, count, buf);
|
2023-10-14 20:47:55 +00:00
|
|
|
memcpy(buf, map_sysmem(sector, count), count);
|
2018-06-26 17:10:03 +00:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2019-09-23 02:18:42 +00:00
|
|
|
unsigned long __weak spl_nor_get_uboot_base(void)
|
|
|
|
{
|
2022-11-16 18:10:41 +00:00
|
|
|
return CFG_SYS_UBOOT_BASE;
|
2019-09-23 02:18:42 +00:00
|
|
|
}
|
|
|
|
|
2016-09-25 00:20:13 +00:00
|
|
|
static int spl_nor_load_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev)
|
2012-08-27 10:50:59 +00:00
|
|
|
{
|
2023-10-14 20:47:38 +00:00
|
|
|
struct legacy_img_hdr *header;
|
2018-06-26 17:10:03 +00:00
|
|
|
__maybe_unused struct spl_load_info load;
|
|
|
|
|
2012-08-27 10:50:59 +00:00
|
|
|
/*
|
|
|
|
* Loading of the payload to SDRAM is done with skipping of
|
|
|
|
* the mkimage header in this SPL NOR driver
|
|
|
|
*/
|
2016-09-25 00:20:13 +00:00
|
|
|
spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
|
2012-08-27 10:50:59 +00:00
|
|
|
|
2021-10-31 03:03:48 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OS_BOOT)
|
2015-01-08 10:23:35 +00:00
|
|
|
if (!spl_start_uboot()) {
|
2012-08-27 10:50:59 +00:00
|
|
|
/*
|
|
|
|
* Load Linux from its location in NOR flash to its defined
|
|
|
|
* location in SDRAM
|
|
|
|
*/
|
2023-10-14 20:47:38 +00:00
|
|
|
header = (void *)CONFIG_SYS_OS_BASE;
|
2018-06-26 17:10:03 +00:00
|
|
|
#ifdef CONFIG_SPL_LOAD_FIT
|
|
|
|
if (image_get_magic(header) == FDT_MAGIC) {
|
2020-04-21 07:28:44 +00:00
|
|
|
int ret;
|
|
|
|
|
2018-06-26 17:10:03 +00:00
|
|
|
debug("Found FIT\n");
|
|
|
|
load.bl_len = 1;
|
|
|
|
load.read = spl_nor_load_read;
|
2012-08-27 10:50:59 +00:00
|
|
|
|
2018-06-26 17:10:03 +00:00
|
|
|
ret = spl_load_simple_fit(spl_image, &load,
|
|
|
|
CONFIG_SYS_OS_BASE,
|
|
|
|
(void *)header);
|
|
|
|
|
2023-09-26 14:14:17 +00:00
|
|
|
#if defined CONFIG_SPL_PAYLOAD_ARGS_ADDR && defined CONFIG_CMD_SPL_NOR_OFS
|
|
|
|
memcpy((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR,
|
2019-10-15 08:28:45 +00:00
|
|
|
(void *)CONFIG_CMD_SPL_NOR_OFS,
|
|
|
|
CONFIG_CMD_SPL_WRITE_SIZE);
|
|
|
|
#endif
|
2018-06-26 17:10:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
2015-01-08 10:23:35 +00:00
|
|
|
if (image_get_os(header) == IH_OS_LINUX) {
|
|
|
|
/* happy - was a Linux */
|
2020-04-21 07:28:44 +00:00
|
|
|
int ret;
|
2012-08-27 10:50:59 +00:00
|
|
|
|
2022-01-14 13:31:38 +00:00
|
|
|
ret = spl_parse_image_header(spl_image, bootdev, header);
|
2016-04-28 22:44:54 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-01-08 10:23:35 +00:00
|
|
|
|
2016-09-25 00:20:13 +00:00
|
|
|
memcpy((void *)spl_image->load_addr,
|
2015-01-08 10:23:35 +00:00
|
|
|
(void *)(CONFIG_SYS_OS_BASE +
|
2022-09-07 02:26:52 +00:00
|
|
|
sizeof(struct legacy_img_hdr)),
|
2016-09-25 00:20:13 +00:00
|
|
|
spl_image->size);
|
2023-09-26 14:14:17 +00:00
|
|
|
#ifdef CONFIG_SPL_PAYLOAD_ARGS_ADDR
|
|
|
|
spl_image->arg = (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR;
|
2018-06-26 17:10:04 +00:00
|
|
|
#endif
|
2015-01-08 10:23:35 +00:00
|
|
|
|
2015-11-08 15:11:49 +00:00
|
|
|
return 0;
|
2015-01-08 10:23:35 +00:00
|
|
|
} else {
|
|
|
|
puts("The Expected Linux image was not found.\n"
|
|
|
|
"Please check your NOR configuration.\n"
|
|
|
|
"Trying to start u-boot now...\n");
|
|
|
|
}
|
2012-08-27 10:50:59 +00:00
|
|
|
}
|
2015-01-08 10:23:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load real U-Boot from its location in NOR flash to its
|
|
|
|
* defined location in SDRAM
|
|
|
|
*/
|
2023-10-14 20:47:55 +00:00
|
|
|
header = map_sysmem(spl_nor_get_uboot_base(), sizeof(*header));
|
2023-10-14 20:47:38 +00:00
|
|
|
#ifdef CONFIG_SPL_LOAD_FIT
|
2018-06-26 17:10:03 +00:00
|
|
|
if (image_get_magic(header) == FDT_MAGIC) {
|
|
|
|
debug("Found FIT format U-Boot\n");
|
|
|
|
load.bl_len = 1;
|
|
|
|
load.read = spl_nor_load_read;
|
2020-04-21 07:28:44 +00:00
|
|
|
return spl_load_simple_fit(spl_image, &load,
|
|
|
|
spl_nor_get_uboot_base(),
|
|
|
|
(void *)header);
|
2018-06-26 17:10:03 +00:00
|
|
|
}
|
|
|
|
#endif
|
arm: imx: Check header before calling spl_load_imx_container
Make sure we have an IMX header before calling spl_load_imx_container,
since if we don't it will fail with -ENOENT. This allows us to fall back to
legacy/raw images if they are also enabled.
This is a functional change, one which likely should have been in place
from the start, but a functional change nonetheless. Previously, all
non-IMX8 images (except FITs without FIT_FULL) would be optimized out if
the only image load method enabled supported IMX8 images. With this change,
support for other image types now has an effect.
There are seven boards with SPL_LOAD_IMX_CONTAINER enabled: three with
SPL_BOOTROM_SUPPORT:
imx93_11x11_evk_ld imx93_11x11_evk imx8ulp_evk
and four with SPL_MMC:
deneb imx8qxp_mek giedi imx8qm_mek
All of these boards also have SPL_RAW_IMAGE_SUPPORT and
SPL_LEGACY_IMAGE_FORMAT enabled as well. However, none have FIT support
enabled. Of the six load methods affected by this patch, only SPL_MMC and
SPL_BOOTROM_SUPPORT are enabled with SPL_LOAD_IMX_CONTAINER.
spl_romapi_load_image_seekable does not support legacy or raw images, so
there is no growth. However, mmc_load_image_raw_sector does support loading
legacy/raw images. Since these images could not have been booted before, I
have disabled support for legacy/raw images on these four boards. This
reduces bloat from around 800 bytes to around 200.
There are no in-tree boards with SPL_LOAD_IMX_CONTAINER and AHAB_BOOT both
enabled, so we do not need to worry about potentially falling back to
legacy images in a secure boot scenario.
Future work could include merging imx_container.h with imx8image.h, since
they appear to define mostly the same structures.
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-10-14 20:47:44 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
|
|
|
|
valid_container_hdr((void *)header)) {
|
2019-09-23 02:18:48 +00:00
|
|
|
load.bl_len = 1;
|
|
|
|
load.read = spl_nor_load_read;
|
|
|
|
return spl_load_imx_container(spl_image, &load,
|
|
|
|
spl_nor_get_uboot_base());
|
|
|
|
}
|
|
|
|
|
2020-04-21 07:28:43 +00:00
|
|
|
/* Legacy image handling */
|
2022-05-04 20:52:25 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT)) {
|
2020-04-21 07:28:43 +00:00
|
|
|
load.bl_len = 1;
|
|
|
|
load.read = spl_nor_load_read;
|
2022-01-14 13:31:38 +00:00
|
|
|
return spl_load_legacy_img(spl_image, bootdev, &load,
|
2022-09-29 10:11:28 +00:00
|
|
|
spl_nor_get_uboot_base(),
|
2023-10-14 20:47:38 +00:00
|
|
|
header);
|
2020-04-21 07:28:43 +00:00
|
|
|
}
|
2015-11-08 15:11:49 +00:00
|
|
|
|
2023-01-30 09:21:43 +00:00
|
|
|
return -EINVAL;
|
2012-08-27 10:50:59 +00:00
|
|
|
}
|
2016-11-30 22:30:50 +00:00
|
|
|
SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);
|