From f059bd1ebfc4cf2e96c4639ad7fa6cf3a3198a2f Mon Sep 17 00:00:00 2001 From: Oleksandr Tymoshenko Date: Fri, 10 Mar 2017 03:28:43 +0000 Subject: [PATCH] Import dtc 1.4.3 Obtained from: https://www.kernel.org/pub/software/utils/dtc/dtc-1.4.3.tar.gz --- Documentation/dt-object-internal.txt | 310 ++++++++ Documentation/manual.txt | 45 +- Makefile | 35 +- Makefile.ftdump | 12 - README | 16 + checks.c | 502 +++++++------ convert-dtsv0-lexer.l | 3 +- data.c | 2 +- dtc-lexer.l | 69 +- dtc-parser.y | 116 ++- dtc.c | 141 +++- dtc.h | 48 +- fdtdump.c | 39 +- fdtget.c | 8 +- fdtput.c | 99 ++- flattree.c | 45 +- fstree.c | 21 +- ftdump.c | 208 ------ libfdt/Makefile.libfdt | 3 +- libfdt/fdt.c | 13 +- libfdt/fdt_addresses.c | 96 +++ libfdt/fdt_overlay.c | 676 ++++++++++++++++++ libfdt/fdt_ro.c | 154 +++- libfdt/fdt_rw.c | 17 +- libfdt/fdt_strerror.c | 6 + libfdt/fdt_wip.c | 31 +- libfdt/libfdt.h | 378 +++++++++- libfdt/libfdt_env.h | 1 + libfdt/libfdt_internal.h | 6 +- libfdt/version.lds | 8 + livetree.c | 309 +++++++- scripts/kup-dtc | 31 + srcpos.c | 43 +- srcpos.h | 1 - tests/Makefile.tests | 7 +- tests/addr_size_cells.c | 64 ++ tests/addresses.dts | 15 + tests/bad-octal-literal.dts | 5 + tests/bad-size-cells.dts | 12 + tests/check_path.c | 83 +++ tests/division-by-zero.dts | 6 + tests/dumptrees.c | 1 + tests/embedded_nul.dts | Bin 0 -> 152 bytes tests/embedded_nul_equiv.dts | 6 + tests/fdtdump-runtest.sh | 30 + tests/fdtdump.dts | 38 + tests/get_phandle.c | 6 + tests/line_directives.dts | 5 + tests/multilabel.dts | 2 + tests/multilabel_merge.dts | 4 + tests/nul-in-escape.dts | Bin 0 -> 36 bytes tests/nul-in-line-info1.dts | Bin 0 -> 8 bytes tests/nul-in-line-info2.dts | 1 + tests/overlay.c | 233 ++++++ tests/overlay_bad_fixup.c | 70 ++ tests/overlay_bad_fixup_bad_index.dts | 14 + tests/overlay_bad_fixup_base.dtsi | 18 + tests/overlay_bad_fixup_empty.dts | 14 + tests/overlay_bad_fixup_empty_index.dts | 14 + tests/overlay_bad_fixup_index_trailing.dts | 14 + tests/overlay_bad_fixup_path_empty_prop.dts | 14 + tests/overlay_bad_fixup_path_only.dts | 14 + tests/overlay_bad_fixup_path_only_sep.dts | 14 + tests/overlay_bad_fixup_path_prop.dts | 14 + tests/overlay_base.dts | 21 + tests/overlay_base_manual_symbols.dts | 25 + tests/overlay_overlay.dts | 86 +++ tests/overlay_overlay_manual_fixups.dts | 112 +++ tests/overlay_overlay_no_fixups.dts | 82 +++ tests/overlay_overlay_simple.dts | 12 + tests/path-references.c | 16 + tests/path-references.dts | 1 + tests/path_offset.c | 92 ++- tests/property_iterate.c | 97 +++ tests/property_iterate.dts | 23 + tests/references.c | 19 + tests/references.dts | 2 + tests/references_dts0.dts | 26 - tests/reg-without-unit-addr.dts | 10 + tests/run_tests.sh | 203 +++++- tests/setprop.c | 2 +- tests/setprop_inplace.c | 10 + tests/sourceoutput.dts | 14 + tests/stringlist.c | 154 ++++ tests/stringlist.dts | 12 + tests/subnode_iterate.c | 8 +- tests/test_label_ref.dts | 9 + tests/test_tree1.dts | 44 +- tests/test_tree1_delete.dts | 2 +- tests/test_tree1_dts0.dts | 37 - ...body.dtsi => test_tree1_label_noderef.dts} | 18 +- tests/testdata.h | 4 + tests/tests.sh | 1 + tests/testutils.c | 1 - tests/trees.S | 31 + tests/unit-addr-without-reg.dts | 9 + treesource.c | 18 +- util.c | 49 +- util.h | 18 +- 99 files changed, 4623 insertions(+), 855 deletions(-) create mode 100644 Documentation/dt-object-internal.txt delete mode 100644 Makefile.ftdump create mode 100644 README delete mode 100644 ftdump.c create mode 100644 libfdt/fdt_addresses.c create mode 100644 libfdt/fdt_overlay.c create mode 100755 scripts/kup-dtc create mode 100644 tests/addr_size_cells.c create mode 100644 tests/addresses.dts create mode 100644 tests/bad-octal-literal.dts create mode 100644 tests/bad-size-cells.dts create mode 100644 tests/check_path.c create mode 100644 tests/division-by-zero.dts create mode 100644 tests/embedded_nul.dts create mode 100644 tests/embedded_nul_equiv.dts create mode 100755 tests/fdtdump-runtest.sh create mode 100644 tests/fdtdump.dts create mode 100644 tests/nul-in-escape.dts create mode 100644 tests/nul-in-line-info1.dts create mode 100644 tests/nul-in-line-info2.dts create mode 100644 tests/overlay.c create mode 100644 tests/overlay_bad_fixup.c create mode 100644 tests/overlay_bad_fixup_bad_index.dts create mode 100644 tests/overlay_bad_fixup_base.dtsi create mode 100644 tests/overlay_bad_fixup_empty.dts create mode 100644 tests/overlay_bad_fixup_empty_index.dts create mode 100644 tests/overlay_bad_fixup_index_trailing.dts create mode 100644 tests/overlay_bad_fixup_path_empty_prop.dts create mode 100644 tests/overlay_bad_fixup_path_only.dts create mode 100644 tests/overlay_bad_fixup_path_only_sep.dts create mode 100644 tests/overlay_bad_fixup_path_prop.dts create mode 100644 tests/overlay_base.dts create mode 100644 tests/overlay_base_manual_symbols.dts create mode 100644 tests/overlay_overlay.dts create mode 100644 tests/overlay_overlay_manual_fixups.dts create mode 100644 tests/overlay_overlay_no_fixups.dts create mode 100644 tests/overlay_overlay_simple.dts create mode 100644 tests/property_iterate.c create mode 100644 tests/property_iterate.dts delete mode 100644 tests/references_dts0.dts create mode 100644 tests/reg-without-unit-addr.dts create mode 100644 tests/sourceoutput.dts create mode 100644 tests/stringlist.c create mode 100644 tests/stringlist.dts create mode 100644 tests/test_label_ref.dts delete mode 100644 tests/test_tree1_dts0.dts rename tests/{test_tree1_body.dtsi => test_tree1_label_noderef.dts} (73%) create mode 100644 tests/unit-addr-without-reg.dts diff --git a/Documentation/dt-object-internal.txt b/Documentation/dt-object-internal.txt new file mode 100644 index 00000000000..51d68ab93ac --- /dev/null +++ b/Documentation/dt-object-internal.txt @@ -0,0 +1,310 @@ +Device Tree Dynamic Object format internals +------------------------------------------- + +The Device Tree for most platforms is a static representation of +the hardware capabilities. This is insufficient for platforms +that need to dynamically insert Device Tree fragments into the +live tree. + +This document explains the the Device Tree object format and +modifications made to the Device Tree compiler, which make it possible. + +1. Simplified Problem Definition +-------------------------------- + +Assume we have a platform which boots using following simplified Device Tree. + +---- foo.dts ----------------------------------------------------------------- + /* FOO platform */ + / { + compatible = "corp,foo"; + + /* shared resources */ + res: res { + }; + + /* On chip peripherals */ + ocp: ocp { + /* peripherals that are always instantiated */ + peripheral1 { ... }; + }; + }; +---- foo.dts ----------------------------------------------------------------- + +We have a number of peripherals that after probing (using some undefined method) +should result in different Device Tree configuration. + +We cannot boot with this static tree because due to the configuration of the +foo platform there exist multiple conficting peripherals DT fragments. + +So for the bar peripheral we would have this: + +---- foo+bar.dts ------------------------------------------------------------- + /* FOO platform + bar peripheral */ + / { + compatible = "corp,foo"; + + /* shared resources */ + res: res { + }; + + /* On chip peripherals */ + ocp: ocp { + /* peripherals that are always instantiated */ + peripheral1 { ... }; + + /* bar peripheral */ + bar { + compatible = "corp,bar"; + ... /* various properties and child nodes */ + }; + }; + }; +---- foo+bar.dts ------------------------------------------------------------- + +While for the baz peripheral we would have this: + +---- foo+baz.dts ------------------------------------------------------------- + /* FOO platform + baz peripheral */ + / { + compatible = "corp,foo"; + + /* shared resources */ + res: res { + /* baz resources */ + baz_res: res_baz { ... }; + }; + + /* On chip peripherals */ + ocp: ocp { + /* peripherals that are always instantiated */ + peripheral1 { ... }; + + /* baz peripheral */ + baz { + compatible = "corp,baz"; + /* reference to another point in the tree */ + ref-to-res = <&baz_res>; + ... /* various properties and child nodes */ + }; + }; + }; +---- foo+baz.dts ------------------------------------------------------------- + +We note that the baz case is more complicated, since the baz peripheral needs to +reference another node in the DT tree. + +2. Device Tree Object Format Requirements +----------------------------------------- + +Since the Device Tree is used for booting a number of very different hardware +platforms it is imperative that we tread very carefully. + +2.a) No changes to the Device Tree binary format for the base tree. We cannot +modify the tree format at all and all the information we require should be +encoded using Device Tree itself. We can add nodes that can be safely ignored +by both bootloaders and the kernel. The plugin dtbs are optionally tagged +with a different magic number in the header but otherwise they're simple +blobs. + +2.b) Changes to the DTS source format should be absolutely minimal, and should +only be needed for the DT fragment definitions, and not the base boot DT. + +2.c) An explicit option should be used to instruct DTC to generate the required +information needed for object resolution. Platforms that don't use the +dynamic object format can safely ignore it. + +2.d) Finally, DT syntax changes should be kept to a minimum. It should be +possible to express everything using the existing DT syntax. + +3. Implementation +----------------- + +The basic unit of addressing in Device Tree is the phandle. Turns out it's +relatively simple to extend the way phandles are generated and referenced +so that it's possible to dynamically convert symbolic references (labels) +to phandle values. This is a valid assumption as long as the author uses +reference syntax and does not assign phandle values manually (which might +be a problem with decompiled source files). + +We can roughly divide the operation into two steps. + +3.a) Compilation of the base board DTS file using the '-@' option +generates a valid DT blob with an added __symbols__ node at the root node, +containing a list of all nodes that are marked with a label. + +Using the foo.dts file above the following node will be generated; + +$ dtc -@ -O dtb -o foo.dtb -b 0 foo.dts +$ fdtdump foo.dtb +... +/ { + ... + res { + ... + phandle = <0x00000001>; + ... + }; + ocp { + ... + phandle = <0x00000002>; + ... + }; + __symbols__ { + res="/res"; + ocp="/ocp"; + }; +}; + +Notice that all the nodes that had a label have been recorded, and that +phandles have been generated for them. + +This blob can be used to boot the board normally, the __symbols__ node will +be safely ignored both by the bootloader and the kernel (the only loss will +be a few bytes of memory and disk space). + +We generate a __symbols__ node to record nodes that had labels in the base +tree (or subsequent loaded overlays) so that they can be matched up with +references made to them in Device Tree objects. + +3.b) The Device Tree fragments must be compiled with the same option but they +must also have a tag (/plugin/) that allows undefined references to nodes +that are not present at compilation time to be recorded so that the runtime +loader can fix them. + +So the bar peripheral's DTS format would be of the form: + +/dts-v1/; +/plugin/; /* allow undefined references and record them */ +/ { + .... /* various properties for loader use; i.e. part id etc. */ + fragment@0 { + target = <&ocp>; + __overlay__ { + /* bar peripheral */ + bar { + compatible = "corp,bar"; + ... /* various properties and child nodes */ + } + }; + }; +}; + +Note that there's a target property that specifies the location where the +contents of the overlay node will be placed, and it references the node +in the foo.dts file. + +$ dtc -@ -O dtb -o bar.dtbo -b 0 bar.dts +$ fdtdump bar.dtbo +... +/ { + ... /* properties */ + fragment@0 { + target = <0xffffffff>; + __overlay__ { + bar { + compatible = "corp,bar"; + ... /* various properties and child nodes */ + } + }; + }; + __fixups__ { + ocp = "/fragment@0:target:0"; + }; +}; + +No __symbols__ node has been generated (no label in bar.dts). +Note that the target's ocp label is undefined, so the phandle +value is filled with the illegal value '0xffffffff', while a __fixups__ +node has been generated, which marks the location in the tree where +the label lookup should store the runtime phandle value of the ocp node. + +The format of the __fixups__ node entry is + +