mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/6] bbu: Make image pointer const
@ 2018-01-30  8:46 Sascha Hauer
  2018-01-30  8:46 ` [PATCH 1/6] bbu: imx-bbu-internal: Do not modify image Sascha Hauer
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Sascha Hauer @ 2018-01-30  8:46 UTC (permalink / raw)
  To: Barebox List

The image pointer in the bbu data structure should be const so that we
can pass const pointers in there. This is changed in this series.

Sascha Hauer (6):
  bbu: imx-bbu-internal: Do not modify image
  bbu: imx-bbu-internal: make pointers to image const
  bbu: command: create temporary variable holding the pointer to the
    image
  bbu: Make pointer to image const
  usb: gadget: fastboot: allow data.image to be const
  ARM: am33xx: bbu: Make pointers to image const

 arch/arm/mach-imx/imx-bbu-internal.c    | 25 ++++++++++++++++++-------
 arch/arm/mach-omap/am33xx_bbu_spi_mlo.c |  4 ++--
 commands/barebox-update.c               |  8 +++++---
 drivers/usb/gadget/f_fastboot.c         |  9 ++++++---
 include/bbu.h                           |  2 +-
 5 files changed, 32 insertions(+), 16 deletions(-)

-- 
2.15.1


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

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

* [PATCH 1/6] bbu: imx-bbu-internal: Do not modify image
  2018-01-30  8:46 [PATCH 0/6] bbu: Make image pointer const Sascha Hauer
@ 2018-01-30  8:46 ` Sascha Hauer
  2018-01-30  8:46 ` [PATCH 2/6] bbu: imx-bbu-internal: make pointers to image const Sascha Hauer
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2018-01-30  8:46 UTC (permalink / raw)
  To: Barebox List

Instead of copying the existing partition table into the image
to be flashed, modify the temporary buffer and write from this
one. This makes it unnecessary to modify the input image which
can be made const then in a later step.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/imx-bbu-internal.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index 5783da6102..d40bde5339 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -54,6 +54,7 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
 		void *buf, int image_len)
 {
 	int fd, ret;
+	int written = 0;
 
 	fd = open(devicefile, O_RDWR | O_CREAT);
 	if (fd < 0)
@@ -90,15 +91,25 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
 			goto err_close;
 		}
 
-		memcpy(buf + 0x1b8, mbr + 0x1b8, 0x48);
-		free(mbr);
+		memcpy(mbr, buf, 0x1b8);
 
 		ret = lseek(fd, 0, SEEK_SET);
-		if (ret)
+		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, image_len);
+	ret = write(fd, buf + written, image_len - written);
 	if (ret < 0)
 		goto err_close;
 
-- 
2.15.1


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

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

* [PATCH 2/6] bbu: imx-bbu-internal: make pointers to image const
  2018-01-30  8:46 [PATCH 0/6] bbu: Make image pointer const Sascha Hauer
  2018-01-30  8:46 ` [PATCH 1/6] bbu: imx-bbu-internal: Do not modify image Sascha Hauer
@ 2018-01-30  8:46 ` Sascha Hauer
  2018-01-30  8:46 ` [PATCH 3/6] bbu: command: create temporary variable holding the pointer to the image Sascha Hauer
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2018-01-30  8:46 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/imx-bbu-internal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index d40bde5339..d03be72487 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -51,7 +51,7 @@ struct imx_internal_bbu_handler {
  */
 static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
 		const char *devicefile, struct bbu_data *data,
-		void *buf, int image_len)
+		const void *buf, int image_len)
 {
 	int fd, ret;
 	int written = 0;
@@ -358,7 +358,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);
 	int ret;
-	uint32_t *barker;
+	const uint32_t *barker;
 
 	ret = imx_bbu_check_prereq(data->devicefile, data);
 	if (ret)
@@ -386,7 +386,7 @@ static int imx_bbu_internal_v2_mmcboot_update(struct bbu_handler *handler,
 	struct imx_internal_bbu_handler *imx_handler =
 		container_of(handler, struct imx_internal_bbu_handler, handler);
 	int ret;
-	uint32_t *barker;
+	const uint32_t *barker;
 	char *bootpartvar;
 	const char *bootpart;
 	char *devicefile;
-- 
2.15.1


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

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

* [PATCH 3/6] bbu: command: create temporary variable holding the pointer to the image
  2018-01-30  8:46 [PATCH 0/6] bbu: Make image pointer const Sascha Hauer
  2018-01-30  8:46 ` [PATCH 1/6] bbu: imx-bbu-internal: Do not modify image Sascha Hauer
  2018-01-30  8:46 ` [PATCH 2/6] bbu: imx-bbu-internal: make pointers to image const Sascha Hauer
@ 2018-01-30  8:46 ` Sascha Hauer
  2018-01-30  8:46 ` [PATCH 4/6] bbu: Make pointer to image const Sascha Hauer
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2018-01-30  8:46 UTC (permalink / raw)
  To: Barebox List

Create variable to hold the pointer to the image so that we can
make the data.image pointer const later.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/barebox-update.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/commands/barebox-update.c b/commands/barebox-update.c
index c2f2b68e08..84798ab0d9 100644
--- a/commands/barebox-update.c
+++ b/commands/barebox-update.c
@@ -28,6 +28,7 @@ static int do_barebox_update(int argc, char *argv[])
 {
 	int opt, ret, repair = 0;
 	struct bbu_data data = {};
+	void *image = NULL;
 
 	while ((opt = getopt(argc, argv, "t:yf:ld:r")) > 0) {
 		switch (opt) {
@@ -59,9 +60,10 @@ static int do_barebox_update(int argc, char *argv[])
 	if (argc - optind > 0) {
 		data.imagefile = argv[optind];
 
-		data.image = read_file(data.imagefile, &data.len);
-		if (!data.image)
+		image = read_file(data.imagefile, &data.len);
+		if (!image)
 			return -errno;
+		data.image = image;
 	} else {
 		if (!repair)
 			return COMMAND_ERROR_USAGE;
@@ -69,7 +71,7 @@ static int do_barebox_update(int argc, char *argv[])
 
 	ret = barebox_update(&data);
 
-	free(data.image);
+	free(image);
 
 	return ret;
 }
-- 
2.15.1


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

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

* [PATCH 4/6] bbu: Make pointer to image const
  2018-01-30  8:46 [PATCH 0/6] bbu: Make image pointer const Sascha Hauer
                   ` (2 preceding siblings ...)
  2018-01-30  8:46 ` [PATCH 3/6] bbu: command: create temporary variable holding the pointer to the image Sascha Hauer
@ 2018-01-30  8:46 ` Sascha Hauer
  2018-01-30  8:46 ` [PATCH 5/6] usb: gadget: fastboot: allow data.image to be const Sascha Hauer
  2018-01-30  8:46 ` [PATCH 6/6] ARM: am33xx: bbu: Make pointers to image const Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2018-01-30  8:46 UTC (permalink / raw)
  To: Barebox List

Make pointer to image in bbu data const so that we can put
const pointers into that.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/bbu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/bbu.h b/include/bbu.h
index a3824e11cf..def568e498 100644
--- a/include/bbu.h
+++ b/include/bbu.h
@@ -11,7 +11,7 @@ struct bbu_data {
 #define BBU_FLAG_YES	(1 << 1)
 	unsigned long flags;
 	int force;
-	void *image;
+	const void *image;
 	const char *imagefile;
 	const char *devicefile;
 	size_t len;
-- 
2.15.1


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

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

* [PATCH 5/6] usb: gadget: fastboot: allow data.image to be const
  2018-01-30  8:46 [PATCH 0/6] bbu: Make image pointer const Sascha Hauer
                   ` (3 preceding siblings ...)
  2018-01-30  8:46 ` [PATCH 4/6] bbu: Make pointer to image const Sascha Hauer
@ 2018-01-30  8:46 ` Sascha Hauer
  2018-01-30  8:46 ` [PATCH 6/6] ARM: am33xx: bbu: Make pointers to image const Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2018-01-30  8:46 UTC (permalink / raw)
  To: Barebox List

Do not directly store the dynamically allocated memory in data.image
as we want to make that pointer const and then no longer can call
free() on it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/gadget/f_fastboot.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 2ba5977239..87a43cc60e 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -935,6 +935,7 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd
 	}
 
 	if (IS_ENABLED(CONFIG_BAREBOX_UPDATE) && filetype_is_barebox_image(filetype)) {
+		void *image;
 		struct bbu_data data = {
 			.devicefile = filename,
 			.imagefile = FASTBOOT_TMPFILE,
@@ -946,15 +947,17 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd
 
 		fastboot_tx_print(f_fb, "INFOThis is a barebox image...");
 
-		data.image = read_file(data.imagefile, &data.len);
-		if (!data.image) {
+		image = read_file(data.imagefile, &data.len);
+		if (!image) {
 			fastboot_tx_print(f_fb, "FAILreading barebox");
 			return;
 		}
 
+		data.image = image;
+
 		ret = barebox_update(&data);
 
-		free(data.image);
+		free(image);
 
 		if (ret) {
 			fastboot_tx_print(f_fb, "FAILupdate barebox: %s", strerror(-ret));
-- 
2.15.1


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

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

* [PATCH 6/6] ARM: am33xx: bbu: Make pointers to image const
  2018-01-30  8:46 [PATCH 0/6] bbu: Make image pointer const Sascha Hauer
                   ` (4 preceding siblings ...)
  2018-01-30  8:46 ` [PATCH 5/6] usb: gadget: fastboot: allow data.image to be const Sascha Hauer
@ 2018-01-30  8:46 ` Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2018-01-30  8:46 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-omap/am33xx_bbu_spi_mlo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
index 69a73ffb06..03477dbaf1 100644
--- a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
+++ b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
@@ -32,8 +32,8 @@ static int spi_nor_mlo_handler(struct bbu_handler *handler,
 	int ret = 0;
 	uint32_t readbuf;
 	int size = data->len;
-	void *image = data->image;
-	uint32_t *header;
+	const void *image = data->image;
+	const uint32_t *header;
 	int swap = 0;
 	struct stat s;
 
-- 
2.15.1


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

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

end of thread, other threads:[~2018-01-30  8:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-30  8:46 [PATCH 0/6] bbu: Make image pointer const Sascha Hauer
2018-01-30  8:46 ` [PATCH 1/6] bbu: imx-bbu-internal: Do not modify image Sascha Hauer
2018-01-30  8:46 ` [PATCH 2/6] bbu: imx-bbu-internal: make pointers to image const Sascha Hauer
2018-01-30  8:46 ` [PATCH 3/6] bbu: command: create temporary variable holding the pointer to the image Sascha Hauer
2018-01-30  8:46 ` [PATCH 4/6] bbu: Make pointer to image const Sascha Hauer
2018-01-30  8:46 ` [PATCH 5/6] usb: gadget: fastboot: allow data.image to be const Sascha Hauer
2018-01-30  8:46 ` [PATCH 6/6] ARM: am33xx: bbu: Make pointers to image const Sascha Hauer

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