aboutsummaryrefslogtreecommitdiff
path: root/livetree.c
AgeCommit message (Collapse)AuthorFilesLines
2017-10-27livetree: avoid assertion of orphan phandles with overlaysTero Kristo1-1/+4
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>
2017-09-28overlay: Add syntactic sugar version of overlaysPantelis Antoniou1-0/+22
For simple overlays that use a single target there exists a simpler syntax version. &foo { }; generates an overlay with a single target at foo. Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-09-22checks: add phandle with arg property checksRob Herring1-0/+6
Many common bindings follow the same pattern of client properties containing a phandle and N arg cells where N is defined in the provider with a '#<specifier>-cells' property such as: intc0: interrupt-controller@0 { #interrupt-cells = <3>; }; intc1: interrupt-controller@1 { #interrupt-cells = <2>; }; node { interrupts-extended = <&intc0 1 2 3>, <&intc1 4 5>; }; Add checks for properties following this pattern. Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-19Fix get_node_by_path string equality checkTim Montague1-1/+2
When determining if to recurse into a node, get_node_by_path does not check if the length of each node name is equal. If searching for /foo/baz, this can result in recursing into /foobar because strneq("foo", "foobar", 3) is true. This can result in a reference to /foo/baz to be incorrectly set to /foobar/baz. A test for this was added. Signed-off-by: Tim Montague <tmontague@ghs.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-06Fix assorted sparse warningsDavid Gibson1-2/+2
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-06dtc: Don't abuse struct fdt_reserve_entryDavid Gibson1-6/+6
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-02-13dtc: Use streq() in preference to strcmp()David Gibson1-2/+2
dtc defines a streq() (string equality) macro to avoid the easy confusion of the sense of strcmp() comparison for equality. A few places where we don't use it have slipped in, so remove them. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-08livetree.c: Fix memory leakJean-Christophe Dubois1-0/+2
When running coverity on dtc source code the following error is reported. ========================================================================== *** CID 1370967: Resource leaks (RESOURCE_LEAK) /tools/dtc/livetree.c: 850 in add_fixup_entry() 844 if (strchr(node->fullpath, ':') || strchr(prop->name, ':')) 845 die("arguments should not contain ':'\n"); 846 847 xasprintf(&entry, "%s:%s:%u", 848 node->fullpath, prop->name, m->offset); 849 append_to_property(fn, m->ref, entry, strlen(entry) + 1); >>> CID 1370967: Resource leaks (RESOURCE_LEAK) >>> Variable "entry" going out of scope leaks the storage it points to. 850 } ========================================================================== Fix the leak. Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09Rename boot_infoDavid Gibson1-50/+50
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-09dtc: Plugin and fixup supportPantelis Antoniou1-1/+268
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>
2016-09-27Fix some typing errors in libfdt.h and livetree.cThomas Huth1-1/+1
Correct some typos discovered with the codespell utility. Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-05-09Fix bug with references to root nodeDavid Gibson1-1/+3
At present, the lexer token for references to a path doesn't permit a reference to the root node &{/}. Fixing the lexer exposes another bug handling this case. This patch fixes both bugs and adds testcases. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-09-28dtc: zero out new label objectsStephen Warren1-0/+1
Without this, new->deleted may be left set to some random value, which may then cause future label references to fail to locate the label. The code that allocates properties and nodes already contains the equivalent memset(). Signed-off-by: Stephen Warren <swarren@nvidia.com>
2012-09-06dtc: Add ability to delete nodes and propertiesStephen Warren1-13/+112
dtc currently allows the contents of properties to be changed, and the contents of nodes to be added to. There are situations where removing properties or nodes may be useful. This change implements the following syntax to do that: / { /delete-property/ propname; /delete-node/ nodename; }; or: /delete-node/ &noderef; Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2010-11-13dtc: Add code to make diffing trees easierDavid Gibson1-0/+137
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>
2010-02-25Allow device tree to be modified by additonal device tree sectionsGrant Likely1-1/+74
This patch allows the following construct: / { property-a = "old"; property-b = "does not change"; }; / { property-a = "changed"; property-c = "new"; node-a { }; }; Where the later device tree overrides the properties found in the earlier tree. This is useful for laying down a template device tree in an include file and modifying it for a specific board without having to clone the entire tree. Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
2010-02-24dtc: Allow multiple labels on nodes and propertiesDavid Gibson1-22/+27
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-23Disallow re-use of the same label within a dts fileDavid Gibson1-0/+51
Currently, nothing will stop you from re-using the same label string multiple times in a dts, e.g.: / { samelabel: prop1 = "foo"; samelabel: prop2 = "bar"; }; or / { samelabel: prop1 = "foo"; samelabel: subnode { }; }; When using node references by label, this could lead to confusing results (with no warning), and in -Oasm mode will result in output which the assembler will complain about (since it too will have duplicate labels). This patch, therefore, adds code to checks.c to give errors if you attempt to re-use the same label. It treats all labels (node, property, and value) as residing in the same namespace, since the assembler will treat them so for -Oasm mode. Testcases for the new code are also added. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-02-19dtc: Automatically pick a sensible boot_cpuid_physDavid Gibson1-0/+23
Currently, when in -Idts -Odtb or -Ifs -Odtb modes, dtc always defaults to using 0 as the value for the boot_cpuid_phys header field. That's correct quite often, but there are some systems where there is no CPU with hardware ID of 0, or where we don't want to use the CPU with hardware ID 0 at all (e.g. for AMP-style partitioning). The only way to override this default currently, is with the -b command line option. This patch improves dtc to instead base the default boot_cpuid_phys value on the reg property of the first listed subnode of /cpus. This means that dtc will get boot_cpuid_phys correct by default in a greater proportion of cases (since the boot cpu is usually listed first, and this way at least the boot_cpuid_phys default will match some existing cpu node). If the node doesn't exist or has an invalid 'reg' property (missing or not 4 bytes in length), then boot_cpuid_phys is set to 0. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2009-11-26Support ePAPR compliant phandle propertiesDavid Gibson1-2/+12
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>
2008-11-17dtc: Handle linux,phandle properties which self-referenceDavid Gibson1-6/+8
Currently, dtc will generate phandles for nodes which are referenced elsewhere in the tree. phandles can also be explicitly assigned by defining the linux,phandle property. However, there is no way, currently to tell dtc to generate a phandle for a node if it is not referenced elsewhere. This is inconvenient when it's expected that later processing on the flat tree might add nodes which _will_ the node in question. One way one might attempt to do this is with the construct: mynode: mynode { linux,phandle = <&mynode>; /* ... */ }; Though it's a trifle odd, there's really only one sensible meaning which can be assigned to this construct: allocate a unique phandle to "mynode" and put that in its linux,phandle property (as always). Currently, however, dtc will choke on this self-reference. This patch corrects this, making the construct above give the expected results. It also ensures a more meaningful error message is given if you attempt to process the nonsensical construct: mynode: mynode { linux,phandle = <&someothernode>; /* ... */ }; The 'references' testcase is extended to cover this case, as well. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14dtc: Run relevant checks on dtb input as well as dtsDavid Gibson1-0/+1
This patch adjusts the testsuite to run most of the tests for the tree checking code on input in dtb form as well as dts form. Some checks which only make sense for dts input (like reference handling) are excluded, as are those which currently take dtb input because they rely on things which cannot be lexically constructed in a dts file. This shows up two small bugs in dtc, which are also corrected. First, the name_properties test which was is supposed to remove correctly formed 'name' properties (because they can be reconstructed from tne node name) was instead removing 'name' properties even if they weren't correct. Secondly, when using dtb or fs input, the runtime tree in dtc did not have the parent pointer initialized propertly because.built internally. The appropriate initialization is added to the add_child() function. 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-07-14dtc: Use stdint.h types throughout dtcDavid Gibson1-2/+3
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>
2008-05-19dtc: Rework handling of boot_cpuid_physDavid Gibson1-1/+2
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>
2008-05-19dtc: Simplify error handling for unparseable inputDavid Gibson1-1/+0
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-01-04Return a non-zero exit code if an error occurs during dts parsing.Scott Wood1-0/+1
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>
2007-12-04dtc: Add many const qualificationsDavid Gibson1-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>
2007-11-26dtc: Flexible tree checking infrastructure (v2)David Gibson1-56/+11
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>
2007-11-01dtc: Move tree checking code to checks.cDavid Gibson1-444/+5
This patch moves the dtc code for checking the device tree its processing into a new checks.c. The tree accessor functions from livetree.c which the checks use are exported and added to dtc.h. Another small step towards a flexible checking architecture. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-25DTC: Remove the need for the GLR Parser.Jon Loeliger1-1/+16
Previously, there were a few shift/reduce and reduce/reduce errors in the grammar that were being handled by the not-so-popular GLR Parser technique. Flip a right-recursive stack-abusing rule into a left-recursive stack-friendly rule and clear up three messes in one shot: No more conflicts, no need for the GLR parser, and friendlier stackness. Compensate by reversing the property list on the node. Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-10-22dtc: Disable semantic checks by defaultDavid Gibson1-183/+187
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>
2007-09-18dtc: Whitespace cleanupDavid Gibson1-14/+13
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-26Remove bogus errors from check_chosen.Scott Wood1-7/+2
It is not an error for /chosen (or any of its children) to be missing. It is not a requirement that the output of dtc be a complete, valid device tree, as it may be intended that the dtb be passed through boot code that will complete it. Thus, do not complain. Signed-off-by: Scott Wood <scottwood@freescale.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2007-03-19Improve options, #define default version.Jerry Van Baren1-4/+5
Add -h option for help Add -q quiet option to reduce or suppress the whining Create #define for the default version value. Signed-off-by: vanbaren@cideas.com <vanbaren@cideas.com>
2007-02-20remove check for interrupt-controller property under /chosenStuart Yoder1-2/+9
Remove warning for missing interrupt-controller property under /chosen. There is consensus that this property does not belong here. Also, add a warning if interrupt-controller _is_ found under /chosen. Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com> Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-02-08Allow references to labelsDavid Gibson1-3/+29
dtc allows nodes to have labels, which at present are just re-emitted as symbols at the appropriate places when using asm-mode output. It also allows "references" where the notation &/path/to/node in a cell list will be replaced with the phandle of the referenced node. This patch extends the reference syntax to allow references to labels instead of just full device paths. This allows nodes deep within the tree to be referenced with a shorter more convenient name. References to labels are distinguished from reference to paths by the fact that paths must start with a /, but labels can never start with a /. Signed-off-by: David Gibson <dwg@au1.ibm.com> Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-01-31Bugfix for CHECK_HAVE_WARN_PHANDLE()David Gibson1-3/+8
At present, the tree checking code in dtc will die with an assertion failure if given a tree which has the invalid value 0 or -1 in a property which should contain a phandle. This patch fixes the check to die more gracefully with an error message indicating the invalid phandle value. Signed-off-by: David Gibson <dwg@au1.ibm.com>
2007-01-29Remove check for linux,platform property in /chosenDavid Gibson1-2/+0
The linux,platform property in /chosen was obsolete almost as soon as it was invented. Remove the check for it from dtc, which just tends to lead to irritating spurious failures. Signed-off-by: David Gibson <dwg@au1.ibm.com>
2006-12-11dtc: Remove verbose message from get_node_phandle()David Gibson1-3/+0
get_node_phandle() had a leftover debugging printf(), which could muddy dtc's output when checking trees. This patch removes it.
2006-06-07dtc: add setting of physical boot cpuMichael Neuling1-5/+12
dtc always sets the physical boot CPU to 0xfeedbeef. Add a -b option to set this. Also add warnings when using the wrong property with the wrong blob version. Signed-off-by: Michael Neuling <mikey@neuling.org>
2005-10-24Rework tracking of reserve entries during processing. This is initial workDavid Gibson1-2/+42
to allow more powerful handling of reserve entries.
2005-10-21Alter add_property() and add_child() functiosn to add to the end of theirDavid Gibson1-2/+18
respective linked lists. This means we no longer reverse the order or properties and subnodes when in blob or fs input modes.
2005-10-20Reduce message about too-long property names to a mere warning, it causesDavid Gibson1-2/+2
too much trouble. Still need to fix up error handling in general.
2005-08-29Remove an unused function, mark a bunch of other functions and variablesDavid Gibson1-3/+3
as static. Mostly found by sparse.
2005-07-15Support for specifying memreserve ranges in the source format, based onDavid Gibson1-0/+12
a patch by Jon Loeliger <jdl AT freescale.com>, although tweaked substantially.
2005-06-17Remove build_empty_property(). It wasn't useful.David Gibson1-13/+0
2005-06-16Rudimentary phandle reference support.David Gibson1-7/+90
2005-06-16Initial label support. Also switch to glr-parser mode and get rid ofDavid Gibson1-3/+10
hacks that were necessary without it.
2005-06-08Initial commitDavid Gibson1-0/+590