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>
Provide the new command-line option:
--annotate (abbreviated -T)
--annotate provides one or more filenames and line numbers indicating
the origin of a given line. The filename is expressed relative the the
filename provided on the command line. Nothing is printed for overlays,
etc.
-T can be repeated giving more verbose annotations. These consist of
one or more tuples of: filename, starting line, starting column, ending
line ending column. The full path is given for the file name.
Overlays, etc are annotated with <no-file>:<no-line>.
The verbose annotations may be too verbose for normal use.
There are numerous changes in srcpos.c to provide the relative filenames
(variables initial_path, initial_pathlen and initial_cpp, new functions
set_initial_path and shorten_to_initial_path, and changes in
srcfile_push and srcpos_set_line). The change in srcpos_set_line takes
care of the case where cpp is used as a preprocessor. In that case the
initial file name is not the one provided on the command line but the
one found at the beginnning of the cpp output.
shorten_to_initial_path only returns a string if it has some shortening
to do. Otherwise it returns NULL and relies on the caller to use the
initial string. This simplifies memory management, by making clear to
the caller whether a new string is allocated.
The new functions srcpos_string_comment, srcpos_string_first, and
srcpos_string_last print the annotations. srcpos_string_comment is
recursive to print a list of source file positions.
Various changes are sprinkled throughout treesource.c to print the
annotations.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
YAML encoded DT is useful for validation of DTs using binding schemas.
The YAML encoding is an intermediate format used for validation and
is therefore subject to change as needed. The YAML output is dependent
on DTS input with type information preserved.
Signed-off-by: Grant Likely <grant.likely@arm.com>
[robh: make YAML support optional, build fixes, Travis CI test,
preserve type information in paths and phandles]
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Right now, check_interrupts_property fails with overlays, as the phandle
for the interrupt-parent can be orphan. Avoid this by allowing the orphan
node to pass the assert check.
The process_checks() call is also moved later during init sequence,
so that we can use the global variable generate_fixups to check if
we are compiling an overlay.
Signed-off-by: Tero Kristo <t-kristo@ti.com>
[dwg: Shortcut handling of invalid phandles]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The FDT_VERSION() and _FDT_VERSION() macros don't really have anything
specific to do with the fdt version. Rather, they're the common CPP
"stringify" idiom. Move to util.h and rename to stringify() to
reflect this.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Currently, both legacy (linux,phandle) and ePAPR (phandle) properties
are inserted into dtbs by default. The newer ePAPR style has been
supported in dtc and Linux kernel for 7 years. That should be a long
enough transition period. We can save a little space by not putting both
into the dtb.
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
Fix two places where a printf()-style format string does not match the
arguments passed.
Reported-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
For example:
src/arm/at91-ariag25.dtb: Warning (unit_address_vs_reg): Node /memory has a reg or ranges property, but no unit name
If output is to stdout then the prefix is "<stdout>: ".
This helps to direct the developer to where to look when multiple files are
being compiled in parallel.
Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
At the moment we generate a __symbols__ node if -@ is specified OR if the
dts has the /plugin/ tag. That difference in behaviour from handling base
trees is unnecessary and slightly confusing. It also means it's impossible
to create a plugin without symbols. Since symbols in a plugin are only
useful in the case of stacked plugins - and libfdt doesn't even support
merging plugin symbols as part of overlay application yet - that's a thing
that might be useful.
So make __symbols__ generation depend only on -@. We also remove remove
the testcases that checked explicitly for this not very useful behaviour.
Instead we don't use -@ for our basic overlay testcase, and check that
symbols are not generated.
At some point in the future we should add support for symbol merging to
libfdt and add testcases for stacked overlay application.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This patch enable the generation of symbols & local fixup information
for trees compiled with the -@ (--symbols) option.
Using this patch labels in the tree and their users emit information
in __symbols__ and __local_fixups__ nodes.
The __fixups__ node make possible the dynamic resolution of phandle
references which are present in the plugin tree but lie in the
tree that are applying the overlay against.
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
There is one condition that need cat the dtb files
into one dtb.img which can support several boards
use same SoC platform.
And the original dtb file size is not aligned to any base.
This may cause "Synchronous Abort" when load from a unligned
address on some SoC machine, such as ARM.
So this patch implement the -a <aligned number> option to
pad zero at the end of dtb files and make the dtb size aligned
to <aligned number>.
Then, the aligned dtbs can cat together and load without "Synchronous
Abort".
Signed-off-by: Tim Wang <timwang@asrmicro.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
If no output file type is specified via the -O parameter, guess the
desired file type by looking at the file name extension.
If that provides no useful hints, assume "dtb" as long as the input
type is "dts". Any other input type will lead to "dts" being used as
the guessed output type.
Any explicit specification of the output type will skip this guessing.
Signed-off-by: Andre Przywara <osp@andrep.de>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Always needing to specify the input file format can be quite
annoying, especially since a dtb is easily detected by its magic.
Looking at the file name extension sounds useful as a hint, too.
Add heuristic file type guessing of the input file format in case
none has been specified on the command line.
The heuristics are as follows (in that order):
- Any issues with opening the file drop back to the current default
behaviour.
- A directory will be treated as the /proc/device-tree type.
- If the first 4 bytes are the DTB magic, assume "dtb".
- If no other test succeeded so far, use a file name based
guessing method: if the filename ends with .dts or .DTS, device tree
source text is assumed, .dtb or .DTB hint at a device tree blob.
For the majority of practical use cases this gets rid of the tedious
-I specification on the command line and simplifies actual typing of
dtc command lines.
Any explicit specification of the input type by using -I still avoids
any guessing, which resembles the current behaviour.
Signed-off-by: Andre Przywara <osp@andrep.de>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
if #define DEFAULT_FDT_VERSION 17
The message
Blob version to produce, defaults to %d (for dtb and asm output)
should be
Blob version to produce, defaults to 17 (for dtb and asm output)
This patch fix it, and delete the redundant 't'.
Signed-off-by: Wang Long <long.wanglong@huawei.com>
The "b" flag to fopen() is generally a no-op on Unix-like systems, but may
be important on other systems, including Windows.
Signed-off-by: Andrei Errapart <andrei@errapartengineering.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
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>
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>
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>
The 'deprecated' warning is in there for more than 4 years now
and nobody seemed to be confused enough to vote it out. Let's
drop the warning then.
This reverts commit 315c5d095e.
Signed-off-by: Horst Kronstorfer <hkronsto@frequentis.com>
This patch adds -W and -E options to dtc which allow toggling on and off
of the various built in semantic checks on the tree.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Outputing to stderr is best avoided unless there is an error or warning to
display. At present dtc always displays the name of the file it is compiling
and the input/output formats. For example:
DTC: dts->dts on file "-"
This can cause problems in some build systems. For example, U-Boot shows
build errors for any boards which use dtc at present. It is typically the
only message output during such a build. The C compiler does not output
anything in general. The current dtc behaviour makes it difficult to
provide a silent build in the normal case where nothing went wrong.
Remove the message entirely.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
It is often inconvenient to place device tree files in the same directory
as their includes, or to specify the full path to include files.
An example of this is in U-Boot where we have a .dtsi file for each SOC
type, and this is included by the board .dts file. We need to either use
a mechanism like:
/include/ ARCH_CPU_DTS
with sed or cpp to perform the replacement with the correct path, or
we must specify the full path in the file:
/include/ "../../arch/arm/dts/tegra20.dtsi"
The first option is not desirable since it requires anyone compiling the
file to first pre-process it. The second is not desirable since it
introduces a path which is project-specific into a file which is supposed
to be a hardware description. For example Linux and U-Boot are unlikely to
put these include files in the same place.
It is much more convenient to specify the search patch on the command line
as is done with C pre-processors, for example.
Introduce a -i option to add to the list of search paths used to find
source and include files.
We cannot use -I as it is already in use. Other suggestions welcome.
Signed-off-by: Simon Glass <sjg@chromium.org>
This will allow callers to rebuild .dtb files when any of the /include/d
.dtsi files are modified, not just the top-level .dts file.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Commit 376ab6f2 removed the old style check functionality from DTC,
however the check option and variable were not removed. This leads to
build failures when -Werror=unused-but-set-variable is specified:
dtc.c: In function 'main':
dtc.c:102:17: error: variable 'check' set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
make: *** [dtc.o] Error 1
make: *** Waiting for unfinished jobs....
Remove the check variable.
Signed-off-by: Josh Boyer <jwboyer@linux.vnet.ibm.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
This patch adds a "dtdiff" script to do a useful form diff of two
device trees. This automatically converts the tree to dts form (if
it's not already) and uses a new "-s" option in dtc to "sort" the
tree. That is, it sorts the reserve entries, it sorts the properties
within each node by name, and it sorts nodes by name within their
parent.
This gives a pretty sensible diff between the trees, which will ignore
semantically null internal rearrangements (directly diffing the dts
files can give a lot of noise due to the order changes).
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
Currently, the Linux kernel, libfdt and dtc, when using flattened
device trees encode a node's phandle into a property named
"linux,phandle". The ePAPR specification, however - aiming as it is
to not be a Linux specific spec - requires that phandles be encoded in
a property named simply "phandle".
This patch adds support for this newer approach to dtc and libfdt.
Specifically:
- fdt_get_phandle() will now return the correct phandle if it
is supplied in either of these properties
- fdt_node_offset_by_phandle() will correctly find a node with
the given phandle encoded in either property.
- By default, when auto-generating phandles, dtc will encode
it into both properties for maximum compatibility. A new -H
option allows either only old-style or only new-style
properties to be generated.
- If phandle properties are explicitly supplied in the dts
file, dtc will not auto-generate ones in the alternate format.
- If both properties are supplied, dtc will check that they
have the same value.
- Some existing testcases are updated to use a mix of old and
new-style phandles, partially testing the changes.
- A new phandle_format test further tests the libfdt support,
and the -H option.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The "-S" option allowed the specification of a minimum size for
the blob, however the main reason for caring about the size is
so there is enough padding to add a chosen node by u-boot or
whoever. In which case, folks don't really care about the absolute
size, but rather the size of the padding added for this -- which
is what the "-p" option does. Having the "-S" just confuses people.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Currently, dtc will put the nonsense value 0xfeedbeef into the
boot_cpuid_phys field of an output blob, unless explicitly given
another value with the -b command line option. As well as being a
totally unuseful default value, this also means that dtc won't
properly preserve the boot_cpuid_phys field in -I dtb -O dtb mode.
This patch reworks things to improve the boot_cpuid handling. The new
semantics are that the output's boot_cpuid_phys value is:
the value given on the command line if -b is used
otherwise
the value from the input, if in -I dtb mode
otherwise
0
Implementation-wise we do the following:
- boot_cpuid_phys is added to struct boot_info, so that
structure now contains all of the blob's semantic information.
- dt_to_blob() and dt_to_asm() output the cpuid given in
boot_info
- dt_from_blob() fills in boot_info based on the input blob
- The other dt_from_*() functions just record 0, but we can
change this easily if e.g. we invent a way of specifying the boot cpu
in the source format.
- main() overrides the cpuid in the boot_info between input
and output if -b is given
We add some testcases to check this new behaviour.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Currently, main() has a variable for the input file. It used to be
that main() would open the input based on command line arguments
before passing it to the dt_from_*() function. However, only
dt_from_blob() uses this. dt_from_source() opens its own file, and
dt_from_fs() interprets the argument as as a directory and does its
own opendir() call.
Furthermore, main() opened the file with dtc_open_file() but closed it
with a direct call to fclose().
Therefore, to improve the interface consistency between the
dt_from_*() functions, make dt_from_blob() open and close its own
files like the other dt_from_*() functions.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
If dtc's command line arguments are invalid, it prints a usage message
and returns exit code 2. That's the same exit code as for a failed
check, which is potentially confusing if running dtc from an automated
harness. Therefore this patch changes the usage exit code to 3.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
All current callers of dtc_open_file() immediately die() if it returns
an error. In a non-interative tool like dtc, it's hard to see what
you could sensibly do to recover from a failure to open an input file
in any case.
Therefore, make dtc_open_file() itself die() if there's an error
opening the requested file. This removes the need for error checking
at the callsites, and ensures a consistent error message in all cases.
While we're at it, change the rror message from fstree.c when we fail
to open the input directory to match dtc_open_file()'s error message.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
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>
Looking in the diretory dtc is invoked from is not very useful behavior.
As part of the code reorganization to implement this, I removed the
uniquifying of name storage -- it seemed a rather dubious optimization
given likely usage, and some aspects of it would have been mildly awkward
to integrate with the new code.
Signed-off-by: Scott Wood <scottwood@freescale.com>
The remaining old-style tree checking code: check_root(), check_cpus()
and check_memory() really aren't that useful. They mostly check for
the presence of particular nodes and properties. That's inherently
prone to false-positives, because we could be dealing with an
artificial tree (like many of the testcases) or it could be expected
that the missing properties are filled in by a bootloader or other
agent.
If any of these checks really turns out to be useful, we can
reimplement them later in a better conceived way on top of the new
checking infrastructure. For now, just get rid of them, removing the
last vestiges of the old-style checking code (hoorah).
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
My rework of the tree checking code introduced a potentially nasty bug
- it uses the structure_ok variable uninitialized. This patch fixes
the problem. It's a fairly ugly bandaid approach, but the ugly will
disappear once future patches have folded the semantic checks into the
new framework.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
There are times when we need extra space in the blob and just want
to have it added on w/o know the exact size to make it.
The padding and min size options are mutually exclusive.
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
dtc: Flexible tree checking infrastructure
Here, at last, is a substantial start on revising dtc's infrastructure
for checking the tree; this is the rework I've been saying was
necessary practically since dtc was first release.
In the new model, we have a table of "check" structures, each with a
name, references to checking functions, and status variables. Each
check can (in principle) be individually switched off or on (as either
a warning or error). Checks have a list of prerequisites, so if
checks need to rely on results from earlier checks to make sense (or
even to avoid crashing) they just need to list the relevant other
checks there.
For now, only the "structural" checks and the fixups for phandle
references are converted to the new mechanism. The rather more
involved semantic checks (which is where this new mechanism will
really be useful) will have to be converted in future patches.
At present, there's no user interface for turning on/off the checks -
the -f option now forces output even if "error" level checks fail.
Again, future patches will be needed to add the fine-grained control,
but that should be quite straightforward with the infrastructure
implemented here.
Also adds a testcase for the handling of bad references, which catches
a bug encountered while developing this patch.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This patch adds a group of testcases to check that dtc correctly
rejects trees with various structural errors.
To make things easier to test, we change dtc so that failing checks
(as opposed to other errors) result in exit code 2.
This patch also fixes an embarrasing bug uncovered by these new tests:
check_phandles() worked out if the tree's phandles were valid, then
throws that information away and returns success always.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
At present, dtc makes a lot of semantic checks on the device tree by
default, and will refuse to produce output if they fail. This means
people tend to need -f to force output despite failing semantic checks
rather a lot.
This patch splits the device tree checks into structural checks (no
bad or duplicate names or phandles) and semantic checks (everything
else). By default, only the structural checks are performed, and are
fatal. -f will force output even with structural errors (using this
in -Idts mode would essentially always be a bad idea, but it might be
useful in -Idtb mode for examining a malformed dtb).
Semantic checks are only performed if the new -c command line option
is supplied, and are always warnings only. Semantic checks will never
be performed on a tree with structural errors.
This patch is only a stopgap before implementing proper fine-grained
error/warning handling, but it should at least get rid of the
far-too-frequent need for -f for the time being.
This patch removes the -f from the dtc testcases now that it's no
longer necessary.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
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>
This patch turns on optimisation in the Makefile by default. With the
optimizer on, some uninitialized variable warnings (one real, two
bogus) are now generated. This patch also squashes those again.