Re: libfdt: Make unit address optional for finding nodes

2007-10-15 Thread Jon Loeliger
So, like, the other day David Gibson mumbled:
 At present, the fdt_subnode_offset() and fdt_path_offset() functions
 in libfdt require the exact name of the nodes in question be passed,
 including unit address.
 
 This is contrary to traditional OF-like finddevice() behaviour, which
 allows the unit address to be omitted (which is useful when the device
 name is unambiguous without the address).
 
 This patch introduces similar behaviour to
 fdt_subnode_offset_namelen(), and hence to fdt_subnode_offset() and
 fdt_path_offset() which are implemented in terms of the former.  The
 unit address can be omitted from the given node name.  If this is
 ambiguous, the first such node in the flattened tree will be selected
 (this behaviour is consistent with IEEE1275 which specifies only that
 an arbitrary node matching the given information be selected).
 
 This very small change is then followed by many more diffs which
 change the test examples and testcases to exercise this behaviour.
 
 Signed-off-by: David Gibson [EMAIL PROTECTED]
 ---

Applied.


 Jon, I initially considered making this behaviour optional,
 i.e. adding a flag to subnode_offset() determining if it needed exact
 matches or name-without-address matches.  I couldn't see that it was
 actually any use, though.

Yeah, sounds fine to me too.

Thanks,
jdl
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


libfdt: Make unit address optional for finding nodes

2007-09-27 Thread David Gibson
At present, the fdt_subnode_offset() and fdt_path_offset() functions
in libfdt require the exact name of the nodes in question be passed,
including unit address.

This is contrary to traditional OF-like finddevice() behaviour, which
allows the unit address to be omitted (which is useful when the device
name is unambiguous without the address).

This patch introduces similar behaviour to
fdt_subnode_offset_namelen(), and hence to fdt_subnode_offset() and
fdt_path_offset() which are implemented in terms of the former.  The
unit address can be omitted from the given node name.  If this is
ambiguous, the first such node in the flattened tree will be selected
(this behaviour is consistent with IEEE1275 which specifies only that
an arbitrary node matching the given information be selected).

This very small change is then followed by many more diffs which
change the test examples and testcases to exercise this behaviour.

Signed-off-by: David Gibson [EMAIL PROTECTED]
---

Jon, I initially considered making this behaviour optional,
i.e. adding a flag to subnode_offset() determining if it needed exact
matches or name-without-address matches.  I couldn't see that it was
actually any use, though.

Index: dtc/libfdt/fdt_ro.c
===
--- dtc.orig/libfdt/fdt_ro.c2007-09-27 17:58:46.0 +1000
+++ dtc/libfdt/fdt_ro.c 2007-09-27 18:36:03.0 +1000
@@ -62,8 +62,8 @@
return err; \
}
 
-static int offset_streq(const void *fdt, int offset,
-   const char *s, int len)
+static int nodename_eq(const void *fdt, int offset,
+  const char *s, int len)
 {
const char *p = fdt_offset_ptr(fdt, offset, len+1);
 
@@ -74,10 +74,12 @@ static int offset_streq(const void *fdt,
if (memcmp(p, s, len) != 0)
return 0;
 
-   if (p[len] != '\0')
+   if (p[len] == '\0')
+   return 1;
+   else if (!memchr(s, '@', len)  (p[len] == '@'))
+   return 1;
+   else
return 0;
-
-   return 1;
 }
 
 char *fdt_string(const void *fdt, int stroffset)
@@ -110,7 +112,7 @@ int fdt_subnode_offset_namelen(const voi
level++;
if (level != 1)
continue;
-   if (offset_streq(fdt, offset+FDT_TAGSIZE, name, 
namelen))
+   if (nodename_eq(fdt, offset+FDT_TAGSIZE, name, namelen))
/* Found it! */
return offset;
break;
Index: dtc/tests/trees.S
===
--- dtc.orig/tests/trees.S  2007-09-27 17:58:46.0 +1000
+++ dtc/tests/trees.S   2007-09-27 17:58:54.0 +1000
@@ -78,7 +78,7 @@ test_tree1_struct:
PROP_INT(test_tree1, prop_int, TEST_VALUE_1)
PROP_STR(test_tree1, prop_str, TEST_STRING_1)
 
-   BEGIN_NODE(subnode1)
+   BEGIN_NODE([EMAIL PROTECTED])
PROP_INT(test_tree1, prop_int, TEST_VALUE_1)
 
BEGIN_NODE(subsubnode)
@@ -86,10 +86,10 @@ test_tree1_struct:
END_NODE
END_NODE
 
-   BEGIN_NODE(subnode2)
+   BEGIN_NODE([EMAIL PROTECTED])
PROP_INT(test_tree1, prop_int, TEST_VALUE_2)
 
-   BEGIN_NODE(subsubnode)
+   BEGIN_NODE([EMAIL PROTECTED])
PROP_INT(test_tree1, prop_int, TEST_VALUE_2)
END_NODE
END_NODE
Index: dtc/tests/subnode_offset.c
===
--- dtc.orig/tests/subnode_offset.c 2007-09-27 17:58:46.0 +1000
+++ dtc/tests/subnode_offset.c  2007-09-27 17:58:54.0 +1000
@@ -48,7 +48,7 @@ int check_subnode(struct fdt_header *fdt
 
if (tag != FDT_BEGIN_NODE)
FAIL(Incorrect tag 0x%08x on property \%s\, tag, name);
-   if (!streq(nh-name, name))
+   if (!nodename_eq(nh-name, name))
FAIL(Subnode name mismatch \%s\ instead of \%s\,
 nh-name, name);
 
@@ -59,13 +59,13 @@ int main(int argc, char *argv[])
 {
void *fdt;
int subnode1_offset, subnode2_offset;
-   int subsubnode1_offset, subsubnode2_offset;
+   int subsubnode1_offset, subsubnode2_offset, subsubnode2_offset2;
 
test_init(argc, argv);
fdt = load_blob_arg(argc, argv);
 
-   subnode1_offset = check_subnode(fdt, 0, subnode1);
-   subnode2_offset = check_subnode(fdt, 0, subnode2);
+   subnode1_offset = check_subnode(fdt, 0, [EMAIL PROTECTED]);
+   subnode2_offset = check_subnode(fdt, 0, [EMAIL PROTECTED]);
 
if (subnode1_offset == subnode2_offset)
FAIL(Different subnodes have same offset);
@@ -74,10 +74,15 @@ int main(int argc, char *argv[])
check_property_typed(fdt, subnode2_offset, prop-int, TEST_VALUE_2);
 
subsubnode1_offset = check_subnode(fdt, subnode1_offset, subsubnode);
-