I originally did this with fusefat, but it was unbearably slow. It could be useful with some optimization work... I switched to mtools instead. I have used fuse2fs on another project and it worked great.
I didn't test this too throughoughly; I just made sure that the contents were intact (by using a loopback mount). Signed-off-by: Sean Anderson <sean...@gmail.com> --- test/py/tests/test_ut.py | 44 ++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 9d42390373..8bd7153ed7 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -21,26 +21,14 @@ def setup_bootflow_image(u_boot_console): """Create a 20MB disk image with a single FAT partition""" cons = u_boot_console fname = os.path.join(cons.config.source_dir, 'mmc1.img') + fatpart = os.path.join(cons.config.source_dir, 'mmc1p1.img') mnt = os.path.join(cons.config.persistent_data_dir, 'mnt') mkdir_cond(mnt) - u_boot_utils.run_and_log(cons, 'qemu-img create %s 20M' % fname) - u_boot_utils.run_and_log(cons, 'sudo sfdisk %s' % fname, - stdin=b'type=c') - - loop = None - mounted = False - complete = False try: - out = u_boot_utils.run_and_log(cons, - 'sudo losetup --show -f -P %s' % fname) - loop = out.strip() - fatpart = '%sp1' % loop - u_boot_utils.run_and_log(cons, 'sudo mkfs.vfat %s' % fatpart) - u_boot_utils.run_and_log( - cons, 'sudo mount -o loop %s %s -o uid=%d,gid=%d' % - (fatpart, mnt, os.getuid(), os.getgid())) - mounted = True + with open(fatpart, 'ab') as part: + part.truncate(19 * 1024 * 1024) + u_boot_utils.run_and_log(cons, f'mkfs.vfat {fatpart}') vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl' initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img' @@ -78,17 +66,22 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) dtb_file = os.path.join(mnt, '%s/sandbox.dtb' % dtbdir) u_boot_utils.run_and_log( cons, 'dtc -o %s' % dtb_file, stdin=b'/dts-v1/; / {};') - complete = True + + u_boot_utils.run_and_log(cons, ('mcopy', '-bQmsi', fatpart, + *(os.path.join(mnt, file) for file in + (vmlinux, initrd, dtbdir, 'extlinux')), + '::')) + + with open(fname, 'ab') as image: + image.truncate(20 * 1024 * 1024) + u_boot_utils.run_and_log(cons, f'sfdisk {fname}', + stdin=b'type=c, start=1M, size=19M') + image.seek(1 * 1024 * 1024) + with open(fatpart, 'rb') as part: + image.write(part.read()) except ValueError as exc: - print('Falled to create image, failing back to prepared copy: %s', + print('Failed to create image, failing back to prepared copy:', str(exc)) - finally: - if mounted: - u_boot_utils.run_and_log(cons, 'sudo umount %s' % mnt) - if loop: - u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop) - - if not complete: # Use a prepared image since we cannot create one infname = os.path.join(cons.config.source_dir, 'test/py/tests/bootstd/mmc1.img.xz') @@ -96,7 +89,6 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) cons, ['sh', '-c', 'xz -dc %s >%s' % (infname, fname)]) - @pytest.mark.buildconfigspec('ut_dm') def test_ut_dm_init(u_boot_console): """Initialize data for ut dm tests.""" -- 2.37.1