[U-Boot] [PATCH 0/5] Resync libfdt with dtc upstream

2013-05-06 Thread gvb . uboot
From: Gerald Van Baren 

The following patchset resynchronizes the u-boot libfdt files with the
upstream dtc updates plus one minor u-boot cleanup.

Cleanup: Move FDT_RAMDISK_OVERHEAD from fdt.h to libfdt_env.h
* That was placed in the wrong .h file.  My bad. :-/

Trivia: I picked up Justin Sobata's patch to apply a copyright notice
only to the fdt.h file, not the libfdt_env.h file (I kept the full subject
line so that it will be easier to match up dtc vs. u-boot patchsets in
the future).  The libfdt_env.h file is for application customizations... I
wrote the original libfdt_env.h file and included a copyright notice.

François Revol (1):
  Fix typo

Gerald Van Baren (1):
  Move FDT_RAMDISK_OVERHEAD from fdt.h to libfdt_env.h

Justin Sobota (1):
  Added license header to dtc/libfdt/fdt.h and libfdt_env.h

Simon Glass (2):
  Export fdt_stringlist_contains()
  libfdt: Add fdt_next_subnode() to permit easy subnode iteration

 include/fdt.h|   53 --
 include/libfdt.h |   38 +++-
 include/libfdt_env.h |3 +++
 lib/libfdt/fdt.c |   28 ++
 lib/libfdt/fdt_ro.c  |5 ++---
 5 files changed, 121 insertions(+), 6 deletions(-)

-- 
1.7.9.5

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 5/5] Move FDT_RAMDISK_OVERHEAD from fdt.h to libfdt_env.h

2013-05-06 Thread gvb . uboot
From: Gerald Van Baren 

The define should not have been put in fdt.h originally, libfdt_env.h
is the proper place for target-specific customizations.

Signed-off-by: Gerald Van Baren 
---
 include/fdt.h|2 --
 include/libfdt_env.h |3 +++
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/fdt.h b/include/fdt.h
index 488343c..526aedb 100644
--- a/include/fdt.h
+++ b/include/fdt.h
@@ -108,6 +108,4 @@ struct fdt_property {
 #define FDT_V16_SIZE   FDT_V3_SIZE
 #define FDT_V17_SIZE   (FDT_V16_SIZE + sizeof(fdt32_t))
 
-/* adding a ramdisk needs 0x44 bytes in version 2008.10 */
-#define FDT_RAMDISK_OVERHEAD   0x80
 #endif /* _FDT_H */
diff --git a/include/libfdt_env.h b/include/libfdt_env.h
index 3e3defc..0821258 100644
--- a/include/libfdt_env.h
+++ b/include/libfdt_env.h
@@ -35,4 +35,7 @@ typedef __be64 fdt64_t;
 #define fdt64_to_cpu(x)be64_to_cpu(x)
 #define cpu_to_fdt64(x)cpu_to_be64(x)
 
+/* adding a ramdisk needs 0x44 bytes in version 2008.10 */
+#define FDT_RAMDISK_OVERHEAD   0x80
+
 #endif /* _LIBFDT_ENV_H */
-- 
1.7.9.5

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 4/5] libfdt: Add fdt_next_subnode() to permit easy subnode iteration

2013-05-06 Thread gvb . uboot
From: Simon Glass 

Iterating through subnodes with libfdt is a little painful to write as we
need something like this:

for (depth = 0, count = 0,
offset = fdt_next_node(fdt, parent_offset, &depth);
 (offset >= 0) && (depth > 0);
 offset = fdt_next_node(fdt, offset, &depth)) {
if (depth == 1) {
/* code body */
}
}

Using fdt_next_subnode() we can instead write this, which is shorter and
easier to get right:

for (offset = fdt_first_subnode(fdt, parent_offset);
 offset >= 0;
 offset = fdt_next_subnode(fdt, offset)) {
/* code body */
}

Also, it doesn't require two levels of indentation for the loop body.

Signed-off-by: Simon Glass 
Acked-by: David Gibson 
---
 include/libfdt.h |   22 ++
 lib/libfdt/fdt.c |   28 
 2 files changed, 50 insertions(+)

diff --git a/include/libfdt.h b/include/libfdt.h
index 7403d5a..c5ec2ac 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -136,6 +136,28 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int 
*nextoffset);
 
 int fdt_next_node(const void *fdt, int offset, int *depth);
 
+/**
+ * fdt_first_subnode() - get offset of first direct subnode
+ *
+ * @fdt:   FDT blob
+ * @offset:Offset of node to check
+ * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
+ */
+int fdt_first_subnode(const void *fdt, int offset);
+
+/**
+ * fdt_next_subnode() - get offset of next direct subnode
+ *
+ * After first calling fdt_first_subnode(), call this function repeatedly to
+ * get direct subnodes of a parent node.
+ *
+ * @fdt:   FDT blob
+ * @offset:Offset of previous subnode
+ * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
+ * subnodes
+ */
+int fdt_next_subnode(const void *fdt, int offset);
+
 /**/
 /* General functions  */
 /**/
diff --git a/lib/libfdt/fdt.c b/lib/libfdt/fdt.c
index 387e354..154e9a4 100644
--- a/lib/libfdt/fdt.c
+++ b/lib/libfdt/fdt.c
@@ -202,6 +202,34 @@ int fdt_next_node(const void *fdt, int offset, int *depth)
return offset;
 }
 
+int fdt_first_subnode(const void *fdt, int offset)
+{
+   int depth = 0;
+
+   offset = fdt_next_node(fdt, offset, &depth);
+   if (offset < 0 || depth != 1)
+   return -FDT_ERR_NOTFOUND;
+
+   return offset;
+}
+
+int fdt_next_subnode(const void *fdt, int offset)
+{
+   int depth = 1;
+
+   /*
+* With respect to the parent, the depth of the next subnode will be
+* the same as the last.
+*/
+   do {
+   offset = fdt_next_node(fdt, offset, &depth);
+   if (offset < 0 || depth < 1)
+   return -FDT_ERR_NOTFOUND;
+   } while (depth > 1);
+
+   return offset;
+}
+
 const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
 {
int len = strlen(s) + 1;
-- 
1.7.9.5

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 1/5] Export fdt_stringlist_contains()

2013-05-06 Thread gvb . uboot
From: Simon Glass 

This function is useful outside libfdt, so export it.

Signed-off-by: Simon Glass 
Acked-by: David Gibson 
---
 include/libfdt.h|   14 ++
 lib/libfdt/fdt_ro.c |5 ++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/include/libfdt.h b/include/libfdt.h
index fc7f75b..b153cc3 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -816,6 +816,20 @@ int fdt_node_check_compatible(const void *fdt, int 
nodeoffset,
 int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
  const char *compatible);
 
+/**
+ * fdt_stringlist_contains - check a string list property for a string
+ * @strlist: Property containing a list of strings to check
+ * @listlen: Length of property
+ * @str: String to search for
+ *
+ * This is a utility function provided for convenience. The list contains
+ * one or more strings, each terminated by \0, as is found in a device tree
+ * "compatible" property.
+ *
+ * @return: 1 if the string is found in the list, 0 not found, or invalid list
+ */
+int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
+
 /**/
 /* Write-in-place functions   */
 /**/
diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c
index 1a461c3..b65f4e2 100644
--- a/lib/libfdt/fdt_ro.c
+++ b/lib/libfdt/fdt_ro.c
@@ -519,8 +519,7 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t 
phandle)
return offset; /* error from fdt_next_node() */
 }
 
-static int _fdt_stringlist_contains(const char *strlist, int listlen,
-   const char *str)
+int fdt_stringlist_contains(const char *strlist, int listlen, const char *str)
 {
int len = strlen(str);
const char *p;
@@ -546,7 +545,7 @@ int fdt_node_check_compatible(const void *fdt, int 
nodeoffset,
prop = fdt_getprop(fdt, nodeoffset, "compatible", &len);
if (!prop)
return len;
-   if (_fdt_stringlist_contains(prop, len, compatible))
+   if (fdt_stringlist_contains(prop, len, compatible))
return 0;
else
return 1;
-- 
1.7.9.5

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 3/5] Added license header to dtc/libfdt/fdt.h and libfdt_env.h

2013-05-06 Thread gvb . uboot
From: Justin Sobota 

This commit adds a license header to fdt.h and libfdt_env.h
because the license was omitted.

U-Boot note: the u-boot libfdt_env.h header portion was not applied to
the u-boot libfdt_env.h because that file was created by Gerald Van Baren
(with a license header). - gvb

Signed-off-by: Justin Sobota 
Acked-by: David Gibson 
Signed-off-by: Gerald Van Baren 
---
 include/fdt.h |   51 +++
 1 file changed, 51 insertions(+)

diff --git a/include/fdt.h b/include/fdt.h
index f9612ed..488343c 100644
--- a/include/fdt.h
+++ b/include/fdt.h
@@ -1,5 +1,56 @@
 #ifndef _FDT_H
 #define _FDT_H
+/*
+ * libfdt - Flat Device Tree manipulation
+ * Copyright (C) 2006 David Gibson, IBM Corporation.
+ * Copyright 2012 Kim Phillips, Freescale Semiconductor.
+ *
+ * libfdt is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ *
+ *  a) This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ *
+ * Alternatively,
+ *
+ *  b) Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 
 #ifndef __ASSEMBLY__
 
-- 
1.7.9.5

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 2/5] Fix typo

2013-05-06 Thread gvb . uboot
From: François Revol 

Signed-off-by: François Revol 
---
 include/libfdt.h |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/libfdt.h b/include/libfdt.h
index b153cc3..7403d5a 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -582,7 +582,7 @@ const char *fdt_get_alias_namelen(const void *fdt,
  * value of the property named 'name' in the node /aliases.
  *
  * returns:
- * a pointer to the expansion of the alias named 'name', of it exists
+ * a pointer to the expansion of the alias named 'name', if 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);
-- 
1.7.9.5

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 1/7] dtc: Enable and fix -Wpointer-arith warnings

2008-08-19 Thread gvb . uboot
From: David Gibson <[EMAIL PROTECTED]>

This patch turns on the -Wpointer-arith option in the dtc Makefile,
and fixes the resulting warnings due to using (void *) in pointer
arithmetic.  While convenient, pointer arithmetic on void * is not
portable, so it's better that we avoid it, particularly in libfdt.

Also add necessary definition of uintptr_t needed by David Gibson's
changeset "dtc: Enable and fix -Wpointer-arith warnings" (the definition
comes from stdint.h, which u-boot doesn't have). -- gvb

Signed-off-by: David Gibson <[EMAIL PROTECTED]>
Signed-off-by: Gerald Van Baren <[EMAIL PROTECTED]>
---
 include/libfdt_env.h |   12 +++
 libfdt/fdt.c |2 +-
 libfdt/fdt_ro.c  |4 +-
 libfdt/fdt_rw.c  |   49 +
 libfdt/fdt_sw.c  |2 +-
 libfdt/fdt_wip.c |2 +-
 libfdt/libfdt_internal.h |6 ++--
 7 files changed, 47 insertions(+), 30 deletions(-)

diff --git a/include/libfdt_env.h b/include/libfdt_env.h
index a7fd2f8..671c3a8 100644
--- a/include/libfdt_env.h
+++ b/include/libfdt_env.h
@@ -38,4 +38,16 @@ extern struct fdt_header *working_fdt;  /* Pointer to the 
working fdt */
 #define fdt64_to_cpu(x)__be64_to_cpu(x)
 #define cpu_to_fdt64(x)__cpu_to_be64(x)
 
+/*
+ * Types for `void *' pointers.
+ *
+ * Note: libfdt uses this definition from /usr/include/stdint.h.
+ * Define it here rather than pulling in all of stdint.h.
+ */
+#if __WORDSIZE == 64
+typedef unsigned long int   uintptr_t;
+#else
+typedef unsigned intuintptr_t;
+#endif
+
 #endif /* _LIBFDT_ENV_H */
diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index cb08ba0..18e8d3c 100644
--- a/libfdt/fdt.c
+++ b/libfdt/fdt.c
@@ -80,7 +80,7 @@ int fdt_check_header(const void *fdt)
 
 const void *fdt_offset_ptr(const void *fdt, int offset, int len)
 {
-   const void *p;
+   const char *p;
 
if (fdt_version(fdt) >= 0x11)
if (((offset + len) < offset)
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 69af7bb..8382afd 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -412,10 +412,10 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t 
phandle)
 &phandle, sizeof(phandle));
 }
 
-int _stringlist_contains(const void *strlist, int listlen, const char *str)
+int _stringlist_contains(const char *strlist, int listlen, const char *str)
 {
int len = strlen(str);
-   const void *p;
+   const char *p;
 
while (listlen >= len) {
if (memcmp(str, strlist, len+1) == 0)
diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c
index 95a5c2c..4a16014 100644
--- a/libfdt/fdt_rw.c
+++ b/libfdt/fdt_rw.c
@@ -98,13 +98,14 @@ static inline int _blob_data_size(void *fdt)
return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
 }
 
-static int _blob_splice(void *fdt, void *p, int oldlen, int newlen)
+static int _blob_splice(void *fdt, void *splicepoint, int oldlen, int newlen)
 {
-   void *end = fdt + _blob_data_size(fdt);
+   char *p = splicepoint;
+   char *end = (char *)fdt + _blob_data_size(fdt);
 
if (((p + oldlen) < p) || ((p + oldlen) > end))
return -FDT_ERR_BADOFFSET;
-   if ((end - oldlen + newlen) > (fdt + fdt_totalsize(fdt)))
+   if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt)))
return -FDT_ERR_NOSPACE;
memmove(p + newlen, p + oldlen, end - p - oldlen);
return 0;
@@ -139,7 +140,8 @@ static int _blob_splice_struct(void *fdt, void *p,
 
 static int _blob_splice_string(void *fdt, int newlen)
 {
-   void *p = fdt + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
+   void *p = (char *)fdt
+   + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
int err;
 
if ((err = _blob_splice(fdt, p, 0, newlen)))
@@ -342,7 +344,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
memset(nh->name, 0, ALIGN(namelen+1, FDT_TAGSIZE));
memcpy(nh->name, name, namelen);
-   endtag = (uint32_t *)((void *)nh + nodelen - FDT_TAGSIZE);
+   endtag = (uint32_t *)((char *)nh + nodelen - FDT_TAGSIZE);
*endtag = cpu_to_fdt32(FDT_END_NODE);
 
return offset;
@@ -367,7 +369,7 @@ int fdt_del_node(void *fdt, int nodeoffset)
   endoffset - nodeoffset, 0);
 }
 
-static void _packblocks(const void *fdt, void *buf,
+static void _packblocks(const char *old, char *new,
   int mem_rsv_size, int struct_size)
 {
int mem_rsv_off, struct_off, strings_off;
@@ -376,17 +378,17 @@ static void _packblocks(const void *fdt, void *buf,
struct_off = mem_rsv_off + mem_rsv_size;
strings_off = struct_off + struct_size;
 
-   memmove(buf + mem_rsv_off, fdt + fdt_off_mem_rsvmap(fdt), mem_rsv_size);
-   fdt_set_off_mem_rsvmap(buf, mem_rsv_off);
+   

[U-Boot] [PATCH 6/7] libfdt: Implement fdt_get_property_namelen() and fdt_getprop_namelen()

2008-08-19 Thread gvb . uboot
From: David Gibson <[EMAIL PROTECTED]>

As well as fdt_subnode_offset(), libfdt includes an
fdt_subnode_offset_namelen() function that takes the subnode name to
look up not as a NUL-terminated string, but as a string with an
explicit length.  This can be useful when the caller has the name as
part of a longer string, such as a full path.

However, we don't have corresponding 'namelen' versions for
fdt_get_property() and fdt_getprop().  There are less obvious use
cases for these variants on property names, but there are
circumstances where they can be useful e.g. looking up property names
which need to be parsed from a longer string buffer such as user input
or a configuration file, or looking up an alias in a path with
IEEE1275 style aliases.

So, since it's very easy to implement such variants, this patch does
so.  The original NUL-terminated variants are, of course, implemented
in terms of the namelen versions.

Signed-off-by: David Gibson <[EMAIL PROTECTED]>
---
 include/libfdt.h |   30 ++
 libfdt/fdt_ro.c  |   37 ++---
 2 files changed, 60 insertions(+), 7 deletions(-)

diff --git a/include/libfdt.h b/include/libfdt.h
index 0747981..94c35e3 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -343,6 +343,22 @@ int fdt_path_offset(const void *fdt, const char *path);
 const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
 
 /**
+ * fdt_get_property_namelen - find a property based on substring
+ * @fdt: pointer to the device tree blob
+ * @nodeoffset: offset of the node whose property to find
+ * @name: name of the property to find
+ * @namelen: number of characters of name to consider
+ * @lenp: pointer to an integer variable (will be overwritten) or NULL
+ *
+ * Identical to fdt_get_property_namelen(), but only examine the first
+ * namelen characters of name for matching the property name.
+ */
+const struct fdt_property *fdt_get_property_namelen(const void *fdt,
+   int nodeoffset,
+   const char *name,
+   int namelen, int *lenp);
+
+/**
  * fdt_get_property - find a given property in a given node
  * @fdt: pointer to the device tree blob
  * @nodeoffset: offset of the node whose property to find
@@ -380,6 +396,20 @@ static inline struct fdt_property *fdt_get_property_w(void 
*fdt, int nodeoffset,
 }
 
 /**
+ * fdt_getprop_namelen - get property value based on substring
+ * @fdt: pointer to the device tree blob
+ * @nodeoffset: offset of the node whose property to find
+ * @name: name of the property to find
+ * @namelen: number of characters of name to consider
+ * @lenp: pointer to an integer variable (will be overwritten) or NULL
+ *
+ * Identical to fdt_getprop(), but only examine the first namelen
+ * characters of name for matching the property name.
+ */
+const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
+   const char *name, int namelen, int *lenp);
+
+/**
  * fdt_getprop - retrieve the value of a given property
  * @fdt: pointer to the device tree blob
  * @nodeoffset: offset of the node whose property to find
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 6292a00..d566eba 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -84,6 +84,14 @@ const char *fdt_string(const void *fdt, int stroffset)
return (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset;
 }
 
+static int _fdt_string_eq(const void *fdt, int stroffset,
+ const char *s, int len)
+{
+   const char *p = fdt_string(fdt, stroffset);
+
+   return (strlen(p) == len) && (memcmp(p, s, len) == 0);
+}
+
 int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)
 {
FDT_CHECK_HEADER(fdt);
@@ -179,9 +187,10 @@ const char *fdt_get_name(const void *fdt, int nodeoffset, 
int *len)
return NULL;
 }
 
-const struct fdt_property *fdt_get_property(const void *fdt,
-   int nodeoffset,
-   const char *name, int *lenp)
+const struct fdt_property *fdt_get_property_namelen(const void *fdt,
+   int nodeoffset,
+   const char *name,
+   int namelen, int *lenp)
 {
uint32_t tag;
const struct fdt_property *prop;
@@ -214,7 +223,7 @@ const struct fdt_property *fdt_get_property(const void *fdt,
if (! prop)
goto fail;
namestroff = fdt32_to_cpu(prop->nameoff);
-   if (strcmp(fdt_string(fdt, namestroff), name) == 0) {
+   if (_fdt_string_eq(fdt, namestroff, name, namelen)) {
/* Found it! */
int len = f

[U-Boot] [PATCH 0/7] libfdt: Update to resync with dtc/libfdt

2008-08-19 Thread gvb . uboot
The following changesets resynchronize u-boot with the master libfdt.

Best regards,
gvb
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 3/7] libfdt: Increase namespace-pollution paranoia

2008-08-19 Thread gvb . uboot
From: David Gibson <[EMAIL PROTECTED]>

libfdt is supposed to easy to embed in projects all and sundry.
Often, it won't be practical to separate the embedded libfdt's
namespace from that of the surrounding project.  Which means there can
be namespace conflicts between even libfdt's internal/static functions
and functions or macros coming from the surrounding project's headers
via libfdt_env.h.

This patch, therefore, renames a bunch of libfdt internal functions
and macros and makes a few other chances to reduce the chances of
namespace collisions with embedding projects.  Specifically:
- Internal functions (even static ones) are now named _fdt_*()

- The type and (static) global for the error table in
  fdt_strerror() gain an fdt_ prefix

- The unused macro PALIGN is removed

- The memeq and streq macros are removed and open-coded in the
  users (they were only used once each)

- Other macros gain an FDT_ prefix

- To save some of the bulk from the previous change, an
  FDT_TAGALIGN() macro is introduced, where FDT_TAGALIGN(x) ==
  FDT_ALIGN(x, FDT_TAGSIZE)

Signed-off-by: David Gibson <[EMAIL PROTECTED]>
---
 libfdt/fdt.c |8 ++--
 libfdt/fdt_ro.c  |   22 
 libfdt/fdt_rw.c  |  121 +++---
 libfdt/fdt_strerror.c|   34 +++---
 libfdt/fdt_sw.c  |   38 +++---
 libfdt/fdt_wip.c |7 ++-
 libfdt/libfdt_internal.h |   11 ++---
 7 files changed, 119 insertions(+), 122 deletions(-)

diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index 18e8d3c..732103b 100644
--- a/libfdt/fdt.c
+++ b/libfdt/fdt.c
@@ -67,7 +67,7 @@ int fdt_check_header(const void *fdt)
return -FDT_ERR_BADVERSION;
if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION)
return -FDT_ERR_BADVERSION;
-   } else if (fdt_magic(fdt) == SW_MAGIC) {
+   } else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
/* Unfinished sequential-write blob */
if (fdt_size_dt_struct(fdt) == 0)
return -FDT_ERR_BADSTATE;
@@ -128,7 +128,7 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int 
*nextoffset)
}
 
if (nextoffset)
-   *nextoffset = ALIGN(offset, FDT_TAGSIZE);
+   *nextoffset = FDT_TAGALIGN(offset);
 
return tag;
 }
@@ -188,14 +188,14 @@ const char *_fdt_find_string(const char *strtab, int 
tabsize, const char *s)
const char *p;
 
for (p = strtab; p <= last; p++)
-   if (memeq(p, s, len))
+   if (memcmp(p, s, len) == 0)
return p;
return NULL;
 }
 
 int fdt_move(const void *fdt, void *buf, int bufsize)
 {
-   CHECK_HEADER(fdt);
+   FDT_CHECK_HEADER(fdt);
 
if (fdt_totalsize(fdt) > bufsize)
return -FDT_ERR_NOSPACE;
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 1c897c5..326d19c 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -59,8 +59,8 @@
 
 #include "libfdt_internal.h"
 
-static int nodename_eq(const void *fdt, int offset,
-  const char *s, int len)
+static int _fdt_nodename_eq(const void *fdt, int offset,
+   const char *s, int len)
 {
const char *p = fdt_offset_ptr(fdt, offset + FDT_TAGSIZE, len+1);
 
@@ -86,7 +86,7 @@ const char *fdt_string(const void *fdt, int stroffset)
 
 int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)
 {
-   CHECK_HEADER(fdt);
+   FDT_CHECK_HEADER(fdt);
*address = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->address);
*size = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->size);
return 0;
@@ -106,7 +106,7 @@ int fdt_subnode_offset_namelen(const void *fdt, int offset,
 {
int depth;
 
-   CHECK_HEADER(fdt);
+   FDT_CHECK_HEADER(fdt);
 
for (depth = 0;
 offset >= 0;
@@ -114,7 +114,7 @@ int fdt_subnode_offset_namelen(const void *fdt, int offset,
if (depth < 0)
return -FDT_ERR_NOTFOUND;
else if ((depth == 1)
-&& nodename_eq(fdt, offset, name, namelen))
+&& _fdt_nodename_eq(fdt, offset, name, namelen))
return offset;
}
 
@@ -133,7 +133,7 @@ int fdt_path_offset(const void *fdt, const char *path)
const char *p = path;
int offset = 0;
 
-   CHECK_HEADER(fdt);
+   FDT_CHECK_HEADER(fdt);
 
if (*path != '/')
return -FDT_ERR_BADPATH;
@@ -214,7 +214,7 @@ const struct fdt_property *fdt_get_property(const void *fdt,
if (! prop)
goto fail;
namestroff = fdt32_to_cpu(prop->nameoff);
-   if (streq(fdt_string(fdt, namestroff), name)) {
+   if (strcmp(fdt_string(fdt, n

[U-Boot] [PATCH 7/7] libfdt: Add support for using aliases in fdt_path_offset()

2008-08-19 Thread gvb . uboot
From: Kumar Gala <[EMAIL PROTECTED]>

If the path doesn't start with '/' check to see if it matches some alias
under "/aliases" and substitute the matching alias value in the path
and retry the lookup.

Signed-off-by: Kumar Gala <[EMAIL PROTECTED]>
Acked-by: David Gibson <[EMAIL PROTECTED]>
Acked-by: Gerald Van Baren <[EMAIL PROTECTED]>
---
 libfdt/fdt_ro.c |   21 +++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index d566eba..b09a6e9 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -143,8 +143,25 @@ int fdt_path_offset(const void *fdt, const char *path)
 
FDT_CHECK_HEADER(fdt);
 
-   if (*path != '/')
-   return -FDT_ERR_BADPATH;
+   /* 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;
+
+   q = strchr(path, '/');
+   if (!q)
+   q = end;
+
+   p = fdt_getprop_namelen(fdt, aliasoffset, path, q - p, NULL);
+   if (!p)
+   return -FDT_ERR_BADPATH;
+   offset = fdt_path_offset(fdt, p);
+
+   p = q;
+   }
 
while (*p) {
const char *q;
-- 
1.5.6.3

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 4/7] libfdt: Improve documentation in libfdt.h

2008-08-19 Thread gvb . uboot
From: Wolfram Sang <[EMAIL PROTECTED]>

Fix a few typos and mistakes.

Signed-off-by: Wolfram Sang <[EMAIL PROTECTED]>
Acked-by: David Gibson <[EMAIL PROTECTED]>
---
 include/libfdt.h |   28 ++--
 1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/include/libfdt.h b/include/libfdt.h
index 7e043ef..0747981 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -213,7 +213,7 @@ int fdt_move(const void *fdt, void *buf, int bufsize);
 /**/
 
 /**
- * fdt_string - retreive a string from the strings block of a device tree
+ * fdt_string - retrieve a string from the strings block of a device tree
  * @fdt: pointer to the device tree blob
  * @stroffset: offset of the string within the strings block (native endian)
  *
@@ -227,7 +227,7 @@ int fdt_move(const void *fdt, void *buf, int bufsize);
 const char *fdt_string(const void *fdt, int stroffset);
 
 /**
- * fdt_num_mem_rsv - retreive the number of memory reserve map entries
+ * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
  * @fdt: pointer to the device tree blob
  *
  * Returns the number of entries in the device tree blob's memory
@@ -240,7 +240,7 @@ const char *fdt_string(const void *fdt, int stroffset);
 int fdt_num_mem_rsv(const void *fdt);
 
 /**
- * fdt_get_mem_rsv - retreive one memory reserve map entry
+ * fdt_get_mem_rsv - retrieve one memory reserve map entry
  * @fdt: pointer to the device tree blob
  * @address, @size: pointers to 64-bit variables
  *
@@ -320,7 +320,7 @@ int fdt_subnode_offset(const void *fdt, int parentoffset, 
const char *name);
 int fdt_path_offset(const void *fdt, const char *path);
 
 /**
- * fdt_get_name - retreive the name of a given node
+ * fdt_get_name - retrieve the name of a given node
  * @fdt: pointer to the device tree blob
  * @nodeoffset: structure block offset of the starting node
  * @lenp: pointer to an integer variable (will be overwritten) or NULL
@@ -352,7 +352,7 @@ const char *fdt_get_name(const void *fdt, int nodeoffset, 
int *lenp);
  * fdt_get_property() retrieves a pointer to the fdt_property
  * structure within the device tree blob corresponding to the property
  * named 'name' of the node at offset nodeoffset.  If lenp is
- * non-NULL, the length of the property value also returned, in the
+ * non-NULL, the length of the property value is also returned, in the
  * integer pointed to by lenp.
  *
  * returns:
@@ -389,7 +389,7 @@ static inline struct fdt_property *fdt_get_property_w(void 
*fdt, int nodeoffset,
  * fdt_getprop() retrieves a pointer to the value of the property
  * named 'name' of the node at offset nodeoffset (this will be a
  * pointer to within the device blob itself, not a copy of the value).
- * If lenp is non-NULL, the length of the property value also
+ * If lenp is non-NULL, the length of the property value is also
  * returned, in the integer pointed to by lenp.
  *
  * returns:
@@ -415,7 +415,7 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
 }
 
 /**
- * fdt_get_phandle - retreive the phandle of a given node
+ * fdt_get_phandle - retrieve the phandle of a given node
  * @fdt: pointer to the device tree blob
  * @nodeoffset: structure block offset of the node
  *
@@ -423,7 +423,7 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
  * structure block offset nodeoffset.
  *
  * returns:
- * the phandle of the node at nodeoffset, on succes (!= 0, != -1)
+ * the phandle of the node at nodeoffset, on success (!= 0, != -1)
  * 0, if the node has no phandle, or another error occurs
  */
 uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
@@ -522,7 +522,7 @@ int fdt_node_depth(const void *fdt, int nodeoffset);
  * structure from the start to nodeoffset, *twice*.
  *
  * returns:
- * stucture block offset of the parent of the node at nodeoffset
+ * structure block offset of the parent of the node at nodeoffset
  * (>=0), on success
  * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
  * -FDT_ERR_BADMAGIC,
@@ -579,7 +579,7 @@ int fdt_node_offset_by_prop_value(const void *fdt, int 
startoffset,
  * @fdt: pointer to the device tree blob
  * @phandle: phandle value
  *
- * fdt_node_offset_by_prop_value() returns the offset of the node
+ * fdt_node_offset_by_phandle() returns the offset of the node
  * which has the given phandle value.  If there is more than one node
  * in the tree with the given phandle (an invalid tree), results are
  * undefined.
@@ -806,13 +806,13 @@ int fdt_pack(void *fdt);
 /**
  * fdt_add_mem_rsv - add one memory reserve map entry
  * @fdt: pointer to the device tree blob
- * @addres, @size: 64-bit values (native endian)
+ * @address, @size: 64-bit values (native endian)
  *
  * Adds a reserve map entry to the given blob reserving a region at
  * address address of length size.
  *
  * This function will insert data into the reserve map and will
-

[U-Boot] [PATCH 5/7] libfdt: Forgot one function when cleaning the namespace

2008-08-19 Thread gvb . uboot
From: David Gibson <[EMAIL PROTECTED]>

In commit b6d80a20fc293f3b995c3ce1a6744a5574192125, we renamed all
libfdt functions to be prefixed with fdt_ or _fdt_ to minimise the
chance of collisions with things from whatever package libfdt is
embedded in, pulled into the libfdt build via that environment's
libfdt_env.h.

Except... I missed one.  This patch applies the same treatment to
_stringlist_contains().  While we're at it, also make it static since
it's only used in the same file.

Signed-off-by: David Gibson <[EMAIL PROTECTED]>
---
 libfdt/fdt_ro.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 326d19c..6292a00 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -412,7 +412,8 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t 
phandle)
 &phandle, sizeof(phandle));
 }
 
-int _stringlist_contains(const char *strlist, int listlen, const char *str)
+static int _fdt_stringlist_contains(const char *strlist, int listlen,
+   const char *str)
 {
int len = strlen(str);
const char *p;
@@ -438,7 +439,7 @@ int fdt_node_check_compatible(const void *fdt, int 
nodeoffset,
prop = fdt_getprop(fdt, nodeoffset, "compatible", &len);
if (!prop)
return len;
-   if (_stringlist_contains(prop, len, compatible))
+   if (_fdt_stringlist_contains(prop, len, compatible))
return 0;
else
return 1;
-- 
1.5.6.3

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 2/7] dtc: Enable and fix -Wcast-qual warnings

2008-08-19 Thread gvb . uboot
From: David Gibson <[EMAIL PROTECTED]>

Enabling -Wcast-qual warnings in dtc shows up a number of places where
we are incorrectly discarding a const qualification.  There are also
some places where we are intentionally discarding the 'const', and we
need an ugly cast through uintptr_t to suppress the warning.  However,
most of these are pretty well isolated with the *_w() functions.  So
in the interests of maximum safety with const qualifications, this
patch enables the warnings and fixes the existing complaints.

Signed-off-by: David Gibson <[EMAIL PROTECTED]>
Acked-by: Gerald Van Baren <[EMAIL PROTECTED]>
---
 include/libfdt.h |8 
 libfdt/fdt_ro.c  |2 +-
 libfdt/fdt_rw.c  |4 ++--
 libfdt/libfdt_internal.h |7 ---
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/include/libfdt.h b/include/libfdt.h
index 2a2b23d..7e043ef 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -125,7 +125,7 @@
 const void *fdt_offset_ptr(const void *fdt, int offset, int checklen);
 static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
 {
-   return (void *)fdt_offset_ptr(fdt, offset, checklen);
+   return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
 }
 
 uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
@@ -375,8 +375,8 @@ static inline struct fdt_property *fdt_get_property_w(void 
*fdt, int nodeoffset,
  const char *name,
  int *lenp)
 {
-   return (struct fdt_property *)fdt_get_property(fdt, nodeoffset,
-  name, lenp);
+   return (struct fdt_property *)(uintptr_t)
+   fdt_get_property(fdt, nodeoffset, name, lenp);
 }
 
 /**
@@ -411,7 +411,7 @@ const void *fdt_getprop(const void *fdt, int nodeoffset,
 static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
  const char *name, int *lenp)
 {
-   return (void *)fdt_getprop(fdt, nodeoffset, name, lenp);
+   return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
 }
 
 /**
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 8382afd..1c897c5 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -81,7 +81,7 @@ static int nodename_eq(const void *fdt, int offset,
 
 const char *fdt_string(const void *fdt, int stroffset)
 {
-   return (char *)fdt + fdt_off_dt_strings(fdt) + stroffset;
+   return (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset;
 }
 
 int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)
diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c
index 4a16014..6837fb1 100644
--- a/libfdt/fdt_rw.c
+++ b/libfdt/fdt_rw.c
@@ -261,7 +261,7 @@ int fdt_set_name(void *fdt, int nodeoffset, const char 
*name)
 
RW_CHECK_HEADER(fdt);
 
-   namep = (char *)fdt_get_name(fdt, nodeoffset, &oldlen);
+   namep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen);
if (!namep)
return oldlen;
 
@@ -436,7 +436,7 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
/* But if that overlaps with the old tree... */
if (((tmp + newsize) > fdtstart) && (tmp < fdtend)) {
/* Try right after the old tree instead */
-   tmp = (char *)fdtend;
+   tmp = (char *)(uintptr_t)fdtend;
if ((tmp + newsize) > ((char *)buf + bufsize))
return -FDT_ERR_NOSPACE;
}
diff --git a/libfdt/libfdt_internal.h b/libfdt/libfdt_internal.h
index 2ba30db..549e345 100644
--- a/libfdt/libfdt_internal.h
+++ b/libfdt/libfdt_internal.h
@@ -77,19 +77,20 @@ static inline const void *_fdt_offset_ptr(const void *fdt, 
int offset)
 
 static inline void *_fdt_offset_ptr_w(void *fdt, int offset)
 {
-   return (void *)_fdt_offset_ptr(fdt, offset);
+   return (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset);
 }
 
 static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, 
int n)
 {
-   const struct fdt_reserve_entry *rsv_table = (struct fdt_reserve_entry *)
+   const struct fdt_reserve_entry *rsv_table =
+   (const struct fdt_reserve_entry *)
((const char *)fdt + fdt_off_mem_rsvmap(fdt));
 
return rsv_table + n;
 }
 static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n)
 {
-   return (void *)_fdt_mem_rsv(fdt, n);
+   return (void *)(uintptr_t)_fdt_mem_rsv(fdt, n);
 }
 
 #define SW_MAGIC   (~FDT_MAGIC)
-- 
1.5.6.3

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot