u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] binman: Skip processing "hash" subnodes of FIT subsections
@ 2022-02-09 19:02 Alper Nebi Yasak
  2022-02-11 15:05 ` Simon Glass
  2022-02-23  2:34 ` Simon Glass
  0 siblings, 2 replies; 3+ messages in thread
From: Alper Nebi Yasak @ 2022-02-09 19:02 UTC (permalink / raw)
  To: u-boot; +Cc: Heiko Thiery, Jan Kiszka, Simon Glass, Alper Nebi Yasak

Binman's FIT entry type can have image subentries with "hash" subnodes
intended to be processed by mkimage, but not binman. However, the Entry
class and any subclass that reuses its implementation tries to process
these unconditionally. This can lead to an error when boards specify
hash algorithms that binman doesn't support, but mkimage supports.

Let entries skip processing these "hash" subnodes based on an instance
variable, and set this instance variable for FIT subsections. Also
re-enable processing of calculated and missing properties of FIT entries
which was disabled to mitigate this issue.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
---
This applies on top of u-boot-dm/master, and does not resend my
"binman: Update image positions of FIT subentries" patch [1] which
should be applied on top of this.

[1] https://patchwork.ozlabs.org/project/uboot/patch/20220207220809.4497-6-alpernebiyasak@gmail.com/

Changes in v2:
- Set update_hash via a SetUpdateHash() method
- Add a test using hash nodes in FIT subentries

v1: https://patchwork.ozlabs.org/project/uboot/patch/20220208230656.43504-1-alpernebiyasak@gmail.com/

 tools/binman/entry.py                       | 23 +++++++--
 tools/binman/etype/fit.py                   | 12 +----
 tools/binman/ftest.py                       | 24 ++++++++++
 tools/binman/test/221_fit_subentry_hash.dts | 52 +++++++++++++++++++++
 4 files changed, 97 insertions(+), 14 deletions(-)
 create mode 100644 tools/binman/test/221_fit_subentry_hash.dts

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index dc26f8f167b0..631215dfc88a 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -78,6 +78,8 @@ class Entry(object):
         external: True if this entry contains an external binary blob
         bintools: Bintools used by this entry (only populated for Image)
         missing_bintools: List of missing bintools for this entry
+        update_hash: True if this entry's "hash" subnode should be
+            updated with a hash of the entry contents
     """
     def __init__(self, section, etype, node, name_prefix=''):
         # Put this here to allow entry-docs and help to work without libfdt
@@ -111,6 +113,7 @@ def __init__(self, section, etype, node, name_prefix=''):
         self.allow_fake = False
         self.bintools = {}
         self.missing_bintools = []
+        self.update_hash = True
 
     @staticmethod
     def FindEntryClass(etype, expanded):
@@ -315,9 +318,11 @@ def AddMissingProperties(self, have_image_pos):
 
         if self.compress != 'none':
             state.AddZeroProp(self._node, 'uncomp-size')
-        err = state.CheckAddHashProp(self._node)
-        if err:
-            self.Raise(err)
+
+        if self.update_hash:
+            err = state.CheckAddHashProp(self._node)
+            if err:
+                self.Raise(err)
 
     def SetCalculatedProperties(self):
         """Set the value of device-tree properties calculated by binman"""
@@ -333,7 +338,9 @@ def SetCalculatedProperties(self):
                 state.SetInt(self._node, 'orig-size', self.orig_size, True)
         if self.uncomp_size is not None:
             state.SetInt(self._node, 'uncomp-size', self.uncomp_size)
-        state.CheckSetHashValue(self._node, self.GetData)
+
+        if self.update_hash:
+            state.CheckSetHashValue(self._node, self.GetData)
 
     def ProcessFdt(self, fdt):
         """Allow entries to adjust the device tree
@@ -1108,3 +1115,11 @@ def AddBintool(self, tools, name):
         btool = bintool.Bintool.create(name)
         tools[name] = btool
         return btool
+
+    def SetUpdateHash(self, update_hash):
+        """Set whether this entry's "hash" subnode should be updated
+
+        Args:
+            update_hash: True if hash should be updated, False if not
+        """
+        self.update_hash = update_hash
diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
index a56b0564f9a1..cd7ebc571e27 100644
--- a/tools/binman/etype/fit.py
+++ b/tools/binman/etype/fit.py
@@ -186,6 +186,8 @@ def _AddNode(base_node, depth, node):
                 # 'data' property later.
                 entry = Entry.Create(self.section, node, etype='section')
                 entry.ReadNode()
+                # The hash subnodes here are for mkimage, not binman.
+                entry.SetUpdateHash(False)
                 self._entries[rel_path] = entry
 
             for subnode in node.subnodes:
@@ -294,13 +296,3 @@ def _BuildInput(self, fdt):
     def AddBintools(self, tools):
         super().AddBintools(tools)
         self.mkimage = self.AddBintool(tools, 'mkimage')
-
-    def AddMissingProperties(self, have_image_pos):
-        # We don't want to interfere with any hash properties in the FIT, so
-        # disable this for now.
-        pass
-
-    def SetCalculatedProperties(self):
-        # We don't want to interfere with any hash properties in the FIT, so
-        # disable this for now.
-        pass
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 59b6d52fbe4b..b6801b727568 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -5160,5 +5160,29 @@ def testFitSubentryMissingBintool(self):
         self.assertRegex(err,
                          "Image 'main-section'.*missing bintools.*: futility")
 
+    def testFitSubentryHashSubnode(self):
+        """Test an image with a FIT inside"""
+        data, _, _, out_dtb_name = self._DoReadFileDtb(
+            '221_fit_subentry_hash.dts', use_real_dtb=True, update_dtb=True)
+
+        mkimage_dtb = fdt.Fdt.FromData(data)
+        mkimage_dtb.Scan()
+        binman_dtb = fdt.Fdt(out_dtb_name)
+        binman_dtb.Scan()
+
+        # Check that binman didn't add hash values
+        fnode = binman_dtb.GetNode('/binman/fit/images/kernel/hash')
+        self.assertNotIn('value', fnode.props)
+
+        fnode = binman_dtb.GetNode('/binman/fit/images/fdt-1/hash')
+        self.assertNotIn('value', fnode.props)
+
+        # Check that mkimage added hash values
+        fnode = mkimage_dtb.GetNode('/images/kernel/hash')
+        self.assertIn('value', fnode.props)
+
+        fnode = mkimage_dtb.GetNode('/images/fdt-1/hash')
+        self.assertIn('value', fnode.props)
+
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/221_fit_subentry_hash.dts b/tools/binman/test/221_fit_subentry_hash.dts
new file mode 100644
index 000000000000..2cb04f96d088
--- /dev/null
+++ b/tools/binman/test/221_fit_subentry_hash.dts
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		fit {
+			description = "test-desc";
+			#address-cells = <1>;
+
+			images {
+				kernel {
+					description = "Vanilla Linux kernel";
+					type = "kernel";
+					arch = "ppc";
+					os = "linux";
+					compression = "gzip";
+					load = <00000000>;
+					entry = <00000000>;
+					hash {
+						algo = "sha1";
+					};
+					u-boot {
+					};
+				};
+				fdt-1 {
+					description = "Flattened Device Tree blob";
+					type = "flat_dt";
+					arch = "ppc";
+					compression = "none";
+					hash {
+						algo = "crc32";
+					};
+					u-boot-spl-dtb {
+					};
+				};
+			};
+
+			configurations {
+				default = "conf-1";
+				conf-1 {
+					description = "Boot Linux kernel with FDT blob";
+					kernel = "kernel";
+					fdt = "fdt-1";
+				};
+			};
+		};
+	};
+};
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] binman: Skip processing "hash" subnodes of FIT subsections
  2022-02-09 19:02 [PATCH v2] binman: Skip processing "hash" subnodes of FIT subsections Alper Nebi Yasak
@ 2022-02-11 15:05 ` Simon Glass
  2022-02-23  2:34 ` Simon Glass
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2022-02-11 15:05 UTC (permalink / raw)
  To: Alper Nebi Yasak; +Cc: U-Boot Mailing List, Heiko Thiery, Jan Kiszka

On Wed, 9 Feb 2022 at 12:02, Alper Nebi Yasak <alpernebiyasak@gmail.com> wrote:
>
> Binman's FIT entry type can have image subentries with "hash" subnodes
> intended to be processed by mkimage, but not binman. However, the Entry
> class and any subclass that reuses its implementation tries to process
> these unconditionally. This can lead to an error when boards specify
> hash algorithms that binman doesn't support, but mkimage supports.
>
> Let entries skip processing these "hash" subnodes based on an instance
> variable, and set this instance variable for FIT subsections. Also
> re-enable processing of calculated and missing properties of FIT entries
> which was disabled to mitigate this issue.
>
> Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
> ---
> This applies on top of u-boot-dm/master, and does not resend my
> "binman: Update image positions of FIT subentries" patch [1] which
> should be applied on top of this.
>
> [1] https://patchwork.ozlabs.org/project/uboot/patch/20220207220809.4497-6-alpernebiyasak@gmail.com/
>
> Changes in v2:
> - Set update_hash via a SetUpdateHash() method
> - Add a test using hash nodes in FIT subentries
>
> v1: https://patchwork.ozlabs.org/project/uboot/patch/20220208230656.43504-1-alpernebiyasak@gmail.com/
>
>  tools/binman/entry.py                       | 23 +++++++--
>  tools/binman/etype/fit.py                   | 12 +----
>  tools/binman/ftest.py                       | 24 ++++++++++
>  tools/binman/test/221_fit_subentry_hash.dts | 52 +++++++++++++++++++++
>  4 files changed, 97 insertions(+), 14 deletions(-)
>  create mode 100644 tools/binman/test/221_fit_subentry_hash.dts
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] binman: Skip processing "hash" subnodes of FIT subsections
  2022-02-09 19:02 [PATCH v2] binman: Skip processing "hash" subnodes of FIT subsections Alper Nebi Yasak
  2022-02-11 15:05 ` Simon Glass
@ 2022-02-23  2:34 ` Simon Glass
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2022-02-23  2:34 UTC (permalink / raw)
  To: Simon Glass
  Cc: U-Boot Mailing List, Heiko Thiery, Jan Kiszka, Alper Nebi Yasak

On Wed, 9 Feb 2022 at 12:02, Alper Nebi Yasak <alpernebiyasak@gmail.com> wrote:
>
> Binman's FIT entry type can have image subentries with "hash" subnodes
> intended to be processed by mkimage, but not binman. However, the Entry
> class and any subclass that reuses its implementation tries to process
> these unconditionally. This can lead to an error when boards specify
> hash algorithms that binman doesn't support, but mkimage supports.
>
> Let entries skip processing these "hash" subnodes based on an instance
> variable, and set this instance variable for FIT subsections. Also
> re-enable processing of calculated and missing properties of FIT entries
> which was disabled to mitigate this issue.
>
> Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
> ---
> This applies on top of u-boot-dm/master, and does not resend my
> "binman: Update image positions of FIT subentries" patch [1] which
> should be applied on top of this.
>
> [1] https://patchwork.ozlabs.org/project/uboot/patch/20220207220809.4497-6-alpernebiyasak@gmail.com/
>
> Changes in v2:
> - Set update_hash via a SetUpdateHash() method
> - Add a test using hash nodes in FIT subentries
>
> v1: https://patchwork.ozlabs.org/project/uboot/patch/20220208230656.43504-1-alpernebiyasak@gmail.com/
>
>  tools/binman/entry.py                       | 23 +++++++--
>  tools/binman/etype/fit.py                   | 12 +----
>  tools/binman/ftest.py                       | 24 ++++++++++
>  tools/binman/test/221_fit_subentry_hash.dts | 52 +++++++++++++++++++++
>  4 files changed, 97 insertions(+), 14 deletions(-)
>  create mode 100644 tools/binman/test/221_fit_subentry_hash.dts
>

Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-23  2:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 19:02 [PATCH v2] binman: Skip processing "hash" subnodes of FIT subsections Alper Nebi Yasak
2022-02-11 15:05 ` Simon Glass
2022-02-23  2:34 ` Simon Glass

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).