Lines Matching +full:child +full:- +full:prop
3 # Copyright (c) 2019 - 2020 Nordic Semiconductor ASA
5 # SPDX-License-Identifier: BSD-3-Clause
16 # Note: Do not access private (_-prefixed) identifiers from edtlib here (and
30 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'python-devicetree',
62 "-Wno-simple_bus_reg" not in args.dtc_flags,
73 with open(args.dts_out, "w", encoding="utf-8") as f:
96 with open(args.header_out, "w", encoding="utf-8") as header_file:
106 # Check to see if we have duplicate "zephyr,memory-region" property values.
109 if 'zephyr,memory-region' in node.props:
110 region = node.props['zephyr,memory-region'].val
112 sys.exit(f"ERROR: Duplicate 'zephyr,memory-region' ({region}) properties "
122 out_comment("Node's name with unit-address:")
164 # - the root node's path "/" has path identifier "N"
165 # - "/foo" has "N_S_foo"
166 # - "/foo/bar" has "N_S_foo_S_bar"
167 # - "/foo/bar@123" has "N_S_foo_S_bar_123"
180 # Returns parsed command-line arguments
183 parser.add_argument("--dts", required=True, help="DTS file")
184 parser.add_argument("--dtc-flags",
187 parser.add_argument("--bindings-dirs", nargs='+', required=True,
190 parser.add_argument("--header-out", required=True,
192 parser.add_argument("--dts-out", required=True,
195 parser.add_argument("--edt-pickle-out",
197 parser.add_argument("--vendor-prefixes", action='append', default=[],
198 help="vendor-prefixes.txt path; used for validation; "
200 parser.add_argument("--edtlib-Werror", action="store_true",
201 help="if set, edtlib-specific warnings become errors. "
274 # themselves couldn't contain C multi-line comments, which is
358 # ranges property: edtlib knows the right #address-cells and
359 # #size-cells of parent and child, and can therefore pack the
360 # child & parent addresses and sizes correctly
374 idx_value = range.child_bus_addr >> ((range.child_bus_cells - 1) * 32)
380 idx_value = range.child_bus_addr & ((1 << (range.child_bus_cells - 1) * 32) - 1)
401 # reg property: edtlib knows the right #address-cells and
402 # #size-cells, and can therefore pack the register base addresses
436 # interrupts property: we have some hard-coded logic for interrupt
447 "interrupt-cells")
466 "interrupt-cells")
525 out_comment("Helper macros for child nodes of this node.")
528 " ".join(f"fn(DT_{child.z_path_id})" for child in
532 " DT_DEBRACKET_INTERNAL sep ".join(f"fn(DT_{child.z_path_id})"
533 for child in node.children.values()))
536 " ".join(f"fn(DT_{child.z_path_id}, __VA_ARGS__)"
537 for child in node.children.values()))
540 " DT_DEBRACKET_INTERNAL sep ".join(f"fn(DT_{child.z_path_id}, __VA_ARGS__)"
541 for child in node.children.values()))
544 " ".join(f"fn(DT_{child.z_path_id})"
545 for child in node.children.values() if child.status == "okay"))
548 " DT_DEBRACKET_INTERNAL sep ".join(f"fn(DT_{child.z_path_id})"
549 for child in node.children.values() if child.status == "okay"))
552 " ".join(f"fn(DT_{child.z_path_id}, __VA_ARGS__)"
553 for child in node.children.values() if child.status == "okay"))
556 " DT_DEBRACKET_INTERNAL sep ".join(f"fn(DT_{child.z_path_id}, __VA_ARGS__)"
557 for child in node.children.values() if child.status == "okay"))
565 # Write special macros for pinctrl-<index> and pinctrl-names properties.
567 out_comment("Pin control (pinctrl-<i>, pinctrl-names) properties:")
583 # pinctrl-<pc_idx> properties are contiguous, start from 0,
595 # Macros for child nodes of each fixed-partitions node.
597 if not (node.parent and "fixed-partitions" in node.parent.compats):
601 out_comment("fixed-partitions identifier:")
607 # Write special macros for gpio-hog node properties.
627 # never-ending amounts of special case code here to skip special
633 for prop_name, prop in node.props.items():
636 val = prop2value(prop)
638 # DT_N_<node-id>_P_<prop-id>
641 if prop.spec.type == 'string':
642 # DT_N_<node-id>_P_<prop-id>_IDX_<i>_STRING_UNQUOTED
643 macro2val[macro + "_STRING_UNQUOTED"] = prop.val
644 # DT_N_<node-id>_P_<prop-id>_IDX_<i>_STRING_TOKEN
645 macro2val[macro + "_STRING_TOKEN"] = prop.val_as_token
646 # DT_N_<node-id>_P_<prop-id>_IDX_<i>_STRING_UPPER_TOKEN
647 macro2val[macro + "_STRING_UPPER_TOKEN"] = prop.val_as_token.upper()
648 # DT_N_<node-id>_P_<prop-id>_IDX_0:
649 # DT_N_<node-id>_P_<prop-id>_IDX_0_EXISTS:
651 # string-array of length 1.
652 macro2val[macro + "_IDX_0"] = quote_str(prop.val)
655 if prop.enum_index is not None:
656 # DT_N_<node-id>_P_<prop-id>_ENUM_IDX
657 macro2val[macro + "_ENUM_IDX"] = prop.enum_index
658 spec = prop.spec
661 as_token = prop.val_as_token
663 # DT_N_<node-id>_P_<prop-id>_ENUM_VAL_<val>_EXISTS 1
665 # DT_N_<node-id>_P_<prop-id>_ENUM_TOKEN
669 # DT_N_<node-id>_P_<prop-id>_ENUM_UPPER_TOKEN
672 # DT_N_<node-id>_P_<prop-id>_ENUM_VAL_<val>_EXISTS 1
673 macro2val[macro + f"_ENUM_VAL_{prop.val}_EXISTS"] = 1
675 if "phandle" in prop.type:
676 macro2val.update(phandle_macros(prop, macro))
677 elif "array" in prop.type:
678 for i, subval in enumerate(prop.val):
679 # DT_N_<node-id>_P_<prop-id>_IDX_<i>
680 # DT_N_<node-id>_P_<prop-id>_IDX_<i>_EXISTS
685 # DT_N_<node-id>_P_<prop-id>_IDX_<i>_STRING_UNQUOTED
687 # DT_N_<node-id>_P_<prop-id>_IDX_<i>_STRING_TOKEN
689 # DT_N_<node-id>_P_<prop-id>_IDX_<i>_STRING_UPPER_TOKEN
695 plen = prop_len(prop)
697 # DT_N_<node-id>_P_<prop-id>_FOREACH_PROP_ELEM
703 # DT_N_<node-id>_P_<prop-id>_FOREACH_PROP_ELEM_SEP
709 # DT_N_<node-id>_P_<prop-id>_FOREACH_PROP_ELEM_VARGS
715 # DT_N_<node-id>_P_<prop-id>_FOREACH_PROP_ELEM_SEP_VARGS
721 # DT_N_<node-id>_P_<prop-id>_LEN
724 # DT_N_<node-id>_P_<prop-id>_EXISTS
736 # Write dependency-related information about the node.
761 def prop2value(prop): argument
762 # Gets the macro value for property 'prop', if there is
763 # a single well-defined C rvalue that it can be represented as.
766 if prop.type == "string":
767 return quote_str(prop.val)
769 if prop.type == "int":
770 return prop.val
772 if prop.type == "boolean":
773 return 1 if prop.val else 0
775 if prop.type in ["array", "uint8-array"]:
776 return list2init(f"{val} /* {hex(val)} */" for val in prop.val)
778 if prop.type == "string-array":
779 return list2init(quote_str(val) for val in prop.val)
781 # phandle, phandles, phandle-array, path, compound: nothing
785 def prop_len(prop): argument
794 # This deliberately excludes ranges, dma-ranges, reg and interrupts.
796 # basically nonsense semantically due to #address-cells and
797 # #size-cells for "reg", #interrupt-cells for "interrupts"
798 # and #address-cells, #size-cells and the #address-cells from the
799 # parent node for "ranges" and "dma-ranges".
807 if prop.type in ["phandle", "string"]:
809 # string is treated as a string-array of length 1.
812 if (prop.type in ["array", "uint8-array", "string-array",
813 "phandles", "phandle-array"] and
814 prop.name not in ["ranges", "dma-ranges", "reg", "interrupts"]):
815 return len(prop.val)
820 def phandle_macros(prop, macro): argument
821 # Returns a dict of macros for phandle or phandles property 'prop'.
823 # The 'macro' argument is the N_<node-id>_P_<prop-id> bit.
831 # to use the same macros for phandle, phandles, and phandle-array.
835 if prop.type == "phandle":
837 ret[f"{macro}"] = f"DT_{prop.val.z_path_id}"
838 ret[f"{macro}_IDX_0"] = f"DT_{prop.val.z_path_id}"
839 ret[f"{macro}_IDX_0_PH"] = f"DT_{prop.val.z_path_id}"
841 elif prop.type == "phandles":
842 for i, node in enumerate(prop.val):
846 elif prop.type == "phandle-array":
847 for i, entry in enumerate(prop.val):
849 # Unspecified element. The phandle-array at this index
870 # DT_N_<node-id>_P_<prop-id>_IDX_<i>_EXISTS
872 # DT_N_<node-id>_P_<prop-id>_IDX_<i>_PH
874 # DT_N_<node-id>_P_<prop-id>_IDX_<i>_VAL_<VAL>
883 # DT_N_<node-id>_P_<prop-id>_IDX_<i>_EXISTS
885 # DT_N_<node-id>_P_<prop-id>_IDX_<i>_NAME
887 # DT_N_<node-id>_P_<prop-id>_NAME_<NAME>_PH
889 # DT_N_<node-id>_P_<prop-id>_NAME_<NAME>_EXISTS
891 # DT_N_<node-id>_P_<prop-id>_NAME_<NAME>_VAL_<VAL>
902 # Tree-wide information such as chosen nodes is printed here.
915 # Global or tree-wide information, such as number of instances
944 # Helpers for non-INST for-each macros that take node
953 # Helpers for INST versions of for-each macros, which take
955 # avoiding an intermediate node_id --> instance number
967 if compat == "fixed-partitions":
968 for child in node.children.values():
969 if "label" in child.props:
970 label = child.props["label"].val
972 val = f"DT_{child.z_path_id}"
997 return re.sub('[-,.@/+]', '_', s.lower())
1009 # The macro will be left-justified to 'width' characters if that
1047 # Format multi-line comments like
1063 # Format single-line comments like
1070 # Backslash-escapes any double quotes and backslashes in 's'