summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbel Vesa <abel.vesa@nxp.com>2018-09-17 13:18:19 +0300
committerAbel Vesa <abel.vesa@nxp.com>2018-09-18 09:47:48 +0300
commitc70afc348ee9fae242f00be56cde556822f93156 (patch)
treecb716b1b189590cc734c0b1de46c9518820d84c1
parentab8d565f8a57474773d1a86dfa9690dc72d0104d (diff)
MLK-19219-4 iMX8QXP/QM: Add support to get container image set size from QSPI
This transforms almost all related functions from mmc specific to device independent. This allows the container size to be computed from QSPI and other future devices that will be supported for boot. Signed-off-by: Abel Vesa <abel.vesa@nxp.com> Reviewed-by: Ye Li <ye.li@nxp.com>
-rw-r--r--arch/arm/include/asm/arch-imx8/image.h1
-rw-r--r--arch/arm/mach-imx/imx8/image.c84
-rw-r--r--common/spl/spl_spi.c11
3 files changed, 75 insertions, 21 deletions
diff --git a/arch/arm/include/asm/arch-imx8/image.h b/arch/arm/include/asm/arch-imx8/image.h
index ce9c0959f8..2958b49771 100644
--- a/arch/arm/include/asm/arch-imx8/image.h
+++ b/arch/arm/include/asm/arch-imx8/image.h
@@ -8,6 +8,7 @@
#define CONTAINER_HDR_ALIGNMENT 0x400
#define CONTAINER_HDR_MMCSD_OFFSET SZ_32K
+#define CONTAINER_HDR_QSPI_OFFSET SZ_4K
struct container_hdr{
uint8_t version;
diff --git a/arch/arm/mach-imx/imx8/image.c b/arch/arm/mach-imx/imx8/image.c
index 9aaf171119..a274433913 100644
--- a/arch/arm/mach-imx/imx8/image.c
+++ b/arch/arm/mach-imx/imx8/image.c
@@ -8,9 +8,13 @@
#include <asm/io.h>
#include <dm.h>
#include <mmc.h>
+#include <spi_flash.h>
#include <asm/arch/image.h>
-static int get_container_size(ulong addr)
+#define MMC_DEV 0
+#define QSPI_DEV 1
+
+static int __get_container_size(ulong addr)
{
struct container_hdr *phdr;
struct boot_img_t *img_entry;
@@ -50,23 +54,58 @@ static int get_container_size(ulong addr)
return max_offset;
}
-static int mmc_get_imageset_end(struct mmc *mmc)
+static int get_container_size(void *dev, int dev_type, unsigned long offset)
{
- int value_container[2];
- unsigned long count;
uint8_t *buf = malloc(CONTAINER_HDR_ALIGNMENT);
+ unsigned long count = 0;
+ int ret = 0;
+
if (!buf) {
printf("Malloc buffer failed\n");
return -ENOMEM;
}
- count = blk_dread(mmc_get_blk_desc(mmc), CONTAINER_HDR_MMCSD_OFFSET/mmc->read_bl_len, CONTAINER_HDR_ALIGNMENT/mmc->read_bl_len, buf);
- if (count == 0) {
- printf("Read container image from MMC/SD failed\n");
- return -EIO;
+ if (dev_type == MMC_DEV) {
+ struct mmc *mmc = (struct mmc*)dev;
+ count = blk_dread(mmc_get_blk_desc(mmc), offset/mmc->read_bl_len,
+ CONTAINER_HDR_ALIGNMENT/mmc->read_bl_len, buf);
+ if (count == 0) {
+ printf("Read container image from MMC/SD failed\n");
+ return -EIO;
+ }
+#ifdef CONFIG_SPL_SPI_LOAD
+ } else if (dev_type == QSPI_DEV) {
+ struct spi_flash *flash = (struct spi_flash *)dev;
+ ret = spi_flash_read(flash, offset,
+ CONTAINER_HDR_ALIGNMENT, buf);
+ if (ret != 0) {
+ printf("Read container image from QSPI failed\n");
+ return -EIO;
+ }
+#endif
+ }
+
+ ret = __get_container_size((ulong)buf);
+
+ free(buf);
+
+ return ret;
+}
+
+static int get_imageset_end(void *dev, int dev_type)
+{
+ unsigned long offset1 = 0, offset2 = 0;
+ int value_container[2];
+
+ if (dev_type == MMC_DEV) {
+ offset1 = CONTAINER_HDR_MMCSD_OFFSET;
+ offset2 = CONTAINER_HDR_ALIGNMENT + offset1;
+ } else if (dev_type == QSPI_DEV) {
+ offset1 = CONTAINER_HDR_QSPI_OFFSET;
+ offset2 = CONTAINER_HDR_ALIGNMENT + offset1;
}
- value_container[0] = get_container_size((ulong)buf);
+ value_container[0] = get_container_size(dev, dev_type, offset1);
if (value_container[0] < 0) {
printf("Parse seco container failed %d\n", value_container[0]);
return value_container[0];
@@ -74,29 +113,34 @@ static int mmc_get_imageset_end(struct mmc *mmc)
debug("seco container size 0x%x\n", value_container[0]);
- count = blk_dread(mmc_get_blk_desc(mmc), (CONTAINER_HDR_ALIGNMENT + CONTAINER_HDR_MMCSD_OFFSET)/mmc->read_bl_len,
- CONTAINER_HDR_ALIGNMENT/mmc->read_bl_len, buf);
- if (count == 0) {
- printf("Read container image from MMC/SD failed\n");
- return -EIO;
- }
-
- value_container[1] = get_container_size((ulong)buf);
+ value_container[1] = get_container_size(dev, dev_type, offset2);
if (value_container[1] < 0) {
debug("Parse scu container image failed %d, only seco container\n", value_container[1]);
- return value_container[0] + CONTAINER_HDR_MMCSD_OFFSET; /* return seco container total size */
+ return value_container[0] + offset1; /* return seco container total size */
}
debug("scu container size 0x%x\n", value_container[1]);
- return value_container[1] + (CONTAINER_HDR_ALIGNMENT + CONTAINER_HDR_MMCSD_OFFSET);
+ return value_container[1] + offset2;
+}
+
+unsigned long spl_spi_get_uboot_raw_sector(struct spi_flash *flash)
+{
+ int end;
+
+ end = get_imageset_end(flash, QSPI_DEV);
+ end = ROUND(end, SZ_1K);
+
+ printf("Load image from QSPI 0x%x\n", end);
+
+ return end;
}
unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc)
{
int end;
- end = mmc_get_imageset_end(mmc);
+ end = get_imageset_end(mmc, MMC_DEV);
end = ROUND(end, SZ_1K);
printf("Load image from MMC/SD 0x%x\n", end);
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index 42880d56b9..c26896ed65 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -51,6 +51,13 @@ static int spi_load_image_os(struct spl_image_info *spl_image,
}
#endif
+#ifdef CONFIG_SYS_SPI_U_BOOT_OFFS
+unsigned long __weak spl_spi_get_uboot_raw_sector(struct spi_flash *flash)
+{
+ return CONFIG_SYS_SPI_U_BOOT_OFFS;
+}
+#endif
+
static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector,
ulong count, void *buf)
{
@@ -72,7 +79,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev)
{
int err = 0;
- unsigned payload_offs = CONFIG_SYS_SPI_U_BOOT_OFFS;
+ unsigned payload_offs = 0;
struct spi_flash *flash;
struct image_header *header;
@@ -89,6 +96,8 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
return -ENODEV;
}
+ payload_offs = spl_spi_get_uboot_raw_sector(flash);
+
/* use CONFIG_SYS_TEXT_BASE as temporary storage area */
header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);