mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <uwe@kleine-koenig.org>
To: barebox@lists.infradead.org
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Subject: [PATCH v2 1/3] ARM: i.MX: bbu-internal: make filename for device to write to adaptable
Date: Mon, 23 Oct 2017 11:21:01 +0200	[thread overview]
Message-ID: <20171023092103.10023-2-uwe@kleine-koenig.org> (raw)
In-Reply-To: <20171023092103.10023-1-uwe@kleine-koenig.org>

From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

This is a preparatory for the next patch that autodetects the device to
write to. To not have to modify the callback data for each call, some
static functions get an additional parameter to allow that.

This doesn't affect boards making use of the file's function and doesn't
change behaviour.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 arch/arm/mach-imx/imx-bbu-internal.c | 37 +++++++++++++++++++-----------------
 arch/arm/mach-imx/include/mach/bbu.h | 10 ++++++++++
 2 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index 51ec8b8270f9..254ccb6369e6 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -49,29 +49,30 @@ struct imx_internal_bbu_handler {
  * DOS partition table on the device
  */
 static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
-		struct bbu_data *data, void *buf, int image_len)
+		const char *devicefile, struct bbu_data *data,
+		void *buf, int image_len)
 {
 	int fd, ret;
 
-	fd = open(data->devicefile, O_RDWR | O_CREAT);
+	fd = open(devicefile, O_RDWR | O_CREAT);
 	if (fd < 0)
 		return fd;
 
 	if (imx_handler->flags & IMX_INTERNAL_FLAG_ERASE) {
 		debug("%s: unprotecting %s from 0 to 0x%08x\n", __func__,
-				data->devicefile, image_len);
+				devicefile, image_len);
 		ret = protect(fd, image_len, 0, 0);
 		if (ret && ret != -ENOSYS) {
-			printf("unprotecting %s failed with %s\n", data->devicefile,
+			printf("unprotecting %s failed with %s\n", devicefile,
 					strerror(-ret));
 			goto err_close;
 		}
 
 		debug("%s: erasing %s from 0 to 0x%08x\n", __func__,
-				data->devicefile, image_len);
+				devicefile, image_len);
 		ret = erase(fd, image_len, 0);
 		if (ret) {
-			printf("erasing %s failed with %s\n", data->devicefile,
+			printf("erasing %s failed with %s\n", devicefile,
 					strerror(-ret));
 			goto err_close;
 		}
@@ -102,10 +103,10 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
 
 	if (imx_handler->flags & IMX_INTERNAL_FLAG_ERASE) {
 		debug("%s: protecting %s from 0 to 0x%08x\n", __func__,
-				data->devicefile, image_len);
+				devicefile, image_len);
 		ret = protect(fd, image_len, 0, 1);
 		if (ret && ret != -ENOSYS) {
-			printf("protecting %s failed with %s\n", data->devicefile,
+			printf("protecting %s failed with %s\n", devicefile,
 					strerror(-ret));
 		}
 	}
@@ -118,7 +119,7 @@ err_close:
 	return ret;
 }
 
-static int imx_bbu_check_prereq(struct bbu_data *data)
+static int imx_bbu_check_prereq(const char *devicefile, struct bbu_data *data)
 {
 	int ret;
 
@@ -131,8 +132,8 @@ static int imx_bbu_check_prereq(struct bbu_data *data)
 	if (ret)
 		return ret;
 
-	if (!strncmp(data->devicefile, "/dev/", 5))
-		device_detect_by_name(data->devicefile + 5);
+	if (!strncmp(devicefile, "/dev/", 5))
+		device_detect_by_name(devicefile + 5);
 
 	return 0;
 }
@@ -150,13 +151,13 @@ static int imx_bbu_internal_v1_update(struct bbu_handler *handler, struct bbu_da
 		container_of(handler, struct imx_internal_bbu_handler, handler);
 	int ret;
 
-	ret = imx_bbu_check_prereq(data);
+	ret = imx_bbu_check_prereq(data->devicefile, data);
 	if (ret)
 		return ret;
 
 	printf("updating to %s\n", data->devicefile);
 
-	ret = imx_bbu_write_device(imx_handler, data, data->image, data->len);
+	ret = imx_bbu_write_device(imx_handler, data->devicefile, data, data->image, data->len);
 
 	return ret;
 }
@@ -348,7 +349,7 @@ static int imx_bbu_internal_v2_update(struct bbu_handler *handler, struct bbu_da
 	int ret;
 	uint32_t *barker;
 
-	ret = imx_bbu_check_prereq(data);
+	ret = imx_bbu_check_prereq(data->devicefile, data);
 	if (ret)
 		return ret;
 
@@ -362,7 +363,8 @@ static int imx_bbu_internal_v2_update(struct bbu_handler *handler, struct bbu_da
 	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);
+		ret = imx_bbu_write_device(imx_handler, data->devicefile, data,
+					   data->image, data->len);
 
 	return ret;
 }
@@ -373,11 +375,12 @@ static int imx_bbu_external_update(struct bbu_handler *handler, struct bbu_data
 		container_of(handler, struct imx_internal_bbu_handler, handler);
 	int ret;
 
-	ret = imx_bbu_check_prereq(data);
+	ret = imx_bbu_check_prereq(data->devicefile, data);
 	if (ret)
 		return ret;
 
-	return imx_bbu_write_device(imx_handler, data, data->image, data->len);
+	return imx_bbu_write_device(imx_handler, data->devicefile, data,
+				    data->image, data->len);
 }
 
 static struct imx_internal_bbu_handler *__init_handler(const char *name, char *devicefile,
diff --git a/arch/arm/mach-imx/include/mach/bbu.h b/arch/arm/mach-imx/include/mach/bbu.h
index 8039091395de..15bdbe1bec0d 100644
--- a/arch/arm/mach-imx/include/mach/bbu.h
+++ b/arch/arm/mach-imx/include/mach/bbu.h
@@ -24,6 +24,9 @@ int imx53_bbu_internal_nand_register_handler(const char *name,
 int imx6_bbu_internal_mmc_register_handler(const char *name, char *devicefile,
 		unsigned long flags);
 
+int imx6_bbu_internal_mmcboot_register_handler(const char *name, char *devicefile,
+		unsigned long flags);
+
 int imx6_bbu_internal_spi_i2c_register_handler(const char *name, char *devicefile,
 		unsigned long flags);
 
@@ -62,6 +65,13 @@ static inline int imx6_bbu_internal_mmc_register_handler(const char *name, char
 	return -ENOSYS;
 }
 
+static inline int imx6_bbu_internal_mmcboot_register_handler(const char *name,
+							     char *devicefile,
+							     unsigned long flags)
+{
+	return -ENOSYS;
+}
+
 static inline int imx6_bbu_internal_spi_i2c_register_handler(const char *name, char *devicefile,
 		unsigned long flags)
 {
-- 
2.14.2


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

  reply	other threads:[~2017-10-23  9:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-23  9:21 [PATCH v2 0/3] ARM: i.MX: bbu-internal: new handler to make use of mmc boot partitions Uwe Kleine-König
2017-10-23  9:21 ` Uwe Kleine-König [this message]
2017-10-23  9:21 ` [PATCH v2 2/3] " Uwe Kleine-König
2017-10-23  9:21 ` [PATCH v2 3/3] ARM: i.MX: bbu-internal: update tqma6x to make use of new bbu handler Uwe Kleine-König
2017-10-24 12:10 ` [PATCH v2 0/3] ARM: i.MX: bbu-internal: new handler to make use of mmc boot partitions 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=20171023092103.10023-2-uwe@kleine-koenig.org \
    --to=uwe@kleine-koenig.org \
    --cc=barebox@lists.infradead.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /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