All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] binman: Tweak implementation of fmap
@ 2021-04-02 22:05 Simon Glass
  2021-04-02 22:05 ` [PATCH 2/2] binman: Support adding sections to FMAPs Simon Glass
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Simon Glass @ 2021-04-02 22:05 UTC (permalink / raw)
  To: u-boot

Use an interator in two of the fmap tests so it is easier to add new
items. Also check the name first since that is the first indication
that something is wrong. Use a variable for the expected size of the
fmap to avoid repeating the code.

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

 tools/binman/ftest.py | 69 ++++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 31 deletions(-)

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 89fe6612e1b..217cd0a4249 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1594,26 +1594,29 @@ class TestFunctional(unittest.TestCase):
         self.assertEqual(1, fhdr.ver_major)
         self.assertEqual(0, fhdr.ver_minor)
         self.assertEqual(0, fhdr.base)
-        self.assertEqual(16 + 16 +
-                         fmap_util.FMAP_HEADER_LEN +
-                         fmap_util.FMAP_AREA_LEN * 3, fhdr.image_size)
+        expect_size = fmap_util.FMAP_HEADER_LEN + fmap_util.FMAP_AREA_LEN * 3
+        self.assertEqual(16 + 16 + expect_size, fhdr.image_size)
         self.assertEqual(b'FMAP', fhdr.name)
         self.assertEqual(3, fhdr.nareas)
-        for fentry in fentries:
-            self.assertEqual(0, fentry.flags)
-
-        self.assertEqual(0, fentries[0].offset)
-        self.assertEqual(4, fentries[0].size)
-        self.assertEqual(b'RO_U_BOOT', fentries[0].name)
-
-        self.assertEqual(16, fentries[1].offset)
-        self.assertEqual(4, fentries[1].size)
-        self.assertEqual(b'RW_U_BOOT', fentries[1].name)
-
-        self.assertEqual(32, fentries[2].offset)
-        self.assertEqual(fmap_util.FMAP_HEADER_LEN +
-                         fmap_util.FMAP_AREA_LEN * 3, fentries[2].size)
-        self.assertEqual(b'FMAP', fentries[2].name)
+        fiter = iter(fentries)
+
+        fentry = next(fiter)
+        self.assertEqual(b'RO_U_BOOT', fentry.name)
+        self.assertEqual(0, fentry.offset)
+        self.assertEqual(4, fentry.size)
+        self.assertEqual(0, fentry.flags)
+
+        fentry = next(fiter)
+        self.assertEqual(b'RW_U_BOOT', fentry.name)
+        self.assertEqual(16, fentry.offset)
+        self.assertEqual(4, fentry.size)
+        self.assertEqual(0, fentry.flags)
+
+        fentry = next(fiter)
+        self.assertEqual(b'FMAP', fentry.name)
+        self.assertEqual(32, fentry.offset)
+        self.assertEqual(expect_size, fentry.size)
+        self.assertEqual(0, fentry.flags)
 
     def testBlobNamedByArg(self):
         """Test we can add a blob with the filename coming from an entry arg"""
@@ -2064,19 +2067,23 @@ class TestFunctional(unittest.TestCase):
         fhdr, fentries = fmap_util.DecodeFmap(data[36:])
 
         self.assertEqual(0x100, fhdr.image_size)
-
-        self.assertEqual(0, fentries[0].offset)
-        self.assertEqual(4, fentries[0].size)
-        self.assertEqual(b'U_BOOT', fentries[0].name)
-
-        self.assertEqual(4, fentries[1].offset)
-        self.assertEqual(3, fentries[1].size)
-        self.assertEqual(b'INTEL_MRC', fentries[1].name)
-
-        self.assertEqual(36, fentries[2].offset)
-        self.assertEqual(fmap_util.FMAP_HEADER_LEN +
-                         fmap_util.FMAP_AREA_LEN * 3, fentries[2].size)
-        self.assertEqual(b'FMAP', fentries[2].name)
+        expect_size = fmap_util.FMAP_HEADER_LEN + fmap_util.FMAP_AREA_LEN * 3
+        fiter = iter(fentries)
+
+        fentry = next(fiter)
+        self.assertEqual(b'U_BOOT', fentry.name)
+        self.assertEqual(0, fentry.offset)
+        self.assertEqual(4, fentry.size)
+
+        fentry = next(fiter)
+        self.assertEqual(b'INTEL_MRC', fentry.name)
+        self.assertEqual(4, fentry.offset)
+        self.assertEqual(3, fentry.size)
+
+        fentry = next(fiter)
+        self.assertEqual(b'FMAP', fentry.name)
+        self.assertEqual(36, fentry.offset)
+        self.assertEqual(expect_size, fentry.size)
 
     def testElf(self):
         """Basic test of ELF entries"""
-- 
2.31.0.208.g409f899ff0-goog

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

* [PATCH 2/2] binman: Support adding sections to FMAPs
  2021-04-02 22:05 [PATCH 1/2] binman: Tweak implementation of fmap Simon Glass
@ 2021-04-02 22:05 ` Simon Glass
  2021-04-29 16:03 ` Simon Glass
  2021-04-29 16:03 ` [PATCH 1/2] binman: Tweak implementation of fmap Simon Glass
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Glass @ 2021-04-02 22:05 UTC (permalink / raw)
  To: u-boot

When used with hierarchical images, use the Chromium OS convention of
adding a section before all the subentries it contains.

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

 tools/binman/entries.rst                   | 13 +++++++++--
 tools/binman/etype/fmap.py                 | 20 +++++++++++++++--
 tools/binman/ftest.py                      | 25 ++++++++++++++++++----
 tools/binman/test/095_fmap_x86_section.dts |  2 +-
 4 files changed, 51 insertions(+), 9 deletions(-)

diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst
index a91211e93ed..f1c3b7de7ab 100644
--- a/tools/binman/entries.rst
+++ b/tools/binman/entries.rst
@@ -461,8 +461,12 @@ see www.flashrom.org/Flashrom for more information.
 
 When used, this entry will be populated with an FMAP which reflects the
 entries in the current image. Note that any hierarchy is squashed, since
-FMAP does not support this. Also, CBFS entries appear as a single entry -
-the sub-entries are ignored.
+FMAP does not support this. Sections are represented as an area appearing
+before its contents, so that it is possible to reconstruct the hierarchy
+from the FMAP by using the offset information. This convention does not
+seem to be documented, but is used in Chromium OS.
+
+CBFS entries appear as a single entry, i.e. the sub-entries are ignored.
 
 
 
@@ -804,6 +808,11 @@ Properties:
         missing their contents. The second will produce an image but of
         course it will not work.
 
+Properties:
+    _allow_missing: True if this section permits external blobs to be
+        missing their contents. The second will produce an image but of
+        course it will not work.
+
 Since a section is also an entry, it inherits all the properies of entries
 too.
 
diff --git a/tools/binman/etype/fmap.py b/tools/binman/etype/fmap.py
index fe81c6f64a5..fc490292786 100644
--- a/tools/binman/etype/fmap.py
+++ b/tools/binman/etype/fmap.py
@@ -28,8 +28,12 @@ class Entry_fmap(Entry):
 
     When used, this entry will be populated with an FMAP which reflects the
     entries in the current image. Note that any hierarchy is squashed, since
-    FMAP does not support this. Also, CBFS entries appear as a single entry -
-    the sub-entries are ignored.
+    FMAP does not support this. Sections are represented as an area appearing
+    before its contents, so that it is possible to reconstruct the hierarchy
+    from the FMAP by using the offset information. This convention does not
+    seem to be documented, but is used in Chromium OS.
+
+    CBFS entries appear as a single entry, i.e. the sub-entries are ignored.
     """
     def __init__(self, section, etype, node):
         super().__init__(section, etype, node)
@@ -45,6 +49,18 @@ class Entry_fmap(Entry):
             tout.Debug("fmap: Add entry '%s' type '%s' (%s subentries)" %
                        (entry.GetPath(), entry.etype, ToHexSize(entries)))
             if entries and entry.etype != 'cbfs':
+                # Create an area for the section, which encompasses all entries
+                # within it
+                if entry.image_pos is None:
+                    pos = 0
+                else:
+                    pos = entry.image_pos - entry.GetRootSkipAtStart()
+
+                # Drop @ symbols in name
+                name = entry.name.replace('@', '')
+                areas.append(
+                    fmap_util.FmapArea(pos, entry.size or 0,
+                                       tools.FromUnicode(name), 0))
                 for subentry in entries.values():
                     _AddEntries(areas, subentry)
             else:
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 217cd0a4249..1f94d99bcfb 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1594,18 +1594,30 @@ class TestFunctional(unittest.TestCase):
         self.assertEqual(1, fhdr.ver_major)
         self.assertEqual(0, fhdr.ver_minor)
         self.assertEqual(0, fhdr.base)
-        expect_size = fmap_util.FMAP_HEADER_LEN + fmap_util.FMAP_AREA_LEN * 3
+        expect_size = fmap_util.FMAP_HEADER_LEN + fmap_util.FMAP_AREA_LEN * 5
         self.assertEqual(16 + 16 + expect_size, fhdr.image_size)
         self.assertEqual(b'FMAP', fhdr.name)
-        self.assertEqual(3, fhdr.nareas)
+        self.assertEqual(5, fhdr.nareas)
         fiter = iter(fentries)
 
+        fentry = next(fiter)
+        self.assertEqual(b'SECTION0', fentry.name)
+        self.assertEqual(0, fentry.offset)
+        self.assertEqual(16, fentry.size)
+        self.assertEqual(0, fentry.flags)
+
         fentry = next(fiter)
         self.assertEqual(b'RO_U_BOOT', fentry.name)
         self.assertEqual(0, fentry.offset)
         self.assertEqual(4, fentry.size)
         self.assertEqual(0, fentry.flags)
 
+        fentry = next(fiter)
+        self.assertEqual(b'SECTION1', fentry.name)
+        self.assertEqual(16, fentry.offset)
+        self.assertEqual(16, fentry.size)
+        self.assertEqual(0, fentry.flags)
+
         fentry = next(fiter)
         self.assertEqual(b'RW_U_BOOT', fentry.name)
         self.assertEqual(16, fentry.offset)
@@ -2066,8 +2078,8 @@ class TestFunctional(unittest.TestCase):
         self.assertEqual(expected, data[:32])
         fhdr, fentries = fmap_util.DecodeFmap(data[36:])
 
-        self.assertEqual(0x100, fhdr.image_size)
-        expect_size = fmap_util.FMAP_HEADER_LEN + fmap_util.FMAP_AREA_LEN * 3
+        self.assertEqual(0x180, fhdr.image_size)
+        expect_size = fmap_util.FMAP_HEADER_LEN + fmap_util.FMAP_AREA_LEN * 4
         fiter = iter(fentries)
 
         fentry = next(fiter)
@@ -2075,6 +2087,11 @@ class TestFunctional(unittest.TestCase):
         self.assertEqual(0, fentry.offset)
         self.assertEqual(4, fentry.size)
 
+        fentry = next(fiter)
+        self.assertEqual(b'SECTION', fentry.name)
+        self.assertEqual(4, fentry.offset)
+        self.assertEqual(0x20 + expect_size, fentry.size)
+
         fentry = next(fiter)
         self.assertEqual(b'INTEL_MRC', fentry.name)
         self.assertEqual(4, fentry.offset)
diff --git a/tools/binman/test/095_fmap_x86_section.dts b/tools/binman/test/095_fmap_x86_section.dts
index 4cfce456705..fd5f018c923 100644
--- a/tools/binman/test/095_fmap_x86_section.dts
+++ b/tools/binman/test/095_fmap_x86_section.dts
@@ -7,7 +7,7 @@
 
 	binman {
 		end-at-4gb;
-		size = <0x100>;
+		size = <0x180>;
 		u-boot {
 		};
 		section {
-- 
2.31.0.208.g409f899ff0-goog

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

* [PATCH 2/2] binman: Support adding sections to FMAPs
  2021-04-02 22:05 [PATCH 1/2] binman: Tweak implementation of fmap Simon Glass
  2021-04-02 22:05 ` [PATCH 2/2] binman: Support adding sections to FMAPs Simon Glass
@ 2021-04-29 16:03 ` Simon Glass
  2021-04-29 16:03 ` [PATCH 1/2] binman: Tweak implementation of fmap Simon Glass
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Glass @ 2021-04-29 16:03 UTC (permalink / raw)
  To: u-boot

When used with hierarchical images, use the Chromium OS convention of
adding a section before all the subentries it contains.

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

 tools/binman/entries.rst                   | 13 +++++++++--
 tools/binman/etype/fmap.py                 | 20 +++++++++++++++--
 tools/binman/ftest.py                      | 25 ++++++++++++++++++----
 tools/binman/test/095_fmap_x86_section.dts |  2 +-
 4 files changed, 51 insertions(+), 9 deletions(-)

Applied to u-boot-dm, thanks!

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

* [PATCH 1/2] binman: Tweak implementation of fmap
  2021-04-02 22:05 [PATCH 1/2] binman: Tweak implementation of fmap Simon Glass
  2021-04-02 22:05 ` [PATCH 2/2] binman: Support adding sections to FMAPs Simon Glass
  2021-04-29 16:03 ` Simon Glass
@ 2021-04-29 16:03 ` Simon Glass
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Glass @ 2021-04-29 16:03 UTC (permalink / raw)
  To: u-boot

Use an interator in two of the fmap tests so it is easier to add new
items. Also check the name first since that is the first indication
that something is wrong. Use a variable for the expected size of the
fmap to avoid repeating the code.

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

 tools/binman/ftest.py | 69 ++++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 31 deletions(-)

Applied to u-boot-dm, thanks!

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

end of thread, other threads:[~2021-04-29 16:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-02 22:05 [PATCH 1/2] binman: Tweak implementation of fmap Simon Glass
2021-04-02 22:05 ` [PATCH 2/2] binman: Support adding sections to FMAPs Simon Glass
2021-04-29 16:03 ` Simon Glass
2021-04-29 16:03 ` [PATCH 1/2] binman: Tweak implementation of fmap Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.