Lines Matching +full:column +full:- +full:offset
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 { ... };').
68 stored in big-endian format.
121 def name(self) -> str:
125 # Converted to a property to discourage renaming -- that has to be done
130 def lineno(self) -> int:
137 def filename(self) -> str:
144 def unit_addr(self) -> str:
151 def path(self) -> str:
166 def node_iter(self) -> Iterable['Node']:
181 def _get_prop(self, name: str) -> 'Property':
191 def _del(self) -> None:
273 big-endian format, and strings are null-terminated. Putting multiple
274 comma-separated values in an assignment (e.g., 'x = < 1 >, "foo"') will
285 ----------------------------+------------------------
318 offset, in bytes. For example, 'x = < 0 label_1: 1 label_2: >' gives
340 self.lineno = -1
350 # A list of [offset, label, type] lists (sorted by offset),
359 def type(self) -> Type:
400 def to_num(self, signed=False) -> int:
420 def to_nums(self, signed=False) -> list[int]:
441 def to_bytes(self) -> bytes:
458 def to_string(self) -> str:
468 not valid UTF-8.
476 ret = self.value.decode("utf-8")[:-1] # Strip null
480 "is not valid UTF-8")
484 def to_strings(self) -> list[str]:
493 Also raises DTError if any of the strings are not valid UTF-8.
501 ret = self.value.decode("utf-8").split("\0")[:-1]
505 "is not valid UTF-8")
509 def to_node(self) -> Node:
525 def to_nodes(self) -> list[Node]:
552 def to_path(self) -> Node:
571 path = self.value.decode("utf-8")[:-1]
575 "is not valid UTF-8")
581 f"{self.node.dt.filename} points to the non-existent node "
594 if i < len(self._markers) - 1:
603 # end - 1 to strip off the null terminator
604 s += f' "{_decode_and_escape(self.value[pos:end - 1])}"'
659 # len(self.value) gives the current offset. This function is called
741 (e.g., 'x = label_1: < 1 label2: 2 >;') to a (prop, offset) tuple, where
742 'prop' is a Property instance and 'offset' the byte offset (0 for label_1
802 def root(self) -> Node:
807 # treat self._root as a non-None value until it's initialized
811 def get_node(self, path: str) -> Node:
816 For example, both dt.get_node("/foo/bar") and dt.get_node("bar-alias")
819 /dts-v1/;
830 bar-alias = &bar-label;
835 dt.get_node("bar-alias/baz") returns the 'baz' node.
843 _err(f"no alias '{alias}' found -- did you forget the leading "
848 def has_node(self, path: str) -> bool:
905 def node_iter(self) -> Iterable[Node]:
923 s = "/dts-v1/;\n\n"
926 for labels, address, offset in self.memreserves:
930 s += f"/memreserve/ {address:#018x} {offset:#018x};\n"
1028 prop, offset = prop_offset
1031 ret_label2prop_offset[label] = (prop_copy, offset)
1050 with open(filename, encoding="utf-8") as f:
1072 # Parses /dts-v1/ (expected) and /plugin/ (unsupported) at the start of
1073 # files. There may be multiple /dts-v1/ at the start of a file.
1081 # /plugin/ always comes after /dts-v1/
1086 self._parse_error("expected '/dts-v1/;' at start of file")
1089 # Parses /memreserve/, which appears after /dts-v1/
1109 # Top-level parsing loop
1160 # Parses the '{ ... };' part of 'node-name { ... };'.
1205 "/omit-if-no-ref/ can only be used on nodes")
1243 # _parse_node() helpers for parsing labels and /omit-if-no-ref/s before
1244 # nodes and properties. Returns a (<label list>, <omit-if-no-ref bool>)
1264 # Parses the right-hand side of property assignment
1269 # Remove any old value, path/phandle references, and in-value labels,
1295 prop.value += self._unescape(tok.val.encode("utf-8")) + b"\0"
1327 "arrays with 32-bit elements")
1367 self._parse_error("expected two-digit byte or ']'")
1376 # /incbin/ ("filename", <offset>, <size>)
1389 offset = self._eval_prim()
1396 offset = None
1400 if offset is None:
1403 f.seek(offset)
1410 # comma-separated value
1422 # self-referential phandles (which get set to b'\0\0\0\0' initially).
1423 # Self-referential phandles must be rewritten instead of recreated, so
1536 elif self._check_token("-"):
1537 val -= self._eval_mul()
1560 if self._check_token("-"):
1561 return -self._eval_unary()
1596 val = self._unescape(match.group(tok_id).encode("utf-8"))
1655 filename = tok_val[tok_val.find('"') + 1:-1]
1661 self._lineno = int(tok_val.split()[0]) - 1
1662 self.filename = tok_val[tok_val.find('"') + 1:-1]
1706 # returns -1
1707 column = self._tok_i - self._file_contents.rfind("\n", 0,
1709 _err(f"{self.filename}:{self._lineno} (column {column}): "
1721 filename = self._unescape(filename.encode("utf-8"))
1723 filename = filename.decode("utf-8")
1725 self._parse_error("filename is not valid UTF-8")
1727 with self._open(filename, encoding="utf-8") as f:
1736 self._parse_error("recursive /include/:\n" + " ->\n".join(
1770 path = s[1:-1]
1787 # Post-processing
1791 # Registers any manually-inserted phandle properties in
1857 # Fix the marker offset so that it's correct for the
1859 # function). The offset might change due to path
1876 # For /omit-if-no-ref/
1880 res += ref_node.path.encode("utf-8") + b'\0'
1888 # Store the final fixed-up value. Add the data after the last
1900 alias_re = re.compile("[0-9a-z-]+$")
1907 "should include only characters from [0-9a-z-]")
1922 # Removes any unreferenced nodes marked with /omit-if-no-ref/ from the
1948 for label, offset in prop._label_offset_lst:
1949 label2things[label].add((prop, offset))
1950 self.label2prop_offset[label] = (prop, offset)
1982 # the string level, because the result might not be valid UTF-8 when
2006 # Return <char> as-is for other \<char>
2016 # The C tools support specifying stdin with '-' too
2017 if filename == "-":
2044 signed: bool = False) -> int:
2047 in big-endian format, which is standard in devicetree.
2064 def to_nums(data: bytes, length: int = 4, signed: bool = False) -> list[int]:
2067 are assumed to be in big-endian format, which is standard in devicetree.
2099 # Decodes the 'bytes' array 'b' as UTF-8 and backslash-escapes special
2102 # Hacky but robust way to avoid double-escaping any '\' spit out by
2106 return (b.decode("utf-8", "surrogateescape")
2108 .encode("utf-8", "surrogateescape")
2109 .decode("utf-8", "backslashreplace"))
2130 def _err(msg) -> NoReturn:
2149 _num_re = re.compile(r"(0[xX][0-9a-fA-F]+|[0-9]+)(?:ULL|UL|LL|U|L)?")
2153 _propnodename_re = re.compile(r"\\?([a-zA-Z0-9,._+*#?@-]+)")
2156 _nodename_chars = set(string.ascii_letters + string.digits + ',._+-@')
2162 "==", "!=", "!", "=", ",", ";", "+", "-", "*", "/", "%", "~", "?", ":",
2166 _byte_re = re.compile(r"[0-9a-fA-F]{2}")
2170 _unescape_re = re.compile(br'\\([0-7]{1,3}|x[0-9A-Fa-f]{1,2}|.)')
2184 r'^#(?:line)?[ \t]+([0-9]+[ \t]+"(?:[^\\"]|\\.)*")(?:[ \t]+[0-9]+){0,4}',
2187 _T.DTS_V1: r"(/dts-v1/)",
2191 _T.DEL_PROP: r"(/delete-property/)",
2192 _T.DEL_NODE: r"(/delete-node/)",
2193 _T.OMIT_IF_NO_REF: r"(/omit-if-no-ref/)",
2194 _T.LABEL: r"([a-zA-Z_][a-zA-Z0-9_]*):",
2196 _T.REF: r"&([a-zA-Z_][a-zA-Z0-9_]*|{[a-zA-Z0-9,._+*#?@/-]*})",
2200 # Return a token for end-of-file so that the parsing code can