Resync libfdt with dtc upstream
cover Resync libfdt with dtc upstream
From: Gerald Van Baren <[email protected]>
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(-)
Signature · 1 line
1.7.9.5
PATCH 1/5 Export fdt_stringlist_contains()
From: Simon Glass <[email protected]>
This function is useful outside libfdt, so export it.
--- include/libfdt.h | 14 ++++++++++++++ lib/libfdt/fdt_ro.c | 5 ++--- 2 files changed, 16 insertions(+), 3 deletions(-)
include/libfdt.h +14 -0
@@ -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 */ /**********************************************************************/
lib/libfdt/fdt_ro.c +2 -3
@@ -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 ;
Signature · 1 line
1.7.9.5
PATCH 1/5 Export fdt_stringlist_contains()
Quoted 6 lines · On Mon, May 6, 2013 at 5:31 PM, <[email protected]> wrote:
From: Simon Glass <[email protected]>
This function is useful outside libfdt, so export it.
Signed-off-by Simon Glass <[email protected]>Acked-by David Gibson <[email protected]>
PATCH 2/5 Fix typo
In reply to gvb.uboot at gmail.comFrom: Fran?ois Revol <[email protected]>
--- include/libfdt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/libfdt.h +1 -1
@@ -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);
Signature · 1 line
1.7.9.5
PATCH 3/5 Added license header to dtc/libfdt/fdt.h and libfdt_env.h
In reply to gvb.uboot at gmail.comFrom: Justin Sobota <[email protected]>
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
--- include/fdt.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
include/fdt.h +51 -0
@@ -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__
Signature · 1 line
1.7.9.5
PATCH 4/5 libfdt: Add fdt_next_subnode() to permit easy subnode iteration
In reply to gvb.uboot at gmail.comFrom: Simon Glass <[email protected]>
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.
--- include/libfdt.h | 22 ++++++++++++++++++++++ lib/libfdt/fdt.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)
include/libfdt.h +22 -0
@@ -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 */ /**********************************************************************/
lib/libfdt/fdt.c +28 -0
@@ -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 ;
Signature · 1 line
1.7.9.5
PATCH 4/5 libfdt: Add fdt_next_subnode() to permit easy subnode iteration
Quoted 23 lines · On Mon, May 6, 2013 at 5:31 PM, <[email protected]> wrote:
From: Simon Glass <[email protected]>
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 */ }
Quoted 4 lines
Also, it doesn't require two levels of indentation for the loop body.
Signed-off-by Simon Glass <[email protected]>Acked-by David Gibson <[email protected]>
PATCH 5/5 Move FDT_RAMDISK_OVERHEAD from fdt.h to libfdt_env.h
In reply to gvb.uboot at gmail.comFrom: Gerald Van Baren <[email protected]>
The define should not have been put in fdt.h originally, libfdt_env.h is the proper place for target-specific customizations.
--- include/fdt.h | 2 -- include/libfdt_env.h | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-)
include/fdt.h +0 -2
@@ -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 */
include/libfdt_env.h +3 -0
@@ -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 */
Signature · 1 line
1.7.9.5