U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Simon Glass <sjg@chromium.org>
Subject: [PATCH v2 20/38] binman: Add a bintool implementation for ifwitool
Date: Sun,  9 Jan 2022 20:13:55 -0700	[thread overview]
Message-ID: <20220110031413.1970836-21-sjg@chromium.org> (raw)
In-Reply-To: <20220110031413.1970836-1-sjg@chromium.org>

Add a Bintool for this, which is used to build Intel IFWI images. It
supports the features needed by the tests as well as downloading a binary
from Google Drive. Although this is built in the U-Boot tree, it is not
currently included with u-boot-tools, so it may be useful to install a
binary on the system.

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

(no changes since v1)

 tools/binman/btool/ifwitool.py | 166 +++++++++++++++++++++++++++++++++
 1 file changed, 166 insertions(+)
 create mode 100644 tools/binman/btool/ifwitool.py

diff --git a/tools/binman/btool/ifwitool.py b/tools/binman/btool/ifwitool.py
new file mode 100644
index 00000000000..96778fce87f
--- /dev/null
+++ b/tools/binman/btool/ifwitool.py
@@ -0,0 +1,166 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2022 Google LLC
+#
+"""Bintool implementation for ifwitool
+
+ifwitool provides a way to package firmware in an Intel Firmware Image (IFWI)
+file on some Intel SoCs, e.g. Apolo Lake.
+
+Documentation is not really available so far as I can tell
+
+Source code is at tools/ifwitool.c which is a cleaned-up version of
+https://github.com/coreboot/coreboot/blob/master/util/cbfstool/ifwitool.c
+
+Here is the help:
+
+ifwitool: Utility for IFWI manipulation
+
+USAGE:
+ /tmp/b/sandbox/tools/ifwitool [-h]
+ /tmp/b/sandbox/tools/ifwitool FILE COMMAND [PARAMETERS]
+
+COMMANDs:
+ add -f FILE -n NAME [-d -e ENTRY]
+ create -f FILE
+ delete -n NAME
+ extract -f FILE -n NAME [-d -e ENTRY]
+ print [-d]
+ replace -f FILE -n NAME [-d -e ENTRY]
+OPTIONs:
+ -f FILE : File to read/write/create/extract
+ -d      : Perform directory operation
+ -e ENTRY: Name of directory entry to operate on
+ -v      : Verbose level
+ -h      : Help message
+ -n NAME : Name of sub-partition to operate on
+
+NAME should be one of:
+SMIP(SMIP)
+RBEP(CSE_RBE)
+FTPR(CSE_BUP)
+UCOD(Microcode)
+IBBP(Bootblock)
+S_BPDT(S-BPDT)
+OBBP(OEM boot block)
+NFTP(CSE_MAIN)
+ISHP(ISH)
+DLMP(CSE_IDLM)
+IFP_OVERRIDE(IFP_OVERRIDE)
+DEBUG_TOKENS(Debug Tokens)
+UFS_PHY(UFS Phy)
+UFS_GPP(UFS GPP)
+PMCP(PMC firmware)
+IUNP(IUNIT)
+NVM_CONFIG(NVM Config)
+UEP(UEP)
+UFS_RATE_B(UFS Rate B Config)
+"""
+
+from binman import bintool
+
+class Bintoolifwitool(bintool.Bintool):
+    """Handles the 'ifwitool' tool
+
+    This bintool supports running `ifwitool` with some basic parameters as
+    neeed by binman. It includes creating a file from a FIT as well as adding,
+    replacing, deleting and extracting subparts.
+
+    The tool is built as part of U-Boot, but a binary version can be fetched if
+    required.
+
+    ifwitool provides a way to package firmware in an Intel Firmware Image
+    (IFWI) file on some Intel SoCs, e.g. Apolo Lake.
+    """
+    def __init__(self, name):
+        super().__init__(name, 'Manipulate Intel IFWI files')
+
+    def create_ifwi(self, intel_fit, ifwi_file):
+        """Create a new IFWI file, using an existing Intel FIT binary
+
+        Args:
+            intel_fit (str): Filename of exist Intel FIT file
+            ifwi_file (str): Output filename to write the new IFWI too
+
+        Returns:
+            str: Tool output
+        """
+        args = [intel_fit, 'create', '-f', ifwi_file]
+        return self.run_cmd(*args)
+
+    def delete_subpart(self, ifwi_file, subpart):
+        """Delete a subpart within the IFWI file
+
+        Args:
+            ifwi_file (str): IFWI filename to update
+            subpart (str): Name of subpart to delete, e.g. 'OBBP'
+
+        Returns:
+            str: Tool output
+        """
+        args = [ifwi_file, 'delete', '-n', subpart]
+        return self.run_cmd(*args)
+
+    # pylint: disable=R0913
+    def add_subpart(self, ifwi_file, subpart, entry_name, infile,
+                    replace=False):
+        """Add or replace a subpart within the IFWI file
+
+        Args:
+            ifwi_file (str): IFWI filename to update
+            subpart (str): Name of subpart to add/replace
+            entry_nme (str): Name of entry to add/replace
+            replace (bool): True to replace the existing entry, False to add a
+                new one
+
+        Returns:
+            str: Tool output
+        """
+        args = [
+            ifwi_file,
+            'replace' if replace else 'add',
+            '-n', subpart,
+            '-d', '-e', entry_name,
+            '-f', infile,
+            ]
+        return self.run_cmd(*args)
+
+    def extract(self, ifwi_file, subpart, entry_name, outfile):
+        """Extract a subpart from the IFWI file
+
+        Args:
+            ifwi_file (str): IFWI filename to extract from
+            subpart (str): Name of subpart to extract
+            entry_nme (str): Name of entry to extract
+
+        Returns:
+            str: Tool output
+        """
+        args = [
+            ifwi_file,
+            'extract',
+            '-n', subpart,
+            '-d', '-e', entry_name,
+            '-f', outfile,
+            ]
+        return self.run_cmd(*args)
+
+    def fetch(self, method):
+        """Fetch handler for ifwitool
+
+        This installs ifwitool using a binary download.
+
+        Args:
+            method (FETCH_...): Method to use
+
+        Returns:
+            True if the file was fetched, None if a method other than FETCH_BIN
+            was requested
+
+        Raises:
+            Valuerror: Fetching could not be completed
+        """
+        if method != bintool.FETCH_BIN:
+            return None
+        fname, tmpdir = self.fetch_from_drive(
+            '18JDghOxlt2Hcc5jv51O1t6uNVHQ0XKJS')
+        return fname, tmpdir
-- 
2.34.1.575.g55b058a8bb-goog


  parent reply	other threads:[~2022-01-10  3:18 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-10  3:13 [PATCH v2 00/38] binman: Add support for bintools and missing tools Simon Glass
2022-01-10  3:13 ` [PATCH v2 01/38] Makefile: Fake external blobs by default with binman Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-10-10 10:15   ` Rasmus Villemoes
2022-10-10 14:25     ` Tom Rini
2022-10-10 15:19     ` Simon Glass
2022-10-10 15:24       ` Tom Rini
2022-10-10 15:33         ` Simon Glass
2022-10-10 15:36           ` Tom Rini
2022-10-10 15:43             ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 02/38] binman: Tweak elf tests for a toolchain change Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 03/38] mkimage: Show the external-offset error Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 04/38] binman: Expand the external FIT test a little Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 05/38] patman: Allow running a tool and returning the full result Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 06/38] buildman: Move the download function to tools Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 07/38] patman: Tidy up the download function a little Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 08/38] patman: Add a function to find a tool on the path Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 09/38] binman: Write fake blobs to the output directory Simon Glass
2022-01-10  3:13 ` [PATCH v2 10/38] binman: Drop the image name from the fake-blob message Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 11/38] binman: Allow faked blobs in blob-ext-list Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 12/38] binman: Correct path for fip_util Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 13/38] binman: Add installation instructions Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 14/38] binman: Add support for bintools Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 15/38] binman: Plumb in " Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 16/38] binman: Add tests for bintool Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 17/38] binman: Add a bintool implementation for cbfstool Simon Glass
2022-01-26 15:37   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 18/38] binman: Add a bintool implementation for fiptool Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 19/38] binman: Add a bintool implementation for futility Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:13 ` Simon Glass [this message]
2022-01-26 15:36   ` [PATCH v2 20/38] binman: Add a bintool implementation for ifwitool Simon Glass
2022-01-10  3:13 ` [PATCH v2 21/38] binman: Add a bintool implementation for mkimage Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 22/38] binman: Enable bintool tests including cmdline processing Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 23/38] binman: Convert to using the CBFS bintool Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:13 ` [PATCH v2 24/38] binman: Convert to using the FIP bintool Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 25/38] binman: Convert to using the futility bintool Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 26/38] binman: Convert to using the ifwitool bintool Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 27/38] binman: Convert to using the mkimage bintool Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 28/38] binman: Move compression into binman Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 29/38] binman: Tidy up pylint warnings in comp_util Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 30/38] binman: Add a bintool implementation for lz4 Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 31/38] binman: Convert to using the lz4 bintool Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 32/38] binman: Add a bintool implementation for lzma_alone Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 33/38] binman: Convert to using the lzma_alone bintool Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 34/38] binman: Plumb in support for missing bintools Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 35/38] binman: Complete test coverage of comp_util Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 36/38] binman: Add a command to generate bintool docs Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 37/38] binman: Add documentation for bintools Simon Glass
2022-01-26 15:36   ` Simon Glass
2022-01-10  3:14 ` [PATCH v2 38/38] RFC: Move Odroid-C2 to use binman to produce the image Simon Glass
2022-01-21  2:02 ` [PATCH v2 00/38] binman: Add support for bintools and missing tools 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=20220110031413.1970836-21-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox