mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 06/21] mci: imx-esdhc-pbl: refactor the esdhc_load_image function
Date: Thu, 09 Mar 2023 11:40:38 +0100	[thread overview]
Message-ID: <20230228-v2023-02-0-topic-flexspi-v1-6-7b3c3fa295f5@pengutronix.de> (raw)
In-Reply-To: <20230228-v2023-02-0-topic-flexspi-v1-0-7b3c3fa295f5@pengutronix.de>

Loading a i.MX image always invovles a IVT and DCD header. The header
detection and verification can be reused by other boot mediums as well.
The only hardware dependencies are the custom read() implementations and
possible alignments. This commit is in preparation of adding QSPI boot
support.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/mci/imx-esdhc-pbl.c | 42 ++++++++++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 12 deletions(-)

diff --git a/drivers/mci/imx-esdhc-pbl.c b/drivers/mci/imx-esdhc-pbl.c
index 0b6ab9b5d0..4884a68837 100644
--- a/drivers/mci/imx-esdhc-pbl.c
+++ b/drivers/mci/imx-esdhc-pbl.c
@@ -104,9 +104,13 @@ 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, u32 ivt_offset)
+#define HDR_SIZE	512
+
+static int
+imx_search_header(struct imx_flash_header_v2 **header_pointer,
+		  void *buffer, u32 *offset, u32 ivt_offset,
+		  int (*read)(void *dest, size_t len, void *priv),
+		  void *priv)
 {
 	int ret;
 	int i, header_count = 1;
@@ -114,15 +118,14 @@ static int esdhc_search_header(struct fsl_esdhc_host *host,
 	struct imx_flash_header_v2 *hdr;
 
 	for (i = 0; i < header_count; i++) {
-		ret = esdhc_read_blocks(host, buf,
-					*offset + ivt_offset + SECTOR_SIZE);
+		ret = read(buf, *offset + ivt_offset + HDR_SIZE, priv);
 		if (ret)
 			return ret;
 
 		hdr = buf + *offset + ivt_offset;
 
 		if (!is_imx_flash_header_v2(hdr)) {
-			pr_debug("IVT header not found on SD card. "
+			pr_debug("No IVT header! "
 				 "Found tag: 0x%02x length: 0x%04x "
 				 "version: %02x\n",
 				 hdr->header.tag, hdr->header.length,
@@ -150,9 +153,10 @@ static int esdhc_search_header(struct fsl_esdhc_host *host,
 	return 0;
 }
 
-static int
-esdhc_load_image(struct fsl_esdhc_host *host, ptrdiff_t address,
-		 ptrdiff_t entry, u32 offset, u32 ivt_offset, bool start)
+int imx_load_image(ptrdiff_t address, ptrdiff_t entry, u32 offset,
+		   u32 ivt_offset, bool start, unsigned int alignment,
+		   int (*read)(void *dest, size_t len, void *priv),
+		   void *priv)
 {
 
 	void *buf = (void *)address;
@@ -162,9 +166,10 @@ esdhc_load_image(struct fsl_esdhc_host *host, ptrdiff_t address,
 	unsigned int ofs;
 
 	len = imx_image_size();
-	len = ALIGN(len, SECTOR_SIZE);
+	if (alignment)
+		len = ALIGN(len, alignment);
 
-	ret = esdhc_search_header(host, &hdr, buf, &offset, ivt_offset);
+	ret = imx_search_header(&hdr, buf, &offset, ivt_offset, read, priv);
 	if (ret)
 		return ret;
 
@@ -199,7 +204,7 @@ esdhc_load_image(struct fsl_esdhc_host *host, ptrdiff_t address,
 		buf = (void *)(entry - ofs);
 	}
 
-	ret = esdhc_read_blocks(host, buf, ofs + len);
+	ret = read(buf, ofs + len, priv);
 	if (ret) {
 		pr_err("Loading image failed with %d\n", ret);
 		return ret;
@@ -217,6 +222,19 @@ esdhc_load_image(struct fsl_esdhc_host *host, ptrdiff_t address,
 	bb();
 }
 
+static int imx_read_blocks(void *dest, size_t len, void *priv)
+{
+	return esdhc_read_blocks(priv, dest, len);
+}
+
+static int
+esdhc_load_image(struct fsl_esdhc_host *host, ptrdiff_t address,
+		 ptrdiff_t entry, u32 offset, u32 ivt_offset, bool start)
+{
+	return imx_load_image(address, entry, offset, ivt_offset, start,
+			      SECTOR_SIZE, imx_read_blocks, host);
+}
+
 static void imx_esdhc_init(struct fsl_esdhc_host *host,
 			   struct esdhc_soc_data *data)
 {

-- 
2.30.2




  parent reply	other threads:[~2023-03-09 10:42 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09 10:40 [PATCH 00/21] FlexSPI image/boot/update support Marco Felsch
2023-03-09 10:40 ` [PATCH 01/21] spi: remove flash_platform_data support Marco Felsch
2023-03-09 10:40 ` [PATCH 02/21] bbu: make it possible to check multiple of-compatibles Marco Felsch
2023-03-09 10:40 ` [PATCH 03/21] ARM: i.MX8MM: add missing IMD_USED_OF image metadata entry Marco Felsch
2023-03-09 10:40 ` [PATCH 04/21] ARM: i.MX8MN: add missing IMD_USED_OF image metadata entries Marco Felsch
2023-03-09 10:40 ` [PATCH 05/21] mci: imx-esdhc-pbl: fix number of read blocks Marco Felsch
2023-03-09 10:40 ` Marco Felsch [this message]
2023-03-09 10:40 ` [PATCH 07/21] mci: imx-esdhc-pbl: move imx_load_image into common xload code Marco Felsch
2023-03-09 10:40 ` [PATCH 08/21] ARM: i.MX8M: Add QSPI image load support Marco Felsch
2023-03-09 10:40 ` [PATCH 09/21] ARM: i.MX8MM bootsource: fix QSPI boot source detection Marco Felsch
2023-03-09 10:40 ` [PATCH 10/21] ARM: i.MX8M: Add QSPI boot support Marco Felsch
2023-03-09 10:40 ` [PATCH 11/21] scripts: imx-image: convert flag variables into bool Marco Felsch
2023-03-09 10:40 ` [PATCH 12/21] scripts: imx-image: header_v2: factor out offset parameter Marco Felsch
2023-03-09 10:40 ` [PATCH 13/21] scripts: imx-image: header_v2: add header_len parameter Marco Felsch
2023-03-09 10:40 ` [PATCH 14/21] scripts: imx-image: add FlexSPI image support Marco Felsch
2023-03-09 10:40 ` [PATCH 15/21] filetype: add NXP FlexSPI filetype Marco Felsch
2023-03-09 10:40 ` [PATCH 16/21] ARM: i.MX: bbu: rename IMX_INTERNAL_FLAG_ERASE to IMX_BBU_FLAG_ERASE Marco Felsch
2023-03-09 10:40 ` [PATCH 17/21] ARM: i.MX: bbu: add target device offset Marco Felsch
2023-03-09 10:40 ` [PATCH 18/21] ARM: i.MX: bbu: add FlexSPI update handler Marco Felsch
2023-03-09 10:40 ` [PATCH 19/21] ARM: i.MX8M: enable FlexSPI image support Marco Felsch
2023-03-09 10:40 ` [PATCH 20/21] ARM: i.MX8M: add qspi barebox and barebox-environment partitions Marco Felsch
2023-03-09 10:40 ` [PATCH 21/21] ARM: i.MX8M: add QSPI update handler Marco Felsch
2023-03-09 11:28 ` [PATCH 00/21] FlexSPI image/boot/update support Ahmad Fatoum
2023-03-09 11:41   ` Marco Felsch

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=20230228-v2023-02-0-topic-flexspi-v1-6-7b3c3fa295f5@pengutronix.de \
    --to=m.felsch@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