Commit Graph

8 Commits

Author SHA1 Message Date
Masahiro Yamada
50a327ded6 lib: libfdt: wrap scripts/dtc/libfdt/* where possible
lib/libfdt/ and scripts/dtc/libfdt have the same copies for the
followings 6 files:
  fdt.c fdt_addresses.c fdt_empty_tree.c fdt_overlay.c fdt_strerr.c
  fdt_sw.c

Make them a wrapper of scripts/dtc/libfdt/*.  This is exactly what
Linux does to sync libfdt.  In order to make is possible, import
<linux/libfdt.h> and <linux/libfdt_env.h> from Linux 4.14-rc5.

Unfortunately, U-Boot locally modified the following 3 files:
  fdt_ro.c fdt_wip.c fdt_rw.c

The fdt_region.c is U-Boot own file.

I did not touch them in order to avoid unpredictable impact.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-11-17 07:44:13 -05:00
David Gibson
491c7b6f42 libfdt: Fix undefined behaviour in fdt_offset_ptr()
Using pointer arithmetic to generate a pointer outside a known object is,
technically, undefined behaviour in C.  Unfortunately, we were using that
in fdt_offset_ptr() to detect overflows.

To fix this we need to do our bounds / overflow checking on the offsets
before constructing pointers from them.

Reported-by: David Binderman <dcb314@hotmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Simon Glass <sjg@chromium.org>
2016-10-13 13:54:10 -06:00
Robert P. J. Day
6feed2a5ae lib/libfdt/: General aesthetic/style fixes.
A number of style fixes across the files in this directory, including:

 * Correct invalid kernel-doc content.
 * Tidy up massive comment in fdt_region.c.
 * Use correct spelling of "U-Boot".
 * Replace tests of "! <var>" with "!<var>".
 * Replace "libfdt_env.h" with <libfdt_env.h>.

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>
Acked-by: Simon Glass <sjg@chromium.org>
2016-06-19 17:05:55 -06:00
Roger Meier
35084760a9 libfdt: SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause
Signed-off-by: Roger Meier <roger@bufferoverflow.ch>
Acked-by: Wolfgang Denk <wd@denx.de>
2013-08-10 09:04:25 -04:00
Simon Glass
88f95bbadd libfdt: Add fdt_next_subnode() to permit easy subnode iteration
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>
(Cherry-picked from dtc commit 4e76ec79)
Acked-by: Gerald Van Baren <vanbaren@cideas.com>
2013-05-14 15:37:25 -04:00
Kim Phillips
b2ba62a1aa libfdt: update from upstream dtc commit 142419e
commit 142419e "dtc/libfdt: sparse fixes", for u-boot's libfdt copy.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Cc: Jerry Van Baren <gvb.uboot@gmail.com>
2013-02-07 20:38:55 -05:00
David Gibson
d1c6314887 libfdt: Implement property iteration functions
For ages, we've been talking about adding functions to libfdt to allow
iteration through properties.  So, finally, here are some.

I got bogged down on this for a long time because I didn't want to
expose offsets directly to properties to the callers.  But without
that, attempting to make reasonable iteration functions just became
horrible.  So eventually, I settled on an interface which does now
expose property offsets.  fdt_first_property_offset() and
fdt_next_property_offset() are used to step through the offsets of the
properties starting from a particularly node offset.  The details of
the property at each offset can then be retrieved with either
fdt_get_property_by_offset() or fdt_getprop_by_offset() which have
interfaces similar to fdt_get_property() and fdt_getprop()
respectively.

No explicit testcases are included, but we do use the new functions to
reimplement the existing fdt_get_property() function.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

This was extracted from the DTC commit:
73dca9ae0b9abe6924ba640164ecce9f8df69c5a Mon Sep 17 00:00:00 2001

Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
2011-07-14 21:10:34 -04:00
Peter Tyser
0de71d5071 Move libfdt/ into lib/
Move the libfdt directory into the common lib/ directory to clean up the
top-level directory.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
2010-04-13 09:13:04 +02:00