mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] scripts: imx-image: Do not pad image
@ 2015-07-15  6:02 Sascha Hauer
  2015-07-15  6:02 ` [PATCH 2/2] scripts: imx-image: Make in-place capable Sascha Hauer
  2015-07-15 11:10 ` [PATCH 1/2] scripts: imx-image: Do not pad image Marc Kleine-Budde
  0 siblings, 2 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-07-15  6:02 UTC (permalink / raw)
  To: Barebox List

We have to pad the load size to the next 4k boundary, but we don't
need to pad the image itself since we do not care what data the ROM
actually loads.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/imx/imx-image.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index e765c1d..a588882 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -823,18 +823,6 @@ int main(int argc, char *argv[])
 		image_size -= now;
 	}
 
-	/* pad until next 4k boundary */
-	now = 4096 - now;
-	if (now) {
-		memset(buf, 0x5a, now);
-
-		ret = xwrite(outfd, buf, now);
-		if (ret) {
-			perror("write");
-			exit(1);
-		}
-	}
-
 	ret = close(outfd);
 	if (ret) {
 		perror("close");
-- 
2.1.4


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

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

* [PATCH 2/2] scripts: imx-image: Make in-place capable
  2015-07-15  6:02 [PATCH 1/2] scripts: imx-image: Do not pad image Sascha Hauer
@ 2015-07-15  6:02 ` Sascha Hauer
  2015-07-15 11:10 ` [PATCH 1/2] scripts: imx-image: Do not pad image Marc Kleine-Budde
  1 sibling, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-07-15  6:02 UTC (permalink / raw)
  To: Barebox List

Read in the source image completely before starting to write the output
image. This makes it possible to pass the same file as input and output.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/imx/imx-image.c | 46 +++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index a588882..c13e059 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -666,11 +666,11 @@ int main(int argc, char *argv[])
 	char *imagename = NULL;
 	char *outfile = NULL;
 	void *buf;
-	size_t image_size = 0, load_size;
+	size_t image_size = 0, load_size, insize;
+	void *infile;
 	struct stat s;
 	int infd, outfd;
 	int dcd_only = 0;
-	int now = 0;
 
 	while ((opt = getopt(argc, argv, "c:hf:o:bdp")) != -1) {
 		switch (opt) {
@@ -779,6 +779,24 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
+	infd = open(imagename, O_RDONLY);
+	if (infd < 0) {
+		perror("open");
+		exit(1);
+	}
+
+	ret = fstat(infd, &s);
+	if (ret)
+		return ret;
+
+	insize = s.st_size;
+	infile = malloc(insize);
+	if (!infile)
+		exit(1);
+
+	xread(infd, infile, insize);
+	close(infd);
+
 	outfd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
 	if (outfd < 0) {
 		perror("open");
@@ -799,30 +817,12 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	infd = open(imagename, O_RDONLY);
-	if (infd < 0) {
-		perror("open");
+	ret = xwrite(outfd, infile, insize);
+	if (ret) {
+		perror("write");
 		exit(1);
 	}
 
-	while (image_size) {
-		now = image_size < 4096 ? image_size : 4096;
-
-		ret = xread(infd, buf, now);
-		if (ret) {
-			perror("read");
-			exit(1);
-		}
-
-		ret = xwrite(outfd, buf, now);
-		if (ret) {
-			perror("write");
-			exit(1);
-		}
-
-		image_size -= now;
-	}
-
 	ret = close(outfd);
 	if (ret) {
 		perror("close");
-- 
2.1.4


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

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

* Re: [PATCH 1/2] scripts: imx-image: Do not pad image
  2015-07-15  6:02 [PATCH 1/2] scripts: imx-image: Do not pad image Sascha Hauer
  2015-07-15  6:02 ` [PATCH 2/2] scripts: imx-image: Make in-place capable Sascha Hauer
@ 2015-07-15 11:10 ` Marc Kleine-Budde
  2015-07-15 12:06   ` Sascha Hauer
  1 sibling, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2015-07-15 11:10 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List


[-- Attachment #1.1: Type: text/plain, Size: 586 bytes --]

On 07/15/2015 08:02 AM, Sascha Hauer wrote:
> We have to pad the load size to the next 4k boundary, but we don't
> need to pad the image itself since we do not care what data the ROM
> actually loads.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

NACK - We do for the HABv4 case.

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: 455 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] 6+ messages in thread

* Re: [PATCH 1/2] scripts: imx-image: Do not pad image
  2015-07-15 11:10 ` [PATCH 1/2] scripts: imx-image: Do not pad image Marc Kleine-Budde
@ 2015-07-15 12:06   ` Sascha Hauer
  2015-07-15 12:09     ` Marc Kleine-Budde
  0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2015-07-15 12:06 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: Barebox List

On Wed, Jul 15, 2015 at 01:10:41PM +0200, Marc Kleine-Budde wrote:
> On 07/15/2015 08:02 AM, Sascha Hauer wrote:
> > We have to pad the load size to the next 4k boundary, but we don't
> > need to pad the image itself since we do not care what data the ROM
> > actually loads.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> 
> NACK - We do for the HABv4 case.

Hm, I just wanted to make that optional, the first option letter that
came to my mind was -p for padding. Shortly afterwards I noticed this already exists
and is for: "-p           prepare image for signing". Can we attach the
padding to this option?

Sascha

-- 
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] 6+ messages in thread

* Re: [PATCH 1/2] scripts: imx-image: Do not pad image
  2015-07-15 12:06   ` Sascha Hauer
@ 2015-07-15 12:09     ` Marc Kleine-Budde
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2015-07-15 12:09 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List


[-- Attachment #1.1: Type: text/plain, Size: 1052 bytes --]

On 07/15/2015 02:06 PM, Sascha Hauer wrote:
> On Wed, Jul 15, 2015 at 01:10:41PM +0200, Marc Kleine-Budde wrote:
>> On 07/15/2015 08:02 AM, Sascha Hauer wrote:
>>> We have to pad the load size to the next 4k boundary, but we don't
>>> need to pad the image itself since we do not care what data the ROM
>>> actually loads.
>>>
>>> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
>>
>> NACK - We do for the HABv4 case.
> 
> Hm, I just wanted to make that optional, the first option letter that
> came to my mind was -p for padding. Shortly afterwards I noticed this already exists
> and is for: "-p           prepare image for signing". Can we attach the
> padding to this option?

sure - I'll test with my HAB usecase after you send me a patch.

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: 455 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] 6+ messages in thread

* [PATCH 1/2] scripts: imx-image: Do not pad image
  2015-07-16  7:48 [PATCH v2]: imx-image changes Sascha Hauer
@ 2015-07-16  7:48 ` Sascha Hauer
  0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-07-16  7:48 UTC (permalink / raw)
  To: Barebox List

We have to pad the load size to the next 4k boundary, but only for the
HAB4 case we actually care what data is loaded in the rest of the image.
This lets the padding depend on the prepare_sign option.

Background for this patch is a new yet-to-be-introduced image loading
mechanism for i.MX. This new mechanism only loads the PBL portion of
the image to memory, and not the whole image anymore. This means that
the image in this case changes from:

i.MX header (with loadsize: whole image), PBL, payload, padding

to:

i.MX header (with loadsize: header + PBL + padding), PBL, padding, payload

With the padding between PBL and payload we are no longer able to find
the payload, so we cannot add the padding there.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/imx/imx-image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index e765c1d..f0e8ca3 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -825,7 +825,7 @@ int main(int argc, char *argv[])
 
 	/* pad until next 4k boundary */
 	now = 4096 - now;
-	if (now) {
+	if (prepare_sign && now) {
 		memset(buf, 0x5a, now);
 
 		ret = xwrite(outfd, buf, now);
-- 
2.1.4


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

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

end of thread, other threads:[~2015-07-16  7:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-15  6:02 [PATCH 1/2] scripts: imx-image: Do not pad image Sascha Hauer
2015-07-15  6:02 ` [PATCH 2/2] scripts: imx-image: Make in-place capable Sascha Hauer
2015-07-15 11:10 ` [PATCH 1/2] scripts: imx-image: Do not pad image Marc Kleine-Budde
2015-07-15 12:06   ` Sascha Hauer
2015-07-15 12:09     ` Marc Kleine-Budde
2015-07-16  7:48 [PATCH v2]: imx-image changes Sascha Hauer
2015-07-16  7:48 ` [PATCH 1/2] scripts: imx-image: Do not pad image Sascha Hauer

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