summaryrefslogtreecommitdiff
path: root/util.h
Commit message (Collapse)AuthorAgeFilesLines
* util: add common ARRAY_SIZE defineMike Frysinger2013-05-241-0/+2
| | | | | | | | I want to use this in more places, so put it in util.h rather than copying & pasting it into another file. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* util: drop "long" from usage helpersMike Frysinger2013-05-241-9/+9
| | | | | | | | 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>
* dtc/fdt{get, put}/convert-dtsv0-lexer: convert to new usage helpersMike Frysinger2013-05-241-1/+1
| | | | | | | | | | 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>
* fdtdump: make usage a bit more friendlyMike Frysinger2013-05-241-0/+61
| | | | | | | | 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>
* utilfdt_read: pass back up the length of data readMike Frysinger2013-04-221-0/+13
| | | | | | | | | 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>
* Revert "utilfdt_read: pass back up the length of data read"Jon Loeliger2013-04-221-4/+2
| | | | | This reverts commit cc2c178727cdeca4eb9756637c2e09e50e0856e7. It was the wrong version of the patch.
* util_version: new helper for displaying version infoMike Frysinger2013-04-211-0/+5
| | | | | | | 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>
* die: constify format string argMike Frysinger2013-04-211-1/+1
| | | | | | | | We only display this string, so there's no need for it to be writable. Constify away! Acked-by: David Gibson <David@gibson.dropbear.id.au> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* utilfdt_read: pass back up the length of data readMike Frysinger2013-04-211-2/+4
| | | | | | | | 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>
* Move property-printing into utilSimon Glass2013-01-271-0/+14
| | | | | | | | 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>
* Adjust util_is_printable_string() comment and fix testSimon Glass2013-01-271-3/+5
| | | | | | | | | This commit which changed the behaviour of this function broke one of the tests. Also the comment should be updated to reflect its new behaviour. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: David Gibson <david@gibson.dropbear.id.au>
* Add fdtget utility to read property values from a device treeSimon Glass2012-01-211-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This simply utility makes it easy for scripts to read values from the device tree. It is written in C and uses the same libfdt as the rest of the dtc package. What is it for: - Reading fdt values from scripts - Extracting fdt information within build systems - Looking at particular values without having to dump the entire tree To use it, specify the fdt binary file on command line followed by a list of node, property pairs. The utility then looks up each node, finds the property and displays the value. Each value is printed on a new line. fdtget tries to guess the type of each property based on its contents. This is not always reliable, so you can use the -t option to force fdtget to decode the value as a string, or byte, etc. To read from stdin, use - as the file. Usage: fdtget <options> <dt file> [<node> <property>]... Options: -t <type> Type of data -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) Signed-off-by: Simon Glass <sjg@chromium.org>
* Add fdt read/write utility functionsSimon Glass2011-09-221-0/+68
| | | | | | | | | | | | 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>
* dtc: Refactor character literal parsing codeAnton Staaf2011-09-091-0/+8
| | | | | | | | | 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>
* Split out is_printable_string() into util.cSimon Glass2011-07-171-0/+11
| | | | | | | | 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>
* dtc: Simpler interface to source file managementDavid Gibson2010-01-141-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* dtc: Move some functions to util.[ch]David Gibson2009-01-071-0/+35
| | | | | | | | | | | Now that we have a util.[ch] file shared between dtc and convert-dtsv0, move some functions which are currently duplicated in the two to util files. Specifically we move the die(), xmalloc() and xrealloc() functions. While we're at it, add standard double-include protection to util.h Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Implement and use an xstrdup() functionJon Loeliger2008-10-031-0/+20
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>