mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/4] ARM: i.MX5: internal NAND update: simplify code
Date: Thu, 24 Jul 2014 08:48:13 +0200	[thread overview]
Message-ID: <1406184493-29225-5-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1406184493-29225-1-git-send-email-s.hauer@pengutronix.de>

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

      parent reply	other threads:[~2014-07-24  6:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Sascha Hauer [this message]

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=1406184493-29225-5-git-send-email-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