[U-Boot] [PATCH 13/34] binman: Use the Makefile to build ELF test files

Simon Glass sjg at chromium.org
Sat Aug 24 13:22:53 UTC 2019


At present the ELF test files are checked into the U-Boot tree. This is
covenient since the files never change and can be used on non-x86
platforms. However it is not good practice to check in binaries and in
this case it does not seem essential.

Update the binman test-file Makefile to support having source in a
different directory. Adjust binman to run it to build bss_data, as a
start. We can add other files as needed.

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

 tools/binman/elf_test.py   |  23 +++++++++++++++++++++++
 tools/binman/ftest.py      |  24 ++++++++++++++++++------
 tools/binman/test/Makefile |   3 ++-
 tools/binman/test/bss_data | Bin 5020 -> 0 bytes
 4 files changed, 43 insertions(+), 7 deletions(-)
 delete mode 100755 tools/binman/test/bss_data

diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
index cc6e9c5128..736b931fd5 100644
--- a/tools/binman/elf_test.py
+++ b/tools/binman/elf_test.py
@@ -50,6 +50,29 @@ class FakeSection:
         return self.sym_value
 
 
+def BuildElfTestFiles(target_dir):
+    """Build ELF files used for testing in binman
+
+    This compiles and links the test files into the specified directory. It the
+    Makefile and source files in the binman test/ directory.
+
+    Args:
+        target_dir: Directory to put the files into
+    """
+    if not os.path.exists(target_dir):
+        os.mkdir(target_dir)
+    testdir = os.path.join(binman_dir, 'test')
+
+    # If binman is involved from the main U-Boot Makefile the -r and -R
+    # flags are set in MAKEFLAGS. This prevents this Makefile from working
+    # correctly. So drop any make flags here.
+    if 'MAKEFLAGS' in os.environ:
+        del os.environ['MAKEFLAGS']
+    tools.Run('make', '-C', target_dir, '-f',
+              os.path.join(testdir, 'Makefile'), 'SRC=%s/' % testdir,
+              'bss_data', 'u_boot_ucode_ptr')
+
+
 class TestElf(unittest.TestCase):
     @classmethod
     def setUpClass(self):
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index bba07e7275..fad62bb04f 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -23,6 +23,7 @@ import cmdline
 import command
 import control
 import elf
+import elf_test
 import fdt
 from etype import fdtmap
 from etype import image_header
@@ -147,6 +148,9 @@ class TestFunctional(unittest.TestCase):
         TestFunctional._MakeInputFile('bmpblk.bin', BMPBLK_DATA)
         TestFunctional._MakeInputFile('refcode.bin', REFCODE_DATA)
 
+        cls._elf_testdir = os.path.join(cls._indir, 'elftest')
+        elf_test.BuildElfTestFiles(cls._elf_testdir)
+
         # ELF file with a '_dt_ucode_base_size' symbol
         with open(cls.TestFile('u_boot_ucode_ptr'), 'rb') as fd:
             TestFunctional._MakeInputFile('u-boot', fd.read())
@@ -484,13 +488,21 @@ class TestFunctional(unittest.TestCase):
         Args:
             Filename of ELF file to use as SPL
         """
-        with open(cls.TestFile(src_fname), 'rb') as fd:
-            TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read())
+        # TODO(sjg at chromium.org): Drop this when all Elf files use ElfTestFile()
+        if src_fname in ['bss_data']:
+            fname = cls.ElfTestFile(src_fname)
+        else:
+            fname = cls.TestFile(src_fname)
+        TestFunctional._MakeInputFile('spl/u-boot-spl', tools.ReadFile(fname))
 
     @classmethod
     def TestFile(cls, fname):
         return os.path.join(cls._binman_dir, 'test', fname)
 
+    @classmethod
+    def ElfTestFile(cls, fname):
+        return os.path.join(cls._elf_testdir, fname)
+
     def AssertInList(self, grep_list, target):
         """Assert that at least one of a list of things is in a target
 
@@ -1551,7 +1563,7 @@ class TestFunctional(unittest.TestCase):
     def testTpl(self):
         """Test that an image with TPL and ots device tree can be created"""
         # ELF file with a '__bss_size' symbol
-        with open(self.TestFile('bss_data'), 'rb') as fd:
+        with open(self.ElfTestFile('bss_data'), 'rb') as fd:
             TestFunctional._MakeInputFile('tpl/u-boot-tpl', fd.read())
         data = self._DoReadFile('078_u_boot_tpl.dts')
         self.assertEqual(U_BOOT_TPL_DATA + U_BOOT_TPL_DTB_DATA, data)
@@ -1861,16 +1873,16 @@ class TestFunctional(unittest.TestCase):
     def testElf(self):
         """Basic test of ELF entries"""
         self._SetupSplElf()
-        with open(self.TestFile('bss_data'), 'rb') as fd:
+        with open(self.ElfTestFile('bss_data'), 'rb') as fd:
             TestFunctional._MakeInputFile('tpl/u-boot-tpl', fd.read())
-        with open(self.TestFile('bss_data'), 'rb') as fd:
+        with open(self.ElfTestFile('bss_data'), 'rb') as fd:
             TestFunctional._MakeInputFile('-boot', fd.read())
         data = self._DoReadFile('096_elf.dts')
 
     def testElfStrip(self):
         """Basic test of ELF entries"""
         self._SetupSplElf()
-        with open(self.TestFile('bss_data'), 'rb') as fd:
+        with open(self.ElfTestFile('bss_data'), 'rb') as fd:
             TestFunctional._MakeInputFile('-boot', fd.read())
         data = self._DoReadFile('097_elf_strip.dts')
 
diff --git a/tools/binman/test/Makefile b/tools/binman/test/Makefile
index e58fc80775..ce1c2f900c 100644
--- a/tools/binman/test/Makefile
+++ b/tools/binman/test/Makefile
@@ -7,6 +7,7 @@
 # SPDX-License-Identifier:      GPL-2.0+
 #
 
+VPATH := $(SRC)
 CFLAGS := -march=i386 -m32 -nostdlib -I ../../../include
 
 LDS_UCODE := -T u_boot_ucode_ptr.lds
@@ -25,7 +26,7 @@ u_boot_no_ucode_ptr: u_boot_no_ucode_ptr.c
 u_boot_ucode_ptr: CFLAGS += $(LDS_UCODE)
 u_boot_ucode_ptr: u_boot_ucode_ptr.c
 
-bss_data: CFLAGS += bss_data.lds
+bss_data: CFLAGS += $(SRC)bss_data.lds
 bss_data: bss_data.c
 
 u_boot_binman_syms.bin: u_boot_binman_syms
diff --git a/tools/binman/test/bss_data b/tools/binman/test/bss_data
deleted file mode 100755
index afa28282aa157f6717c1ba244ecbfc6e1b081734..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 5020
zcmeHLyKWOf6uoP&!GJ+|Af+(H7C{(6hJ>s{1O*}i;vz!9k|7jmvEv0>!j5FGr4S(=
z1rl`m016r?sner~AE2ip9R*N at 0-1AWb`nc8lqu#)$M-R39(#6N?0tS?>89s-Vl5+C
zVfN$CU=YG at j+l{90?A29j!9mR>*@<XFTe^W5IGjX=X`p3hjGA1SOyLOtTX>YU at kF<
zm|&e)-boq-EK+#s=ZTZ35qA7G#*zMGT%X&LM}8Jqyj7L$-{T)<zJ0y(_Vh>Z{jc>)
zoA)Lv)i*nzb0r)u1JV{C_dj{X>=n-E`M(bagY)oQhvscm#Cw|eiUr?)4Z<nZh%N9m
z=h}(<tIYiI-10UUoZ-wV;1qBQI0c*nP64NYQ@|<U6mSYS1)Ks0M}ZQKvbeBtIVe@@
z{Z7&kLN%wtsf&G`%{-e4)pV$4&zic3>OE;EwK{y#HNI)1&RP<yN1eW^_gjw}Q>})m
zBwkNM#m(qpx7LoMW}~~GiE7l6ny7lOCu()A-HtoS|Lal&^)SHCcil&Tp9HMgPjH0-
zzvtN-*hQ~l7v6r;Bi!p{glWw6bl(A!hIw|q`5|6_-b4W29BS4qZwUqN%N~U8gQR^A
zrZmf|AkG8i1!zb3;PIVU3)0{&JlC5}bMnrmF&)Q<Q9$nrPrCr#109(ka%l8?R%_)k
z^iEJbiUPs&VX7PfhSyse7rBm_HM^e8hdtj5bJI~W`kUPBOr1?`cA%anPt}1QCfA)M
zt&hodCyAl9EN;T^Iehs!uw(Sh3-I>2Mv+e-r`{#_QQVFIo;@!(Jhvxj;Qe&}5sc3w
z=l$WG7=v<r=lkP1xr)3z#1~xah!<R~N)$2awKn3tszkk{)=lh?j at z|XN1|B&E26m5
FkiP*om$v`_

-- 
2.23.0.187.g17f5b7556c-goog



More information about the U-Boot mailing list