Commit graph

34 commits

Author SHA1 Message Date
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
David Gibson
49300f2ade dtc: Don't abuse struct fdt_reserve_entry
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>
2017-03-06 12:04:45 +11:00
David Gibson
00fbb8696b Rename boot_info
struct boot_info is named that for historical reasons, and isn't
particularly meaningful.  Essentially it contains all the information -
in "live" form from a single dts or dtb file.  As we move towards support
for dynamic dt overlays, that name will become increasingly bad.

So, in preparation, rename it to dt_info.  At the same time rename the
'the_boot_info' global to 'parser_output' since that's its actual purpose.
Unfortunately we do need the global unless we switch to bison's re-entrant
parser extensions, which would introduce its own complications.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09 16:30:43 +11:00
Andrei Errapart
25a9bd6267 Correct write_propval_bytes() for platforms with signed char by default
Some platforms (including the Microsoft C compiler) have char defaulting
to signed.  write_propval_bytes() in the -O dts code will not behave
correctly in this case, due to sign extension.

Signed-off-by: Andrei Errapart <andrei@errapartengineering.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-06-19 21:05:34 +10:00
David Gibson
fa928fba7e Fix an off-by-2 error in the source output code
This has been there for ages, but the assertion makes no sense in the
context of the test immediately preceding it.  This caused an abort()
when in -I dts -O dts mode with the right sort of internal labels in a
string property value.

Add a testcase for this and another candidate edge case (though this one
we already get right).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-06-18 22:49:43 +10: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
Horst Kronstorfer
a6e6c60e3a dtc: Fix zero-length input segfault
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>
2012-02-16 06:43:51 -06:00
David Gibson
05898c67c1 dtc: Allow multiple labels on nodes and properties
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-02-24 08:48:51 -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
David Gibson
c623fe5c21 Fix bug in -Odts with properties containing multiple terminating nulls
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>
2009-11-11 07:34:01 -06:00
David Gibson
01a2d8a3e9 dtc: Make many functions 'static'
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-08-13 13:04:39 -05:00
David Gibson
1409097db8 dtc: Enable and fix -Wcast-qual warnings
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-14 12:36:08 -05:00
David Gibson
c8c374b856 dtc: Use the same endian-conversion functions as libfdt
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-07-14 12:07:22 -05:00
David Gibson
35aa1a273b dtc: Simplify error handling for unparseable input
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-05-19 14:07:40 -05:00
David Gibson
8a88ad8bad dtc: Remove ugly include stack abuse
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-23 08:00:33 -05:00
David Gibson
b2de518b80 dtc: Make -I dtb mode use fill_fullpaths()
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-03-23 08:00:33 -05:00
Scott Wood
ad4f54ae2b Return a non-zero exit code if an error occurs during dts parsing.
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-04 08:21:54 -06:00
Scott Wood
f77fe6a20e Add yyerrorf() for formatted error messages.
Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-04 08:04:15 -06:00
David Gibson
92cb9a25b1 dtc: Add many const qualifications
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-12-04 07:54:03 -06:00
David Gibson
dc941774e2 dtc: Merge refs and labels into single "markers" list (v2)
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-26 16:00:19 -06:00
David Gibson
91967acabd dtc: -Odts produces v1 output
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-12 07:46:04 -06:00
David Gibson
d3ea6e5f96 dtc: Make -Idts -Odts preserve property-internal labels
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-08 09:02:49 -06:00
David Gibson
ed01ae41e2 dtc: Refactor printing of property values in -Odts mode
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-08 09:00:36 -06:00
David Gibson
02563ad023 dtc: Make -Idts -Odts preserve node/property labels
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-11-05 08:41:23 -06:00
David Gibson
5a98ddd10a dtc: Improve -Odts output
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-10-17 07:14:38 -05:00
David Gibson
63dc9c7113 dtc: Whitespace cleanup
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-09-18 09:43:26 -05:00
Jon Loeliger
e45e6fd274 DTC: Add support for a C-like #include "file" mechanism.
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>
2007-03-26 08:36:07 -05:00
David Gibson
712e52e438 Use names for output functions in the form dt_to_*() instead of
write_dt_*() for consistency with the dt_from_*() input functions.
2005-10-26 16:56:26 +10:00
David Gibson
f040d95b84 Rework tracking of reserve entries during processing. This is initial work
to allow more powerful handling of reserve entries.
2005-10-24 18:18:38 +10:00
David Gibson
6c0f36769a Fix endian problems with handling of memreserve entries (bug pointed out
by Pantelis Antoniou).  The rule is that the memreserve data in struct
boot_info is always stored big-endian.
2005-08-29 13:36:15 +10:00
David Gibson
230f253e9b Remove an unused function, mark a bunch of other functions and variables
as static.  Mostly found by sparse.
2005-08-29 12:48:02 +10:00
David Gibson
f0517db250 Support for specifying memreserve ranges in the source format, based on
a patch by Jon Loeliger <jdl AT freescale.com>, although tweaked
substantially.
2005-07-15 17:14:24 +10:00
David Gibson
fc14dad769 Initial commit 2005-06-08 17:18:34 +10:00