summaryrefslogtreecommitdiff
path: root/livetree.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2007-11-22 14:38:07 +1100
committerJon Loeliger <jdl@freescale.com>2007-11-26 16:00:08 -0600
commitb16a2bd89dbf109b9c8d1c9e047b9afa72af6d2f (patch)
tree199c466df196fe34582e47de3c2aab4eb2479a4c /livetree.c
parent67b6b33b9b413a450a72135b5dc59c0a1e33e647 (diff)
downloaddevice-tree-compiler-b16a2bd89dbf109b9c8d1c9e047b9afa72af6d2f.tar.gz
dtc: Flexible tree checking infrastructure (v2)
dtc: Flexible tree checking infrastructure Here, at last, is a substantial start on revising dtc's infrastructure for checking the tree; this is the rework I've been saying was necessary practically since dtc was first release. In the new model, we have a table of "check" structures, each with a name, references to checking functions, and status variables. Each check can (in principle) be individually switched off or on (as either a warning or error). Checks have a list of prerequisites, so if checks need to rely on results from earlier checks to make sense (or even to avoid crashing) they just need to list the relevant other checks there. For now, only the "structural" checks and the fixups for phandle references are converted to the new mechanism. The rather more involved semantic checks (which is where this new mechanism will really be useful) will have to be converted in future patches. At present, there's no user interface for turning on/off the checks - the -f option now forces output even if "error" level checks fail. Again, future patches will be needed to add the fine-grained control, but that should be quite straightforward with the infrastructure implemented here. Also adds a testcase for the handling of bad references, which catches a bug encountered while developing this patch. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'livetree.c')
-rw-r--r--livetree.c67
1 files changed, 11 insertions, 56 deletions
diff --git a/livetree.c b/livetree.c
index cdd1ab5..6f71c30 100644
--- a/livetree.c
+++ b/livetree.c
@@ -216,7 +216,7 @@ struct node *get_subnode(struct node *node, char *nodename)
return NULL;
}
-static struct node *get_node_by_path(struct node *tree, char *path)
+struct node *get_node_by_path(struct node *tree, char *path)
{
char *p;
struct node *child;
@@ -239,7 +239,7 @@ static struct node *get_node_by_path(struct node *tree, char *path)
return NULL;
}
-static struct node *get_node_by_label(struct node *tree, const char *label)
+struct node *get_node_by_label(struct node *tree, const char *label)
{
struct node *child, *node;
@@ -275,7 +275,15 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
return NULL;
}
-static cell_t get_node_phandle(struct node *root, struct node *node)
+struct node *get_node_by_ref(struct node *tree, char *ref)
+{
+ if (ref[0] == '/')
+ return get_node_by_path(tree, ref);
+ else
+ return get_node_by_label(tree, ref);
+}
+
+cell_t get_node_phandle(struct node *root, struct node *node)
{
static cell_t phandle = 1; /* FIXME: ick, static local */
@@ -295,56 +303,3 @@ static cell_t get_node_phandle(struct node *root, struct node *node)
return node->phandle;
}
-
-/*
- * Reference fixup functions
- */
-
-static void apply_fixup(struct node *root, struct property *prop,
- struct fixup *f)
-{
- struct node *refnode;
- cell_t phandle;
-
- if (f->ref[0] == '/') {
- /* Reference to full path */
- refnode = get_node_by_path(root, f->ref);
- if (! refnode)
- die("Reference to non-existent node \"%s\"\n", f->ref);
- } else {
- refnode = get_node_by_label(root, f->ref);
- if (! refnode)
- die("Reference to non-existent node label \"%s\"\n", f->ref);
- }
-
- phandle = get_node_phandle(root, refnode);
-
- assert(f->offset + sizeof(cell_t) <= prop->val.len);
-
- *((cell_t *)(prop->val.val + f->offset)) = cpu_to_be32(phandle);
-}
-
-static void fixup_phandles(struct node *root, struct node *node)
-{
- struct property *prop;
- struct node *child;
-
- for_each_property(node, prop) {
- struct fixup *f = prop->val.refs;
-
- while (f) {
- apply_fixup(root, prop, f);
- prop->val.refs = f->next;
- fixup_free(f);
- f = prop->val.refs;
- }
- }
-
- for_each_child(node, child)
- fixup_phandles(root, child);
-}
-
-void fixup_references(struct node *dt)
-{
- fixup_phandles(dt, dt);
-}