aboutsummaryrefslogtreecommitdiff
path: root/livetree.c
AgeCommit message (Collapse)AuthorFilesLines
2023-03-01livetree: fix leak spotted by ASANMarc-André Lureau1-11/+18
./dtc -I dts -O dtb -o overlay_base_manual_symbols.test.dtb /home/elmarco/src/dtc/tests/overlay_base_manual_symbols.dts ../data.c:109:2: runtime error: null pointer passed as argument 2, which is declared to never be null ================================================================= ==933317==ERROR: LeakSanitizer: detected memory leaks Direct leak of 24 byte(s) in 1 object(s) allocated from: #0 0x7f49a2aba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af) #1 0x43183d in xmalloc ../util.h:45 #2 0x43482f in data_add_marker ../data.c:230 #3 0x449bb8 in get_node_phandle ../livetree.c:632 #4 0x421058 in fixup_phandle_references ../checks.c:627 #5 0x41b0ba in check_nodes_props ../checks.c:141 #6 0x41b1c8 in check_nodes_props ../checks.c:144 #7 0x41b9f1 in run_check ../checks.c:181 #8 0x430a68 in process_checks ../checks.c:2057 #9 0x436abd in main ../dtc.c:327 #10 0x7f49a30d850f in __libc_start_call_main (/lib64/libc.so.6+0x2750f) Only create data when necessary, and do not alias it. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> [dwg: Small fixup for a slightly different approach to adjacent cleanups] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01Make name_node() xstrdup its name argumentDavid Gibson1-8/+9
The name field of 'struct node' was really always supposed to be a malloc()ed string, that is owned by the structure. To avoid an extra strdup() for strings coming up from the lexer, name_node() expects to take uch an already malloc()ed string, which means it's not correct to pass it a static string literal. That's a pretty non-obvious constraint, so a bunch of incorrect uses have crept in. Really, avoiding the extra dup from the lexer isn't a big enough benefit for this demonstrably dangerous interface. So change it to do the xstrdup() itself, removing the burden from callers. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01Make build_property() xstrdup its name argumentDavid Gibson1-4/+4
The name field of 'struct property' was really always supposed to be a malloc()ed string, that is owned by the structure. To avoid an extra strdup() for strings coming up from the lexer, build_property() and build_property_delete() expect to take such an already malloc()ed string, which means it's not correct to pass it a static string literal. That's a pretty non-obvious constraint, so a bunch of incorrect uses have crept in. Really, avoiding the extra dup from the lexer isn't a big enough benefit for this demonstrably dangerous interface. So change it to do the xstrdup() itself, removing the burden from callers. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-31Don't generate erroneous fixups from reference to pathDavid Gibson1-0/+6
The dtb overlay format only permits (non local) fixups to reference labels, not paths. That's because the fixup target goes into the property name in the overlay, and property names aren't permitted to include '/' characters. Stop erroneously generating such fixups, because we didn't check for this case. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-01-25dtc: introduce label relative path referencesAhmad Fatoum1-3/+30
Reference via label allows extending nodes with compile-time checking of whether the node being extended exists. This is useful to catch renamed/removed nodes after an update of the device trees to be extended. In absence of labels in the original device trees, new style path references can be used: /* upstream device tree */ / { leds: some-non-standard-led-controller-name { led-0 { default-state = "off"; }; }; }; /* downstream device tree */ &{/some-non-standard-led-controller-name/led-0} { default-state = "on"; }; This is a common theme within the barebox bootloader[0], which extends the upstream (Linux) device trees in that manner. The downside is that, especially for deep nodes, these references can get quite long and tend to break often due to upstream rework (e.g. rename to adhere to bindings). Often there is a label a level or two higher that could be used. This patch allows combining both a label and a new style path reference to get a compile-time-checked reference, which allows rewriting the previous downstream device tree snippet to: &{leds/led-0} { default-state = "on"; }; This won't be broken when /some-non-standard-led-controller-name is renamed or moved while keeping the label. And if led-0 is renamed, we will get the expected compile-time error. Overlay support is skipped for now as they require special support: The label and relative path parts need to be resolved at overlay apply-time, not at compile-time. [0]: https://www.barebox.org/doc/latest/devicetree/index.html Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
2021-06-21dtc: Wrap phandle validity checkAndre Przywara1-2/+2
In several places we check for a returned phandle value to be valid, for that it must not be 0 or "-1". Wrap this check in a static inline function in dtc.h, and use ~0U instead of -1 on the way, to keep everything in the unsigned realm. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210618172030.9684-4-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-15dtc: Fix signedness comparisons warnings: pointer diffAndre Przywara1-1/+1
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in the function get_node_by_path(). Taking the difference between two pointers results in a signed ptrdiff_t type, which mismatches the unsigned type returned by strlen(). Since "p" has been returned by a call to strchr() with "path" as its argument, we know for sure that it's bigger than "path", so the difference must be positive. So a cast to an unsigned type is valid. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210611171040.25524-7-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-13dtc: Fix signedness comparisons warnings: change typesAndre Przywara1-1/+1
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in various parts of dtc. Many variables are using signed types unnecessarily, as we never use negative value in them. Change their types to be unsigned, to prevent issues with comparisons. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201012161948.23994-7-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-08-28livetree: simplify condition in get_node_by_pathDenis Efremov1-2/+1
The "strlen && strprefixeq" check in get_node_by_path is excessive, since strlen is checked in strprefixeq macro internally. Thus, "strlen(child->name) == p-path" conjunct duplicates after macro expansion and could be removed. Signed-off-by: Denis Efremov <efremov@linux.com> Message-Id: <20190827204148.20604-1-efremov@linux.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-06-21dtc: Replace GPLv2 boilerplate/reference with SPDX tagsRob Herring1-16/+1
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-12livetree: add missing type markers in generated overlay propertiesRob Herring1-7/+11
The YAML output fails for overlays and when symbol generation are enabled due to missing markers in the generated properties. Add type markers when generating properties under '__symbols__' and '__fixups__' nodes as well as target-path properties. As a side effect of append_to_property() changes, this also sets type markers in '__local_fixups__' node properties. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20190517202804.9084-1-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-05-21Fix typos in various documentation and source filesThomas Huth1-1/+1
The typos have been discovered with the "codespell" utility. Signed-off-by: Thomas Huth <thuth@redhat.com> Message-Id: <20190520081209.20415-1-thuth@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-19annotations: add positionsJulia Lawall1-11/+22
Extend the parser to record positions, in build_node, build_node_delete, and build_property. srcpos structures are added to the property and node types, and to the parameter lists of the above functions that construct these types. Nodes and properties that are created by the compiler rather than from parsing source code have NULL as the srcpos value. merge_nodes, defined in livetree.c, uses srcpos_extend to combine multiple positions, resulting in a list of positions. srcpos_extend is defined in srcpos.c. New elements are added at the end. This requires the srcpos type, define in srcpos.h, to be a list structure with a next field. This next field is initialized to NULL in srcpos.h, in the macro YYLLOC_DEFAULT invoked implicitly by the generated parser code. Another change to srcpos.c is to make srcpos_copy always do a full copy, including a copy of the file substructure. This is required because when dtc is used on the output of cpp, the successive detected file names overwrite the file name in the file structure. The next field does not need to be deep copied, because it is always NULL when srcpos_copy is called; an assert checks for this. File names are only updated in uncopied position structures. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-14Revert "annotations: add positions"David Gibson1-22/+11
This reverts commit baa1d2cf7894a32bf2f640ef40ebce561b2df565. Turns out this introduced memory badness. valgrind picks it up on x86, but it straight out SEGVs on x86. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-13annotations: add positionsJulia Lawall1-11/+22
Extend the parser to record positions, in build_node, build_node_delete, and build_property. srcpos structures are added to the property and node types, and to the parameter lists of the above functions that construct these types. Nodes and properties that are created by the compiler rather than from parsing source code have NULL as the srcpos value. merge_nodes, defined in livetree.c, uses srcpos_extend to combine multiple positions, resulting in a list of positions. srcpos_extend is defined in srcpos.c. New elements are added at the end. The srcpos type, define in srcpos.h, is now a list structure with a next field. Another change to srcpos.c is to make srcpos_copy always do a full copy, including a copy of the file substructure. This is required because when dtc is used on the output of cpp, the successive detected file names overwrite the file name in the file structure. The next field does not need to be deep copied, because it is only updated in newly copied positions and the positions to which it points have also been copied. File names are only updated in uncopied position structures. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-07-13livetree: Set phandle properties type to uint32Rob Herring1-6/+6
Generated phandle property values are a single cell, so set the type marker to uint32. Otherwise, we default to uint8. Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-05-04dtc: add ability to make nodes conditional on them being referencedMaxime Ripard1-0/+14
A number of platforms have a need to reduce the number of DT nodes, mostly because of two similar constraints: the size of the DT blob, and the time it takes to parse it. As the DT is used in more and more SoCs, and by more projects, some constraints start to appear in bootloaders running from SRAM with an order of magnitude of 10kB. A typical DT is in the same order of magnitude, so any effort to reduce the blob size is welcome in such an environment. Some platforms also want to reach very fast boot time, and the time it takes to parse a typical DT starts to be noticeable. Both of these issues can be mitigated by reducing the number of nodes in the DT. The biggest provider of nodes is usually the pin controller and its subnodes, usually one for each valid pin configuration in a given SoC. Obviously, a single, fixed, set of these nodes will be used by a given board, so we can introduce a node property that will tell the DT compiler to drop the nodes when they are not referenced in the tree, and as such wouldn't be useful in the targetted system. Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> Reviewed-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-03-06Correct overlay syntactic sugar for generating target-path fragmentsDavid Gibson1-3/+9
We've recently added "syntactic sugar" support to generate runtime dtb overlays using similar syntax to the compile time overlays we've had for a while. This worked with the &label { ... } syntax, adjusting an existing labelled node, but would fail with the &{/path} { ... } syntax attempting to adjust an existing node referenced by its path. The previous code would always try to use the "target" property in the output overlay, which needs to be fixed up, and __fixups__ can only encode symbols, not paths, so the result could never work properly. This adds support for the &{/path} syntax for overlays, translating it into the "target-path" encoding in the output. It also changes existing behaviour a little because we now unconditionally one fragment for each overlay section in the source. Previously we would only create a fragment if we couldn't locally resolve the node referenced. We need this for path references, because the path is supposed to be referencing something in the (not yet known) base tree, rather than the overlay tree we are working with now. In particular one useful case for path based overlays is using &{/} - but the constructed overlay tree will always have a root node, meaning that without the change that would attempt to resolve the fragment locally, which is not what we want. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-11-21Fix ambiguous grammar for devicetree ruleGrant Likely1-1/+2
Commit 737b2df3, "overlay: Add syntactic sugar version of overlays" introduced an empty rule for "devicetree" that created ambiguities in the grammar and causes the following warning: BISON dtc-parser.tab.c dtc-parser.y: warning: 3 shift/reduce conflicts [-Wconflicts-sr] Fix the grammar by explicitly testing for the condition the new overlay grammar wants to use. This means duplicating a very small amount of grammar processing code, but the alternative seems to be a more invasive reorganization of the devicetree rule. Better to fix it this way now and save the reorg for a separate patch. Signed-off-by: Grant Likely <grant.likely@arm.com> Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com> Cc: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-11-11Fix widespread incorrect use of strneq(), replace with new strprefixeq()David Gibson1-1/+1
Every remaining usage of strneq() is, in fact, incorrect. They're trying to check that the first n characters of one string exactly match another string. But, they fall into the classic trap of strncmp() on which strneq() is based. If n is less than the length of the second string, they only check that the first string matches the start of the second, not the whole of it. To fix this, remove strneq() and replace it with a strprefixeq() function which does what we want here. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>