edtlib: use f-strings where it makes sense
Similarly to what was done for dtlib, use f-strings in places where it improves readability. Some places, e.g. __repr__ methods that construct a string using something like "<SomeType, {}>".format(", ".join(...)) are better left off as-is. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
66ee3d291c
commit
227ce89c41
1 changed files with 105 additions and 112 deletions
|
@ -253,8 +253,8 @@ class EDT:
|
||||||
return f"{self._dt}"
|
return f"{self._dt}"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<EDT for '{}', binding directories '{}'>".format(
|
return f"<EDT for '{self.dts_path}', binding directories " \
|
||||||
self.dts_path, self.bindings_dirs)
|
f"'{self.bindings_dirs}'>"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def scc_order(self):
|
def scc_order(self):
|
||||||
|
@ -674,7 +674,7 @@ class Node:
|
||||||
try:
|
try:
|
||||||
addr = int(self.name.split("@", 1)[1], 16)
|
addr = int(self.name.split("@", 1)[1], 16)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_err("{!r} has non-hex unit address".format(self))
|
_err(f"{self!r} has non-hex unit address")
|
||||||
|
|
||||||
return _translate(addr, self._node)
|
return _translate(addr, self._node)
|
||||||
|
|
||||||
|
@ -777,8 +777,7 @@ class Node:
|
||||||
# parent of the flash node.
|
# parent of the flash node.
|
||||||
|
|
||||||
if not self.parent or not self.parent.parent:
|
if not self.parent or not self.parent.parent:
|
||||||
_err("flash partition {!r} lacks parent or grandparent node"
|
_err(f"flash partition {self!r} lacks parent or grandparent node")
|
||||||
.format(self))
|
|
||||||
|
|
||||||
controller = self.parent.parent
|
controller = self.parent.parent
|
||||||
if controller.matching_compat == "soc-nv-flash":
|
if controller.matching_compat == "soc-nv-flash":
|
||||||
|
@ -793,25 +792,26 @@ class Node:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not self.regs:
|
if not self.regs:
|
||||||
_err("{!r} needs a 'reg' property, to look up the chip select index "
|
_err(f"{self!r} needs a 'reg' property, to look up the "
|
||||||
"for SPI".format(self))
|
"chip select index for SPI")
|
||||||
|
|
||||||
parent_cs_lst = self.bus_node.props["cs-gpios"].val
|
parent_cs_lst = self.bus_node.props["cs-gpios"].val
|
||||||
|
|
||||||
# cs-gpios is indexed by the unit address
|
# cs-gpios is indexed by the unit address
|
||||||
cs_index = self.regs[0].addr
|
cs_index = self.regs[0].addr
|
||||||
if cs_index >= len(parent_cs_lst):
|
if cs_index >= len(parent_cs_lst):
|
||||||
_err("index from 'regs' in {!r} ({}) is >= number of cs-gpios "
|
_err(f"index from 'regs' in {self!r} ({cs_index}) "
|
||||||
"in {!r} ({})".format(
|
"is >= number of cs-gpios in "
|
||||||
self, cs_index, self.bus_node, len(parent_cs_lst)))
|
f"{self.bus_node!r} ({len(parent_cs_lst)})")
|
||||||
|
|
||||||
return parent_cs_lst[cs_index]
|
return parent_cs_lst[cs_index]
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Node {} in '{}', {}>".format(
|
if self.binding_path:
|
||||||
self.path, self.edt.dts_path,
|
binding = "binding " + self.binding_path
|
||||||
"binding " + self.binding_path if self.binding_path
|
else:
|
||||||
else "no binding")
|
binding = "no binding"
|
||||||
|
return f"<Node {self.path} in '{self.edt.dts_path}', {binding}>"
|
||||||
|
|
||||||
def _init_binding(self):
|
def _init_binding(self):
|
||||||
# Initializes Node.matching_compat, Node._binding, and
|
# Initializes Node.matching_compat, Node._binding, and
|
||||||
|
@ -981,7 +981,7 @@ class Node:
|
||||||
name = prop_spec.name
|
name = prop_spec.name
|
||||||
prop_type = prop_spec.type
|
prop_type = prop_spec.type
|
||||||
if not prop_type:
|
if not prop_type:
|
||||||
_err("'{}' in {} lacks 'type'".format(name, self.binding_path))
|
_err(f"'{name}' in {self.binding_path} lacks 'type'")
|
||||||
|
|
||||||
val = self._prop_val(name, prop_type, prop_spec.deprecated,
|
val = self._prop_val(name, prop_type, prop_spec.deprecated,
|
||||||
prop_spec.required, prop_spec.default,
|
prop_spec.required, prop_spec.default,
|
||||||
|
@ -994,17 +994,16 @@ class Node:
|
||||||
|
|
||||||
enum = prop_spec.enum
|
enum = prop_spec.enum
|
||||||
if enum and val not in enum:
|
if enum and val not in enum:
|
||||||
_err("value of property '{}' on {} in {} ({!r}) is not in 'enum' "
|
_err(f"value of property '{name}' on {self.path} in "
|
||||||
"list in {} ({!r})"
|
f"{self.edt.dts_path} ({val!r}) is not in 'enum' list in "
|
||||||
.format(name, self.path, self.edt.dts_path, val,
|
f"{self.binding_path} ({enum!r})")
|
||||||
self.binding_path, enum))
|
|
||||||
|
|
||||||
const = prop_spec.const
|
const = prop_spec.const
|
||||||
if const is not None and val != const:
|
if const is not None and val != const:
|
||||||
_err("value of property '{}' on {} in {} ({!r}) is different from "
|
_err(f"value of property '{name}' on {self.path} in "
|
||||||
"the 'const' value specified in {} ({!r})"
|
f"{self.edt.dts_path} ({val!r}) "
|
||||||
.format(name, self.path, self.edt.dts_path, val,
|
"is different from the 'const' value specified in "
|
||||||
self.binding_path, const))
|
f"{self.binding_path} ({const!r})")
|
||||||
|
|
||||||
# Skip properties that start with '#', like '#size-cells', and mapping
|
# Skip properties that start with '#', like '#size-cells', and mapping
|
||||||
# properties like 'gpio-map'/'interrupt-map'
|
# properties like 'gpio-map'/'interrupt-map'
|
||||||
|
@ -1049,9 +1048,8 @@ class Node:
|
||||||
|
|
||||||
if not prop:
|
if not prop:
|
||||||
if required and self.status == "okay":
|
if required and self.status == "okay":
|
||||||
_err("'{}' is marked as required in 'properties:' in {}, but "
|
_err(f"'{name}' is marked as required in 'properties:' in "
|
||||||
"does not appear in {!r}".format(
|
f"{self.binding_path}, but does not appear in {node!r}")
|
||||||
name, self.binding_path, node))
|
|
||||||
|
|
||||||
if default is not None:
|
if default is not None:
|
||||||
# YAML doesn't have a native format for byte arrays. We need to
|
# YAML doesn't have a native format for byte arrays. We need to
|
||||||
|
@ -1129,10 +1127,9 @@ class Node:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if prop_name not in self._binding.prop2specs:
|
if prop_name not in self._binding.prop2specs:
|
||||||
_err("'{}' appears in {} in {}, but is not declared in "
|
_err(f"'{prop_name}' appears in {self._node.path} in "
|
||||||
"'properties:' in {}"
|
f"{self.edt.dts_path}, but is not declared in "
|
||||||
.format(prop_name, self._node.path, self.edt.dts_path,
|
f"'properties:' in {self.binding_path}")
|
||||||
self.binding_path))
|
|
||||||
|
|
||||||
def _init_regs(self):
|
def _init_regs(self):
|
||||||
# Initializes self.regs
|
# Initializes self.regs
|
||||||
|
@ -1148,8 +1145,8 @@ class Node:
|
||||||
size_cells = _size_cells(node)
|
size_cells = _size_cells(node)
|
||||||
|
|
||||||
for raw_reg in _slice(node, "reg", 4*(address_cells + size_cells),
|
for raw_reg in _slice(node, "reg", 4*(address_cells + size_cells),
|
||||||
"4*(<#address-cells> (= {}) + <#size-cells> (= {}))"
|
f"4*(<#address-cells> (= {address_cells}) + "
|
||||||
.format(address_cells, size_cells)):
|
f"<#size-cells> (= {size_cells}))"):
|
||||||
reg = Register()
|
reg = Register()
|
||||||
reg.node = self
|
reg.node = self
|
||||||
if address_cells == 0:
|
if address_cells == 0:
|
||||||
|
@ -1161,9 +1158,9 @@ class Node:
|
||||||
else:
|
else:
|
||||||
reg.size = to_num(raw_reg[4*address_cells:])
|
reg.size = to_num(raw_reg[4*address_cells:])
|
||||||
if size_cells != 0 and reg.size == 0:
|
if size_cells != 0 and reg.size == 0:
|
||||||
_err("zero-sized 'reg' in {!r} seems meaningless (maybe you "
|
_err(f"zero-sized 'reg' in {self._node!r} seems meaningless "
|
||||||
"want a size of one or #size-cells = 0 instead)"
|
"(maybe you want a size of one or #size-cells = 0 "
|
||||||
.format(self._node))
|
"instead)")
|
||||||
|
|
||||||
self.regs.append(reg)
|
self.regs.append(reg)
|
||||||
|
|
||||||
|
@ -1183,8 +1180,8 @@ class Node:
|
||||||
# Check indices
|
# Check indices
|
||||||
for i, prop in enumerate(pinctrl_props):
|
for i, prop in enumerate(pinctrl_props):
|
||||||
if prop.name != "pinctrl-" + str(i):
|
if prop.name != "pinctrl-" + str(i):
|
||||||
_err("missing 'pinctrl-{}' property on {!r} - indices should "
|
_err(f"missing 'pinctrl-{i}' property on {node!r} "
|
||||||
"be contiguous and start from zero".format(i, node))
|
"- indices should be contiguous and start from zero")
|
||||||
|
|
||||||
self.pinctrls = []
|
self.pinctrls = []
|
||||||
for prop in pinctrl_props:
|
for prop in pinctrl_props:
|
||||||
|
@ -1277,8 +1274,8 @@ class Node:
|
||||||
# byte array.
|
# byte array.
|
||||||
|
|
||||||
if not controller._binding:
|
if not controller._binding:
|
||||||
_err("{} controller {!r} for {!r} lacks binding"
|
_err(f"{basename} controller {controller._node!r} "
|
||||||
.format(basename, controller._node, self._node))
|
f"for {self._node!r} lacks binding")
|
||||||
|
|
||||||
if basename in controller._binding.specifier2cells:
|
if basename in controller._binding.specifier2cells:
|
||||||
cell_names = controller._binding.specifier2cells[basename]
|
cell_names = controller._binding.specifier2cells[basename]
|
||||||
|
@ -1290,10 +1287,9 @@ class Node:
|
||||||
|
|
||||||
data_list = to_nums(data)
|
data_list = to_nums(data)
|
||||||
if len(data_list) != len(cell_names):
|
if len(data_list) != len(cell_names):
|
||||||
_err("unexpected '{}-cells:' length in binding for {!r} - {} "
|
_err(f"unexpected '{basename}-cells:' length in binding for "
|
||||||
"instead of {}"
|
f"{controller._node!r} - {len(cell_names)} "
|
||||||
.format(basename, controller._node, len(cell_names),
|
f"instead of {len(data_list)}")
|
||||||
len(data_list)))
|
|
||||||
|
|
||||||
return OrderedDict(zip(cell_names, data_list))
|
return OrderedDict(zip(cell_names, data_list))
|
||||||
|
|
||||||
|
@ -1365,8 +1361,8 @@ class ControllerAndData:
|
||||||
if self.name is not None:
|
if self.name is not None:
|
||||||
fields.append("name: " + self.name)
|
fields.append("name: " + self.name)
|
||||||
|
|
||||||
fields.append("controller: {}".format(self.controller))
|
fields.append(f"controller: {self.controller}")
|
||||||
fields.append("data: {}".format(self.data))
|
fields.append(f"data: {self.data}")
|
||||||
|
|
||||||
return "<ControllerAndData, {}>".format(", ".join(fields))
|
return "<ControllerAndData, {}>".format(", ".join(fields))
|
||||||
|
|
||||||
|
@ -1497,7 +1493,7 @@ class Property:
|
||||||
"value: " + repr(self.val)]
|
"value: " + repr(self.val)]
|
||||||
|
|
||||||
if self.enum_index is not None:
|
if self.enum_index is not None:
|
||||||
fields.append("enum index: {}".format(self.enum_index))
|
fields.append(f"enum index: {self.enum_index}")
|
||||||
|
|
||||||
return "<Property, {}>".format(", ".join(fields))
|
return "<Property, {}>".format(", ".join(fields))
|
||||||
|
|
||||||
|
@ -2171,17 +2167,16 @@ def _merge_props(to_dict, from_dict, parent, binding_path, check_required):
|
||||||
elif prop not in to_dict:
|
elif prop not in to_dict:
|
||||||
to_dict[prop] = from_dict[prop]
|
to_dict[prop] = from_dict[prop]
|
||||||
elif _bad_overwrite(to_dict, from_dict, prop, check_required):
|
elif _bad_overwrite(to_dict, from_dict, prop, check_required):
|
||||||
_err("{} (in '{}'): '{}' from included file overwritten "
|
_err(f"{binding_path} (in '{parent}'): '{prop}' "
|
||||||
"('{}' replaced with '{}')".format(
|
f"from included file overwritten ('{from_dict[prop]}' "
|
||||||
binding_path, parent, prop, from_dict[prop],
|
f"replaced with '{to_dict[prop]}')")
|
||||||
to_dict[prop]))
|
|
||||||
elif prop == "required":
|
elif prop == "required":
|
||||||
# Need a separate check here, because this code runs before
|
# Need a separate check here, because this code runs before
|
||||||
# Binding._check()
|
# Binding._check()
|
||||||
if not (isinstance(from_dict["required"], bool) and
|
if not (isinstance(from_dict["required"], bool) and
|
||||||
isinstance(to_dict["required"], bool)):
|
isinstance(to_dict["required"], bool)):
|
||||||
_err("malformed 'required:' setting for '{}' in 'properties' "
|
_err(f"malformed 'required:' setting for '{parent}' in "
|
||||||
"in {}, expected true/false".format(parent, binding_path))
|
f"'properties' in {binding_path}, expected true/false")
|
||||||
|
|
||||||
# 'required: true' takes precedence
|
# 'required: true' takes precedence
|
||||||
to_dict["required"] = to_dict["required"] or from_dict["required"]
|
to_dict["required"] = to_dict["required"] or from_dict["required"]
|
||||||
|
@ -2226,23 +2221,24 @@ def _check_prop_type_and_default(prop_name, prop_type, default, binding_path):
|
||||||
# property named 'prop_name'
|
# property named 'prop_name'
|
||||||
|
|
||||||
if prop_type is None:
|
if prop_type is None:
|
||||||
_err("missing 'type:' for '{}' in 'properties' in {}"
|
_err(f"missing 'type:' for '{prop_name}' in 'properties' in "
|
||||||
.format(prop_name, binding_path))
|
f"{binding_path}")
|
||||||
|
|
||||||
ok_types = {"boolean", "int", "array", "uint8-array", "string",
|
ok_types = {"boolean", "int", "array", "uint8-array", "string",
|
||||||
"string-array", "phandle", "phandles", "phandle-array",
|
"string-array", "phandle", "phandles", "phandle-array",
|
||||||
"path", "compound"}
|
"path", "compound"}
|
||||||
|
|
||||||
if prop_type not in ok_types:
|
if prop_type not in ok_types:
|
||||||
_err("'{}' in 'properties:' in {} has unknown type '{}', expected one "
|
_err(f"'{prop_name}' in 'properties:' in {binding_path} "
|
||||||
"of {}".format(prop_name, binding_path, prop_type,
|
f"has unknown type '{prop_type}', expected one of " +
|
||||||
", ".join(ok_types)))
|
", ".join(ok_types))
|
||||||
|
|
||||||
if prop_type == "phandle-array" and not prop_name.endswith("s"):
|
if prop_type == "phandle-array" and not prop_name.endswith("s"):
|
||||||
_err("'{}' in 'properties:' in {} is 'type: phandle-array', but its "
|
_err(f"'{prop_name}' in 'properties:' in {binding_path} "
|
||||||
|
"is 'type: phandle-array', but its "
|
||||||
"name does not end in -s. This is required since property names "
|
"name does not end in -s. This is required since property names "
|
||||||
"like '#pwm-cells' and 'pwm-names' get derived from 'pwms', for "
|
"like '#pwm-cells' and 'pwm-names' get derived from 'pwms', for "
|
||||||
"example.".format(prop_name, binding_path))
|
"example.")
|
||||||
|
|
||||||
# Check default
|
# Check default
|
||||||
|
|
||||||
|
@ -2251,8 +2247,9 @@ def _check_prop_type_and_default(prop_name, prop_type, default, binding_path):
|
||||||
|
|
||||||
if prop_type in {"boolean", "compound", "phandle", "phandles",
|
if prop_type in {"boolean", "compound", "phandle", "phandles",
|
||||||
"phandle-array", "path"}:
|
"phandle-array", "path"}:
|
||||||
_err("'default:' can't be combined with 'type: {}' for '{}' in "
|
_err("'default:' can't be combined with "
|
||||||
"'properties:' in {}".format(prop_type, prop_name, binding_path))
|
f"'type: {prop_type}' for '{prop_name}' in "
|
||||||
|
f"'properties:' in {binding_path}")
|
||||||
|
|
||||||
def ok_default():
|
def ok_default():
|
||||||
# Returns True if 'default' is an okay default for the property's type
|
# Returns True if 'default' is an okay default for the property's type
|
||||||
|
@ -2278,8 +2275,9 @@ def _check_prop_type_and_default(prop_name, prop_type, default, binding_path):
|
||||||
return all(isinstance(val, str) for val in default)
|
return all(isinstance(val, str) for val in default)
|
||||||
|
|
||||||
if not ok_default():
|
if not ok_default():
|
||||||
_err("'default: {}' is invalid for '{}' in 'properties:' in {}, which "
|
_err(f"'default: {default}' is invalid for '{prop_name}' "
|
||||||
"has type {}".format(default, prop_name, binding_path, prop_type))
|
f"in 'properties:' in {binding_path}, "
|
||||||
|
f"which has type {prop_type}")
|
||||||
|
|
||||||
|
|
||||||
def _translate(addr, node):
|
def _translate(addr, node):
|
||||||
|
@ -2312,11 +2310,10 @@ def _translate(addr, node):
|
||||||
entry_cells = child_address_cells + parent_address_cells + child_size_cells
|
entry_cells = child_address_cells + parent_address_cells + child_size_cells
|
||||||
|
|
||||||
for raw_range in _slice(node.parent, "ranges", 4*entry_cells,
|
for raw_range in _slice(node.parent, "ranges", 4*entry_cells,
|
||||||
"4*(<#address-cells> (= {}) + "
|
f"4*(<#address-cells> (= {child_address_cells}) + "
|
||||||
"<#address-cells for parent> (= {}) + "
|
"<#address-cells for parent> "
|
||||||
"<#size-cells> (= {}))"
|
f"(= {parent_address_cells}) + "
|
||||||
.format(child_address_cells, parent_address_cells,
|
f"<#size-cells> (= {child_size_cells}))"):
|
||||||
child_size_cells)):
|
|
||||||
child_addr = to_num(raw_range[:4*child_address_cells])
|
child_addr = to_num(raw_range[:4*child_address_cells])
|
||||||
raw_range = raw_range[4*child_address_cells:]
|
raw_range = raw_range[4*child_address_cells:]
|
||||||
|
|
||||||
|
@ -2351,9 +2348,9 @@ def _add_names(node, names_ident, objs):
|
||||||
if full_names_ident in node.props:
|
if full_names_ident in node.props:
|
||||||
names = node.props[full_names_ident].to_strings()
|
names = node.props[full_names_ident].to_strings()
|
||||||
if len(names) != len(objs):
|
if len(names) != len(objs):
|
||||||
_err("{} property in {} in {} has {} strings, expected {} strings"
|
_err(f"{full_names_ident} property in {node.path} "
|
||||||
.format(full_names_ident, node.path, node.dt.filename,
|
f"in {node.dt.filename} has {len(names)} strings, "
|
||||||
len(names), len(objs)))
|
f"expected {len(objs)} strings")
|
||||||
|
|
||||||
for obj, name in zip(objs, names):
|
for obj, name in zip(objs, names):
|
||||||
if obj is None:
|
if obj is None:
|
||||||
|
@ -2375,8 +2372,8 @@ def _interrupt_parent(node):
|
||||||
return node.props["interrupt-parent"].to_node()
|
return node.props["interrupt-parent"].to_node()
|
||||||
node = node.parent
|
node = node.parent
|
||||||
|
|
||||||
_err("{!r} has an 'interrupts' property, but neither the node nor any "
|
_err(f"{node!r} has an 'interrupts' property, but neither the node "
|
||||||
"of its parents has an 'interrupt-parent' property".format(node))
|
f"nor any of its parents has an 'interrupt-parent' property")
|
||||||
|
|
||||||
|
|
||||||
def _interrupts(node):
|
def _interrupts(node):
|
||||||
|
@ -2420,8 +2417,8 @@ def _map_interrupt(child, parent, child_spec):
|
||||||
|
|
||||||
address_cells = node.props.get("#address-cells")
|
address_cells = node.props.get("#address-cells")
|
||||||
if not address_cells:
|
if not address_cells:
|
||||||
_err("missing #address-cells on {!r} (while handling interrupt-map)"
|
_err(f"missing #address-cells on {node!r} "
|
||||||
.format(node))
|
"(while handling interrupt-map)")
|
||||||
return address_cells.to_num()
|
return address_cells.to_num()
|
||||||
|
|
||||||
def spec_len_fn(node):
|
def spec_len_fn(node):
|
||||||
|
@ -2443,10 +2440,10 @@ def _map_phandle_array_entry(child, parent, child_spec, basename):
|
||||||
# _map_interrupt().
|
# _map_interrupt().
|
||||||
|
|
||||||
def spec_len_fn(node):
|
def spec_len_fn(node):
|
||||||
prop_name = "#{}-cells".format(basename)
|
prop_name = f"#{basename}-cells"
|
||||||
if prop_name not in node.props:
|
if prop_name not in node.props:
|
||||||
_err("expected '{}' property on {!r} (referenced by {!r})"
|
_err(f"expected '{prop_name}' property on {node!r} "
|
||||||
.format(prop_name, node, child))
|
f"(referenced by {child!r})")
|
||||||
return node.props[prop_name].to_num()
|
return node.props[prop_name].to_num()
|
||||||
|
|
||||||
# Do not require <prefix>-controller for anything but interrupts for now
|
# Do not require <prefix>-controller for anything but interrupts for now
|
||||||
|
@ -2483,8 +2480,8 @@ def _map(prefix, child, parent, child_spec, spec_len_fn, require_controller):
|
||||||
map_prop = parent.props.get(prefix + "-map")
|
map_prop = parent.props.get(prefix + "-map")
|
||||||
if not map_prop:
|
if not map_prop:
|
||||||
if require_controller and prefix + "-controller" not in parent.props:
|
if require_controller and prefix + "-controller" not in parent.props:
|
||||||
_err("expected '{}-controller' property on {!r} "
|
_err(f"expected '{prefix}-controller' property on {parent!r} "
|
||||||
"(referenced by {!r})".format(prefix, parent, child))
|
f"(referenced by {child!r})")
|
||||||
|
|
||||||
# No mapping
|
# No mapping
|
||||||
return (parent, child_spec)
|
return (parent, child_spec)
|
||||||
|
@ -2494,26 +2491,23 @@ def _map(prefix, child, parent, child_spec, spec_len_fn, require_controller):
|
||||||
raw = map_prop.value
|
raw = map_prop.value
|
||||||
while raw:
|
while raw:
|
||||||
if len(raw) < len(child_spec):
|
if len(raw) < len(child_spec):
|
||||||
_err("bad value for {!r}, missing/truncated child data"
|
_err(f"bad value for {map_prop!r}, missing/truncated child data")
|
||||||
.format(map_prop))
|
|
||||||
child_spec_entry = raw[:len(child_spec)]
|
child_spec_entry = raw[:len(child_spec)]
|
||||||
raw = raw[len(child_spec):]
|
raw = raw[len(child_spec):]
|
||||||
|
|
||||||
if len(raw) < 4:
|
if len(raw) < 4:
|
||||||
_err("bad value for {!r}, missing/truncated phandle"
|
_err(f"bad value for {map_prop!r}, missing/truncated phandle")
|
||||||
.format(map_prop))
|
|
||||||
phandle = to_num(raw[:4])
|
phandle = to_num(raw[:4])
|
||||||
raw = raw[4:]
|
raw = raw[4:]
|
||||||
|
|
||||||
# Parent specified in *-map
|
# Parent specified in *-map
|
||||||
map_parent = parent.dt.phandle2node.get(phandle)
|
map_parent = parent.dt.phandle2node.get(phandle)
|
||||||
if not map_parent:
|
if not map_parent:
|
||||||
_err("bad phandle ({}) in {!r}".format(phandle, map_prop))
|
_err(f"bad phandle ({phandle}) in {map_prop!r}")
|
||||||
|
|
||||||
map_parent_spec_len = 4*spec_len_fn(map_parent)
|
map_parent_spec_len = 4*spec_len_fn(map_parent)
|
||||||
if len(raw) < map_parent_spec_len:
|
if len(raw) < map_parent_spec_len:
|
||||||
_err("bad value for {!r}, missing/truncated parent data"
|
_err(f"bad value for {map_prop!r}, missing/truncated parent data")
|
||||||
.format(map_prop))
|
|
||||||
parent_spec = raw[:map_parent_spec_len]
|
parent_spec = raw[:map_parent_spec_len]
|
||||||
raw = raw[map_parent_spec_len:]
|
raw = raw[map_parent_spec_len:]
|
||||||
|
|
||||||
|
@ -2527,8 +2521,8 @@ def _map(prefix, child, parent, child_spec, spec_len_fn, require_controller):
|
||||||
return _map(prefix, parent, map_parent, parent_spec, spec_len_fn,
|
return _map(prefix, parent, map_parent, parent_spec, spec_len_fn,
|
||||||
require_controller)
|
require_controller)
|
||||||
|
|
||||||
_err("child specifier for {!r} ({}) does not appear in {!r}"
|
_err(f"child specifier for {child!r} ({child_spec}) "
|
||||||
.format(child, child_spec, map_prop))
|
f"does not appear in {map_prop!r}")
|
||||||
|
|
||||||
|
|
||||||
def _mask(prefix, child, parent, child_spec):
|
def _mask(prefix, child, parent, child_spec):
|
||||||
|
@ -2542,8 +2536,8 @@ def _mask(prefix, child, parent, child_spec):
|
||||||
|
|
||||||
mask = mask_prop.value
|
mask = mask_prop.value
|
||||||
if len(mask) != len(child_spec):
|
if len(mask) != len(child_spec):
|
||||||
_err("{!r}: expected '{}-mask' in {!r} to be {} bytes, is {} bytes"
|
_err(f"{child!r}: expected '{prefix}-mask' in {parent!r} "
|
||||||
.format(child, prefix, parent, len(child_spec), len(mask)))
|
f"to be {len(child_spec)} bytes, is {len(mask)} bytes")
|
||||||
|
|
||||||
return _and(child_spec, mask)
|
return _and(child_spec, mask)
|
||||||
|
|
||||||
|
@ -2564,8 +2558,8 @@ def _pass_thru(prefix, child, parent, child_spec, parent_spec):
|
||||||
|
|
||||||
pass_thru = pass_thru_prop.value
|
pass_thru = pass_thru_prop.value
|
||||||
if len(pass_thru) != len(child_spec):
|
if len(pass_thru) != len(child_spec):
|
||||||
_err("{!r}: expected '{}-map-pass-thru' in {!r} to be {} bytes, is {} bytes"
|
_err(f"{child!r}: expected '{prefix}-map-pass-thru' in {parent!r} "
|
||||||
.format(child, prefix, parent, len(child_spec), len(pass_thru)))
|
f"to be {len(child_spec)} bytes, is {len(pass_thru)} bytes")
|
||||||
|
|
||||||
res = _or(_and(child_spec, pass_thru),
|
res = _or(_and(child_spec, pass_thru),
|
||||||
_and(parent_spec, _not(pass_thru)))
|
_and(parent_spec, _not(pass_thru)))
|
||||||
|
@ -2579,14 +2573,14 @@ def _raw_unit_addr(node):
|
||||||
# #address-cells) as a raw 'bytes'
|
# #address-cells) as a raw 'bytes'
|
||||||
|
|
||||||
if 'reg' not in node.props:
|
if 'reg' not in node.props:
|
||||||
_err("{!r} lacks 'reg' property (needed for 'interrupt-map' unit "
|
_err(f"{node!r} lacks 'reg' property "
|
||||||
"address lookup)".format(node))
|
"(needed for 'interrupt-map' unit address lookup)")
|
||||||
|
|
||||||
addr_len = 4*_address_cells(node)
|
addr_len = 4*_address_cells(node)
|
||||||
|
|
||||||
if len(node.props['reg'].value) < addr_len:
|
if len(node.props['reg'].value) < addr_len:
|
||||||
_err("{!r} has too short 'reg' property (while doing 'interrupt-map' "
|
_err(f"{node!r} has too short 'reg' property "
|
||||||
"unit address lookup)".format(node))
|
"(while doing 'interrupt-map' unit address lookup)")
|
||||||
|
|
||||||
return node.props['reg'].value[:addr_len]
|
return node.props['reg'].value[:addr_len]
|
||||||
|
|
||||||
|
@ -2636,7 +2630,7 @@ def _phandle_val_list(prop, n_cells_name):
|
||||||
# is the node pointed at by <phandle>. If <phandle> does not refer
|
# is the node pointed at by <phandle>. If <phandle> does not refer
|
||||||
# to a node, the entire list element is None.
|
# to a node, the entire list element is None.
|
||||||
|
|
||||||
full_n_cells_name = "#{}-cells".format(n_cells_name)
|
full_n_cells_name = f"#{n_cells_name}-cells"
|
||||||
|
|
||||||
res = []
|
res = []
|
||||||
|
|
||||||
|
@ -2656,7 +2650,7 @@ def _phandle_val_list(prop, n_cells_name):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if full_n_cells_name not in node.props:
|
if full_n_cells_name not in node.props:
|
||||||
_err("{!r} lacks {}".format(node, full_n_cells_name))
|
_err(f"{node!r} lacks {full_n_cells_name}")
|
||||||
|
|
||||||
n_cells = node.props[full_n_cells_name].to_num()
|
n_cells = node.props[full_n_cells_name].to_num()
|
||||||
if len(raw) < 4*n_cells:
|
if len(raw) < 4*n_cells:
|
||||||
|
@ -2691,7 +2685,7 @@ def _interrupt_cells(node):
|
||||||
# 'node' has no #interrupt-cells property
|
# 'node' has no #interrupt-cells property
|
||||||
|
|
||||||
if "#interrupt-cells" not in node.props:
|
if "#interrupt-cells" not in node.props:
|
||||||
_err("{!r} lacks #interrupt-cells".format(node))
|
_err(f"{node!r} lacks #interrupt-cells")
|
||||||
return node.props["#interrupt-cells"].to_num()
|
return node.props["#interrupt-cells"].to_num()
|
||||||
|
|
||||||
|
|
||||||
|
@ -2703,11 +2697,10 @@ def _slice(node, prop_name, size, size_hint):
|
||||||
|
|
||||||
raw = node.props[prop_name].value
|
raw = node.props[prop_name].value
|
||||||
if len(raw) % size:
|
if len(raw) % size:
|
||||||
_err("'{}' property in {!r} has length {}, which is not evenly "
|
_err(f"'{prop_name}' property in {node!r} has length {len(raw)}, "
|
||||||
"divisible by {} (= {}). Note that #*-cells "
|
f"which is not evenly divisible by {size} (= {size_hint}). "
|
||||||
"properties come either from the parent node or from the "
|
"Note that #*-cells properties come either from the parent node or "
|
||||||
"controller (in the case of 'interrupts')."
|
"from the controller (in the case of 'interrupts').")
|
||||||
.format(prop_name, node, len(raw), size, size_hint))
|
|
||||||
|
|
||||||
return [raw[i:i + size] for i in range(0, len(raw), size)]
|
return [raw[i:i + size] for i in range(0, len(raw), size)]
|
||||||
|
|
||||||
|
@ -2731,17 +2724,17 @@ def _check_dt(dt):
|
||||||
_err(str(e))
|
_err(str(e))
|
||||||
|
|
||||||
if status_val not in ok_status:
|
if status_val not in ok_status:
|
||||||
_err("unknown 'status' value \"{}\" in {} in {}, expected one "
|
_err(f"unknown 'status' value \"{status_val}\" in {node.path} "
|
||||||
"of {} (see the devicetree specification)"
|
f"in {node.dt.filename}, expected one of " +
|
||||||
.format(status_val, node.path, node.dt.filename,
|
", ".join(ok_status) +
|
||||||
", ".join(ok_status)))
|
" (see the devicetree specification)")
|
||||||
|
|
||||||
ranges_prop = node.props.get("ranges")
|
ranges_prop = node.props.get("ranges")
|
||||||
if ranges_prop:
|
if ranges_prop:
|
||||||
if ranges_prop.type not in (Type.EMPTY, Type.NUMS):
|
if ranges_prop.type not in (Type.EMPTY, Type.NUMS):
|
||||||
_err("expected 'ranges = < ... >;' in {} in {}, not '{}' "
|
_err(f"expected 'ranges = < ... >;' in {node.path} in "
|
||||||
"(see the devicetree specification)"
|
f"{node.dt.filename}, not '{ranges_prop}' "
|
||||||
.format(node.path, node.dt.filename, ranges_prop))
|
"(see the devicetree specification)")
|
||||||
|
|
||||||
|
|
||||||
def _err(msg):
|
def _err(msg):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue