mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/4] omap/am33xx_bbu: use file_write_flash() instead of its own variant
Date: Fri,  1 Jun 2018 20:07:49 +0200	[thread overview]
Message-ID: <20180601180750.5436-3-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20180601180750.5436-1-u.kleine-koenig@pengutronix.de>

There are two differences between file_write_flash() and write_image()
(which is removed in this patch):

 - file_write_flash() uses write_full() vs. write() in write_image()
 - file_write_flash() doesn't erase the whole device but only the needed
   space

So the new code should be more robust and maybe even faster.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 arch/arm/mach-omap/am33xx_bbu_nand.c | 37 ++--------------------------
 1 file changed, 2 insertions(+), 35 deletions(-)

diff --git a/arch/arm/mach-omap/am33xx_bbu_nand.c b/arch/arm/mach-omap/am33xx_bbu_nand.c
index 7785d40f1f25..9ee483855e42 100644
--- a/arch/arm/mach-omap/am33xx_bbu_nand.c
+++ b/arch/arm/mach-omap/am33xx_bbu_nand.c
@@ -28,39 +28,6 @@ struct nand_bbu_handler {
 	int num_devicefiles;
 };
 
-static int write_image(const char *devfile, const void *image, size_t size)
-{
-	int fd = 0;
-	int ret = 0;
-
-	fd = open(devfile, O_WRONLY);
-	if (fd < 0) {
-		pr_err("could not open %s: %s\n", devfile,
-			errno_str());
-		return fd;
-	}
-
-	ret = erase(fd, ERASE_SIZE_ALL, 0);
-	if (ret < 0) {
-		pr_err("could not erase %s: %s\n", devfile,
-			errno_str());
-		close(fd);
-		return ret;
-	}
-
-	ret = write(fd, image, size);
-	if (ret < 0) {
-		pr_err("could not write to fd %s: %s\n", devfile,
-			errno_str());
-		close(fd);
-		return ret;
-	}
-
-	close(fd);
-
-	return 0;
-}
-
 /*
  * Upate given nand partitions with an image
  */
@@ -80,12 +47,12 @@ static int nand_slot_update_handler(struct bbu_handler *handler,
 
 	/* check if the devicefile has been overwritten */
 	if (strcmp(data->devicefile, nh->devicefile[0]) != 0) {
-		ret = write_image(data->devicefile, image, size);
+		ret = write_file_flash(data->devicefile, image, size);
 		if (ret != 0)
 			return ret;
 	} else {
 		for (i = 0; i < nh->num_devicefiles; i++) {
-			ret =  write_image(nh->devicefile[i], image, size);
+			ret =  write_file_flash(nh->devicefile[i], image, size);
 			if (ret != 0)
 				return ret;
 		}
-- 
2.17.0


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

  parent reply	other threads:[~2018-06-01 18:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-01 18:07 [PATCH 1/4] kwbimage_v0: add support to detect and boot a mvebu v0 image Uwe Kleine-König
2018-06-01 18:07 ` [PATCH 2/4] libfile: implement new helper write_file_flash() Uwe Kleine-König
2018-06-07 20:53   ` Uwe Kleine-König
2018-06-08  7:10     ` Sascha Hauer
2018-06-08  8:44       ` Uwe Kleine-König
2018-06-01 18:07 ` Uwe Kleine-König [this message]
2018-06-01 18:07 ` [PATCH 4/4] scripts/kwboot: fix image check for v0 images Uwe Kleine-König
2018-06-04  7:01 ` [PATCH 1/4] kwbimage_v0: add support to detect and boot a mvebu v0 image Sascha Hauer
2018-06-04  7:02   ` Uwe Kleine-König

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=20180601180750.5436-3-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@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