From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Quentin Schulz <quentin.schulz@theobroma-systems.com>,
Alper Nebi Yasak <alpernebiyasak@gmail.com>,
Philippe Reynes <philippe.reynes@softathome.com>,
Marek Vasut <marex@denx.de>, Simon Glass <sjg@chromium.org>
Subject: [PATCH v2 05/11] binman: Add a way to check for missing properties
Date: Sat, 13 Aug 2022 11:40:44 -0600 [thread overview]
Message-ID: <20220813174051.1813081-6-sjg@chromium.org> (raw)
In-Reply-To: <20220813174051.1813081-1-sjg@chromium.org>
Some new entries are likely to have required properties. Support this in a
standard way, with a list of required properties which can be set up by
base classes. Check for missing properties when the entry is read.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v2:
- Use a dict to hold required properties
tools/binman/entry.py | 20 ++++++++++++++++++++
tools/binman/etype/fill.py | 3 +--
tools/binman/ftest.py | 2 +-
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 41f0eb58ae0..5424a0e6e32 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -84,6 +84,8 @@ class Entry(object):
update_hash: True if this entry's "hash" subnode should be
updated with a hash of the entry contents
fake_fname: Fake filename, if one was created, else None
+ required_props (dict of str): Properties which must be present. This can
+ be added to by subclasses
"""
fake_dir = None
@@ -121,6 +123,7 @@ class Entry(object):
self.missing_bintools = []
self.update_hash = True
self.fake_fname = None
+ self.required_props = []
@staticmethod
def FindEntryClass(etype, expanded):
@@ -238,6 +241,7 @@ class Entry(object):
This reads all the fields we recognise from the node, ready for use.
"""
+ self.ensure_props()
if 'pos' in self._node.props:
self.Raise("Please use 'offset' instead of 'pos'")
if 'expand-size' in self._node.props:
@@ -1179,3 +1183,19 @@ features to produce new behaviours.
if not os.path.exists(cls.fake_dir):
os.mkdir(cls.fake_dir)
tout.notice(f"Fake-blob dir is '{cls.fake_dir}'")
+
+ def ensure_props(self):
+ """Raise an exception if properties are missing
+
+ Args:
+ prop_list (list of str): List of properties to check for
+
+ Raises:
+ ValueError: Any property is missing
+ """
+ not_present = []
+ for prop in self.required_props:
+ if not prop in self._node.props:
+ not_present.append(prop)
+ if not_present:
+ self.Raise(f"'{self.etype}' entry is missing properties: {' '.join(not_present)}")
diff --git a/tools/binman/etype/fill.py b/tools/binman/etype/fill.py
index cd382799199..c91d0152a8a 100644
--- a/tools/binman/etype/fill.py
+++ b/tools/binman/etype/fill.py
@@ -23,11 +23,10 @@ class Entry_fill(Entry):
"""
def __init__(self, section, etype, node):
super().__init__(section, etype, node)
+ self.required_props = ['size']
def ReadNode(self):
super().ReadNode()
- if self.size is None:
- self.Raise("'fill' entry must have a size property")
self.fill_value = fdt_util.GetByte(self._node, 'fill-byte', 0)
def ObtainContents(self):
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index c8bab5c9416..4f696c68600 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1693,7 +1693,7 @@ class TestFunctional(unittest.TestCase):
"""Test for an fill entry type with no size"""
with self.assertRaises(ValueError) as e:
self._DoReadFile('070_fill_no_size.dts')
- self.assertIn("'fill' entry must have a size property",
+ self.assertIn("'fill' entry is missing properties: size",
str(e.exception))
def _HandleGbbCommand(self, pipe_list):
--
2.37.1.595.g718a3a8f04-goog
next prev parent reply other threads:[~2022-08-13 17:41 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-13 17:40 [PATCH v2 00/11] binman: Enhancements to binman mkimage Simon Glass
2022-08-13 17:40 ` [PATCH v2 01/11] doc: Build documentation in parallel Simon Glass
2022-08-20 21:33 ` Simon Glass
2022-08-27 1:59 ` Simon Glass
2022-08-13 17:40 ` [PATCH v2 02/11] patman: Put the coverage command-line last Simon Glass
2022-08-13 17:40 ` [PATCH v2 03/11] patman: Don't buffer test output with a single test Simon Glass
2022-08-13 17:40 ` [PATCH v2 04/11] binman: Fix up the entry-docs for Entry_pre_load Simon Glass
2022-08-13 17:40 ` Simon Glass [this message]
2022-08-13 17:40 ` [PATCH v2 06/11] binman: Adjust mkimage etype node reading Simon Glass
2022-08-13 17:40 ` [PATCH v2 07/11] binman: Avoid use of expected failure Simon Glass
2022-08-13 17:40 ` [PATCH v2 08/11] binman: Improve mkimage documentation Simon Glass
2022-08-13 17:40 ` [PATCH v2 09/11] binman: Allow the image name to be the data file Simon Glass
2022-08-13 17:40 ` [PATCH v2 10/11] binman: Allow passing entries using -n Simon Glass
2022-08-13 17:40 ` [PATCH v2 11/11] binman: Allow collection to use entries from other sections Simon Glass
2022-08-21 0:10 ` Simon Glass
2022-08-21 0:10 ` [PATCH v2 09/11] binman: Allow the image name to be the data file Simon Glass
2022-08-21 0:10 ` [PATCH v2 10/11] binman: Allow passing entries using -n Simon Glass
2022-08-21 0:10 ` [PATCH v2 08/11] binman: Improve mkimage documentation Simon Glass
2022-08-21 0:10 ` [PATCH v2 07/11] binman: Avoid use of expected failure Simon Glass
2022-08-21 0:10 ` [PATCH v2 06/11] binman: Adjust mkimage etype node reading Simon Glass
2022-08-21 0:10 ` [PATCH v2 05/11] binman: Add a way to check for missing properties Simon Glass
2022-08-21 0:10 ` [PATCH v2 04/11] binman: Fix up the entry-docs for Entry_pre_load Simon Glass
2022-08-21 0:10 ` [PATCH v2 03/11] patman: Don't buffer test output with a single test Simon Glass
2022-08-21 0:10 ` [PATCH v2 02/11] patman: Put the coverage command-line last Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220813174051.1813081-6-sjg@chromium.org \
--to=sjg@chromium.org \
--cc=alpernebiyasak@gmail.com \
--cc=marex@denx.de \
--cc=philippe.reynes@softathome.com \
--cc=quentin.schulz@theobroma-systems.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).