mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] scripts: fix_size: check magic
@ 2014-01-29 11:05 Sascha Hauer
  2014-01-29 11:05 ` [PATCH 2/3] images: fix image size in pblx Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2014-01-29 11:05 UTC (permalink / raw)
  To: barebox

Instead of passing the offset to the fix_size tool check the image to
fixup for a valid header so that only recognized files are fixed up.
This makes the usage of this tool safer.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/pbl/Makefile |  2 +-
 scripts/fix_size.c    | 32 +++++++++++++++++++++++++-------
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/arch/arm/pbl/Makefile b/arch/arm/pbl/Makefile
index bfa73b9..5e90f3d 100644
--- a/arch/arm/pbl/Makefile
+++ b/arch/arm/pbl/Makefile
@@ -23,7 +23,7 @@ $(obj)/zbarebox.bin:	$(obj)/zbarebox FORCE
 	$(call if_changed,objcopy)
 	$(call cmd,check_file_size,$(CONFIG_BAREBOX_MAX_IMAGE_SIZE))
 	$(Q)$(kecho) '  Barebox: fix size'
-	$(Q)$(objtree)/scripts/fix_size -f $(objtree)/$@ -o 0x2c $(FIX_SIZE)
+	$(Q)$(objtree)/scripts/fix_size -f $(objtree)/$@ $(FIX_SIZE)
 	$(Q)$(kecho) '  Barebox: $@ is ready'
 
 $(obj)/zbarebox.S: $(obj)/zbarebox FORCE
diff --git a/scripts/fix_size.c b/scripts/fix_size.c
index 869ae7e..1daf5fc 100644
--- a/scripts/fix_size.c
+++ b/scripts/fix_size.c
@@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <string.h>
 #include <unistd.h>
 #include <stdint.h>
 #include <fcntl.h>
@@ -15,20 +16,17 @@ int main(int argc, char**argv)
 	struct stat s;
 	int c;
 	int fd;
-	uint64_t offset = 0;
 	uint32_t size = 0;
 	char *file = NULL;
 	int ret = 1;
 	int is_bigendian = 0;
+	char magic[8];
 
-	while ((c = getopt (argc, argv, "hf:o:b")) != -1) {
+	while ((c = getopt (argc, argv, "hf:b")) != -1) {
 		switch (c) {
 		case 'f':
 			file = optarg;
 			break;
-		case 'o':
-			offset = strtoul(optarg, NULL, 16);
-			break;
 		case 'b':
 			is_bigendian = 1;
 			break;
@@ -45,13 +43,33 @@ int main(int argc, char**argv)
 		return 1;
 	}
 
-	fd = open(file, O_WRONLY);
+	fd = open(file, O_RDWR);
 	if (fd < 0) {
 		perror("open");
 		return 1;
 	}
 
-	ret = lseek(fd, offset, SEEK_SET);
+	ret = lseek(fd, 0x20, SEEK_SET);
+	if (ret < 0) {
+		perror("lseek");
+		ret = 1;
+		goto err;
+	}
+
+	ret = read(fd, magic, sizeof(magic));
+	if (ret < 0) {
+		perror("read");
+		ret = 1;
+		goto err;
+	}
+
+	if (strcmp(magic, "barebox")) {
+		fprintf(stderr, "invalid magic\n");
+		ret = 1;
+		goto err;
+	}
+
+	ret = lseek(fd, 0x2c, SEEK_SET);
 	if (ret < 0) {
 		perror("lseek");
 		ret = 1;
-- 
1.8.5.3


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

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

* [PATCH 2/3] images: fix image size in pblx
  2014-01-29 11:05 [PATCH 1/3] scripts: fix_size: check magic Sascha Hauer
@ 2014-01-29 11:05 ` Sascha Hauer
  2014-01-29 11:05 ` [PATCH 3/3] ARM: i.MX: external NAND boot: use image size from image header Sascha Hauer
  2014-01-31 17:57 ` [PATCH 1/3] scripts: fix_size: check magic Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2014-01-29 11:05 UTC (permalink / raw)
  To: barebox

The pblx is a self extracting barebox binary. This doesn't have
the size of the image correctly set because the linker doesn't
generate it for relocatable binaries.
This currently only works on ARM, but this is the only architecture
supporting multi images anyway. TO make it work on other architectures
fix_size would have to be extended to recognize other images.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 images/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/images/Makefile b/images/Makefile
index 4ff0602..3e707e8 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -70,7 +70,8 @@ $(obj)/%.pblb: $(obj)/%.pbl FORCE
 quiet_cmd_pblx ?= PBLX    $@
       cmd_pblx ?= cat $(obj)/$(patsubst %.pblx,%.pblb,$(2)) > $@; \
 		  $(call size_append, $(obj)/barebox.z) >> $@; \
-		  cat $(obj)/barebox.z >> $@
+		  cat $(obj)/barebox.z >> $@; \
+		  $(objtree)/scripts/fix_size -f $@
 
 $(obj)/%.pblx: $(obj)/%.pblb $(obj)/barebox.z FORCE
 	$(call if_changed,pblx,$(@F))
-- 
1.8.5.3


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

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

* [PATCH 3/3] ARM: i.MX: external NAND boot: use image size from image header
  2014-01-29 11:05 [PATCH 1/3] scripts: fix_size: check magic Sascha Hauer
  2014-01-29 11:05 ` [PATCH 2/3] images: fix image size in pblx Sascha Hauer
@ 2014-01-29 11:05 ` Sascha Hauer
  2014-01-31 17:57 ` [PATCH 1/3] scripts: fix_size: check magic Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2014-01-29 11:05 UTC (permalink / raw)
  To: barebox

When compiling with multiimage support ld_var(_barebox_image_size) only
contains the length of the PBL image, but not including the appended
compressed data. With this patch the image size is read from the barebox
header instead which contains the correct size, either from the linker
or from the fix_size tool.
This makes the external_nand_boot compatible with multiimage support.

Tested on Phytec phyCARD-i.MX27 with and without PBL.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/external-nand-boot.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-imx/external-nand-boot.c b/arch/arm/mach-imx/external-nand-boot.c
index fab37bf..c08806c 100644
--- a/arch/arm/mach-imx/external-nand-boot.c
+++ b/arch/arm/mach-imx/external-nand-boot.c
@@ -322,10 +322,13 @@ void __noreturn BARE_INIT_FUNCTION(imx##soc##_boot_nand_external_cont)  \
 			(uint32_t boarddata)				\
 {									\
 	unsigned long nfc_base = MX##soc##_NFC_BASE_ADDR;		\
-	unsigned long sdram = MX##soc##_CSD0_BASE_ADDR;			\
+	void *sdram = (void *)MX##soc##_CSD0_BASE_ADDR;			\
+	uint32_t image_size;						\
+									\
+	image_size = *(uint32_t *)(sdram + 0x2c);			\
 									\
-	imx##soc##_nand_load_image((void *)sdram,			\
-			ld_var(_barebox_image_size),			\
+	imx##soc##_nand_load_image(sdram,				\
+			image_size,					\
 			(void *)nfc_base,				\
 			imx##soc##_pagesize_2k());			\
 									\
-- 
1.8.5.3


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

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

* Re: [PATCH 1/3] scripts: fix_size: check magic
  2014-01-29 11:05 [PATCH 1/3] scripts: fix_size: check magic Sascha Hauer
  2014-01-29 11:05 ` [PATCH 2/3] images: fix image size in pblx Sascha Hauer
  2014-01-29 11:05 ` [PATCH 3/3] ARM: i.MX: external NAND boot: use image size from image header Sascha Hauer
@ 2014-01-31 17:57 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2014-01-31 17:57 UTC (permalink / raw)
  To: barebox

On Wed, Jan 29, 2014 at 12:05:06PM +0100, Sascha Hauer wrote:
> Instead of passing the offset to the fix_size tool check the image to
> fixup for a valid header so that only recognized files are fixed up.
> This makes the usage of this tool safer.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/pbl/Makefile |  2 +-
>  scripts/fix_size.c    | 32 +++++++++++++++++++++++++-------
>  2 files changed, 26 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/arm/pbl/Makefile b/arch/arm/pbl/Makefile
> index bfa73b9..5e90f3d 100644
> --- a/arch/arm/pbl/Makefile
> +++ b/arch/arm/pbl/Makefile
> @@ -23,7 +23,7 @@ $(obj)/zbarebox.bin:	$(obj)/zbarebox FORCE
>  	$(call if_changed,objcopy)
>  	$(call cmd,check_file_size,$(CONFIG_BAREBOX_MAX_IMAGE_SIZE))
>  	$(Q)$(kecho) '  Barebox: fix size'
> -	$(Q)$(objtree)/scripts/fix_size -f $(objtree)/$@ -o 0x2c $(FIX_SIZE)
> +	$(Q)$(objtree)/scripts/fix_size -f $(objtree)/$@ $(FIX_SIZE)

I had to squash in a -i option to ignore invalid headers and return
successfully instead of failing. This is necessary for zynq which
doesn't generate an image with a barebox header but instead with a zynq
header. Before this patch fix_size silently corrupted the image.

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

end of thread, other threads:[~2014-01-31 17:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-29 11:05 [PATCH 1/3] scripts: fix_size: check magic Sascha Hauer
2014-01-29 11:05 ` [PATCH 2/3] images: fix image size in pblx Sascha Hauer
2014-01-29 11:05 ` [PATCH 3/3] ARM: i.MX: external NAND boot: use image size from image header Sascha Hauer
2014-01-31 17:57 ` [PATCH 1/3] scripts: fix_size: check magic Sascha Hauer

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