* [PATCH v2 3/8] bootstrap_read_devfs(): Check for errors from devfs_add_partition()
2015-05-03 21:55 [PATCH v2 1/8] imx-image: Correctly fill image size in prepended header Andrey Smirnov
@ 2015-05-03 21:55 ` Andrey Smirnov
2015-05-03 21:55 ` [PATCH v2 5/8] bootstrap_read_devfs(): Fix potential memory leak Andrey Smirnov
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Andrey Smirnov @ 2015-05-03 21:55 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Check for errors returned by devfs_add_partition() and bail if there
are any.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
Changes since v1:
- Fix a compile time error that snuck in during the time the diff was
being split into multiple patches
lib/bootstrap/devfs.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lib/bootstrap/devfs.c b/lib/bootstrap/devfs.c
index 82c7d21..ff0540f 100644
--- a/lib/bootstrap/devfs.c
+++ b/lib/bootstrap/devfs.c
@@ -82,10 +82,17 @@ void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,
int ret;
int size = 0;
void *to, *header;
- struct cdev *cdev;
+ struct cdev *cdev, *partition;
char *partname = "x";
- devfs_add_partition(devname, offset, max_size, DEVFS_PARTITION_FIXED, partname);
+ partition = devfs_add_partition(devname, offset, max_size,
+ DEVFS_PARTITION_FIXED, partname);
+ if (IS_ERR_OR_NULL(partition)) {
+ bootstrap_err("%s: failed to add partition (%ld)\n",
+ devname, PTR_ERR(partition));
+ return NULL;
+ }
+
if (use_bb) {
dev_add_bb_dev(partname, "bbx");
partname = "bbx";
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 5/8] bootstrap_read_devfs(): Fix potential memory leak
2015-05-03 21:55 [PATCH v2 1/8] imx-image: Correctly fill image size in prepended header Andrey Smirnov
2015-05-03 21:55 ` [PATCH v2 3/8] bootstrap_read_devfs(): Check for errors from devfs_add_partition() Andrey Smirnov
@ 2015-05-03 21:55 ` Andrey Smirnov
2015-05-03 21:55 ` [PATCH v2 7/8] bootstrap_read_devfs(): Remove all partitions upon function completion Andrey Smirnov
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Andrey Smirnov @ 2015-05-03 21:55 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
In case of a failure in one of the cdev_* functions original version
of bootstrap_read_devfs would not release memory allocated for barebox
header or memory allocated for the image. This commit fixes this by
adding resource deallocation code.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
Changes since v1:
- Fix a compile time error that snuck in during the time the diff was
being split into multiple patches
lib/bootstrap/devfs.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/lib/bootstrap/devfs.c b/lib/bootstrap/devfs.c
index 3c4276f..05a6346 100644
--- a/lib/bootstrap/devfs.c
+++ b/lib/bootstrap/devfs.c
@@ -81,7 +81,7 @@ void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,
{
int ret;
int size = 0;
- void *to, *header;
+ void *to, *header, *result = NULL;
struct cdev *cdev, *partition;
char *partname = "x";
@@ -116,16 +116,21 @@ void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,
cdev = cdev_open(partname, O_RDONLY);
if (!cdev) {
bootstrap_err("%s: failed to open %s\n", devname, partname);
- return NULL;
+ goto free_memory;
}
ret = cdev_read(cdev, to, size, 0, 0);
cdev_close(cdev);
- if (ret != size) {
+ if (ret != size)
bootstrap_err("%s: failed to read from %s\n", devname, partname);
- return NULL;
- }
+ else
+ result = to;
+
+free_memory:
+ free(header);
+ if (!result)
+ free(to);
- return to;
+ return result;
}
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 7/8] bootstrap_read_devfs(): Remove all partitions upon function completion
2015-05-03 21:55 [PATCH v2 1/8] imx-image: Correctly fill image size in prepended header Andrey Smirnov
2015-05-03 21:55 ` [PATCH v2 3/8] bootstrap_read_devfs(): Check for errors from devfs_add_partition() Andrey Smirnov
2015-05-03 21:55 ` [PATCH v2 5/8] bootstrap_read_devfs(): Fix potential memory leak Andrey Smirnov
@ 2015-05-03 21:55 ` Andrey Smirnov
2015-05-03 22:05 ` [PATCH v2 1/8] imx-image: Correctly fill image size in prepended header Marc Kleine-Budde
2015-05-04 7:41 ` Sascha Hauer
4 siblings, 0 replies; 7+ messages in thread
From: Andrey Smirnov @ 2015-05-03 21:55 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Bootstrap_read_devfs does not remove the devices it creates during the
course of its execution which might be considered as a resource
leak. Remedy that by adding the code to remove those devices upon
function completion.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
Changes since v1:
- Fix a compile time error that snuck in during the time the diff was
being split into multiple patches
lib/bootstrap/devfs.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/lib/bootstrap/devfs.c b/lib/bootstrap/devfs.c
index df4840e..e9bd2bb 100644
--- a/lib/bootstrap/devfs.c
+++ b/lib/bootstrap/devfs.c
@@ -99,7 +99,7 @@ void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,
bootstrap_err(
"%s: failed to add bad block aware partition (%d)\n",
devname, ret);
- goto exit;
+ goto delete_devfs_partition;
}
partname = "bbx";
@@ -138,6 +138,14 @@ free_memory:
free(header);
if (!result)
free(to);
-exit:
+
+ if (use_bb) {
+ dev_remove_bb_dev(partname);
+ partname = "x";
+ }
+
+delete_devfs_partition:
+ devfs_del_partition(partname);
+
return result;
}
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/8] imx-image: Correctly fill image size in prepended header
2015-05-03 21:55 [PATCH v2 1/8] imx-image: Correctly fill image size in prepended header Andrey Smirnov
` (2 preceding siblings ...)
2015-05-03 21:55 ` [PATCH v2 7/8] bootstrap_read_devfs(): Remove all partitions upon function completion Andrey Smirnov
@ 2015-05-03 22:05 ` Marc Kleine-Budde
[not found] ` <CAHQ1cqEoL1PD4Cg7G52YvosXmsmcg1jckGL9-65_J-=qHc3XvA@mail.gmail.com>
2015-05-04 7:41 ` Sascha Hauer
4 siblings, 1 reply; 7+ messages in thread
From: Marc Kleine-Budde @ 2015-05-03 22:05 UTC (permalink / raw)
To: Andrey Smirnov, barebox
[-- Attachment #1.1: Type: text/plain, Size: 2811 bytes --]
On 05/03/2015 11:55 PM, Andrey Smirnov wrote:
> If called with '-b' option 'imx-image' tool prepends barebox header to
> the image, but the tool does not fill the data at image size offset
> correctly. Fix that.
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>
> This patch supercedes the one sent earlier titled:
> "[PATCH 1/8] Makefile.lib: Fix i.MX image size after generation"
>
> scripts/imx/Makefile | 2 ++
> scripts/imx/imx-image.c | 12 ++++++++++--
> 2 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/imx/Makefile b/scripts/imx/Makefile
> index be0b490..ee0acc1 100644
> --- a/scripts/imx/Makefile
> +++ b/scripts/imx/Makefile
> @@ -6,5 +6,7 @@ always := $(hostprogs-y)
> HOSTCFLAGS_imx-usb-loader.o = `pkg-config --cflags libusb-1.0`
> HOSTLOADLIBES_imx-usb-loader = `pkg-config --libs libusb-1.0`
>
> +HOSTCFLAGS_imx-image.o = -I$(srctree)
> +
> imx-usb-loader-objs := imx-usb-loader.o
> imx-image-objs := imx-image.o
> diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
> index 25ea4d8..c0181df 100644
> --- a/scripts/imx/imx-image.c
> +++ b/scripts/imx/imx-image.c
> @@ -27,6 +27,8 @@
> #include <fcntl.h>
> #include <endian.h>
>
> +#include <include/filetype.h>
> +
> #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
> #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
> #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
> @@ -92,8 +94,11 @@ static int add_header_v1(void *buf, int offset, uint32_t loadaddr, uint32_t imag
> struct imx_flash_header *hdr;
> int dcdsize = curdcd * sizeof(uint32_t);
>
> - if (add_barebox_header)
> + if (add_barebox_header) {
> + uint32_t *psize = buf + ARM_HEAD_SIZE_OFFSET;
> memcpy(buf, bb_header, sizeof(bb_header));
> + *psize = imagesize;
> + }
>
> buf += offset;
> hdr = buf;
> @@ -178,8 +183,11 @@ static int add_header_v2(void *buf, int offset, uint32_t loadaddr, uint32_t imag
> struct imx_flash_header_v2 *hdr;
> int dcdsize = curdcd * sizeof(uint32_t);
>
> - if (add_barebox_header)
> + if (add_barebox_header) {
> + uint32_t *psize = buf + ARM_HEAD_SIZE_OFFSET;
> memcpy(buf, bb_header, sizeof(bb_header));
> + *psize = imagesize;
> + }
In the HAB case, the resulting image will be CSF_LEN bytes bigger, see:
"if (prepare_sign)" below. (A signature + padding will be appended to
the barebox image.)
What does the size in the barebox header mean exactly?
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
[-- Attachment #2: Type: text/plain, Size: 149 bytes --]
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/8] imx-image: Correctly fill image size in prepended header
2015-05-03 21:55 [PATCH v2 1/8] imx-image: Correctly fill image size in prepended header Andrey Smirnov
` (3 preceding siblings ...)
2015-05-03 22:05 ` [PATCH v2 1/8] imx-image: Correctly fill image size in prepended header Marc Kleine-Budde
@ 2015-05-04 7:41 ` Sascha Hauer
4 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2015-05-04 7:41 UTC (permalink / raw)
To: Andrey Smirnov; +Cc: barebox
It seems you only resent the patches from this series you actually
changed. Could you resent *all* patches again next time?
Sascha
On Sun, May 03, 2015 at 02:55:22PM -0700, Andrey Smirnov wrote:
> If called with '-b' option 'imx-image' tool prepends barebox header to
> the image, but the tool does not fill the data at image size offset
> correctly. Fix that.
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>
> This patch supercedes the one sent earlier titled:
> "[PATCH 1/8] Makefile.lib: Fix i.MX image size after generation"
>
> scripts/imx/Makefile | 2 ++
> scripts/imx/imx-image.c | 12 ++++++++++--
> 2 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/imx/Makefile b/scripts/imx/Makefile
> index be0b490..ee0acc1 100644
> --- a/scripts/imx/Makefile
> +++ b/scripts/imx/Makefile
> @@ -6,5 +6,7 @@ always := $(hostprogs-y)
> HOSTCFLAGS_imx-usb-loader.o = `pkg-config --cflags libusb-1.0`
> HOSTLOADLIBES_imx-usb-loader = `pkg-config --libs libusb-1.0`
>
> +HOSTCFLAGS_imx-image.o = -I$(srctree)
> +
> imx-usb-loader-objs := imx-usb-loader.o
> imx-image-objs := imx-image.o
> diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
> index 25ea4d8..c0181df 100644
> --- a/scripts/imx/imx-image.c
> +++ b/scripts/imx/imx-image.c
> @@ -27,6 +27,8 @@
> #include <fcntl.h>
> #include <endian.h>
>
> +#include <include/filetype.h>
> +
> #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
> #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
> #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
> @@ -92,8 +94,11 @@ static int add_header_v1(void *buf, int offset, uint32_t loadaddr, uint32_t imag
> struct imx_flash_header *hdr;
> int dcdsize = curdcd * sizeof(uint32_t);
>
> - if (add_barebox_header)
> + if (add_barebox_header) {
> + uint32_t *psize = buf + ARM_HEAD_SIZE_OFFSET;
> memcpy(buf, bb_header, sizeof(bb_header));
> + *psize = imagesize;
> + }
>
> buf += offset;
> hdr = buf;
> @@ -178,8 +183,11 @@ static int add_header_v2(void *buf, int offset, uint32_t loadaddr, uint32_t imag
> struct imx_flash_header_v2 *hdr;
> int dcdsize = curdcd * sizeof(uint32_t);
>
> - if (add_barebox_header)
> + if (add_barebox_header) {
> + uint32_t *psize = buf + ARM_HEAD_SIZE_OFFSET;
> memcpy(buf, bb_header, sizeof(bb_header));
> + *psize = imagesize;
> + }
>
> buf += offset;
> hdr = buf;
> --
> 2.1.4
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
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] 7+ messages in thread