]> git.sur5r.net Git - u-boot/commitdiff
Merge branch 'master' of git://git.denx.de/u-boot-fdt
authorWolfgang Denk <wd@denx.de>
Sun, 12 Oct 2008 21:13:16 +0000 (23:13 +0200)
committerWolfgang Denk <wd@denx.de>
Sun, 12 Oct 2008 21:13:16 +0000 (23:13 +0200)
include/libfdt.h
lib_ppc/bootm.c
libfdt/fdt.c
libfdt/fdt_ro.c

index 94c35e330c8d7a62a760b9d8774f08d3df1c2db0..ce374fded10454b59bfb90cf1f4f2292afd58c17 100644 (file)
 /* Low-level functions (you probably don't need these)                */
 /**********************************************************************/
 
-const void *fdt_offset_ptr(const void *fdt, int offset, int checklen);
+const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
 static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
 {
        return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
@@ -458,6 +458,32 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
  */
 uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
 
+/**
+ * fdt_get_alias_namelen - get alias based on substring
+ * @fdt: pointer to the device tree blob
+ * @name: name of the alias th look up
+ * @namelen: number of characters of name to consider
+ *
+ * Identical to fdt_get_alias(), but only examine the first namelen
+ * characters of name for matching the alias name.
+ */
+const char *fdt_get_alias_namelen(const void *fdt,
+                                 const char *name, int namelen);
+
+/**
+ * fdt_get_alias - retreive the path referenced by a given alias
+ * @fdt: pointer to the device tree blob
+ * @name: name of the alias th look up
+ *
+ * fdt_get_alias() retrieves the value of a given alias.  That is, the
+ * value of the property named 'name' in the node /aliases.
+ *
+ * returns:
+ *     a pointer to the expansion of the alias named 'name', of it exists
+ *     NULL, if the given alias or the /aliases node does not exist
+ */
+const char *fdt_get_alias(const void *fdt, const char *name);
+
 /**
  * fdt_get_path - determine the full path of a node
  * @fdt: pointer to the device tree blob
index 38266e1da2176f94ce3bfae1c39866728f9d4a61..5af25dd222f1eb23d6a896f307d9472839fecb08 100644 (file)
@@ -145,7 +145,7 @@ int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
         * if the user wants it (the logic is in the subroutines).
         */
        if (of_size) {
-               if (fdt_chosen(of_flat_tree, 0) < 0) {
+               if (fdt_chosen(of_flat_tree, 1) < 0) {
                        puts ("ERROR: ");
                        puts ("/chosen node create failed");
                        puts (" - must RESET the board to recover.\n");
index 732103b07bd368790ba28ecfe1ea551345aa80a8..a59a518b0e2e1684d976c7e36e37063e8bce2579 100644 (file)
@@ -78,7 +78,7 @@ int fdt_check_header(const void *fdt)
        return 0;
 }
 
-const void *fdt_offset_ptr(const void *fdt, int offset, int len)
+const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
 {
        const char *p;
 
index b09a6e9eb7e5976333d6e4626f67102074dabdd8..b705f91ecb760cd8120589f23865d58363ff56f0 100644 (file)
@@ -145,17 +145,12 @@ int fdt_path_offset(const void *fdt, const char *path)
 
        /* see if we have an alias */
        if (*path != '/') {
-               const char *q;
-               int aliasoffset = fdt_path_offset(fdt, "/aliases");
-
-               if (aliasoffset < 0)
-                       return -FDT_ERR_BADPATH;
+               const char *q = strchr(path, '/');
 
-               q = strchr(path, '/');
                if (!q)
                        q = end;
 
-               p = fdt_getprop_namelen(fdt, aliasoffset, path, q - p, NULL);
+               p = fdt_get_alias_namelen(fdt, p, q - p);
                if (!p)
                        return -FDT_ERR_BADPATH;
                offset = fdt_path_offset(fdt, p);
@@ -306,6 +301,23 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
        return fdt32_to_cpu(*php);
 }
 
+const char *fdt_get_alias_namelen(const void *fdt,
+                                 const char *name, int namelen)
+{
+       int aliasoffset;
+
+       aliasoffset = fdt_path_offset(fdt, "/aliases");
+       if (aliasoffset < 0)
+               return NULL;
+
+       return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL);
+}
+
+const char *fdt_get_alias(const void *fdt, const char *name)
+{
+       return fdt_get_alias_namelen(fdt, name, strlen(name));
+}
+
 int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
 {
        int pdepth = 0, p = 0;
@@ -320,9 +332,6 @@ int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
        for (offset = 0, depth = 0;
             (offset >= 0) && (offset <= nodeoffset);
             offset = fdt_next_node(fdt, offset, &depth)) {
-               if (pdepth < depth)
-                       continue; /* overflowed buffer */
-
                while (pdepth > depth) {
                        do {
                                p--;
@@ -330,14 +339,16 @@ int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
                        pdepth--;
                }
 
-               name = fdt_get_name(fdt, offset, &namelen);
-               if (!name)
-                       return namelen;
-               if ((p + namelen + 1) <= buflen) {
-                       memcpy(buf + p, name, namelen);
-                       p += namelen;
-                       buf[p++] = '/';
-                       pdepth++;
+               if (pdepth >= depth) {
+                       name = fdt_get_name(fdt, offset, &namelen);
+                       if (!name)
+                               return namelen;
+                       if ((p + namelen + 1) <= buflen) {
+                               memcpy(buf + p, name, namelen);
+                               p += namelen;
+                               buf[p++] = '/';
+                               pdepth++;
+                       }
                }
 
                if (offset == nodeoffset) {
@@ -347,7 +358,7 @@ int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
                        if (p > 1) /* special case so that root path is "/", not "" */
                                p--;
                        buf[p] = '\0';
-                       return p;
+                       return 0;
                }
        }