[PATCH 1/6] test: Update fs_helper to support passing in the image
Simon Glass
sjg at chromium.org
Sun May 11 16:18:16 CEST 2025
This function is useful for other scripts, so add a parameter to specify
the image name, if desired.
Also add a flag to quieten the output of some of the tools, since in
many cases we only want to see warnings / errors.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
test/py/tests/fs_helper.py | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py
index b8a22b22806..d124f03a7dc 100644
--- a/test/py/tests/fs_helper.py
+++ b/test/py/tests/fs_helper.py
@@ -8,8 +8,10 @@
import re
import os
from subprocess import call, check_call, check_output, CalledProcessError
+from subprocess import DEVNULL
-def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):
+def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000,
+ fs_img=None, quiet=False):
"""Create a file system volume
Args:
@@ -19,12 +21,15 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):
prefix (str): Prefix string of volume's file name
src_dir (str): Root directory to use, or None for none
size_gran (int): Size granularity of file system image in bytes
+ fs_img (str or None): Filename for image, or None to invent one
+ quiet (bool): Suppress non-error output
Raises:
CalledProcessError: if any error occurs when creating the filesystem
"""
- fs_img = f'{prefix}.{fs_type}.img'
- fs_img = os.path.join(config.persistent_data_dir, fs_img)
+ if not fs_img:
+ leaf = f'{prefix}.{fs_type}.img'
+ fs_img = os.path.join(config.persistent_data_dir, leaf)
if fs_type == 'fat12':
mkfs_opt = '-F 12'
@@ -58,14 +63,17 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):
check_call(f'rm -f {fs_img}', shell=True)
check_call(f'truncate -s $(( {size_gran} * {count} )) {fs_img}',
shell=True)
- check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True)
+ check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True,
+ stdout=DEVNULL if quiet else None)
if fs_type == 'ext4':
sb_content = check_output(f'tune2fs -l {fs_img}',
shell=True).decode()
if 'metadata_csum' in sb_content:
check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True)
elif fs_lnxtype == 'vfat' and src_dir:
- check_call(f'mcopy -i {fs_img} -vsmpQ {src_dir}/* ::/', shell=True)
+ flags = f"-smpQ{'' if quiet else 'v'}"
+ check_call(f'mcopy -i {fs_img} {flags} {src_dir}/* ::/',
+ shell=True)
elif fs_lnxtype == 'exfat' and src_dir:
check_call(f'fattools cp {src_dir}/* {fs_img}', shell=True)
return fs_img
--
2.43.0
More information about the U-Boot
mailing list