mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] arm: fix zImage support when a oftree is concatenated
@ 2012-04-11  6:38 Jean-Christophe PLAGNIOL-VILLARD
  2012-04-11  8:12 ` Sascha Hauer
  2012-04-11  9:13 ` [PATCH 1/1] arm: bootm: zImage allow to use the concataned oftree Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 2 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-11  6:38 UTC (permalink / raw)
  To: barebox

When a oftree is concatenated,the zImage is bigger than the size specified in
the zImage header. Detect it and copy it too.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/lib/bootm.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index defc89b..dc379d8 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -123,6 +123,51 @@ struct zimage_header {
 
 #define ZIMAGE_MAGIC 0x016F2818
 
+static int do_bootz_linux_fdt(int fd, struct image_data *data)
+{
+	struct fdt_header __header, *header;
+	struct resource *r = data->os_res;
+	struct resource *of_res = data->os_res;
+	void *oftree;
+	int ret;
+
+	u32 end;
+
+	header = &__header;
+	ret = read(fd, header, sizeof(*header));
+	if (ret < sizeof(*header))
+		return ret;
+
+	if (file_detect_type(header) != filetype_oftree)
+		return -ENXIO;
+
+	end = be32_to_cpu(header->totalsize);
+
+	of_res = request_sdram_region("oftree", r->start + r->size, end);
+	if (!of_res) {
+		perror("zImage: oftree request_sdram_region");
+		return -ENOMEM;
+	}
+
+	oftree = (void*)of_res->start;
+
+	memcpy(oftree, header, sizeof(*header));
+
+	end -= sizeof(*header);
+
+	ret = read_full(fd, oftree + sizeof(*header), end);
+	if (ret < 0)
+		return ret;
+	if (ret < end) {
+		printf("premature end of image\n");
+		return -EIO;
+	}
+
+	pr_info("zImage: concatenated oftree detected\n");
+
+	return 0;
+}
+
 static int do_bootz_linux(struct image_data *data)
 {
 	int fd, ret, swap = 0;
@@ -196,6 +241,10 @@ static int do_bootz_linux(struct image_data *data)
 			*(u32 *)ptr = swab32(*(u32 *)ptr);
 	}
 
+	ret = do_bootz_linux_fdt(fd, data);
+	if (ret && ret != -ENXIO)
+		return ret;
+
 	return __do_bootm_linux(data, swap);
 
 err_out:
-- 
1.7.9.1


_______________________________________________
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 v2] arm: fix zImage support when a oftree is concatenated
  2012-04-11  6:38 [PATCH v2] arm: fix zImage support when a oftree is concatenated Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-11  8:12 ` Sascha Hauer
  2012-04-11  8:20   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-11  9:13 ` [PATCH 1/1] arm: bootm: zImage allow to use the concataned oftree Jean-Christophe PLAGNIOL-VILLARD
  1 sibling, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2012-04-11  8:12 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Wed, Apr 11, 2012 at 08:38:18AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> When a oftree is concatenated,the zImage is bigger than the size specified in
> the zImage header. Detect it and copy it too.
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  arch/arm/lib/bootm.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 49 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
> index defc89b..dc379d8 100644
> --- a/arch/arm/lib/bootm.c
> +++ b/arch/arm/lib/bootm.c
> @@ -123,6 +123,51 @@ struct zimage_header {
>  
>  #define ZIMAGE_MAGIC 0x016F2818
>  
> +static int do_bootz_linux_fdt(int fd, struct image_data *data)
> +{
> +	struct fdt_header __header, *header;
> +	struct resource *r = data->os_res;
> +	struct resource *of_res = data->os_res;
> +	void *oftree;
> +	int ret;
> +
> +	u32 end;
> +
> +	header = &__header;
> +	ret = read(fd, header, sizeof(*header));
> +	if (ret < sizeof(*header))
> +		return ret;
> +
> +	if (file_detect_type(header) != filetype_oftree)
> +		return -ENXIO;
> +
> +	end = be32_to_cpu(header->totalsize);
> +
> +	of_res = request_sdram_region("oftree", r->start + r->size, end);
> +	if (!of_res) {
> +		perror("zImage: oftree request_sdram_region");
> +		return -ENOMEM;
> +	}
> +
> +	oftree = (void*)of_res->start;
> +
> +	memcpy(oftree, header, sizeof(*header));
> +
> +	end -= sizeof(*header);
> +
> +	ret = read_full(fd, oftree + sizeof(*header), end);
> +	if (ret < 0)
> +		return ret;
> +	if (ret < end) {
> +		printf("premature end of image\n");
> +		return -EIO;
> +	}

I am missing a call to of_fix_tree() here. Without it the command line
will not be passed to the kernel. Maybe this is not really the intended
usecase for appending an oftree to the zImage. Being able to append the
oftree to the zImage seems more for bootloaders which do not have native
support for devicetrees.

We could be more clever here and read the oftree to a seperately
allocated area and set data->oftree then.

Sascha

> +
> +	pr_info("zImage: concatenated oftree detected\n");
> +
> +	return 0;
> +}
> +
>  static int do_bootz_linux(struct image_data *data)
>  {
>  	int fd, ret, swap = 0;
> @@ -196,6 +241,10 @@ static int do_bootz_linux(struct image_data *data)
>  			*(u32 *)ptr = swab32(*(u32 *)ptr);
>  	}
>  
> +	ret = do_bootz_linux_fdt(fd, data);
> +	if (ret && ret != -ENXIO)
> +		return ret;
> +
>  	return __do_bootm_linux(data, swap);
>  
>  err_out:
> -- 
> 1.7.9.1
> 
> 
> _______________________________________________
> 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] 6+ messages in thread

* Re: [PATCH v2] arm: fix zImage support when a oftree is concatenated
  2012-04-11  8:12 ` Sascha Hauer
@ 2012-04-11  8:20   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-11  8:20 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 10:12 Wed 11 Apr     , Sascha Hauer wrote:
> On Wed, Apr 11, 2012 at 08:38:18AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > When a oftree is concatenated,the zImage is bigger than the size specified in
> > the zImage header. Detect it and copy it too.
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> >  arch/arm/lib/bootm.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 files changed, 49 insertions(+), 0 deletions(-)
> > 
> > diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
> > index defc89b..dc379d8 100644
> > --- a/arch/arm/lib/bootm.c
> > +++ b/arch/arm/lib/bootm.c
> > @@ -123,6 +123,51 @@ struct zimage_header {
> >  
> >  #define ZIMAGE_MAGIC 0x016F2818
> >  
> > +static int do_bootz_linux_fdt(int fd, struct image_data *data)
> > +{
> > +	struct fdt_header __header, *header;
> > +	struct resource *r = data->os_res;
> > +	struct resource *of_res = data->os_res;
> > +	void *oftree;
> > +	int ret;
> > +
> > +	u32 end;
> > +
> > +	header = &__header;
> > +	ret = read(fd, header, sizeof(*header));
> > +	if (ret < sizeof(*header))
> > +		return ret;
> > +
> > +	if (file_detect_type(header) != filetype_oftree)
> > +		return -ENXIO;
> > +
> > +	end = be32_to_cpu(header->totalsize);
> > +
> > +	of_res = request_sdram_region("oftree", r->start + r->size, end);
> > +	if (!of_res) {
> > +		perror("zImage: oftree request_sdram_region");
> > +		return -ENOMEM;
> > +	}
> > +
> > +	oftree = (void*)of_res->start;
> > +
> > +	memcpy(oftree, header, sizeof(*header));
> > +
> > +	end -= sizeof(*header);
> > +
> > +	ret = read_full(fd, oftree + sizeof(*header), end);
> > +	if (ret < 0)
> > +		return ret;
> > +	if (ret < end) {
> > +		printf("premature end of image\n");
> > +		return -EIO;
> > +	}
> 
> I am missing a call to of_fix_tree() here. Without it the command line
> will not be passed to the kernel. Maybe this is not really the intended
> usecase for appending an oftree to the zImage. Being able to append the
> oftree to the zImage seems more for bootloaders which do not have native
> support for devicetrees.
> 
> We could be more clever here and read the oftree to a seperately
> allocated area and set data->oftree then.
yeah I was thinking about it too

I'll do it as un incremetal patch

Best Regards,
J.

_______________________________________________
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/1] arm: bootm: zImage allow to use the concataned oftree
  2012-04-11  6:38 [PATCH v2] arm: fix zImage support when a oftree is concatenated Jean-Christophe PLAGNIOL-VILLARD
  2012-04-11  8:12 ` Sascha Hauer
@ 2012-04-11  9:13 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-12 10:03   ` Sascha Hauer
  1 sibling, 1 reply; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-11  9:13 UTC (permalink / raw)
  To: barebox

This will allow to update it with fixup.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/lib/bootm.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 813927a..213f136 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -14,6 +14,7 @@
 #include <sizes.h>
 #include <libbb.h>
 #include <magicvar.h>
+#include <libfdt.h>
 
 #include <asm/byteorder.h>
 #include <asm/setup.h>
@@ -127,8 +128,6 @@ struct zimage_header {
 static int do_bootz_linux_fdt(int fd, struct image_data *data)
 {
 	struct fdt_header __header, *header;
-	struct resource *r = data->os_res;
-	struct resource *of_res = data->os_res;
 	void *oftree;
 	int ret;
 
@@ -144,14 +143,12 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 
 	end = be32_to_cpu(header->totalsize);
 
-	of_res = request_sdram_region("oftree", r->start + r->size, end);
-	if (!of_res) {
-		perror("zImage: oftree request_sdram_region");
+	oftree = malloc(end + 0x8000);
+	if (!oftree) {
+		perror("zImage: oftree malloc");
 		return -ENOMEM;
 	}
 
-	oftree = (void*)of_res->start;
-
 	memcpy(oftree, header, sizeof(*header));
 
 	end -= sizeof(*header);
@@ -164,6 +161,14 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 		return -EIO;
 	}
 
+	fdt_open_into(oftree, oftree, end + 0x8000);
+
+	ret = of_fix_tree(oftree);
+	if (ret)
+		return ret;
+
+	data->oftree = oftree;
+
 	pr_info("zImage: concatenated oftree detected\n");
 
 	return 0;
-- 
1.7.9.1


_______________________________________________
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/1] arm: bootm: zImage allow to use the concataned oftree
  2012-04-11  9:13 ` [PATCH 1/1] arm: bootm: zImage allow to use the concataned oftree Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-12 10:03   ` Sascha Hauer
  2012-04-12 11:35     ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2012-04-12 10:03 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Wed, Apr 11, 2012 at 11:13:08AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> This will allow to update it with fixup.
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

This looks like a followup to the previous patch, but it does not apply
neither with or without this patch.

Sascha

> ---
>  arch/arm/lib/bootm.c |   19 ++++++++++++-------
>  1 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
> index 813927a..213f136 100644
> --- a/arch/arm/lib/bootm.c
> +++ b/arch/arm/lib/bootm.c
> @@ -14,6 +14,7 @@
>  #include <sizes.h>
>  #include <libbb.h>
>  #include <magicvar.h>
> +#include <libfdt.h>
>  
>  #include <asm/byteorder.h>
>  #include <asm/setup.h>
> @@ -127,8 +128,6 @@ struct zimage_header {
>  static int do_bootz_linux_fdt(int fd, struct image_data *data)
>  {
>  	struct fdt_header __header, *header;
> -	struct resource *r = data->os_res;
> -	struct resource *of_res = data->os_res;
>  	void *oftree;
>  	int ret;
>  
> @@ -144,14 +143,12 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
>  
>  	end = be32_to_cpu(header->totalsize);
>  
> -	of_res = request_sdram_region("oftree", r->start + r->size, end);
> -	if (!of_res) {
> -		perror("zImage: oftree request_sdram_region");
> +	oftree = malloc(end + 0x8000);
> +	if (!oftree) {
> +		perror("zImage: oftree malloc");
>  		return -ENOMEM;
>  	}
>  
> -	oftree = (void*)of_res->start;
> -
>  	memcpy(oftree, header, sizeof(*header));
>  
>  	end -= sizeof(*header);
> @@ -164,6 +161,14 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
>  		return -EIO;
>  	}
>  
> +	fdt_open_into(oftree, oftree, end + 0x8000);
> +
> +	ret = of_fix_tree(oftree);
> +	if (ret)
> +		return ret;
> +
> +	data->oftree = oftree;
> +
>  	pr_info("zImage: concatenated oftree detected\n");
>  
>  	return 0;
> -- 
> 1.7.9.1
> 
> 
> _______________________________________________
> 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] 6+ messages in thread

* Re: [PATCH 1/1] arm: bootm: zImage allow to use the concataned oftree
  2012-04-12 10:03   ` Sascha Hauer
@ 2012-04-12 11:35     ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-12 11:35 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 12:03 Thu 12 Apr     , Sascha Hauer wrote:
> On Wed, Apr 11, 2012 at 11:13:08AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > This will allow to update it with fixup.
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> 
> This looks like a followup to the previous patch, but it does not apply
> neither with or without this patch.
it's apply over the android patch sereis

I put the patch merge there

The following changes since commit 6c727af2c27d84f26a04a8075890f575ebf91814:

  Final switch to use combined driver mc13xxx (2012-04-11 09:51:01 +0200)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git zImage

for you to fetch changes up to 576b0d48b3f27388240538f85ec4aa1f778f2573:

  arm: bootm: zImage allow to use the concataned oftree (2012-04-12 19:50:42 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (2):
      arm: fix zImage support when a oftree is concatenated
      arm: bootm: zImage allow to use the concataned oftree

 arch/arm/lib/bootm.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

Best Regards,
J. 
> Sascha
> 
> > ---
> >  arch/arm/lib/bootm.c |   19 ++++++++++++-------
> >  1 files changed, 12 insertions(+), 7 deletions(-)
> > 
> > diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
> > index 813927a..213f136 100644
> > --- a/arch/arm/lib/bootm.c
> > +++ b/arch/arm/lib/bootm.c
> > @@ -14,6 +14,7 @@
> >  #include <sizes.h>
> >  #include <libbb.h>
> >  #include <magicvar.h>
> > +#include <libfdt.h>
> >  
> >  #include <asm/byteorder.h>
> >  #include <asm/setup.h>
> > @@ -127,8 +128,6 @@ struct zimage_header {
> >  static int do_bootz_linux_fdt(int fd, struct image_data *data)
> >  {
> >  	struct fdt_header __header, *header;
> > -	struct resource *r = data->os_res;
> > -	struct resource *of_res = data->os_res;
> >  	void *oftree;
> >  	int ret;
> >  
> > @@ -144,14 +143,12 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
> >  
> >  	end = be32_to_cpu(header->totalsize);
> >  
> > -	of_res = request_sdram_region("oftree", r->start + r->size, end);
> > -	if (!of_res) {
> > -		perror("zImage: oftree request_sdram_region");
> > +	oftree = malloc(end + 0x8000);
> > +	if (!oftree) {
> > +		perror("zImage: oftree malloc");
> >  		return -ENOMEM;
> >  	}
> >  
> > -	oftree = (void*)of_res->start;
> > -
> >  	memcpy(oftree, header, sizeof(*header));
> >  
> >  	end -= sizeof(*header);
> > @@ -164,6 +161,14 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
> >  		return -EIO;
> >  	}
> >  
> > +	fdt_open_into(oftree, oftree, end + 0x8000);
> > +
> > +	ret = of_fix_tree(oftree);
> > +	if (ret)
> > +		return ret;
> > +
> > +	data->oftree = oftree;
> > +
> >  	pr_info("zImage: concatenated oftree detected\n");
> >  
> >  	return 0;
> > -- 
> > 1.7.9.1
> > 
> > 
> > _______________________________________________
> > 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] 6+ messages in thread

end of thread, other threads:[~2012-04-12 11:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-11  6:38 [PATCH v2] arm: fix zImage support when a oftree is concatenated Jean-Christophe PLAGNIOL-VILLARD
2012-04-11  8:12 ` Sascha Hauer
2012-04-11  8:20   ` Jean-Christophe PLAGNIOL-VILLARD
2012-04-11  9:13 ` [PATCH 1/1] arm: bootm: zImage allow to use the concataned oftree Jean-Christophe PLAGNIOL-VILLARD
2012-04-12 10:03   ` Sascha Hauer
2012-04-12 11:35     ` Jean-Christophe PLAGNIOL-VILLARD

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