mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Rouven Czerwinski <r.czerwinski@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Subject: [PATCH v3 05/16] esdhc-pbl: extract header parsing from image start
Date: Tue,  6 Aug 2019 07:10:55 +0200	[thread overview]
Message-ID: <cbc4bb1562ac44ec2fd00f9694e9357ab0342831.1565068235.git-series.r.czerwinski@pengutronix.de> (raw)
In-Reply-To: <cover.20f706d0d5a7ead5c114378becb025aefb9c7b8a.1565068235.git-series.r.czerwinski@pengutronix.de>

Extract the header parsing code from esdc_start_image. The header
parsing function will be used by the piggy loading code added in the
next commit.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 drivers/mci/imx-esdhc-pbl.c | 44 +++++++++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 14 deletions(-)

diff --git a/drivers/mci/imx-esdhc-pbl.c b/drivers/mci/imx-esdhc-pbl.c
index 367daa8..49514fc 100644
--- a/drivers/mci/imx-esdhc-pbl.c
+++ b/drivers/mci/imx-esdhc-pbl.c
@@ -243,27 +243,22 @@ static int esdhc_read_blocks(struct esdhc *esdhc, void *dst, size_t len)
 }
 
 #ifdef CONFIG_ARCH_IMX
-static int
-esdhc_start_image(struct esdhc *esdhc, ptrdiff_t address, ptrdiff_t entry, u32 offset)
+static int esdhc_search_header(struct esdhc *esdhc,
+			       struct imx_flash_header_v2 **header_pointer,
+			       void *buffer, u32 *offset)
 {
-
-	void *buf = (void *)address;
-	struct imx_flash_header_v2 *hdr;
-	int ret, len;
-	void __noreturn (*bb)(void);
-	unsigned int ofs;
+	int ret;
 	int i, header_count = 1;
-
-	len = imx_image_size();
-	len = ALIGN(len, SECTOR_SIZE);
+	void *buf = buffer;
+	struct imx_flash_header_v2 *hdr;
 
 	for (i = 0; i < header_count; i++) {
 		ret = esdhc_read_blocks(esdhc, buf,
-					offset + SZ_1K + SECTOR_SIZE);
+					*offset + SZ_1K + SECTOR_SIZE);
 		if (ret)
 			return ret;
 
-		hdr = buf + offset + SZ_1K;
+		hdr = buf + *offset + SZ_1K;
 
 		if (!is_imx_flash_header_v2(hdr)) {
 			pr_debug("IVT header not found on SD card. "
@@ -286,10 +281,31 @@ esdhc_start_image(struct esdhc *esdhc, ptrdiff_t address, ptrdiff_t entry, u32 o
 			 * this time skipping anything HDMI firmware
 			 * related.
 			 */
-			offset += hdr->boot_data.size + hdr->header.length;
+			*offset += hdr->boot_data.size + hdr->header.length;
 			header_count++;
 		}
 	}
+	*header_pointer = hdr;
+	return 0;
+}
+
+static int
+esdhc_start_image(struct esdhc *esdhc, ptrdiff_t address, ptrdiff_t entry,
+		  u32 offset)
+{
+
+	void *buf = (void *)address;
+	struct imx_flash_header_v2 *hdr = NULL;
+	int ret, len;
+	void __noreturn (*bb)(void);
+	unsigned int ofs;
+
+	len = imx_image_size();
+	len = ALIGN(len, SECTOR_SIZE);
+
+	ret = esdhc_search_header(esdhc, &hdr, buf, &offset);
+	if (ret)
+		return ret;
 
 	pr_debug("Check ok, loading image\n");
 
-- 
git-series 0.9.1

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2019-08-06  5:11 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06  5:10 [PATCH v3 00/16] HAB for i.MX8MQ Rouven Czerwinski
2019-08-06  5:10 ` [PATCH v3 01/16] i.MX: HABv4: ignore return for i.MX28/6 initcalls Rouven Czerwinski
2019-08-06  5:10 ` [PATCH v3 02/16] i.MX: HABv4: implement interface for i.MX8MQ Rouven Czerwinski
2019-08-06  5:10 ` [PATCH v3 03/16] mach-imx: enable HAB on i.MX8MQ Rouven Czerwinski
2019-08-06  5:10 ` [PATCH v3 04/16] arm: lib: add CSF section between PBL and piggy Rouven Czerwinski
2019-08-06  5:10 ` Rouven Czerwinski [this message]
2019-08-06  5:10 ` [PATCH v3 06/16] esdhc-pbl: add piggy load function Rouven Czerwinski
2019-08-06  5:10 ` [PATCH v3 07/16] sections: fix macro for barebox_pbl_size Rouven Czerwinski
2019-08-06  5:10 ` [PATCH v3 08/16] scripts: imx: support signing for i.MX8MQ Rouven Czerwinski
2019-08-06  5:10 ` [PATCH v3 09/16] images: always build sha256sum into pbl Rouven Czerwinski
2019-08-06  5:11 ` [PATCH v3 10/16] pbl: add sha256 and piggy verification to PBL Rouven Czerwinski
2019-08-06  8:16   ` Lucas Stach
2019-08-06 13:21   ` [PATCH] fixup! " r.czerwinski
2019-08-06  5:11 ` [PATCH v3 11/16] stdio: puts and putchar static inline wrappers Rouven Czerwinski
2019-08-06  5:11 ` [PATCH v3 12/16] pbl: support panic with log output Rouven Czerwinski
2019-08-06  5:11 ` [PATCH v3 13/16] arm: uncompress: verify sha256 if enabled Rouven Czerwinski
2019-08-06  5:11 ` [PATCH v3 14/16] mach-imx: add gencsf header for i.MX8MQ Rouven Czerwinski
2019-08-06  5:11 ` [PATCH v3 15/16] mach-imx: hab: select piggy verification for i.MX8 Rouven Czerwinski
2019-08-06  5:11 ` [PATCH v3 16/16] boards: nxp-mx8-evk: rework to different boot flow Rouven Czerwinski
2019-08-08  6:21 ` [PATCH v3 00/16] HAB for i.MX8MQ Sascha Hauer
2019-08-08  6:51   ` Rouven Czerwinski
2019-08-08  7:43     ` 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=cbc4bb1562ac44ec2fd00f9694e9357ab0342831.1565068235.git-series.r.czerwinski@pengutronix.de \
    --to=r.czerwinski@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