Commit graph

19 commits

Author SHA1 Message Date
Rob Herring
acfe84f2c4 dtc: Replace GPLv2 boilerplate/reference with SPDX tags
Replace instances of GPLv2 or later boilerplate with SPDX tags.

Signed-off-by: Rob Herring <robh@kernel.org>
Message-Id: <20190620211944.9378-2-robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-06-21 21:06:10 +10:00
David Gibson
6473a21d8b Consolidate utilfdt_read_len() variants
There are no less than _four_ variants on utilfdt_read() which is a bit
excessive.  The _len() variants are particularly pointless, since we can
achieve the same thing with very little extra verbosity by using the usual
convention of ignoring return parameters if they're NULL.  So, get rid of
them (we keep the shorter names without _len, but add now-optional len
parameters).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2018-06-07 11:48:20 +10:00
David Gibson
3b62fdaebf Remove leading underscores from identifiers
In a number of places, dtc and associated tools and test code use
leading _ characters on identifiers to flag them as "internal", an
idiom taken from the Linux kernel.  This is a bad idea in a userspace
program, because identifiers with a leading _ are reserved for the C
library / system.

In some cases, the extra _ served no real purpose, so simply drop it.  In
others move to the end of the identifier, which is a convention we're free
to use for our own purposes.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-10-26 09:25:14 +02:00
Nicolas Iooss
c17a811c62 fdtput: Remove star from value_len documentation
When clang checks the documentation tags (with -Wdocumentation flag), it
reports the following warning:

    fdtput.c:70:11: error: parameter '*value_len' not found in the
    function declaration [-Werror,-Wdocumentation]
     * @param *value_len    Returns length of value encoded
              ^~~~~~~~~~
    fdtput.c:70:11: note: did you mean 'value_len'?
     * @param *value_len    Returns length of value encoded
              ^~~~~~~~~~
              value_len

As this sounds reasonable, remove the star from the documentation tag.

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-06 14:19:26 +11:00
David Gibson
bad5b28049 Fix assorted sparse warnings
This fixes a great many sparse warnings on the fdt and libfdt sources.
These are mostly due to incorrect mixing of endian annotated and native
integer types.

This includes fixing a couple of quasi-bugs where we had endian conversions
the wrong way around (this will have the right effect in practice, but is
certainly conceptually incorrect).

This doesn't make the whole tree sparse clean: there are many warnings in
bison and lex generated code, and there are a handful of other remaining
warnings that are (for now) more trouble than they're worth to fix (and
are not genuine bugs).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-06 12:08:53 +11:00
Jean-Christophe Dubois
c539075ba8 fdtput.c: Fix memory leak.
CID 132821 (#1 of 1): Resource leak (RESOURCE_LEAK)
12. leaked_storage: Variable value going out of scope leaks the storage it points to.

Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-07-24 01:05:05 +10:00
Wang Long
aa719618a8 fdtput: add delete node and property function
add the delete node and property function for fdtput.

usage:
1) delete nodes
   fdtput -r <options> <dt file> [<node>...]
2) delete properties
   fdtput -d <options> <dt file> <node> [<property>...]

Signed-off-by: Wang Long <long.wanglong@huawei.com>
2015-01-27 19:30:19 +11:00
Heinrich Schuchardt
8ce36476ae Consistently use xrealloc instead of realloc
fdtput.c:
Replace the remaining call to realloc by xrealloc.
Some redundant lines in encode_value can be saved.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2014-03-03 10:37:30 +11:00
Srinivas Kandagatla
d214655904 fdtput: expand fdt if value does not fit
If you try to insert a new node or extend a property with large value,
using fdtput you will notice that it always fails.

example:
fdtput -v -p -ts ./tst.dtb "/node-1" "property-1" "value-1
Error at 'node-1': FDT_ERR_NOSPACE

or

fdtput -v -c ./tst.dtb "/node-1"
Error at 'node-1': FDT_ERR_NOSPACE

or

fdtput -v  -ts ./tst.dtb "/node" "property" "very big value"
Decoding value:
	string: 'very big value'
Value size 15
Error at 'property': FDT_ERR_NOSPACE

All these error are returned from libfdt, as the size of the fdt passed
has no space to accomdate these new properties.
This patch adds realloc functions in fdtput to allocate new space in fdt
when it detects a shortage in space for new value or node. With this
patch, fdtput can insert a new node or property or extend a property
with new value greater than original size. Also it packs the final blob
to clean up any extra padding.

Without this patch fdtput tool complains with FDT_ERR_NOSPACE when we
try to add a node/property or extend the value of a property.

Testcases for the new behaviour added by David Gibson.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-29 12:48:16 +10:00
Mike Frysinger
b9e80656f2 util: drop "long" from usage helpers
Now that all utils have converted to the new usage framework, we can
rename to just plain "usage()" and avoid naming conflicts.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-24 18:20:53 +10:00
Mike Frysinger
03449b84c8 dtc/fdt{get, put}/convert-dtsv0-lexer: convert to new usage helpers
This helps standardize the flag processing and the usage screens.

Only lightly tested; would be great if someone who uses these utils
could double check.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-24 18:20:53 +10:00
Jon Loeliger
5543b88d5e Revert "utilfdt_read: pass back up the length of data read"
This reverts commit cc2c178727.
It was the wrong version of the patch.
2013-04-22 15:41:41 -05:00
Mike Frysinger
cc2c178727 utilfdt_read: pass back up the length of data read
For a follow up commit, we want to be able to scan the buffer that was
returned to us.  In order to do that safely, we need to know how big
the buffer actually is, so pass that back if requested.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2013-04-21 14:23:32 -05:00
Simon Glass
f807af1928 fdtput: Add -p option to create subnodes along entire path
This option mimics mkdir's -p option. It automatically creates nodes
as needed along the path provided. If the node already exists, no
error is given.

Signed-off-by: Simon Glass <sjg@chromium.org>
2012-07-12 12:00:25 -05:00
Simon Glass
3553dfac22 fdtput: Adjust report_error() to use name, namelen params
As with many fdt functions, report_error() should permit a namelen to
be specified, thus obviating the need for nul termination in strings
passed to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-07-12 11:58:22 -05:00
Simon Glass
d46c2de570 fdtput: Add -c option to create nodes
This option allows the creation of new nodes in a dtb file. The syntax
is:

   fdtput -c <dtb_file> <node_path>

The node_path contains the path of the node to be created. All path
components up to the final one must exist already. The final one must
not exist already.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-07-12 11:57:36 -05:00
Simon Glass
f58dff5040 fdtput: Prepare to support multiple operations
We want to add new options to this tool. In preparation for this, add
the concept of a current operation.

Signed-off-by: Simon Glass <sjg@chromium.org>
2012-07-12 11:54:06 -05:00
Simon Glass
bb21f0a766 fdtput: Fix nit in help message
There was an extra < in the help message, so fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-07-11 09:39:23 -05:00
Simon Glass
1ede50c355 Add fdtput utility to write property values to a device tree
This simple utility allows writing of values into a device tree from the
command line. It aimes to be the opposite of fdtget.

What is it for:
- Updating fdt values when a binary blob already exists
   (even though source may be available it might be easier to use this
    utility rather than sed, etc.)
- Writing machine-specific fdt values within a build system

To use it, specify the fdt binary file on command line followed by the node
and property to set. Then, provide a list of values to put into that
property. Often there will be just one, but fdtput also supports arrays and
string lists.

fdtput does not try to guess the type of the property based on looking at
the arguments. Instead it always assumes that an integer is provided. To
indicate that you want to write a string, use -ts. You can also provide
hex values with -tx.

The command line arguments are joined together into a single value. For
strings, a nul terminator is placed between each string when it is packed
into the property. To avoid this, pass the string as a single argument.

Usage:
	fdtput <options> <dt file> <<node> <property> [<value>...]
Options:
	-t <type>	Type of data
	-v		Verbose: display each value decoded from command line
	-h		Print this help

<type>	s=string, i=int, u=unsigned, x=hex
	Optional modifier prefix:
		hh or b=byte, h=2 byte, l=4 byte (default)

To read from stdin and write to stdout, use - as the file. So you can do:

cat somefile.dtb | fdtput -ts - /node prop "My string value" > newfile.dtb

This commit also adds basic tests to verify the major features.

Signed-off-by: Simon Glass <sjg@chromium.org>
2012-01-21 15:08:39 -06:00