public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
To: u-boot@lists.denx.de
Cc: Heiko Thiery <heiko.thiery@gmail.com>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Simon Glass <sjg@chromium.org>,
	Alper Nebi Yasak <alpernebiyasak@gmail.com>
Subject: [PATCH v2 4/5] binman: Convert FIT entry type to a subclass of Section entry type
Date: Tue,  8 Feb 2022 01:08:07 +0300	[thread overview]
Message-ID: <20220207220809.4497-5-alpernebiyasak@gmail.com> (raw)
In-Reply-To: <20220207220809.4497-1-alpernebiyasak@gmail.com>

The binman FIT entry type shares some code with the Section entry type.
This shared code is bound to grow, since FIT entries are conceptually a
variation of Section entries.

Make FIT entry type a subclass of Section entry type, simplifying it a
bit and providing us the features that Section implements. Also fix the
subentry alignment test which now attempts to write symbols to a
nonexistent SPL ELF test file by creating it first.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Add tag: "Reviewed-by: Simon Glass <sjg@chromium.org>"

 tools/binman/etype/fit.py | 70 +++++++++++----------------------------
 tools/binman/ftest.py     |  1 +
 2 files changed, 20 insertions(+), 51 deletions(-)

diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
index 9dffcd5adbd6..0f8c88a9720e 100644
--- a/tools/binman/etype/fit.py
+++ b/tools/binman/etype/fit.py
@@ -9,11 +9,12 @@
 import libfdt
 
 from binman.entry import Entry, EntryArg
+from binman.etype.section import Entry_section
 from dtoc import fdt_util
 from dtoc.fdt import Fdt
 from patman import tools
 
-class Entry_fit(Entry):
+class Entry_fit(Entry_section):
     """Flat Image Tree (FIT)
 
     This calls mkimage to create a FIT (U-Boot Flat Image Tree) based on the
@@ -112,15 +113,15 @@ def __init__(self, section, etype, node):
         """
         Members:
             _fit: FIT file being built
-            _fit_sections: dict:
+            _entries: dict from Entry_section:
                 key: relative path to entry Node (from the base of the FIT)
                 value: Entry_section object comprising the contents of this
                     node
         """
         super().__init__(section, etype, node)
         self._fit = None
-        self._fit_sections = {}
         self._fit_props = {}
+
         for pname, prop in self._node.props.items():
             if pname.startswith('fit,'):
                 self._fit_props[pname] = prop
@@ -185,7 +186,7 @@ def _AddNode(base_node, depth, node):
                 # 'data' property later.
                 entry = Entry.Create(self.section, node, etype='section')
                 entry.ReadNode()
-                self._fit_sections[rel_path] = entry
+                self._entries[rel_path] = entry
 
             for subnode in node.subnodes:
                 if has_images and not (subnode.name.startswith('hash') or
@@ -237,18 +238,19 @@ def _AddNode(base_node, depth, node):
         self._fdt = Fdt.FromData(fdt.as_bytearray())
         self._fdt.Scan()
 
-    def ExpandEntries(self):
-        super().ExpandEntries()
-        for section in self._fit_sections.values():
-            section.ExpandEntries()
-
-    def ObtainContents(self):
-        """Obtain the contents of the FIT
+    def BuildSectionData(self, required):
+        """Build FIT entry contents
 
         This adds the 'data' properties to the input ITB (Image-tree Binary)
         then runs mkimage to process it.
+
+        Args:
+            required: True if the data must be present, False if it is OK to
+                return None
+
+        Returns:
+            Contents of the section (bytes)
         """
-        # self._BuildInput() either returns bytes or raises an exception.
         data = self._BuildInput(self._fdt)
         uniq = self.GetUniqueName()
         input_fname = tools.GetOutputFilename('%s.itb' % uniq)
@@ -264,14 +266,12 @@ def ObtainContents(self):
                 'pad': fdt_util.fdt32_to_cpu(ext_offset.value)
                 }
         if self.mkimage.run(reset_timestamp=True, output_fname=output_fname,
-                            **args) is not None:
-            self.SetContents(tools.ReadFile(output_fname))
-        else:
+                            **args) is None:
             # Bintool is missing; just use empty data as the output
             self.record_missing_bintool(self.mkimage)
-            self.SetContents(tools.GetBytes(0, 1024))
+            return tools.GetBytes(0, 1024)
 
-        return True
+        return tools.ReadFile(output_fname)
 
     def _BuildInput(self, fdt):
         """Finish the FIT by adding the 'data' properties to it
@@ -282,12 +282,8 @@ def _BuildInput(self, fdt):
         Returns:
             New fdt contents (bytes)
         """
-        for path, section in self._fit_sections.items():
+        for path, section in self._entries.items():
             node = fdt.GetNode(path)
-            # Entry_section.ObtainContents() either returns True or
-            # raises an exception.
-            section.ObtainContents()
-            section.Pack(0)
             data = section.GetData()
             node.AddData('data', data)
 
@@ -295,34 +291,6 @@ def _BuildInput(self, fdt):
         data = fdt.GetContents()
         return data
 
-    def CheckMissing(self, missing_list):
-        """Check if any entries in this FIT have missing external blobs
-
-        If there are missing blobs, the entries are added to the list
-
-        Args:
-            missing_list: List of Entry objects to be added to
-        """
-        for path, section in self._fit_sections.items():
-            section.CheckMissing(missing_list)
-
-    def SetAllowMissing(self, allow_missing):
-        for section in self._fit_sections.values():
-            section.SetAllowMissing(allow_missing)
-
     def AddBintools(self, tools):
-        for section in self._fit_sections.values():
-            section.AddBintools(tools)
+        super().AddBintools(tools)
         self.mkimage = self.AddBintool(tools, 'mkimage')
-
-    def check_missing_bintools(self, missing_list):
-        """Check if any entries in this section have missing bintools
-
-        If there are missing bintools, these are added to the list
-
-        Args:
-            missing_list: List of Bintool objects to be added to
-        """
-        super().check_missing_bintools(missing_list)
-        for entry in self._fit_sections.values():
-            entry.check_missing_bintools(missing_list)
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index bc073587cc07..f16798960b84 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -3850,6 +3850,7 @@ def testPadInSections(self):
 
     def testFitImageSubentryAlignment(self):
         """Test relative alignability of FIT image subentries"""
+        self._SetupSplElf()
         entry_args = {
             'test-id': TEXT_DATA,
         }
-- 
2.34.1


  parent reply	other threads:[~2022-02-07 22:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-07 22:08 [PATCH v2 0/5] binman: Improvements to FIT entry type Alper Nebi Yasak
2022-02-07 22:08 ` [PATCH v2 1/5] binman: Fix subentry expansion for " Alper Nebi Yasak
2022-02-08 15:05   ` Simon Glass
2022-02-08 20:39     ` Simon Glass
2022-02-07 22:08 ` [PATCH v2 2/5] binman: Register and check bintools from FIT subentries Alper Nebi Yasak
2022-02-08 20:39   ` Simon Glass
2022-02-07 22:08 ` [PATCH v2 3/5] binman: Check missing bintools of Section subclasses Alper Nebi Yasak
2022-02-08 20:39   ` Simon Glass
2022-02-07 22:08 ` Alper Nebi Yasak [this message]
2022-02-08 20:39   ` [PATCH v2 4/5] binman: Convert FIT entry type to a subclass of Section entry type Simon Glass
2022-02-14  9:09   ` Jan Kiszka
2022-02-15 12:27     ` Alper Nebi Yasak
2022-02-15 16:50       ` Jan Kiszka
2022-02-15 17:06         ` Jan Kiszka
2022-02-18 16:50           ` Jan Kiszka
2022-02-18 17:34             ` Alper Nebi Yasak
2022-02-19 15:53               ` Simon Glass
2022-02-21  4:40                 ` Simon Glass
2022-02-22 18:58                   ` Alper Nebi Yasak
2022-02-23 22:59                     ` Simon Glass
2022-02-28 11:48                       ` Jan Kiszka
2022-02-28 13:51                         ` Alper Nebi Yasak
2022-02-28 13:56                         ` Simon Glass
2022-02-28 14:14                           ` Jan Kiszka
2022-02-07 22:08 ` [PATCH v2 5/5] binman: Update image positions of FIT subentries Alper Nebi Yasak
2022-02-08 20:43   ` Simon Glass
2022-02-23  2:35     ` 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=20220207220809.4497-5-alpernebiyasak@gmail.com \
    --to=alpernebiyasak@gmail.com \
    --cc=heiko.thiery@gmail.com \
    --cc=jan.kiszka@siemens.com \
    --cc=sjg@chromium.org \
    --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