From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 16/20] mci: imx-esdhc-pbl: Add imx8mp_esdhc_load_image() for i.MX8MP
Date: Tue, 23 Jun 2020 15:16:02 +0200 [thread overview]
Message-ID: <20200623131606.16316-17-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20200623131606.16316-1-s.hauer@pengutronix.de>
The image format of the i.MX8MP is different from i.MX8M, so add its own
image loading function for it.
Older i.MX SoCs had a IVT Offset (the offset from the start of the image
to the actual data) of 1KiB. This was done to leave space for the
partition table at the beginning of the device. To support GPT SoCs
starting with i.MX8M an additional gap of 32KiB was added, so that the
actual image started at offset 33KiB. Now starting with i.MX8MP the now
superfluous 1KiB offset was removed do that the actual image now starts
at 32KiB.
Unfortunately the 1KiB offset is woven into the offsets of the IVT
whereas the 32KiB are not, which means that we really have to handle
both offsets individually instead of just handling the sum of the
offsets.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/mach-imx/include/mach/xload.h | 1 +
drivers/mci/imx-esdhc-pbl.c | 42 +++++++++++++++++++++-----
2 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/arch/arm/mach-imx/include/mach/xload.h b/arch/arm/mach-imx/include/mach/xload.h
index dca05aa5d4..05022e9d09 100644
--- a/arch/arm/mach-imx/include/mach/xload.h
+++ b/arch/arm/mach-imx/include/mach/xload.h
@@ -6,6 +6,7 @@ int imx6_spi_load_image(int instance, unsigned int flash_offset, void *buf, int
int imx6_spi_start_image(int instance);
int imx6_esdhc_start_image(int instance);
int imx8m_esdhc_load_image(int instance, bool start);
+int imx8mp_esdhc_load_image(int instance, bool start);
int imx_image_size(void);
int piggydata_size(void);
diff --git a/drivers/mci/imx-esdhc-pbl.c b/drivers/mci/imx-esdhc-pbl.c
index caaf1ac9b5..5c382bbcc2 100644
--- a/drivers/mci/imx-esdhc-pbl.c
+++ b/drivers/mci/imx-esdhc-pbl.c
@@ -77,7 +77,7 @@ static int esdhc_read_blocks(struct fsl_esdhc_host *host, void *dst, size_t len)
#ifdef CONFIG_ARCH_IMX
static int esdhc_search_header(struct fsl_esdhc_host *host,
struct imx_flash_header_v2 **header_pointer,
- void *buffer, u32 *offset)
+ void *buffer, u32 *offset, u32 ivt_offset)
{
int ret;
int i, header_count = 1;
@@ -86,11 +86,11 @@ static int esdhc_search_header(struct fsl_esdhc_host *host,
for (i = 0; i < header_count; i++) {
ret = esdhc_read_blocks(host, buf,
- *offset + SZ_1K + SECTOR_SIZE);
+ *offset + ivt_offset + SECTOR_SIZE);
if (ret)
return ret;
- hdr = buf + *offset + SZ_1K;
+ hdr = buf + *offset + ivt_offset;
if (!is_imx_flash_header_v2(hdr)) {
pr_debug("IVT header not found on SD card. "
@@ -123,7 +123,7 @@ static int esdhc_search_header(struct fsl_esdhc_host *host,
static int
esdhc_load_image(struct fsl_esdhc_host *host, ptrdiff_t address,
- ptrdiff_t entry, u32 offset, bool start)
+ ptrdiff_t entry, u32 offset, u32 ivt_offset, bool start)
{
void *buf = (void *)address;
@@ -135,7 +135,7 @@ esdhc_load_image(struct fsl_esdhc_host *host, ptrdiff_t address,
len = imx_image_size();
len = ALIGN(len, SECTOR_SIZE);
- ret = esdhc_search_header(host, &hdr, buf, &offset);
+ ret = esdhc_search_header(host, &hdr, buf, &offset, ivt_offset);
if (ret)
return ret;
@@ -262,7 +262,7 @@ int imx6_esdhc_start_image(int instance)
imx_esdhc_init(&host, &data);
- return esdhc_load_image(&host, 0x10000000, 0x10000000, 0, true);
+ return esdhc_load_image(&host, 0x10000000, 0x10000000, 0, SZ_1K, true);
}
/**
@@ -289,7 +289,35 @@ int imx8m_esdhc_load_image(int instance, bool start)
return ret;
return esdhc_load_image(&host, MX8M_DDR_CSD1_BASE_ADDR,
- MX8MQ_ATF_BL33_BASE_ADDR, SZ_32K, start);
+ MX8MQ_ATF_BL33_BASE_ADDR, SZ_32K, SZ_1K,
+ start);
+}
+
+/**
+ * imx8mp_esdhc_load_image - Load and optionally start an image from USDHC controller
+ * @instance: The USDHC controller instance (0..2)
+ * @start: Whether to directly start the loaded image
+ *
+ * This uses esdhc_start_image() to load an image from SD/MMC. It is
+ * assumed that the image is the currently running barebox image (This
+ * information is used to calculate the length of the image). The
+ * image is started afterwards.
+ *
+ * Return: If successful, this function does not return (if directly started)
+ * or 0. A negative error code is returned when this function fails.
+ */
+int imx8mp_esdhc_load_image(int instance, bool start)
+{
+ struct esdhc_soc_data data;
+ struct fsl_esdhc_host host;
+ int ret;
+
+ ret = imx8m_esdhc_init(&host, &data, instance);
+ if (ret)
+ return ret;
+
+ return esdhc_load_image(&host, MX8M_DDR_CSD1_BASE_ADDR,
+ MX8MQ_ATF_BL33_BASE_ADDR, SZ_32K, 0, start);
}
#endif
--
2.27.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2020-06-23 13:16 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-23 13:15 [PATCH 00/20] i.MX8MP support Sascha Hauer
2020-06-23 13:15 ` [PATCH 01/20] scripts: imx-image: Only set DCD pointer when we have DCD data Sascha Hauer
2020-06-23 13:15 ` [PATCH 02/20] scripts: imx-image: exit on read/write failures Sascha Hauer
2020-06-23 13:15 ` [PATCH 03/20] scripts: imx-image: Add extra code path for i.MX35 Sascha Hauer
2020-06-23 13:15 ` [PATCH 04/20] scripts: imx-image: exit with error when barebox header conflicts with IVT Sascha Hauer
2020-06-23 13:15 ` [PATCH 05/20] scripts: imx-image: Fix writing image with IVT offset = 0 Sascha Hauer
2020-06-23 13:15 ` [PATCH 06/20] scripts: imx-image: rename image_dcd_offset to image_ivt_offset Sascha Hauer
2020-06-23 13:15 ` [PATCH 07/20] scripts: imx-image: rename dcdofs to ivtofs Sascha Hauer
2020-06-23 13:15 ` [PATCH 08/20] serial: i.MX: Add i.MX8MP compatible Sascha Hauer
2020-06-23 13:15 ` [PATCH 09/20] pinctrl: imx-iomux-v3: " Sascha Hauer
2020-06-23 13:15 ` [PATCH 10/20] net: fec_imx: add fsl,imx8mp-fec compatible Sascha Hauer
2020-06-23 13:15 ` [PATCH 11/20] mci: imx-esdhc: Add i.MX8mp compatible Sascha Hauer
2020-06-23 13:15 ` [PATCH 12/20] arm: imx: add initial imx8mp support Sascha Hauer
2020-06-23 13:15 ` [PATCH 13/20] scripts: imx-image: Add i.MX8MP support Sascha Hauer
2020-06-23 13:16 ` [PATCH 14/20] mfd: Add pca9440 register map Sascha Hauer
2020-06-23 13:16 ` [PATCH 15/20] clk: imx: Add imx8mp clk driver Sascha Hauer
2020-06-23 13:16 ` Sascha Hauer [this message]
2020-06-23 13:16 ` [PATCH 17/20] net: phy: realtek: handle RX delay setting Sascha Hauer
2020-06-23 13:16 ` [PATCH 18/20] ARM: i.MX: bbu: Fix IVT offset for i.MX8MP Sascha Hauer
2020-06-23 13:16 ` [PATCH 19/20] ARM: i.MX8MP: Add ocotp support Sascha Hauer
2020-06-23 13:16 ` [PATCH 20/20] arm: boards: add initial imx8mp-evk support Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200623131606.16316-17-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox