mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] i.MX5 internal NAND update fixes/cleanup
@ 2014-07-24  6:48 Sascha Hauer
  2014-07-24  6:48 ` [PATCH 1/4] ARM: i.MX5: internal NAND update: Use variable for pre_image_size Sascha Hauer
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-07-24  6:48 UTC (permalink / raw)
  To: barebox

The internal NAND update handler for i.MX5 is broken since:

| commit 15ee30138f59eac95379a4b94c538c1fcc338ed5
| Author: Sascha Hauer <s.hauer@pengutronix.de>
| Date:   Fri Jul 26 10:52:25 2013 +0200
| 
|     ARM: i.MX: bbu-internal: optionally use DCD data from image
|     
|     We used to pass the DCD data from the boards. This patch allows
|     to optionally skip passing DCD data. In this case the DCD data
|     from the flash image is used if present.
|     
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

This fixes it and also cleans up the code a bit.

Sascha

----------------------------------------------------------------
Sascha Hauer (4):
      ARM: i.MX5: internal NAND update: Use variable for pre_image_size
      ARM: i.MX5: internal NAND update: Fix firmware start page for internal nand boot
      ARM: i.MX5: internal NAND update: Use variables for some constants
      ARM: i.MX5: internal NAND update: simplify code

 arch/arm/mach-imx/imx-bbu-internal.c | 63 +++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 34 deletions(-)

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] ARM: i.MX5: internal NAND update: Use variable for pre_image_size
  2014-07-24  6:48 [PATCH] i.MX5 internal NAND update fixes/cleanup Sascha Hauer
@ 2014-07-24  6:48 ` Sascha Hauer
  2014-07-24  6:48 ` [PATCH 2/4] ARM: i.MX5: internal NAND update: Fix firmware start page for internal nand boot Sascha Hauer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-07-24  6:48 UTC (permalink / raw)
  To: barebox

We have the hardcoded value 0x8000 for the space needed for FCB and
DBBT in several places. Use a variable instead and initialize it
correctly with 12 * meminfo.writesize (which is in fact 0x6000 for
2k pagesize).

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/imx-bbu-internal.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index 125415e..ae981e8 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -178,6 +178,7 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler *
 	uint32_t *ptr, *num_bb, *bb;
 	uint64_t offset;
 	int block = 0, len, now, blocksize;
+	int pre_image_size;
 
 	ret = stat(data->devicefile, &s);
 	if (ret)
@@ -193,6 +194,8 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler *
 	if (ret)
 		goto out;
 
+	pre_image_size = 12 * meminfo.writesize;
+
 	blocksize = meminfo.erasesize;
 
 	ptr = image + 0x4;
@@ -218,7 +221,7 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler *
 	bb = ptr + 1;
 	offset = 0;
 
-	size_need = data->len + 0x8000;
+	size_need = data->len + pre_image_size;
 
 	/*
 	 * Collect bad blocks and construct DBBT
@@ -261,18 +264,18 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler *
 	}
 
 	debug("total image size: 0x%08zx. Space needed including bad blocks: 0x%08zx\n",
-			data->len + 0x8000,
-			data->len + 0x8000 + *num_bb * blocksize);
+			data->len + pre_image_size,
+			data->len + pre_image_size + *num_bb * blocksize);
 
-	if (data->len + 0x8000 + *num_bb * blocksize > imx_handler->device_size) {
+	if (data->len + pre_image_size + *num_bb * blocksize > imx_handler->device_size) {
 		printf("needed space (0x%08zx) exceeds partition space (0x%08zx)\n",
-				data->len + 0x8000 + *num_bb * blocksize,
+				data->len + pre_image_size + *num_bb * blocksize,
 				imx_handler->device_size);
 		ret = -ENOSPC;
 		goto out;
 	}
 
-	len = data->len + 0x8000;
+	len = data->len + pre_image_size;
 	offset = 0;
 
 	/*
-- 
2.0.1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] ARM: i.MX5: internal NAND update: Fix firmware start page for internal nand boot
  2014-07-24  6:48 [PATCH] i.MX5 internal NAND update fixes/cleanup Sascha Hauer
  2014-07-24  6:48 ` [PATCH 1/4] ARM: i.MX5: internal NAND update: Use variable for pre_image_size Sascha Hauer
@ 2014-07-24  6:48 ` Sascha Hauer
  2014-07-24  6:48 ` [PATCH 3/4] ARM: i.MX5: internal NAND update: Use variables for some constants Sascha Hauer
  2014-07-24  6:48 ` [PATCH 4/4] ARM: i.MX5: internal NAND update: simplify code Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-07-24  6:48 UTC (permalink / raw)
  To: barebox

Documentation clearly states that the FCB at offset 0x68 has
to contain the start page of the firmware. In our case this
was set to 0x0. I don't know how this could ever work, but it
did, at least until:

15ee301 ARM: i.MX: bbu-internal: optionally use DCD data from image

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/imx-bbu-internal.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index ae981e8..a5cb7e7 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -202,6 +202,9 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler *
 	*ptr++ = FCB_MAGIC;	/* FCB */
 	*ptr++ = 1;		/* FCB version */
 
+	ptr = image + 0x68; /* Firmware start page */
+	*ptr = 12;
+
 	ptr = image + 0x78; /* DBBT start page */
 	*ptr = 4;
 
-- 
2.0.1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] ARM: i.MX5: internal NAND update: Use variables for some constants
  2014-07-24  6:48 [PATCH] i.MX5 internal NAND update fixes/cleanup Sascha Hauer
  2014-07-24  6:48 ` [PATCH 1/4] ARM: i.MX5: internal NAND update: Use variable for pre_image_size Sascha Hauer
  2014-07-24  6:48 ` [PATCH 2/4] ARM: i.MX5: internal NAND update: Fix firmware start page for internal nand boot Sascha Hauer
@ 2014-07-24  6:48 ` Sascha Hauer
  2014-07-24  6:48 ` [PATCH 4/4] ARM: i.MX5: internal NAND update: simplify code Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-07-24  6:48 UTC (permalink / raw)
  To: barebox

Instead oof using the same constants multiple times use a variable
to make the meaning of the constants clear.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/imx-bbu-internal.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index a5cb7e7..d90d92b 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -178,6 +178,9 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler *
 	uint32_t *ptr, *num_bb, *bb;
 	uint64_t offset;
 	int block = 0, len, now, blocksize;
+	int dbbt_start_page = 4;
+	int firmware_start_page = 12;
+	void *dbbt_base;
 	int pre_image_size;
 
 	ret = stat(data->devicefile, &s);
@@ -194,7 +197,7 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler *
 	if (ret)
 		goto out;
 
-	pre_image_size = 12 * meminfo.writesize;
+	pre_image_size = firmware_start_page * meminfo.writesize;
 
 	blocksize = meminfo.erasesize;
 
@@ -203,23 +206,24 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler *
 	*ptr++ = 1;		/* FCB version */
 
 	ptr = image + 0x68; /* Firmware start page */
-	*ptr = 12;
+	*ptr = firmware_start_page;
 
 	ptr = image + 0x78; /* DBBT start page */
-	*ptr = 4;
+	*ptr = dbbt_start_page;
 
-	ptr = image + 4 * 2048 + 4;
+	dbbt_base = image + dbbt_start_page * meminfo.writesize;
+	ptr = dbbt_base + 4;
 	*ptr++ = DBBT_MAGIC;	/* DBBT */
 	*ptr = 1;		/* DBBT version */
 
-	ptr = (u32*)(image + 0x2010);
+	ptr = (u32*)(dbbt_base + 0x10);
 	/*
 	 * This is marked as reserved in the i.MX53 reference manual, but
 	 * must be != 0. Otherwise the ROM ignores the DBBT
 	 */
 	*ptr = 1;
 
-	ptr = (u32*)(image + 0x4004); /* start of DBBT */
+	ptr = (u32*)(dbbt_base + 4 * meminfo.writesize + 4); /* start of DBBT */
 	num_bb = ptr;
 	bb = ptr + 1;
 	offset = 0;
-- 
2.0.1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] ARM: i.MX5: internal NAND update: simplify code
  2014-07-24  6:48 [PATCH] i.MX5 internal NAND update fixes/cleanup Sascha Hauer
                   ` (2 preceding siblings ...)
  2014-07-24  6:48 ` [PATCH 3/4] ARM: i.MX5: internal NAND update: Use variables for some constants Sascha Hauer
@ 2014-07-24  6:48 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-07-24  6:48 UTC (permalink / raw)
  To: barebox

Allocate space for the resulting image (FCB+DBBT+Firmware) in
imx_bbu_internal_v2_write_nand_dbbt() instead of its caller to make the
code simpler.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/imx-bbu-internal.c | 33 +++++++++------------------------
 1 file changed, 9 insertions(+), 24 deletions(-)

diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index d90d92b..56369a0 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -168,7 +168,7 @@ static int imx_bbu_internal_v1_update(struct bbu_handler *handler, struct bbu_da
  * layer.
  */
 static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler *imx_handler,
-		struct bbu_data *data, void *image, int image_len)
+		struct bbu_data *data)
 {
 	struct mtd_info_user meminfo;
 	int fd;
@@ -181,6 +181,7 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler *
 	int dbbt_start_page = 4;
 	int firmware_start_page = 12;
 	void *dbbt_base;
+	void *image, *freep = NULL;
 	int pre_image_size;
 
 	ret = stat(data->devicefile, &s);
@@ -198,6 +199,8 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler *
 		goto out;
 
 	pre_image_size = firmware_start_page * meminfo.writesize;
+	image = freep = xzalloc(data->len + pre_image_size);
+	memcpy(image + pre_image_size, data->image, data->len);
 
 	blocksize = meminfo.erasesize;
 
@@ -322,6 +325,7 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler *
 
 out:
 	close(fd);
+	free(freep);
 
 	return ret;
 }
@@ -339,10 +343,7 @@ static int imx_bbu_internal_v2_update(struct bbu_handler *handler, struct bbu_da
 {
 	struct imx_internal_bbu_handler *imx_handler =
 		container_of(handler, struct imx_internal_bbu_handler, handler);
-	void *imx_pre_image = NULL;
-	int imx_pre_image_size;
-	int ret, image_len;
-	void *buf;
+	int ret;
 	uint32_t *barker;
 
 	ret = imx_bbu_check_prereq(data);
@@ -356,26 +357,10 @@ static int imx_bbu_internal_v2_update(struct bbu_handler *handler, struct bbu_da
 		return -EINVAL;
 	}
 
-	imx_pre_image_size = 0;
-
-	if (imx_handler->flags & IMX_INTERNAL_FLAG_NAND) {
-		/* NAND needs additional space for the DBBT */
-		imx_pre_image_size += 0x6000;
-		imx_pre_image = xzalloc(imx_pre_image_size);
-
-		/* Create a buffer containing header and image data */
-		image_len = data->len + imx_pre_image_size;
-		buf = xzalloc(image_len);
-		memcpy(buf, imx_pre_image, imx_pre_image_size);
-		memcpy(buf + imx_pre_image_size, data->image, data->len);
-
-		ret = imx_bbu_internal_v2_write_nand_dbbt(imx_handler, data, buf,
-				image_len);
-		free(buf);
-		free(imx_pre_image);
-	} else {
+	if (imx_handler->flags & IMX_INTERNAL_FLAG_NAND)
+		ret = imx_bbu_internal_v2_write_nand_dbbt(imx_handler, data);
+	else
 		ret = imx_bbu_write_device(imx_handler, data, data->image, data->len);
-	}
 
 	return ret;
 }
-- 
2.0.1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-07-24  6:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-24  6:48 [PATCH] i.MX5 internal NAND update fixes/cleanup Sascha Hauer
2014-07-24  6:48 ` [PATCH 1/4] ARM: i.MX5: internal NAND update: Use variable for pre_image_size Sascha Hauer
2014-07-24  6:48 ` [PATCH 2/4] ARM: i.MX5: internal NAND update: Fix firmware start page for internal nand boot Sascha Hauer
2014-07-24  6:48 ` [PATCH 3/4] ARM: i.MX5: internal NAND update: Use variables for some constants Sascha Hauer
2014-07-24  6:48 ` [PATCH 4/4] ARM: i.MX5: internal NAND update: simplify code Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox