All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v3 06/27] binman: Support symbols in u-boot-spl-nodtb
Date: Thu, 18 Mar 2021 20:24:56 +1300	[thread overview]
Message-ID: <20210318072517.26894-7-sjg@chromium.org> (raw)
In-Reply-To: <20210318072517.26894-1-sjg@chromium.org>

Since this is an execuable we should be able insert symbol values into it.
Add support for this.

Use common code for this test and the original testSymbols. Use hex
consistently for the values and add some more comments.

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

Changes in v3:
- Add new patch to support symbols in u-boot-spl-nodtb

 tools/binman/README.entries             |  9 +++++
 tools/binman/etype/u_boot_spl_nodtb.py  | 14 +++++++
 tools/binman/ftest.py                   | 49 +++++++++++++++----------
 tools/binman/test/053_symbols.dts       |  2 +-
 tools/binman/test/192_symbols_nodtb.dts | 26 +++++++++++++
 tools/binman/test/u_boot_binman_syms.c  |  2 +-
 6 files changed, 81 insertions(+), 21 deletions(-)
 create mode 100644 tools/binman/test/192_symbols_nodtb.dts

diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index 5c6663e2c7c..1dbdd0be03d 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -1011,6 +1011,15 @@ a device tree to operate on your platform. You can add a u-boot-spl-dtb
 entry after this one, or use a u-boot-spl entry instead (which contains
 both SPL and the device tree).
 
+SPL can access binman symbols at runtime. See:
+
+    'Access to binman entry offsets at run time (symbols)'
+
+in the binman README for more information.
+
+The ELF file 'spl/u-boot-spl' must also be available for this to work, since
+binman uses that to look up symbols to write into the SPL binary.
+
 
 
 Entry: u-boot-spl-with-ucode-ptr: U-Boot SPL with embedded microcode pointer
diff --git a/tools/binman/etype/u_boot_spl_nodtb.py b/tools/binman/etype/u_boot_spl_nodtb.py
index 41d75054910..dbf2f12743a 100644
--- a/tools/binman/etype/u_boot_spl_nodtb.py
+++ b/tools/binman/etype/u_boot_spl_nodtb.py
@@ -5,6 +5,7 @@
 # Entry-type module for 'u-boot-spl-nodtb.bin'
 #
 
+from binman import elf
 from binman.entry import Entry
 from binman.etype.blob import Entry_blob
 
@@ -19,9 +20,22 @@ class Entry_u_boot_spl_nodtb(Entry_blob):
     a device tree to operate on your platform. You can add a u-boot-spl-dtb
     entry after this one, or use a u-boot-spl entry instead (which contains
     both SPL and the device tree).
+
+    SPL can access binman symbols at runtime. See:
+
+        'Access to binman entry offsets at run time (symbols)'
+
+    in the binman README for more information.
+
+    The ELF file 'spl/u-boot-spl' must also be available for this to work, since
+    binman uses that to look up symbols to write into the SPL binary.
     """
     def __init__(self, section, etype, node):
         super().__init__(section, etype, node)
+        self.elf_fname = 'spl/u-boot-spl'
 
     def GetDefaultFilename(self):
         return 'spl/u-boot-spl-nodtb.bin'
+
+    def WriteSymbols(self, section):
+        elf.LookupAndWriteSymbols(self.elf_fname, self, section.GetImage())
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 814e91d42e9..e056601b9a4 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1337,21 +1337,43 @@ class TestFunctional(unittest.TestCase):
         data = self._DoReadFile('052_u_boot_spl_nodtb.dts')
         self.assertEqual(U_BOOT_SPL_NODTB_DATA, data[:len(U_BOOT_SPL_NODTB_DATA)])
 
-    def testSymbols(self):
-        """Test binman can assign symbols embedded in U-Boot"""
+    def checkSymbols(self, dts, base_data, u_boot_offset):
+        """Check the image contains the expected symbol values
+
+        Args:
+            dts: Device tree file to use for test
+            base_data: Data before and after 'u-boot' section
+            u_boot_offset: Offset of 'u-boot' section in image
+        """
         elf_fname = self.ElfTestFile('u_boot_binman_syms')
         syms = elf.GetSymbols(elf_fname, ['binman', 'image'])
         addr = elf.GetSymbolAddress(elf_fname, '__image_copy_start')
-        self.assertEqual(syms['_binman_u_boot_spl_prop_offset'].address, addr)
+        self.assertEqual(syms['_binman_u_boot_spl_any_prop_offset'].address,
+                         addr)
 
         self._SetupSplElf('u_boot_binman_syms')
-        data = self._DoReadFile('053_symbols.dts')
-        sym_values = struct.pack('<LQLL', 0x00, 0x1c, 0x28, 0x04)
-        expected = (sym_values + U_BOOT_SPL_DATA[20:] +
+        data = self._DoReadFile(dts)
+        # The image should contain the symbols from u_boot_binman_syms.c
+        # Note that image_pos is adjusted by the base address of the image,
+        # which is 0x10 in our test image
+        sym_values = struct.pack('<LQLL', 0x00,
+                                 u_boot_offset + len(U_BOOT_DATA),
+                                 0x10 + u_boot_offset, 0x04)
+        expected = (sym_values + base_data[20:] +
                     tools.GetBytes(0xff, 1) + U_BOOT_DATA + sym_values +
-                    U_BOOT_SPL_DATA[20:])
+                    base_data[20:])
         self.assertEqual(expected, data)
 
+    def testSymbols(self):
+        """Test binman can assign symbols embedded in U-Boot"""
+        self.checkSymbols('053_symbols.dts', U_BOOT_SPL_DATA, 0x18)
+
+    def testSymbolsNoDtb(self):
+        """Test binman can assign symbols embedded in U-Boot SPL"""
+        self.checkSymbols('192_symbols_nodtb.dts',
+                          U_BOOT_SPL_NODTB_DATA + U_BOOT_SPL_DTB_DATA,
+                          0x38)
+
     def testPackUnitAddress(self):
         """Test that we support multiple binaries with the same name"""
         data = self._DoReadFile('054_unit_address.dts')
@@ -4186,18 +4208,7 @@ class TestFunctional(unittest.TestCase):
 
     def testSymbolsSubsection(self):
         """Test binman can assign symbols from a subsection"""
-        elf_fname = self.ElfTestFile('u_boot_binman_syms')
-        syms = elf.GetSymbols(elf_fname, ['binman', 'image'])
-        addr = elf.GetSymbolAddress(elf_fname, '__image_copy_start')
-        self.assertEqual(syms['_binman_u_boot_spl_prop_offset'].address, addr)
-
-        self._SetupSplElf('u_boot_binman_syms')
-        data = self._DoReadFile('187_symbols_sub.dts')
-        sym_values = struct.pack('<LQLL', 0x00, 0x1c, 0x28, 0x04)
-        expected = (sym_values + U_BOOT_SPL_DATA[20:] +
-                    tools.GetBytes(0xff, 1) + U_BOOT_DATA + sym_values +
-                    U_BOOT_SPL_DATA[20:])
-        self.assertEqual(expected, data)
+        self.checkSymbols('187_symbols_sub.dts', U_BOOT_SPL_DATA, 0x18)
 
     def testReadImageEntryArg(self):
         """Test reading an image that would need an entry arg to generate"""
diff --git a/tools/binman/test/053_symbols.dts b/tools/binman/test/053_symbols.dts
index 8af575158f5..29658092764 100644
--- a/tools/binman/test/053_symbols.dts
+++ b/tools/binman/test/053_symbols.dts
@@ -10,7 +10,7 @@
 		};
 
 		u-boot {
-			offset = <24>;
+			offset = <0x18>;
 		};
 
 		u-boot-spl2 {
diff --git a/tools/binman/test/192_symbols_nodtb.dts b/tools/binman/test/192_symbols_nodtb.dts
new file mode 100644
index 00000000000..5c900d60709
--- /dev/null
+++ b/tools/binman/test/192_symbols_nodtb.dts
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		pad-byte = <0xff>;
+		u-boot-spl-nodtb {
+		};
+		u-boot-spl-dtb {
+		};
+
+		u-boot {
+			offset = <0x38>;
+		};
+
+		u-boot-spl2 {
+			type = "u-boot-spl-nodtb";
+		};
+		u-boot-spl-dtb2 {
+			type = "u-boot-spl-dtb";
+		};
+	};
+};
diff --git a/tools/binman/test/u_boot_binman_syms.c b/tools/binman/test/u_boot_binman_syms.c
index 4520b319f16..37fc339ce84 100644
--- a/tools/binman/test/u_boot_binman_syms.c
+++ b/tools/binman/test/u_boot_binman_syms.c
@@ -8,7 +8,7 @@
 #define CONFIG_BINMAN
 #include <binman_sym.h>
 
-binman_sym_declare(unsigned long, u_boot_spl, offset);
+binman_sym_declare(unsigned long, u_boot_spl_any, offset);
 binman_sym_declare(unsigned long long, u_boot_spl2, offset);
 binman_sym_declare(unsigned long, u_boot_any, image_pos);
 binman_sym_declare(unsigned long, u_boot_any, size);
-- 
2.31.0.rc2.261.g7f71774620-goog

  parent reply	other threads:[~2021-03-18  7:24 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18  7:24 [PATCH v3 00/27] binman: Support devicetree update in all entries Simon Glass
2021-03-18  7:24 ` [PATCH v3 01/27] binman: Allow extracting to current directory Simon Glass
2021-03-18  7:24 ` [PATCH v3 02/27] binman: Document ExpandEntries() in the base class Simon Glass
2021-03-18  7:24 ` [PATCH v3 03/27] binman: Update entry help for files-align Simon Glass
2021-03-18  7:24 ` [PATCH v3 04/27] binman: Tidy up underscores in entry documentation Simon Glass
2021-03-18  7:24 ` [PATCH v3 05/27] binman: Correct the documentation for u-boot-spl-bss-pad Simon Glass
2021-03-18  7:24 ` Simon Glass [this message]
2021-03-18  7:24 ` [PATCH v3 07/27] binman: Add support for u-boot-tpl-nodtb Simon Glass
2021-03-18  7:24 ` [PATCH v3 08/27] binman: Add support for u-boot-tpl-bss-bad Simon Glass
2021-03-18  7:24 ` [PATCH v3 09/27] binman: Drop unnecessary 'type' property in tests Simon Glass
2021-03-18  7:25 ` [PATCH v3 10/27] binman: Use the fake SPL/TPL only if requested Simon Glass
2021-03-18  7:25 ` [PATCH v3 11/27] binman: Drop unnecessary field in output_fdt_info Simon Glass
2021-03-18  7:25 ` [PATCH v3 12/27] binman: Move the comment for GetFdts() to the base class Simon Glass
2021-03-18  7:25 ` [PATCH v3 13/27] binman: Use standard filenames for SPL/TPL devicetree Simon Glass
2021-03-18  7:25 ` [PATCH v3 14/27] binman: Allow using an an 'expanded' entry type Simon Glass
2021-03-18  7:25 ` [PATCH v3 15/27] binman: Allow a way to select expanded entries Simon Glass
2021-03-18  7:25 ` [PATCH v3 16/27] binman: Plumb expanded entries through fully Simon Glass
2021-03-18  7:25 ` [PATCH v3 17/27] binman: Automatically expand phase binaries into sections Simon Glass
2021-03-18  7:25 ` [PATCH v3 18/27] Makefile: Pass new entry args to binman Simon Glass
2021-03-18  7:25 ` [PATCH v3 19/27] x86: Make use of binman expanded entries Simon Glass
2021-03-18  7:25 ` [PATCH v3 20/27] x86: dts: Drop unused CONFIG_SPL Simon Glass
2021-03-18  7:25 ` [PATCH v3 21/27] doc: Move UEFI under develop/ Simon Glass
2021-03-18  9:23   ` Heinrich Schuchardt
2021-03-19 23:52   ` Simon Glass
2021-03-18  7:25 ` [PATCH v3 22/27] doc: Move driver model docs " Simon Glass
2021-03-18  7:25 ` [PATCH v3 23/27] binman: doc: Add documentation to htmldocs Simon Glass
2021-03-18  7:25 ` [PATCH v3 24/27] binman: Rearrange documentation into headings Simon Glass
2021-03-18  7:25 ` [PATCH v3 25/27] binman: Incorporate entry documentation Simon Glass
2021-03-18  7:25 ` [PATCH v3 26/27] binman: Drop repetitive heading for each entry Simon Glass
2021-03-18  7:25 ` [PATCH v3 27/27] binman: Update various pieces of the documentation Simon Glass
2021-03-19 23:52 ` Simon Glass
2021-03-19 23:52 ` [PATCH v3 26/27] binman: Drop repetitive heading for each entry Simon Glass
2021-03-19 23:52 ` [PATCH v3 25/27] binman: Incorporate entry documentation Simon Glass
2021-03-19 23:52 ` [PATCH v3 24/27] binman: Rearrange documentation into headings Simon Glass
2021-03-19 23:52 ` [PATCH v3 23/27] binman: doc: Add documentation to htmldocs Simon Glass
2021-03-19 23:52 ` [PATCH v3 22/27] doc: Move driver model docs under develop/ Simon Glass
2021-03-19 23:52 ` [PATCH v3 20/27] x86: dts: Drop unused CONFIG_SPL Simon Glass
2021-03-19 23:52 ` [PATCH v3 19/27] x86: Make use of binman expanded entries Simon Glass
2021-03-19 23:52 ` [PATCH v3 18/27] Makefile: Pass new entry args to binman Simon Glass
2021-03-19 23:52 ` [PATCH v3 17/27] binman: Automatically expand phase binaries into sections Simon Glass
2021-03-19 23:52 ` [PATCH v3 16/27] binman: Plumb expanded entries through fully Simon Glass
2021-03-19 23:52 ` [PATCH v3 15/27] binman: Allow a way to select expanded entries Simon Glass
2021-03-19 23:52 ` [PATCH v3 14/27] binman: Allow using an an 'expanded' entry type Simon Glass
2021-03-19 23:52 ` [PATCH v3 13/27] binman: Use standard filenames for SPL/TPL devicetree Simon Glass
2021-03-19 23:52 ` [PATCH v3 12/27] binman: Move the comment for GetFdts() to the base class Simon Glass
2021-03-19 23:52 ` [PATCH v3 11/27] binman: Drop unnecessary field in output_fdt_info Simon Glass
2021-03-19 23:52 ` [PATCH v3 10/27] binman: Use the fake SPL/TPL only if requested Simon Glass
2021-03-19 23:53 ` [PATCH v3 09/27] binman: Drop unnecessary 'type' property in tests Simon Glass
2021-03-19 23:53 ` [PATCH v3 08/27] binman: Add support for u-boot-tpl-bss-bad Simon Glass
2021-03-19 23:53 ` [PATCH v3 07/27] binman: Add support for u-boot-tpl-nodtb Simon Glass
2021-03-19 23:53 ` [PATCH v3 06/27] binman: Support symbols in u-boot-spl-nodtb Simon Glass
2021-03-19 23:53 ` [PATCH v3 05/27] binman: Correct the documentation for u-boot-spl-bss-pad Simon Glass
2021-03-19 23:53 ` [PATCH v3 04/27] binman: Tidy up underscores in entry documentation Simon Glass
2021-03-19 23:53 ` [PATCH v3 03/27] binman: Update entry help for files-align Simon Glass
2021-03-19 23:53 ` [PATCH v3 02/27] binman: Document ExpandEntries() in the base class Simon Glass
2021-03-19 23:53 ` [PATCH v3 01/27] binman: Allow extracting to current directory 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=20210318072517.26894-7-sjg@chromium.org \
    --to=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 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.