summaryrefslogtreecommitdiff
path: root/data.c
Commit message (Collapse)AuthorAgeFilesLines
* dtc: Fix signedness comparisons warnings: Wrap (-1)Andre Przywara2020-10-131-1/+1
| | | | | | | | | | | | | | With -Wsign-compare, compilers warn about a mismatching signedness in a comparison in dtc's data_copy_file(). Even though maxlen is of an unsigned type, we compare against "-1", which is passed in from the parser to indicate an unknown size. Cast the "-1" to an unsigned size to make the comparison match. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201012161948.23994-9-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Fix signedness comparisons warnings: change typesAndre Przywara2020-10-131-2/+2
| | | | | | | | | | | | | With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in various parts of dtc. Many variables are using signed types unnecessarily, as we never use negative value in them. Change their types to be unsigned, to prevent issues with comparisons. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201012161948.23994-7-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Replace GPLv2 boilerplate/reference with SPDX tagsRob Herring2019-06-211-16/+1
| | | | | | | | 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>
* Kill bogus TYPE_BLOB marker typeGreg Kurz2018-08-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since commit 32b9c6130762 "Preserve datatype markers when emitting dts format", we no longer try to guess the value type. Instead, we reuse the type of the datatype markers when they are present, if the type is either TYPE_UINT* or TYPE_STRING. This causes 'dtc -I fs' to crash: Starting program: /root/dtc -q -f -O dts -I fs /proc/device-tree /dts-v1/; / { Program received signal SIGSEGV, Segmentation fault. __strlen_power8 () at ../sysdeps/powerpc/powerpc64/power8/strlen.S:47 47 ld r12,0(r4) /* Load doubleword from memory. */ (gdb) bt #0 __strlen_power8 () at ../sysdeps/powerpc/powerpc64/power8/strlen.S:47 #1 0x00007ffff7de3d10 in __GI__IO_fputs (str=<optimized out>, fp=<optimized out>) at iofputs.c:33 #2 0x000000001000c7a0 in write_propval (prop=0x100525e0, f=0x7ffff7f718a0 <_IO_2_1_stdout_>) at treesource.c:245 The offending line is: fprintf(f, "%s", delim_start[emit_type]); where emit_type is TYPE_BLOB and: static const char *delim_start[] = { [TYPE_UINT8] = "[", [TYPE_UINT16] = "/bits/ 16 <", [TYPE_UINT32] = "<", [TYPE_UINT64] = "/bits/ 64 <", [TYPE_STRING] = "", }; /* Data blobs */ enum markertype { TYPE_NONE, REF_PHANDLE, REF_PATH, LABEL, TYPE_UINT8, TYPE_UINT16, TYPE_UINT32, TYPE_UINT64, TYPE_BLOB, TYPE_STRING, }; Because TYPE_BLOB < TYPE_STRING and delim_start[] is a static array, delim_start[emit_type] is 0x0. The glibc usually prints out "(null)" when one passes 0x0 to %s, but it seems to call fputs() internally if the format is exactly "%s", hence the crash. TYPE_BLOB basically means the data comes from a file and we don't know its type. We don't care for the former, and the latter is TYPE_NONE. So let's drop TYPE_BLOB completely and use TYPE_NONE instead when reading the file. Then, try to guess the data type at emission time, like the code already does for refs and labels. Instead of adding yet another check for TYPE_NONE, an helper is introduced to check if the data marker has type information, ie, >= TYPE_UINT8. Fixes: 32b9c61307629ac76c6ac0bead6f926d579b3d2c Suggested-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Greg Kurz <groug@kaod.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Preserve datatype information when parsing dtsGrant Likely2018-06-041-1/+3
| | | | | | | | | | | | | | | | The current code throws away all the data type and grouping information when parsing the DTS source file, which makes it difficult to reconstruct the data format when emitting a format that can express data types (ie. dts and yaml). Use the marker structure to mark the beginning of each integer array block (<> and []), and the datatype contained in each (8, 16, 32 & 64 bit widths). Signed-off-by: Grant Likely <grant.likely@arm.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> [robh: s/MARKER_/TYPE_/] Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Fix assorted sparse warningsDavid Gibson2017-03-061-3/+3
| | | | | | | | | | | | | | | | | 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>
* dtc: Don't abuse struct fdt_reserve_entryDavid Gibson2017-03-061-5/+5
| | | | | | | | | | | | | | | | struct fdt_reserve_entry is defined in fdt.h to exactly mirror the in-memory layout of a reserve entry in the flattened tree. Since that is always big-endian, it uses fdt64_t elements, which have sparse annotations marking them as not native endian. However, in dtc, we also use struct fdt_reserve_entry inside struct reserve_info, and use it with native endian values. This will cause sparse errors. This stops this abuse, making struct reserve_info have its own native endian fields for the same information. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Properly handle embedded nul delimited string listsJack Miller2014-08-081-1/+1
| | | | | | | | | | | | | For example: reserved-names="res1\0res2\0res3"; Where \0 is an actual embedded NUL in the source instead of a string escape. To achieve this, use the len given by the lexer instead of strlen. Without this patch dtc will mangle the output and possibly hang on realloc.
* Use stdbool more widelyDavid Gibson2013-10-281-5/+5
| | | | | | | | 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>
* dtc: Add data_append_integer functionAnton Staaf2011-10-111-7/+32
| | | | | | | | | | | | | This function deals with appending integers of various sizes (8, 16 32, and 64 bit currently). It handles endianess conversions. If the integer will not fit in the requested number of bits of storage it will have it's high bits ignored. This patch also rewrites data_append_cell and data_append_addr to use data_append_integer. Signed-off-by: Anton Staaf <robotboy@chromium.org> Acked-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Refactor character literal parsing codeAnton Staaf2011-09-091-81/+4
| | | | | | | | | 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>
* dtc: Make many functions 'static'David Gibson2008-08-131-1/+1
| | | | | | | | | | | | | This patch marks various functions not shared between c files 'static', as they should be. There are a couple of functions in dtc, and many in the testsuite. This is *almost* enough to enable the -Wmissing-prototypes warning. It's not quite enough, because there's a mess of junk in the flex generated code which triggers that warning which I'm not yet sure how to deal with. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Use the same endian-conversion functions as libfdtDavid Gibson2008-07-141-4/+4
| | | | | | | | | | | | | | | | Currently both libfdt and dtc define a set of endian conversion macros for accessing the device tree blob which is always big-endian. libfdt uses names like cpu_to_fdt32() and dtc uses names like cpu_to_be32 (as the Linux kernel). This patch switches dtc over to using the libfdt macros (including libfdt_env.h to supply them). This has a couple of small advantages: - Removes some code duplication - Will make conversion a bit easier if we ever need to produce little-endian device tree blobs. - dtc no longer needs to pull in netinet/in.h simply for the ntohs() and ntohl() functions Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Use stdint.h types throughout dtcDavid Gibson2008-07-141-2/+2
| | | | | | | | | Currently, dtc defines Linux-like names for various fixed-size integer types. There's no good reason to do this; even Linux itself doesn't use these names for externally visible things any more. This patch replaces these with the C99 standardized type names from stdint.h. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Add support for binary includes.David Gibson2008-06-191-5/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Wed, Jun 04, 2008 at 09:26:23AM -0500, Jon Loeliger wrote: > David Gibson wrote: > >> But as I said that can be dealt with in the future without breaking >> compatibility. Objection withdrawn. >> > > And on that note, I officially implore Scott to > re-submit his binary include patch! Scott's original patch does still have some implementation details I didn't like. So in the interests of saving time, I've addressed some of those, added a testcase, and and now resubmitting my revised version of Scott's patch. dtc: Add support for binary includes. A property's data can be populated with a file's contents as follows: node { prop = /incbin/("path/to/data"); }; A subset of a file can be included by passing start and size parameters. For example, to include bytes 8 through 23: node { prop = /incbin/("path/to/data", 8, 16); }; As with /include/, non-absolute paths are looked for in the directory of the source file that includes them. Implementation revised, and a testcase added by David Gibson Signed-off-by: Scott Wood <scottwood@freescale.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Acked-by: Scott Wood <scottwood@freescale.com>
* dtc: Cleanup \nnn and \xNN string escape handlingDavid Gibson2008-03-231-13/+6
| | | | | | | | | | | | | | | Several small cleanups to the handling of octal and hex string escapes: - Use strncmp() instead dof what were essentially open-coded versions of the same, with short fixed lengths. - The call path to get_oct_char() means an empty escape is not possible. So replace the error message in this case with an assert. - Use die() instead of a non-fatal error message if get_hex_char() is given an empty escape. Change error message to close match gcc's in the same circumstance. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Abolish asize field of struct dataDavid Gibson2008-03-231-8/+0
| | | | | | | | | | | The asize field in struct data is a hangover from the early days when a struct data was sometimes allowed to refer to a static chunk of memory rather than a malloc()ed block. That's long gone, since the lifetime issues were far more trouble than it was worth, so get rid of the asize field. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Implement path referencesDavid Gibson2007-12-051-0/+15
| | | | | | | | | | | | This patch extends dtc syntax to allow references (&label, or &{/full/path}) directly within property definitions, rather than inside a cell list. Such references are expanded to the full path of the referenced node, as a string, instead of to a phandle as references within cell lists are evaluated. A testcase is also included. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Add many const qualificationsDavid Gibson2007-12-041-6/+6
| | | | | | | | This adds 'const' qualifiers to many variables and functions. In particular it's now used for passing names to the tree accesor functions. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Merge refs and labels into single "markers" list (v2)David Gibson2007-11-261-74/+29
| | | | | | | | | | | | | | | | | | | | | Currently, every 'data' object, used to represent property values, has two lists of fixup structures - one for labels and one for references. Sometimes we want to look at them separately, but other times we need to consider both types of fixup. I'm planning to implement string references, where a full path rather than a phandle is substituted into a property value. Adding yet another list of fixups for that would start to get silly. So, this patch merges the "refs" and "labels" lists into a single list of "markers", each of which has a type field indicating if it represents a label or a phandle reference. String references or any other new type of in-data marker will then just need a new type value - merging data blocks and other common manipulations will just work. While I was at it I made some cleanups to the handling of fixups which simplify things further. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: data.c doesn't need to include dtc-parser.tab.hDavid Gibson2007-10-221-1/+0
| | | | | | | Presumably we used this #include once, but it's certainly not necessary now. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Improve support for string escapesDavid Gibson2007-10-161-0/+12
| | | | | | | | | | | | | | | | | | | | dtc supports the use of C-style escapes (\n, \t and so forth) in string property definitions via the data_copy_escape_string() function. However, while it supports the most common escape characters, it doesn't support the full set that C does, which is a potential gotcha. Worse, a bug in the lexer means that while data_copy_escape_string() can handle the \" escape, a string with such an escape won't lex correctly. This patch fixes both problems, extending data_copy_escape_string() to support the missing escapes, and fixing the regex for strings in the lexer to handle internal escaped quotes. This also adds a testcase for string escape functionality. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Use libfdt/fdt.h instead of flat_dt.hDavid Gibson2007-09-271-2/+2
| | | | | | | | | | | | In the dtc tree, both flat_dt.h and libfdt/fdt.h have structures and constants relating to the flattened device tree format derived from asm-powerpc/prom.h in the kernel. The former is used in dtc, the latter in libfdt. libfdt/fdt.h is the more recent, revised version, so use that throughout, removing flat_dt.h. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Whitespace cleanupDavid Gibson2007-09-181-8/+8
| | | | | | | | | | | | This large patch removes all trailing whitespace from dtc (including libfdt, the testsuite and documentation). It also removes a handful of redundant blank lines (at the end of functions, or when there are two blank lines together for no particular reason). As well as anything else, this means that quilt won't whinge when I go to convert the whole of libfdt into a patch to apply to the kernel. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: store labels in ascending orderMilton Miller2007-07-071-3/+9
| | | | | | | | | | | | | | | When adding a label, walk to the end of the list since the label reflects the end of the data. Since merging data buffers already preserved the order, this will cause the labels to be emitted in order when writing assembly output. It should also aid emiting labels when writing dts output should that be added in the future (data formatting would need to break at each label). Signed-off-by: Milton Miller <miltonm@bga.com>
* dtc: implement labels on property dataMilton Miller2007-07-071-10/+40
| | | | | | | | | | | | | | | | | | | | | | | Extend the parser grammer to allow labels before or after any property data (string, cell list, or byte list), and any byte or cell within the property data. Store the labels using the same linked list structure as node references, but using a parallel list. When writing assembly output emit global labels as offsets from the start of the definition of the data. Note that the alignment for a cell list is done as part of the opening < delimiter, not the = or , before it. To label a cell after a string or byte list put the label inside the cell list. For example, prop = zero: [ aa bb ], two: < four: 1234 > eight: ; will produce labels with offsets 0, 2, 4, and 8 bytes from the beginning of the data for property prop. Signed-off-by: Milton Miller <miltonm@bga.com>
* dtc: clean up grow_data_for()Milton Miller2007-07-071-2/+2
| | | | | | | | | | | | Change the grow_data_for function to copy struct data and modifiy the fields it is updating instead of storing all fields individually to a stack allocated struct. This reduces maintence for future enhancements as now all instances of struct data are created by modifying a copy of an existing struct data or directly copying empty_data. Signed-off-by: Milton Miller <miltonm@bga.com>
* Moved data_convert_cell() out of data.c to the parser.Jon Loeliger2007-02-161-20/+0
| | | | | | | It constructs a cell_t, not data objects. Renamed it to cell_from_string() as well. Signed-off-by: Jon Loeliger <jdl@freescale.com>
* Add support for decimal, octal and binary based cell values.Jon Loeliger2007-02-151-0/+21
| | | | | | | New syntax d#, b#, o# and h# allow for an explicit prefix on cell values to specify their base. Eg: <d# 123> Signed-off-by: Jon Loeliger <jdl@freescale.com>
* Allow multipart property valuesDavid Gibson2007-02-081-0/+27
| | | | | | | | | | | | | | | | | | | | At present each property definition in a dts file must give as the value either a string ("abc..."), a bytestring ([12abcd...]) or a cell list (<1 2 3 ...>). This patch allows a property value to be given as several of these, comma-separated. The final property value is just the components appended together. So a property could have a list of cells followed by a string, or a bytestring followed by some cells. Cells are always aligned, so if cells are given following a string or bytestring which is not a multiple of 4 bytes long, zero bytes are inserted to align the following cells. The primary motivation for this feature, however, is to allow defining a property as a list of several strings. This is what's needed for defining OF 'compatible' properties, and is less ugly and fiddly than using embedded \0s in the strings. Signed-off-by: David Gibson <dwg@au1.ibm.com> Signed-off-by: Jon Loeliger <jdl@freescale.com>
* Remove dead code.Jon Loeliger2006-06-241-18/+0
| | | | Signed-off-by: Jon Loeliger <jdl@jdl.com>
* Rework tracking of reserve entries during processing. This is initial workDavid Gibson2005-10-241-0/+10
| | | | to allow more powerful handling of reserve entries.
* Oops avoid using case range gcc extension.David Gibson2005-10-171-1/+8
|
* Remove an unused function, mark a bunch of other functions and variablesDavid Gibson2005-08-291-16/+2
| | | | as static. Mostly found by sparse.
* Support for specifying memreserve ranges in the source format, based onDavid Gibson2005-07-151-0/+7
| | | | | a patch by Jon Loeliger <jdl AT freescale.com>, although tweaked substantially.
* Rudimentary phandle reference support.David Gibson2005-06-161-0/+34
|
* Initial commitDavid Gibson2005-06-081-0/+250