* [PATCH 1/4] bbu: reserve upper 16 bits for handler specific flags
2018-07-02 4:41 [PATCH v2 0/4] bbu: i.MX: Generalize IMX_INTERNAL_FLAG_KEEP_DOSPART flag Sascha Hauer
@ 2018-07-02 4:41 ` Sascha Hauer
2018-07-02 4:41 ` [PATCH 2/4] ARM: i.MX: bbu: remove handler specific flags variable Sascha Hauer
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2018-07-02 4:41 UTC (permalink / raw)
To: Barebox List
Let the handler store 16 bit of handler specific flags in
the generic handler struct. The setup functions of some
bbu handlers let the user specify a flags field. With this
change they can now pass generic and handler specific flags
in a single variable without having to use a second parameter.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/bbu.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/bbu.h b/include/bbu.h
index def568e498..d1ab9f5638 100644
--- a/include/bbu.h
+++ b/include/bbu.h
@@ -25,6 +25,10 @@ struct bbu_handler {
struct list_head list;
#define BBU_HANDLER_FLAG_DEFAULT (1 << 0)
#define BBU_HANDLER_CAN_REFRESH (1 << 1)
+ /*
+ * The lower 16bit are generic flags, the upper 16bit are reserved
+ * for handler specific flags.
+ */
unsigned long flags;
/* default device file, can be overwritten on the command line */
--
2.17.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.MX: bbu: remove handler specific flags variable
2018-07-02 4:41 [PATCH v2 0/4] bbu: i.MX: Generalize IMX_INTERNAL_FLAG_KEEP_DOSPART flag Sascha Hauer
2018-07-02 4:41 ` [PATCH 1/4] bbu: reserve upper 16 bits for handler specific flags Sascha Hauer
@ 2018-07-02 4:41 ` Sascha Hauer
2018-07-02 4:41 ` [PATCH 3/4] ARM: i.MX: bbu: reimplement IMX_INTERNAL_FLAG_KEEP_DOSPART flag Sascha Hauer
2018-07-02 4:41 ` [PATCH 4/4] ARM: i.MX: bbu: support partitions starting at i.MX header Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2018-07-02 4:41 UTC (permalink / raw)
To: Barebox List
Now that we can store flags in the generic handler flags
we no longer need our own variable.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/mach-imx/imx-bbu-internal.c | 35 ++++++++++++++--------------
1 file changed, 17 insertions(+), 18 deletions(-)
diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index 84810f18a9..fae94fdc4e 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -34,15 +34,14 @@
#define FLASH_HEADER_OFFSET_MMC 0x400
-#define IMX_INTERNAL_FLAG_NAND (1 << 0)
-#define IMX_INTERNAL_FLAG_KEEP_DOSPART (1 << 1)
-#define IMX_INTERNAL_FLAG_ERASE (1 << 2)
+#define IMX_INTERNAL_FLAG_NAND BIT(16)
+#define IMX_INTERNAL_FLAG_KEEP_DOSPART BIT(17)
+#define IMX_INTERNAL_FLAG_ERASE BIT(18)
struct imx_internal_bbu_handler {
struct bbu_handler handler;
unsigned long flash_header_offset;
size_t device_size;
- unsigned long flags;
};
/*
@@ -60,7 +59,7 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
if (fd < 0)
return fd;
- if (imx_handler->flags & IMX_INTERNAL_FLAG_ERASE) {
+ if (imx_handler->handler.flags & IMX_INTERNAL_FLAG_ERASE) {
pr_debug("%s: unprotecting %s from 0 to 0x%08x\n", __func__,
devicefile, image_len);
ret = protect(fd, image_len, 0, 0);
@@ -80,7 +79,7 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
}
}
- if (imx_handler->flags & IMX_INTERNAL_FLAG_KEEP_DOSPART) {
+ if (imx_handler->handler.flags & IMX_INTERNAL_FLAG_KEEP_DOSPART) {
void *mbr = xzalloc(512);
pr_debug("%s: reading DOS partition table in order to keep it\n", __func__);
@@ -113,7 +112,7 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
if (ret < 0)
goto err_close;
- if (imx_handler->flags & IMX_INTERNAL_FLAG_ERASE) {
+ if (imx_handler->handler.flags & IMX_INTERNAL_FLAG_ERASE) {
pr_debug("%s: protecting %s from 0 to 0x%08x\n", __func__,
devicefile, image_len);
ret = protect(fd, image_len, 0, 1);
@@ -371,7 +370,7 @@ static int imx_bbu_internal_v2_update(struct bbu_handler *handler, struct bbu_da
return -EINVAL;
}
- if (imx_handler->flags & IMX_INTERNAL_FLAG_NAND)
+ if (imx_handler->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->devicefile, data,
@@ -479,10 +478,10 @@ imx_bbu_internal_mmc_register_handler(const char *name, char *devicefile,
{
struct imx_internal_bbu_handler *imx_handler;
- imx_handler = __init_handler(name, devicefile, flags);
+ imx_handler = __init_handler(name, devicefile, flags |
+ IMX_INTERNAL_FLAG_KEEP_DOSPART);
imx_handler->flash_header_offset = FLASH_HEADER_OFFSET_MMC;
- imx_handler->flags = IMX_INTERNAL_FLAG_KEEP_DOSPART;
imx_handler->handler.handler = handler;
return __register_handler(imx_handler);
@@ -493,10 +492,10 @@ int imx51_bbu_internal_spi_i2c_register_handler(const char *name,
{
struct imx_internal_bbu_handler *imx_handler;
- imx_handler = __init_handler(name, devicefile, flags);
+ imx_handler = __init_handler(name, devicefile, flags |
+ IMX_INTERNAL_FLAG_ERASE);
imx_handler->flash_header_offset = FLASH_HEADER_OFFSET_MMC;
- imx_handler->flags = IMX_INTERNAL_FLAG_ERASE;
imx_handler->handler.handler = imx_bbu_internal_v1_update;
return __register_handler(imx_handler);
@@ -533,10 +532,10 @@ int imx53_bbu_internal_spi_i2c_register_handler(const char *name, char *devicefi
{
struct imx_internal_bbu_handler *imx_handler;
- imx_handler = __init_handler(name, devicefile, flags);
+ imx_handler = __init_handler(name, devicefile, flags |
+ IMX_INTERNAL_FLAG_ERASE);
imx_handler->flash_header_offset = FLASH_HEADER_OFFSET_MMC;
- imx_handler->flags = IMX_INTERNAL_FLAG_ERASE;
imx_handler->handler.handler = imx_bbu_internal_v2_update;
return __register_handler(imx_handler);
@@ -550,11 +549,11 @@ int imx53_bbu_internal_nand_register_handler(const char *name,
{
struct imx_internal_bbu_handler *imx_handler;
- imx_handler = __init_handler(name, NULL, flags);
+ imx_handler = __init_handler(name, NULL, flags |
+ IMX_INTERNAL_FLAG_NAND);
imx_handler->flash_header_offset = FLASH_HEADER_OFFSET_MMC;
imx_handler->handler.handler = imx_bbu_internal_v2_update;
- imx_handler->flags = IMX_INTERNAL_FLAG_NAND;
imx_handler->handler.devicefile = "/dev/nand0";
imx_handler->device_size = partition_size;
@@ -612,8 +611,8 @@ int imx_bbu_external_nor_register_handler(const char *name, char *devicefile,
{
struct imx_internal_bbu_handler *imx_handler;
- imx_handler = __init_handler(name, devicefile, flags);
- imx_handler->flags = IMX_INTERNAL_FLAG_ERASE;
+ imx_handler = __init_handler(name, devicefile, flags |
+ IMX_INTERNAL_FLAG_ERASE);
imx_handler->handler.handler = imx_bbu_external_update;
return __register_handler(imx_handler);
--
2.17.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.MX: bbu: reimplement IMX_INTERNAL_FLAG_KEEP_DOSPART flag
2018-07-02 4:41 [PATCH v2 0/4] bbu: i.MX: Generalize IMX_INTERNAL_FLAG_KEEP_DOSPART flag Sascha Hauer
2018-07-02 4:41 ` [PATCH 1/4] bbu: reserve upper 16 bits for handler specific flags Sascha Hauer
2018-07-02 4:41 ` [PATCH 2/4] ARM: i.MX: bbu: remove handler specific flags variable Sascha Hauer
@ 2018-07-02 4:41 ` Sascha Hauer
2018-07-02 4:41 ` [PATCH 4/4] ARM: i.MX: bbu: support partitions starting at i.MX header Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2018-07-02 4:41 UTC (permalink / raw)
To: Barebox List
This patch reimplements the IMX_INTERNAL_FLAG_KEEP_DOSPART flag
and makes it more generic. Until now we only kept a dos partition
table over the update. Beginning with i.MX8 we may also want to
preserve a GPT, so we have to extend the preserved area.
It might also be the case that not (only) a partition table is
stored in the initial area of a device, but also other unrelated
data, so it's better to just keep the initial area that is unused
by the i.MX ROM. It's also good to export the flag to allow boards
to specify the initial area shall be preserved.
When a board wants to set the flag for a mtd like device then it
has to check for suitable erase sizes beforehand. We do not check
this (yet).
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/mach-imx/imx-bbu-internal.c | 65 +++++++++-------------------
arch/arm/mach-imx/include/mach/bbu.h | 15 +++++++
2 files changed, 35 insertions(+), 45 deletions(-)
diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index fae94fdc4e..7a512b1de4 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -34,9 +34,8 @@
#define FLASH_HEADER_OFFSET_MMC 0x400
-#define IMX_INTERNAL_FLAG_NAND BIT(16)
-#define IMX_INTERNAL_FLAG_KEEP_DOSPART BIT(17)
-#define IMX_INTERNAL_FLAG_ERASE BIT(18)
+#define IMX_INTERNAL_FLAG_NAND BIT(31)
+#define IMX_INTERNAL_FLAG_ERASE BIT(30)
struct imx_internal_bbu_handler {
struct bbu_handler handler;
@@ -52,26 +51,31 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
const char *devicefile, struct bbu_data *data,
const void *buf, int image_len)
{
- int fd, ret;
- int written = 0;
+ int fd, ret, offset = 0;
fd = open(devicefile, O_RDWR | O_CREAT);
if (fd < 0)
return fd;
+ if (imx_handler->handler.flags & IMX_BBU_FLAG_KEEP_HEAD) {
+ image_len -= imx_handler->flash_header_offset;
+ offset += imx_handler->flash_header_offset;
+ buf += imx_handler->flash_header_offset;
+ }
+
if (imx_handler->handler.flags & IMX_INTERNAL_FLAG_ERASE) {
- pr_debug("%s: unprotecting %s from 0 to 0x%08x\n", __func__,
- devicefile, image_len);
- ret = protect(fd, image_len, 0, 0);
+ pr_debug("%s: unprotecting %s from 0x%08x to 0x%08x\n", __func__,
+ devicefile, offset, image_len);
+ ret = protect(fd, image_len, offset, 0);
if (ret && ret != -ENOSYS) {
pr_err("unprotecting %s failed with %s\n", devicefile,
strerror(-ret));
goto err_close;
}
- pr_debug("%s: erasing %s from 0 to 0x%08x\n", __func__,
- devicefile, image_len);
- ret = erase(fd, image_len, 0);
+ pr_debug("%s: erasing %s from 0x%08x to 0x%08x\n", __func__,
+ devicefile, offset, image_len);
+ ret = erase(fd, image_len, offset);
if (ret) {
pr_err("erasing %s failed with %s\n", devicefile,
strerror(-ret));
@@ -79,43 +83,14 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
}
}
- if (imx_handler->handler.flags & IMX_INTERNAL_FLAG_KEEP_DOSPART) {
- void *mbr = xzalloc(512);
-
- pr_debug("%s: reading DOS partition table in order to keep it\n", __func__);
-
- ret = read(fd, mbr, 512);
- if (ret < 0) {
- free(mbr);
- goto err_close;
- }
-
- memcpy(mbr, buf, 0x1b8);
-
- ret = lseek(fd, 0, SEEK_SET);
- if (ret) {
- free(mbr);
- goto err_close;
- }
-
- ret = write(fd, mbr, 512);
-
- free(mbr);
-
- if (ret < 0)
- goto err_close;
-
- written = 512;
- }
-
- ret = write(fd, buf + written, image_len - written);
+ ret = pwrite(fd, buf, image_len, offset);
if (ret < 0)
goto err_close;
if (imx_handler->handler.flags & IMX_INTERNAL_FLAG_ERASE) {
- pr_debug("%s: protecting %s from 0 to 0x%08x\n", __func__,
- devicefile, image_len);
- ret = protect(fd, image_len, 0, 1);
+ pr_debug("%s: protecting %s from 0x%08x to 0x%08x\n", __func__,
+ devicefile, offset, image_len);
+ ret = protect(fd, image_len, offset, 1);
if (ret && ret != -ENOSYS) {
pr_err("protecting %s failed with %s\n", devicefile,
strerror(-ret));
@@ -479,7 +454,7 @@ imx_bbu_internal_mmc_register_handler(const char *name, char *devicefile,
struct imx_internal_bbu_handler *imx_handler;
imx_handler = __init_handler(name, devicefile, flags |
- IMX_INTERNAL_FLAG_KEEP_DOSPART);
+ IMX_BBU_FLAG_KEEP_HEAD);
imx_handler->flash_header_offset = FLASH_HEADER_OFFSET_MMC;
imx_handler->handler.handler = handler;
diff --git a/arch/arm/mach-imx/include/mach/bbu.h b/arch/arm/mach-imx/include/mach/bbu.h
index d623828312..f19aacce06 100644
--- a/arch/arm/mach-imx/include/mach/bbu.h
+++ b/arch/arm/mach-imx/include/mach/bbu.h
@@ -7,6 +7,21 @@
struct imx_dcd_entry;
struct imx_dcd_v2_entry;
+/*
+ * The ROM code reads images from a certain offset of the boot device
+ * (usually 0x400), whereas the update images start from offset 0x0.
+ * Set this flag to skip the offset on both the update image and the
+ * device so that the initial boot device portion is preserved. This
+ * is useful if a partition table or other data is in this area.
+ */
+#define IMX_BBU_FLAG_KEEP_HEAD BIT(16)
+
+/*
+ * The upper 16 bit of the flags passes to the below functions are reserved
+ * for i.MX specific flags
+ */
+#define IMX_BBU_FLAG_MASK 0xffff0000
+
#ifdef CONFIG_BAREBOX_UPDATE
int imx51_bbu_internal_mmc_register_handler(const char *name, char *devicefile,
--
2.17.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.MX: bbu: support partitions starting at i.MX header
2018-07-02 4:41 [PATCH v2 0/4] bbu: i.MX: Generalize IMX_INTERNAL_FLAG_KEEP_DOSPART flag Sascha Hauer
` (2 preceding siblings ...)
2018-07-02 4:41 ` [PATCH 3/4] ARM: i.MX: bbu: reimplement IMX_INTERNAL_FLAG_KEEP_DOSPART flag Sascha Hauer
@ 2018-07-02 4:41 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2018-07-02 4:41 UTC (permalink / raw)
To: Barebox List
The i.MX header is at an offset in the boot device, usually 0x400 bytes.
This patch adds a flag to support the case that the partition the image
is written to starts at that offset rather than 0x0.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/mach-imx/imx-bbu-internal.c | 7 +++++--
arch/arm/mach-imx/include/mach/bbu.h | 8 ++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index 7a512b1de4..55e344cff2 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -57,12 +57,15 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
if (fd < 0)
return fd;
- if (imx_handler->handler.flags & IMX_BBU_FLAG_KEEP_HEAD) {
+ if (imx_handler->handler.flags & (IMX_BBU_FLAG_KEEP_HEAD |
+ IMX_BBU_FLAG_PARTITION_STARTS_AT_HEADER)) {
image_len -= imx_handler->flash_header_offset;
- offset += imx_handler->flash_header_offset;
buf += imx_handler->flash_header_offset;
}
+ if (imx_handler->handler.flags & IMX_BBU_FLAG_KEEP_HEAD)
+ offset += imx_handler->flash_header_offset;
+
if (imx_handler->handler.flags & IMX_INTERNAL_FLAG_ERASE) {
pr_debug("%s: unprotecting %s from 0x%08x to 0x%08x\n", __func__,
devicefile, offset, image_len);
diff --git a/arch/arm/mach-imx/include/mach/bbu.h b/arch/arm/mach-imx/include/mach/bbu.h
index f19aacce06..7df9d668bb 100644
--- a/arch/arm/mach-imx/include/mach/bbu.h
+++ b/arch/arm/mach-imx/include/mach/bbu.h
@@ -16,6 +16,14 @@ struct imx_dcd_v2_entry;
*/
#define IMX_BBU_FLAG_KEEP_HEAD BIT(16)
+/*
+ * Set this flag when the partition the update image is written to
+ * actually starts at the offset where the i.MX flash header is expected
+ * (usually 0x400). This means for the update code that it has to skip
+ * the first 0x400 bytes of the image.
+ */
+#define IMX_BBU_FLAG_PARTITION_STARTS_AT_HEADER (1 << 17)
+
/*
* The upper 16 bit of the flags passes to the below functions are reserved
* for i.MX specific flags
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread