Commit graph

38 commits

Author SHA1 Message Date
Pierre-Clément Tosi
9c26cc838f ANDROID: Merge upstream ed310803ea (v1.6.1)
Upgrade to the latest master from

    git://git.kernel.org/pub/scm/utils/dtc/dtc.git.

at commit ed310803ea.

Bug: 221191119
Bug: 222320399
Bug: 230794395
Bug: 234413190
Change-Id: I6cc623e217641d7db3d4f2c4873cda472da08ef4
2022-05-31 09:16:03 +01:00
Ahmad Fatoum
651410e54c util: introduce xstrndup helper
We already have xstrdup, add xstrndup as well to make it
straight-forward to clone part of a string.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
2022-01-25 17:10:47 +11:00
Rafał Miłecki
17739b7ef5 Support 'r' format for printing raw bytes with fdtget
FT is sometimes used for storing raw data. That is quite common for
U-Boot FIT images.

Extracting such data is not trivial currently. Using type 's' (string)
will replace every 0x00 (NUL) with 0x20 (space). Using type 'x' will
print bytes but in xxd incompatible format.

This commit adds support for 'r' (raw) format. Example usage:
fdtget -t r firmware.itb /images/foo data > image.raw

Support for encoding isn't added as there isn't any clean way of passing
binary data as command line argument.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Message-Id: <20211209061420.29466-1-zajec5@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-09 17:48:58 +11:00
Steve Muckle
b734cfd607 Update dtc to 1.6.0
Upstream commit 9d7888cbf1.

Bug: 160825200
Change-Id: I1f8c79f09190af4025b186166a25b745710f2871
2020-07-09 14:54:01 -07:00
David Gibson
6ce585ac15 Use correct inttypes.h format specifier
The type here is uint32_t which should use PRIx32, not plain %x which is
for an int, we've just gotten away with it so far.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-11-07 17:46:43 +01:00
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
Rob Herring
a1eff70c02 util: Add xa{v}sprintf_append functions
Add variadic and va_list functions, xa{v}sprintf, which appends a
formatted string to an existing string and re-allocate the string buffer
if necessary. xasprintf becomes just a special case of xasprintf_append
with a NULL starting string.

Rather than looping to get a big enough buffer, simply the implementation
by assuming we have a C99 compliant vsnprintf implementation to return the
necessary size. A side effect is glibc 2.0 support is dropped which seems
unnecessary.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-25 18:21:48 +11:00
David Gibson
fb9c6abdda Use size_t for blob lengths in utilfdt_read*
It's more appropriate than off_t since it is, after all, a size not an
offset.

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:49:17 +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
SzuWei Lin
41c88b14dc Update to dtc-1.4.4
Merge dtc to upstream 558cd81bdd
and merge history

Bug: 37655045
Test: Build dtc, use output dtc to build dts, can output correct dtb.
Change-Id: Ibd9a82768e999bc46e6de349ca97ba6447e85455
2017-04-25 18:27:20 +08: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
SzuWei Lin
507cd9883a Reset master to upstream
Reset master to upstream 120775eb1c
and merge history.

Bug: 35151782
Test: Build dtc, use output dtc to build dts, can output correct dtb.
Change-Id: I4d3ef31a8597f7b214fea2d70ceb99a08d57d925
2017-02-17 11:16:16 +08:00
Pantelis Antoniou
9dc404958e util: Add xasprintf portable asprintf variant
Include a portable asprintf variant that works on any C99
conforming platform.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-05-25 14:55:17 +10:00
Chris Phoenix
a768648acb Make it build under Android
Replace version_gen.h with hardcoded version_non_gen.h
Add Android.mk and libfdt/Android.mk
Change dtc-parser.tab.h to dtc-parser.h (in dtc-lexer.l)

Change-Id: If7b8ac5fdad41294298161b3e800fc81347be415
2016-02-23 16:26:37 -08:00
David Gibson
d728ad59f5 Fix crash on nul character in string escape sequence
If a dts file contains a string with \ followed by a nul byte - an actual
nul in the input file, not the \\0 escape - then the assert() in
get_escape_char() will trip, crashing dtc.

As far as I can tell, there isn't any valid need for this assert(), so just
remove it.

Reported-by: Anton Blanchard <anton@samba.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-01-03 23:01:24 +11:00
David Gibson
e5e6df7c37 fdtdump: Fix bug printing bytestrings with negative values
On systems where 'char' is signed, fdtdump will currently print the wrong
thing on properties containing bytestring values with "negative" bytes
(that is with values from 0x80..0xff).  The fdtdump testcase is extended
to cover this case too.

This corrects the problem by forcing use of unsigned char - although this
is perhaps another indication that fdtdump is a buggy hack and if you want
to do real work you should use dtc -O dts.

Reported-by: Igor Prusov <Igor.V.Prusov@mcst.ru>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-07-09 13:47:19 +10:00
Simon Glass
c78ca72e1e Tweak code to display cell values
Move the division out of the loop; this seems slightly cleaner.

Signed-off-by: Simon Glass <sjg@chromium.org>
2014-06-18 21:02:51 +10:00
Heinrich Schuchardt
821acd4c17 Remove dead code in util.c
xrealloc never returns null

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2014-03-02 11:45:25 +11:00
Florian Fainelli
24cb3d0681 dtc: fix some more -Wshadow warnings
Building on a RHEL6 system produced the following -Wshadow warnings in
fstree.c, util.c and checks.c:

cc1: warnings being treated as errors
checks.c: In function 'parse_checks_option':
checks.c:709: error: declaration of 'optarg' shadows a global
declaration
/usr/include/getopt.h:59: error: shadowed declaration is here
make[1]: *** [checks.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: *** Waiting for unfinished jobs....
cc1: warnings being treated as errors
fstree.c: In function 'read_fstree':
fstree.c:40: error: declaration of 'tmpnam' shadows a global
declaration
/usr/include/stdio.h:208: error: shadowed declaration is here
make[1]: *** [fstree.o] Error 1
cc1: warnings being treated as errors
util.c: In function 'xstrdup':
util.c:42: error: declaration of 'dup' shadows a global declaration
/usr/include/unistd.h:528: error: shadowed declaration is here

Fix all of these -Wshadow warnings by using slightly different variable
names which won't collide with anything else.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2014-02-01 16:48:19 +11:00
Serge Lamikhov-Center
17119ab0a5 Pass 'unsigned char' type to isdigit()/isspace()/isprint() functions
The isdigit(), isprint(), etc. functions take an int, whose value is
required to be in the range of an _unsigned_ char, or EOF.  This, horribly,
means that systems which have a signed char by default need casts to pass
a char variable safely to these functions.

We can't do this more nicely by making the variables themselves 'unsigned
char *' because then we'll get warnings passing them to the strchr() etc.
functions.

At least the cygwin version of these functions, are designed to generate
warnings if this isn't done, as explained by this comment from ctype.h:
   These macros are intentionally written in a manner that will trigger
   a gcc -Wall warning if the user mistakenly passes a 'char' instead
   of an int containing an 'unsigned char'.

Signed-off-by: Serge Lamikhov-Center <Serge.Lamikhov@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-12-25 15:27:22 +11:00
David Gibson
17625371ee Use stdbool more widely
We already use the C99 bool type from stdbool.h in a few places.  However
there are many other places we represent boolean values as plain ints.
This patch changes that.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-10-28 21:06:53 +11:00
Serge Lamikhov-Center
883238dc50 util: Fix out of bounds memory access
The change also fixes numeric values output produced by fdtdump.

Signed-off-by: Serge Lamikhov-Center <Serge.Lamikhov@gmail.com>
2013-10-01 14:21:18 +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
be8d1c82cb fdtdump: make usage a bit more friendly
This starts a new usage framework and then cuts fdtdump over to it.
Now we can do `fdtdump -h` and get something useful back.

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
a6d55e039f 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 create a new set of funcs to pass that back.

Acked-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2013-04-22 15:42:14 -05: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
31be4ce7ca util_version: new helper for displaying version info
This is so all utilities can have this flag and not just dtc.

Acked-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2013-04-21 14:23:56 -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
Mike Frysinger
f8cb5dd949 utilfdt_read_err: use xmalloc funcs
We've got these handy helpers, so let's use them.

Acked-by: David Gibson <David@gibson.dropbear.id.au>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2013-04-21 14:23:02 -05:00
Simon Glass
d20391d6ff Move property-printing into util
The function that prints a property can be useful to other programs,
so move it into util.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2013-01-27 14:20:56 -06:00
Pantelis Antoniou
1c1efd6954 Fix util_is_printable_string
The method used did not account for multi-part strings.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2013-01-06 15:37:19 -06:00
David Gibson
e280442e08 Fix uninitialized access bug in utilfdt_decode_type
I just found this little bug with valgrind.  strchr() will return true
if the given character is '\0'.  This meant that utilfdt_decode_type()
could take a path which accesses uninitialized data when given the
(invalid) format string "L".

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-02-03 08:43:40 -06:00
Simon Glass
36204fdf74 Add fdt read/write utility functions
This adds higher-level libfdt operations for reading/writing an fdt
blob from/to a file, as well as a function to decode a data type string
as will be used by fdtget, fdtput.

This also adds a few tests for the simple type argument supported by
utilfdt_decode_type.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-09-22 13:49:33 -05:00
Anton Staaf
b43335a238 dtc: Refactor character literal parsing code
Move the parsing of hex, octal and escaped characters from data.c
to util.c where it can be used for character literal parsing within
strings as well as for stand alone C style character literals.

Signed-off-by: Anton Staaf <robotboy@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-09-09 16:05:36 -05:00
Simon Glass
492f9d5de7 Split out is_printable_string() into util.c
This useful function is split out so it will be available to programs
other than ftdump.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-07-17 07:42:26 -05:00
David Gibson
8765874963 dtc: Correct headers in util.c
Since util.c is used in programs other than full dtc, it shouldn't
include the full dtc.h, just util.h which has prototypes directly
relevant to it.  This patch makes the change, and also adds includes
of the necessary system headers which were previously included
indirectly by dtc.h.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-03-03 07:55:54 -06:00
David Gibson
d68cb36b0b dtc: Simpler interface to source file management
This patch cleans up our handling of input files, particularly dts
source files, but also (to an extent) other input files such as those
used by /incbin/ and those used in -I dtb and -I fs modes.

We eliminate the current clunky mechanism which combines search paths
(which we don't actually use at present) with the open relative to
current source file behaviour, which we do.

Instead there's a single srcfile_relative_open() entry point for
callers which opens a new input file relative to the current source
file (which the srcpos code tracks internally).  It doesn't currently
do search paths, but we can add that later without messing with the
callers, by drawing the search path from a global (which makes sense
anyway, rather than shuffling it around the rest of the processing
code).

That suffices for non-dts input files.  For the actual dts files,
srcfile_push() and srcfile_pop() wrappers open the file while also
keeping track of it as the current source file for future opens.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-01-14 07:52:25 -06:00
Jon Loeliger
879e4d2590 Implement and use an xstrdup() function
Many places in dtc use strdup(), but none of them actually check the
return value to see if the implied allocation succeeded.  This is a
potential bug, which we fix in the patch below by replacing strdup()
with an xstrdup() which in analogy to xmalloc() will quit with a fatal
error if the allocation fails.

I felt the introduciton of util.[ch] was a better choice
for utility oriented code than directly using srcpos.c
for the new string function.

This patch is a re-factoring of Dave Gibson's similar patch.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-10-03 11:12:33 -05:00