[PATCH 01/11] test: Create a common file for image utilities

Simon Glass sjg at chromium.org
Mon May 18 00:50:59 CEST 2026


Move mkdir_cond(), copy_partition(), and setup_extlinux_image() to a
common module which can be used by the rest of the image-creation code.

Add myself as a maintainer for this new directory, and the test/py
framework itself.

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

 MAINTAINERS              |  5 +++
 test/py/img/common.py    | 86 ++++++++++++++++++++++++++++++++++++++++
 test/py/tests/test_ut.py | 73 +---------------------------------
 3 files changed, 92 insertions(+), 72 deletions(-)
 create mode 100644 test/py/img/common.py

diff --git a/MAINTAINERS b/MAINTAINERS
index 0dcc7243124..d33ea42116c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1829,6 +1829,11 @@ M:	Liviu Dudau <liviu.dudau at foss.arm.com>
 S:	Maintained
 F:	drivers/video/tda19988.c
 
+TEST FRAMEWORK (PYTHON)
+M:	Simon Glass <sjg at chromium.org>
+F:	test/py
+F:	test/py/img
+
 TI LP5562 LED DRIVER
 M:	Rasmus Villemoes <rasmus.villemoes at prevas.dk>
 S:	Supported
diff --git a/test/py/img/common.py b/test/py/img/common.py
new file mode 100644
index 00000000000..37349c0a2e7
--- /dev/null
+++ b/test/py/img/common.py
@@ -0,0 +1,86 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
+
+"""Common utilities for image creation"""
+
+import gzip
+import os
+
+import utils
+from fs_helper import DiskHelper, FsHelper
+
+
+def mkdir_cond(dirname):
+    """Create a directory if it doesn't already exist
+
+    Args:
+        dirname (str): Name of directory to create
+    """
+    if not os.path.exists(dirname):
+        os.mkdir(dirname)
+
+
+def copy_partition(ubman, fsfile, outname):
+    """Copy a partition into a disk image
+
+    Args:
+        ubman (ConsoleBase): U-Boot fixture
+        fsfile (str): Name of partition file
+        outname (str): Name of full-disk file to update
+    """
+    utils.run_and_log(ubman,
+                      f'dd if={fsfile} of={outname} bs=1M seek=1 conv=notrunc')
+
+
+def setup_extlinux_image(ubman, devnum, basename, vmlinux, initrd, dtbdir,
+                         script):
+    """Create a 20MB disk image with a single FAT partition
+
+    Args:
+        ubman (ConsoleBase): Console to use
+        devnum (int): Device number to use, e.g. 1
+        basename (str): Base name to use in the filename, e.g. 'mmc'
+        vmlinux (str): Kernel filename
+        initrd (str): Ramdisk filename
+        dtbdir (str or None): Devicetree filename
+        script (str): Script to place in the extlinux.conf file
+    """
+    fsh = FsHelper(ubman.config, 'vfat', 18, prefix=basename)
+    fsh.setup()
+
+    ext = os.path.join(fsh.srcdir, 'extlinux')
+    mkdir_cond(ext)
+
+    conf = os.path.join(ext, 'extlinux.conf')
+    with open(conf, 'w', encoding='ascii') as fd:
+        print(script, file=fd)
+
+    inf = os.path.join(ubman.config.persistent_data_dir, 'inf')
+    with open(inf, 'wb') as fd:
+        fd.write(gzip.compress(b'vmlinux'))
+    mkimage = ubman.config.build_dir + '/tools/mkimage'
+    utils.run_and_log(
+        ubman, f'{mkimage} -f auto -d {inf} {os.path.join(fsh.srcdir, vmlinux)}')
+
+    with open(os.path.join(fsh.srcdir, initrd), 'w', encoding='ascii') as fd:
+        print('initrd', file=fd)
+
+    if dtbdir:
+        mkdir_cond(os.path.join(fsh.srcdir, dtbdir))
+
+        dtb_file = os.path.join(fsh.srcdir, f'{dtbdir}/sandbox.dtb')
+        utils.run_and_log(
+            ubman, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};')
+
+    fsh.mk_fs()
+
+    img = DiskHelper(ubman.config, devnum, basename, True)
+    img.add_fs(fsh, DiskHelper.VFAT, bootable=True)
+
+    ext4 = FsHelper(ubman.config, 'ext4', 1, prefix=basename)
+    ext4.setup()
+    ext4.mk_fs()
+
+    img.add_fs(ext4, DiskHelper.EXT4)
+    img.create()
+    fsh.cleanup()
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index dce5a37dd35..97ef2d8e517 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -19,26 +19,8 @@ import utils
 from tests import fs_helper
 from fs_helper import DiskHelper, FsHelper
 from test_android import test_abootimg
+from img.common import mkdir_cond, copy_partition, setup_extlinux_image
 
-def mkdir_cond(dirname):
-    """Create a directory if it doesn't already exist
-
-    Args:
-        dirname (str): Name of directory to create
-    """
-    if not os.path.exists(dirname):
-        os.mkdir(dirname)
-
-def copy_partition(ubman, fsfile, outname):
-    """Copy a partition into a disk iamge
-
-    Args:
-        ubman (ConsoleBase): U-Boot fixture
-        fsfile (str): Name of partition file
-        outname (str): Name of full-disk file to update
-    """
-    utils.run_and_log(ubman,
-                      f'dd if={fsfile} of={outname} bs=1M seek=1 conv=notrunc')
 
 def setup_bootmenu_image(ubman):
     """Create a 20MB disk image with a single ext4 partition
@@ -159,59 +141,6 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
     fsh.cleanup()
 
 
-def setup_extlinux_image(ubman, devnum, basename, vmlinux, initrd, dtbdir,
-                         script):
-    """Create a 20MB disk image with a single FAT partition
-
-    Args:
-        ubman (ConsoleBase): Console to use
-        devnum (int): Device number to use, e.g. 1
-        basename (str): Base name to use in the filename, e.g. 'mmc'
-        vmlinux (str): Kernel filename
-        initrd (str): Ramdisk filename
-        dtbdir (str or None): Devicetree filename
-        script (str): Script to place in the extlinux.conf file
-    """
-    fsh = FsHelper(ubman.config, 'vfat', 18, prefix=basename)
-    fsh.setup()
-
-    ext = os.path.join(fsh.srcdir, 'extlinux')
-    mkdir_cond(ext)
-
-    conf = os.path.join(ext, 'extlinux.conf')
-    with open(conf, 'w', encoding='ascii') as fd:
-        print(script, file=fd)
-
-    inf = os.path.join(ubman.config.persistent_data_dir, 'inf')
-    with open(inf, 'wb') as fd:
-        fd.write(gzip.compress(b'vmlinux'))
-    mkimage = ubman.config.build_dir + '/tools/mkimage'
-    utils.run_and_log(
-        ubman, f'{mkimage} -f auto -d {inf} {os.path.join(fsh.srcdir, vmlinux)}')
-
-    with open(os.path.join(fsh.srcdir, initrd), 'w', encoding='ascii') as fd:
-        print('initrd', file=fd)
-
-    if dtbdir:
-        mkdir_cond(os.path.join(fsh.srcdir, dtbdir))
-
-        dtb_file = os.path.join(fsh.srcdir, f'{dtbdir}/sandbox.dtb')
-        utils.run_and_log(
-            ubman, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};')
-
-    fsh.mk_fs()
-
-    img = DiskHelper(ubman.config, devnum, basename, True)
-    img.add_fs(fsh, DiskHelper.VFAT, bootable=True)
-
-    ext4 = FsHelper(ubman.config, 'ext4', 1, prefix=basename)
-    ext4.setup()
-    ext4.mk_fs()
-
-    img.add_fs(ext4, DiskHelper.EXT4)
-    img.create()
-    fsh.cleanup()
-
 def setup_fedora_image(ubman, devnum, basename):
     """Create a 20MB Fedora disk image with a single FAT partition
 
-- 
2.43.0



More information about the U-Boot mailing list