Skip to contentSkip to conversation

remove libfdt

PATCH New Sascha Hauer 2 participants 39 messages Mar 4, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 remove libfdt

In the beginning we only had libfdt to handle devicetrees. With devicetree probing support we gained two parallel universes for handling devicetrees. This series cleans this up by switching to the internal devicetree completely and removing libfdt.

The dtb format is now only used while flattening/unflattening the tree. All tree manipulation is done on the internal tree format only. This introduces some time overhead (~2ms on a i.MX51) needed for (un)flattening the tree, but actually manipulating the tree is a factor of about 50 faster compared to libfdt. This means the overhead can become more than compensated once we start manipulating the tree in more places.

The overall code and binary size becomes a bit smaller with this due to less duplicated code.

Changes since v1:

- rebase on current master
- add of_write_number helper and use it
- add reserve map handling
- add initrd handling for ARM

Sascha

The following changes since commit 2ecdea32dde307acd5b3f1c49ac666d4c494dfe9:

switch more boards to lwl-y (2013-03-04 09:23:45 +0100)

are available in the git repository at:

git://git.pengutronix.de/git/barebox.git pu/oftree

for you to fetch changes up to 279b70e19ce9698ab1f8f65cbe32ec9497ce247d:

of: make locally used functions static (2013-03-04 09:28:12 +0100)

----------------------------------------------------------------
Sascha Hauer (37):
of: unflatten: allocate root node explicitly
of: export of_find_child
of: removed unused variables
of: Let of_find_node_by_path iterate over tree
of: remove allnodes list
ARM bootm: Use of_get_fixed_tree
of: Add of_set_property and of_create_node
of_node command: use of_create_node
of: Add missing prototype for of_device_is_compatible
of: let of_unflatten_dtb return the unflattened tree
of: Add root node argument to of_find_node_by_path
of: Add of_write_number helper
of: Add initrd helper
of: make unflatten independent of libfdt
of: make flatten independent of libfdt
of/fdt: use optimized endianess conversion
oftree command: Use of_print_nodes
of: move OFTREE Kconfig option to drivers/of/
of: make OFDEVICE a user selectable option
oftree command: retire CMD_OFTREE_PROBE Kconfig option
of: move oftree Kconfig to the top of the drivers menu
of: Pass barebox internal format devicetree to of_get_fixed_tree
bootm: Use of_print_nodes instead of fdt_print
of: move flat devicetree functions to separate file
of: Add of property write functions for u32
of: make value of property in of_new_property optional
of: Add missing prototype for size/address counting functions
of: fixup unflattened devicetree
of_* commands: print usage when insufficient arguments are given of_property command: Fix crash with empty property value
ARM: bootm: rework concatenated oftree
of: memory: Use of_write_number
of: Add reservemap handling
bootm: Pass unflattened devicetree to handlers
ARM bootm: Switch initrd support to unflattened tree
of: remove unused libfdt
of: make locally used functions static

 arch/arm/boards/at91sam9m10ihd/hw_version.c |    1 -
 arch/arm/boards/at91sam9x5ek/hw_version.c   |   32 +-
 arch/arm/boards/highbank/init.c             |   49 +-
 arch/arm/boards/sama5d3xek/hw_version.c     |    1 -
 arch/arm/lib/armlinux.c                     |    2 -
 arch/arm/lib/bootm.c                        |   56 +-
 arch/ppc/Kconfig                            |    1 +
 arch/ppc/lib/ppclinux.c                     |    8 +
 arch/ppc/mach-mpc5xxx/cpu.c                 |   26 +-
 commands/Kconfig                            |   10 -
 commands/bootm.c                            |   22 +-
 commands/of_node.c                          |   33 +-
 commands/of_property.c                      |   24 +-
 commands/oftree.c                           |   42 +-
 common/memory.c                             |   70 +-
 common/oftree.c                             |  314 +------
 drivers/Kconfig                             |    2 +-
 drivers/Makefile                            |    2 +-
 drivers/of/Kconfig                          |    6 +-
 drivers/of/Makefile                         |    2 +-
 drivers/of/base.c                           |  364 ++++----
 drivers/of/dtb.c                            |  465 ++++++++++
 include/boot.h                              |    1 +
 include/fdt.h                               |   13 +
 include/libfdt.h                            | 1235 ---------------------------
 include/libfdt_env.h                        |   22 -
 include/of.h                                |  110 ++-
 lib/Kconfig                                 |    7 -
 lib/Makefile                                |    1 -
 lib/fdt/Makefile                            |    2 -
 lib/fdt/TODO                                |    3 -
 lib/fdt/fdt.c                               |  222 -----
 lib/fdt/fdt_ro.c                            |  574 -------------
 lib/fdt/fdt_rw.c                            |  465 ----------
 lib/fdt/fdt_strerror.c                      |   96 ---
 lib/fdt/fdt_sw.c                            |  256 ------
 lib/fdt/fdt_wip.c                           |  118 ---
 lib/fdt/libfdt_internal.h                   |   95 ---
 38 files changed, 971 insertions(+), 3781 deletions(-)
 create mode 100644 drivers/of/dtb.c
 delete mode 100644 include/libfdt.h
 delete mode 100644 include/libfdt_env.h
 delete mode 100644 lib/fdt/Makefile
 delete mode 100644 lib/fdt/TODO
 delete mode 100644 lib/fdt/fdt.c
 delete mode 100644 lib/fdt/fdt_ro.c
 delete mode 100644 lib/fdt/fdt_rw.c
 delete mode 100644 lib/fdt/fdt_strerror.c
 delete mode 100644 lib/fdt/fdt_sw.c
 delete mode 100644 lib/fdt/fdt_wip.c
 delete mode 100644 lib/fdt/libfdt_internal.h

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH 1/37 of: unflatten: allocate root node explicitly

By doing so of_new_node does not depend on the global root_node anymore.

---
 drivers/of/base.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/of/base.c +12 -5
index fd9b8e1..d134f1e 100644
@@ -946,7 +946,7 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 	const struct fdt_property *fdt_prop;
 	const char *pathp;
 	int depth = 10000;
-	struct device_node *node = NULL, *n;
+	struct device_node *node = NULL, *n, *root = NULL;
 	struct property *p;
 
 	nodeoffset = fdt_path_offset(fdt, "/");
@@ -959,6 +959,10 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 		return -EINVAL;
 	}
 
+	root = of_new_node(NULL, NULL);
+	if (!root)
+		return -ENOMEM;
+
 	while (1) {
 		tag = fdt_next_tag(fdt, nodeoffset, &nextoffset);
 		switch (tag) {
@@ -968,11 +972,14 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 			if (pathp == NULL)
 				pathp = "/* NULL pointer error */";
 
-			n = of_find_child(node, pathp);
-			if (n) {
-				node = n;
+			if (!node) {
+				node = root;
 			} else {
-				node = of_new_node(node, pathp);
+				if ((n = of_find_child(node, pathp))) {
+					node = n;
+				} else {
+					node = of_new_node(node, pathp);
+				}
 			}
 			break;
 		case FDT_END_NODE:
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/37 of: export of_find_child

In reply to Sascha Hauer

of_find_child is a useful function. Export it and rename it to of_find_child_by_name.

---
 drivers/of/base.c |   16 +++-------------
 include/of.h      |    2 ++
 2 files changed, 5 insertions(+), 13 deletions(-)
drivers/of/base.c +3 -13
index d134f1e..86dca6a 100644
@@ -910,23 +910,13 @@ int of_probe(void)
 	return 0;
 }
 
-static struct device_node *of_find_child(struct device_node *node, const char *name)
+struct device_node *of_find_child_by_name(struct device_node *node, const char *name)
 {
 	struct device_node *_n;
 
-	if (!root_node)
-		return NULL;
-
-	if (!node && !*name)
-		return root_node;
-
-	if (!node)
-		node = root_node;
-
-	list_for_each_entry(_n, &node->children, parent_list) {
+	device_node_for_nach_child(node, _n)
 		if (!strcmp(_n->name, name))
 			return _n;
-	}
 
 	return NULL;
 }
@@ -975,7 +965,7 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 			if (!node) {
 				node = root;
 			} else {
-				if ((n = of_find_child(node, pathp))) {
+				if ((n = of_find_child_by_name(node, pathp))) {
 					node = n;
 				} else {
 					node = of_new_node(node, pathp);
include/of.h +2 -0
index 95d9702..f3fc2ae 100644
@@ -72,6 +72,8 @@ struct property *of_find_property(const struct device_node *node, const char *na
 
 struct device_node *of_find_node_by_path(const char *path);
 
+struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
+
 struct fdt_header *fdt_get_tree(void);
 
 #define device_node_for_nach_child(node, child) \
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 3/37 of: removed unused variables

In reply to Sascha Hauer
---
 drivers/of/base.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/of/base.c +1 -4
index 86dca6a..01d4e4f 100644
@@ -932,10 +932,8 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 	int  nextoffset;	/* next node offset from libfdt */
 	uint32_t tag;		/* tag */
 	int  len;		/* length of the property */
-	int  level = 0;		/* keep track of nesting level */
 	const struct fdt_property *fdt_prop;
 	const char *pathp;
-	int depth = 10000;
 	struct device_node *node = NULL, *n, *root = NULL;
 	struct property *p;
 
@@ -998,8 +996,7 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 			of_alias_scan();
 			return 0;
 		default:
-			if (level <= depth)
-				printf("Unknown tag 0x%08X\n", tag);
+			printf("Unknown tag 0x%08X\n", tag);
 			return -EINVAL;
 		}
 		nodeoffset = nextoffset;
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH 4/37 of: Let of_find_node_by_path iterate over tree

In reply to Sascha Hauer

of_find_node_by_path iterates over the allnodes list. Depending on where the node we look for is, this can be significantly slower than using the tree structure to look for a node, so iterate over the tree instead.

---
 drivers/of/base.c |   37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)
drivers/of/base.c +30 -7
index 01d4e4f..37d3128 100644
@@ -491,17 +491,40 @@ EXPORT_SYMBOL(of_machine_is_compatible);
  */
 struct device_node *of_find_node_by_path(const char *path)
 {
-	struct device_node *np;
+	char *slash, *p, *freep;
+	struct device_node *dn = root_node;
+
+	if (!root_node)
+		return NULL;
+
+	if (*path != '/')
+		return NULL;
+
+	path++;
 
-	if (!strcmp(path, "/"))
-		return root_node;
+	freep = p = xstrdup(path);
 
-	list_for_each_entry(np, &allnodes, list) {
-		if (np->full_name && (strcmp(np->full_name, path) == 0))
-			return np;
+	while (1) {
+		if (!*p)
+			goto out;
+
+		slash = strchr(p, '/');
+		if (slash)
+			*slash = 0;
+
+		dn = of_find_child_by_name(dn, p);
+		if (!dn)
+			goto out;
+
+		if (!slash)
+			goto out;
+
+		p = slash + 1;
 	}
+out:
+	free(freep);
 
-	return NULL;
+	return dn;
 }
 EXPORT_SYMBOL(of_find_node_by_path);
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH 5/37 of: remove allnodes list

In reply to Sascha Hauer

The allnodes list makes it hard to handle multiple devicetrees. Having a list to iterate over all nodes of a tree is still good to have though. This patch uses the list_head of the root node as the head of the list. This way the root node is no longer part of the list, but when iterating over a tree the root node is not interesting anyway.

---
 drivers/of/base.c |   12 +++++-------
 include/of.h      |    8 ++++++++
 2 files changed, 13 insertions(+), 7 deletions(-)
drivers/of/base.c +5 -7
index 37d3128..ad278ad 100644
@@ -51,8 +51,6 @@ static LIST_HEAD(aliases_lookup);
 
 static LIST_HEAD(phandle_list);
 
-static LIST_HEAD(allnodes);
-
 struct device_node *root_node;
 
 struct device_node *of_aliases;
@@ -629,13 +627,13 @@ struct device_node *of_new_node(struct device_node *parent, const char *name)
 	if (parent) {
 		node->name = xstrdup(name);
 		node->full_name = asprintf("%s/%s", node->parent->full_name, name);
+		list_add(&node->list, &parent->list);
 	} else {
 		node->name = xstrdup("");
 		node->full_name = xstrdup("");
+		INIT_LIST_HEAD(&node->list);
 	}
 
-	list_add_tail(&node->list, &allnodes);
-
 	return node;
 }
 
@@ -868,8 +866,6 @@ void of_free(struct device_node *node)
 	if (!node)
 		return;
 
-	list_del(&node->list);
-
 	list_for_each_entry_safe(p, pt, &node->properties, list) {
 		list_del(&p->list);
 		free(p->name);
@@ -881,8 +877,10 @@ void of_free(struct device_node *node)
 		of_free(n);
 	}
 
-	if (node->parent)
+	if (node->parent) {
 		list_del(&node->parent_list);
+		list_del(&node->list);
+	}
 
 	if (node->device)
 		node->device->device_node = NULL;
include/of.h +8 -0
index f3fc2ae..8166273 100644
@@ -79,6 +79,14 @@ struct fdt_header *fdt_get_tree(void);
 #define device_node_for_nach_child(node, child) \
 	list_for_each_entry(child, &node->children, parent_list)
 
+/*
+ * Iterate over all nodes of a tree. As a devicetree does not
+ * have a dedicated list head, the start node (usually the root
+ * node) will not be iterated over.
+ */
+#define of_tree_for_each_node(node, root) \
+	list_for_each_entry(node, &root->list, list)
+
 /* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 of_read_number(const __be32 *cell, int size)
 {
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH 6/37 ARM bootm: Use of_get_fixed_tree

In reply to Sascha Hauer
---
 arch/arm/lib/bootm.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
arch/arm/lib/bootm.c +1 -7
index dc29004..cf192cf 100644
@@ -181,13 +181,7 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 	}
 
 	if (IS_BUILTIN(CONFIG_OFTREE)) {
-		fdt_open_into(oftree, oftree, end + 0x8000);
-
-		ret = of_fix_tree(oftree);
-		if (ret)
-			return ret;
-
-		data->oftree = oftree;
+		data->oftree = of_get_fixed_tree(oftree);
 	}
 
 	pr_info("zImage: concatenated oftree detected\n");
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH 7/37 of: Add of_set_property and of_create_node

In reply to Sascha Hauer

Add functions to create a new device node and to create/set a new property based on the nodepath.

---
 drivers/of/base.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/of.h      |    3 ++
 2 files changed, 82 insertions(+)
drivers/of/base.c +79 -0
index ad278ad..11d17c6 100644
@@ -663,6 +663,41 @@ void of_delete_property(struct property *pp)
 	free(pp);
 }
 
+/**
+ * of_set_property - create a property for a given node
+ * @node - the node
+ * @name - the name of the property
+ * @val - the value for the property
+ * @len - the length of the properties value
+ * @create - if true, the property is created if not existing already
+ */
+int of_set_property(struct device_node *np, const char *name, const void *val, int len,
+		int create)
+{
+	struct property *pp;
+
+	if (!np)
+		return -ENOENT;
+
+	pp = of_find_property(np, name);
+	if (pp) {
+		void *data;
+
+		free(pp->value);
+		data = xzalloc(len);
+		memcpy(data, val, len);
+		pp->value = data;
+		pp->length = len;
+	} else {
+		if (!create)
+			return -ENOENT;
+
+		pp = of_new_property(np, name, val, len);
+	}
+
+	return 0;
+}
+
 static struct device_d *add_of_amba_device(struct device_node *node)
 {
 	struct amba_device *dev;
@@ -942,6 +977,50 @@ struct device_node *of_find_child_by_name(struct device_node *node, const char *
 	return NULL;
 }
 
+/**
+ * of_create_node - create a new node including its parents
+ * @path - the nodepath to create
+ */
+struct device_node *of_create_node(struct device_node *root, const char *path)
+{
+	char *slash, *p, *freep;
+	struct device_node *tmp, *dn = root;
+
+	if (*path != '/')
+		return NULL;
+
+	path++;
+
+	p = freep = xstrdup(path);
+
+	while (1) {
+		if (!*p)
+			goto out;
+
+		slash = strchr(p, '/');
+		if (slash)
+			*slash = 0;
+
+		tmp = of_find_child_by_name(dn, p);
+		if (tmp)
+			dn = tmp;
+		else
+			dn = of_new_node(dn, p);
+
+		if (!dn)
+			goto out;
+
+		if (!slash)
+			goto out;
+
+		p = slash + 1;
+	}
+out:
+	free(freep);
+
+	return dn;
+}
+
 /*
  * Parse a flat device tree binary blob and store it in the barebox
  * internal tree format,
include/of.h +3 -0
index 8166273..3305f03 100644
@@ -138,6 +138,9 @@ void of_delete_property(struct property *pp);
 
 int of_property_read_string(struct device_node *np, const char *propname,
 				const char **out_string);
+int of_set_property(struct device_node *node, const char *p, const void *val, int len,
+		int create);
+struct device_node *of_create_node(struct device_node *root, const char *path);
 
 #ifdef CONFIG_OFDEVICE
 int of_parse_partitions(const char *cdevname,
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH 8/37 of_node command: use of_create_node

In reply to Sascha Hauer
---
 commands/of_node.c |   27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)
commands/of_node.c +10 -17
index a370e26..bf9799c 100644
@@ -39,6 +39,7 @@ static int do_of_node(int argc, char *argv[])
 	int create = 0;
 	char *path = NULL;
 	struct device_node *node = NULL;
+	struct device_node *root;
 
 	while ((opt = getopt(argc, argv, "cd")) > 0) {
 		switch (opt) {
@@ -57,27 +58,19 @@ static int do_of_node(int argc, char *argv[])
 		path = argv[optind];
 	}
 
-	if (create) {
-		char *name;
+	root = of_get_root_node();
+	if (!root) {
+		printf("root node not set\n");
+		return -ENOENT;
+	}
 
+	if (create) {
 		if (!path)
 			return COMMAND_ERROR_USAGE;
 
-		name = xstrdup(basename(path));
-		path = dirname(path);
-
-		node = of_find_node_by_path(path);
-		if (!node) {
-			printf("Cannot find nodepath %s\n", path);
-			free(name);
-			return -ENOENT;
-		}
-
-		debug("create node \"%s\" \"%s\"\n", path, name);
-
-		of_new_node(node, name);
-
-		free(name);
+		node = of_create_node(root, path);
+		if (!node)
+			return -EINVAL;
 
 		return 0;
 	}
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH 9/37 of: Add missing prototype for of_device_is_compatible

In reply to Sascha Hauer
---
 include/of.h |    3 +++
 1 file changed, 3 insertions(+)
include/of.h +3 -0
index 3305f03..d780dcf 100644
@@ -121,6 +121,9 @@ int of_get_named_gpio(struct device_node *np,
 struct device_node *of_find_node_by_phandle(phandle phandle);
 void of_print_property(const void *data, int len);
 
+int of_device_is_compatible(const struct device_node *device,
+		const char *compat);
+
 int of_machine_is_compatible(const char *compat);
 
 #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

PATCH 10/37 of: let of_unflatten_dtb return the unflattened tree

In reply to Sascha Hauer

In order to be able to handle multiple devicetrees, do not assume the tree to be unflattened is the barebox internal one. Instead, just return a pointer to it and assign the barebox internal root_node external to the unflatten function.

---
 arch/arm/boards/highbank/init.c |   11 +++++---
 commands/oftree.c               |   14 +++++++++-
 drivers/of/base.c               |   57 ++++++++++++++++++++++++---------------
 include/of.h                    |    3 ++-
 4 files changed, 58 insertions(+), 27 deletions(-)
arch/arm/boards/highbank/init.c +7 -4
index e36674f..0f64fc8 100644
@@ -17,6 +17,7 @@
 #include <sizes.h>
 #include <io.h>
 #include <libfdt.h>
+#include <of.h>
 
 #define FIRMWARE_DTB_BASE	0x1000
 
@@ -63,19 +64,21 @@ static int hb_fixup(struct fdt_header *fdt)
 
 static int highbank_mem_init(void)
 {
-	struct device_node *np;
+	struct device_node *root, *np;
 	int ret;
 
 	/* load by the firmware at 0x1000 */
 	fdt = IOMEM(FIRMWARE_DTB_BASE);
 
-	ret = of_unflatten_dtb(fdt);
-	if (ret) {
+	root = of_unflatten_dtb(NULL, fdt);
+	if (!root) {
 		pr_warn("no dtb found at 0x1000 use default configuration\n");
 		fdt = NULL;
 		goto not_found;
 	}
 
+	of_set_root_node(root);
+
 	np = of_find_node_by_path("/memory");
 	if (!np) {
 		pr_warn("no memory node use default configuration\n");
@@ -109,7 +112,7 @@ static int highbank_devices_init(void)
 		highbank_register_xgmac(0);
 		highbank_register_xgmac(1);
 	} else {
-		fdt = of_get_fixed_tree(fdt);
+		fdt = of_get_fixed_tree(NULL);
 		add_mem_device("dtb", (unsigned long)fdt, fdt_totalsize(fdt),
 		       IORESOURCE_MEM_WRITEABLE);
 		devfs_add_partition("ram0", FIRMWARE_DTB_BASE, SZ_64K, DEVFS_PARTITION_FIXED, "firmware-dtb");
commands/oftree.c +13 -1
index ddbff3e..68e3fb4 100644
@@ -32,6 +32,7 @@
 #include <malloc.h>
 #include <libfdt.h>
 #include <linux/ctype.h>
+#include <linux/err.h>
 #include <asm/byteorder.h>
 #include <errno.h>
 #include <getopt.h>
@@ -52,6 +53,7 @@ static int do_oftree(int argc, char *argv[])
 	int save = 0;
 	int free_of = 0;
 	int ret;
+	struct device_node *n, *root;
 
 	while ((opt = getopt(argc, argv, "dpfn:ls")) > 0) {
 		switch (opt) {
@@ -135,7 +137,17 @@ static int do_oftree(int argc, char *argv[])
 			goto out;
 		}
 
-		ret = of_unflatten_dtb(fdt);
+		n = of_get_root_node();
+
+		root = of_unflatten_dtb(n, fdt);
+		if (IS_ERR(root))
+			ret = PTR_ERR(root);
+		else
+			ret = 0;
+
+		if (!n)
+			ret = of_set_root_node(root);
+
 		if (ret) {
 			printf("parse oftree: %s\n", strerror(-ret));
 			goto out;
drivers/of/base.c +36 -21

119 lines not on this page · raw message

include/of.h +2 -1
index d780dcf..333a7eb 100644
@@ -133,7 +133,7 @@ void of_print_nodes(struct device_node *node, int indent);
 int of_probe(void);
 int of_parse_dtb(struct fdt_header *fdt);
 void of_free(struct device_node *node);
-int of_unflatten_dtb(struct fdt_header *fdt);
+struct device_node *of_unflatten_dtb(struct device_node *root, struct fdt_header *fdt);
 struct device_node *of_new_node(struct device_node *parent, const char *name);
 struct property *of_new_property(struct device_node *node, const char *name,
 		const void *data, int len);
@@ -150,6 +150,7 @@ int of_parse_partitions(const char *cdevname,
 			    struct device_node *node);
 
 struct device_node *of_get_root_node(void);
+int of_set_root_node(struct device_node *);
 int of_alias_get_id(struct device_node *np, const char *stem);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw

PATCH 11/37 of: Add root node argument to of_find_node_by_path

In reply to Sascha Hauer

This makes of_find_node_by_path usable with multiple trees.

---
 arch/arm/boards/highbank/init.c |    2 +-
 commands/of_node.c              |    2 +-
 commands/of_property.c          |   10 ++++++++--
 commands/oftree.c               |   10 +++++++++-
 drivers/of/base.c               |   16 +++++++---------
 include/of.h                    |    2 +-
 6 files changed, 27 insertions(+), 15 deletions(-)
arch/arm/boards/highbank/init.c +1 -1
index 0f64fc8..a689b6a 100644
@@ -79,7 +79,7 @@ static int highbank_mem_init(void)
 
 	of_set_root_node(root);
 
-	np = of_find_node_by_path("/memory");
+	np = of_find_node_by_path(root, "/memory");
 	if (!np) {
 		pr_warn("no memory node use default configuration\n");
 		goto not_found;
commands/of_node.c +1 -1
index bf9799c..2f6ecae 100644
@@ -79,7 +79,7 @@ static int do_of_node(int argc, char *argv[])
 		if (!path)
 			return COMMAND_ERROR_USAGE;
 
-		node = of_find_node_by_path(path);
+		node = of_find_node_by_path(root, path);
 		if (!node) {
 			printf("Cannot find nodepath %s\n", path);
 			return -ENOENT;
commands/of_property.c +8 -2
index 42b6f11..585522c 100644
@@ -176,7 +176,7 @@ static int do_of_property(int argc, char *argv[])
 	int set = 0;
 	int ret;
 	char *path = NULL, *propname = NULL;
-	struct device_node *node = NULL;
+	struct device_node *root, *node = NULL;
 	struct property *pp = NULL;
 
 	while ((opt = getopt(argc, argv, "ds")) > 0) {
@@ -192,9 +192,15 @@ static int do_of_property(int argc, char *argv[])
 		}
 	}
 
+	root = of_get_root_node();
+	if (!root) {
+		printf("root node not set\n");
+		return -ENOENT;
+	}
+
 	if (optind < argc) {
 		path = argv[optind];
-		node = of_find_node_by_path(path);
+		node = of_find_node_by_path(root, path);
 		if (!node) {
 			printf("Cannot find nodepath %s\n", path);
 			return -ENOENT;
commands/oftree.c +9 -1
index 68e3fb4..83ffe12 100644
@@ -158,7 +158,15 @@ static int do_oftree(int argc, char *argv[])
 		if (fdt) {
 			ret = fdt_print(fdt, node);
 		} else {
-			struct device_node *n = of_find_node_by_path(node);
+			struct device_node *root, *n;
+
+			root = of_get_root_node();
+			if (!root) {
+				ret = -ENOENT;
+				goto out;
+			}
+
+			n = of_find_node_by_path(root, node);
 
 			if (!n) {
 				ret = -ENOENT;
drivers/of/base.c +7 -9
index ae15524..721db29 100644
@@ -146,7 +146,7 @@ void of_alias_scan(void)
 
 	INIT_LIST_HEAD(&aliases_lookup);
 
-	of_aliases = of_find_node_by_path("/aliases");
+	of_aliases = of_find_node_by_path(root_node, "/aliases");
 	if (!of_aliases)
 		return;
 
@@ -163,7 +163,7 @@ void of_alias_scan(void)
 		    !strcmp(pp->name, "linux,phandle"))
 			continue;
 
-		np = of_find_node_by_path(pp->value);
+		np = of_find_node_by_path(root_node, pp->value);
 		if (!np)
 			continue;
 
@@ -483,18 +483,16 @@ EXPORT_SYMBOL(of_machine_is_compatible);
 
 /**
  *	of_find_node_by_path - Find a node matching a full OF path
+ *	@root:	The root node of this tree
  *	@path:	The full path to match
  *
  *	Returns a node pointer with refcount incremented, use
  *	of_node_put() on it when done.
  */
-struct device_node *of_find_node_by_path(const char *path)
+struct device_node *of_find_node_by_path(struct device_node *root, const char *path)
 {
 	char *slash, *p, *freep;
-	struct device_node *dn = root_node;
-
-	if (!root_node)
-		return NULL;
+	struct device_node *dn = root;
 
 	if (*path != '/')
 		return NULL;
@@ -964,7 +962,7 @@ int of_probe(void)
 	if(!root_node)
 		return -ENODEV;
 
-	of_chosen = of_find_node_by_path("/chosen");
+	of_chosen = of_find_node_by_path(root_node, "/chosen");
 	of_property_read_string(root_node, "model", &of_model);
 
 	__of_probe(root_node);
@@ -1193,7 +1191,7 @@ int of_device_is_stdout_path(struct device_d *dev)
 	name = of_get_property(of_chosen, "linux,stdout-path", NULL);
 	if (name == NULL)
 		return 0;
-	dn = of_find_node_by_path(name);
+	dn = of_find_node_by_path(root_node, name);
 
 	if (!dn)
 		return 0;
include/of.h +1 -1
index 333a7eb..63c99b2 100644
@@ -70,7 +70,7 @@ int of_match(struct device_d *dev, struct driver_d *drv);
 
 struct property *of_find_property(const struct device_node *node, const char *name);
 
-struct device_node *of_find_node_by_path(const char *path);
+struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
 
 struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#12 lore raw

PATCH 12/37 of: Add of_write_number helper

In reply to Sascha Hauer

The counterpart to of_read_number: Write a 32bit or 64bit number to a devicetree.

---
 include/of.h |   11 +++++++++++
 1 file changed, 11 insertions(+)
include/of.h +11 -0
index 63c99b2..6154490 100644
@@ -96,6 +96,17 @@ static inline u64 of_read_number(const __be32 *cell, int size)
 	return r;
 }
 
+/* Helper to write a big number; size is in cells (not bytes) */
+static inline void of_write_number(void *__cell, u64 val, int size)
+{
+	__be32 *cell = __cell;
+
+	while (size--) {
+		cell[size] = cpu_to_be32(val);
+		val >>= 32;
+	}
+}
+
 int of_property_read_u32_array(const struct device_node *np,
 			       const char *propname, u32 *out_values,
 			       size_t sz);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#13 lore raw

PATCH 13/37 of: Add initrd helper

In reply to Sascha Hauer

Add a helper to set the initrd properties in the unflattened tree.

---
 drivers/of/base.c |   39 +++++++++++++++++++++++++++++++++++++++
 include/of.h      |    3 +++
 2 files changed, 42 insertions(+)
drivers/of/base.c +39 -0
index 721db29..4dbe11e 100644
@@ -1201,3 +1201,42 @@ int of_device_is_stdout_path(struct device_d *dev)
 
 	return 0;
 }
+
+/**
+ * of_add_initrd - add initrd properties to the devicetree
+ * @root - the root node of the tree
+ * @start - physical start address of the initrd image
+ * @end - physical end address of the initrd image
+ *
+ * Add initrd properties to the devicetree, or, if end is 0,
+ * delete them.
+ */
+int of_add_initrd(struct device_node *root, resource_size_t start,
+		resource_size_t end)
+{
+	struct device_node *chosen;
+	__be32 buf[2];
+
+	chosen = of_find_node_by_path(root, "/chosen");
+	if (!chosen)
+		return -EINVAL;
+
+	if (end) {
+		of_write_number(buf, start, 2);
+		of_set_property(chosen, "linux,initrd-start", buf, 8, 1);
+		of_write_number(buf, end, 2);
+		of_set_property(chosen, "linux,initrd-end", buf, 8, 1);
+	} else {
+		struct property *pp;
+
+		pp = of_find_property(chosen, "linux,initrd-start");
+		if (pp)
+			of_delete_property(pp);
+
+		pp = of_find_property(chosen, "linux,initrd-end");
+		if (pp)
+			of_delete_property(pp);
+	}
+
+	return 0;
+}
include/of.h +3 -0
index 6154490..1562f4e 100644
@@ -68,6 +68,9 @@ struct driver_d;
 
 int of_match(struct device_d *dev, struct driver_d *drv);
 
+int of_add_initrd(struct device_node *root, resource_size_t start,
+		resource_size_t end);
+
 struct property *of_find_property(const struct device_node *node, const char *name);
 
 struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#14 lore raw

Re: [PATCH 13/37] of: Add initrd helper

Hi Sascha,

Quoted 27 lines · Sascha Hauer

Add a helper to set the initrd properties in the unflattened tree.

---
 drivers/of/base.c |   39 +++++++++++++++++++++++++++++++++++++++
 include/of.h      |    3 +++
 2 files changed, 42 insertions(+)
drivers/of/base.c +11 -0
index 721db29..4dbe11e 100644
@@ -1201,3 +1201,42 @@ int of_device_is_stdout_path(struct device_d *dev)
 
 	return 0;
 }
+
+/**
+ * of_add_initrd - add initrd properties to the devicetree
+ * @root - the root node of the tree
+ * @start - physical start address of the initrd image
+ * @end - physical end address of the initrd image
+ *
+ * Add initrd properties to the devicetree, or, if end is 0,
+ * delete them.
+ */
+int of_add_initrd(struct device_node *root, resource_size_t start,

drivers/of/base.c int of_device_is_stdout_path(struct device_d *dev) · line 1224

Quoted 10 lines
drivers/of/base.c +10 -0
+		resource_size_t end)
+{
+	struct device_node *chosen;
+	__be32 buf[2];
+
+	chosen = of_find_node_by_path(root, "/chosen");
+	if (!chosen)
+		return -EINVAL;
+
+	if (end) {

Perhaps it's better here to check on (start && end) instead of end address only.

Similar in "[PATCH 35/37] ARM bootm: Switch initrd support to unflattened tree" at "of_add_reserve_entry(initrd_start, initrd_end);".

Regards
Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#15 lore raw

PATCH 14/37 of: make unflatten independent of libfdt

In reply to Sascha Hauer
---
 drivers/of/base.c |  160 +++++++++++++++++++++++++++++++++++++++++------------
 include/of.h      |    2 +-
 2 files changed, 127 insertions(+), 35 deletions(-)
drivers/of/base.c +126 -34
index 4dbe11e..8bb80e6 100644
@@ -1025,92 +1025,184 @@ out:
 	return dn;
 }
 
+static inline uint32_t dt_struct_advance(struct fdt_header *f, uint32_t dt, int size)
+{
+	dt += size;
+	dt = ALIGN(dt, 4);
+
+	if (dt > f->off_dt_struct + f->size_dt_struct)
+		return 0;
+
+	return dt;
+}
+
+static inline char *dt_string(struct fdt_header *f, char *strstart, uint32_t ofs)
+{
+	if (ofs > f->size_dt_strings)
+		return NULL;
+	else
+		return strstart + ofs;
+}
+
 /**
- * of_unflatten_dtb - unflatten a fdt blob
+ * of_unflatten_dtb - unflatten a dtb binary blob
  * @root - node in which the fdt blob should be merged into or NULL
- * @fdt - the fdt blob to unflatten
+ * @infdt - the fdt blob to unflatten
  *
  * Parse a flat device tree binary blob and return a pointer to the
  * unflattened tree.
  */
-struct device_node *of_unflatten_dtb(struct device_node *root, struct fdt_header *fdt)
+struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
 {
 	const void *nodep;	/* property node pointer */
-	int  nodeoffset;	/* node offset from libfdt */
-	int  nextoffset;	/* next node offset from libfdt */
 	uint32_t tag;		/* tag */
 	int  len;		/* length of the property */
 	const struct fdt_property *fdt_prop;
-	const char *pathp;
+	const char *pathp, *name;
 	struct device_node *node = NULL, *n;
 	struct property *p;
-	int ret;
+	uint32_t dt_struct;
+	struct fdt_node_header *fnh;
+	void *dt_strings;
+	struct fdt_header f;
+	int ret, merge = 0;
+	unsigned int maxlen;
+	struct fdt_header *fdt = infdt;
+
+	if (fdt->magic != cpu_to_fdt32(FDT_MAGIC)) {
+		pr_err("bad magic: 0x%08x\n", fdt32_to_cpu(fdt->magic));
+		return ERR_PTR(-EINVAL);
+	}
 
-	nodeoffset = fdt_path_offset(fdt, "/");
-	if (nodeoffset < 0) {
-		/*
-		 * Not found or something else bad happened.
-		 */
-		printf ("libfdt fdt_path_offset() returned %s\n",
-			fdt_strerror(nodeoffset));
+	if (fdt->version != cpu_to_fdt32(17)) {
+		pr_err("bad dt version: 0x%08x\n", fdt32_to_cpu(fdt->version));
 		return ERR_PTR(-EINVAL);
 	}
 
-	if (!root) {
+	f.totalsize = fdt32_to_cpu(fdt->totalsize);
+	f.off_dt_struct = fdt32_to_cpu(fdt->off_dt_struct);
+	f.size_dt_struct = fdt32_to_cpu(fdt->size_dt_struct);
+	f.off_dt_strings = fdt32_to_cpu(fdt->off_dt_strings);
+	f.size_dt_strings = fdt32_to_cpu(fdt->size_dt_strings);
+
+	if (f.off_dt_struct + f.size_dt_struct > f.totalsize) {
+		pr_err("unflatten: dt size exceeds total size\n");
+		return ERR_PTR(-ESPIPE);
+	}
+
+	if (f.off_dt_strings + f.size_dt_strings > f.totalsize) {
+		pr_err("unflatten: string size exceeds total size\n");
+		return ERR_PTR(-ESPIPE);
+	}
+
+	dt_struct = f.off_dt_struct;
+	dt_strings = (void *)fdt + f.off_dt_strings;
+
+	if (root) {
+		pr_debug("unflatten: merging into existing tree\n");
+		merge = 1;
+	} else {
 		root = of_new_node(NULL, NULL);
 		if (!root)
 			return ERR_PTR(-ENOMEM);
 	}
 
 	while (1) {
-		tag = fdt_next_tag(fdt, nodeoffset, &nextoffset);
+		tag = be32_to_cpu(*(uint32_t *)(infdt + dt_struct));
+
 		switch (tag) {
 		case FDT_BEGIN_NODE:
-			pathp = fdt_get_name(fdt, nodeoffset, NULL);
+			fnh = infdt + dt_struct;
+			pathp = name = fnh->name;
+			maxlen = (unsigned long)fdt + f.off_dt_struct +
+				f.size_dt_struct - (unsigned long)name;
+
+			len = strnlen(name, maxlen + 1);
+			if (len > maxlen) {
+				ret = -ESPIPE;
+				goto err;
+			}
 
-			if (pathp == NULL)
-				pathp = "/* NULL pointer error */";
+			dt_struct = dt_struct_advance(&f, dt_struct,
+					sizeof(struct fdt_node_header) + len + 1);
+			if (!dt_struct) {
+				ret = -ESPIPE;
+				goto err;
+			}
 
 			if (!node) {
 				node = root;
 			} else {
-				if ((n = of_find_child_by_name(node, pathp))) {
+				if (merge && (n = of_find_child_by_name(node, pathp)))
 					node = n;
-				} else {
+				else
 					node = of_new_node(node, pathp);
-				}
 			}
+
 			break;
+
 		case FDT_END_NODE:
+			if (!node) {
+				pr_err("unflatten: too many end nodes\n");
+				ret = -EINVAL;
+				goto err;
+			}
+
 			node = node->parent;
+
+			dt_struct = dt_struct_advance(&f, dt_struct, FDT_TAGSIZE);
+			if (!dt_struct) {
+				ret = -ESPIPE;
+				goto err;
+			}
+
 			break;
+
 		case FDT_PROP:
-			fdt_prop = fdt_offset_ptr(fdt, nodeoffset,
-					sizeof(*fdt_prop));
-			pathp    = fdt_string(fdt,
-					fdt32_to_cpu(fdt_prop->nameoff));
-			len      = fdt32_to_cpu(fdt_prop->len);
-			nodep    = fdt_prop->data;
-
-			p = of_find_property(node, pathp);
-			if (p) {
+			fdt_prop = infdt + dt_struct;
+			len = fdt32_to_cpu(fdt_prop->len);
+			nodep = fdt_prop->data;
+
+			name = dt_string(&f, dt_strings, fdt32_to_cpu(fdt_prop->nameoff));
+			if (!name) {
+				ret = -ESPIPE;
+				goto err;
+			}
+
+			dt_struct = dt_struct_advance(&f, dt_struct,
+					sizeof(struct fdt_property) + len);
+			if (!dt_struct) {
+				ret = -ESPIPE;
+				goto err;
+			}
+
+			if (merge && (p = of_find_property(node, name))) {
 				free(p->value);
 				p->value = xzalloc(len);
 				memcpy(p->value, nodep, len);
 			} else {
-				of_new_property(node, pathp, nodep, len);
+				of_new_property(node, name, nodep, len);
 			}
+
 			break;
+
 		case FDT_NOP:
+			dt_struct = dt_struct_advance(&f, dt_struct, FDT_TAGSIZE);
+			if (!dt_struct) {
+				ret = -ESPIPE;
+				goto err;
+			}
+
 			break;
+
 		case FDT_END:
 			return root;
+
 		default:
-			printf("Unknown tag 0x%08X\n", tag);
+			pr_err("unflatten: Unknown tag 0x%08X\n", tag);
 			ret = -EINVAL;
 			goto err;
 		}
-		nodeoffset = nextoffset;
 	}
 err:
 	of_free(root);
include/of.h +1 -1
index 1562f4e..4622b80 100644
@@ -147,7 +147,7 @@ void of_print_nodes(struct device_node *node, int indent);
 int of_probe(void);
 int of_parse_dtb(struct fdt_header *fdt);
 void of_free(struct device_node *node);
-struct device_node *of_unflatten_dtb(struct device_node *root, struct fdt_header *fdt);
+struct device_node *of_unflatten_dtb(struct device_node *root, void *fdt);
 struct device_node *of_new_node(struct device_node *parent, const char *name);
 struct property *of_new_property(struct device_node *node, const char *name,
 		const void *data, int len);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#16 lore raw

PATCH 15/37 of: make flatten independent of libfdt

In reply to Sascha Hauer
---
 common/oftree.c   |    8 ++-
 drivers/of/base.c |  180 ++++++++++++++++++++++++++++++++++++++++++++---------
 include/of.h      |    6 +-
 3 files changed, 162 insertions(+), 32 deletions(-)
common/oftree.c +7 -1
index 82e5ddd..555aa0b 100644
@@ -422,7 +422,13 @@ struct fdt_header *of_get_fixed_tree(struct fdt_header *fdt)
 	int size, align;
 
 	if (!fdt) {
-		fdt = internalfdt = of_flatten_dtb();
+		struct device_node *root_node;
+
+		root_node = of_get_root_node();
+		if (!root_node)
+			return NULL;
+
+		fdt = internalfdt = of_flatten_dtb(root_node);
 		if (!fdt)
 			return NULL;
 	}
drivers/of/base.c +151 -29

216 lines not on this page · raw message

include/of.h +4 -2
index 4622b80..2cd55c0 100644
@@ -64,6 +64,8 @@ struct of_device_id {
 	unsigned long data;
 };
 
+#define OF_MAX_RESERVE_MAP	16
+
 struct driver_d;
 
 int of_match(struct device_d *dev, struct driver_d *drv);
@@ -168,7 +170,7 @@ int of_set_root_node(struct device_node *);
 int of_alias_get_id(struct device_node *np, const char *stem);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
-void *of_flatten_dtb(void);
+void *of_flatten_dtb(struct device_node *node);
 int of_add_memory(struct device_node *node, bool dump);
 #else
 static inline int of_parse_partitions(const char *cdevname,
@@ -197,7 +199,7 @@ static inline const char *of_get_model(void)
 	return NULL;
 }
 
-static inline void *of_flatten_dtb(void)
+static inline void *of_flatten_dtb(struct device_node *node)
 {
 	return NULL;
 }
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#17 lore raw

PATCH 16/37 of/fdt: use optimized endianess conversion

In reply to Sascha Hauer
---
 include/libfdt_env.h |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
include/libfdt_env.h +4 -5
index e83aa96..6486187 100644
@@ -3,13 +3,12 @@
 
 #include <linux/types.h>
 #include <string.h>
+#include <asm/byteorder.h>
 
 #define _B(n)	((unsigned long long)((uint8_t *)&x)[n])
-static inline uint32_t fdt32_to_cpu(uint32_t x)
-{
-	return (_B(0) << 24) | (_B(1) << 16) | (_B(2) << 8) | _B(3);
-}
-#define cpu_to_fdt32(x) fdt32_to_cpu(x)
+
+#define fdt32_to_cpu(x)	be32_to_cpu(x)
+#define cpu_to_fdt32(x) cpu_to_be32(x)
 
 static inline uint64_t fdt64_to_cpu(uint64_t x)
 {
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#18 lore raw

PATCH 17/37 oftree command: Use of_print_nodes

In reply to Sascha Hauer
---
 commands/oftree.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
commands/oftree.c +10 -3
index 83ffe12..612d01a 100644
@@ -156,7 +156,14 @@ static int do_oftree(int argc, char *argv[])
 
 	if (dump) {
 		if (fdt) {
-			ret = fdt_print(fdt, node);
+			root = of_unflatten_dtb(NULL, fdt);
+			if (IS_ERR(root)) {
+				printf("parse oftree: %s\n", strerror(-PTR_ERR(root)));
+				ret = 1;
+				goto out;
+			}
+			of_print_nodes(root, 0);
+			of_free(root);
 		} else {
 			struct device_node *root, *n;
 
@@ -174,10 +181,10 @@ static int do_oftree(int argc, char *argv[])
 			}
 
 			of_print_nodes(n, 0);
-
-			ret = 0;
 		}
 
+		ret = 0;
+
 		goto out;
 	}
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#19 lore raw

PATCH 18/37 of: move OFTREE Kconfig option to drivers/of/

In reply to Sascha Hauer
---
 drivers/of/Kconfig |    4 ++++
 lib/Kconfig        |    4 ----
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/of/Kconfig +4 -0
index 95f10d0..5e53d25 100644
@@ -1,2 +1,6 @@
+config OFTREE
+	select FDT
+	bool
+
 config OFDEVICE
 	bool
lib/Kconfig +0 -4
index 4578353..d58109b 100644
@@ -25,10 +25,6 @@ source lib/lzo/Kconfig
 config FDT
 	bool
 
-config OFTREE
-	select FDT
-	bool
-
 config BCH
 	bool
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#20 lore raw

PATCH 19/37 of: make OFDEVICE a user selectable option

In reply to Sascha Hauer

OFDEVICE decides whether or not we compile in support for probing devices from the devicetree. Let the user decide this explicitly. This makes the oftree, of_node and of_property commands independent of devicetree device support since being able to manipulate devicetrees has nothing to do with probing devices from the devicetree.

---
 commands/Kconfig   |    3 ---
 drivers/Makefile   |    2 +-
 drivers/of/Kconfig |    3 ++-
 include/of.h       |   12 ++++--------
 4 files changed, 7 insertions(+), 13 deletions(-)
commands/Kconfig +0 -3
index c1454c7..c8f06d8 100644
@@ -481,7 +481,6 @@ config CMD_GO
 config CMD_OFTREE
 	tristate
 	select OFTREE
-	select OFDEVICE
 	prompt "oftree"
 	help
 	  The oftree command has support for dumping devicetrees and, if
@@ -497,7 +496,6 @@ config CMD_OFTREE_PROBE
 config CMD_OF_PROPERTY
 	tristate
 	select OFTREE
-	select OFDEVICE
 	prompt "of_property"
 	help
 	  The of_property command allows setting and deleting of properties in
@@ -506,7 +504,6 @@ config CMD_OF_PROPERTY
 config CMD_OF_NODE
 	tristate
 	select OFTREE
-	select OFDEVICE
 	prompt "of_node"
 	help
 	  The of_property command allows adding and removing devicetree nodes.
drivers/Makefile +1 -1
index f81bf99..03a10fb 100644
@@ -20,5 +20,5 @@ obj-y	+= misc/
 obj-y	+= dma/
 obj-y  += watchdog/
 obj-y	+= gpio/
-obj-$(CONFIG_OFDEVICE) += of/
+obj-$(CONFIG_OFTREE) += of/
 obj-$(CONFIG_W1) += w1/
drivers/of/Kconfig +2 -1
index 5e53d25..c30b1c1 100644
@@ -3,4 +3,5 @@ config OFTREE
 	bool
 
 config OFDEVICE
-	bool
+	select OFTREE
+	bool "Enable probing of devices from the devicetree"
include/of.h +4 -8
index 2cd55c0..2234dae 100644
@@ -161,12 +161,13 @@ int of_set_property(struct device_node *node, const char *p, const void *val, in
 		int create);
 struct device_node *of_create_node(struct device_node *root, const char *path);
 
-#ifdef CONFIG_OFDEVICE
+struct device_node *of_get_root_node(void);
+int of_set_root_node(struct device_node *);
+
+#ifdef CONFIG_OFTREE
 int of_parse_partitions(const char *cdevname,
 			    struct device_node *node);
 
-struct device_node *of_get_root_node(void);
-int of_set_root_node(struct device_node *);
 int of_alias_get_id(struct device_node *np, const char *stem);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
@@ -179,11 +180,6 @@ static inline int of_parse_partitions(const char *cdevname,
 	return -EINVAL;
 }
 
-static inline struct device_node *of_get_root_node(void)
-{
-	return NULL;
-}
-
 static inline int of_alias_get_id(struct device_node *np, const char *stem)
 {
 	return -ENOENT;
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#21 lore raw

PATCH 20/37 oftree command: retire CMD_OFTREE_PROBE Kconfig option

In reply to Sascha Hauer

Whether or not the user wishes devicetree probe support can now be decided indepentently of the oftree command, so retire the CMD_OFTREE_PROBE option and use OFDEVICE in the code instead.

---
 commands/Kconfig  |    7 -------
 commands/oftree.c |    2 +-
 2 files changed, 1 insertion(+), 8 deletions(-)
commands/Kconfig +0 -7
index c8f06d8..0062758 100644
@@ -486,13 +486,6 @@ config CMD_OFTREE
 	  The oftree command has support for dumping devicetrees and, if
 	  enabled, to probe devices from the devicetree
 
-config CMD_OFTREE_PROBE
-	bool
-	depends on CMD_OFTREE
-	prompt "oftree probe support"
-	help
-	  This enables the -p option to probe devices from the devicetree
-
 config CMD_OF_PROPERTY
 	tristate
 	select OFTREE
commands/oftree.c +1 -1
index 612d01a..e4f52b8 100644
@@ -64,7 +64,7 @@ static int do_oftree(int argc, char *argv[])
 			dump = 1;
 			break;
 		case 'p':
-			if (IS_ENABLED(CONFIG_CMD_OFTREE_PROBE)) {
+			if (IS_ENABLED(CONFIG_OFDEVICE)) {
 				probe = 1;
 			} else {
 				printf("oftree device probe support disabled\n");
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#22 lore raw

PATCH 21/37 of: move oftree Kconfig to the top of the drivers menu

In reply to Sascha Hauer

Using OFDEVICE is a basic decision, so move it to the top of the driver menu.

---
 drivers/Kconfig |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/Kconfig +1 -1
index 16ca5b9..b213849 100644
@@ -1,5 +1,6 @@
 menu "Drivers"
 
+source "drivers/of/Kconfig"
 source "drivers/amba/Kconfig"
 source "drivers/serial/Kconfig"
 source "drivers/net/Kconfig"
@@ -21,7 +22,6 @@ source "drivers/watchdog/Kconfig"
 source "drivers/pwm/Kconfig"
 source "drivers/dma/Kconfig"
 source "drivers/gpio/Kconfig"
-source "drivers/of/Kconfig"
 source "drivers/w1/Kconfig"
 
 endmenu
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#23 lore raw

PATCH 22/37 of: Pass barebox internal format devicetree to of_get_fixed_tree

In reply to Sascha Hauer

With this every devicetree is first converted to the barebox internal format before it's converted back to dtb again.

---
 arch/arm/lib/bootm.c |   10 +++++++++-
 commands/bootm.c     |    9 ++++++++-
 common/oftree.c      |   19 +++++++++----------
 include/of.h         |    3 ++-
 4 files changed, 28 insertions(+), 13 deletions(-)
arch/arm/lib/bootm.c +9 -1
index cf192cf..234f3e0 100644
@@ -181,7 +181,15 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 	}
 
 	if (IS_BUILTIN(CONFIG_OFTREE)) {
-		data->oftree = of_get_fixed_tree(oftree);
+		struct device_node *node;
+
+		node = of_unflatten_dtb(NULL, oftree);
+		if (!node) {
+			pr_err("unable to unflatten devicetree\n");
+			return -EINVAL;
+		}
+
+		data->oftree = of_get_fixed_tree(node);
 	}
 
 	pr_info("zImage: concatenated oftree detected\n");
commands/bootm.c +8 -1
index 4d3f022..38233e7 100644
@@ -140,6 +140,7 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 	enum filetype ft;
 	struct fdt_header *fdt, *fixfdt;
 	size_t size;
+	struct device_node *node;
 
 	printf("Loading devicetree from '%s'\n", oftree);
 
@@ -187,7 +188,13 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 				file_type_to_string(ft));
 	}
 
-	fixfdt = of_get_fixed_tree(fdt);
+	node = of_unflatten_dtb(NULL, fdt);
+	if (!node) {
+		pr_err("unable to unflatten devicetree\n");
+		return -EINVAL;
+	}
+
+	fixfdt = of_get_fixed_tree(node);
 	if (!fixfdt)
 		return -EINVAL;
 
common/oftree.c +9 -10
index 555aa0b..be9eb28 100644
@@ -415,24 +415,23 @@ int of_fix_tree(struct fdt_header *fdt)
  * It increases the size of the tree and applies the registered
  * fixups.
  */
-struct fdt_header *of_get_fixed_tree(struct fdt_header *fdt)
+struct fdt_header *of_get_fixed_tree(struct device_node *node)
 {
 	int ret;
 	void *fixfdt, *internalfdt = NULL;
 	int size, align;
+	struct fdt_header *fdt;
 
-	if (!fdt) {
-		struct device_node *root_node;
-
-		root_node = of_get_root_node();
-		if (!root_node)
-			return NULL;
-
-		fdt = internalfdt = of_flatten_dtb(root_node);
-		if (!fdt)
+	if (!node) {
+		node = of_get_root_node();
+		if (!node)
 			return NULL;
 	}
 
+	fdt = internalfdt = of_flatten_dtb(node);
+	if (!fdt)
+		return NULL;
+
 	size = fdt_totalsize(fdt);
 
 	/*
include/of.h +2 -1
index 2234dae..fe9f65d 100644
@@ -7,7 +7,6 @@
 
 int fdt_print(struct fdt_header *working_fdt, const char *pathp);
 
-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 *));
 
@@ -81,6 +80,8 @@ struct device_node *of_find_child_by_name(struct device_node *node, const char *
 
 struct fdt_header *fdt_get_tree(void);
 
+struct fdt_header *of_get_fixed_tree(struct device_node *node);
+
 #define device_node_for_nach_child(node, child) \
 	list_for_each_entry(child, &node->children, parent_list)
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#24 lore raw

PATCH 23/37 bootm: Use of_print_nodes instead of fdt_print

In reply to Sascha Hauer

Now that we use the unflattened tree in bootm we can use of_print_nodes instead of printing the flattened tree.

---
 commands/bootm.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
commands/bootm.c +3 -3
index 38233e7..65a75e2 100644
@@ -194,15 +194,15 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 		return -EINVAL;
 	}
 
+	if (bootm_verbose(data) > 1)
+		of_print_nodes(node, 0);
+
 	fixfdt = of_get_fixed_tree(node);
 	if (!fixfdt)
 		return -EINVAL;
 
 	free(fdt);
 
-	if (bootm_verbose(data) > 1)
-		fdt_print(fixfdt, "/");
-
 	data->oftree = fixfdt;
 
 	return 0;
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#25 lore raw

PATCH 24/37 of: move flat devicetree functions to separate file

In reply to Sascha Hauer
---
 drivers/of/Makefile |    2 +-
 drivers/of/base.c   |  372 -----------------------------------------------
 drivers/of/dtb.c    |  401 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 402 insertions(+), 373 deletions(-)
 create mode 100644 drivers/of/dtb.c
drivers/of/Makefile +1 -1
index 5a5960d..fc71962 100644
@@ -1,3 +1,3 @@
-obj-y += base.o
+obj-y += base.o dtb.o
 obj-$(CONFIG_GPIOLIB) += gpio.o
 obj-y += partition.o
drivers/of/base.c +0 -372

378 lines not on this page · raw message

drivers/of/dtb.c new file +401 -0

401 lines not on this page · raw message

Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#26 lore raw

PATCH 25/37 of: Add of property write functions for u32

In reply to Sascha Hauer
---
 drivers/of/base.c |   25 +++++++++++++++++++++++++
 include/of.h      |   11 +++++++++++
 2 files changed, 36 insertions(+)
drivers/of/base.c +25 -0
index b9db261..9f9d9a0 100644
@@ -350,6 +350,31 @@ int of_property_read_u32_array(const struct device_node *np,
 }
 EXPORT_SYMBOL_GPL(of_property_read_u32_array);
 
+int of_property_write_u32_array(struct device_node *np,
+				const char *propname, const u32 *values,
+				size_t sz)
+{
+	struct property *prop = of_find_property(np, propname);
+	__be32 *val;
+
+	if (!prop)
+		prop = of_new_property(np, propname, NULL, 0);
+	if (!prop)
+		return -ENOMEM;
+
+	free(prop->value);
+
+	prop->value = malloc(sizeof(__be32) * sz);
+	if (!prop->value)
+		return -ENOMEM;
+
+	val = prop->value;
+
+	while (sz--)
+		*val++ = cpu_to_be32(*values++);
+	return 0;
+}
+
 /**
  * of_parse_phandles_with_args - Find a node pointed by phandle in a list
  * @np:		pointer to a device tree node containing a list
include/of.h +11 -0
index fe9f65d..eeea016 100644
@@ -124,6 +124,17 @@ static inline int of_property_read_u32(const struct device_node *np,
 	return of_property_read_u32_array(np, propname, out_value, 1);
 }
 
+int of_property_write_u32_array(struct device_node *np,
+				const char *propname, const u32 *values,
+				size_t sz);
+
+static inline int of_property_write_u32(struct device_node *np,
+					const char *propname,
+					u32 value)
+{
+	return of_property_write_u32_array(np, propname, &value, 1);
+}
+
 const void *of_get_property(const struct device_node *np, const char *name,
 			 int *lenp);
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#27 lore raw

PATCH 26/37 of: make value of property in of_new_property optional

In reply to Sascha Hauer
---
 drivers/of/base.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/of/base.c +4 -2
index 9f9d9a0..5891138 100644
@@ -677,8 +677,10 @@ struct property *of_new_property(struct device_node *node, const char *name,
 
 	prop->name = strdup(name);
 	prop->length = len;
-	prop->value = xzalloc(len);
-	memcpy(prop->value, data, len);
+	if (len) {
+		prop->value = xzalloc(len);
+		memcpy(prop->value, data, len);
+	}
 
 	list_add_tail(&prop->list, &node->properties);
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#28 lore raw

PATCH 27/37 of: Add missing prototype for size/address counting functions

In reply to Sascha Hauer
---
 include/of.h |    3 +++
 1 file changed, 3 insertions(+)
include/of.h +3 -0
index eeea016..85adc80 100644
@@ -72,6 +72,9 @@ int of_match(struct device_d *dev, struct driver_d *drv);
 int of_add_initrd(struct device_node *root, resource_size_t start,
 		resource_size_t end);
 
+int of_n_addr_cells(struct device_node *np);
+int of_n_size_cells(struct device_node *np);
+
 struct property *of_find_property(const struct device_node *node, const char *name);
 
 struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#29 lore raw

PATCH 28/37 of: fixup unflattened devicetree

In reply to Sascha Hauer
---
 arch/arm/boards/at91sam9x5ek/hw_version.c |   31 +++++++------
 arch/arm/boards/highbank/init.c           |   33 +++++++++-----
 arch/ppc/mach-mpc5xxx/cpu.c               |   26 +++++++----
 common/memory.c                           |   48 ++++++--------------
 common/oftree.c                           |   70 +++++++++--------------------
 include/of.h                              |    6 +--
 6 files changed, 94 insertions(+), 120 deletions(-)
arch/arm/boards/at91sam9x5ek/hw_version.c +15 -16
index 47c640a..2695faa 100644
@@ -232,26 +232,25 @@ static void at91sam9x5ek_devices_detect_one(const char *name)
 
 #define NODE_NAME_LEN  128
 
-static int cm_cogent_fixup(struct fdt_header *fdt)
+static int cm_cogent_fixup(struct device_node *root)
 {
-	int off, ret;
-	char node_name[NODE_NAME_LEN];
+	int ret;
+	struct device_node *node;
 
-	off = fdt_node_offset_by_compatible(fdt, -1, "atmel,hsmci");
+	of_tree_for_each_node(node, root) {
+		struct device_node *slotnode;
 
-	while (off != -FDT_ERR_NOTFOUND) {
-		off = fdt_subnode_offset(fdt, off, "slot");
-		fdt_get_path(fdt, off, node_name, NODE_NAME_LEN);
-		ret = fdt_setprop(fdt, off, "broken-cd", NULL, 0);
-		if (ret < 0) {
-			pr_err("error %d while adding broken-cd property to node %s\n",
-				ret, node_name);
-			return ret;
-		} else {
-			pr_debug("add broken-cd property to node %s\n", node_name);
-		}
+		if (!of_device_is_compatible(node, "atmel,hsmci"))
+			continue;
 
-		off = fdt_node_offset_by_compatible(fdt, off, "atmel,hsmci");
+		slotnode = of_find_child_by_name(node, "slot");
+		if (!slotnode)
+			continue;
+
+		ret = of_set_property(slotnode, "broken-cd", NULL, 0, 1);
+		if (ret)
+			pr_err("error %d while adding broken-cd property to node %s\n",
+				ret, slotnode->name);
 	}
 
 	return 0;
arch/arm/boards/highbank/init.c +22 -11
index a689b6a..bd32c1d 100644
@@ -25,8 +25,9 @@
 
 struct fdt_header *fdt = NULL;
 
-static int hb_fixup(struct fdt_header *fdt)
+static int hb_fixup(struct device_node *root)
 {
+	struct device_node *node;
 	u32 reg = readl(sregs_base + HB_SREG_A9_PWRDOM_DATA);
 	u32 *opp_table = (u32 *)HB_SYSRAM_OPP_TABLE_BASE;
 	u32 dtb_table[2*10];
@@ -34,17 +35,29 @@ static int hb_fixup(struct fdt_header *fdt)
 	u32 num_opps;
 	__be32 latency;
 
-	if (!(reg & HB_PWRDOM_STAT_SATA))
-		do_fixup_by_compatible_string(fdt, "calxeda,hb-ahci", "status",
-					           "disabled", 1);
+	if (!(reg & HB_PWRDOM_STAT_SATA)) {
+		of_tree_for_each_node(node, root) {
+			if (of_device_is_compatible(node, "calxeda,hb-ahci"))
+				of_set_property(node, "status", "disabled",
+						sizeof("disabled"), 1);
+		}
+	}
 
-	if (!(reg & HB_PWRDOM_STAT_EMMC))
-		do_fixup_by_compatible_string(fdt, "calxeda,hb-sdhci", "status",
-					           "disabled", 1);
+	if (!(reg & HB_PWRDOM_STAT_EMMC)) {
+		of_tree_for_each_node(node, root) {
+			if (of_device_is_compatible(node, "calxeda,hb-sdhci"))
+				of_set_property(node, "status", "disabled",
+						sizeof("disabled"), 1);
+		}
+	}
 
 	if ((opp_table[0] >> 16) != HB_OPP_VERSION)
 		return 0;
 
+	node = of_find_node_by_path(root, "/cpus/cpu@0");
+	if (!node)
+		return 0;
+
 	num_opps = opp_table[0] & 0xff;
 
 	for (i = 0; i < num_opps; i++) {
@@ -54,10 +67,8 @@ static int hb_fixup(struct fdt_header *fdt)
 
 	latency = cpu_to_be32(opp_table[1]);
 
-	fdt_find_and_setprop(fdt, "/cpus/cpu@0", "transition-latency",
-				  &latency, 4, 1);
-	fdt_find_and_setprop(fdt, "/cpus/cpu@0", "operating-points",
-				  dtb_table, 8 * num_opps, 1);
+	of_set_property(node, "transition-latency", &latency, 4, 1);
+	of_set_property(node, "operating-points", dtb_table, 8 * num_opps, 1);
 
 	return 0;
 }
arch/ppc/mach-mpc5xxx/cpu.c +18 -8
index 5bbd49a..99f16eb 100644
@@ -77,17 +77,27 @@ void __noreturn reset_cpu (unsigned long addr)
 /* ------------------------------------------------------------------------- */
 
 #ifdef CONFIG_OFTREE
-static int of_mpc5200_fixup(struct fdt_header *fdt)
+static int of_mpc5200_fixup(struct device_node *root)
 {
-	char *cpu_path = "/cpus/PowerPC,5200@0";
+	struct device_node *node;
+
 	int div = in_8((void*)CFG_MBAR + 0x204) & 0x0020 ? 8 : 4;
 
-	do_fixup_by_path_u32(fdt, cpu_path, "timebase-frequency", get_timebase_clock(), 1);
-	do_fixup_by_path_u32(fdt, cpu_path, "bus-frequency", get_bus_clock(), 1);
-	do_fixup_by_path_u32(fdt, cpu_path, "clock-frequency", get_cpu_clock(), 1);
-	do_fixup_by_path_u32(fdt, "/soc5200@f0000000", "bus-frequency", get_ipb_clock(), 1);
-	do_fixup_by_path_u32(fdt, "/soc5200@f0000000", "system-frequency",
-				get_bus_clock() * div, 1);
+	node = of_find_node_by_path(root, "/cpus/PowerPC,5200@0");
+	if (!node)
+		return -EINVAL;
+
+	of_property_write_u32(node, "timebase-frequency", get_timebase_clock());
+	of_property_write_u32(node, "bus-frequency", get_bus_clock());
+	of_property_write_u32(node, "clock-frequency", get_cpu_clock());
+
+	node = of_find_node_by_path(root, "/soc5200@f0000000");
+	if (!node)
+		return -EINVAL;
+
+	of_property_write_u32(node, "bus-frequency", get_ipb_clock());
+	of_property_write_u32(node, "system-frequency", get_bus_clock() * div);
+
 	return 0;
 }
 
common/memory.c +14 -34

76 lines not on this page · raw message

common/oftree.c +22 -48

117 lines not on this page · raw message

include/of.h +3 -3
index 85adc80..ef6a4ce 100644
@@ -7,9 +7,6 @@
 
 int fdt_print(struct fdt_header *working_fdt, const char *pathp);
 
-int of_fix_tree(struct fdt_header *fdt);
-int of_register_fixup(int (*fixup)(struct fdt_header *));
-
 int fdt_find_and_setprop(struct fdt_header *fdt, const char *node, const char *prop,
 			 const void *val, int len, int create);
 void do_fixup_by_path(struct fdt_header *fdt, const char *path, const char *prop,
@@ -67,6 +64,9 @@ struct of_device_id {
 
 struct driver_d;
 
+int of_fix_tree(struct device_node *);
+int of_register_fixup(int (*fixup)(struct device_node *));
+
 int of_match(struct device_d *dev, struct driver_d *drv);
 
 int of_add_initrd(struct device_node *root, resource_size_t start,
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#30 lore raw

PATCH 29/37 of_* commands: print usage when insufficient arguments are given

In reply to Sascha Hauer
---
 commands/of_node.c     |    3 +++
 commands/of_property.c |    3 +++
 2 files changed, 6 insertions(+)
commands/of_node.c +3 -0
index 2f6ecae..171ea2c 100644
@@ -54,6 +54,9 @@ static int do_of_node(int argc, char *argv[])
 		}
 	}
 
+	if (optind == argc)
+		return COMMAND_ERROR_USAGE;
+
 	if (optind < argc) {
 		path = argv[optind];
 	}
commands/of_property.c +3 -0
index 585522c..bd9ff72 100644
@@ -192,6 +192,9 @@ static int do_of_property(int argc, char *argv[])
 		}
 	}
 
+	if (optind == argc)
+		return COMMAND_ERROR_USAGE;
+
 	root = of_get_root_node();
 	if (!root) {
 		printf("root node not set\n");
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#31 lore raw

PATCH 30/37 of_property command: Fix crash with empty property value

In reply to Sascha Hauer

the of_property command crashes when an empty property value was given. This is because xrealloc is called with a length argument of 0. Fix this.

---
 commands/of_property.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
commands/of_property.c +8 -2
index bd9ff72..1567a0f 100644
@@ -255,9 +255,15 @@ static int do_of_property(int argc, char *argv[])
 
 		if (pp) {
 			free(pp->value);
+
 			/* limit property data to the actual size */
-			data = xrealloc(data, len);
-			pp->value = data;
+			if (len) {
+				pp->value = xrealloc(data, len);
+			} else {
+				pp->value = NULL;
+				free(data);
+			}
+
 			pp->length = len;
 		} else {
 			pp = of_new_property(node, propname, data, len);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#32 lore raw

PATCH 31/37 ARM: bootm: rework concatenated oftree

In reply to Sascha Hauer

Without compiled in devicetree support we used to copy the concatenated devicetree directly behind the zImage. This is unnecessary, even if we do not have devicetree support we can copy the devicetree whereever we like and pass the kernel a pointer to it. This makes the code a bit easier. While at it, add the missing free calls in the error case.

---
 arch/arm/lib/bootm.c |   36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)
arch/arm/lib/bootm.c +16 -20
index 234f3e0..2a7d0f5 100644
@@ -131,8 +131,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;
 
@@ -151,21 +149,10 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 
 	end = be32_to_cpu(header->totalsize);
 
-	if (IS_BUILTIN(CONFIG_OFTREE)) {
-		oftree = malloc(end + 0x8000);
-		if (!oftree) {
-			perror("zImage: oftree malloc");
-			return -ENOMEM;
-		}
-	} else {
-
-		of_res = request_sdram_region("oftree", r->start + resource_size(r), end);
-		if (!of_res) {
-			perror("zImage: oftree request_sdram_region");
-			return -ENOMEM;
-		}
-
-		oftree = (void*)of_res->start;
+	oftree = malloc(end + 0x8000);
+	if (!oftree) {
+		perror("zImage: oftree malloc");
+		return -ENOMEM;
 	}
 
 	memcpy(oftree, header, sizeof(*header));
@@ -174,10 +161,11 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 
 	ret = read_full(fd, oftree + sizeof(*header), end);
 	if (ret < 0)
-		return ret;
+		goto err_free;
 	if (ret < end) {
 		printf("premature end of image\n");
-		return -EIO;
+		ret = -EIO;
+		goto err_free;
 	}
 
 	if (IS_BUILTIN(CONFIG_OFTREE)) {
@@ -186,15 +174,23 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 		node = of_unflatten_dtb(NULL, oftree);
 		if (!node) {
 			pr_err("unable to unflatten devicetree\n");
-			return -EINVAL;
+			ret = -EINVAL;
+			goto err_free;
 		}
 
 		data->oftree = of_get_fixed_tree(node);
+	} else {
+		data->oftree = oftree;
 	}
 
 	pr_info("zImage: concatenated oftree detected\n");
 
 	return 0;
+
+err_free:
+	free(oftree);
+
+	return ret;
 }
 
 static int do_bootz_linux(struct image_data *data)
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#33 lore raw

PATCH 32/37 of: memory: Use of_write_number

In reply to Sascha Hauer
---
 common/memory.c |   25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)
common/memory.c +6 -19
index 1d2e3a3..61cca0d 100644
@@ -164,19 +164,6 @@ int release_sdram_region(struct resource *res)
 
 #ifdef CONFIG_OFTREE
 
-/*
- * Write a 4 or 8 byte big endian cell
- */
-static void write_cell(u8 *addr, u64 val, int size)
-{
-	int shift = (size - 1) * 8;
-
-	while (size-- > 0) {
-		*addr++ = (val >> shift) & 0xff;
-		shift -= 8;
-	}
-}
-
 static int of_memory_fixup(struct device_node *node)
 {
 	struct memory_bank *bank;
@@ -193,14 +180,14 @@ static int of_memory_fixup(struct device_node *node)
 	if (err)
 		return err;
 
-	addr_cell_len = of_n_addr_cells(memnode) * 4;
-	size_cell_len = of_n_size_cells(memnode) * 4;
+	addr_cell_len = of_n_addr_cells(memnode);
+	size_cell_len = of_n_size_cells(memnode);
 
 	for_each_memory_bank(bank) {
-		write_cell(tmp + len, bank->start, addr_cell_len);
-		len += addr_cell_len;
-		write_cell(tmp + len, bank->size, size_cell_len);
-		len += size_cell_len;
+		of_write_number(tmp + len, bank->start, addr_cell_len);
+		len += addr_cell_len * 4;
+		of_write_number(tmp + len, bank->size, size_cell_len);
+		len += size_cell_len * 4;
 	}
 
 	err = of_set_property(memnode, "reg", tmp, len, 1);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#34 lore raw

PATCH 33/37 of: Add reservemap handling

In reply to Sascha Hauer
---
 drivers/of/dtb.c |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/of.h     |   10 +++++++++
 2 files changed, 75 insertions(+)
drivers/of/dtb.c +65 -0
index 3867128..856b591 100644
@@ -399,3 +399,68 @@ out_free:
 
 	return NULL;
 }
+
+/*
+ * The last entry is the zeroed sentinel, the one before is
+ * reserved for the reservemap entry for the dtb itself.
+ */
+#define OF_MAX_FREE_RESERVE_MAP	(OF_MAX_RESERVE_MAP - 2)
+
+static struct of_reserve_map of_reserve_map;
+
+int of_add_reserve_entry(resource_size_t start, resource_size_t end)
+{
+	int e = of_reserve_map.num_entries;
+
+	if (e >= OF_MAX_FREE_RESERVE_MAP)
+		return -ENOSPC;
+
+	of_reserve_map.start[e] = start;
+	of_reserve_map.end[e] = end;
+	of_reserve_map.num_entries++;
+
+	return 0;
+}
+
+struct of_reserve_map *of_get_reserve_map(void)
+{
+	return &of_reserve_map;
+}
+
+void of_clean_reserve_map(void)
+{
+	of_reserve_map.num_entries = 0;
+}
+
+/**
+ * fdt_add_reserve_map - Add reserve map entries to a devicetree binary
+ * @__fdt: The devicetree blob
+ *
+ * This adds the reservemap entries previously colllected in
+ * of_add_reserve_entry() to a devicetree binary blob. This also
+ * adds the devicetree itself to the reserved list, so after calling
+ * this function the tree should not be relocated anymore.
+ */
+void fdt_add_reserve_map(void *__fdt)
+{
+	struct fdt_header *fdt = __fdt;
+	struct of_reserve_map *res = &of_reserve_map;
+	struct fdt_reserve_entry *fdt_res =
+		__fdt + be32_to_cpu(fdt->off_mem_rsvmap);
+	int i;
+
+	for (i = 0; i < res->num_entries; i++) {
+		of_write_number(&fdt_res->address, res->start[i], 2);
+		of_write_number(&fdt_res->size, res->end[i] - res->start[i] + 1,
+				2);
+		fdt_res++;
+	}
+
+	of_write_number(&fdt_res->address, (unsigned long)__fdt, 2);
+	of_write_number(&fdt_res->size, (unsigned long)__fdt +
+			be32_to_cpu(fdt->totalsize), 2);
+	fdt_res++;
+
+	of_write_number(&fdt_res->address, 0, 2);
+	of_write_number(&fdt_res->size, 0, 2);
+}
include/of.h +10 -0
index ef6a4ce..1535694 100644
@@ -61,6 +61,16 @@ struct of_device_id {
 };
 
 #define OF_MAX_RESERVE_MAP	16
+struct of_reserve_map {
+	uint64_t start[OF_MAX_RESERVE_MAP];
+	uint64_t end[OF_MAX_RESERVE_MAP];
+	int num_entries;
+};
+
+int of_add_reserve_entry(resource_size_t start, resource_size_t end);
+struct of_reserve_map *of_get_reserve_map(void);
+void of_clean_reserve_map(void);
+void fdt_add_reserve_map(void *fdt);
 
 struct driver_d;
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#35 lore raw

PATCH 34/37 bootm: Pass unflattened devicetree to handlers

In reply to Sascha Hauer

This makes it possible to modify the tree in the handlers. This is necessary because the initrd addresses are only known inside the handlers, but not to the generic bootm code.

---
 arch/arm/lib/bootm.c    |    8 ++------
 arch/ppc/Kconfig        |    1 +
 arch/ppc/lib/ppclinux.c |    8 ++++++++
 commands/bootm.c        |   24 +++++++++---------------
 include/boot.h          |    1 +
 5 files changed, 21 insertions(+), 21 deletions(-)
arch/arm/lib/bootm.c +2 -6
index 2a7d0f5..00c4908 100644
@@ -169,16 +169,12 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 	}
 
 	if (IS_BUILTIN(CONFIG_OFTREE)) {
-		struct device_node *node;
-
-		node = of_unflatten_dtb(NULL, oftree);
-		if (!node) {
+		data->of_root_node = of_unflatten_dtb(NULL, oftree);
+		if (!data->of_root_node) {
 			pr_err("unable to unflatten devicetree\n");
 			ret = -EINVAL;
 			goto err_free;
 		}
-
-		data->oftree = of_get_fixed_tree(node);
 	} else {
 		data->oftree = oftree;
 	}
arch/ppc/Kconfig +1 -0
index d124065..db269dd 100644
@@ -4,6 +4,7 @@ config PPC
 	select HAS_KALLSYMS
 	select HAS_MODULES
 	select HAVE_CONFIGURABLE_MEMORY_LAYOUT
+	select OFTREE
 	default y
 
 choice
arch/ppc/lib/ppclinux.c +8 -0
index 95dc83b..ef69ead 100644
@@ -18,6 +18,14 @@ static int do_bootm_linux(struct image_data *data)
 	if (!data->os_res)
 		return -EINVAL;
 
+	data->oftree = of_get_fixed_tree(data->of_root_node);
+	if (!data->oftree) {
+		pr_err("bootm: No devicetree given.\n");
+		return -EINVAL;
+	}
+
+	fdt_add_reserve_map(data->oftree);
+
 	kernel = (void *)(data->os_address + data->os_entry);
 
 	/*
commands/bootm.c +9 -15
index 65a75e2..ea5a35b 100644
@@ -138,9 +138,8 @@ static int bootm_open_initrd_uimage(struct image_data *data)
 static int bootm_open_oftree(struct image_data *data, const char *oftree, int num)
 {
 	enum filetype ft;
-	struct fdt_header *fdt, *fixfdt;
+	struct fdt_header *fdt;
 	size_t size;
-	struct device_node *node;
 
 	printf("Loading devicetree from '%s'\n", oftree);
 
@@ -188,23 +187,14 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 				file_type_to_string(ft));
 	}
 
-	node = of_unflatten_dtb(NULL, fdt);
-	if (!node) {
+	data->of_root_node = of_unflatten_dtb(NULL, fdt);
+	if (!data->of_root_node) {
 		pr_err("unable to unflatten devicetree\n");
 		return -EINVAL;
 	}
 
-	if (bootm_verbose(data) > 1)
-		of_print_nodes(node, 0);
-
-	fixfdt = of_get_fixed_tree(node);
-	if (!fixfdt)
-		return -EINVAL;
-
 	free(fdt);
 
-	data->oftree = fixfdt;
-
 	return 0;
 }
 #endif
@@ -408,10 +398,14 @@ static int do_bootm(int argc, char *argv[])
 		if (ret)
 			goto err_out;
 	} else {
-		data.oftree = of_get_fixed_tree(NULL);
-		if (bootm_verbose(&data) && data.oftree)
+		data.of_root_node = of_get_root_node();
+		if (bootm_verbose(&data) && data.of_root_node)
 			printf("using internal devicetree\n");
 	}
+
+
+	if (bootm_verbose(&data) > 1 && data.of_root_node)
+		of_print_nodes(data.of_root_node, 0);
 #endif
 	if (data.os_address == UIMAGE_SOME_ADDRESS)
 		data.os_address = UIMAGE_INVALID_ADDRESS;
include/boot.h +1 -0
index 3ce0de1..971a403 100644
@@ -41,6 +41,7 @@ struct image_data {
 
 	unsigned long initrd_address;
 
+	struct device_node *of_root_node;
 	struct fdt_header *oftree;
 
 	int verify;
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#36 lore raw

PATCH 35/37 ARM bootm: Switch initrd support to unflattened tree

In reply to Sascha Hauer
---
 arch/arm/lib/armlinux.c |    2 --
 arch/arm/lib/bootm.c    |   11 +++++++-
 common/oftree.c         |   66 -----------------------------------------------
 3 files changed, 10 insertions(+), 69 deletions(-)
arch/arm/lib/armlinux.c +0 -2
index 4dd84ed..40a63ea 100644
@@ -266,8 +266,6 @@ void start_linux(void *adr, int swap, unsigned long initrd_address,
 
 	if (oftree) {
 		printf("booting Linux kernel with devicetree\n");
-		fdt_initrd(oftree, initrd_address,
-			initrd_address + initrd_size, 1);
 		params = oftree;
 	} else {
 		setup_tags(initrd_address, initrd_size, swap);
arch/arm/lib/bootm.c +10 -1
index 00c4908..4decee4 100644
@@ -26,7 +26,7 @@
 static int __do_bootm_linux(struct image_data *data, int swap)
 {
 	unsigned long kernel;
-	unsigned long initrd_start = 0, initrd_size = 0;
+	unsigned long initrd_start = 0, initrd_size = 0, initrd_end = 0;
 	struct memory_bank *bank;
 	unsigned long load_address;
 
@@ -82,9 +82,18 @@ static int __do_bootm_linux(struct image_data *data, int swap)
 
 	if (data->initrd_res) {
 		initrd_start = data->initrd_res->start;
+		initrd_end = data->initrd_res->end;
 		initrd_size = resource_size(data->initrd_res);
 	}
 
+	if (IS_ENABLED(CONFIG_OFTREE) && data->of_root_node) {
+		of_add_initrd(data->of_root_node, initrd_start, initrd_end);
+		if (initrd_end)
+			of_add_reserve_entry(initrd_start, initrd_end);
+		data->oftree = of_get_fixed_tree(data->of_root_node);
+		fdt_add_reserve_map(data->oftree);
+	}
+
 	if (bootm_verbose(data)) {
 		printf("\nStarting kernel at 0x%08lx", kernel);
 		if (initrd_size)
common/oftree.c +0 -66

72 lines not on this page · raw message

Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#37 lore raw

PATCH 36/37 of: remove unused libfdt

In reply to Sascha Hauer

Now that we are completely independent of libfdt remove the unused code.

---
 arch/arm/boards/at91sam9m10ihd/hw_version.c |    1 -
 arch/arm/boards/at91sam9x5ek/hw_version.c   |    1 -
 arch/arm/boards/highbank/init.c             |    3 +-
 arch/arm/boards/sama5d3xek/hw_version.c     |    1 -
 arch/arm/lib/bootm.c                        |    1 -
 commands/bootm.c                            |    1 -
 commands/of_node.c                          |    1 -
 commands/of_property.c                      |    1 -
 commands/oftree.c                           |    3 +-
 common/memory.c                             |    1 -
 common/oftree.c                             |  175 ----
 drivers/of/Kconfig                          |    1 -
 drivers/of/base.c                           |    1 -
 drivers/of/dtb.c                            |    1 -
 include/fdt.h                               |   13 +
 include/libfdt.h                            | 1235 ---------------------------
 include/libfdt_env.h                        |   21 -
 include/of.h                                |   24 -
 lib/Kconfig                                 |    3 -
 lib/Makefile                                |    1 -
 lib/fdt/Makefile                            |    2 -
 lib/fdt/TODO                                |    3 -
 lib/fdt/fdt.c                               |  222 -----
 lib/fdt/fdt_ro.c                            |  574 -------------
 lib/fdt/fdt_rw.c                            |  465 ----------
 lib/fdt/fdt_strerror.c                      |   96 ---
 lib/fdt/fdt_sw.c                            |  256 ------
 lib/fdt/fdt_wip.c                           |  118 ---
 lib/fdt/libfdt_internal.h                   |   95 ---
 29 files changed, 15 insertions(+), 3305 deletions(-)
 delete mode 100644 include/libfdt.h
 delete mode 100644 include/libfdt_env.h
 delete mode 100644 lib/fdt/Makefile
 delete mode 100644 lib/fdt/TODO
 delete mode 100644 lib/fdt/fdt.c
 delete mode 100644 lib/fdt/fdt_ro.c
 delete mode 100644 lib/fdt/fdt_rw.c
 delete mode 100644 lib/fdt/fdt_strerror.c
 delete mode 100644 lib/fdt/fdt_sw.c
 delete mode 100644 lib/fdt/fdt_wip.c
 delete mode 100644 lib/fdt/libfdt_internal.h
arch/arm/boards/at91sam9m10ihd/hw_version.c +0 -1
index cd522f7..be910df 100644
@@ -20,7 +20,6 @@
 #include <libbb.h>
 #include <asm/armlinux.h>
 #include <of.h>
-#include <libfdt.h>
 
 #include "hw_version.h"
 
arch/arm/boards/at91sam9x5ek/hw_version.c +0 -1
index 2695faa..76d4e1b 100644
@@ -20,7 +20,6 @@
 #include <libbb.h>
 #include <asm/armlinux.h>
 #include <of.h>
-#include <libfdt.h>
 
 #include "hw_version.h"
 
arch/arm/boards/highbank/init.c +1 -2
index bd32c1d..d4a5c5a 100644
@@ -16,7 +16,6 @@
 #include <partition.h>
 #include <sizes.h>
 #include <io.h>
-#include <libfdt.h>
 #include <of.h>
 
 #define FIRMWARE_DTB_BASE	0x1000
@@ -124,7 +123,7 @@ static int highbank_devices_init(void)
 		highbank_register_xgmac(1);
 	} else {
 		fdt = of_get_fixed_tree(NULL);
-		add_mem_device("dtb", (unsigned long)fdt, fdt_totalsize(fdt),
+		add_mem_device("dtb", (unsigned long)fdt, be32_to_cpu(fdt->totalsize),
 		       IORESOURCE_MEM_WRITEABLE);
 		devfs_add_partition("ram0", FIRMWARE_DTB_BASE, SZ_64K, DEVFS_PARTITION_FIXED, "firmware-dtb");
 	}
arch/arm/boards/sama5d3xek/hw_version.c +0 -1
index a9fcf7d..79fd63a 100644
@@ -20,7 +20,6 @@
 #include <libbb.h>
 #include <asm/armlinux.h>
 #include <of.h>
-#include <libfdt.h>
 
 #include "hw_version.h"
 
arch/arm/lib/bootm.c +0 -1
index 4decee4..e7a0625 100644
@@ -14,7 +14,6 @@
 #include <sizes.h>
 #include <libbb.h>
 #include <magicvar.h>
-#include <libfdt.h>
 #include <binfmt.h>
 
 #include <asm/byteorder.h>
commands/bootm.c +0 -1
index ea5a35b..e5dfc6a 100644
@@ -34,7 +34,6 @@
 #include <errno.h>
 #include <boot.h>
 #include <of.h>
-#include <libfdt.h>
 #include <rtc.h>
 #include <init.h>
 #include <of.h>
commands/of_node.c +0 -1
index 171ea2c..0249d97 100644
@@ -24,7 +24,6 @@
 #include <command.h>
 #include <fs.h>
 #include <malloc.h>
-#include <libfdt.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <errno.h>
commands/of_property.c +0 -1
index 1567a0f..6311b70 100644
@@ -24,7 +24,6 @@
 #include <command.h>
 #include <fs.h>
 #include <malloc.h>
-#include <libfdt.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <errno.h>
commands/oftree.c +1 -2
index e4f52b8..468235a 100644
@@ -30,7 +30,6 @@
 #include <command.h>
 #include <fs.h>
 #include <malloc.h>
-#include <libfdt.h>
 #include <linux/ctype.h>
 #include <linux/err.h>
 #include <asm/byteorder.h>
@@ -114,7 +113,7 @@ static int do_oftree(int argc, char *argv[])
 			goto out;
 		}
 
-		ret = write_file(file, fdt, fdt_totalsize(fdt));
+		ret = write_file(file, fdt, fdt32_to_cpu(fdt->totalsize));
 
 		goto out;
 	}
common/memory.c +0 -1
index 61cca0d..7ec211b 100644
@@ -21,7 +21,6 @@
 #include <memory.h>
 #include <of.h>
 #include <init.h>
-#include <libfdt.h>
 #include <linux/ioport.h>
 #include <asm-generic/memory_layout.h>
 #include <asm/sections.h>
common/oftree.c +0 -175

187 lines not on this page · raw message

drivers/of/Kconfig +0 -1
index c30b1c1..031bec1 100644
@@ -1,5 +1,4 @@
 config OFTREE
-	select FDT
 	bool
 
 config OFDEVICE
drivers/of/base.c +0 -1
index 5891138..ada3fc1 100644
@@ -20,7 +20,6 @@
 #include <common.h>
 #include <of.h>
 #include <errno.h>
-#include <libfdt.h>
 #include <malloc.h>
 #include <init.h>
 #include <memory.h>
drivers/of/dtb.c +0 -1
index 856b591..6d6b76d 100644
@@ -20,7 +20,6 @@
 #include <common.h>
 #include <of.h>
 #include <errno.h>
-#include <libfdt.h>
 #include <malloc.h>
 #include <init.h>
 #include <memory.h>
include/fdt.h +13 -0
index 48ccfd9..35278e3 100644
@@ -3,6 +3,19 @@
 
 #ifndef __ASSEMBLY__
 
+#define _B(n)	((unsigned long long)((uint8_t *)&x)[n])
+
+#define fdt32_to_cpu(x)	be32_to_cpu(x)
+#define cpu_to_fdt32(x) cpu_to_be32(x)
+
+static inline uint64_t fdt64_to_cpu(uint64_t x)
+{
+	return (_B(0) << 56) | (_B(1) << 48) | (_B(2) << 40) | (_B(3) << 32)
+		| (_B(4) << 24) | (_B(5) << 16) | (_B(6) << 8) | _B(7);
+}
+#define cpu_to_fdt64(x) fdt64_to_cpu(x)
+#undef _B
+
 struct fdt_header {
 	uint32_t magic;			 /* magic word FDT_MAGIC */
 	uint32_t totalsize;		 /* total size of DT block */
include/libfdt.h deleted +0 -0
deleted file mode 100644
index 55f3eb3..0000000
include/libfdt_env.h deleted +0 -0
deleted file mode 100644
index 6486187..0000000
include/of.h +0 -24
index 1535694..c10afa7 100644
@@ -5,30 +5,6 @@
 #include <errno.h>
 #include <asm/byteorder.h>
 
-int fdt_print(struct fdt_header *working_fdt, const char *pathp);
-
-int fdt_find_and_setprop(struct fdt_header *fdt, const char *node, const char *prop,
-			 const void *val, int len, int create);
-void do_fixup_by_path(struct fdt_header *fdt, const char *path, const char *prop,
-		      const void *val, int len, int create);
-void do_fixup_by_path_u32(struct fdt_header *fdt, const char *path, const char *prop,
-			  u32 val, int create);
-void do_fixup_by_compatible(struct fdt_header *fdt, const char *compatible,
-			const char *prop, const void *val, int len, int create);
-void do_fixup_by_compatible_u32(struct fdt_header *fdt, const char *compatible,
-				const char *prop, u32 val, int create);
-void do_fixup_by_compatible_string(struct fdt_header *fdt, const char *compatible,
-				const char *prop, const char *val, int create);
-int fdt_get_path_or_create(struct fdt_header *fdt, const char *path);
-#ifdef CONFIG_FDT
-int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force);
-#else
-static inline int fdt_initrd(void *fdt, ulong start, ulong end, int force)
-{
-	return 0;
-}
-#endif
-
 #define OF_BAD_ADDR      ((u64)-1)
 
 typedef u32 phandle;
lib/Kconfig +0 -3
index d58109b..646fdb7 100644
@@ -22,9 +22,6 @@ config PROCESS_ESCAPE_SEQUENCE
 
 source lib/lzo/Kconfig
 
-config FDT
-	bool
-
 config BCH
 	bool
 
lib/Makefile +0 -1
index 3c94542..7c42537 100644
@@ -31,7 +31,6 @@ obj-y			+= lzo/
 obj-y			+= show_progress.o
 obj-$(CONFIG_LZO_DECOMPRESS)		+= decompress_unlzo.o
 obj-$(CONFIG_PROCESS_ESCAPE_SEQUENCE)	+= process_escape_sequence.o
-obj-$(CONFIG_FDT)	+= fdt/
 obj-$(CONFIG_UNCOMPRESS)	+= uncompress.o
 obj-$(CONFIG_BCH)	+= bch.o
 obj-$(CONFIG_BITREV)	+= bitrev.o
lib/fdt/Makefile deleted +0 -0
deleted file mode 100644
index 853bee9..0000000
lib/fdt/TODO deleted +0 -0
deleted file mode 100644
index 288437e..0000000
lib/fdt/fdt.c deleted +0 -0
deleted file mode 100644
index e56833a..0000000
lib/fdt/fdt_ro.c deleted +0 -0
deleted file mode 100644
index 02b6d68..0000000
lib/fdt/fdt_rw.c deleted +0 -0
deleted file mode 100644
index 994037b..0000000
lib/fdt/fdt_strerror.c deleted +0 -0
deleted file mode 100644
index e6c3cee..0000000
lib/fdt/fdt_sw.c deleted +0 -0
deleted file mode 100644
index 55ebebf..0000000
lib/fdt/fdt_wip.c deleted +0 -0
deleted file mode 100644
index 6025fa1..0000000
lib/fdt/libfdt_internal.h deleted +0 -0
deleted file mode 100644
index 381133b..0000000
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#38 lore raw

PATCH 37/37 of: make locally used functions static

In reply to Sascha Hauer
---
 drivers/of/base.c |    6 +++---
 include/of.h      |    2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/of/base.c +3 -3
index ada3fc1..d22031f 100644
@@ -96,7 +96,7 @@ static void of_bus_default_count_cells(struct device_node *dev,
 		*sizec = of_n_size_cells(dev);
 }
 
-void of_bus_count_cells(struct device_node *dev,
+static void of_bus_count_cells(struct device_node *dev,
 			int *addrc, int *sizec)
 {
 	of_bus_default_count_cells(dev, addrc, sizec);
@@ -135,7 +135,7 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
  * the global lookup table with the properties.  It returns the
  * number of alias_prop found, or error code in error case.
  */
-void of_alias_scan(void)
+static void of_alias_scan(void)
 {
 	struct property *pp;
 	struct alias_prop *app, *tmp;
@@ -814,7 +814,7 @@ static struct device_d *add_of_device(struct device_node *node)
 }
 EXPORT_SYMBOL(add_of_device);
 
-u64 dt_mem_next_cell(int s, const __be32 **cellp)
+static u64 dt_mem_next_cell(int s, const __be32 **cellp)
 {
 	const __be32 *p = *cellp;
 
include/of.h +2 -0
index c10afa7..94ccfd8 100644
@@ -143,6 +143,8 @@ int of_device_is_compatible(const struct device_node *device,
 
 int of_machine_is_compatible(const char *compat);
 
+u64 of_translate_address(struct device_node *node, const __be32 *in_addr);
+
 #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
 #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox