remove libfdt
Subsystems (4)
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
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
@@ -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
PATCH 2/37 of: export of_find_child
In reply to Sascha Hauerof_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
@@ -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
@@ -72,6 +72,8 @@ struct property *of_find_property(const struct device_node *node, const char *nastruct 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
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
@@ -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
PATCH 4/37 of: Let of_find_node_by_path iterate over tree
In reply to Sascha Hauerof_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
@@ -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
PATCH 5/37 of: remove allnodes list
In reply to Sascha HauerThe 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
@@ -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
@@ -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
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
@@ -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
PATCH 7/37 of: Add of_set_property and of_create_node
In reply to Sascha HauerAdd 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
@@ -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
@@ -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
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
@@ -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
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
@@ -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
PATCH 10/37 of: let of_unflatten_dtb return the unflattened tree
In reply to Sascha HauerIn 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
@@ -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
@@ -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
@@ -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
PATCH 11/37 of: Add root node argument to of_find_node_by_path
In reply to Sascha HauerThis 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH 12/37 of: Add of_write_number helper
In reply to Sascha HauerThe 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
@@ -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
PATCH 13/37 of: Add initrd helper
In reply to Sascha HauerAdd 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
@@ -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
@@ -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
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.
Signed-off-by Sascha Hauer <[email protected]>--- drivers/of/base.c | 39 +++++++++++++++++++++++++++++++++++++++ include/of.h | 3 +++ 2 files changed, 42 insertions(+)drivers/of/base.c +11
-0@@ -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
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
@@ -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
@@ -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
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
@@ -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
@@ -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
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
@@ -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
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
@@ -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
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
@@ -1,2 +1,6 @@ +config OFTREE + select FDT + bool + config OFDEVICE bool
lib/Kconfig +0 -4
@@ -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
PATCH 19/37 of: make OFDEVICE a user selectable option
In reply to Sascha HauerOFDEVICE 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH 20/37 oftree command: retire CMD_OFTREE_PROBE Kconfig option
In reply to Sascha HauerWhether 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
@@ -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
@@ -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
PATCH 21/37 of: move oftree Kconfig to the top of the drivers menu
In reply to Sascha HauerUsing 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
@@ -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
PATCH 22/37 of: Pass barebox internal format devicetree to of_get_fixed_tree
In reply to Sascha HauerWith 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
@@ -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
@@ -140,6 +140,7 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nuenum 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
@@ -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
@@ -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
PATCH 23/37 bootm: Use of_print_nodes instead of fdt_print
In reply to Sascha HauerNow 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
@@ -194,15 +194,15 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nureturn -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
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
@@ -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
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
@@ -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
@@ -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
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
@@ -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
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
@@ -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
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
@@ -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
@@ -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
@@ -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
@@ -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
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
@@ -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
@@ -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
PATCH 30/37 of_property command: Fix crash with empty property value
In reply to Sascha Hauerthe 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
@@ -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
PATCH 31/37 ARM: bootm: rework concatenated oftree
In reply to Sascha HauerWithout 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
@@ -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
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
@@ -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
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
@@ -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
@@ -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
PATCH 34/37 bootm: Pass unflattened devicetree to handlers
In reply to Sascha HauerThis 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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
@@ -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
@@ -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
PATCH 36/37 of: remove unused libfdt
In reply to Sascha HauerNow 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,5 +1,4 @@ config OFTREE - select FDT bool config OFDEVICE
drivers/of/base.c +0 -1
@@ -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
@@ -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
@@ -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
include/libfdt_env.h deleted +0 -0
include/of.h +0 -24
@@ -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
@@ -22,9 +22,6 @@ config PROCESS_ESCAPE_SEQUENCE source lib/lzo/Kconfig -config FDT - bool - config BCH bool
lib/Makefile +0 -1
@@ -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
lib/fdt/TODO deleted +0 -0
lib/fdt/fdt.c deleted +0 -0
lib/fdt/fdt_ro.c deleted +0 -0
lib/fdt/fdt_rw.c deleted +0 -0
lib/fdt/fdt_strerror.c deleted +0 -0
lib/fdt/fdt_sw.c deleted +0 -0
lib/fdt/fdt_wip.c deleted +0 -0
lib/fdt/libfdt_internal.h deleted +0 -0
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
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
@@ -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
@@ -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