Commit graph

16 commits

Author SHA1 Message Date
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