aboutsummaryrefslogtreecommitdiff
path: root/treesource.c
AgeCommit message (Collapse)AuthorFilesLines
2013-12-25Pass 'unsigned char' type to isdigit()/isspace()/isprint() functionsSerge Lamikhov-Center1-2/+2
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-10-28Use stdbool more widelyDavid Gibson1-3/+3
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>
2012-02-16dtc: Fix zero-length input segfaultHorst Kronstorfer1-0/+2
This patch fixes a segmentation fault caused by dereferencing a NULL pointer (pos->file aka yylloc.file) in srcpos_string when the input length is 0 (fe 'dtc </dev/null'.) Reason: yylloc.file is initialized with 0 and the tokenizer, which updates yylloc.file via srcpos_update doesn't get a chance to run on zero-length input. Signed-off-by: Horst Kronstorfer <hkronsto@frequentis.com>
2010-02-24dtc: Allow multiple labels on nodes and propertiesDavid Gibson1-6/+9
At present, both the grammar and our internal data structures mean that there can be only one label on a node or property. This is a fairly arbitrary constraint, given that any number of value labels can appear at the same point, and that in C you can have any number of labels on the same statement. This is pretty much a non-issue now, but it may become important with some of the extensions that Grant and I have in mind. It's not that hard to change, so this patch does so, allowing an arbitrary number of labels on any given node or property. As usual a testcase is added too. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Acked-by: Grant Likely <grant.likely@secretlab.ca>
2010-01-14dtc: Simpler interface to source file managementDavid Gibson1-2/+2
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>
2009-11-11Fix bug in -Odts with properties containing multiple terminating nullsDavid Gibson1-14/+15
When in -Odts mode, dtc will not produce correct output for string-like properties which have more than one \0 character at the end of the property's bytestring. In fact, it generates output which is not syntactically correct. This patch fixes the bug, and adds a testcase for future regressions here. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-08-13dtc: Make many functions 'static'David Gibson1-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>
2008-07-14dtc: Enable and fix -Wcast-qual warningsDavid Gibson1-1/+1
Enabling -Wcast-qual warnings in dtc shows up a number of places where we are incorrectly discarding a const qualification. There are also some places where we are intentionally discarding the 'const', and we need an ugly cast through uintptr_t to suppress the warning. However, most of these are pretty well isolated with the *_w() functions. So in the interests of maximum safety with const qualifications, this patch enables the warnings and fixes the existing complaints. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14dtc: Use the same endian-conversion functions as libfdtDavid Gibson1-1/+1
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>
2008-05-19dtc: Simplify error handling for unparseable inputDavid Gibson1-2/+4
Currently, main() tests if it got a valid input tree from whichever dt_from_*() function it invoked and if not, die()s. For one thing, this test has, for no good reason, three different ways for those functions to communicate a failure to provide input (bi NULL, bi->dt NULL, or bi->error non-zero). For another, in every case save one, if the dt_from_*() functions are unable to provide input they will immediately die() (with a more specific error message) rather than proceeding to the test in main(). Therefore, this patch removes this test, making the one case that could have triggered it (in dt_from_source()) call die() directly instead. With this change, the error field in struct boot_info is now unused, so remove it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23dtc: Remove ugly include stack abuseDavid Gibson1-1/+2
Currently, dt_from_source() uses push_input_file() to set up the initial input file for the lexer. That sounds sensible - put the outermost input file at the bottom of the stack - until you realise that what it *actually* does is pushes the current, uninitialized, lexer input state onto the stack, then sets up the new lexer input. That necessitates an extra check in pop_input_file(), rather than signalling termination in the natural way when the include stack is empty, it has to check when it pops the bogus uninitialized state off the stack. Ick. With that fixed, push_input_file(), pop_input_file() and incl_file_stack itself become local to the lexer, so make them static. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23dtc: Make -I dtb mode use fill_fullpaths()David Gibson1-2/+0
At present -I dts and -I fs modes both use the fill_fullpaths() helper function to fill in the fullpath and basenamelen fields of struct node, which are useful in later parts of the code. -I dtb mode, however, fills these in itself. This patch simplifies flattree.c by making -I dtb mode use fill_fullpaths() like the others. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-01-04Return a non-zero exit code if an error occurs during dts parsing.Scott Wood1-0/+3
Previously, only failure to parse caused the reading of the tree to fail; semantic errors that called yyerror() but not YYERROR only emitted a message, without signalling make to stop the build. Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-04Add yyerrorf() for formatted error messages.Scott Wood1-1/+0
Signed-off-by: Scott Wood <scottwood@freescale.com>
2007-12-04dtc: Add many const qualificationsDavid Gibson1-3/+3
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>
2007-11-26dtc: Merge refs and labels into single "markers" list (v2)David Gibson1-30/+32
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>
2007-11-12dtc: -Odts produces v1 outputDavid Gibson1-3/+5
This patch alters the -Odts mode output so that it uses dts-v1 format. This means that dtc -Idts -Odts used on a v0 dts file will convert that file to v1. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-11-08dtc: Make -Idts -Odts preserve property-internal labelsDavid Gibson1-5/+61
This patch changes -Odts mode output so that labels within property values in the input are preserved in the output. Applied on top of the earlier patch to preserve node and property labels in -Odts mode, this means that dtc in -Idts -Odts mode will transfer all labels in the input to the output. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-08dtc: Refactor printing of property values in -Odts modeDavid Gibson1-59/+38
Currently the main recursive tree printing function, write_tree_source_node(), calls guess_type() to apply heuristics to see how to print a property value, then calls the appropriate write_propval_*() function to print it. However, future heuristics for handling internal labels and the like don't work well this way. Therefore, this patch refactors things to have write_tree_source_node() call a new write_propval() function, which incorporates the heurstic logic from guess_type() and also calls the right function to do the actual printing. No behavioural change. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-05dtc: Make -Idts -Odts preserve node/property labelsDavid Gibson1-2/+8
This patch changes -Odts mode output so that labels on properties, nodes and memreserve entries in input source are preserved in the output. Preserving labels within property values is trickier - another patch coming later. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-17dtc: Improve -Odts outputDavid Gibson1-27/+97
This patch makes improvements to the way properties are printed when in dtc is producing dts output. - Characters which need escaping are now properly handled when printing properties as strings - The heuristics for what format to use for a property are improved so that 'compatible' properties will be displayed as expected. - escapes.dts is altered to better demonstrate the changes, and the string_escapes testcase is adjusted accordingly. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-09-18dtc: Whitespace cleanupDavid Gibson1-7/+6
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>
2007-03-26DTC: Add support for a C-like #include "file" mechanism.Jon Loeliger1-2/+4
Keeps track of open files in a stack, and assigns a filenum to source positions for each lexical token. Modified error reporting to show source file as well. No policy on file directory basis has been decided. Still handles stdin. Tested on all arch/powerpc/boot/dts DTS files Signed-off-by: Jon Loeliger <jdl@freescale.com>
2005-10-26Use names for output functions in the form dt_to_*() instead ofDavid Gibson1-1/+1
write_dt_*() for consistency with the dt_from_*() input functions.
2005-10-24Rework tracking of reserve entries during processing. This is initial workDavid Gibson1-23/+4
to allow more powerful handling of reserve entries.
2005-08-29Fix endian problems with handling of memreserve entries (bug pointed outDavid Gibson1-2/+3
by Pantelis Antoniou). The rule is that the memreserve data in struct boot_info is always stored big-endian.
2005-08-29Remove an unused function, mark a bunch of other functions and variablesDavid Gibson1-1/+1
as static. Mostly found by sparse.
2005-07-15Support for specifying memreserve ranges in the source format, based onDavid Gibson1-7/+44
a patch by Jon Loeliger <jdl AT freescale.com>, although tweaked substantially.
2005-06-08Initial commitDavid Gibson1-0/+140