Skip to contentSkip to conversation

binman: build_from_git: Add argument specifying branch

PATCH In review Leonard Anderweit 3 participants 7 messages Feb 26, 2025 – Mar 12, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 binman: build_from_git: Add argument specifying branch

Add optional argument git_branch to build_from_git. The new argument allows specifying which branch of the repo to use.

---
 tools/binman/bintool.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/binman/bintool.py +8 -2
index 3c4ad1adbb9e..7280ee4f8cd9 100644
@@ -328,7 +328,8 @@ class Bintool:
             return result.stdout
 
     @classmethod
-    def build_from_git(cls, git_repo, make_targets, bintool_path, flags=None):
+    def build_from_git(cls, git_repo, make_targets, bintool_path,
+            flags=None, git_branch=None):
         """Build a bintool from a git repo
 
         This clones the repo in a temporary directory, builds it with 'make',
@@ -341,6 +342,7 @@ class Bintool:
             bintool_path (str): Relative path of the tool in the repo, after
                 build is complete
             flags (list of str): Flags or variables to pass to make, or None
+            git_branch (str): Branch of git repo, or None to use the default
 
         Returns:
             tuple:
@@ -350,7 +352,11 @@ class Bintool:
         """
         tmpdir = tempfile.mkdtemp(prefix='binmanf.')
         print(f"- clone git repo '{git_repo}' to '{tmpdir}'")
-        tools.run('git', 'clone', '--depth', '1', git_repo, tmpdir)
+        if git_branch:
+            tools.run('git', 'clone', '--depth', '1', '--branch', git_branch,
+                      git_repo, tmpdir)
+        else:
+            tools.run('git', 'clone', '--depth', '1', git_repo, tmpdir)
         for target in make_targets:
             print(f"- build target '{target}'")
             cmd = ['make', '-C', tmpdir, '-j', f'{multiprocessing.cpu_count()}',
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/3 binman: build_from_git: Add optional make path inside git repo

Add optional argument make_path to build_from git. The new argument allows specifying the path to a Makefile in case it is not in the root of the git repo.
Also adjust the corresponding test.

---
v2: fix tests

---
 tools/binman/bintool.py      | 9 +++++++--
 tools/binman/bintool_test.py | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)
tools/binman/bintool.py +7 -2
index 7280ee4f8cd9..81872db377f9 100644
@@ -329,7 +329,7 @@ class Bintool:
 
     @classmethod
     def build_from_git(cls, git_repo, make_targets, bintool_path,
-            flags=None, git_branch=None):
+            flags=None, git_branch=None, make_path=None):
         """Build a bintool from a git repo
 
         This clones the repo in a temporary directory, builds it with 'make',
@@ -343,6 +343,8 @@ class Bintool:
                 build is complete
             flags (list of str): Flags or variables to pass to make, or None
             git_branch (str): Branch of git repo, or None to use the default
+            make_path (str): Relative path inside git repo containing the
+                Makefile, or None
 
         Returns:
             tuple:
@@ -359,7 +361,10 @@ class Bintool:
             tools.run('git', 'clone', '--depth', '1', git_repo, tmpdir)
         for target in make_targets:
             print(f"- build target '{target}'")
-            cmd = ['make', '-C', tmpdir, '-j', f'{multiprocessing.cpu_count()}',
+            makedir = tmpdir
+            if make_path:
+                makedir = os.path.join(tmpdir, make_path)
+            cmd = ['make', '-C', makedir, '-j', f'{multiprocessing.cpu_count()}',
                    target]
             if flags:
                 cmd += flags
tools/binman/bintool_test.py +1 -0
index f9b16d4c73b5..949d6f4c8a90 100644
@@ -303,6 +303,7 @@ class TestBintool(unittest.TestCase):
                 # See Bintool.build_from_git()
                 tmpdir = cmd[2]
                 self.fname = os.path.join(tmpdir, 'pathname')
+                os.makedirs(os.path.dirname(tmpdir), exist_ok=True)
                 tools.write_file(self.fname, b'hello')
 
         expected = b'this is a test'
Signature · 1 line
2.34.1
Reviewed-by on v2 2/3
#2 lore raw

Re: [PATCH v2 2/3] binman: build_from_git: Add optional make path inside git repo

Quoted 6 lines · Leonard Anderweit

Add optional argument make_path to build_from git. The new argument allows specifying the path to a Makefile in case it is not in the root of the git repo.
Also adjust the corresponding test.

Quoted 7 lines

---
v2: fix tests

---
 tools/binman/bintool.py      | 9 +++++++--
 tools/binman/bintool_test.py | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)
#3 lore raw

PATCH v2 3/3 binman: cst: Build from source

In reply to Leonard Anderweit

Build the imx code singing tool from source instead of relying on the distro to provide the tool.
Use the debian/unstable branch because the default branch is outdated. The binary is supposed to be build with docker, work around that by selecting the correct Makefile directly.
Also append the description and add a link to documentation.

---
v2: add documentation

---
 tools/binman/bintools.rst |  8 ++++++++
 tools/binman/btool/cst.py | 37 +++++++++++++++++++++----------------
 2 files changed, 29 insertions(+), 16 deletions(-)
tools/binman/bintools.rst +8 -0
index cd05ad8cb26d..9f6cab544a5e 100644
@@ -52,6 +52,14 @@ Bintool: cst: Image generation for U-Boot
 This bintool supports running `cst` with some basic parameters as
 needed by binman.
 
+cst (imx code signing tool) is used for sigining bootloader binaries for
+various i.MX SoCs.
+
+See `Code Signing Tool Users Guide`_ for more information.
+
+.. _`Code Signing Tool Users Guide`:
+    https://community.nxp.com/pwmxy87654/attachments/pwmxy87654/imx-processors/202591/1/CST_UG.pdf
+
 
 
 Bintool: fdt_add_pubkey: Add public key to control dtb (spl or u-boot proper)
tools/binman/btool/cst.py +21 -16
index 30e78bdbbd9d..8a3981adc890 100644
@@ -12,6 +12,14 @@ class Bintoolcst(bintool.Bintool):
 
     This bintool supports running `cst` with some basic parameters as
     needed by binman.
+
+    cst (imx code signing tool) is used for sigining bootloader binaries for
+    various i.MX SoCs.
+
+    See `Code Signing Tool Users Guide`_ for more information.
+
+    .. _`Code Signing Tool Users Guide`:
+        https://community.nxp.com/pwmxy87654/attachments/pwmxy87654/imx-processors/202591/1/CST_UG.pdf
     """
     def __init__(self, name):
         super().__init__(name, 'Sign NXP i.MX image')
@@ -29,20 +37,17 @@ class Bintoolcst(bintool.Bintool):
         return self.run_cmd(*args)
 
     def fetch(self, method):
-        """Fetch handler for cst
-
-        This installs cst using the apt utility.
-
-        Args:
-            method (FETCH_...): Method to use
-
-        Returns:
-            True if the file was fetched and now installed, None if a method
-            other than FETCH_BIN was requested
-
-        Raises:
-            Valuerror: Fetching could not be completed
-        """
-        if method != bintool.FETCH_BIN:
+        """Build cst from git"""
+        if method != bintool.FETCH_BUILD:
             return None
-        return self.apt_install('imx-code-signing-tool')
+
+        from platform import architecture
+        arch = 'linux64' if architecture()[0] == '64bit' else 'linux32'
+        result = self.build_from_git(
+            'https://gitlab.apertis.org/pkg/imx-code-signing-tool',
+            ['all'],
+            f'code/obj.{arch}/cst',
+            flags=[f'OSTYPE={arch}', 'ENCRYPTION=yes'],
+            git_branch='debian/unstable',
+            make_path=f'code/obj.{arch}/')
+        return result
Signature · 1 line
2.34.1
Reviewed-by on v2 3/3
#4 lore raw

Re: [PATCH v2 3/3] binman: cst: Build from source

Quoted 8 lines · Leonard Anderweit

Build the imx code singing tool from source instead of relying on the distro to provide the tool.
Use the debian/unstable branch because the default branch is outdated. The binary is supposed to be build with docker, work around that by selecting the correct Makefile directly.
Also append the description and add a link to documentation.

Quoted 8 lines

---
v2: add documentation

---
 tools/binman/bintools.rst |  8 ++++++++
 tools/binman/btool/cst.py | 37 +++++++++++++++++++++----------------
 2 files changed, 29 insertions(+), 16 deletions(-)
#6 lore raw
In reply to Leonard Anderweit
Quoted 4 lines · Leonard Anderweit

Add optional argument git_branch to build_from_git. The new argument allows specifying which branch of the repo to use.

Applied to u-boot/next, thanks!

[1/3] binman: build_from_git: Add argument specifying branch

      commit: 5f2096d2bc58ac265110777d08673a0e4b27cd84
[2/3] binman: build_from_git: Add optional make path inside git repo
      commit: b48bc416206788da990c34ddcf92d5c3816247ea
[3/3] binman: cst: Build from source
      commit: 326b7ea9823a74a83b3a7ef6ee3f4927eb36987e
Signature · 1 line
Tom