mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/4] scripts/kwbimage: fix handling of binary header
@ 2016-11-16  9:52 Uwe Kleine-König
  2016-11-16  9:52 ` [PATCH v2 2/4] scripts/kwbimage: fix typo Uwe Kleine-König
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2016-11-16  9:52 UTC (permalink / raw)
  To: barebox

A binary header is 12 bytes + (4 bytes * Number of Arguments) bigger
than the actual binary. Before this commit image extraction was wrong an
made binary.0 too big by four bytes at the end (which were 0 in all usual
cases). Image creation had the same problem which resulted in broken
images when the binary doesn't end in 4 bytes containing 0.

Further handle binaries with a length that is not aligned to 4 bytes.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Changes since (implicit) v1:
 - make it patch 1 as it is a fix

 scripts/kwbimage.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index 448ac2a5d416..c560f581a727 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -490,7 +490,7 @@ static int image_extract_binary_hdr_v1(const void *binary, const char *output,
 	}
 
 	ret = fwrite(binary + (nargs + 1) * sizeof(unsigned int),
-		     binsz - (nargs + 1) * sizeof(unsigned int), 1,
+		     binsz - (nargs + 2) * sizeof(unsigned int), 1,
 		     binaryout);
 	if (ret != 1) {
 		fprintf(stderr, "Could not write to output file %s\n",
@@ -869,8 +869,8 @@ static void *image_create_v1(struct image_cfg_element *image_cfg,
 			return NULL;
 		}
 
-		headersz += s.st_size +
-			binarye->binary.nargs * sizeof(unsigned int);
+		headersz += ALIGN_SUP(s.st_size, 4) +
+			12 + binarye->binary.nargs * sizeof(unsigned int);
 		hasext = 1;
 	}
 
@@ -951,8 +951,8 @@ static void *image_create_v1(struct image_cfg_element *image_cfg,
 		fstat(fileno(bin), &s);
 
 		binhdrsz = sizeof(struct opt_hdr_v1) +
-			(binarye->binary.nargs + 1) * sizeof(unsigned int) +
-			s.st_size;
+			(binarye->binary.nargs + 2) * sizeof(unsigned int) +
+			ALIGN_SUP(s.st_size, 4);
 		hdr->headersz_lsb = binhdrsz & 0xFFFF;
 		hdr->headersz_msb = (binhdrsz & 0xFFFF0000) >> 16;
 
@@ -976,7 +976,7 @@ static void *image_create_v1(struct image_cfg_element *image_cfg,
 
 		fclose(bin);
 
-		cur += s.st_size;
+		cur += ALIGN_SUP(s.st_size, 4);
 
 		/*
 		 * For now, we don't support more than one binary
-- 
2.10.2


_______________________________________________
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:[~2016-11-17  6:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-16  9:52 [PATCH v2 1/4] scripts/kwbimage: fix handling of binary header Uwe Kleine-König
2016-11-16  9:52 ` [PATCH v2 2/4] scripts/kwbimage: fix typo Uwe Kleine-König
2016-11-16  9:52 ` [PATCH v2 3/4] scripts/kwbimage: use ALIGN_SUP instead of open-coding it Uwe Kleine-König
2016-11-16  9:52 ` [PATCH v2 4/4] scripts/kwbimage: allow to overwrite binary Uwe Kleine-König
2016-11-17  6:58 ` [PATCH v2 1/4] scripts/kwbimage: fix handling of binary header Sascha Hauer

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