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

From: Gerald Van Baren vanbaren@cideas.com
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(-)

From: Simon Glass sjg@chromium.org
This function is useful outside libfdt, so export it.
Signed-off-by: Simon Glass sjg@chromium.org Acked-by: David Gibson david@gibson.dropbear.id.au --- 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;

On Mon, May 6, 2013 at 5:31 PM, gvb.uboot@gmail.com wrote:
From: Simon Glass sjg@chromium.org
This function is useful outside libfdt, so export it.
Signed-off-by: Simon Glass sjg@chromium.org Acked-by: David Gibson david@gibson.dropbear.id.au
Acked-by: Simon Glass sjg@chromium.org

From: François Revol revol@free.fr
Signed-off-by: François Revol revol@free.fr --- 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);

From: Justin Sobota jsobota@ti.com
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 jsobota@ti.com Acked-by: David Gibson david@gibson.dropbear.id.au Signed-off-by: Gerald Van Baren vanbaren@cideas.com --- 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__

From: Simon Glass sjg@chromium.org
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 sjg@chromium.org Acked-by: David Gibson david@gibson.dropbear.id.au --- 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;

On Mon, May 6, 2013 at 5:31 PM, gvb.uboot@gmail.com wrote:
From: Simon Glass sjg@chromium.org
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 sjg@chromium.org Acked-by: David Gibson david@gibson.dropbear.id.au
Acked-by: Simon Glass sjg@chromium.org

From: Gerald Van Baren gvb@unssw.com
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 vanbaren@cideas.com --- 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 */
participants (2)
-
gvb.uboot@gmail.com
-
Simon Glass