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

---
 scripts/kwbimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index eabd09f45d42..15726e066a01 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -524,7 +524,7 @@ static int image_extract_v1(void *fdimap, const char *output, FILE *focfg)
 	int opthdrid;
 
 	/*
-	 * Verify the checkum. We have to substract the checksum
+	 * Verify the checksum. We have to subtract the checksum
 	 * itself, because when the checksum is calculated, the
 	 * checksum field is 0.
 	 */
-- 
2.10.2


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

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

* [PATCH 2/3] scripts/kwbimage: use ALIGN_SUP instead of open-coding it
  2016-11-16  9:11 [PATCH 1/3] scripts/kwbimage: fix typo Uwe Kleine-König
@ 2016-11-16  9:11 ` Uwe Kleine-König
  2016-11-16  9:11 ` [PATCH 3/3] scripts/kwbimage: fix handling of binary header Uwe Kleine-König
  1 sibling, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2016-11-16  9:11 UTC (permalink / raw)
  To: barebox

---
 scripts/kwbimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index 15726e066a01..57f563ece651 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -887,7 +887,7 @@ static void *image_create_v1(struct image_cfg_element *image_cfg,
 		}
 
 		/* payload size must be multiple of 32b */
-		payloadsz = 4 * ((s.st_size + 3)/4);
+		payloadsz = ALIGN_SUP(s.st_size, 4);
 	}
 
 	/* The payload should be aligned on some reasonable
-- 
2.10.2


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

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

* [PATCH 3/3] scripts/kwbimage: fix handling of binary header
  2016-11-16  9:11 [PATCH 1/3] scripts/kwbimage: fix typo Uwe Kleine-König
  2016-11-16  9:11 ` [PATCH 2/3] scripts/kwbimage: use ALIGN_SUP instead of open-coding it Uwe Kleine-König
@ 2016-11-16  9:11 ` Uwe Kleine-König
  1 sibling, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2016-11-16  9:11 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.

Note this is an incompatible change in the sense that a binary.0 that is
extracted with the new code cannot be used by the old code. The other
way around works however unless the image does very strange things.

If you find this commit during bisection, try appending 4 zero bytes to
your binary.0.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 scripts/kwbimage.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index 57f563ece651..5b84db3f7a23 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -491,7 +491,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",
@@ -870,8 +870,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;
 	}
 
@@ -952,8 +952,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;
 
@@ -977,7 +977,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] 3+ messages in thread

end of thread, other threads:[~2016-11-16  9:12 UTC | newest]

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

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