Commit Graph

57 Commits

Author SHA1 Message Date
Jan Kundrát
b95a5190ba Do not attempt to use the systemwide libfdt
U-Boot bundles a patched copy of libfdt, so it's wrong to attempt to
include it <like/this>. This breaks the build for me when I have dtc
fully installed in my host -- as happened earlier tonight with
Buildroot, for example.

There are several other occurrences throughout the code where '<libfdt'
matches. I'm not modifying these because I have no clue why the
<systemwide> include style is being used -- IMHO wrongly.

Signed-off-by: Jan Kundrát <jan.kundrat@cesnet.cz>
2017-11-06 09:59:02 -05:00
Simon Glass
a2b2caae5a fdt: Move header files into lib/libfdt
These header files are actually part of libfdt. Move them there to make
it easier to build pylibfdt and easier to merge changes from upstream.

Update the license header to use SPDX at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02 10:16:46 -06:00
Simon Glass
c40bfbadf2 fdt: Use SPDX format for licenses in the libfdt headers
These should follow the UBoot standard. Update them.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02 10:16:46 -06:00
Maxime Ripard
610db7058f libfdt: Sync overlay with upstream
Now that the overlay code has been merge upstream, update our copy to
what's been merged, since a significant number of issues have been fixed
during the merge process.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Acked-by: Simon Glass <sjg@chromium.org>
2016-10-23 12:08:48 -07:00
Simon Glass
42b7600d62 libfdt: Drop inlining of fdt_path_offset()
The fdt_path_offset() function is not inlined in upstream libfdt. Adjust
U-Boot's version to match.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-10-13 14:12:40 -06:00
Simon Glass
df87e6b1b8 libfdt: Sync fdt_for_each_subnode() with upstream
The signature for this macro has changed. Bring in the upstream version and
adjust U-Boot's usages to suit.

Signed-off-by: Simon Glass <sjg@chromium.org>
Update to drivers/power/pmic/palmas.c:
Signed-off-by: Keerthy <j-keerthy@ti.com>

Change-Id: I6cc9021339bfe686f9df21d61a1095ca2b3776e8
2016-10-13 14:10:32 -06:00
Simon Glass
b02e4044ff libfdt: Bring in upstream stringlist functions
These have now landed upstream. The naming is different and in one case the
function signature has changed. Update the code to match.

This applies the following upstream commits by
Thierry Reding <treding@nvidia.com> :

   604e61e fdt: Add functions to retrieve strings
   8702bd1 fdt: Add a function to get the index of a string
   2218387 fdt: Add a function to count strings

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-10-13 13:54:10 -06:00
Simon Glass
9c07b9877c libfdt: Sync up with upstream
This includes small changes to the following functions, from upstream
commit 6d1832c:

- fdt_get_max_phandle() (upstream commit 84e0e134)
- fdt_node_check_compatible (upstream commit 53bf130b)
- fdt_setprop_inplace_namelen_partial() to remove useless brackets and
     use idx instead of index
- _fdt_resize_property() to use idx instead of index
- _fdt_splice() (upstream commit d4c7c25c)

It also includes various typo fixes in libfdt.h

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-10-13 13:54:10 -06:00
Maxime Ripard
ddf67f7135 libfdt: Add overlay application function
The device tree overlays are a good way to deal with user-modifyable
boards or boards with some kind of an expansion mechanism where we can
easily plug new board in (like the BBB, the Raspberry Pi or the CHIP).

Add a new function to merge overlays with a base device tree.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
2016-08-20 11:35:04 -04:00
Maxime Ripard
ea7b1a213e libfdt: Add fdt_setprop_inplace_namelen_partial
Add a function to modify inplace only a portion of a property..

This is especially useful when the property is an array of values, and you
want to update one of them without changing the DT size.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Acked-by: Simon Glass <sjg@chromium.org>
2016-08-20 11:35:04 -04:00
Maxime Ripard
2b941bf96d libfdt: Add fdt_getprop_namelen_w
Add a function to retrieve a writeable property only by the first
characters of its name.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
2016-08-20 11:35:03 -04:00
Maxime Ripard
8e9685715b libfdt: Add fdt_path_offset_namelen
Add a namelen variant of fdt_path_offset to retrieve the node offset using
only a fixed number of characters.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
2016-08-20 11:35:02 -04:00
Maxime Ripard
57c7809ab0 libfdt: Add max phandle retrieval function
Add a function to retrieve the highest phandle in a given device tree.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Reviewed-by: Stefan Agner <stefan@agner.ch>
Acked-by: Simon Glass <sjg@chromium.org>
2016-08-20 11:35:01 -04:00
Maxime Ripard
67e610d9f0 libfdt: Add iterator over properties
Implement a macro based on fdt_first_property_offset and
fdt_next_property_offset that provides a convenience to iterate over all
the properties of a given node.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Acked-by: Simon Glass <sjg@chromium.org>
2016-08-20 11:35:00 -04:00
Simon Glass
f8a2d7a416 libfdt: Add a function to write a property placeholder
The existing function to add a new property to a tree being built requires
that the entire contents of the new property be passed in. For some
applications it is more convenient to be able to add the property contents
later, perhaps by reading from a file. This avoids double-buffering of the
contents.

Add a new function to support this and adust the existing fdt_property() to
use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-03-14 14:19:11 -04:00
Simon Glass
c3c4c00563 fdt: Add fdt_first/next_region() functions
These have been sent upstream but not accepted to libfdt. For now, bring
these into U-Boot to enable fdtgrep to operate. We will use fdtgrep to
cut device tree files down for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
2015-07-21 17:39:20 -06:00
Simon Glass
8f6e2e1ee1 fdt: Add a function to remove unused strings from a device tree
Property names are stored in a string table. When a node property is
removed, the string table is not updated since other nodes may have a
property with the same name.

Thus it is possible for the string table to build up a number of unused
strings. Add a function to remove these. This works by building a new device
tree from the old one, adding strings one by one as needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
2015-07-21 17:39:20 -06:00
Masahiro Yamada
965fab1adf libfdt: fix description of fdt_get_string()
Looks like this comment was copied from that of
fdt_get_string_index().

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Fixes: 5094eb408a ("fdt: Add functions to retrieve strings")
Acked-by: Simon Glass <sjg@chromium.org>
2015-07-20 07:21:47 -06:00
Thierry Reding
2f3760428f fdt: Add a subnodes iterator macro
The fdt_for_each_subnode() iterator macro provided by this patch can be
used to iterate over a device tree node's subnodes. At each iteration a
loop variable will be set to the next subnode.

Acked-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Thierry Reding <treding@nvidia.com>
2014-10-22 16:56:41 -06:00
Thierry Reding
5094eb408a fdt: Add functions to retrieve strings
Given a device tree node, a property name and an index, the new function
fdt_get_string_index() will return in an output argument a pointer to
the index'th string in the property's value.

The fdt_get_string() is a shortcut for the above with the index being 0.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
2014-10-22 16:56:41 -06:00
Thierry Reding
fc503c1791 fdt: Add a function to get the index of a string
Given a device tree node and a property name, the new fdt_find_string()
function will look up a given string in the string list contained in the
property's value and return its index.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
2014-10-22 16:56:40 -06:00
Thierry Reding
bc4147ab2d fdt: Add a function to count strings
Given a device tree node and a property name, the fdt_count_strings()
function counts the number of strings found in the property value.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
2014-10-22 16:56:40 -06:00
Simon Glass
0596d35d80 fdt: Sync up with libfdt
This brings in changes up to commit f9e91a48 in the libfdt repo.
Mostly this is whitespace/minor changes. But there are a few new
features:

- fdt_size_cells() and fdt_address_cells()
- fdt_resize()

Signed-off-by: Simon Glass <sjg@chromium.org>
2014-08-09 11:17:04 -04:00
Robert P. J. Day
1f8b546f9e Fix some obvious typos across multiple subsystems.
Typoes fixed:

  "partion" -> "partition"
  "retrive", "retreive" -> "retrieve"
  "th" -> "to"

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>
2013-09-20 10:29:48 -04:00
Simon Glass
3e06cd1f97 libfdt: Add fdt_find_regions()
Add a function to find regions in device tree given a list of nodes to
include and properties to exclude.

See the header file for full documentation.

Signed-off-by: Simon Glass <sjg@chromium.org>
2013-06-26 10:18:56 -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
François Revol
c73bd49dee Fix typo
Ref: DTC commit cc11e522

Signed-off-by: François Revol <revol@free.fr>
2013-05-10 19:04:49 -04:00
Simon Glass
e853b32424 Export fdt_stringlist_contains()
This function is useful outside libfdt, so export it.

Ref: DTC commit b7aa300e

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-10 19:04:49 -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
Gerald Van Baren
c71b64f361 libfdt: Add helper function to create a trivial, empty tree
The libfdt read/write functions are now usable enough that it's become a
moderately common pattern to use them to build and manipulate a device
tree from scratch.  For example, we do so ourself in our rw_tree1 testcase,
and qemu is starting to use this model when building device trees for some
targets such as e500.

However, the read/write functions require some sort of valid tree to begin
with, so this necessitates either having a trivial canned dtb to begin with
or, more commonly, creating an empty tree using the serial-write functions
first.

This patch adds a helper function which uses the serial-write functions to
create a trivial, empty but complete and valid tree in a supplied buffer,
ready for manipulation with the read/write functions.

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

From git://git.jdl.com/software/dtc.git patch hash be6026838 with
adaptations to include/libfdt.h and lib/libfdt/Makefile for the U-Boot
environment.

Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
2012-10-15 22:24:36 -04:00
David Gibson
24fa0e588e libfdt: Add helpers for 64-bit integer properties
In device trees in the world, properties consisting of a single 64-bit
integer are not as common as those consisting of a single 32-bit, cell
sized integer, but they're common enough that they're worth including
convenience functions for.

This patch adds helper wrappers of fdt_setprop_inplace(), fdt_setprop() and
fdt_appendprop() for handling 64-bit integer quantities in properties.  For
better consistency with the names of these new *_u64() functions we also
add *_u32() functions as alternative names for the existing *_cell()
functions handling 32-bit integers.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-10-15 19:15:39 -04:00
Minghuan Lian
36ad18a6db libfdt: Add support for appending the values to a existing property
Some properties may contain multiple values, these values may need
to be added to the property respectively. this patch provides this
functionality. The main purpose of fdt_append_prop() is to append
the values to a existing property, or create a new property if it
dose not exist.

Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-10-15 19:15:39 -04: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
Laurent Gregoire
67b89c79e7 libfdt: Fix C++ compile-time cast error on gnu 4.2.1
Allow the inclusion of libfdt.h in C++ source.

Signed-off-by: Laurent Gregoire <laurent.gregoire@tomtom.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2009-04-01 19:30:27 -04:00
Gerald Van Baren
cd3cb0d926 libfdt: Fix error in documentation for fdt_get_alias_namelen()
Oops, screwed up the function name in the documenting comment for this
function.  Trivial correction in this patch.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: Gerald Van Baren <vanbaren@cideas.com>
2008-10-04 07:56:06 -04:00
David Gibson
9a6cf73a88 libfdt: Add function to explicitly expand aliases
Kumar has already added alias expansion to fdt_path_offset().
However, in some circumstances it may be convenient for the user of
libfdt to explicitly get the string expansion of an alias.  This patch
adds a function to do this, fdt_get_alias(), and uses it to implement
fdt_path_offset().

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-10-02 19:06:09 -04:00
Jon Loeliger
741a6d010d Fix an overflow case in fdt_offset_ptr() detected by GCC 4.3.
Using Gcc 4.3 detected this problem:

    ../dtc/libfdt/fdt.c: In function 'fdt_next_tag':
    ../dtc/libfdt/fdt.c:82: error: assuming signed overflow does not
    occur when assuming that (X + c) < X is always false

To fix the problem, treat the offset as an unsigned int.

The problem report and proposed fix were provided
by Steve Papacharalambous <stevep@freescale.com>.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-10-01 22:01:52 -04:00
David Gibson
0219399a4e libfdt: Implement fdt_get_property_namelen() and fdt_getprop_namelen()
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 <david@gibson.dropbear.id.au>
2008-08-24 22:20:50 -04:00
Wolfram Sang
46390da154 libfdt: Improve documentation in libfdt.h
Fix a few typos and mistakes.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2008-08-24 22:20:49 -04:00
David Gibson
c66830263a dtc: Enable and fix -Wcast-qual warnings
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 <david@gibson.dropbear.id.au>
Acked-by: Gerald Van Baren <vanbaren@cideas.com>
2008-08-24 22:20:49 -04:00
Wolfgang Denk
53677ef18e Big white-space cleanup.
This commit gets rid of a huge amount of silly white-space issues.
Especially, all sequences of SPACEs followed by TAB characters get
removed (unless they appear in print statements).

Also remove all embedded "vim:" and "vi:" statements which hide
indentation problems.

Signed-off-by: Wolfgang Denk <wd@denx.de>
2008-05-21 00:14:08 +02:00
David Gibson
ae0b5908de libfdt: Add and use a node iteration helper function.
This patch adds an fdt_next_node() function which can be used to
iterate through nodes of the tree while keeping track of depth.  This
function is used to simplify the iteration code in a lot of other
functions, and is also exported for use by library users.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-18 21:03:45 -04:00
David Gibson
9eaeb07a71 libfdt: Add fdt_set_name() function
This patch adds an fdt_set_name() function to libfdt, mirroring
fdt_get_name().  This is a r/w function which alters the name of a
given device tree node.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-18 21:03:45 -04:00
David Gibson
aec7135bc3 libfdt: Add more documentation (patch the seventh)
This patch adds more documenting comments to libfdt.h.  Specifically,
these document the read/write functions (not including fdt_open_into()
and fdt_pack(), for now).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-01-08 15:03:42 -05:00
David Gibson
9d4450b5ad libfdt: Add more documentation (patch the sixth)
This patch adds some more documenting comments to libfdt.h.
Specifically this documents all the write-in-place functions.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-01-08 15:03:34 -05:00
Wolfgang Denk
1182e9f8e3 Fix compile problem introduced by "cleanup" commit 3dfd708c
Signed-off-by: Wolfgang Denk <wd@denx.de>
2008-01-02 15:58:44 +01:00
Wolfgang Denk
3dfd708cc1 Minor coding style cleanup.
Signed-off-by: Wolfgang Denk <wd@denx.de>
2008-01-02 12:38:43 +01:00
Kumar Gala
8d04f02f62 Update libfdt from device tree compiler (dtc)
Update libfdt to commit 8eaf5e358366017aa2e846c5038d1aa19958314e from
the device tree compiler (dtc) project.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2007-11-21 14:04:05 -06:00
Kumar Gala
a3c2933e02 Removed some nonused fdt functions and moved fdt_find_and_setprop out of libfdt
Removed:
	fdt_node_is_compatible
	fdt_find_node_by_type
	fdt_find_compatible_node

To ease merge of newer libfdt as we aren't using them anywhere at this time.

Also moved fdt_find_and_setprop out of libfdt into fdt_support.c for the same
reason.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2007-11-21 14:01:49 -06:00
Grant Likely
41bb76e941 libfdt: add convenience function fdt_find_and_setprop()
Given the path to a node, fdt_find_and_setprop() allows a property value
to be set directly.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
2007-09-06 09:46:17 -06:00