Lines Matching +full:bad +full:- +full:key +full:- +full:2
2 # SPDX-License-Identifier: BSD-3-Clause
10 The top-level entry point of the library is the DT class. DT.__init__() takes a
30 "Exception raised for devicetree-related errors"
34 Represents a node in the devicetree ('node-name { ... };').
62 stored in big-endian format.
109 dt._parse_error(f"{self.path}: bad character '{char}' "
113 def name(self) -> str:
117 # Converted to a property to discourage renaming -- that has to be done
122 def unit_addr(self) -> str:
126 return self.name.partition("@")[2]
129 def path(self) -> str:
144 def node_iter(self) -> Iterable['Node']:
159 def _get_prop(self, name: str) -> 'Property':
169 def _del(self) -> None:
209 NUM = 2
225 LABEL = 2 # foo: <1 2 3>
229 UINT16 = 4 # /bits/ 16 <1 2 3>
230 UINT32 = 5 # <1 2 3>
231 UINT64 = 6 # /bits/ 64 <1 2 3>
245 big-endian format, and strings are null-terminated. Putting multiple
246 comma-separated values in an assignment (e.g., 'x = < 1 >, "foo"') will
257 ----------------------------+------------------------
264 foo = <1 2 3>; | dtlib.Type.NUMS
265 foo = <1 2>, <3>; | dtlib.Type.NUMS
271 foo = <&l1 1 2 &l2 3 4>; | dtlib.Type.PHANDLES_AND_NUMS
272 foo = <&l1 1 2>, <&l2 3 4>; | dtlib.Type.PHANDLES_AND_NUMS
329 def type(self) -> Type:
347 # Treat 'foo = <1 2 3>, <4 5>, ...' as Type.NUMS too
370 def to_num(self, signed=False) -> int:
384 _err("expected property '{0}' on {1} in {2} to be assigned with "
391 def to_nums(self, signed=False) -> List[int]:
398 foo = < 1 2 ... >;
405 _err("expected property '{0}' on {1} in {2} to be assigned with "
413 def to_bytes(self) -> bytes:
424 _err("expected property '{0}' on {1} in {2} to be assigned with "
431 def to_string(self) -> str:
441 not valid UTF-8.
444 _err("expected property '{0}' on {1} in {2} to be assigned with "
450 ret = self.value.decode("utf-8")[:-1] # Strip null
454 "is not valid UTF-8")
458 def to_strings(self) -> List[str]:
467 Also raises DTError if any of the strings are not valid UTF-8.
470 _err("expected property '{0}' on {1} in {2} to be assigned with "
476 ret = self.value.decode("utf-8").split("\0")[:-1]
480 "is not valid UTF-8")
484 def to_node(self) -> Node:
494 _err("expected property '{0}' on {1} in {2} to be assigned with "
501 def to_nodes(self) -> List[Node]:
520 _err("expected property '{0}' on {1} in {2} to be assigned with "
529 def to_path(self) -> Node:
542 _err("expected property '{0}' on {1} in {2} to be assigned with "
548 path = self.value.decode("utf-8")[:-1]
552 "is not valid UTF-8")
558 f"{self.node.dt.filename} points to the non-existent node "
571 if i < len(self._markers) - 1:
580 # end - 1 to strip off the null terminator
581 s += f' "{_decode_and_escape(self.value[pos:end - 1])}"'
653 LINE = 2
674 BAD = 21 variable in _T
719 (e.g., 'x = label_1: < 1 label2: 2 >;') to a (prop, offset) tuple, where
780 def root(self) -> Node:
785 # treat self._root as a non-None value until it's initialized
789 def get_node(self, path: str) -> Node:
794 For example, both dt.get_node("/foo/bar") and dt.get_node("bar-alias")
797 /dts-v1/;
808 bar-alias = &bar-label;
813 dt.get_node("bar-alias/baz") returns the 'baz' node.
821 _err(f"no alias '{alias}' found -- did you forget the leading "
826 def has_node(self, path: str) -> bool:
861 _err(f"new path '{new_path}': bad character '{char}'")
883 def node_iter(self) -> Iterable[Node]:
901 s = "/dts-v1/;\n\n"
986 key: path2node_copy[original[key].path]
987 for key in original
1011 (set(memreserve[0]), memreserve[1], memreserve[2])
1026 with open(filename, encoding="utf-8") as f:
1048 # Parses /dts-v1/ (expected) and /plugin/ (unsupported) at the start of
1049 # files. There may be multiple /dts-v1/ at the start of a file.
1057 # /plugin/ always comes after /dts-v1/
1062 self._parse_error("expected '/dts-v1/;' at start of file")
1065 # Parses /memreserve/, which appears after /dts-v1/
1085 # Top-level parsing loop
1134 # Parses the '{ ... };' part of 'node-name { ... };'.
1173 "/omit-if-no-ref/ can only be used on nodes")
1209 # _parse_node() helpers for parsing labels and /omit-if-no-ref/s before
1210 # nodes and properties. Returns a (<label list>, <omit-if-no-ref bool>)
1230 # Parses the right-hand side of property assignment
1235 # Remove any old value, path/phandle references, and in-value labels,
1261 prop.value += self._unescape(tok.val.encode("utf-8")) + b"\0"
1293 "arrays with 32-bit elements")
1333 self._parse_error("expected two-digit byte or ']'")
1376 # comma-separated value
1388 # self-referential phandles (which get set to b'\0\0\0\0' initially).
1389 # Self-referential phandles must be rewritten instead of recreated, so
1502 elif self._check_token("-"):
1503 val -= self._eval_mul()
1526 if self._check_token("-"):
1527 return -self._eval_unary()
1562 val = self._unescape(match.group(tok_id).encode("utf-8"))
1601 # an unexpected context as well as for bad characters in
1605 return _Token(_T.BAD, "<unknown token>")
1621 filename = tok_val[tok_val.find('"') + 1:-1]
1627 self._lineno = int(tok_val.split()[0]) - 1
1628 self.filename = tok_val[tok_val.find('"') + 1:-1]
1672 # returns -1
1673 column = self._tok_i - self._file_contents.rfind("\n", 0,
1687 filename = self._unescape(filename.encode("utf-8"))
1689 filename = filename.decode("utf-8")
1691 self._parse_error("filename is not valid UTF-8")
1693 with self._open(filename, encoding="utf-8") as f:
1702 self._parse_error("recursive /include/:\n" + " ->\n".join(
1736 path = s[1:-1]
1753 # Post-processing
1757 # Registers any manually-inserted phandle properties in
1766 _err(f"{node.path}: bad phandle length "
1791 _err(f"{node.path}: bad value {phandle_val:#010x} "
1842 # For /omit-if-no-ref/
1846 res += ref_node.path.encode("utf-8") + b'\0'
1854 # Store the final fixed-up value. Add the data after the last
1866 alias_re = re.compile("[0-9a-z-]+$")
1873 "should include only characters from [0-9a-z-]")
1888 # Removes any unreferenced nodes marked with /omit-if-no-ref/ from the
1948 # the string level, because the result might not be valid UTF-8 when
1972 # Return <char> as-is for other \<char>
1982 # The C tools support specifying stdin with '-' too
1983 if filename == "-":
2010 signed: bool = False) -> int:
2013 in big-endian format, which is standard in devicetree.
2030 def to_nums(data: bytes, length: int = 4, signed: bool = False) -> List[int]:
2033 are assumed to be in big-endian format, which is standard in devicetree.
2065 # Decodes the 'bytes' array 'b' as UTF-8 and backslash-escapes special
2068 # Hacky but robust way to avoid double-escaping any '\' spit out by
2072 return (b.decode("utf-8", "surrogateescape")
2074 .encode("utf-8", "surrogateescape")
2075 .decode("utf-8", "backslashreplace"))
2096 def _err(msg) -> NoReturn:
2113 _EXPECT_BYTE = 2
2115 _num_re = re.compile(r"(0[xX][0-9a-fA-F]+|[0-9]+)(?:ULL|UL|LL|U|L)?")
2119 _propnodename_re = re.compile(r"\\?([a-zA-Z0-9,._+*#?@-]+)")
2122 _nodename_chars = set(string.ascii_letters + string.digits + ',._+-@')
2128 "==", "!=", "!", "=", ",", ";", "+", "-", "*", "/", "%", "~", "?", ":",
2132 _byte_re = re.compile(r"[0-9a-fA-F]{2}")
2136 _unescape_re = re.compile(br'\\([0-7]{1,3}|x[0-9A-Fa-f]{1,2}|.)')
2139 # Builds a (<token 1>)|(<token 2>)|... regex and returns it. The
2150 r'^#(?:line)?[ \t]+([0-9]+[ \t]+"(?:[^\\"]|\\.)*")(?:[ \t]+[0-9]+){0,4}',
2153 _T.DTS_V1: r"(/dts-v1/)",
2157 _T.DEL_PROP: r"(/delete-property/)",
2158 _T.DEL_NODE: r"(/delete-node/)",
2159 _T.OMIT_IF_NO_REF: r"(/omit-if-no-ref/)",
2160 _T.LABEL: r"([a-zA-Z_][a-zA-Z0-9_]*):",
2162 _T.REF: r"&([a-zA-Z_][a-zA-Z0-9_]*|{[a-zA-Z0-9,._+*#?@/-]*})",
2166 # Return a token for end-of-file so that the parsing code can
2181 _MarkerType.UINT16: 2,
2188 2: _MarkerType.UINT16,
2195 2: " /bits/ 16 <",
2202 2: " >",