2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-09-14 19:33:34 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2010
|
|
|
|
* Texas Instruments, <www.ti.com>
|
|
|
|
*
|
|
|
|
* Aneesh V <aneesh@ti.com>
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2015-06-23 21:38:51 +00:00
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2023-10-14 20:47:55 +00:00
|
|
|
#include <mapmem.h>
|
2020-05-10 17:39:58 +00:00
|
|
|
#include <part.h>
|
2012-08-13 19:03:19 +00:00
|
|
|
#include <spl.h>
|
2015-04-27 08:20:22 +00:00
|
|
|
#include <linux/compiler.h>
|
2015-11-08 15:11:49 +00:00
|
|
|
#include <errno.h>
|
2011-09-14 19:33:34 +00:00
|
|
|
#include <asm/u-boot.h>
|
2015-11-08 15:11:44 +00:00
|
|
|
#include <errno.h>
|
2011-09-14 19:33:34 +00:00
|
|
|
#include <mmc.h>
|
2013-06-28 18:43: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>
|
2011-09-14 19:33:34 +00:00
|
|
|
|
2022-01-14 13:31:38 +00:00
|
|
|
static int mmc_load_legacy(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev,
|
|
|
|
struct mmc *mmc,
|
2022-09-07 02:26:52 +00:00
|
|
|
ulong sector, struct legacy_img_hdr *header)
|
2016-02-23 05:55:58 +00:00
|
|
|
{
|
2021-07-23 09:14:27 +00:00
|
|
|
u32 image_offset_sectors;
|
2016-02-23 05:55:58 +00:00
|
|
|
u32 image_size_sectors;
|
|
|
|
unsigned long count;
|
2021-07-23 09:14:27 +00:00
|
|
|
u32 image_offset;
|
2016-04-28 22:44:54 +00:00
|
|
|
int ret;
|
|
|
|
|
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;
|
2016-02-23 05:55:58 +00:00
|
|
|
|
2021-07-23 09:14:27 +00:00
|
|
|
/* convert offset to sectors - round down */
|
|
|
|
image_offset_sectors = spl_image->offset / mmc->read_bl_len;
|
|
|
|
/* calculate remaining offset */
|
|
|
|
image_offset = spl_image->offset % mmc->read_bl_len;
|
|
|
|
|
2016-02-23 05:55:58 +00:00
|
|
|
/* convert size to sectors - round up */
|
2016-09-25 00:20:13 +00:00
|
|
|
image_size_sectors = (spl_image->size + mmc->read_bl_len - 1) /
|
2016-02-23 05:55:58 +00:00
|
|
|
mmc->read_bl_len;
|
|
|
|
|
|
|
|
/* Read the header too to avoid extra memcpy */
|
2021-07-23 09:14:27 +00:00
|
|
|
count = blk_dread(mmc_get_blk_desc(mmc),
|
|
|
|
sector + image_offset_sectors,
|
|
|
|
image_size_sectors,
|
2023-10-14 20:47:55 +00:00
|
|
|
map_sysmem(spl_image->load_addr,
|
|
|
|
image_size_sectors * mmc->read_bl_len));
|
2017-01-02 11:48:31 +00:00
|
|
|
debug("read %x sectors to %lx\n", image_size_sectors,
|
2016-09-25 00:20:13 +00:00
|
|
|
spl_image->load_addr);
|
2016-02-23 05:55:58 +00:00
|
|
|
if (count != image_size_sectors)
|
|
|
|
return -EIO;
|
|
|
|
|
2021-07-23 09:14:27 +00:00
|
|
|
if (image_offset)
|
|
|
|
memmove((void *)(ulong)spl_image->load_addr,
|
|
|
|
(void *)(ulong)spl_image->load_addr + image_offset,
|
|
|
|
spl_image->size);
|
|
|
|
|
2016-02-23 05:55:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ulong h_spl_load_read(struct spl_load_info *load, ulong sector,
|
|
|
|
ulong count, void *buf)
|
|
|
|
{
|
|
|
|
struct mmc *mmc = load->dev;
|
|
|
|
|
2016-05-14 20:03:06 +00:00
|
|
|
return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf);
|
2016-02-23 05:55:58 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 07:08:08 +00:00
|
|
|
static __maybe_unused unsigned long spl_mmc_raw_uboot_offset(int part)
|
|
|
|
{
|
|
|
|
#if IS_ENABLED(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR)
|
|
|
|
if (part == 0)
|
|
|
|
return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-19 04:29:45 +00:00
|
|
|
static __maybe_unused
|
|
|
|
int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
|
2022-01-14 13:31:38 +00:00
|
|
|
struct spl_boot_device *bootdev,
|
2017-09-19 04:29:45 +00:00
|
|
|
struct mmc *mmc, unsigned long sector)
|
2011-09-14 19:33:34 +00:00
|
|
|
{
|
2015-05-22 10:45:35 +00:00
|
|
|
unsigned long count;
|
2022-09-07 02:26:52 +00:00
|
|
|
struct legacy_img_hdr *header;
|
2018-08-14 09:27:02 +00:00
|
|
|
struct blk_desc *bd = mmc_get_blk_desc(mmc);
|
2016-02-23 05:55:58 +00:00
|
|
|
int ret = 0;
|
2011-09-14 19:33:34 +00:00
|
|
|
|
2018-08-14 09:27:02 +00:00
|
|
|
header = spl_get_load_buffer(-sizeof(*header), bd->blksz);
|
2011-09-14 19:33:34 +00:00
|
|
|
|
|
|
|
/* read image header to find the image size & load address */
|
2018-08-14 09:27:02 +00:00
|
|
|
count = blk_dread(bd, sector, 1, header);
|
2016-02-23 05:55:58 +00:00
|
|
|
debug("hdr read sector %lx, count=%lu\n", sector, count);
|
|
|
|
if (count == 0) {
|
|
|
|
ret = -EIO;
|
2011-09-14 19:33:34 +00:00
|
|
|
goto end;
|
2016-02-23 05:55:58 +00:00
|
|
|
}
|
2011-09-14 19:33:34 +00:00
|
|
|
|
2016-03-16 03:10:00 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
|
|
|
|
image_get_magic(header) == FDT_MAGIC) {
|
2016-02-23 05:55:58 +00:00
|
|
|
struct spl_load_info load;
|
|
|
|
|
|
|
|
debug("Found FIT\n");
|
|
|
|
load.dev = mmc;
|
|
|
|
load.priv = NULL;
|
2016-05-24 05:04:38 +00:00
|
|
|
load.filename = NULL;
|
2016-02-23 05:55:58 +00:00
|
|
|
load.bl_len = mmc->read_bl_len;
|
|
|
|
load.read = h_spl_load_read;
|
2016-09-25 00:20:16 +00:00
|
|
|
ret = spl_load_simple_fit(spl_image, &load, sector, header);
|
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
|
|
|
} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
|
|
|
|
valid_container_hdr((void *)header)) {
|
2019-08-22 07:42:38 +00:00
|
|
|
struct spl_load_info load;
|
|
|
|
|
|
|
|
load.dev = mmc;
|
|
|
|
load.priv = NULL;
|
|
|
|
load.filename = NULL;
|
|
|
|
load.bl_len = mmc->read_bl_len;
|
|
|
|
load.read = h_spl_load_read;
|
|
|
|
|
|
|
|
ret = spl_load_imx_container(spl_image, &load, sector);
|
2016-03-16 03:10:00 +00:00
|
|
|
} else {
|
2022-01-14 13:31:38 +00:00
|
|
|
ret = mmc_load_legacy(spl_image, bootdev, mmc, sector, header);
|
2015-06-23 21:38:47 +00:00
|
|
|
}
|
2013-06-28 18:43:01 +00:00
|
|
|
|
2011-09-14 19:33:34 +00:00
|
|
|
end:
|
2016-02-23 05:55:58 +00:00
|
|
|
if (ret) {
|
2013-09-04 15:12:24 +00:00
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
2016-04-21 02:12:04 +00:00
|
|
|
puts("mmc_load_image_raw_sector: mmc block read error\n");
|
2013-09-04 15:12:24 +00:00
|
|
|
#endif
|
2015-05-22 10:45:35 +00:00
|
|
|
return -1;
|
2015-06-03 16:48:51 +00:00
|
|
|
}
|
2015-05-22 10:45:35 +00:00
|
|
|
|
|
|
|
return 0;
|
2011-09-14 19:33:34 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 07:52:36 +00:00
|
|
|
static int spl_mmc_get_device_index(u32 boot_device)
|
2015-11-08 15:11:54 +00:00
|
|
|
{
|
|
|
|
switch (boot_device) {
|
|
|
|
case BOOT_DEVICE_MMC1:
|
|
|
|
return 0;
|
|
|
|
case BOOT_DEVICE_MMC2:
|
|
|
|
case BOOT_DEVICE_MMC2_2:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
|
|
|
printf("spl: unsupported mmc boot device.\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2015-12-02 17:59:12 +00:00
|
|
|
static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
|
2015-11-08 15:11:44 +00:00
|
|
|
{
|
2015-11-08 15:11:54 +00:00
|
|
|
int err, mmc_dev;
|
|
|
|
|
|
|
|
mmc_dev = spl_mmc_get_device_index(boot_device);
|
|
|
|
if (mmc_dev < 0)
|
|
|
|
return mmc_dev;
|
2015-11-08 15:11:44 +00:00
|
|
|
|
2019-09-09 09:10:36 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_MMC)
|
|
|
|
err = mmc_init_device(mmc_dev);
|
|
|
|
#else
|
2015-11-08 15:11:44 +00:00
|
|
|
err = mmc_initialize(NULL);
|
2019-09-09 09:10:36 +00:00
|
|
|
#endif /* DM_MMC */
|
2015-11-08 15:11:44 +00:00
|
|
|
if (err) {
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
|
|
|
printf("spl: could not initialize mmc. error: %d\n", err);
|
|
|
|
#endif
|
|
|
|
return err;
|
|
|
|
}
|
2015-12-02 17:59:13 +00:00
|
|
|
*mmcp = find_mmc_device(mmc_dev);
|
|
|
|
err = *mmcp ? 0 : -ENODEV;
|
2015-11-08 15:11:44 +00:00
|
|
|
if (err) {
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
2018-09-18 08:11:55 +00:00
|
|
|
printf("spl: could not find mmc device %d. error: %d\n",
|
|
|
|
mmc_dev, err);
|
2015-11-08 15:11:44 +00:00
|
|
|
#endif
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-11 01:15:35 +00:00
|
|
|
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
|
2016-09-25 00:20:13 +00:00
|
|
|
static int mmc_load_image_raw_partition(struct spl_image_info *spl_image,
|
2022-01-14 13:31:38 +00:00
|
|
|
struct spl_boot_device *bootdev,
|
2019-06-04 22:55:46 +00:00
|
|
|
struct mmc *mmc, int partition,
|
|
|
|
unsigned long sector)
|
2014-11-08 22:14:56 +00:00
|
|
|
{
|
2020-05-10 17:39:57 +00:00
|
|
|
struct disk_partition info;
|
2015-05-22 10:45:35 +00:00
|
|
|
int err;
|
2014-11-08 22:14:56 +00:00
|
|
|
|
2017-02-11 01:15:34 +00:00
|
|
|
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE
|
|
|
|
int type_part;
|
|
|
|
/* Only support MBR so DOS_ENTRY_NUMBERS */
|
|
|
|
for (type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) {
|
|
|
|
err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info);
|
|
|
|
if (err)
|
|
|
|
continue;
|
2021-09-27 15:42:38 +00:00
|
|
|
if (info.sys_ind ==
|
2017-02-11 01:15:34 +00:00
|
|
|
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE) {
|
|
|
|
partition = type_part;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-07-05 23:10:18 +00:00
|
|
|
err = part_get_info(mmc_get_blk_desc(mmc), partition, &info);
|
2015-05-22 10:45:35 +00:00
|
|
|
if (err) {
|
2014-11-08 22:14:56 +00:00
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
2015-06-03 16:48:51 +00:00
|
|
|
puts("spl: partition error\n");
|
2014-11-08 22:14:56 +00:00
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-11-16 17:19:05 +00:00
|
|
|
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
|
2022-01-14 13:31:38 +00:00
|
|
|
return mmc_load_image_raw_sector(spl_image, bootdev, mmc, info.start + sector);
|
2015-07-20 09:20:39 +00:00
|
|
|
#else
|
2022-01-14 13:31:38 +00:00
|
|
|
return mmc_load_image_raw_sector(spl_image, bootdev, mmc, info.start);
|
2015-07-20 09:20:39 +00:00
|
|
|
#endif
|
2014-11-08 22:14:56 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-12-30 16:39:59 +00:00
|
|
|
#if CONFIG_IS_ENABLED(FALCON_BOOT_MMCSD)
|
2016-09-25 00:20:13 +00:00
|
|
|
static int mmc_load_image_raw_os(struct spl_image_info *spl_image,
|
2022-01-14 13:31:38 +00:00
|
|
|
struct spl_boot_device *bootdev,
|
2016-09-25 00:20:13 +00:00
|
|
|
struct mmc *mmc)
|
2013-05-13 08:36:29 +00:00
|
|
|
{
|
2016-04-11 09:54:50 +00:00
|
|
|
int ret;
|
2015-04-27 08:20:22 +00:00
|
|
|
|
2023-08-08 13:42:15 +00:00
|
|
|
#if defined(CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR)
|
2018-06-26 16:44:39 +00:00
|
|
|
unsigned long count;
|
|
|
|
|
2016-06-13 05:30:32 +00:00
|
|
|
count = blk_dread(mmc_get_blk_desc(mmc),
|
2015-05-22 10:45:35 +00:00
|
|
|
CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR,
|
|
|
|
CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS,
|
2023-09-26 14:14:17 +00:00
|
|
|
(void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR);
|
2017-08-15 01:01:30 +00:00
|
|
|
if (count != CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS) {
|
2013-09-04 15:12:24 +00:00
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
2016-04-21 02:12:04 +00:00
|
|
|
puts("mmc_load_image_raw_os: mmc block read error\n");
|
2013-09-04 15:12:24 +00:00
|
|
|
#endif
|
2013-05-13 08:36:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2018-06-26 16:44:39 +00:00
|
|
|
#endif /* CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR */
|
2013-05-13 08:36:29 +00:00
|
|
|
|
2022-01-14 13:31:38 +00:00
|
|
|
ret = mmc_load_image_raw_sector(spl_image, bootdev, mmc,
|
2015-04-27 08:20:22 +00:00
|
|
|
CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR);
|
2016-04-11 09:54:50 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2021-07-15 19:19:23 +00:00
|
|
|
if (spl_image->os != IH_OS_LINUX && spl_image->os != IH_OS_TEE) {
|
2023-05-17 07:17:16 +00:00
|
|
|
puts("Expected image is not found. Trying to start U-Boot\n");
|
2016-04-11 09:54:50 +00:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2013-05-13 08:36:29 +00:00
|
|
|
}
|
2015-11-08 15:11:45 +00:00
|
|
|
#else
|
2016-09-25 00:20:13 +00:00
|
|
|
static int mmc_load_image_raw_os(struct spl_image_info *spl_image,
|
2022-01-14 13:31:38 +00:00
|
|
|
struct spl_boot_device *bootdev,
|
2016-09-25 00:20:13 +00:00
|
|
|
struct mmc *mmc)
|
2015-11-08 15:11:45 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2013-05-13 08:36:29 +00:00
|
|
|
#endif
|
|
|
|
|
2021-12-30 16:39:59 +00:00
|
|
|
#ifndef CONFIG_SPL_OS_BOOT
|
|
|
|
int spl_start_uboot(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-01-21 14:13:08 +00:00
|
|
|
#ifdef CONFIG_SYS_MMCSD_FS_BOOT
|
2022-01-14 13:31:38 +00:00
|
|
|
static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev,
|
|
|
|
struct mmc *mmc,
|
2019-06-04 22:55:46 +00:00
|
|
|
const char *filename)
|
2015-11-08 15:11:47 +00:00
|
|
|
{
|
|
|
|
int err = -ENOSYS;
|
|
|
|
|
2022-03-15 20:34:51 +00:00
|
|
|
__maybe_unused int partition = CONFIG_SYS_MMCSD_FS_BOOT_PARTITION;
|
|
|
|
|
|
|
|
#if CONFIG_SYS_MMCSD_FS_BOOT_PARTITION == -1
|
|
|
|
{
|
|
|
|
struct disk_partition info;
|
|
|
|
debug("Checking for the first MBR bootable partition\n");
|
|
|
|
for (int type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) {
|
|
|
|
err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info);
|
|
|
|
if (err)
|
|
|
|
continue;
|
|
|
|
debug("Partition %d is of type %d and bootable=%d\n", type_part, info.sys_ind, info.bootable);
|
|
|
|
if (info.bootable != 0) {
|
|
|
|
debug("Partition %d is bootable, using it\n", type_part);
|
|
|
|
partition = type_part;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("Using first bootable partition: %d\n", partition);
|
|
|
|
if (partition == CONFIG_SYS_MMCSD_FS_BOOT_PARTITION) {
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-01-23 06:20:03 +00:00
|
|
|
#ifdef CONFIG_SPL_FS_FAT
|
2015-11-08 15:11:47 +00:00
|
|
|
if (!spl_start_uboot()) {
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_load_image_fat_os(spl_image, bootdev, mmc_get_blk_desc(mmc),
|
2022-03-15 20:34:51 +00:00
|
|
|
partition);
|
2015-11-08 15:11:47 +00:00
|
|
|
if (!err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_load_image_fat(spl_image, bootdev, mmc_get_blk_desc(mmc),
|
2022-03-15 20:34:51 +00:00
|
|
|
partition,
|
2019-06-04 22:55:46 +00:00
|
|
|
filename);
|
2015-11-08 15:11:47 +00:00
|
|
|
if (!err)
|
|
|
|
return err;
|
|
|
|
#endif
|
|
|
|
#endif
|
2019-01-23 06:20:05 +00:00
|
|
|
#ifdef CONFIG_SPL_FS_EXT4
|
2015-11-08 15:11:47 +00:00
|
|
|
if (!spl_start_uboot()) {
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_load_image_ext_os(spl_image, bootdev, mmc_get_blk_desc(mmc),
|
2022-03-15 20:34:51 +00:00
|
|
|
partition);
|
2015-11-08 15:11:47 +00:00
|
|
|
if (!err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_load_image_ext(spl_image, bootdev, mmc_get_blk_desc(mmc),
|
2022-03-15 20:34:51 +00:00
|
|
|
partition,
|
2019-06-04 22:55:46 +00:00
|
|
|
filename);
|
2015-11-08 15:11:47 +00:00
|
|
|
if (!err)
|
|
|
|
return err;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2019-01-23 06:20:05 +00:00
|
|
|
#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
|
2015-11-08 15:11:47 +00:00
|
|
|
err = -ENOENT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-07-12 10:06:49 +00:00
|
|
|
u32 __weak spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
|
2018-02-03 07:29:52 +00:00
|
|
|
{
|
2019-01-23 06:20:05 +00:00
|
|
|
#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
|
2018-02-03 07:29:52 +00:00
|
|
|
return MMCSD_MODE_FS;
|
|
|
|
#elif defined(CONFIG_SUPPORT_EMMC_BOOT)
|
|
|
|
return MMCSD_MODE_EMMCBOOT;
|
|
|
|
#else
|
|
|
|
return MMCSD_MODE_RAW;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-03-20 09:54:51 +00:00
|
|
|
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
|
2020-04-15 09:33:31 +00:00
|
|
|
int __weak spl_mmc_boot_partition(const u32 boot_device)
|
2018-03-20 09:54:51 +00:00
|
|
|
{
|
|
|
|
return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-10-16 16:16:12 +00:00
|
|
|
unsigned long __weak arch_spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
|
|
|
|
unsigned long raw_sect)
|
|
|
|
{
|
|
|
|
return raw_sect;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long __weak board_spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
|
|
|
|
unsigned long raw_sect)
|
|
|
|
{
|
|
|
|
return arch_spl_mmc_get_uboot_raw_sector(mmc, raw_sect);
|
|
|
|
}
|
|
|
|
|
2020-02-26 08:14:35 +00:00
|
|
|
unsigned long __weak spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
|
|
|
|
unsigned long raw_sect)
|
2019-09-23 02:18:40 +00:00
|
|
|
{
|
2023-10-16 16:16:12 +00:00
|
|
|
return board_spl_mmc_get_uboot_raw_sector(mmc, raw_sect);
|
2019-09-23 02:18:40 +00:00
|
|
|
}
|
|
|
|
|
2021-07-03 02:55:32 +00:00
|
|
|
int default_spl_mmc_emmc_boot_partition(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
int part;
|
|
|
|
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_EMMC_BOOT_PARTITION
|
|
|
|
part = CONFIG_SYS_MMCSD_RAW_MODE_EMMC_BOOT_PARTITION;
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* We need to check what the partition is configured to.
|
|
|
|
* 1 and 2 match up to boot0 / boot1 and 7 is user data
|
|
|
|
* which is the first physical partition (0).
|
|
|
|
*/
|
2023-03-11 10:44:27 +00:00
|
|
|
part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
|
2021-07-03 02:55:32 +00:00
|
|
|
if (part == 7)
|
|
|
|
part = 0;
|
|
|
|
#endif
|
|
|
|
return part;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __weak spl_mmc_emmc_boot_partition(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
return default_spl_mmc_emmc_boot_partition(mmc);
|
|
|
|
}
|
|
|
|
|
2022-07-11 12:35:32 +00:00
|
|
|
static int spl_mmc_get_mmc_devnum(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
struct blk_desc *block_dev;
|
|
|
|
#if !CONFIG_IS_ENABLED(BLK)
|
|
|
|
block_dev = &mmc->block_dev;
|
|
|
|
#else
|
2023-10-08 01:47:48 +00:00
|
|
|
block_dev = mmc_get_blk_desc(mmc);
|
2022-07-11 12:35:32 +00:00
|
|
|
#endif
|
|
|
|
return block_dev->devnum;
|
|
|
|
}
|
|
|
|
|
2023-10-14 20:47:54 +00:00
|
|
|
static struct mmc *mmc;
|
|
|
|
|
|
|
|
void spl_mmc_clear_cache(void)
|
|
|
|
{
|
|
|
|
mmc = NULL;
|
|
|
|
}
|
|
|
|
|
2019-06-04 22:55:46 +00:00
|
|
|
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)
|
2011-09-14 19:33:34 +00:00
|
|
|
{
|
|
|
|
u32 boot_mode;
|
2015-06-23 21:38:51 +00:00
|
|
|
int err = 0;
|
2020-01-15 07:08:08 +00:00
|
|
|
__maybe_unused int part = 0;
|
2022-07-11 12:35:32 +00:00
|
|
|
int mmc_dev;
|
2011-09-14 19:33:34 +00:00
|
|
|
|
2022-07-11 12:35:32 +00:00
|
|
|
/* Perform peripheral init only once for an mmc device */
|
|
|
|
mmc_dev = spl_mmc_get_device_index(bootdev->boot_device);
|
|
|
|
if (!mmc || spl_mmc_get_mmc_devnum(mmc) != mmc_dev) {
|
2019-06-04 22:55:46 +00:00
|
|
|
err = spl_mmc_find_device(&mmc, bootdev->boot_device);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2011-09-14 19:33:34 +00:00
|
|
|
|
2019-06-04 22:55:46 +00:00
|
|
|
err = mmc_init(mmc);
|
|
|
|
if (err) {
|
|
|
|
mmc = NULL;
|
2013-09-04 15:12:24 +00:00
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
2019-06-04 22:55:46 +00:00
|
|
|
printf("spl: mmc init failed with error: %d\n", err);
|
2013-09-04 15:12:24 +00:00
|
|
|
#endif
|
2019-06-04 22:55:46 +00:00
|
|
|
return err;
|
|
|
|
}
|
2011-09-14 19:33:34 +00:00
|
|
|
}
|
2013-05-13 08:36:25 +00:00
|
|
|
|
2021-07-12 10:06:49 +00:00
|
|
|
boot_mode = spl_mmc_boot_mode(mmc, bootdev->boot_device);
|
2015-11-08 15:11:49 +00:00
|
|
|
err = -EINVAL;
|
2015-04-27 08:20:22 +00:00
|
|
|
switch (boot_mode) {
|
2015-11-08 15:11:48 +00:00
|
|
|
case MMCSD_MODE_EMMCBOOT:
|
2021-07-03 02:55:32 +00:00
|
|
|
part = spl_mmc_emmc_boot_partition(mmc);
|
2019-09-03 14:17:17 +00:00
|
|
|
|
|
|
|
if (CONFIG_IS_ENABLED(MMC_TINY))
|
|
|
|
err = mmc_switch_part(mmc, part);
|
|
|
|
else
|
|
|
|
err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part);
|
|
|
|
|
|
|
|
if (err) {
|
2015-11-08 15:11:48 +00:00
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
2019-09-03 14:17:17 +00:00
|
|
|
puts("spl: mmc partition switch failed\n");
|
2015-11-08 15:11:48 +00:00
|
|
|
#endif
|
2019-09-03 14:17:17 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
/* Fall through */
|
2015-04-27 08:20:22 +00:00
|
|
|
case MMCSD_MODE_RAW:
|
|
|
|
debug("spl: mmc boot mode: raw\n");
|
|
|
|
|
|
|
|
if (!spl_start_uboot()) {
|
2022-01-14 13:31:38 +00:00
|
|
|
err = mmc_load_image_raw_os(spl_image, bootdev, mmc);
|
2015-04-27 08:20:22 +00:00
|
|
|
if (!err)
|
2015-11-08 15:11:49 +00:00
|
|
|
return err;
|
2015-04-27 08:20:22 +00:00
|
|
|
}
|
2019-10-23 01:43:30 +00:00
|
|
|
|
2020-02-26 08:14:35 +00:00
|
|
|
raw_sect = spl_mmc_get_uboot_raw_sector(mmc, raw_sect);
|
2019-10-23 01:43:30 +00:00
|
|
|
|
2017-02-11 01:15:35 +00:00
|
|
|
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
|
2022-01-14 13:31:38 +00:00
|
|
|
err = mmc_load_image_raw_partition(spl_image, bootdev,
|
|
|
|
mmc, raw_part,
|
2019-06-04 22:55:46 +00:00
|
|
|
raw_sect);
|
2015-06-08 21:05:09 +00:00
|
|
|
if (!err)
|
2015-11-08 15:11:49 +00:00
|
|
|
return err;
|
2017-02-11 01:15:35 +00:00
|
|
|
#endif
|
2016-11-16 17:19:05 +00:00
|
|
|
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
|
2022-01-14 13:31:38 +00:00
|
|
|
err = mmc_load_image_raw_sector(spl_image, bootdev, mmc,
|
2020-01-15 07:08:08 +00:00
|
|
|
raw_sect + spl_mmc_raw_uboot_offset(part));
|
2015-04-27 08:20:22 +00:00
|
|
|
if (!err)
|
2015-11-08 15:11:49 +00:00
|
|
|
return err;
|
2015-06-08 21:05:09 +00:00
|
|
|
#endif
|
2016-02-18 17:17:36 +00:00
|
|
|
/* If RAW mode fails, try FS mode. */
|
2023-01-21 14:13:08 +00:00
|
|
|
#ifdef CONFIG_SYS_MMCSD_FS_BOOT
|
2015-04-27 08:20:22 +00:00
|
|
|
case MMCSD_MODE_FS:
|
|
|
|
debug("spl: mmc boot mode: fs\n");
|
|
|
|
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_mmc_do_fs_boot(spl_image, bootdev, mmc, filename);
|
2015-04-27 08:20:22 +00:00
|
|
|
if (!err)
|
2015-11-08 15:11:49 +00:00
|
|
|
return err;
|
2015-11-08 15:11:47 +00:00
|
|
|
|
2015-11-08 15:11:43 +00:00
|
|
|
break;
|
2023-01-21 14:13:08 +00:00
|
|
|
#endif
|
2013-09-04 15:12:24 +00:00
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
2015-11-08 15:11:43 +00:00
|
|
|
default:
|
|
|
|
puts("spl: mmc: wrong boot mode\n");
|
2013-09-04 15:12:24 +00:00
|
|
|
#endif
|
2015-04-27 08:20:22 +00:00
|
|
|
}
|
2015-11-08 15:11:43 +00:00
|
|
|
|
2015-11-08 15:11:49 +00:00
|
|
|
return err;
|
2011-09-14 19:33:34 +00:00
|
|
|
}
|
2016-09-25 00:20:00 +00:00
|
|
|
|
2019-06-04 22:55:46 +00:00
|
|
|
int spl_mmc_load_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev)
|
|
|
|
{
|
|
|
|
return spl_mmc_load(spl_image, bootdev,
|
|
|
|
#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
|
|
|
|
CONFIG_SPL_FS_LOAD_PAYLOAD_NAME,
|
|
|
|
#else
|
|
|
|
NULL,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
|
2020-04-15 09:33:31 +00:00
|
|
|
spl_mmc_boot_partition(bootdev->boot_device),
|
2019-06-04 22:55:46 +00:00
|
|
|
#else
|
|
|
|
0,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
|
|
|
|
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
|
|
|
|
#else
|
|
|
|
0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-11-30 22:30:50 +00:00
|
|
|
SPL_LOAD_IMAGE_METHOD("MMC1", 0, BOOT_DEVICE_MMC1, spl_mmc_load_image);
|
|
|
|
SPL_LOAD_IMAGE_METHOD("MMC2", 0, BOOT_DEVICE_MMC2, spl_mmc_load_image);
|
|
|
|
SPL_LOAD_IMAGE_METHOD("MMC2_2", 0, BOOT_DEVICE_MMC2_2, spl_mmc_load_image);
|