mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 01/16] of: make of_get_fixed_tree more universally usable
Date: Fri, 11 Jan 2013 14:24:21 +0100	[thread overview]
Message-ID: <1357910676-4231-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1357910676-4231-1-git-send-email-s.hauer@pengutronix.de>

Currently the bootm code uses of_fix_tree to apply the fixups
to the devicetree given on the command line. This function assumes
that there is enough space for the fixups available. Also on ARM
we have to make sure the tree does not cross 1Mib boundaries.

This patch moves the space allocation and alignment ensurance
to of_get_fixed_tree and uses it in bootm. This is the first
step for making of_get_fixed_tree the single point of devicetree
handling in barebox.
of_get_fixed_tree now takes an argument of the input fdt. If it is
given, this one is used, otherwise an internal oftree is used which
will be created in subsequent patches.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/bootu.c |    2 +-
 arch/arm/lib/bootz.c |    2 +-
 commands/bootm.c     |   32 ++++++++------------------------
 common/oftree.c      |   50 +++++++++++++++++++++++++++++++++++++++++++++-----
 include/of.h         |    2 +-
 5 files changed, 56 insertions(+), 32 deletions(-)

diff --git a/arch/arm/lib/bootu.c b/arch/arm/lib/bootu.c
index 75e0de3..fdb0362 100644
--- a/arch/arm/lib/bootu.c
+++ b/arch/arm/lib/bootu.c
@@ -23,7 +23,7 @@ static int do_bootu(int argc, char *argv[])
 		kernel = (void *)simple_strtoul(argv[1], NULL, 0);
 
 #ifdef CONFIG_OFTREE
-	oftree = of_get_fixed_tree();
+	oftree = of_get_fixed_tree(NULL);
 #endif
 
 	start_linux(kernel, 0, 0, 0, oftree);
diff --git a/arch/arm/lib/bootz.c b/arch/arm/lib/bootz.c
index 9f5b3b4..e32a77b 100644
--- a/arch/arm/lib/bootz.c
+++ b/arch/arm/lib/bootz.c
@@ -109,7 +109,7 @@ static int do_bootz(int argc, char *argv[])
 
 	printf("loaded zImage from %s with size %d\n", argv[1], end);
 #ifdef CONFIG_OFTREE
-	oftree = of_get_fixed_tree();
+	oftree = of_get_fixed_tree(NULL);
 #endif
 
 	start_linux(zimage, swap, 0, 0, oftree);
diff --git a/commands/bootm.c b/commands/bootm.c
index 483e6a1..d8b8469 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -139,9 +139,7 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 {
 	enum filetype ft;
 	struct fdt_header *fdt, *fixfdt;
-	int ret;
 	size_t size;
-	unsigned int align;
 
 	if (bootm_verbose(data))
 		printf("Loading oftree from '%s'\n", oftree);
@@ -190,36 +188,18 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 				file_type_to_string(ft));
 	}
 
-	/*
-	 * 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);
-
-
-	ret = fdt_open_into(fdt, fixfdt, size + OFTREE_SIZE_INCREASE);
+	fixfdt = of_get_fixed_tree(fdt);
+	if (!fixfdt)
+		return -EINVAL;
 
 	free(fdt);
 
-	if (ret) {
-		printf("unable to parse %s\n", oftree);
-		return -ENODEV;
-	}
-
-	ret = of_fix_tree(fixfdt);
-	if (ret)
-		return ret;
-
 	if (bootm_verbose(data) > 1)
 		fdt_print(fixfdt, "/");
 
 	data->oftree = fixfdt;
 
-	return ret;
+	return 0;
 }
 #endif
 
@@ -420,6 +400,10 @@ static int do_bootm(int argc, char *argv[])
 		ret = bootm_open_oftree(&data, oftree, oftree_num);
 		if (ret)
 			goto err_out;
+	} else {
+		data.oftree = of_get_fixed_tree(NULL);
+		if (bootm_verbose(&data) && data.oftree)
+			printf("using internal devicetree\n");
 	}
 #endif
 	if (data.os_address == UIMAGE_SOME_ADDRESS)
diff --git a/common/oftree.c b/common/oftree.c
index 3e8c6f8..0dd6d5c 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -294,6 +294,10 @@ int of_register_fixup(int (*fixup)(struct fdt_header *))
 	return 0;
 }
 
+/*
+ * Apply registered fixups for the given fdt. The fdt must have
+ * enough free space to apply the fixups.
+ */
 int of_fix_tree(struct fdt_header *fdt)
 {
 	struct of_fixup *of_fixup;
@@ -308,14 +312,50 @@ int of_fix_tree(struct fdt_header *fdt)
 	return 0;
 }
 
-struct fdt_header *of_get_fixed_tree(void)
+/*
+ * The size by which we increase the dtb to have space for additional
+ * fixups. Ideally this would be done by libfdt automatically
+ */
+#define OFTREE_SIZE_INCREASE 0x8000
+
+/*
+ * Get the fixed fdt. This function uses the fdt input pointer
+ * if provided or the barebox internal devicetree if not.
+ * It increases the size of the tree and applies the registered
+ * fixups.
+ */
+struct fdt_header *of_get_fixed_tree(struct fdt_header *fdt)
 {
 	int ret;
+	void *fixfdt;
+	int size, align;
 
-	if (!barebox_fdt)
+	if (!fdt)
 		return NULL;
-	ret = of_fix_tree(barebox_fdt);
+
+	size = fdt_totalsize(fdt);
+
+	/*
+	 * 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);
+	ret = fdt_open_into(fdt, fixfdt, size + OFTREE_SIZE_INCREASE);
+
 	if (ret)
-		return NULL;
-	return barebox_fdt;
+		goto out_free;
+
+	ret = of_fix_tree(fixfdt);
+	if (ret)
+		goto out_free;
+
+	return fixfdt;
+
+out_free:
+	free(fixfdt);
+
+	return NULL;
 }
diff --git a/include/of.h b/include/of.h
index 58b4590..3999ded 100644
--- a/include/of.h
+++ b/include/of.h
@@ -9,7 +9,7 @@ extern struct fdt_header *barebox_fdt;
 
 int fdt_print(struct fdt_header *working_fdt, const char *pathp);
 
-struct fdt_header *of_get_fixed_tree(void);
+struct fdt_header *of_get_fixed_tree(struct fdt_header *fdt);
 int of_fix_tree(struct fdt_header *fdt);
 int of_register_fixup(int (*fixup)(struct fdt_header *));
 
-- 
1.7.10.4


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

  reply	other threads:[~2013-01-11 13:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-11 13:24 [PATCH] devicetree improvements Sascha Hauer
2013-01-11 13:24 ` Sascha Hauer [this message]
2013-01-11 13:24 ` [PATCH 02/16] of: Fix invalid path for of_find_node_by_path Sascha Hauer
2013-01-11 13:24 ` [PATCH 03/16] ARM android image: remove double of_fix_tree Sascha Hauer
2013-01-11 13:24 ` [PATCH 04/16] of: of_free fixes Sascha Hauer
2013-01-11 13:24 ` [PATCH 05/16] of of_free: remove old node from allnodes list Sascha Hauer
2013-01-11 13:24 ` [PATCH 06/16] of: return root node when looking for a node with path / Sascha Hauer
2013-01-11 13:24 ` [PATCH 07/16] of: rename of_parse_dtb to of_unflatten_dtb Sascha Hauer
2013-01-11 13:24 ` [PATCH 08/16] of: Add support for converting the unflattened tree back to a dtb Sascha Hauer
2013-01-11 13:24 ` [PATCH 09/16] of: remove unused barebox_fdt Sascha Hauer
2013-01-11 13:24 ` [PATCH 10/16] ARM bootm: only use concatenated oftree when no other is available Sascha Hauer
2013-01-11 13:24 ` [PATCH 11/16] of: unflatten: allow overlay dtbs Sascha Hauer
2013-01-11 13:24 ` [PATCH 12/16] oftree command: refactor Sascha Hauer
2013-01-11 13:24 ` [PATCH 13/16] of: add of_delete_property Sascha Hauer
2013-01-11 13:24 ` [PATCH 14/16] of: rename new_device_node to of_new_node and export it Sascha Hauer
2013-01-11 13:24 ` [PATCH 15/16] commands: Add of_property command Sascha Hauer
2013-01-11 13:24 ` [PATCH 16/16] commands: Add of_node command Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1357910676-4231-2-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox