diff mbox series

[2/5] binman: Add basic 'file_size' and 'int32' entry types

Message ID 20240126092533.20709-2-piotr.wojtaszczyk@timesys.com
State New
Delegated to: Marek Vasut
Headers show
Series [1/5] usb: ohci-generic: ignore ENOSYS and ENOTSUPP errors from clk and reset | expand

Commit Message

Piotr Wojtaszczyk Jan. 26, 2024, 9:25 a.m. UTC
Entry 'int32' type can inject arbitrary 32bit integer value into a firmware
file. Entry 'file_size' type can inject file size as 32bit integer value into a
firmware file.
Both entries are helpful when a boot ROM requires magic value and/or
firmware length in header.

Signed-off-by: Piotr Wojtaszczyk <piotr.wojtaszczyk@timesys.com>
---

 tools/binman/entries.rst        | 25 +++++++++++++++++++++++++
 tools/binman/etype/file_size.py | 28 ++++++++++++++++++++++++++++
 tools/binman/etype/int32.py     | 24 ++++++++++++++++++++++++
 3 files changed, 77 insertions(+)
 create mode 100644 tools/binman/etype/file_size.py
 create mode 100644 tools/binman/etype/int32.py
diff mbox series

Patch

diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst
index 254afe7607..7696ea7023 100644
--- a/tools/binman/entries.rst
+++ b/tools/binman/entries.rst
@@ -712,6 +712,18 @@  without the fdtmap header, so it can be viewed with `fdtdump`.
 
 
 
+.. _etype_file_size:
+
+Entry: file_size: Size of a file as 32bit integer
+--------------------------------------------------
+
+Properties / Entry arguments:
+    - filename: relative file path
+
+This entry reads file size and places it as 32bit integer.
+
+
+
 .. _etype_files:
 
 Entry: files: A set of files arranged in a section
@@ -1138,6 +1150,19 @@  first/last in the entry list.
 
 
 
+.. _etype_int32:
+
+Entry: int32: Arbitrary 32bit integer
+--------------------------------------------------
+
+Properties / Entry arguments:
+    - value: 32bit integer value
+
+This entry places arbitrary 32bit integer. Useful when a magic value is
+required in a firmware.
+
+
+
 .. _etype_intel_cmc:
 
 Entry: intel-cmc: Intel Chipset Micro Code (CMC) file
diff --git a/tools/binman/etype/file_size.py b/tools/binman/etype/file_size.py
new file mode 100644
index 0000000000..d99ca1c067
--- /dev/null
+++ b/tools/binman/etype/file_size.py
@@ -0,0 +1,28 @@ 
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2023 Timesys
+# Written by Piotr Wojtaszczyk <piotr.wojtaszczyk@timesys.com>
+#
+
+from binman.entry import Entry
+from dtoc import fdt_util
+from u_boot_pylib import tools
+import sys
+
+class Entry_file_size(Entry):
+    """An entry which is filled size of a file
+
+    Properties / Entry arguments:
+        - file: path to the file
+
+    Useful where a firmware header needs length of the firmware.
+    """
+    def __init__(self, section, etype, node):
+        super().__init__(section, etype, node)
+        self._filename = fdt_util.GetString(self._node, 'filename', self.etype)
+
+    def ObtainContents(self):
+        self._pathname = tools.get_input_filename(self._filename,
+            self.external and self.section.GetAllowMissing())
+        self._file_size = len(tools.read_file(self._pathname))
+        self.SetContents(self._file_size.to_bytes(4, sys.byteorder))
+        return True
diff --git a/tools/binman/etype/int32.py b/tools/binman/etype/int32.py
new file mode 100644
index 0000000000..463dfe46fd
--- /dev/null
+++ b/tools/binman/etype/int32.py
@@ -0,0 +1,24 @@ 
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2023 Timesys
+# Written by Piotr Wojtaszczyk <piotr.wojtaszczyk@timesys.com>
+#
+
+from binman.entry import Entry
+from dtoc import fdt_util
+import sys
+
+class Entry_int32(Entry):
+    """An entry which is filled with arbitrary int32 data
+
+    Properties / Entry arguments:
+        - value: int32 value
+
+    Useful where a magic header is needed.
+    """
+    def __init__(self, section, etype, node):
+        super().__init__(section, etype, node)
+        self._int32_value = fdt_util.GetInt(self._node, 'value', 0)
+
+    def ObtainContents(self):
+        self.SetContents(self._int32_value.to_bytes(4, sys.byteorder))
+        return True