binman: Add a consistent way to report errors with fit

Add a new function to handling reporting errors within a particular
subnode of the FIT description. This can be used to make the format of
these errors consistent.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
This commit is contained in:
Simon Glass
2022-03-05 20:19:09 -07:00
parent 5795497e8b
commit ce4e402a32
2 changed files with 24 additions and 9 deletions

View File

@@ -184,11 +184,11 @@ class Entry_fit(Entry_section):
self._fit_default_dt = self.GetEntryArgsOrProps([EntryArg('default-dt', self._fit_default_dt = self.GetEntryArgsOrProps([EntryArg('default-dt',
str)])[0] str)])[0]
def _get_operation(self, subnode): def _get_operation(self, base_node, node):
"""Get the operation referenced by a subnode """Get the operation referenced by a subnode
Args: Args:
subnode (Node): Subnode (of the FIT) to check node (Node): Subnode (of the FIT) to check
Returns: Returns:
int: Operation to perform int: Operation to perform
@@ -196,12 +196,12 @@ class Entry_fit(Entry_section):
Raises: Raises:
ValueError: Invalid operation name ValueError: Invalid operation name
""" """
oper_name = subnode.props.get('fit,operation') oper_name = node.props.get('fit,operation')
if not oper_name: if not oper_name:
return OP_GEN_FDT_NODES return OP_GEN_FDT_NODES
oper = OPERATIONS.get(oper_name.value) oper = OPERATIONS.get(oper_name.value)
if not oper: if oper is None:
self.Raise(f"Unknown operation '{oper_name.value}'") self._raise_subnode(node, f"Unknown operation '{oper_name.value}'")
return oper return oper
def ReadEntries(self): def ReadEntries(self):
@@ -271,6 +271,19 @@ class Entry_fit(Entry_section):
return tools.read_file(output_fname) return tools.read_file(output_fname)
def _raise_subnode(self, node, msg):
"""Raise an error with a paticular FIT subnode
Args:
node (Node): FIT subnode containing the error
msg (str): Message to report
Raises:
ValueError, as requested
"""
rel_path = node.path[len(self._node.path) + 1:]
self.Raise(f"subnode '{rel_path}': {msg}")
def _build_input(self): def _build_input(self):
"""Finish the FIT by adding the 'data' properties to it """Finish the FIT by adding the 'data' properties to it
@@ -358,7 +371,7 @@ class Entry_fit(Entry_section):
else: else:
self.Raise("Generator node requires 'fit,fdt-list' property") self.Raise("Generator node requires 'fit,fdt-list' property")
def _gen_node(subnode, depth, in_images): def _gen_node(base_node, subnode, depth, in_images):
"""Generate nodes from a template """Generate nodes from a template
This creates one node for each member of self._fdts using the This creates one node for each member of self._fdts using the
@@ -368,12 +381,14 @@ class Entry_fit(Entry_section):
first. first.
Args: Args:
base_node (Node): Base Node of the FIT (with 'description'
property)
subnode (Node): Generator node to process subnode (Node): Generator node to process
depth (int): Current node depth (0 is the base 'fit' node) depth (int): Current node depth (0 is the base 'fit' node)
in_images (bool): True if this is inside the 'images' node, so in_images (bool): True if this is inside the 'images' node, so
that 'data' properties should be generated that 'data' properties should be generated
""" """
oper = self._get_operation(subnode) oper = self._get_operation(base_node, subnode)
if oper == OP_GEN_FDT_NODES: if oper == OP_GEN_FDT_NODES:
_gen_fdt_nodes(subnode, depth, in_images) _gen_fdt_nodes(subnode, depth, in_images)
@@ -414,7 +429,7 @@ class Entry_fit(Entry_section):
elif self.GetImage().generate and subnode.name.startswith('@'): elif self.GetImage().generate and subnode.name.startswith('@'):
subnode_path = f'{rel_path}/{subnode.name}' subnode_path = f'{rel_path}/{subnode.name}'
entry = self._entries.get(subnode_path) entry = self._entries.get(subnode_path)
_gen_node(subnode, depth, in_images) _gen_node(base_node, subnode, depth, in_images)
if entry: if entry:
del self._entries[subnode_path] del self._entries[subnode_path]
else: else:

View File

@@ -5303,7 +5303,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap
"""Check handling of an FDT map when the section cannot be found""" """Check handling of an FDT map when the section cannot be found"""
with self.assertRaises(ValueError) as exc: with self.assertRaises(ValueError) as exc:
self._DoReadFileDtb('224_fit_bad_oper.dts') self._DoReadFileDtb('224_fit_bad_oper.dts')
self.assertIn("Node '/binman/fit': Unknown operation 'unknown'", self.assertIn("Node '/binman/fit': subnode 'images/@fdt-SEQ': Unknown operation 'unknown'",
str(exc.exception)) str(exc.exception))
def test_uses_expand_size(self): def test_uses_expand_size(self):