mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] scripts: kwboot: fix missing soh initialization
@ 2013-11-12 20:58 Sebastian Hesselbarth
  2013-11-12 20:58 ` [PATCH 2/2] scripts: kwbimage: fix mis-sized payload Sebastian Hesselbarth
  2013-11-18  9:53 ` [PATCH 1/2] scripts: kwboot: fix missing soh initialization Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Sebastian Hesselbarth @ 2013-11-12 20:58 UTC (permalink / raw)
  To: Sebastian Hesselbarth; +Cc: Thomas Petazzoni, barebox

Xmodem blocks should start with SOH but kwboot never sets the first
block byte. This fixes kwboot's Xmodem block initialization and sets
first block byte to SOH.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 scripts/kwboot.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/kwboot.c b/scripts/kwboot.c
index 33c94b3..81da3e8 100644
--- a/scripts/kwboot.c
+++ b/scripts/kwboot.c
@@ -334,6 +334,7 @@ kwboot_xm_makeblock(struct kwboot_block *block, const void *data,
 	size_t n;
 	int i;
 
+	block->soh = SOH;
 	block->pnum = pnum;
 	block->_pnum = ~block->pnum;
 
-- 
1.7.10.4


_______________________________________________
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/2] scripts: kwbimage: fix mis-sized payload
  2013-11-12 20:58 [PATCH 1/2] scripts: kwboot: fix missing soh initialization Sebastian Hesselbarth
@ 2013-11-12 20:58 ` Sebastian Hesselbarth
  2013-11-18  9:53 ` [PATCH 1/2] scripts: kwboot: fix missing soh initialization Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sebastian Hesselbarth @ 2013-11-12 20:58 UTC (permalink / raw)
  To: Sebastian Hesselbarth; +Cc: Thomas Petazzoni, barebox

Image payload size should always be a multiple of 4 bytes. This fixes
mis-sized image payload by allocating payload buffer as multiple of 4
but load true filesize into the payload buffer.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 scripts/kwbimage.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index 4ebb07f..82cf21c 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -685,6 +685,7 @@ static int image_create_payload(void *payload_start, size_t payloadsz,
 				const char *payload_filename)
 {
 	FILE *payload;
+	struct stat s;
 	uint32_t *payload_checksum =
 		(uint32_t *) (payload_start + payloadsz);
 	int ret;
@@ -696,7 +697,14 @@ static int image_create_payload(void *payload_start, size_t payloadsz,
 		return -1;
 	}
 
-	ret = fread(payload_start, payloadsz, 1, payload);
+	ret = stat(payload_filename, &s);
+	if (ret < 0) {
+		fprintf(stderr, "Cannot stat payload file %s\n",
+			payload_filename);
+		return ret;
+	}
+
+	ret = fread(payload_start, s.st_size, 1, payload);
 	if (ret != 1) {
 		fprintf(stderr, "Cannot read payload file %s\n",
 			payload_filename);
@@ -747,7 +755,8 @@ static void *image_create_v0(struct image_cfg_element *image_cfg,
 			return NULL;
 		}
 
-		payloadsz = s.st_size;
+		/* payload size must be multiple of 32b */
+		payloadsz = 4 * ((s.st_size + 3)/4);
 	}
 
 	/* Headers, payload and 32-bits checksum */
@@ -875,7 +884,8 @@ static void *image_create_v1(struct image_cfg_element *image_cfg,
 			return NULL;
 		}
 
-		payloadsz = s.st_size;
+		/* payload size must be multiple of 32b */
+		payloadsz = 4 * ((s.st_size + 3)/4);
 	}
 
 	/* The payload should be aligned on some reasonable
-- 
1.7.10.4


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

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

* Re: [PATCH 1/2] scripts: kwboot: fix missing soh initialization
  2013-11-12 20:58 [PATCH 1/2] scripts: kwboot: fix missing soh initialization Sebastian Hesselbarth
  2013-11-12 20:58 ` [PATCH 2/2] scripts: kwbimage: fix mis-sized payload Sebastian Hesselbarth
@ 2013-11-18  9:53 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2013-11-18  9:53 UTC (permalink / raw)
  To: Sebastian Hesselbarth; +Cc: Thomas Petazzoni, barebox

On Tue, Nov 12, 2013 at 09:58:03PM +0100, Sebastian Hesselbarth wrote:
> Xmodem blocks should start with SOH but kwboot never sets the first
> block byte. This fixes kwboot's Xmodem block initialization and sets
> first block byte to SOH.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>

Applied, thanks

Sascha

> ---
> Cc: barebox@lists.infradead.org
> Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> ---
>  scripts/kwboot.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/scripts/kwboot.c b/scripts/kwboot.c
> index 33c94b3..81da3e8 100644
> --- a/scripts/kwboot.c
> +++ b/scripts/kwboot.c
> @@ -334,6 +334,7 @@ kwboot_xm_makeblock(struct kwboot_block *block, const void *data,
>  	size_t n;
>  	int i;
>  
> +	block->soh = SOH;
>  	block->pnum = pnum;
>  	block->_pnum = ~block->pnum;
>  
> -- 
> 1.7.10.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] 3+ messages in thread

end of thread, other threads:[~2013-11-18  9:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-12 20:58 [PATCH 1/2] scripts: kwboot: fix missing soh initialization Sebastian Hesselbarth
2013-11-12 20:58 ` [PATCH 2/2] scripts: kwbimage: fix mis-sized payload Sebastian Hesselbarth
2013-11-18  9:53 ` [PATCH 1/2] scripts: kwboot: fix missing soh initialization Sascha Hauer

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