From 5b2ea71eaf13694b77545c5df9ec80d25d0e2f14 Mon Sep 17 00:00:00 2001 From: Richard Weinberger Date: Thu, 21 Nov 2024 15:32:07 -0700 Subject: [PATCH 01/20] test_fs: Allow running unprivileged There is no need to mount the filesystem on the host side. All filesystem tools offer some way to fill the fs without mounting. So, create the content on the host side, create and fill the fs without mounting. No more sudo or guestmount needed. This new approach works because the tests don't care about user IDs and no device files are needed. If user IDs start to matter it's still possible to use wrapper tools like fakeroot in future while filling the fs. Signed-off-by: Richard Weinberger Signed-off-by: Simon Glass Tested-by: Mattijs Korpershoek --- test/py/tests/fs_helper.py | 11 +- test/py/tests/test_fs/conftest.py | 175 ++++++------------------------ test/py/tests/test_ut.py | 4 +- 3 files changed, 47 insertions(+), 143 deletions(-) diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py index 380f4c4dca3..ccfc0201a49 100644 --- a/test/py/tests/fs_helper.py +++ b/test/py/tests/fs_helper.py @@ -9,7 +9,7 @@ import re import os from subprocess import call, check_call, check_output, CalledProcessError -def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000): +def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): """Create a file system volume Args: @@ -17,6 +17,7 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000): fs_type (str): File system type, e.g. 'ext4' size (int): Size of file system in bytes 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 Raises: @@ -39,6 +40,12 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000): else: fs_lnxtype = fs_type + if src_dir: + if fs_lnxtype == 'ext4': + mkfs_opt = mkfs_opt + ' -d ' + src_dir + elif fs_lnxtype != 'vfat': + raise ValueError(f'src_dir not implemented for fs {fs_lnxtype}') + count = (size + size_gran - 1) // size_gran # Some distributions do not add /sbin to the default PATH, where mkfs lives @@ -55,6 +62,8 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000): 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) return fs_img except CalledProcessError: call(f'rm -f {fs_img}', shell=True) diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index fca54488374..59342a6e3dd 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -156,64 +156,6 @@ def tool_is_in_path(tool): return True return False -fuse_mounted = False - -def mount_fs(fs_type, device, mount_point): - """Mount a volume. - - Args: - fs_type: File system type. - device: Volume's file name. - mount_point: Mount point. - - Return: - Nothing. - """ - global fuse_mounted - - try: - check_call('guestmount --pid-file guestmount.pid -a %s -m /dev/sda %s' - % (device, mount_point), shell=True) - fuse_mounted = True - return - except CalledProcessError: - fuse_mounted = False - - mount_opt = 'loop,rw' - if re.match('fat', fs_type): - mount_opt += ',umask=0000' - - check_call('sudo mount -o %s %s %s' - % (mount_opt, device, mount_point), shell=True) - - # may not be effective for some file systems - check_call('sudo chmod a+rw %s' % mount_point, shell=True) - -def umount_fs(mount_point): - """Unmount a volume. - - Args: - mount_point: Mount point. - - Return: - Nothing. - """ - if fuse_mounted: - call('sync') - call('guestunmount %s' % mount_point, shell=True) - - try: - with open("guestmount.pid", "r") as pidfile: - pid = int(pidfile.read()) - util.waitpid(pid, kill=True) - os.remove("guestmount.pid") - - except FileNotFoundError: - pass - - else: - call('sudo umount %s' % mount_point, shell=True) - # # Fixture for basic fs test # derived from test/fs/fs-test.sh @@ -241,14 +183,6 @@ def fs_obj_basic(request, u_boot_config): small_file = mount_dir + '/' + SMALL_FILE big_file = mount_dir + '/' + BIG_FILE - try: - - # 3GiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB') - except CalledProcessError as err: - pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) - return - try: check_call('mkdir -p %s' % mount_dir, shell=True) except CalledProcessError as err: @@ -256,15 +190,6 @@ def fs_obj_basic(request, u_boot_config): call('rm -f %s' % fs_img, shell=True) return - try: - # Mount the image so we can populate it. - mount_fs(fs_type, fs_img, mount_dir) - except CalledProcessError as err: - pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err)) - call('rmdir %s' % mount_dir, shell=True) - call('rm -f %s' % fs_img, shell=True) - return - try: # Create a subdirectory. check_call('mkdir %s/SUBDIR' % mount_dir, shell=True) @@ -326,15 +251,20 @@ def fs_obj_basic(request, u_boot_config): % big_file, shell=True).decode() md5val.append(out.split()[0]) + try: + # 3GiB volume + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB', mount_dir) + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + except CalledProcessError as err: pytest.skip('Setup failed for filesystem: ' + fs_type + '. {}'.format(err)) - umount_fs(mount_dir) return else: - umount_fs(mount_dir) yield [fs_ubtype, fs_img, md5val] finally: - call('rmdir %s' % mount_dir, shell=True) + call('rm -rf %s' % mount_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -363,14 +293,6 @@ def fs_obj_ext(request, u_boot_config): min_file = mount_dir + '/' + MIN_FILE tmp_file = mount_dir + '/tmpfile' - try: - - # 128MiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') - except CalledProcessError as err: - pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) - return - try: check_call('mkdir -p %s' % mount_dir, shell=True) except CalledProcessError as err: @@ -378,15 +300,6 @@ def fs_obj_ext(request, u_boot_config): call('rm -f %s' % fs_img, shell=True) return - try: - # Mount the image so we can populate it. - mount_fs(fs_type, fs_img, mount_dir) - except CalledProcessError as err: - pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err)) - call('rmdir %s' % mount_dir, shell=True) - call('rm -f %s' % fs_img, shell=True) - return - try: # Create a test directory check_call('mkdir %s/dir1' % mount_dir, shell=True) @@ -427,15 +340,21 @@ def fs_obj_ext(request, u_boot_config): md5val.append(out.split()[0]) check_call('rm %s' % tmp_file, shell=True) + + try: + # 128MiB volume + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', mount_dir) + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + except CalledProcessError: pytest.skip('Setup failed for filesystem: ' + fs_type) - umount_fs(mount_dir) return else: - umount_fs(mount_dir) yield [fs_ubtype, fs_img, md5val] finally: - call('rmdir %s' % mount_dir, shell=True) + call('rm -rf %s' % mount_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -461,7 +380,7 @@ def fs_obj_mkdir(request, u_boot_config): try: # 128MiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', None) except: pytest.skip('Setup failed for filesystem: ' + fs_type) return @@ -492,14 +411,6 @@ def fs_obj_unlink(request, u_boot_config): mount_dir = u_boot_config.persistent_data_dir + '/mnt' - try: - - # 128MiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') - except CalledProcessError as err: - pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) - return - try: check_call('mkdir -p %s' % mount_dir, shell=True) except CalledProcessError as err: @@ -507,15 +418,6 @@ def fs_obj_unlink(request, u_boot_config): call('rm -f %s' % fs_img, shell=True) return - try: - # Mount the image so we can populate it. - mount_fs(fs_type, fs_img, mount_dir) - except CalledProcessError as err: - pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err)) - call('rmdir %s' % mount_dir, shell=True) - call('rm -f %s' % fs_img, shell=True) - return - try: # Test Case 1 & 3 check_call('mkdir %s/dir1' % mount_dir, shell=True) @@ -538,15 +440,20 @@ def fs_obj_unlink(request, u_boot_config): check_call('dd if=/dev/urandom of=%s/dir5/file1 bs=1K count=1' % mount_dir, shell=True) + try: + # 128MiB volume + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', mount_dir) + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + except CalledProcessError: pytest.skip('Setup failed for filesystem: ' + fs_type) - umount_fs(mount_dir) return else: - umount_fs(mount_dir) yield [fs_ubtype, fs_img] finally: - call('rmdir %s' % mount_dir, shell=True) + call('rm -rf %s' % mount_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -575,14 +482,6 @@ def fs_obj_symlink(request, u_boot_config): small_file = mount_dir + '/' + SMALL_FILE medium_file = mount_dir + '/' + MEDIUM_FILE - try: - - # 1GiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB') - except CalledProcessError as err: - pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) - return - try: check_call('mkdir -p %s' % mount_dir, shell=True) except CalledProcessError as err: @@ -590,15 +489,6 @@ def fs_obj_symlink(request, u_boot_config): call('rm -f %s' % fs_img, shell=True) return - try: - # Mount the image so we can populate it. - mount_fs(fs_type, fs_img, mount_dir) - except CalledProcessError as err: - pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err)) - call('rmdir %s' % mount_dir, shell=True) - call('rm -f %s' % fs_img, shell=True) - return - try: # Create a subdirectory. check_call('mkdir %s/SUBDIR' % mount_dir, shell=True) @@ -621,15 +511,20 @@ def fs_obj_symlink(request, u_boot_config): % medium_file, shell=True).decode() md5val.extend([out.split()[0]]) + try: + # 1GiB volume + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB', mount_dir) + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + except CalledProcessError: pytest.skip('Setup failed for filesystem: ' + fs_type) - umount_fs(mount_dir) return else: - umount_fs(mount_dir) yield [fs_ubtype, fs_img, md5val] finally: - call('rmdir %s' % mount_dir, shell=True) + call('rm -rf %s' % mount_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -665,7 +560,7 @@ def fs_obj_fat(request, u_boot_config): try: # the volume size depends on the filesystem - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, fs_size, f'{fs_size}', 1024) + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, fs_size, f'{fs_size}', None, 1024) except: pytest.skip('Setup failed for filesystem: ' + fs_type) return diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 7a0bde4da25..940373c4ab3 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -589,8 +589,8 @@ def test_ut_dm_init(u_boot_console): u_boot_utils.run_and_log( u_boot_console, f'sfdisk {fn}', stdin=b'type=83') - fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB') - fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB') + fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB', None) + fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB', None) mmc_dev = 6 fn = os.path.join(u_boot_console.config.source_dir, f'mmc{mmc_dev}.img') From c25e8ceea45038ce6a1cf6d00904059e493961ee Mon Sep 17 00:00:00 2001 From: Richard Weinberger Date: Thu, 21 Nov 2024 15:32:08 -0700 Subject: [PATCH 02/20] test_fs: Rename mount dir to scratch Since no mounting happens anymore, rename the "mnt" directory to "scratch" and the related variables. Signed-off-by: Richard Weinberger Reviewed-by: Mattijs Korpershoek Signed-off-by: Simon Glass --- test/py/tests/test_fs/conftest.py | 66 +++++++++++++++---------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index 59342a6e3dd..af2adaf1645 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -178,13 +178,13 @@ def fs_obj_basic(request, u_boot_config): fs_ubtype = fstype_to_ubname(fs_type) check_ubconfig(u_boot_config, fs_ubtype) - mount_dir = u_boot_config.persistent_data_dir + '/mnt' + scratch_dir = u_boot_config.persistent_data_dir + '/scratch' - small_file = mount_dir + '/' + SMALL_FILE - big_file = mount_dir + '/' + BIG_FILE + small_file = scratch_dir + '/' + SMALL_FILE + big_file = scratch_dir + '/' + BIG_FILE try: - check_call('mkdir -p %s' % mount_dir, shell=True) + check_call('mkdir -p %s' % scratch_dir, shell=True) except CalledProcessError as err: pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) call('rm -f %s' % fs_img, shell=True) @@ -192,7 +192,7 @@ def fs_obj_basic(request, u_boot_config): try: # Create a subdirectory. - check_call('mkdir %s/SUBDIR' % mount_dir, shell=True) + check_call('mkdir %s/SUBDIR' % scratch_dir, shell=True) # Create big file in this image. # Note that we work only on the start 1MB, couple MBs in the 2GB range @@ -253,7 +253,7 @@ def fs_obj_basic(request, u_boot_config): try: # 3GiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB', mount_dir) + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB', scratch_dir) except CalledProcessError as err: pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) return @@ -264,7 +264,7 @@ def fs_obj_basic(request, u_boot_config): else: yield [fs_ubtype, fs_img, md5val] finally: - call('rm -rf %s' % mount_dir, shell=True) + call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -288,13 +288,13 @@ def fs_obj_ext(request, u_boot_config): fs_ubtype = fstype_to_ubname(fs_type) check_ubconfig(u_boot_config, fs_ubtype) - mount_dir = u_boot_config.persistent_data_dir + '/mnt' + scratch_dir = u_boot_config.persistent_data_dir + '/scratch' - min_file = mount_dir + '/' + MIN_FILE - tmp_file = mount_dir + '/tmpfile' + min_file = scratch_dir + '/' + MIN_FILE + tmp_file = scratch_dir + '/tmpfile' try: - check_call('mkdir -p %s' % mount_dir, shell=True) + check_call('mkdir -p %s' % scratch_dir, shell=True) except CalledProcessError as err: pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) call('rm -f %s' % fs_img, shell=True) @@ -302,7 +302,7 @@ def fs_obj_ext(request, u_boot_config): try: # Create a test directory - check_call('mkdir %s/dir1' % mount_dir, shell=True) + check_call('mkdir %s/dir1' % scratch_dir, shell=True) # Create a small file and calculate md5 check_call('dd if=/dev/urandom of=%s bs=1K count=20' @@ -343,7 +343,7 @@ def fs_obj_ext(request, u_boot_config): try: # 128MiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', mount_dir) + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', scratch_dir) except CalledProcessError as err: pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) return @@ -354,7 +354,7 @@ def fs_obj_ext(request, u_boot_config): else: yield [fs_ubtype, fs_img, md5val] finally: - call('rm -rf %s' % mount_dir, shell=True) + call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -409,10 +409,10 @@ def fs_obj_unlink(request, u_boot_config): fs_ubtype = fstype_to_ubname(fs_type) check_ubconfig(u_boot_config, fs_ubtype) - mount_dir = u_boot_config.persistent_data_dir + '/mnt' + scratch_dir = u_boot_config.persistent_data_dir + '/scratch' try: - check_call('mkdir -p %s' % mount_dir, shell=True) + check_call('mkdir -p %s' % scratch_dir, shell=True) except CalledProcessError as err: pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) call('rm -f %s' % fs_img, shell=True) @@ -420,29 +420,29 @@ def fs_obj_unlink(request, u_boot_config): try: # Test Case 1 & 3 - check_call('mkdir %s/dir1' % mount_dir, shell=True) + check_call('mkdir %s/dir1' % scratch_dir, shell=True) check_call('dd if=/dev/urandom of=%s/dir1/file1 bs=1K count=1' - % mount_dir, shell=True) + % scratch_dir, shell=True) check_call('dd if=/dev/urandom of=%s/dir1/file2 bs=1K count=1' - % mount_dir, shell=True) + % scratch_dir, shell=True) # Test Case 2 - check_call('mkdir %s/dir2' % mount_dir, shell=True) + check_call('mkdir %s/dir2' % scratch_dir, shell=True) for i in range(0, 20): check_call('mkdir %s/dir2/0123456789abcdef%02x' - % (mount_dir, i), shell=True) + % (scratch_dir, i), shell=True) # Test Case 4 - check_call('mkdir %s/dir4' % mount_dir, shell=True) + check_call('mkdir %s/dir4' % scratch_dir, shell=True) # Test Case 5, 6 & 7 - check_call('mkdir %s/dir5' % mount_dir, shell=True) + check_call('mkdir %s/dir5' % scratch_dir, shell=True) check_call('dd if=/dev/urandom of=%s/dir5/file1 bs=1K count=1' - % mount_dir, shell=True) + % scratch_dir, shell=True) try: # 128MiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', mount_dir) + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', scratch_dir) except CalledProcessError as err: pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) return @@ -453,7 +453,7 @@ def fs_obj_unlink(request, u_boot_config): else: yield [fs_ubtype, fs_img] finally: - call('rm -rf %s' % mount_dir, shell=True) + call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -477,13 +477,13 @@ def fs_obj_symlink(request, u_boot_config): fs_ubtype = fstype_to_ubname(fs_type) check_ubconfig(u_boot_config, fs_ubtype) - mount_dir = u_boot_config.persistent_data_dir + '/mnt' + scratch_dir = u_boot_config.persistent_data_dir + '/scratch' - small_file = mount_dir + '/' + SMALL_FILE - medium_file = mount_dir + '/' + MEDIUM_FILE + small_file = scratch_dir + '/' + SMALL_FILE + medium_file = scratch_dir + '/' + MEDIUM_FILE try: - check_call('mkdir -p %s' % mount_dir, shell=True) + check_call('mkdir -p %s' % scratch_dir, shell=True) except CalledProcessError as err: pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) call('rm -f %s' % fs_img, shell=True) @@ -491,7 +491,7 @@ def fs_obj_symlink(request, u_boot_config): try: # Create a subdirectory. - check_call('mkdir %s/SUBDIR' % mount_dir, shell=True) + check_call('mkdir %s/SUBDIR' % scratch_dir, shell=True) # Create a small file in this image. check_call('dd if=/dev/urandom of=%s bs=1M count=1' @@ -513,7 +513,7 @@ def fs_obj_symlink(request, u_boot_config): try: # 1GiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB', mount_dir) + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB', scratch_dir) except CalledProcessError as err: pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) return @@ -524,7 +524,7 @@ def fs_obj_symlink(request, u_boot_config): else: yield [fs_ubtype, fs_img, md5val] finally: - call('rm -rf %s' % mount_dir, shell=True) + call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # From fde4e53aaa7032538b7f583829dcc436ce2d55a4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 21 Nov 2024 15:32:09 -0700 Subject: [PATCH 03/20] test_ut: Add an image size to setup_image() Add a parameter to indicate the size of the image to build. Signed-off-by: Simon Glass Signed-off-by: Richard Weinberger --- test/py/tests/test_ut.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 940373c4ab3..647e424d6fb 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -28,13 +28,15 @@ def mkdir_cond(dirname): if not os.path.exists(dirname): os.mkdir(dirname) -def setup_image(cons, devnum, part_type, second_part=False, basename='mmc'): - """Create a 20MB disk image with a single partition +def setup_image(cons, devnum, part_type, img_size=20, second_part=False, + basename='mmc'): + """Create a disk image with a single partition Args: cons (ConsoleBase): Console to use devnum (int): Device number to use, e.g. 1 part_type (int): Partition type, e.g. 0xc for FAT32 + img_size (int): Image size in MiB second_part (bool): True to contain a small second partition basename (str): Base name to use in the filename, e.g. 'mmc' @@ -47,11 +49,11 @@ def setup_image(cons, devnum, part_type, second_part=False, basename='mmc'): mnt = os.path.join(cons.config.persistent_data_dir, 'mnt') mkdir_cond(mnt) - spec = f'type={part_type:x}, size=18M, bootable' + spec = f'type={part_type:x}, size={img_size - 2}M, start=1M, bootable' if second_part: spec += '\ntype=c' - u_boot_utils.run_and_log(cons, f'qemu-img create {fname} 20M') + u_boot_utils.run_and_log(cons, f'qemu-img create {fname} {img_size}M') u_boot_utils.run_and_log(cons, f'sudo sfdisk {fname}', stdin=spec.encode('utf-8')) return fname, mnt From 360315b3603c557549704ed6bc3b39eba12e92b0 Mon Sep 17 00:00:00 2001 From: Richard Weinberger Date: Thu, 21 Nov 2024 15:32:10 -0700 Subject: [PATCH 04/20] test_ut: Allow running unprivileged Like for test_fs, no need to mess with loop mounts. Signed-off-by: Richard Weinberger Tweaks to reduce diff (keep mnt variable): Signed-off-by: Simon Glass --- test/py/tests/test_ut.py | 86 ++++++++++++---------------------------- 1 file changed, 26 insertions(+), 60 deletions(-) diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 647e424d6fb..90c1419ec51 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -8,7 +8,6 @@ test one at a time, as well setting up some files needed by the tests. # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. """ import collections -import getpass import gzip import os import os.path @@ -43,44 +42,21 @@ def setup_image(cons, devnum, part_type, img_size=20, second_part=False, Returns: tuple: str: Filename of MMC image - str: Directory name of 'mnt' directory + str: Directory name of scratch directory """ fname = os.path.join(cons.config.source_dir, f'{basename}{devnum}.img') - mnt = os.path.join(cons.config.persistent_data_dir, 'mnt') + mnt = os.path.join(cons.config.persistent_data_dir, 'scratch') mkdir_cond(mnt) spec = f'type={part_type:x}, size={img_size - 2}M, start=1M, bootable' if second_part: spec += '\ntype=c' - u_boot_utils.run_and_log(cons, f'qemu-img create {fname} {img_size}M') - u_boot_utils.run_and_log(cons, f'sudo sfdisk {fname}', + u_boot_utils.run_and_log(cons, f'qemu-img create {fname} 20M') + u_boot_utils.run_and_log(cons, f'sfdisk {fname}', stdin=spec.encode('utf-8')) return fname, mnt -def mount_image(cons, fname, mnt, fstype): - """Create a filesystem and mount it on partition 1 - - Args: - cons (ConsoleBase): Console to use - fname (str): Filename of MMC image - mnt (str): Directory name of 'mnt' directory - fstype (str): Filesystem type ('vfat' or 'ext4') - - Returns: - str: Name of loop device used - """ - out = u_boot_utils.run_and_log(cons, f'sudo losetup --show -f -P {fname}') - loop = out.strip() - part = f'{loop}p1' - u_boot_utils.run_and_log(cons, f'sudo mkfs.{fstype} {part}') - opts = '' - if fstype == 'vfat': - opts += f' -o uid={os.getuid()},gid={os.getgid()}' - u_boot_utils.run_and_log(cons, f'sudo mount -o loop {part} {mnt}{opts}') - u_boot_utils.run_and_log(cons, f'sudo chown {getpass.getuser()} {mnt}') - return loop - def copy_prepared_image(cons, devnum, fname, basename='mmc'): """Use a prepared image since we cannot create one @@ -102,13 +78,8 @@ def setup_bootmenu_image(cons): mmc_dev = 4 fname, mnt = setup_image(cons, mmc_dev, 0x83) - loop = None - mounted = False complete = False try: - loop = mount_image(cons, fname, mnt, 'ext4') - mounted = True - script = '''# DO NOT EDIT THIS FILE # # Please edit /boot/armbianEnv.txt to set supported parameters @@ -212,15 +183,16 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} cons, f'echo here {kernel} {symlink}') os.symlink(kernel, symlink) + fsfile = 'ext18M.img' + u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') + u_boot_utils.run_and_log(cons, f'mkfs.ext4 {fsfile} -d {mnt}') + u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') complete = True - except ValueError as exc: print(f'Falled to create image, failing back to prepared copy: {exc}') finally: - if mounted: - u_boot_utils.run_and_log(cons, f'sudo umount --lazy {mnt}') - if loop: - u_boot_utils.run_and_log(cons, f'sudo losetup -d {loop}') + u_boot_utils.run_and_log(cons, f'rm -rf {mnt}') + u_boot_utils.run_and_log(cons, f'rm -f {fsfile}') if not complete: copy_prepared_image(cons, mmc_dev, fname) @@ -230,13 +202,8 @@ def setup_bootflow_image(cons): mmc_dev = 1 fname, mnt = setup_image(cons, mmc_dev, 0xc, second_part=True) - loop = None - mounted = False complete = False try: - loop = mount_image(cons, fname, mnt, 'vfat') - mounted = True - vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl' initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img' dtbdir = 'dtb-5.3.7-301.fc31.armv7hl' @@ -274,19 +241,21 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) dtb_file = os.path.join(mnt, f'{dtbdir}/sandbox.dtb') u_boot_utils.run_and_log( cons, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};') + + fsfile = 'vfat18M.img' + u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') + u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}') + u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/']) + u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') complete = True except ValueError as exc: print(f'Falled to create image, failing back to prepared copy: {exc}') finally: - if mounted: - u_boot_utils.run_and_log(cons, f'sudo umount --lazy {mnt}') - if loop: - u_boot_utils.run_and_log(cons, f'sudo losetup -d {loop}') - + u_boot_utils.run_and_log(cons, f'rm -rf {mnt}') + u_boot_utils.run_and_log(cons, f'rm -f {fsfile}') if not complete: copy_prepared_image(cons, mmc_dev, fname) - def setup_cros_image(cons): """Create a 20MB disk image with ChromiumOS partitions""" Partition = collections.namedtuple('part', 'start,size,name') @@ -336,8 +305,6 @@ def setup_cros_image(cons): mmc_dev = 5 fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img') u_boot_utils.run_and_log(cons, f'qemu-img create {fname} 20M') - #mnt = os.path.join(cons.config.persistent_data_dir, 'mnt') - #mkdir_cond(mnt) u_boot_utils.run_and_log(cons, f'cgpt create {fname}') uuid_state = 'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7' @@ -608,31 +575,30 @@ def setup_efi_image(cons): fname, mnt = setup_image(cons, devnum, 0xc, second_part=True, basename=basename) - loop = None - mounted = False complete = False try: - loop = mount_image(cons, fname, mnt, 'ext4') - mounted = True efi_dir = os.path.join(mnt, 'EFI') mkdir_cond(efi_dir) bootdir = os.path.join(efi_dir, 'BOOT') mkdir_cond(bootdir) efi_src = os.path.join(cons.config.build_dir, - f'lib/efi_loader/testapp.efi') + 'lib/efi_loader/testapp.efi') efi_dst = os.path.join(bootdir, 'BOOTSBOX.EFI') with open(efi_src, 'rb') as inf: with open(efi_dst, 'wb') as outf: outf.write(inf.read()) + fsfile = 'vfat18M.img' + u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') + u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}') + u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/']) + u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') complete = True except ValueError as exc: print(f'Falled to create image, failing back to prepared copy: {exc}') finally: - if mounted: - u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt) - if loop: - u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop) + u_boot_utils.run_and_log(cons, f'rm -rf {mnt}') + u_boot_utils.run_and_log(cons, f'rm -f {fsfile}') if not complete: copy_prepared_image(cons, devnum, fname, basename) From 22eef59dd3642c0ea47bd4974e11ba6ef1a88d43 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 21 Nov 2024 15:32:11 -0700 Subject: [PATCH 05/20] test_ut: Drop exeception handling We don't need the fallback anymore. As a first step to removing it, drop the try...except clauses and unindent the code. This produces a large diff but there are no other code changes. Signed-off-by: Simon Glass --- test/py/tests/test_ut.py | 169 ++++++++++++++++++--------------------- 1 file changed, 78 insertions(+), 91 deletions(-) diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 90c1419ec51..0b3ab6242d8 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -79,8 +79,7 @@ def setup_bootmenu_image(cons): fname, mnt = setup_image(cons, mmc_dev, 0x83) complete = False - try: - script = '''# DO NOT EDIT THIS FILE + script = '''# DO NOT EDIT THIS FILE # # Please edit /boot/armbianEnv.txt to set supported parameters # @@ -154,45 +153,42 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} # Recompile with: # mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr ''' - bootdir = os.path.join(mnt, 'boot') - mkdir_cond(bootdir) - cmd_fname = os.path.join(bootdir, 'boot.cmd') - scr_fname = os.path.join(bootdir, 'boot.scr') - with open(cmd_fname, 'w', encoding='ascii') as outf: - print(script, file=outf) + bootdir = os.path.join(mnt, 'boot') + mkdir_cond(bootdir) + cmd_fname = os.path.join(bootdir, 'boot.cmd') + scr_fname = os.path.join(bootdir, 'boot.scr') + with open(cmd_fname, 'w', encoding='ascii') as outf: + print(script, file=outf) - infname = os.path.join(cons.config.source_dir, - 'test/py/tests/bootstd/armbian.bmp.xz') - bmp_file = os.path.join(bootdir, 'boot.bmp') - u_boot_utils.run_and_log( - cons, - ['sh', '-c', f'xz -dc {infname} >{bmp_file}']) + infname = os.path.join(cons.config.source_dir, + 'test/py/tests/bootstd/armbian.bmp.xz') + bmp_file = os.path.join(bootdir, 'boot.bmp') + u_boot_utils.run_and_log( + cons, + ['sh', '-c', f'xz -dc {infname} >{bmp_file}']) - u_boot_utils.run_and_log( - cons, f'mkimage -C none -A arm -T script -d {cmd_fname} {scr_fname}') + u_boot_utils.run_and_log( + cons, f'mkimage -C none -A arm -T script -d {cmd_fname} {scr_fname}') - kernel = 'vmlinuz-5.15.63-rockchip64' - target = os.path.join(bootdir, kernel) - with open(target, 'wb') as outf: - print('kernel', outf) + kernel = 'vmlinuz-5.15.63-rockchip64' + target = os.path.join(bootdir, kernel) + with open(target, 'wb') as outf: + print('kernel', outf) - symlink = os.path.join(bootdir, 'Image') - if os.path.exists(symlink): - os.remove(symlink) - u_boot_utils.run_and_log( - cons, f'echo here {kernel} {symlink}') - os.symlink(kernel, symlink) + symlink = os.path.join(bootdir, 'Image') + if os.path.exists(symlink): + os.remove(symlink) + u_boot_utils.run_and_log( + cons, f'echo here {kernel} {symlink}') + os.symlink(kernel, symlink) - fsfile = 'ext18M.img' - u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') - u_boot_utils.run_and_log(cons, f'mkfs.ext4 {fsfile} -d {mnt}') - u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') - complete = True - except ValueError as exc: - print(f'Falled to create image, failing back to prepared copy: {exc}') - finally: - u_boot_utils.run_and_log(cons, f'rm -rf {mnt}') - u_boot_utils.run_and_log(cons, f'rm -f {fsfile}') + fsfile = 'ext18M.img' + u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') + u_boot_utils.run_and_log(cons, f'mkfs.ext4 {fsfile} -d {mnt}') + u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') + complete = True + u_boot_utils.run_and_log(cons, f'rm -rf {mnt}') + u_boot_utils.run_and_log(cons, f'rm -f {fsfile}') if not complete: copy_prepared_image(cons, mmc_dev, fname) @@ -203,11 +199,10 @@ def setup_bootflow_image(cons): fname, mnt = setup_image(cons, mmc_dev, 0xc, second_part=True) complete = False - try: - vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl' - initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img' - dtbdir = 'dtb-5.3.7-301.fc31.armv7hl' - script = '''# extlinux.conf generated by appliance-creator + vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl' + initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img' + dtbdir = 'dtb-5.3.7-301.fc31.armv7hl' + script = '''# extlinux.conf generated by appliance-creator ui menu.c32 menu autoboot Welcome to Fedora-Workstation-armhfp-31-1.9. Automatic boot in # second{,s}. Press a key for options. menu title Fedora-Workstation-armhfp-31-1.9 Boot Options. @@ -220,39 +215,36 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) append ro root=UUID=9732b35b-4cd5-458b-9b91-80f7047e0b8a rhgb quiet LANG=en_US.UTF-8 cma=192MB cma=256MB fdtdir /%s/ initrd /%s''' % (vmlinux, dtbdir, initrd) - ext = os.path.join(mnt, 'extlinux') - mkdir_cond(ext) + ext = os.path.join(mnt, 'extlinux') + mkdir_cond(ext) - conf = os.path.join(ext, 'extlinux.conf') - with open(conf, 'w', encoding='ascii') as fd: - print(script, file=fd) + conf = os.path.join(ext, 'extlinux.conf') + with open(conf, 'w', encoding='ascii') as fd: + print(script, file=fd) - inf = os.path.join(cons.config.persistent_data_dir, 'inf') - with open(inf, 'wb') as fd: - fd.write(gzip.compress(b'vmlinux')) - u_boot_utils.run_and_log( - cons, f'mkimage -f auto -d {inf} {os.path.join(mnt, vmlinux)}') + inf = os.path.join(cons.config.persistent_data_dir, 'inf') + with open(inf, 'wb') as fd: + fd.write(gzip.compress(b'vmlinux')) + u_boot_utils.run_and_log( + cons, f'mkimage -f auto -d {inf} {os.path.join(mnt, vmlinux)}') - with open(os.path.join(mnt, initrd), 'w', encoding='ascii') as fd: - print('initrd', file=fd) + with open(os.path.join(mnt, initrd), 'w', encoding='ascii') as fd: + print('initrd', file=fd) - mkdir_cond(os.path.join(mnt, dtbdir)) + mkdir_cond(os.path.join(mnt, dtbdir)) - dtb_file = os.path.join(mnt, f'{dtbdir}/sandbox.dtb') - u_boot_utils.run_and_log( - cons, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};') + dtb_file = os.path.join(mnt, f'{dtbdir}/sandbox.dtb') + u_boot_utils.run_and_log( + cons, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};') - fsfile = 'vfat18M.img' - u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') - u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}') - u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/']) - u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') - complete = True - except ValueError as exc: - print(f'Falled to create image, failing back to prepared copy: {exc}') - finally: - u_boot_utils.run_and_log(cons, f'rm -rf {mnt}') - u_boot_utils.run_and_log(cons, f'rm -f {fsfile}') + fsfile = 'vfat18M.img' + u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') + u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}') + u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/']) + u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') + complete = True + u_boot_utils.run_and_log(cons, f'rm -rf {mnt}') + u_boot_utils.run_and_log(cons, f'rm -f {fsfile}') if not complete: copy_prepared_image(cons, mmc_dev, fname) @@ -576,29 +568,24 @@ def setup_efi_image(cons): basename=basename) complete = False - try: - efi_dir = os.path.join(mnt, 'EFI') - mkdir_cond(efi_dir) - bootdir = os.path.join(efi_dir, 'BOOT') - mkdir_cond(bootdir) - efi_src = os.path.join(cons.config.build_dir, - 'lib/efi_loader/testapp.efi') - efi_dst = os.path.join(bootdir, 'BOOTSBOX.EFI') - with open(efi_src, 'rb') as inf: - with open(efi_dst, 'wb') as outf: - outf.write(inf.read()) - fsfile = 'vfat18M.img' - u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') - u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}') - u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/']) - u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') - complete = True - except ValueError as exc: - print(f'Falled to create image, failing back to prepared copy: {exc}') - - finally: - u_boot_utils.run_and_log(cons, f'rm -rf {mnt}') - u_boot_utils.run_and_log(cons, f'rm -f {fsfile}') + efi_dir = os.path.join(mnt, 'EFI') + mkdir_cond(efi_dir) + bootdir = os.path.join(efi_dir, 'BOOT') + mkdir_cond(bootdir) + efi_src = os.path.join(cons.config.build_dir, + 'lib/efi_loader/testapp.efi') + efi_dst = os.path.join(bootdir, 'BOOTSBOX.EFI') + with open(efi_src, 'rb') as inf: + with open(efi_dst, 'wb') as outf: + outf.write(inf.read()) + fsfile = 'vfat18M.img' + u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') + u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}') + u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/']) + u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') + complete = True + u_boot_utils.run_and_log(cons, f'rm -rf {mnt}') + u_boot_utils.run_and_log(cons, f'rm -f {fsfile}') if not complete: copy_prepared_image(cons, devnum, fname, basename) From 2fad73a166a709de69a57a0ec655918f053af169 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 21 Nov 2024 15:32:12 -0700 Subject: [PATCH 06/20] test_ut: Use the built mkimage The mkimage tool is not present in the docker image. Use the one in the build directory. Signed-off-by: Simon Glass --- test/py/tests/test_ut.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 0b3ab6242d8..c97ab6b2a46 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -167,8 +167,9 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} cons, ['sh', '-c', f'xz -dc {infname} >{bmp_file}']) + mkimage = cons.config.build_dir + '/tools/mkimage' u_boot_utils.run_and_log( - cons, f'mkimage -C none -A arm -T script -d {cmd_fname} {scr_fname}') + cons, f'{mkimage} -C none -A arm -T script -d {cmd_fname} {scr_fname}') kernel = 'vmlinuz-5.15.63-rockchip64' target = os.path.join(bootdir, kernel) @@ -225,8 +226,9 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) inf = os.path.join(cons.config.persistent_data_dir, 'inf') with open(inf, 'wb') as fd: fd.write(gzip.compress(b'vmlinux')) + mkimage = cons.config.build_dir + '/tools/mkimage' u_boot_utils.run_and_log( - cons, f'mkimage -f auto -d {inf} {os.path.join(mnt, vmlinux)}') + cons, f'{mkimage} -f auto -d {inf} {os.path.join(mnt, vmlinux)}') with open(os.path.join(mnt, initrd), 'w', encoding='ascii') as fd: print('initrd', file=fd) From 01c0695d9da8c13bca80e12cda3b9518d2d91b20 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 21 Nov 2024 15:32:13 -0700 Subject: [PATCH 07/20] test_ut: Drop support for fallback files We don't need the fallback anymore. Remove the code which uses these files. Signed-off-by: Simon Glass Signed-off-by: Richard Weinberger --- test/py/tests/test_ut.py | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index c97ab6b2a46..10ec7e582e0 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -57,19 +57,6 @@ def setup_image(cons, devnum, part_type, img_size=20, second_part=False, stdin=spec.encode('utf-8')) return fname, mnt -def copy_prepared_image(cons, devnum, fname, basename='mmc'): - """Use a prepared image since we cannot create one - - Args: - cons (ConsoleBase): Console touse - devnum (int): device number - fname (str): Filename of MMC image - basename (str): Base name to use in the filename, e.g. 'mmc' - """ - infname = os.path.join(cons.config.source_dir, - f'test/py/tests/bootstd/{basename}{devnum}.img.xz') - u_boot_utils.run_and_log(cons, ['sh', '-c', f'xz -dc {infname} >{fname}']) - def setup_bootmenu_image(cons): """Create a 20MB disk image with a single ext4 partition @@ -78,7 +65,6 @@ def setup_bootmenu_image(cons): mmc_dev = 4 fname, mnt = setup_image(cons, mmc_dev, 0x83) - complete = False script = '''# DO NOT EDIT THIS FILE # # Please edit /boot/armbianEnv.txt to set supported parameters @@ -187,19 +173,14 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') u_boot_utils.run_and_log(cons, f'mkfs.ext4 {fsfile} -d {mnt}') u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') - complete = True u_boot_utils.run_and_log(cons, f'rm -rf {mnt}') u_boot_utils.run_and_log(cons, f'rm -f {fsfile}') - if not complete: - copy_prepared_image(cons, mmc_dev, fname) - def setup_bootflow_image(cons): """Create a 20MB disk image with a single FAT partition""" mmc_dev = 1 fname, mnt = setup_image(cons, mmc_dev, 0xc, second_part=True) - complete = False vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl' initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img' dtbdir = 'dtb-5.3.7-301.fc31.armv7hl' @@ -244,11 +225,8 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}') u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/']) u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') - complete = True u_boot_utils.run_and_log(cons, f'rm -rf {mnt}') u_boot_utils.run_and_log(cons, f'rm -f {fsfile}') - if not complete: - copy_prepared_image(cons, mmc_dev, fname) def setup_cros_image(cons): """Create a 20MB disk image with ChromiumOS partitions""" @@ -569,7 +547,6 @@ def setup_efi_image(cons): fname, mnt = setup_image(cons, devnum, 0xc, second_part=True, basename=basename) - complete = False efi_dir = os.path.join(mnt, 'EFI') mkdir_cond(efi_dir) bootdir = os.path.join(efi_dir, 'BOOT') @@ -585,14 +562,9 @@ def setup_efi_image(cons): u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}') u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/']) u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') - complete = True u_boot_utils.run_and_log(cons, f'rm -rf {mnt}') u_boot_utils.run_and_log(cons, f'rm -f {fsfile}') - if not complete: - copy_prepared_image(cons, devnum, fname, basename) - - @pytest.mark.buildconfigspec('cmd_bootflow') @pytest.mark.buildconfigspec('sandbox') def test_ut_dm_init_bootstd(u_boot_console): From bda30f83f9a218bbcf6f58a5ad15eb00a5bd3c4b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 21 Nov 2024 15:32:14 -0700 Subject: [PATCH 08/20] bootstd: Remove prepared images These are no-longer used. Drop them. Signed-off-by: Simon Glass --- test/py/tests/bootstd/flash1.img.xz | Bin 4924 -> 0 bytes test/py/tests/bootstd/mmc1.img.xz | Bin 4480 -> 0 bytes test/py/tests/bootstd/mmc4.img.xz | Bin 7072 -> 0 bytes 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/py/tests/bootstd/flash1.img.xz delete mode 100644 test/py/tests/bootstd/mmc1.img.xz delete mode 100644 test/py/tests/bootstd/mmc4.img.xz diff --git a/test/py/tests/bootstd/flash1.img.xz b/test/py/tests/bootstd/flash1.img.xz deleted file mode 100644 index 29b78c62a9bf264fa8b795b82b432bf3ab4e2765..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4924 zcmeI0X*d*W8^_0*H8g}6dyF*-i8PUAWUM3mp5^3V?6Qq*EN4(;8yri7vacz7wlLY5 zk|ks}H1-jicl+|b*Hzc4_dVzR)aU2Ap69v$*M0y0zw17|8fa<`08lRD>NLm!{AA|= z0D#Y>r2-O3kn)Qa0Dw3>fp$#gTZJ7`&p3FrG%i|A3T@230$3p2{8kcKY}m@*6z=4eUeY7SMOpXLyfos&tjkY1B9 ziyV5|&-HS$S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FQm7)MWF#WO%&ENHC4Vg zDD_s3$rrPd`z7}Xlgv7Up}_^}VuNG`Vupt~ohKAp_(p#TEuJJLiV4kE-dSUW>D~v6 zrQs+e%$L;YU!4H_G1$njmejn?F4EGJV{$NLlwg$NDC%T893Ps%?#+S_X`IU$WE4m? zKiR1XK6}w@jvT0knB2FdxYo(87ir8XF!f&!I}O4Yl^XR5-@ZTL zevNY|nav(Ef^>!HhbR+2f+mq=0*EE6N_L z&k{BY*n+-WdvW;U>R+h{la>BvG5x?|e@~cRl@lF^=2|p)cvRo;SoR7U;Qh)7 zI_gM~1_pmqu@gIPtl!~VyKRw(IWQY<`5i0H&Pdr+j5Cj>AKir?Osn0V{H2 zqvsZ@7kE|$HM(4#ZaAlV>GkW;h^mlr8EC5MbZf;(xqDPzFQURFi@V|eR-Qg{O%f!K z;CEKmE%DW+)dTaG?dFD*rI3>>fMbSGLZT8}EwC5HMVLd~H|-|N5|wh2Na?~jNmU7M zF)p7pUpoYN^6rgX{UKPf!g|n^GR^! zU|hYNJsqW_dah>v_T^ea_V{84byUneev!xZs zY#g11p`r}hkMN2SIzt9^Pk1_o$gA5jp9A}Cw#Cs6(mWKhuC|D7b<*tj=~ppYqxri* zid@a3EEH01zHr<7Ypce>uma{I6pmSCf3C$q(!Pe0KQ+rYlz|6HPY{Y!r)y?-l~h=b zYPb;t!a98=gw_K8!Vdvs_6EOX?Rx%sbAAE8bg#5x+1=*+BCPM(l~va5_CR?y5iRbX zQICwhx*dSrV{dy)+Q7O(D?ZaH-@G*zAI75CNT>f>2rh?PdT0rfh z$(|)GKKPRI1bdgYn@M*eS46 zTk+qq`seoIrxN|omHy9_#Dlp2KtNZbb$T|y)PGD+3sL|DuzZ2z@pw+QlC=JsPTT?O LKYtbgI|lnVW!bv$ diff --git a/test/py/tests/bootstd/mmc4.img.xz b/test/py/tests/bootstd/mmc4.img.xz deleted file mode 100644 index f4db011969fa8bea352ee2b8318dfdd72ccf72d8..0000000000000000000000000000000000000000 GIT binary pat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z-${w&L|yOpE09P>2H@GLiBNWRDe{)F{-msXR9YG92($m17dD>FLQhvC z+zXGJFB+Tjy{g>u=euIynw~9Gm*-taa2A9WBv|q3q*(CIH0JVizMP3}TOD+AX_1~ zLWxcjHFI;Q?GiZ*dayo#?vocSN}AE3Ji*ayu6NCGG<9#P%9ktL<42F8BujipOgl^2MF>fns-SkpMtol{6 z@7zK09fX|L;Y+bRwWIFoql2<8au^S$_pF-yq+_o_m9xJ*44f~E;AnOG1xl=5lBVrq zPu2P3wUiufo*2FsacSRDUHunn_xMmUb3A;Dq~CSw)HHACW-VA+S5~?7iXdME(dwl2)}jfsS!i-d*UT^eRkO-rt~;3VJr77NYNm`2^L3bhb-_&PVHH%wx(|R zO{|7#bK=8S_xf4WHF>*tf+N7Z><8wyh~8AGF3*F@H2^aaFJuiMPm5SCR2qgWSO5|x zAk|zvsUED4f8VG5W7EFh9lQVMK_d{iUI1}R3l#sY-}IAZi{LUe!hV)c)?p8Pt@md* z-v1*=Vn#Q{|7H;deg`=rb(`3Fy276vh5ddx3j@Crga1XfzmsYqghl{7Kzq!n pcF Date: Wed, 27 Nov 2024 11:17:19 -0600 Subject: [PATCH 09/20] sandbox: efi_loader: Correct use of addresses as pointers The cache-flush function is incorrect which causes a crash in the remoteproc tests with arm64. Fix both problems by using map_sysmem() to convert an address to a pointer and map_to_sysmem() to convert a pointer to an address. Also update the image-loader's cache-flushing logic. Signed-off-by: Simon Glass Fixes: 3286d223fd7 ("sandbox: implement invalidate_icache_all()") Acked-by: Heinrich Schuchardt Changes in v6: - Re-introduce Changes in v2: - Drop message about EFI_LOADER arch/sandbox/cpu/cache.c | 8 +++++++- drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++------- lib/efi_loader/efi_image_loader.c | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) Reviewed-by: Heinrich Schuchardt --- arch/sandbox/cpu/cache.c | 8 +++++++- drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++------- lib/efi_loader/efi_image_loader.c | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/arch/sandbox/cpu/cache.c b/arch/sandbox/cpu/cache.c index c8a5e64214b..96b3da47e8e 100644 --- a/arch/sandbox/cpu/cache.c +++ b/arch/sandbox/cpu/cache.c @@ -4,12 +4,18 @@ */ #include +#include #include void flush_cache(unsigned long addr, unsigned long size) { + void *ptr; + + ptr = map_sysmem(addr, size); + /* Clang uses (char *) parameters, GCC (void *) */ - __builtin___clear_cache((void *)addr, (void *)(addr + size)); + __builtin___clear_cache(map_sysmem(addr, size), ptr + size); + unmap_sysmem(ptr); } void invalidate_icache_all(void) diff --git a/drivers/remoteproc/rproc-elf-loader.c b/drivers/remoteproc/rproc-elf-loader.c index ab1836b3f07..0b3941b7798 100644 --- a/drivers/remoteproc/rproc-elf-loader.c +++ b/drivers/remoteproc/rproc-elf-loader.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,7 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size) for (i = 0; i < ehdr->e_phnum; i++, phdr++) { void *dst = (void *)(uintptr_t)phdr->p_paddr; void *src = (void *)addr + phdr->p_offset; + ulong dst_addr; if (phdr->p_type != PT_LOAD) continue; @@ -195,10 +197,11 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size) if (phdr->p_filesz != phdr->p_memsz) memset(dst + phdr->p_filesz, 0x00, phdr->p_memsz - phdr->p_filesz); - flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN), - roundup((unsigned long)dst + phdr->p_filesz, + dst_addr = map_to_sysmem(dst); + flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN), + roundup(dst_addr + phdr->p_filesz, ARCH_DMA_MINALIGN) - - rounddown((unsigned long)dst, ARCH_DMA_MINALIGN)); + rounddown(dst_addr, ARCH_DMA_MINALIGN)); } return 0; @@ -377,6 +380,7 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr, const struct dm_rproc_ops *ops; Elf32_Shdr *shdr; void *src, *dst; + ulong dst_addr; shdr = rproc_elf32_find_rsc_table(dev, fw_addr, fw_size); if (!shdr) @@ -398,10 +402,10 @@ int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr, (ulong)dst, *rsc_size); memcpy(dst, src, *rsc_size); - flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN), - roundup((unsigned long)dst + *rsc_size, - ARCH_DMA_MINALIGN) - - rounddown((unsigned long)dst, ARCH_DMA_MINALIGN)); + dst_addr = map_to_sysmem(dst); + flush_cache(rounddown(dst_addr, ARCH_DMA_MINALIGN), + roundup(dst_addr + *rsc_size, ARCH_DMA_MINALIGN) - + rounddown(dst_addr, ARCH_DMA_MINALIGN)); return 0; } diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index 0ddf69a0918..bb58cf1badb 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -977,7 +978,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, } /* Flush cache */ - flush_cache((ulong)efi_reloc, + flush_cache(map_to_sysmem(efi_reloc), ALIGN(virt_size, EFI_CACHELINE_SIZE)); /* From 5c8c0738877e15cfe263c721989969c43ff9e5bf Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Nov 2024 11:17:20 -0600 Subject: [PATCH 10/20] test: Adjust print_ut test to use unsigned char Since char is unsigned on arm64, this test currently fails. It seems better to use unsigned anyway, since 0xff is written into the string at the start. Update the terminator-assert to use a character instead of a byte. Signed-off-by: Simon Glass Reviewed-by: Heinrich Schuchardt Changes in v6: - Re-introduce Changes in v2: - Use '\0' instead of 0 test/print_ut.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- test/common/print.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/common/print.c b/test/common/print.c index 464e425edee..e3711b10809 100644 --- a/test/common/print.c +++ b/test/common/print.c @@ -241,7 +241,7 @@ COMMON_TEST(print_display_buffer, UTF_CONSOLE); static int print_hexdump_line(struct unit_test_state *uts) { - char *linebuf; + u8 *linebuf; u8 *buf; int i; @@ -254,10 +254,10 @@ static int print_hexdump_line(struct unit_test_state *uts) linebuf = map_sysmem(0x400, BUF_SIZE); memset(linebuf, '\xff', BUF_SIZE); ut_asserteq(-ENOSPC, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 75)); - ut_asserteq(-1, linebuf[0]); + ut_asserteq(0xff, linebuf[0]); ut_asserteq(0x10, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 76)); - ut_asserteq(0, linebuf[75]); - ut_asserteq(-1, linebuf[76]); + ut_asserteq('\0', linebuf[75]); + ut_asserteq(0xff, linebuf[76]); unmap_sysmem(buf); From 042b067a5ec19c5a49cbc892f6d746a2e21f66f5 Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 27 Nov 2024 11:17:21 -0600 Subject: [PATCH 11/20] docker: Add kernel.org x86_64 toolchain Add in the x86_64 toolchain, but do not enforce using it for sandbox. Reviewed-by: Simon Glass Signed-off-by: Tom Rini --- tools/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 967ac89fbde..0f6890b7821 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -27,6 +27,7 @@ RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_ RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-riscv64-linux.tar.xz | tar -C /opt -xJ RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-riscv32-linux.tar.xz | tar -C /opt -xJ RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-sh2-linux.tar.xz | tar -C /opt -xJ +RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-x86_64-linux.tar.xz | tar -C /opt -xJ # Manually install other toolchains RUN wget -O - https://github.com/foss-xtensa/toolchain/releases/download/2020.07/x86_64-2020.07-xtensa-dc233c-elf.tar.gz | tar -C /opt -xz @@ -280,7 +281,6 @@ RUN /bin/echo -e "[toolchain]\nroot = /usr" > ~/.buildman RUN /bin/echo -e "kernelorg = /opt/gcc-13.2.0-nolibc/*" >> ~/.buildman RUN /bin/echo -e "\n[toolchain-prefix]\nxtensa = /opt/2020.07/xtensa-dc233c-elf/bin/xtensa-dc233c-elf-" >> ~/.buildman; RUN /bin/echo -e "\n[toolchain-alias]\nsh = sh2" >> ~/.buildman -RUN /bin/echo -e "\nsandbox = x86_64" >> ~/.buildman RUN /bin/echo -e "\nx86 = i386" >> ~/.buildman; # Add mkbootimg tool From 2fc92695fb65ab9ce8a4e35371c1ef9cfdbf642c Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 27 Nov 2024 11:17:22 -0600 Subject: [PATCH 12/20] docker: Use "make -j$(nproc)" when invoking make We had a few places that were not using "make -j$(nproc)" but instead just plain "make" and so slowing down the overall build. Reviewed-by: Simon Glass Signed-off-by: Tom Rini --- tools/docker/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 0f6890b7821..449745712de 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -142,7 +142,7 @@ RUN git clone git://git.savannah.gnu.org/grub.git /tmp/grub && \ TARGET_STRIP=/opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-strip \ TARGET_NM=/opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-nm \ TARGET_RANLIB=/opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-ranlib && \ - make && \ + make -j$(nproc) && \ ./grub-mkimage -O arm64-efi -o /opt/grub/grubaa64.efi --prefix= -d \ grub-core cat chain configfile echo efinet ext2 fat halt help linux \ lsefisystab loadenv lvm minicmd normal part_msdos part_gpt reboot \ @@ -156,7 +156,7 @@ RUN git clone git://git.savannah.gnu.org/grub.git /tmp/grub && \ TARGET_STRIP=/opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-strip \ TARGET_NM=/opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-nm \ TARGET_RANLIB=/opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-ranlib && \ - make && \ + make -j$(nproc) && \ ./grub-mkimage -O arm-efi -o /opt/grub/grubarm.efi --prefix= -d \ grub-core cat chain configfile echo efinet ext2 fat halt help linux \ lsefisystab loadenv lvm minicmd normal part_msdos part_gpt reboot \ @@ -170,7 +170,7 @@ RUN git clone git://git.savannah.gnu.org/grub.git /tmp/grub && \ TARGET_STRIP=/opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-strip \ TARGET_NM=/opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-nm \ TARGET_RANLIB=/opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-ranlib && \ - make && \ + make -j$(nproc) && \ ./grub-mkimage -O riscv64-efi -o /opt/grub/grubriscv64.efi --prefix= -d \ grub-core cat chain configfile echo efinet ext2 fat halt help linux \ lsefisystab loadenv lvm minicmd normal part_msdos part_gpt reboot \ @@ -196,7 +196,7 @@ RUN git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git /tmp/t cd /tmp/tf-a/ && \ git checkout v2.10.0 && \ cd tools/fiptool && \ - make && \ + make -j$(nproc) && \ mkdir -p /usr/local/bin && \ cp fiptool /usr/local/bin && \ rm -rf /tmp/tf-a From 70712a6acb3d916055b84c96768f8e10bfd49589 Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 27 Nov 2024 11:17:23 -0600 Subject: [PATCH 13/20] docker: Update to grub-2.12 The current release of grub is 2.12 and it will be good to pick this up now so that we can update other parts of our stack. Reviewed-by: Simon Glass Signed-off-by: Tom Rini --- tools/docker/Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 449745712de..11beaedf9b3 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -55,6 +55,7 @@ RUN apt-get update && apt-get install -y \ flex \ gawk \ gdisk \ + gettext \ git \ gnu-efi \ gnutls-dev \ @@ -128,11 +129,9 @@ RUN chmod +r /boot/vmlinu* # Build GRUB UEFI targets for ARM & RISC-V, 32-bit and 64-bit RUN git clone git://git.savannah.gnu.org/grub.git /tmp/grub && \ cd /tmp/grub && \ - git checkout grub-2.06 && \ + git checkout grub-2.12 && \ git config --global user.name "GitLab CI Runner" && \ git config --global user.email trini@konsulko.com && \ - git cherry-pick 049efdd72eb7baa7b2bf8884391ee7fe650da5a0 && \ - git cherry-pick 403d6540cd608b2706cfa0cb4713f7e4b490ff45 && \ ./bootstrap && \ mkdir -p /opt/grub && \ ./configure --target=aarch64 --with-platform=efi \ From 5fb78e0e2f8cac1678d11f1660f74e00c36159dc Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 27 Nov 2024 11:17:24 -0600 Subject: [PATCH 14/20] docker: Build grub for all architectures For consistency now, and future ease of testing with non-amd64 hosts, build grub for all architectures rather than relying on host binaries for i386/x86_64. Reviewed-by: Simon Glass Signed-off-by: Tom Rini --- .azure-pipelines.yml | 6 ++---- .gitlab-ci.yml | 6 ++---- tools/docker/Dockerfile | 24 ++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 4ecf76eaa0b..cc335e5f720 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -245,8 +245,6 @@ stages: ln -s u_boot_boardenv_qemu_arm64_na.py /tmp/uboot-test-hooks/py/travis-ci/u_boot_boardenv_qemu_arm64_lwip_na.py ln -s travis-ci /tmp/uboot-test-hooks/bin/\`hostname\` ln -s travis-ci /tmp/uboot-test-hooks/py/\`hostname\` - grub-mkimage --prefix=\"\" -o ~/grub_x86.efi -O i386-efi normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd - grub-mkimage --prefix=\"\" -o ~/grub_x64.efi -O x86_64-efi normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd if [[ "\${TEST_PY_BD}" == "qemu-riscv32_spl" ]]; then wget -O - https://github.com/riscv-software-src/opensbi/releases/download/v1.3.1/opensbi-1.3.1-rv-bin.tar.xz | tar -C /tmp -xJ; export OPENSBI=/tmp/opensbi-1.3.1-rv-bin/share/opensbi/ilp32/generic/firmware/fw_dynamic.bin; @@ -268,8 +266,8 @@ stages: fi pip install -r tools/buildman/requirements.txt tools/buildman/buildman -o \${UBOOT_TRAVIS_BUILD_DIR} -w -E -W -e --board \${TEST_PY_BD} \${OVERRIDE} - cp ~/grub_x86.efi \${UBOOT_TRAVIS_BUILD_DIR}/ - cp ~/grub_x64.efi \${UBOOT_TRAVIS_BUILD_DIR}/ + cp /opt/grub/grub_x86.efi \${UBOOT_TRAVIS_BUILD_DIR}/ + cp /opt/grub/grub_x64.efi \${UBOOT_TRAVIS_BUILD_DIR}/ cp /opt/grub/grubriscv64.efi \${UBOOT_TRAVIS_BUILD_DIR}/grub_riscv64.efi cp /opt/grub/grubaa64.efi \${UBOOT_TRAVIS_BUILD_DIR}/grub_arm64.efi cp /opt/grub/grubarm.efi \${UBOOT_TRAVIS_BUILD_DIR}/grub_arm.efi diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2164ad79a72..23bbe2c24b8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,8 +34,6 @@ stages: - ln -s conf.qemu_arm64_na /tmp/uboot-test-hooks/bin/travis-ci/conf.qemu_arm64_lwip_na - ln -s travis-ci /tmp/uboot-test-hooks/bin/`hostname` - ln -s travis-ci /tmp/uboot-test-hooks/py/`hostname` - - grub-mkimage --prefix="" -o ~/grub_x86.efi -O i386-efi normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd - - grub-mkimage --prefix="" -o ~/grub_x64.efi -O x86_64-efi normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd - if [[ "${TEST_PY_BD}" == "qemu-riscv32_spl" ]]; then wget -O - https://github.com/riscv-software-src/opensbi/releases/download/v1.3.1/opensbi-1.3.1-rv-bin.tar.xz | tar -C /tmp -xJ; export OPENSBI=/tmp/opensbi-1.3.1-rv-bin/share/opensbi/ilp32/generic/firmware/fw_dynamic.bin; @@ -62,8 +60,8 @@ stages: fi - tools/buildman/buildman -o ${UBOOT_TRAVIS_BUILD_DIR} -w -E -W -e --board ${TEST_PY_BD} ${OVERRIDE} - - cp ~/grub_x86.efi $UBOOT_TRAVIS_BUILD_DIR/ - - cp ~/grub_x64.efi $UBOOT_TRAVIS_BUILD_DIR/ + - cp /opt/grub/grub_x86.efi $UBOOT_TRAVIS_BUILD_DIR/ + - cp /opt/grub/grub_x64.efi $UBOOT_TRAVIS_BUILD_DIR/ - cp /opt/grub/grubriscv64.efi $UBOOT_TRAVIS_BUILD_DIR/grub_riscv64.efi - cp /opt/grub/grubaa64.efi $UBOOT_TRAVIS_BUILD_DIR/grub_arm64.efi - cp /opt/grub/grubarm.efi $UBOOT_TRAVIS_BUILD_DIR/grub_arm.efi diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 11beaedf9b3..90c90bd05f0 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -60,8 +60,6 @@ RUN apt-get update && apt-get install -y \ gnu-efi \ gnutls-dev \ graphviz \ - grub-efi-amd64-bin \ - grub-efi-ia32-bin \ help2man \ iasl \ imagemagick \ @@ -175,6 +173,28 @@ RUN git clone git://git.savannah.gnu.org/grub.git /tmp/grub && \ lsefisystab loadenv lvm minicmd normal part_msdos part_gpt reboot \ search search_fs_file search_fs_uuid search_label serial sleep test \ true && \ + make clean && \ + ./configure --target=i386 --with-platform=efi \ + CC=gcc \ + TARGET_CC=/opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-gcc \ + TARGET_OBJCOPY=/opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-objcopy \ + TARGET_STRIP=/opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-strip \ + TARGET_NM=/opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-nm \ + TARGET_RANLIB=/opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-ranlib && \ + make -j$(nproc) && \ + ./grub-mkimage -O i386-efi -o /opt/grub/grub_x86.efi --prefix= -d \ + grub-core normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd && \ + make clean && \ + ./configure --target=x86_64 --with-platform=efi \ + CC=gcc \ + TARGET_CC=/opt/gcc-13.2.0-nolibc/x86_64-linux/bin/x86_64-linux-gcc \ + TARGET_OBJCOPY=/opt/gcc-13.2.0-nolibc/x86_64-linux/bin/x86_64-linux-objcopy \ + TARGET_STRIP=/opt/gcc-13.2.0-nolibc/x86_64-linux/bin/x86_64-linux-strip \ + TARGET_NM=/opt/gcc-13.2.0-nolibc/x86_64-linux/bin/x86_64-linux-nm \ + TARGET_RANLIB=/opt/gcc-13.2.0-nolibc/x86_64-linux/bin/x86_64-linux-ranlib && \ + make -j$(nproc) && \ + ./grub-mkimage -O x86_64-efi -o /opt/grub/grub_x64.efi --prefix= -d \ + grub-core normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd && \ rm -rf /tmp/grub RUN git clone https://gitlab.com/qemu-project/qemu.git /tmp/qemu && \ From 191e1454711717bfee10cc76c015a083208b9609 Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 27 Nov 2024 11:17:25 -0600 Subject: [PATCH 15/20] docker: Use cache mounts for apt Instead of deleting /var/lib/apt/lists after each relevant RUN line, use a cache mount as is the current best practices. Reviewed-by: Simon Glass Signed-off-by: Tom Rini --- tools/docker/Dockerfile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 90c90bd05f0..bc8d1ebbb1e 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -10,7 +10,9 @@ LABEL org.opencontainers.image.description=" This image is for building U-Boot i ENV DEBIAN_FRONTEND=noninteractive # Add LLVM repository -RUN apt-get update && apt-get install -y gnupg2 wget xz-utils && rm -rf /var/lib/apt/lists/* +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt-get update && apt-get install -y gnupg2 wget xz-utils RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - RUN echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main | tee /etc/apt/sources.list.d/llvm.list @@ -33,7 +35,9 @@ RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_ RUN wget -O - https://github.com/foss-xtensa/toolchain/releases/download/2020.07/x86_64-2020.07-xtensa-dc233c-elf.tar.gz | tar -C /opt -xz # Update and install things from apt now -RUN apt-get update && apt-get install -y \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt-get update && apt-get install -y \ automake \ autopoint \ bc \ @@ -118,8 +122,7 @@ RUN apt-get update && apt-get install -y \ vboot-utils \ xilinx-bootgen \ xxd \ - zip \ - && rm -rf /var/lib/apt/lists/* + zip # Make kernels readable for libguestfs tools to work correctly RUN chmod +r /boot/vmlinu* From 45b2f9d4fbae507d23ffdd08601bbad6b83c0fd6 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Nov 2024 11:17:26 -0600 Subject: [PATCH 16/20] docker: Support building for multiple architectures Add instructions on how to build the file for multiple architectures. Add a message indicating what is happening. Update the documentation as well. Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- doc/build/docker.rst | 23 +++++++++++++++++++++-- tools/docker/Dockerfile | 9 +++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/doc/build/docker.rst b/doc/build/docker.rst index 45659b3b89d..5896dd5ac4a 100644 --- a/doc/build/docker.rst +++ b/doc/build/docker.rst @@ -1,11 +1,30 @@ GitLab CI / U-Boot runner container =================================== -In order to have a reproducible and portable build environment for CI we use a container for building in. This means that developers can also reproduce the CI environment, to a large degree at least, locally. This file is located in the tools/docker directory. To build the image yourself +In order to have a reproducible and portable build environment for CI we use a container for building in. This means that developers can also reproduce the CI environment, to a large degree at least, locally. This file is located in the tools/docker directory. + +The docker image supports both amd64 and arm64. Ensure that the +'docker-buildx' Debian package is installed (or the equivalent on another +distribution). + +You will need a multi-platform container, otherwise this error is shown:: + + ERROR: Multi-platform build is not supported for the docker driver. + Switch to a different driver, or turn on the containerd image store, and try again. + +You can add one with:: + + sudo docker buildx create --name multiarch --driver docker-container --use + +Building is supported on both amd64 (i.e. 64-bit x86) and arm64 machines. While +both amd64 and arm64 happen in parallel, the non-native part will take +considerably longer as it must use QEMU to emulate the foreign code. + +To build the image yourself:: .. code-block:: bash - sudo docker build -t your-namespace:your-tag . + sudo docker buildx build --platform linux/arm64/v8,linux/amd64 -t your-namespace:your-tag . Or to use an existing container diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index bc8d1ebbb1e..43cd37070e4 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -6,9 +6,18 @@ FROM ubuntu:jammy-20240808 LABEL org.opencontainers.image.authors="Tom Rini " LABEL org.opencontainers.image.description=" This image is for building U-Boot inside a container" +# Used by docker to set the target platform: valid values are linux/arm64/v8 +# and linux/amd64 +ARG TARGETPLATFORM + +# Used by docker to set the build platform: the only valid value is linux/amd64 +ARG BUILDPLATFORM + # Make sure apt is happy ENV DEBIAN_FRONTEND=noninteractive +RUN echo "Building on $BUILDPLATFORM, for target $TARGETPLATFORM" + # Add LLVM repository RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked \ From 6e510606d4e327e457cfdbe264162610c0caabd1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Nov 2024 11:17:27 -0600 Subject: [PATCH 17/20] docker: Adjust installed packages slightly We no longer need to install libc6-i386 so we can drop that. Switch to installing linux-image-generic as that will be available on all hosts, to provide the /boot/vmlinu* file that's requires for various tools. Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- tools/docker/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 43cd37070e4..5d3bd4e24ab 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -77,7 +77,6 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ iasl \ imagemagick \ iputils-ping \ - libc6-i386 \ libconfuse-dev \ libgit2-dev \ libjson-glib-dev \ @@ -95,7 +94,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ libtool \ libudev-dev \ libusb-1.0-0-dev \ - linux-image-kvm \ + linux-image-generic \ lzma-alone \ lzop \ mount \ From ffbaa6458b46d4438b659e951b985fa9c2ee1cef Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Nov 2024 11:17:28 -0600 Subject: [PATCH 18/20] docker: Fix LegacyKeyValueFormat warning with PYTHONPATH Fix a warning due to the syntax used for PYTHONPATH: LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 304) Signed-off-by: Simon Glass Reviewed-by: Heinrich Schuchardt Reviewed-by: Tom Rini --- tools/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 5d3bd4e24ab..9d10de5b892 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -315,4 +315,4 @@ RUN /bin/echo -e "\nx86 = i386" >> ~/.buildman; # Add mkbootimg tool RUN git clone https://android.googlesource.com/platform/system/tools/mkbootimg /home/uboot/mkbootimg -ENV PYTHONPATH "${PYTHONPATH}:/home/uboot/mkbootimg" +ENV PYTHONPATH="${PYTHONPATH}:/home/uboot/mkbootimg" From 939b29e5923188cd4e9d67423288f66cada7f2b3 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Nov 2024 11:17:29 -0600 Subject: [PATCH 19/20] docker: Install toolchains on arm64 host Refactor the code to support downloading toolchains for arm64 as well as x86_64 There doesn't seem to be an xtensa toolchain for arm64 at the same location, so download that only on x86 Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- tools/docker/Dockerfile | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 9d10de5b892..ce1ad7cb23a 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -16,6 +16,15 @@ ARG BUILDPLATFORM # Make sure apt is happy ENV DEBIAN_FRONTEND=noninteractive +# Set architectures to build for (leaving out ARM which is an exception) +ENV ARCHS="aarch64 arc i386 m68k mips microblaze nios2 powerpc riscv64 riscv32 sh2 x86_64" + +# Mirror containing the toolchains +ENV MIRROR=https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin + +# Toolchain version +ENV TCVER=13.2.0 + RUN echo "Building on $BUILDPLATFORM, for target $TARGETPLATFORM" # Add LLVM repository @@ -25,23 +34,25 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - RUN echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main | tee /etc/apt/sources.list.d/llvm.list -# Manually install the kernel.org "Crosstool" based toolchains for gcc-13.2.0 -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-aarch64-linux.tar.xz | tar -C /opt -xJ -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-arc-linux.tar.xz | tar -C /opt -xJ -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-arm-linux-gnueabi.tar.xz | tar -C /opt -xJ -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-i386-linux.tar.xz | tar -C /opt -xJ -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-m68k-linux.tar.xz | tar -C /opt -xJ -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-mips-linux.tar.xz | tar -C /opt -xJ -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-microblaze-linux.tar.xz | tar -C /opt -xJ -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-nios2-linux.tar.xz | tar -C /opt -xJ -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-powerpc-linux.tar.xz | tar -C /opt -xJ -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-riscv64-linux.tar.xz | tar -C /opt -xJ -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-riscv32-linux.tar.xz | tar -C /opt -xJ -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-sh2-linux.tar.xz | tar -C /opt -xJ -RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-x86_64-linux.tar.xz | tar -C /opt -xJ +# Create a list of URLs to process, then pass them into a 'while read' loop +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then HOSTARCH=x86_64; else HOSTARCH=arm64; fi; ( \ + # Manually install the kernel.org "Crosstool"-based toolchains + for arch in $ARCHS; do \ + echo $MIRROR/$HOSTARCH/$TCVER/${HOSTARCH}-gcc-$TCVER-nolibc-${arch}-linux.tar.xz; \ + done; \ + \ + # Deal with ARM, which has a 'gnueabi' suffix + echo $MIRROR/${HOSTARCH}/$TCVER/${HOSTARCH}-gcc-$TCVER-nolibc-arm-linux-gnueabi.tar.xz; \ + \ + ) | while read url; do \ + # Read the URL and unpack it into /opt + wget -O - $url | tar -C /opt -xJ; \ + done # Manually install other toolchains -RUN wget -O - https://github.com/foss-xtensa/toolchain/releases/download/2020.07/x86_64-2020.07-xtensa-dc233c-elf.tar.gz | tar -C /opt -xz +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + wget -O - https://github.com/foss-xtensa/toolchain/releases/download/2020.07/x86_64-2020.07-xtensa-dc233c-elf.tar.gz | tar -C /opt -xz; \ + fi # Update and install things from apt now RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ From 0025e7e40c8e89b42fee06dcb67f60dd9fc912e5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Nov 2024 11:17:30 -0600 Subject: [PATCH 20/20] CI: Add platform variable Add a list of possible platforms that can be used by gitlab runners. Signed-off-by: Simon Glass Reviewed-by: Tom Rini Reviewed-by: Ilias Apalodimas --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 23bbe2c24b8..f0113361a3f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,7 @@ variables: DEFAULT_TAG: "" MIRROR_DOCKER: docker.io SJG_LAB: "" + PLATFORM: linux/amd64,linux/arm64 default: tags: