Skip to contentSkip to conversation

binman: build_from_git: Add argument specifying branch

PATCH Superseded Leonard Anderweit 2 participants 6 messages Feb 25, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 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.

---
 tools/binman/bintool.py | 9 +++++++--
 1 file changed, 7 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
Signature · 1 line
2.34.1
#2 lore raw

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

Hi Leonard,

Quoted 45 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.

---
 tools/binman/bintool.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/binman/bintool.py +7 -3
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
--
Quoted 2 lines

2.34.1

This is fine, but you need to update the fake_run() function in test_all_bintools() so that the tests will pass:

            if cmd[0] == 'make':
                ...
                os.makedirs(os.path.dirname(tmpdir), exist_ok=True)

Regards,
Simon

#3 lore raw

PATCH 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.

---
 tools/binman/btool/cst.py | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)
tools/binman/btool/cst.py +13 -16
index 30e78bdbbd9d..0a23d12d3e2f 100644
@@ -29,20 +29,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
#4 lore raw

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

Hi Leonard,

Quoted 7 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.

Quoted 5 lines
---
 tools/binman/btool/cst.py | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

Thank you for doing this!

If you have any more info about the tool, please add it to the comment at the top of Bintoolcst and regenerate the .rst with 'binman bintool-docs'

Quoted 39 lines
tools/binman/btool/cst.py +13 -17
index 30e78bdbbd9d..0a23d12d3e2f 100644
@@ -29,20 +29,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
--
Quoted 2 lines

2.34.1

Regards,
SImon