mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fix devicetree alignment
@ 2012-11-01 11:49 Sascha Hauer
  2012-11-01 11:49 ` [PATCH 1/2] bootm: Add a define for the additional devicetree size Sascha Hauer
  2012-11-01 11:49 ` [PATCH 2/2] bootm: Do not cross 1MiB sections for the devicetree Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2012-11-01 11:49 UTC (permalink / raw)
  To: barebox

The following fixes a nasty problem with passing devicetrees to
the (ARM-) Kernel. In short, we are not allowed to cross 1MiB
boundaries with the devicetree. This can happen sometimes since
we allocate space for the devicetree using memalign(). I think
this is rather a kernel bug since this restriction is not documented
anywhere. Anyway, working around it in barebox is easy enough.

Sascha

----------------------------------------------------------------
Sascha Hauer (2):
      bootm: Add a define for the additional devicetree size
      bootm: Do not cross 1MiB sections for the devicetree

 commands/bootm.c |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

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

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

* [PATCH 1/2] bootm: Add a define for the additional devicetree size
  2012-11-01 11:49 [PATCH] fix devicetree alignment Sascha Hauer
@ 2012-11-01 11:49 ` Sascha Hauer
  2012-11-01 11:49 ` [PATCH 2/2] bootm: Do not cross 1MiB sections for the devicetree Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2012-11-01 11:49 UTC (permalink / raw)
  To: barebox

The fixed devicetree may need more space than the original one.
We used to use 0x8000 here. Add a define for it to have the
space defined at a single place.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 20b49f0..d14ec2b 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -49,6 +49,11 @@
 
 static LIST_HEAD(handler_list);
 
+/*
+ * Additional oftree size for the fixed tree
+ */
+#define OFTREE_SIZE_INCREASE	0x8000
+
 int register_image_handler(struct image_handler *handler)
 {
 	list_add_tail(&handler->list, &handler_list);
@@ -184,12 +189,14 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 				file_type_to_string(ft));
 	}
 
-	fixfdt = xmemalign(4096, size + 0x8000);
+	fixfdt = xmemalign(4096, size + OFTREE_SIZE_INCREASE);
 	memcpy(fixfdt, fdt, size);
 
+
+	ret = fdt_open_into(fdt, fixfdt, size + OFTREE_SIZE_INCREASE);
+
 	free(fdt);
 
-	ret = fdt_open_into(fixfdt, fixfdt, size + 0x8000);
 	if (ret) {
 		printf("unable to parse %s\n", oftree);
 		return -ENODEV;
-- 
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] bootm: Do not cross 1MiB sections for the devicetree
  2012-11-01 11:49 [PATCH] fix devicetree alignment Sascha Hauer
  2012-11-01 11:49 ` [PATCH 1/2] bootm: Add a define for the additional devicetree size Sascha Hauer
@ 2012-11-01 11:49 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2012-11-01 11:49 UTC (permalink / raw)
  To: barebox

ARM Linux only maps a single 1MiB section for the devicetree. This has
a 1Mib alignment, so we are not allowed to cross such a boundary. Align
the devicetree to the next power of two so that this never happens.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index d14ec2b..98d2e4f 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -141,6 +141,7 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 	struct fdt_header *fdt, *fixfdt;
 	int ret;
 	size_t size;
+	unsigned int align;
 
 	if (bootm_verbose(data))
 		printf("Loading oftree from '%s'\n", oftree);
@@ -189,7 +190,14 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 				file_type_to_string(ft));
 	}
 
-	fixfdt = xmemalign(4096, size + OFTREE_SIZE_INCREASE);
+	/*
+	 * ARM Linux uses a single 1MiB section (with 1MiB alignment)
+	 * for mapping the devicetree, so we are not allowed to cross
+	 * 1MiB boundaries.
+	 */
+	align = 1 << fls(size + OFTREE_SIZE_INCREASE - 1);
+
+	fixfdt = xmemalign(align, size + OFTREE_SIZE_INCREASE);
 	memcpy(fixfdt, fdt, size);
 
 
-- 
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

end of thread, other threads:[~2012-11-01 11:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-01 11:49 [PATCH] fix devicetree alignment Sascha Hauer
2012-11-01 11:49 ` [PATCH 1/2] bootm: Add a define for the additional devicetree size Sascha Hauer
2012-11-01 11:49 ` [PATCH 2/2] bootm: Do not cross 1MiB sections for the devicetree Sascha Hauer

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