Lines Matching +full:foo +full:- +full:names

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 { ... };').
65 x = "foo", < 0x12345678 >, [ 9A ];
67 This gives x the value b"foo\0\x12\x34\x56\x78\x9A". Numbers in DTS are
68 stored in big-endian format.
84 The path to the node as a string, e.g. "/foo/bar".
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:
245 PATH = 0 # &foo
246 PHANDLE = 1 # <&foo>
247 LABEL = 2 # foo: <1 2 3>
254 STRING = 7 # "foo"
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 ----------------------------+------------------------
286 foo; | dtlib.Type.EMPTY
287 foo = []; | dtlib.Type.BYTES
288 foo = [01 02]; | dtlib.Type.BYTES
289 foo = /bits/ 8 <1>; | dtlib.Type.BYTES
290 foo = <1>; | dtlib.Type.NUM
291 foo = <>; | dtlib.Type.NUMS
292 foo = <1 2 3>; | dtlib.Type.NUMS
293 foo = <1 2>, <3>; | dtlib.Type.NUMS
294 foo = "foo"; | dtlib.Type.STRING
295 foo = "foo", "bar"; | dtlib.Type.STRINGS
296 foo = <&l>; | dtlib.Type.PHANDLE
297 foo = <&l1 &l2 &l3>; | dtlib.Type.PHANDLES
298 foo = <&l1 &l2>, <&l3>; | dtlib.Type.PHANDLES
299 foo = <&l1 1 2 &l2 3 4>; | dtlib.Type.PHANDLES_AND_NUMS
300 foo = <&l1 1 2>, <&l2 3 4>; | dtlib.Type.PHANDLES_AND_NUMS
301 foo = &l; | dtlib.Type.PATH
336 node.dt._parse_error("'@' is only allowed in node names")
340 self.lineno = -1
359 def type(self) -> Type:
363 # Data labels (e.g. 'foo = label: <3>') are irrelevant, so filter them
377 # Treat 'foo = <1 2 3>, <4 5>, ...' as Type.NUMS too
400 def to_num(self, signed=False) -> int:
407 foo = < 1 >;
420 def to_nums(self, signed=False) -> list[int]:
427 foo = < 1 2 ... >;
441 def to_bytes(self) -> bytes:
449 foo = [ 01 ... ];
458 def to_string(self) -> str:
465 foo = "string";
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]:
491 foo = "string", "string", ... ;
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:
516 foo = < &bar >;
521 f"'{self.name} = < &foo >;', not '{self}'")
525 def to_nodes(self) -> list[Node]:
532 foo = < >
533 foo = < &bar >;
534 foo = < &bar &baz ... >;
535 foo = < &bar ... >, < &baz ... >;
540 # Also accept 'foo = < >;'
546 f"'{self.name} = < &foo &bar ... >;', not '{self}'")
552 def to_path(self) -> Node:
559 foo = &bar;
560 foo = "/bar";
567 f"'{self.name} = &foo' or '{self.name} = \"/path/to/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])}"'
662 # path references, e.g. 'foo = &bar, <3>;', which are expanded later).
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/;
822 foo {
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:
890 # '/foo'.rpartition('/') is ('', '/', 'foo').
905 def node_iter(self) -> Iterable[Node]:
910 called 'foo':
913 if "foo" in node.props:
923 s = "/dts-v1/;\n\n"
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
1123 # '&foo { ... };' or 'label: &foo { ... };'. The C tools only
1130 self._parse_error("expected label reference (&foo)")
1157 self._parse_error("expected '/' or label reference (&foo)")
1160 # Parses the '{ ... };' part of 'node-name { ... };'.
1163 # of curly braces in order to reject duplicate node names.
1205 "/omit-if-no-ref/ can only be used on nodes")
1214 # ';' is for an empty property, like 'foo;'
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>)
1256 # Got something like 'foo: bar: }'
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 ']'")
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,
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(
1759 "expected label (&foo) or path (&{/foo/bar}) reference")
1769 # Path reference (&{/foo/bar})
1770 path = s[1:-1]
1776 # Label reference (&foo).
1787 # Post-processing
1791 # Registers any manually-inserted phandle properties in
1860 # references, which expand to something like "/foo/bar".
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
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"))
2113 # example, if 'cur' has path /foo/bar, and 'path' is "baz/qaz", then the
2114 # node with path /foo/bar/baz/qaz is returned. 'fullpath' is the path as
2130 def _err(msg) -> NoReturn:
2149 _num_re = re.compile(r"(0[xX][0-9a-fA-F]+|[0-9]+)(?:ULL|UL|LL|U|L)?")
2151 # A leading \ is allowed property and node names, probably to allow weird node
2152 # names that would clash with other stuff
2153 _propnodename_re = re.compile(r"\\?([a-zA-Z0-9,._+*#?@-]+)")
2155 # Node names are more restrictive than property names.
2156 _nodename_chars = set(string.ascii_letters + string.digits + ',._+-@')
2159 # there's overlap with the allowed characters in names.
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