From 4c65025799d79a030a61f8d95e20954963c62db4 Mon Sep 17 00:00:00 2001
From: Simon Glass <sjg@chromium.org>
Date: Mon, 8 Jul 2019 13:18:46 -0600
Subject: [PATCH] binman: Support ELF files for TPL

We currenty support using the ELF file in U-Boot proper and SPL, but not
TPL. Add this as it is useful both with sandbox and for CBFS to allow
adding TPL as a 'stage'.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 tools/binman/README.entries          | 11 +++++++++++
 tools/binman/etype/u_boot_tpl_elf.py | 24 ++++++++++++++++++++++++
 tools/binman/ftest.py                |  2 ++
 tools/binman/test/096_elf.dts        |  2 ++
 4 files changed, 39 insertions(+)
 create mode 100644 tools/binman/etype/u_boot_tpl_elf.py

diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index c26addcfe6..9a316763ac 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -574,6 +574,17 @@ process.
 
 
 
+Entry: u-boot-tpl-elf: U-Boot TPL ELF image
+-------------------------------------------
+
+Properties / Entry arguments:
+    - filename: Filename of TPL u-boot (default 'tpl/u-boot-tpl')
+
+This is the U-Boot TPL ELF image. It does not include a device tree but can
+be relocated to any address for execution.
+
+
+
 Entry: u-boot-tpl-with-ucode-ptr: U-Boot TPL with embedded microcode pointer
 ----------------------------------------------------------------------------
 
diff --git a/tools/binman/etype/u_boot_tpl_elf.py b/tools/binman/etype/u_boot_tpl_elf.py
new file mode 100644
index 0000000000..9cc1cc2c45
--- /dev/null
+++ b/tools/binman/etype/u_boot_tpl_elf.py
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2018 Google, Inc
+# Written by Simon Glass <sjg@chromium.org>
+#
+# Entry-type module for U-Boot TPL ELF image
+#
+
+from entry import Entry
+from blob import Entry_blob
+
+class Entry_u_boot_tpl_elf(Entry_blob):
+    """U-Boot TPL ELF image
+
+    Properties / Entry arguments:
+        - filename: Filename of TPL u-boot (default 'tpl/u-boot-tpl')
+
+    This is the U-Boot TPL ELF image. It does not include a device tree but can
+    be relocated to any address for execution.
+    """
+    def __init__(self, section, etype, node):
+        Entry_blob.__init__(self, section, etype, node)
+
+    def GetDefaultFilename(self):
+        return 'tpl/u-boot-tpl'
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 6ff871b3c1..9cec5f42fa 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1745,6 +1745,8 @@ class TestFunctional(unittest.TestCase):
     def testElf(self):
         """Basic test of ELF entries"""
         self._SetupSplElf()
+        with open(self.TestFile('bss_data'), 'rb') as fd:
+            TestFunctional._MakeInputFile('tpl/u-boot-tpl', fd.read())
         with open(self.TestFile('bss_data'), 'rb') as fd:
             TestFunctional._MakeInputFile('-boot', fd.read())
         data = self._DoReadFile('096_elf.dts')
diff --git a/tools/binman/test/096_elf.dts b/tools/binman/test/096_elf.dts
index df3440c319..8e3f3f15ef 100644
--- a/tools/binman/test/096_elf.dts
+++ b/tools/binman/test/096_elf.dts
@@ -10,5 +10,7 @@
 		};
 		u-boot-spl-elf {
 		};
+		u-boot-tpl-elf {
+		};
 	};
 };
-- 
2.39.5