mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 0/3] ARM: i.MX: bbu-internal: new handler to make use of mmc boot partitions
@ 2017-10-23  9:21 Uwe Kleine-König
  2017-10-23  9:21 ` [PATCH v2 1/3] ARM: i.MX: bbu-internal: make filename for device to write to adaptable Uwe Kleine-König
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2017-10-23  9:21 UTC (permalink / raw)
  To: barebox

Hello,

this is v2 of the series. I dropped the error messages as requested by
Sascha and only use the new function on a single board now as the others
have the environment in boot1. Also there is a comment now about what
the new handler does and how it should be used.

Uwe Kleine-König (3):
  ARM: i.MX: bbu-internal: make filename for device to write to
    adaptable
  ARM: i.MX: bbu-internal: new handler to make use of mmc boot
    partitions
  ARM: i.MX: bbu-internal: update tqma6x to make use of new bbu handler

 arch/arm/boards/tqma6x/board.c       |   2 +-
 arch/arm/mach-imx/imx-bbu-internal.c | 113 +++++++++++++++++++++++++++++------
 arch/arm/mach-imx/include/mach/bbu.h |  10 ++++
 3 files changed, 107 insertions(+), 18 deletions(-)

-- 
2.14.2


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

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

* [PATCH v2 1/3] ARM: i.MX: bbu-internal: make filename for device to write to adaptable
  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
  2017-10-23  9:21 ` [PATCH v2 2/3] ARM: i.MX: bbu-internal: new handler to make use of mmc boot partitions Uwe Kleine-König
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2017-10-23  9:21 UTC (permalink / raw)
  To: barebox; +Cc: Uwe Kleine-König

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

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

* [PATCH v2 2/3] ARM: i.MX: bbu-internal: new handler to make use of mmc boot partitions
  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 ` [PATCH v2 1/3] ARM: i.MX: bbu-internal: make filename for device to write to adaptable Uwe Kleine-König
@ 2017-10-23  9:21 ` 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
  3 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2017-10-23  9:21 UTC (permalink / raw)
  To: barebox; +Cc: Uwe Kleine-König

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

This handler updates the non-active MMC boot partition and after a
successful update makes the updated partition the active one. This way
the machine should continue to be bootable when the update fails.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 arch/arm/mach-imx/imx-bbu-internal.c | 76 ++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index 254ccb6369e6..e34638713151 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -29,6 +29,7 @@
 #include <linux/mtd/mtd-abi.h>
 #include <linux/stat.h>
 #include <ioctl.h>
+#include <environment.h>
 #include <mach/bbu.h>
 
 #define FLASH_HEADER_OFFSET_MMC		0x400
@@ -369,6 +370,59 @@ static int imx_bbu_internal_v2_update(struct bbu_handler *handler, struct bbu_da
 	return ret;
 }
 
+static int imx_bbu_internal_v2_mmcboot_update(struct bbu_handler *handler,
+					      struct bbu_data *data)
+{
+	struct imx_internal_bbu_handler *imx_handler =
+		container_of(handler, struct imx_internal_bbu_handler, handler);
+	int ret;
+	uint32_t *barker;
+	char *bootpartvar;
+	const char *bootpart;
+	char *devicefile;
+
+	barker = data->image + imx_handler->flash_header_offset;
+
+	if (*barker != IVT_BARKER) {
+		printf("Board does not provide DCD data and this image is no imximage\n");
+		return -EINVAL;
+	}
+
+	ret = asprintf(&bootpartvar, "%s.boot", data->devicefile);
+	if (ret < 0)
+		return ret;
+
+	bootpart = getenv(bootpartvar);
+
+	if (!strcmp(bootpart, "boot0")) {
+		bootpart = "boot1";
+	} else {
+		bootpart = "boot0";
+	}
+
+	ret = asprintf(&devicefile, "/dev/%s.%s", data->devicefile, bootpart);
+	if (ret < 0)
+		goto free_bootpartvar;
+
+	ret = imx_bbu_check_prereq(devicefile, data);
+	if (ret)
+		goto free_devicefile;
+
+	ret = imx_bbu_write_device(imx_handler, devicefile, data, data->image, data->len);
+
+	if (!ret)
+		/* on success switch boot source */
+		ret = setenv(bootpartvar, bootpart);
+
+free_devicefile:
+	free(devicefile);
+
+free_bootpartvar:
+	free(bootpartvar);
+
+	return ret;
+}
+
 static int imx_bbu_external_update(struct bbu_handler *handler, struct bbu_data *data)
 {
 	struct imx_internal_bbu_handler *imx_handler =
@@ -498,6 +552,28 @@ int imx6_bbu_internal_mmc_register_handler(const char *name, char *devicefile,
 	return __register_handler(imx_handler);
 }
 
+/*
+ * Register a handler that writes to the non-active boot partition of an mmc
+ * medium and on success activates the written-to partition. So the machine can
+ * still boot even after a failed try to write a boot image.
+ *
+ * Pass "devicefile" without partition name and /dev/ prefix. e.g. just "mmc2".
+ * Note that no further partitioning of the boot partition is supported up to
+ * now.
+ */
+int imx6_bbu_internal_mmcboot_register_handler(const char *name, char *devicefile,
+					       unsigned long flags)
+{
+	struct imx_internal_bbu_handler *imx_handler;
+
+	imx_handler = __init_handler(name, devicefile, flags);
+	imx_handler->flash_header_offset = FLASH_HEADER_OFFSET_MMC;
+
+	imx_handler->handler.handler = imx_bbu_internal_v2_mmcboot_update;
+
+	return __register_handler(imx_handler);
+}
+
 /*
  * Register a i.MX53 internal boot update handler for i2c/spi
  * EEPROMs / flashes. Nearly the same as MMC/SD, but we do not need to
-- 
2.14.2


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

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

* [PATCH v2 3/3] ARM: i.MX: bbu-internal: update tqma6x to make use of new bbu handler
  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 ` [PATCH v2 1/3] ARM: i.MX: bbu-internal: make filename for device to write to adaptable Uwe Kleine-König
  2017-10-23  9:21 ` [PATCH v2 2/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
  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
  3 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2017-10-23  9:21 UTC (permalink / raw)
  To: barebox; +Cc: Uwe Kleine-König

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

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 arch/arm/boards/tqma6x/board.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boards/tqma6x/board.c b/arch/arm/boards/tqma6x/board.c
index 8946a27b696a..ecf8fa06af01 100644
--- a/arch/arm/boards/tqma6x/board.c
+++ b/arch/arm/boards/tqma6x/board.c
@@ -105,7 +105,7 @@ static int tqma6x_env_init(void)
 
 	imx6_bbu_internal_spi_i2c_register_handler("spiflash", "/dev/m25p0.barebox",
 		BBU_HANDLER_FLAG_DEFAULT);
-	imx6_bbu_internal_mmc_register_handler("emmc", "/dev/mmc2.boot0", 0);
+	imx6_bbu_internal_mmcboot_register_handler("emmc", "mmc2", 0);
 
 	device_detect_by_name("mmc2");
 
-- 
2.14.2


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

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

* Re: [PATCH v2 0/3] ARM: i.MX: bbu-internal: new handler to make use of mmc boot partitions
  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
                   ` (2 preceding siblings ...)
  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 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2017-10-24 12:10 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: barebox

On Mon, Oct 23, 2017 at 11:21:00AM +0200, Uwe Kleine-König wrote:
> Hello,
> 
> this is v2 of the series. I dropped the error messages as requested by
> Sascha and only use the new function on a single board now as the others
> have the environment in boot1. Also there is a comment now about what
> the new handler does and how it should be used.
> 
> Uwe Kleine-König (3):
>   ARM: i.MX: bbu-internal: make filename for device to write to
>     adaptable
>   ARM: i.MX: bbu-internal: new handler to make use of mmc boot
>     partitions
>   ARM: i.MX: bbu-internal: update tqma6x to make use of new bbu handler

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
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:[~2017-10-24 12:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v2 1/3] ARM: i.MX: bbu-internal: make filename for device to write to adaptable Uwe Kleine-König
2017-10-23  9:21 ` [PATCH v2 2/3] ARM: i.MX: bbu-internal: new handler to make use of mmc boot partitions 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

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