summaryrefslogtreecommitdiffstats
path: root/common/oftree.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-01-10 14:37:17 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2013-01-11 14:08:30 +0100
commitf30b191e36ddc086c3f58a572096d650fd5a6dfa (patch)
treef2d39d637cdaaf14151095b75d7993b6cade693f /common/oftree.c
parent46dae550cdccfee407f8ced183f9102296cb79b7 (diff)
downloadbarebox-f30b191e36ddc086c3f58a572096d650fd5a6dfa.tar.gz
barebox-f30b191e36ddc086c3f58a572096d650fd5a6dfa.tar.xz
of: make of_get_fixed_tree more universally usable
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>
Diffstat (limited to 'common/oftree.c')
-rw-r--r--common/oftree.c50
1 files changed, 45 insertions, 5 deletions
diff --git a/common/oftree.c b/common/oftree.c
index 3e8c6f8c65..0dd6d5c3e4 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;
}