Commit graph

16 commits

Author SHA1 Message Date
Andre Przywara
04cf1fdc0f convert-dtsv0: Fix signedness comparisons warning
With -Wsign-compare, compilers warn about a mismatching signedness in
comparisons in the generated lexer code.

In this case we walk over an array, and never use negative indicies, so
we can change the loop counter variable to be unsigned.

This fixes "make convert-dtsv0", when compiled with -Wsign-compare.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Message-Id: <20201012161948.23994-3-andre.przywara@arm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-13 15:48:40 +11:00
Rob Herring
acfe84f2c4 dtc: Replace GPLv2 boilerplate/reference with SPDX tags
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>
2019-06-21 21:06:10 +10:00
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
1074ee54b6 convert-dtsv0-lexer.l: fix memory leak
CID 132822 (#1 of 1): Resource leak (RESOURCE_LEAK)
9. leaked_storage: Variable newname going out of scope leaks the storage it points to

Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net>
[dwg: Removed unnecessary hunk]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-07-24 00:50:30 +10:00
Wang Long
6a76a9d30c dtc: Delete the unused start condition INCLUDE
The scanners of the latest version of dtc and
convert-dtsv0 are no longer use start condition
"INCLUDE". so we should delete it.

Signed-off-by: Wang Long <long.wanglong@huawei.com>
2014-09-26 12:14:49 +10:00
Mike Frysinger
4ad49c3a9c util: add common ARRAY_SIZE define
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>
2013-05-24 18:20:53 +10:00
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
03449b84c8 dtc/fdt{get, put}/convert-dtsv0-lexer: convert to new usage helpers
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>
2013-05-24 18:20:53 +10:00
David Gibson
341df2bdc3 dtc: Add -Wredundant-decls (resend)
We are almost clean already with the -Wredundant-decls warning.  The
only exception is a declaration for isatty() inside the flex-generated
code.  This can be removed by using flex's "never-interactive" option,
which we probably should be using anyway, since we never parse
interactively in the sense that this option implies.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-04-30 08:36:47 -05: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
b2b4990bbf dtc: Move some functions to util.[ch]
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>
2009-01-07 09:46:04 -06:00
David Gibson
2f766233c2 dtc: Use noinput flex option for convert-dtsv0 to remove warning
The convert-dtsv0 lexer doesn't use lex's input() macro/function.
This can result in "defined but not used" warnings.  This patch uses
flex's noinput option to prevent this warning (as we already do for
dtc-lexer.l).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-11-17 14:05:24 -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
David Gibson
76e0622b68 dtc: Clean up lexing of include files
Currently we scan the /include/ directive as two tokens, the
"/include/" keyword itself, then the string giving the file name to
include.  We use a special scanner state to keep the two linked
together, and use the scanner state stack to keep track of the
original state while we're parsing the two /include/ tokens.

This does mean that we need to enable the 'stack' option in flex,
which results in a not-easily-suppressed warning from the flex
boilerplate code.  This is mildly irritating.

However, this two-token scanning of the /include/ directive also has
some extremely strange edge cases, because there are a variety of
tokens recognized in all scanner states, including INCLUDE.  For
example the following strange dts file:

	/include/ /dts-v1/;
	/ {
		 /* ... */
	};

Will be processed successfully with the /include/ being effectively
ignored: the '/dts-v1/' and ';' are recognized even in INCLUDE state,
then the ';' transitions us to PROPNODENAME state, throwing away
INCLUDE, and the previous state is never popped off the stack.  Or
for another example this construct:
	foo /include/ = "somefile.dts"
will be parsed as though it were:
	foo = /include/ "somefile.dts"
Again, the '=' is scanned without leaving INCLUDE state, then the next
string triggers the include logic.

And finally, we use a different regexp for the string with the
included filename than the normal string regexpt, which is also
potentially weird.

This patch, therefore, cleans up the lexical handling of the /include/
directive.  Instead of the INCLUDE state, we instead scan the whole
include directive, both keyword and filename as a single token.  This
does mean a bit more complexity in extracting the filename out of
yytext, but I think it's worth it to avoid the strageness described
above.  It also means it's no longer possible to put a comment between
the /include/ and the filename, but I'm really not very worried about
breaking files using such a strange construct.
2008-07-14 12:21:24 -05:00
David Gibson
cdcb415851 dtc: Address an assortment of portability problems
I've recently worked with a FreeBSD developer, getting dtc and libfdt
working on FreeBSD.  This showed up a number of portability problems
in the dtc package which this patch addresses.  Changes are as
follows:

	- the parent_offset and supernode_atdepth_offset testcases
used the glibc extension functions strchrnul() and strndupa().  Those
are removed, using slightly longer coding with standard C functions
instead.

	- some other testcases had a #define _GNU_SOURCE for no
particular reason.  This is removed.

	- run_tests.sh has bash specific constructs removed, and the
interpreter changed to /bin/sh.  This apparently now runs fine on
FreeBSD's /bin/sh, and I've also tested it with both ash and dash.

	- convert-dtsv0-lexer.l has some extra #includes added.  These
must have been included indirectly with Linux and glibc, but aren't on
FreeBSD.

	- the endian handling functions in libfdt_env.h, based on
endian.h and byteswap.h are replaced with some portable open-coded
versions.  Unfortunately, these result in fairly crappy code when
compiled, but as far as I can determine there doesn't seem to be any
POSIX, SUS or de facto standard way of determining endianness at
compile time, nor standard names for byteswapping functions.

	- some more endian handling, from testdata.h using the
problematic endian.h is simply removed, since it wasn't actually being
used anyway.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:21:18 -05:00
David Gibson
a84c065f44 dtc: Add program to convert dts files from v0 to v1
This patch adds a new utility program, convert-dtsv0, to the dtc
sources.  This program will convert dts files from v0 to v1,
preserving comments and spacing.  It also includes some heuristics to
guess an appropriate base to use in the v1 output (so it will use hex
for the contents of reg properties and decimal for clock-frequency
properties, for example).  They're limited and imperfect, but not
terrible.

The guts of the converter program is a modified version of the lexer
from dtc itself.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-05-19 21:18:47 -05:00