linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Jon Loeliger <jdl@freescale.com>
Cc: linuxppc-dev@ozlabs.org
Subject: [dtc] Allow references to labels
Date: Wed, 7 Feb 2007 14:29:07 +1100	[thread overview]
Message-ID: <20070207032907.GE23870@localhost.localdomain> (raw)

dtc allows nodes to have labels, which at present are just re-emitted
as symbols at the appropriate places when using asm-mode output.  It
also allows "references" where the notation &/path/to/node in a cell
list will be replaced with the phandle of the referenced node.

This patch extends the reference syntax to allow references to labels
instead of just full device paths.  This allows nodes deep within the
tree to be referenced with a shorter more convenient name.  References
to labels are distinguished from reference to paths by the fact that
paths must start with a /, but labels can never start with a /.

Signed-off-by: David Gibson <dwg@au1.ibm.com>

Index: dtc/livetree.c
===================================================================
--- dtc.orig/livetree.c	2007-01-31 16:05:59.000000000 +1100
+++ dtc/livetree.c	2007-01-31 16:13:00.000000000 +1100
@@ -212,6 +212,24 @@ static struct node *get_node_by_path(str
 	return NULL;
 }
 
+static struct node *get_node_by_label(struct node *tree, const char *label)
+{
+	struct node *child, *node;
+
+	assert(label && (strlen(label) > 0));
+
+	if (tree->label && streq(tree->label, label))
+		return tree;
+
+	for_each_child(tree, child) {
+		node = get_node_by_label(child, label);
+		if (node)
+			return node;
+	}
+
+	return NULL;
+}
+
 static struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
 {
 	struct node *child, *node;	
@@ -229,6 +247,7 @@ static struct node *get_node_by_phandle(
 
 	return NULL;
 }
+
 /*
  * Tree checking functions
  */
@@ -673,9 +692,16 @@ static void apply_fixup(struct node *roo
 	struct node *refnode;
 	cell_t phandle;
 
-	refnode = get_node_by_path(root, f->ref);
-	if (! refnode)
-		die("Reference to non-existent node \"%s\"\n", f->ref);
+	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);
 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

             reply	other threads:[~2007-02-07  3:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-07  3:29 David Gibson [this message]
2007-02-07  4:36 ` [dtc] Allow references to labels Kumar Gala
2007-02-08 23:28 ` Jon Loeliger

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20070207032907.GE23870@localhost.localdomain \
    --to=david@gibson.dropbear.id.au \
    --cc=jdl@freescale.com \
    --cc=linuxppc-dev@ozlabs.org \
    /path/to/YOUR_REPLY

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

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