[PATCH 00/10] test: Split up the image-creation code

From: Simon Glass <sjg@chromium.org> This series moves the image-creation code into separate files so it is easier to find and maintain. Simon Glass (10): test: Move image creation to test/py/img test: Create a common file for image utilities test: Move Fedora image-creation to its own file test: Move Ubuntu image-creation to its own file test: Move Armbian image-creation to its own file test: Move ChromeOS image-creation to its own file test: Move Android image-creation to its own file test: Move EFI image-creation to its own file test: Move the configuration-editor setup to its own file test: Move localboot image-creation to its own file MAINTAINERS | 5 + test/py/img/android.py | 146 ++++++++ test/py/img/armbian.py | 132 +++++++ test/py/img/cedit.py | 25 ++ test/py/img/chromeos.py | 154 +++++++++ test/py/img/common.py | 88 +++++ test/py/img/efi.py | 37 ++ test/py/img/fedora.py | 35 ++ test/py/img/localboot.py | 27 ++ test/py/img/ubuntu.py | 47 +++ test/py/{tests => }/img/vbe.py | 0 test/py/tests/test_ut.py | 616 +-------------------------------- 12 files changed, 705 insertions(+), 607 deletions(-) create mode 100644 test/py/img/android.py create mode 100644 test/py/img/armbian.py create mode 100644 test/py/img/cedit.py create mode 100644 test/py/img/chromeos.py create mode 100644 test/py/img/common.py create mode 100644 test/py/img/efi.py create mode 100644 test/py/img/fedora.py create mode 100644 test/py/img/localboot.py create mode 100644 test/py/img/ubuntu.py rename test/py/{tests => }/img/vbe.py (100%) -- 2.43.0 base-commit: 0d523d8d55dddbd1efd0c734845ceff9a975ff0b branch: makeb

From: Simon Glass <sjg@chromium.org> Rather than having this code mixed with the tests, it seems better to put it up one level. Move the directory and tidy up references. Signed-off-by: Simon Glass <sjg@chromium.org> --- MAINTAINERS | 5 +++++ test/py/{tests => }/img/vbe.py | 0 2 files changed, 5 insertions(+) rename test/py/{tests => }/img/vbe.py (100%) diff --git a/MAINTAINERS b/MAINTAINERS index 4997fc67b10..5d05281633d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1718,6 +1718,11 @@ M: Liviu Dudau <liviu.dudau@foss.arm.com> S: Maintained F: drivers/video/tda19988.c +TEST FRAMEWORK (PYTHON) +M: Simon Glass <sjg@chromium.org> +F: test/py +F: test/py/img + TI LP5562 LED DRIVER M: Rasmus Villemoes <rasmus.villemoes@prevas.dk> S: Supported diff --git a/test/py/tests/img/vbe.py b/test/py/img/vbe.py similarity index 100% rename from test/py/tests/img/vbe.py rename to test/py/img/vbe.py -- 2.43.0

From: Simon Glass <sjg@chromium.org> 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. Signed-off-by: Simon Glass <sjg@chromium.org> Co-authored-by: Claude <noreply@anthropic.com> --- test/py/img/common.py | 88 ++++++++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 74 +-------------------------------- 2 files changed, 89 insertions(+), 73 deletions(-) create mode 100644 test/py/img/common.py diff --git a/test/py/img/common.py b/test/py/img/common.py new file mode 100644 index 00000000000..80f9c124fc8 --- /dev/null +++ b/test/py/img/common.py @@ -0,0 +1,88 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + +"""Common utilities for image creation""" + +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(config, log, devnum, basename, vmlinux, initrd, dtbdir, + script): + """Create a 20MB disk image with a single FAT partition + + Args: + config (ArbitraryAttributeContainer): Configuration + log (multiplexed_log.Logfile): Log to write to + 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 + """ + import gzip + + fsh = FsHelper(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(config.persistent_data_dir, 'inf') + with open(inf, 'wb') as fd: + fd.write(gzip.compress(b'vmlinux')) + mkimage = config.build_dir + '/tools/mkimage' + utils.run_and_log_no_ubman( + log, 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_no_ubman( + log, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};') + + fsh.mk_fs() + + img = DiskHelper(config, devnum, basename, True) + img.add_fs(fsh, DiskHelper.VFAT, bootable=True) + + ext4 = FsHelper(config, 'ext4', 1, prefix=basename) + ext4.setup() + ext4.mk_fs() + + img.add_fs(ext4, DiskHelper.EXT4) + img.create() + fsh.cleanup() \ No newline at end of file diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index f86a4218f9f..9d619eab30d 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -18,26 +18,8 @@ import utils from fs_helper import DiskHelper, FsHelper from test_android import test_abootimg from img.vbe import setup_vbe_image +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(config, log): """Create a 20MB disk image with a single ext4 partition @@ -161,60 +143,6 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} fsh.cleanup() -def setup_extlinux_image(config, log, devnum, basename, vmlinux, initrd, dtbdir, - script): - """Create a 20MB disk image with a single FAT partition - - Args: - config (ArbitraryAttributeContainer): Configuration - log (multiplexed_log.Logfile): Log to write to - 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(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(config.persistent_data_dir, 'inf') - with open(inf, 'wb') as fd: - fd.write(gzip.compress(b'vmlinux')) - mkimage = config.build_dir + '/tools/mkimage' - utils.run_and_log_no_ubman( - log, 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_no_ubman( - log, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};') - - fsh.mk_fs() - - img = DiskHelper(config, devnum, basename, True) - img.add_fs(fsh, DiskHelper.VFAT, bootable=True) - - ext4 = FsHelper(config, 'ext4', 1, prefix=basename) - ext4.setup() - ext4.mk_fs() - - img.add_fs(ext4, DiskHelper.EXT4) - img.create() - fsh.cleanup() - def setup_fedora_image(config, log, devnum, basename): """Create a 20MB Fedora disk image with a single FAT partition -- 2.43.0

From: Simon Glass <sjg@chromium.org> Move setup_fedora_image() to its own module. Signed-off-by: Simon Glass <sjg@chromium.org> Co-authored-by: Claude <noreply@anthropic.com> --- test/py/img/fedora.py | 35 +++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 29 +---------------------------- 2 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 test/py/img/fedora.py diff --git a/test/py/img/fedora.py b/test/py/img/fedora.py new file mode 100644 index 00000000000..ffa546d1cfe --- /dev/null +++ b/test/py/img/fedora.py @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + +"""Create Fedora test disk images""" + +from img.common import setup_extlinux_image + + +def setup_fedora_image(config, log, devnum, basename): + """Create a 20MB Fedora disk image with a single FAT partition + + Args: + config (ArbitraryAttributeContainer): Configuration + log (multiplexed_log.Logfile): Log to write to + devnum (int): Device number to use, e.g. 1 + basename (str): Base name to use in the filename, e.g. 'mmc' + """ + 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. +menu hidden +timeout 20 +totaltimeout 600 + +label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) + kernel /%s + 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) + setup_extlinux_image(config, log, devnum, basename, vmlinux, + initrd, dtbdir, script) \ No newline at end of file diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 9d619eab30d..6412aaaf3bb 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -19,6 +19,7 @@ from fs_helper import DiskHelper, FsHelper from test_android import test_abootimg from img.vbe import setup_vbe_image from img.common import mkdir_cond, copy_partition, setup_extlinux_image +from img.fedora import setup_fedora_image def setup_bootmenu_image(config, log): @@ -143,34 +144,6 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} fsh.cleanup() -def setup_fedora_image(config, log, devnum, basename): - """Create a 20MB Fedora disk image with a single FAT partition - - Args: - config (ArbitraryAttributeContainer): Configuration - log (multiplexed_log.Logfile): Log to write to - devnum (int): Device number to use, e.g. 1 - basename (str): Base name to use in the filename, e.g. 'mmc' - """ - 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. -menu hidden -timeout 20 -totaltimeout 600 - -label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) - kernel /%s - 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) - setup_extlinux_image(config, log, devnum, basename, vmlinux, - initrd, dtbdir, script) - def setup_ubuntu_image(config, log, devnum, basename): """Create a 20MB Ubuntu disk image with a single FAT partition -- 2.43.0

From: Simon Glass <sjg@chromium.org> Move setup_ubuntu_image() to its own module. Signed-off-by: Simon Glass <sjg@chromium.org> Co-authored-by <noreply@anthropic.com> --- test/py/img/ubuntu.py | 47 ++++++++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 41 +---------------------------------- 2 files changed, 48 insertions(+), 40 deletions(-) create mode 100644 test/py/img/ubuntu.py diff --git a/test/py/img/ubuntu.py b/test/py/img/ubuntu.py new file mode 100644 index 00000000000..4fe54cb679b --- /dev/null +++ b/test/py/img/ubuntu.py @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + +"""Create Ubuntu test disk images""" + +from img.common import setup_extlinux_image + + +def setup_ubuntu_image(config, log, devnum, basename): + """Create a 20MB Ubuntu disk image with a single FAT partition + + Args: + config (ArbitraryAttributeContainer): Configuration + log (multiplexed_log.Logfile): Log to write to + devnum (int): Device number to use, e.g. 1 + basename (str): Base name to use in the filename, e.g. 'mmc' + """ + vmlinux = 'vmlinuz-6.8.0-53-generic' + initrd = 'initrd.img-6.8.0-53-generic' + dtbdir = None + script = '''## /boot/extlinux/extlinux.conf +## +## IMPORTANT WARNING +## +## The configuration of this file is generated automatically. +## Do not edit this file manually, use: u-boot-update + +default l0 +menu title U-Boot menu +prompt 1 +timeout 50 + + +label l0 + menu label Ubuntu 24.04.1 LTS 6.8.0-53-generic + linux /boot/%s + initrd /boot/%s + + append root=/dev/disk/by-uuid/bcfdda4a-8249-4f40-9f0f-7c1a76b6cbe8 ro earlycon + +label l0r + menu label Ubuntu 24.04.1 LTS 6.8.0-53-generic (rescue target) + linux /boot/%s + initrd /boot/%s +''' % (vmlinux, initrd, vmlinux, initrd) + setup_extlinux_image(config, log, devnum, basename, vmlinux, initrd, dtbdir, + script) \ No newline at end of file diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 6412aaaf3bb..a586d409505 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -20,6 +20,7 @@ from test_android import test_abootimg from img.vbe import setup_vbe_image from img.common import mkdir_cond, copy_partition, setup_extlinux_image from img.fedora import setup_fedora_image +from img.ubuntu import setup_ubuntu_image def setup_bootmenu_image(config, log): @@ -144,46 +145,6 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} fsh.cleanup() -def setup_ubuntu_image(config, log, devnum, basename): - """Create a 20MB Ubuntu disk image with a single FAT partition - - Args: - config (ArbitraryAttributeContainer): Configuration - log (multiplexed_log.Logfile): Log to write to - devnum (int): Device number to use, e.g. 1 - basename (str): Base name to use in the filename, e.g. 'mmc' - """ - vmlinux = 'vmlinuz-6.8.0-53-generic' - initrd = 'initrd.img-6.8.0-53-generic' - dtbdir = None - script = '''## /boot/extlinux/extlinux.conf -## -## IMPORTANT WARNING -## -## The configuration of this file is generated automatically. -## Do not edit this file manually, use: u-boot-update - -default l0 -menu title U-Boot menu -prompt 1 -timeout 50 - - -label l0 - menu label Ubuntu 24.04.1 LTS 6.8.0-53-generic - linux /boot/%s - initrd /boot/%s - - append root=/dev/disk/by-uuid/bcfdda4a-8249-4f40-9f0f-7c1a76b6cbe8 ro earlycon - -label l0r - menu label Ubuntu 24.04.1 LTS 6.8.0-53-generic (rescue target) - linux /boot/%s - initrd /boot/%s -''' % (vmlinux, initrd, vmlinux, initrd) - setup_extlinux_image(config, log, devnum, basename, vmlinux, initrd, dtbdir, - script) - def setup_cros_image(config, log): """Create a 20MB disk image with ChromiumOS partitions -- 2.43.0

From: Simon Glass <sjg@chromium.org> Move setup_bootmenu_image() to its own module. This function creates an image styled on Armbian 22.08 Jammy with a boot menu. Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <sjg@chromium.org> --- test/py/img/armbian.py | 132 +++++++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 123 +----------------------------------- 2 files changed, 133 insertions(+), 122 deletions(-) create mode 100644 test/py/img/armbian.py diff --git a/test/py/img/armbian.py b/test/py/img/armbian.py new file mode 100644 index 00000000000..4db40fd5070 --- /dev/null +++ b/test/py/img/armbian.py @@ -0,0 +1,132 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + +"""Create Armbian test disk images""" + +import os + +import utils +from fs_helper import DiskHelper, FsHelper +from img.common import mkdir_cond + + +def setup_bootmenu_image(config, log): + """Create a 20MB disk image with a single ext4 partition + + This is modelled on Armbian 22.08 Jammy + + Args: + config (ArbitraryAttributeContainer): Configuration + log (multiplexed_log.Logfile): Log to write to + """ + mmc_dev = 4 + + script = '''# DO NOT EDIT THIS FILE +# +# Please edit /boot/armbianEnv.txt to set supported parameters +# + +setenv load_addr "0x9000000" +setenv overlay_error "false" +# default values +setenv rootdev "/dev/mmcblk%dp1" +setenv verbosity "1" +setenv console "both" +setenv bootlogo "false" +setenv rootfstype "ext4" +setenv docker_optimizations "on" +setenv earlycon "off" + +echo "Boot script loaded from ${devtype} ${devnum}" + +if test -e ${devtype} ${devnum} ${prefix}armbianEnv.txt; then + load ${devtype} ${devnum} ${load_addr} ${prefix}armbianEnv.txt + env import -t ${load_addr} ${filesize} +fi + +if test "${logo}" = "disabled"; then setenv logo "logo.nologo"; fi + +if test "${console}" = "display" || test "${console}" = "both"; then setenv consoleargs "console=tty1"; fi +if test "${console}" = "serial" || test "${console}" = "both"; then setenv consoleargs "console=ttyS2,1500000 ${consoleargs}"; fi +if test "${earlycon}" = "on"; then setenv consoleargs "earlycon ${consoleargs}"; fi +if test "${bootlogo}" = "true"; then setenv consoleargs "bootsplash.bootfile=bootsplash.armbian ${consoleargs}"; fi + +# get PARTUUID of first partition on SD/eMMC the boot script was loaded from +if test "${devtype}" = "mmc"; then part uuid mmc ${devnum}:1 partuuid; fi + +setenv bootargs "root=${rootdev} rootwait rootfstype=${rootfstype} ${consoleargs} consoleblank=0 loglevel=${verbosity} ubootpart=${partuuid} usb-storage.quirks=${usbstoragequirks} ${extraargs} ${extraboardargs}" + +if test "${docker_optimizations}" = "on"; then setenv bootargs "${bootargs} cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory swapaccount=1"; fi + +load ${devtype} ${devnum} ${ramdisk_addr_r} ${prefix}uInitrd +load ${devtype} ${devnum} ${kernel_addr_r} ${prefix}Image + +load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}dtb/${fdtfile} +fdt addr ${fdt_addr_r} +fdt resize 65536 +for overlay_file in ${overlays}; do + if load ${devtype} ${devnum} ${load_addr} ${prefix}dtb/rockchip/overlay/${overlay_prefix}-${overlay_file}.dtbo; then + echo "Applying kernel provided DT overlay ${overlay_prefix}-${overlay_file}.dtbo" + fdt apply ${load_addr} || setenv overlay_error "true" + fi +done +for overlay_file in ${user_overlays}; do + if load ${devtype} ${devnum} ${load_addr} ${prefix}overlay-user/${overlay_file}.dtbo; then + echo "Applying user provided DT overlay ${overlay_file}.dtbo" + fdt apply ${load_addr} || setenv overlay_error "true" + fi +done +if test "${overlay_error}" = "true"; then + echo "Error applying DT overlays, restoring original DT" + load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}dtb/${fdtfile} +else + if load ${devtype} ${devnum} ${load_addr} ${prefix}dtb/rockchip/overlay/${overlay_prefix}-fixup.scr; then + echo "Applying kernel provided DT fixup script (${overlay_prefix}-fixup.scr)" + source ${load_addr} + fi + if test -e ${devtype} ${devnum} ${prefix}fixup.scr; then + load ${devtype} ${devnum} ${load_addr} ${prefix}fixup.scr + echo "Applying user provided fixup script (fixup.scr)" + source ${load_addr} + fi +fi +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 +''' + fsh = FsHelper(config, 'ext4', 18, 'mmc') + fsh.setup() + bootdir = os.path.join(fsh.srcdir, '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(config.source_dir, + 'test/py/tests/bootstd/armbian.bmp.xz') + bmp_file = os.path.join(bootdir, 'boot.bmp') + utils.run_and_log_no_ubman( + log, + ['sh', '-c', f'xz -dc {infname} >{bmp_file}']) + + mkimage = config.build_dir + '/tools/mkimage' + utils.run_and_log_no_ubman( + log, 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) + + symlink = os.path.join(bootdir, 'Image') + if os.path.exists(symlink): + os.remove(symlink) + utils.run_and_log_no_ubman(log, f'echo here {kernel} {symlink}') + os.symlink(kernel, symlink) + fsh.mk_fs() + img = DiskHelper(config, mmc_dev, 'mmc', True) + img.add_fs(fsh, DiskHelper.EXT4) + img.create() + fsh.cleanup() \ No newline at end of file diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index a586d409505..1a868548b92 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -21,128 +21,7 @@ from img.vbe import setup_vbe_image from img.common import mkdir_cond, copy_partition, setup_extlinux_image from img.fedora import setup_fedora_image from img.ubuntu import setup_ubuntu_image - - -def setup_bootmenu_image(config, log): - """Create a 20MB disk image with a single ext4 partition - - This is modelled on Armbian 22.08 Jammy - - Args: - config (ArbitraryAttributeContainer): Configuration - log (multiplexed_log.Logfile): Log to write to - """ - mmc_dev = 4 - - script = '''# DO NOT EDIT THIS FILE -# -# Please edit /boot/armbianEnv.txt to set supported parameters -# - -setenv load_addr "0x9000000" -setenv overlay_error "false" -# default values -setenv rootdev "/dev/mmcblk%dp1" -setenv verbosity "1" -setenv console "both" -setenv bootlogo "false" -setenv rootfstype "ext4" -setenv docker_optimizations "on" -setenv earlycon "off" - -echo "Boot script loaded from ${devtype} ${devnum}" - -if test -e ${devtype} ${devnum} ${prefix}armbianEnv.txt; then - load ${devtype} ${devnum} ${load_addr} ${prefix}armbianEnv.txt - env import -t ${load_addr} ${filesize} -fi - -if test "${logo}" = "disabled"; then setenv logo "logo.nologo"; fi - -if test "${console}" = "display" || test "${console}" = "both"; then setenv consoleargs "console=tty1"; fi -if test "${console}" = "serial" || test "${console}" = "both"; then setenv consoleargs "console=ttyS2,1500000 ${consoleargs}"; fi -if test "${earlycon}" = "on"; then setenv consoleargs "earlycon ${consoleargs}"; fi -if test "${bootlogo}" = "true"; then setenv consoleargs "bootsplash.bootfile=bootsplash.armbian ${consoleargs}"; fi - -# get PARTUUID of first partition on SD/eMMC the boot script was loaded from -if test "${devtype}" = "mmc"; then part uuid mmc ${devnum}:1 partuuid; fi - -setenv bootargs "root=${rootdev} rootwait rootfstype=${rootfstype} ${consoleargs} consoleblank=0 loglevel=${verbosity} ubootpart=${partuuid} usb-storage.quirks=${usbstoragequirks} ${extraargs} ${extraboardargs}" - -if test "${docker_optimizations}" = "on"; then setenv bootargs "${bootargs} cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory swapaccount=1"; fi - -load ${devtype} ${devnum} ${ramdisk_addr_r} ${prefix}uInitrd -load ${devtype} ${devnum} ${kernel_addr_r} ${prefix}Image - -load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}dtb/${fdtfile} -fdt addr ${fdt_addr_r} -fdt resize 65536 -for overlay_file in ${overlays}; do - if load ${devtype} ${devnum} ${load_addr} ${prefix}dtb/rockchip/overlay/${overlay_prefix}-${overlay_file}.dtbo; then - echo "Applying kernel provided DT overlay ${overlay_prefix}-${overlay_file}.dtbo" - fdt apply ${load_addr} || setenv overlay_error "true" - fi -done -for overlay_file in ${user_overlays}; do - if load ${devtype} ${devnum} ${load_addr} ${prefix}overlay-user/${overlay_file}.dtbo; then - echo "Applying user provided DT overlay ${overlay_file}.dtbo" - fdt apply ${load_addr} || setenv overlay_error "true" - fi -done -if test "${overlay_error}" = "true"; then - echo "Error applying DT overlays, restoring original DT" - load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}dtb/${fdtfile} -else - if load ${devtype} ${devnum} ${load_addr} ${prefix}dtb/rockchip/overlay/${overlay_prefix}-fixup.scr; then - echo "Applying kernel provided DT fixup script (${overlay_prefix}-fixup.scr)" - source ${load_addr} - fi - if test -e ${devtype} ${devnum} ${prefix}fixup.scr; then - load ${devtype} ${devnum} ${load_addr} ${prefix}fixup.scr - echo "Applying user provided fixup script (fixup.scr)" - source ${load_addr} - fi -fi -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 -''' - fsh = FsHelper(config, 'ext4', 18, 'mmc') - fsh.setup() - bootdir = os.path.join(fsh.srcdir, '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(config.source_dir, - 'test/py/tests/bootstd/armbian.bmp.xz') - bmp_file = os.path.join(bootdir, 'boot.bmp') - utils.run_and_log_no_ubman( - log, - ['sh', '-c', f'xz -dc {infname} >{bmp_file}']) - - mkimage = config.build_dir + '/tools/mkimage' - utils.run_and_log_no_ubman( - log, 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) - - symlink = os.path.join(bootdir, 'Image') - if os.path.exists(symlink): - os.remove(symlink) - utils.run_and_log_no_ubman(log, f'echo here {kernel} {symlink}') - os.symlink(kernel, symlink) - fsh.mk_fs() - img = DiskHelper(config, mmc_dev, 'mmc', True) - img.add_fs(fsh, DiskHelper.EXT4) - img.create() - fsh.cleanup() +from img.armbian import setup_bootmenu_image def setup_cros_image(config, log): -- 2.43.0

From: Simon Glass <sjg@chromium.org> Move setup_cros_image() to its own module. This function creates disk images with a ChromiumOS partition layout. Signed-off-by: Simon Glass <sjg@chromium.org> Co-authored-by: Claude <noreply@anthropic.com> --- test/py/img/chromeos.py | 154 +++++++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 145 +----------------------------------- 2 files changed, 155 insertions(+), 144 deletions(-) create mode 100644 test/py/img/chromeos.py diff --git a/test/py/img/chromeos.py b/test/py/img/chromeos.py new file mode 100644 index 00000000000..6217b5310f1 --- /dev/null +++ b/test/py/img/chromeos.py @@ -0,0 +1,154 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + +"""Create ChromeOS test disk images""" + +import collections +import os + +import utils + + +def setup_cros_image(config, log): + """Create a 20MB disk image with ChromiumOS partitions + + Args: + config (ArbitraryAttributeContainer): Configuration + log (multiplexed_log.Logfile): Log to write to + """ + Partition = collections.namedtuple('part', 'start,size,name') + parts = {} + disk_data = None + + def pack_kernel(config, log, arch, kern, dummy): + """Pack a kernel containing some fake data + + Args: + config (ArbitraryAttributeContainer): Configuration + log (multiplexed_log.Logfile): Log to write to + arch (str): Architecture to use ('x86' or 'arm') + kern (str): Filename containing kernel + dummy (str): Dummy filename to use for config and bootloader + + Return: + bytes: Packed-kernel data + """ + kern_part = os.path.join(config.result_dir, f'kern-part-{arch}.bin') + utils.run_and_log_no_ubman( + log, + f'futility vbutil_kernel --pack {kern_part} ' + '--keyblock doc/chromium/files/devkeys/kernel.keyblock ' + '--signprivate doc/chromium/files/devkeys/kernel_data_key.vbprivk ' + f'--version 1 --config {dummy} --bootloader {dummy} ' + f'--vmlinuz {kern}') + + with open(kern_part, 'rb') as inf: + kern_part_data = inf.read() + return kern_part_data + + def set_part_data(partnum, data): + """Set the contents of a disk partition + + This updates disk_data by putting data in the right place + + Args: + partnum (int): Partition number to set + data (bytes): Data for that partition + """ + nonlocal disk_data + + start = parts[partnum].start * sect_size + disk_data = disk_data[:start] + data + disk_data[start + len(data):] + + mmc_dev = 5 + fname = os.path.join(config.source_dir, f'mmc{mmc_dev}.img') + utils.run_and_log_no_ubman(log, f'qemu-img create {fname} 20M') + utils.run_and_log_no_ubman(log, f'cgpt create {fname}') + + uuid_state = 'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7' + uuid_kern = 'fe3a2a5d-4f32-41a7-b725-accc3285a309' + uuid_root = '3cb8e202-3b7e-47dd-8a3c-7ff2a13cfcec' + uuid_rwfw = 'cab6e88e-abf3-4102-a07a-d4bb9be3c1d3' + uuid_reserved = '2e0a753d-9e48-43b0-8337-b15192cb1b5e' + uuid_efi = 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b' + + ptr = 40 + + # Number of sectors in 1MB + sect_size = 512 + sect_1mb = (1 << 20) // sect_size + + required_parts = [ + {'num': 0xb, 'label':'RWFW', 'type': uuid_rwfw, 'size': '1'}, + {'num': 6, 'label':'KERN_C', 'type': uuid_kern, 'size': '1'}, + {'num': 7, 'label':'ROOT_C', 'type': uuid_root, 'size': '1'}, + {'num': 9, 'label':'reserved', 'type': uuid_reserved, 'size': '1'}, + {'num': 0xa, 'label':'reserved', 'type': uuid_reserved, 'size': '1'}, + + {'num': 2, 'label':'KERN_A', 'type': uuid_kern, 'size': '1M'}, + {'num': 4, 'label':'KERN_B', 'type': uuid_kern, 'size': '1M'}, + + {'num': 8, 'label':'OEM', 'type': uuid_state, 'size': '1M'}, + {'num': 0xc, 'label':'EFI-SYSTEM', 'type': uuid_efi, 'size': '1M'}, + + {'num': 5, 'label':'ROOT_B', 'type': uuid_root, 'size': '1'}, + {'num': 3, 'label':'ROOT_A', 'type': uuid_root, 'size': '1'}, + {'num': 1, 'label':'STATE', 'type': uuid_state, 'size': '1M'}, + ] + + for part in required_parts: + size_str = part['size'] + if 'M' in size_str: + size = int(size_str[:-1]) * sect_1mb + else: + size = int(size_str) + utils.run_and_log_no_ubman( + log, + f"cgpt add -i {part['num']} -b {ptr} -s {size} -t {part['type']} {fname}") + ptr += size + + utils.run_and_log_no_ubman(log, f'cgpt boot -p {fname}') + out = utils.run_and_log_no_ubman(log, f'cgpt show -q {fname}') + + # We expect something like this: + # 8239 2048 1 Basic data + # 45 2048 2 ChromeOS kernel + # 8238 1 3 ChromeOS rootfs + # 2093 2048 4 ChromeOS kernel + # 8237 1 5 ChromeOS rootfs + # 41 1 6 ChromeOS kernel + # 42 1 7 ChromeOS rootfs + # 4141 2048 8 Basic data + # 43 1 9 ChromeOS reserved + # 44 1 10 ChromeOS reserved + # 40 1 11 ChromeOS firmware + # 6189 2048 12 EFI System Partition + + # Create a dict (indexed by partition number) containing the above info + for line in out.splitlines(): + start, size, num, name = line.split(maxsplit=3) + parts[int(num)] = Partition(int(start), int(size), name) + + # Set up the kernel command-line + dummy = os.path.join(config.result_dir, 'dummy.txt') + with open(dummy, 'wb') as outf: + outf.write(b'BOOT_IMAGE=/vmlinuz-5.15.0-121-generic root=/dev/nvme0n1p1 ro quiet splash vt.handoff=7') + + # For now we just use dummy kernels. This limits testing to just detecting + # a signed kernel. We could add support for the x86 data structures so that + # testing could cover getting the cmdline, setup.bin and other pieces. + kern = os.path.join(config.result_dir, 'kern.bin') + with open(kern, 'wb') as outf: + outf.write(b'kernel\n') + + with open(fname, 'rb') as inf: + disk_data = inf.read() + + # put x86 kernel in partition 2 and arm one in partition 4 + set_part_data(2, pack_kernel(config, log, 'x86', kern, dummy)) + set_part_data(4, pack_kernel(config, log, 'arm', kern, dummy)) + + with open(fname, 'wb') as outf: + outf.write(disk_data) + + return fname \ No newline at end of file diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 1a868548b92..36155c76257 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -22,152 +22,9 @@ from img.common import mkdir_cond, copy_partition, setup_extlinux_image from img.fedora import setup_fedora_image from img.ubuntu import setup_ubuntu_image from img.armbian import setup_bootmenu_image +from img.chromeos import setup_cros_image -def setup_cros_image(config, log): - """Create a 20MB disk image with ChromiumOS partitions - - Args: - config (ArbitraryAttributeContainer): Configuration - log (multiplexed_log.Logfile): Log to write to - """ - Partition = collections.namedtuple('part', 'start,size,name') - parts = {} - disk_data = None - - def pack_kernel(config, log, arch, kern, dummy): - """Pack a kernel containing some fake data - - Args: - config (ArbitraryAttributeContainer): Configuration - log (multiplexed_log.Logfile): Log to write to - arch (str): Architecture to use ('x86' or 'arm') - kern (str): Filename containing kernel - dummy (str): Dummy filename to use for config and bootloader - - Return: - bytes: Packed-kernel data - """ - kern_part = os.path.join(config.result_dir, f'kern-part-{arch}.bin') - utils.run_and_log_no_ubman( - log, - f'futility vbutil_kernel --pack {kern_part} ' - '--keyblock doc/chromium/files/devkeys/kernel.keyblock ' - '--signprivate doc/chromium/files/devkeys/kernel_data_key.vbprivk ' - f'--version 1 --config {dummy} --bootloader {dummy} ' - f'--vmlinuz {kern}') - - with open(kern_part, 'rb') as inf: - kern_part_data = inf.read() - return kern_part_data - - def set_part_data(partnum, data): - """Set the contents of a disk partition - - This updates disk_data by putting data in the right place - - Args: - partnum (int): Partition number to set - data (bytes): Data for that partition - """ - nonlocal disk_data - - start = parts[partnum].start * sect_size - disk_data = disk_data[:start] + data + disk_data[start + len(data):] - - mmc_dev = 5 - fname = os.path.join(config.source_dir, f'mmc{mmc_dev}.img') - utils.run_and_log_no_ubman(log, f'qemu-img create {fname} 20M') - utils.run_and_log_no_ubman(log, f'cgpt create {fname}') - - uuid_state = 'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7' - uuid_kern = 'fe3a2a5d-4f32-41a7-b725-accc3285a309' - uuid_root = '3cb8e202-3b7e-47dd-8a3c-7ff2a13cfcec' - uuid_rwfw = 'cab6e88e-abf3-4102-a07a-d4bb9be3c1d3' - uuid_reserved = '2e0a753d-9e48-43b0-8337-b15192cb1b5e' - uuid_efi = 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b' - - ptr = 40 - - # Number of sectors in 1MB - sect_size = 512 - sect_1mb = (1 << 20) // sect_size - - required_parts = [ - {'num': 0xb, 'label':'RWFW', 'type': uuid_rwfw, 'size': '1'}, - {'num': 6, 'label':'KERN_C', 'type': uuid_kern, 'size': '1'}, - {'num': 7, 'label':'ROOT_C', 'type': uuid_root, 'size': '1'}, - {'num': 9, 'label':'reserved', 'type': uuid_reserved, 'size': '1'}, - {'num': 0xa, 'label':'reserved', 'type': uuid_reserved, 'size': '1'}, - - {'num': 2, 'label':'KERN_A', 'type': uuid_kern, 'size': '1M'}, - {'num': 4, 'label':'KERN_B', 'type': uuid_kern, 'size': '1M'}, - - {'num': 8, 'label':'OEM', 'type': uuid_state, 'size': '1M'}, - {'num': 0xc, 'label':'EFI-SYSTEM', 'type': uuid_efi, 'size': '1M'}, - - {'num': 5, 'label':'ROOT_B', 'type': uuid_root, 'size': '1'}, - {'num': 3, 'label':'ROOT_A', 'type': uuid_root, 'size': '1'}, - {'num': 1, 'label':'STATE', 'type': uuid_state, 'size': '1M'}, - ] - - for part in required_parts: - size_str = part['size'] - if 'M' in size_str: - size = int(size_str[:-1]) * sect_1mb - else: - size = int(size_str) - utils.run_and_log_no_ubman( - log, - f"cgpt add -i {part['num']} -b {ptr} -s {size} -t {part['type']} {fname}") - ptr += size - - utils.run_and_log_no_ubman(log, f'cgpt boot -p {fname}') - out = utils.run_and_log_no_ubman(log, f'cgpt show -q {fname}') - - # We expect something like this: - # 8239 2048 1 Basic data - # 45 2048 2 ChromeOS kernel - # 8238 1 3 ChromeOS rootfs - # 2093 2048 4 ChromeOS kernel - # 8237 1 5 ChromeOS rootfs - # 41 1 6 ChromeOS kernel - # 42 1 7 ChromeOS rootfs - # 4141 2048 8 Basic data - # 43 1 9 ChromeOS reserved - # 44 1 10 ChromeOS reserved - # 40 1 11 ChromeOS firmware - # 6189 2048 12 EFI System Partition - - # Create a dict (indexed by partition number) containing the above info - for line in out.splitlines(): - start, size, num, name = line.split(maxsplit=3) - parts[int(num)] = Partition(int(start), int(size), name) - - # Set up the kernel command-line - dummy = os.path.join(config.result_dir, 'dummy.txt') - with open(dummy, 'wb') as outf: - outf.write(b'BOOT_IMAGE=/vmlinuz-5.15.0-121-generic root=/dev/nvme0n1p1 ro quiet splash vt.handoff=7') - - # For now we just use dummy kernels. This limits testing to just detecting - # a signed kernel. We could add support for the x86 data structures so that - # testing could cover getting the cmdline, setup.bin and other pieces. - kern = os.path.join(config.result_dir, 'kern.bin') - with open(kern, 'wb') as outf: - outf.write(b'kernel\n') - - with open(fname, 'rb') as inf: - disk_data = inf.read() - - # put x86 kernel in partition 2 and arm one in partition 4 - set_part_data(2, pack_kernel(config, log, 'x86', kern, dummy)) - set_part_data(4, pack_kernel(config, log, 'arm', kern, dummy)) - - with open(fname, 'wb') as outf: - outf.write(disk_data) - - return fname - def setup_android_image(config, log): """Create a 20MB disk image with Android partitions -- 2.43.0

From: Simon Glass <sjg@chromium.org> Move setup_android_image() function to its own module. Signed-off-by: Simon Glass <sjg@chromium.org> Co-authored-by: Claude <noreply@anthropic.com> --- test/py/img/android.py | 146 +++++++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 136 +----------------------------------- 2 files changed, 147 insertions(+), 135 deletions(-) create mode 100644 test/py/img/android.py diff --git a/test/py/img/android.py b/test/py/img/android.py new file mode 100644 index 00000000000..44d15fe35a7 --- /dev/null +++ b/test/py/img/android.py @@ -0,0 +1,146 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + +"""Create Android test disk images""" + +import collections +import os + +import utils +from test_android import test_abootimg + + +def setup_android_image(config, log): + """Create a 20MB disk image with Android partitions + + Args: + config (ArbitraryAttributeContainer): Configuration + log (multiplexed_log.Logfile): Log to write to + """ + Partition = collections.namedtuple('part', 'start,size,name') + parts = {} + disk_data = None + + def set_part_data(partnum, data): + """Set the contents of a disk partition + + This updates disk_data by putting data in the right place + + Args: + partnum (int): Partition number to set + data (bytes): Data for that partition + """ + nonlocal disk_data + + start = parts[partnum].start * sect_size + disk_data = disk_data[:start] + data + disk_data[start + len(data):] + + mmc_dev = 7 + fname = os.path.join(config.source_dir, f'mmc{mmc_dev}.img') + utils.run_and_log_no_ubman(log, f'qemu-img create {fname} 20M') + utils.run_and_log_no_ubman(log, f'cgpt create {fname}') + + ptr = 40 + + # Number of sectors in 1MB + sect_size = 512 + sect_1mb = (1 << 20) // sect_size + + required_parts = [ + {'num': 1, 'label':'misc', 'size': '1M'}, + {'num': 2, 'label':'boot_a', 'size': '4M'}, + {'num': 3, 'label':'boot_b', 'size': '4M'}, + {'num': 4, 'label':'vendor_boot_a', 'size': '4M'}, + {'num': 5, 'label':'vendor_boot_b', 'size': '4M'}, + ] + + for part in required_parts: + size_str = part['size'] + if 'M' in size_str: + size = int(size_str[:-1]) * sect_1mb + else: + size = int(size_str) + utils.run_and_log_no_ubman( + log, + f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t basicdata {fname}") + ptr += size + + utils.run_and_log_no_ubman(log, f'cgpt boot -p {fname}') + out = utils.run_and_log_no_ubman(log, f'cgpt show -q {fname}') + + # Create a dict (indexed by partition number) containing the above info + for line in out.splitlines(): + start, size, num, name = line.split(maxsplit=3) + parts[int(num)] = Partition(int(start), int(size), name) + + with open(fname, 'rb') as inf: + disk_data = inf.read() + + test_abootimg.AbootimgTestDiskImage(config, log, 'bootv4.img', + test_abootimg.boot_img_hex) + boot_img = os.path.join(config.result_dir, 'bootv4.img') + with open(boot_img, 'rb') as inf: + set_part_data(2, inf.read()) + + test_abootimg.AbootimgTestDiskImage(config, log, 'vendor_boot.img', + test_abootimg.vboot_img_hex) + vendor_boot_img = os.path.join(config.result_dir, 'vendor_boot.img') + with open(vendor_boot_img, 'rb') as inf: + set_part_data(4, inf.read()) + + with open(fname, 'wb') as outf: + outf.write(disk_data) + + print(f'wrote to {fname}') + + mmc_dev = 8 + fname = os.path.join(config.source_dir, f'mmc{mmc_dev}.img') + utils.run_and_log_no_ubman(log, f'qemu-img create {fname} 20M') + utils.run_and_log_no_ubman(log, f'cgpt create {fname}') + + ptr = 40 + + # Number of sectors in 1MB + sect_size = 512 + sect_1mb = (1 << 20) // sect_size + + required_parts = [ + {'num': 1, 'label':'misc', 'size': '1M'}, + {'num': 2, 'label':'boot_a', 'size': '4M'}, + {'num': 3, 'label':'boot_b', 'size': '4M'}, + ] + + for part in required_parts: + size_str = part['size'] + if 'M' in size_str: + size = int(size_str[:-1]) * sect_1mb + else: + size = int(size_str) + utils.run_and_log_no_ubman( + log, + f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t basicdata {fname}") + ptr += size + + utils.run_and_log_no_ubman(log, f'cgpt boot -p {fname}') + out = utils.run_and_log_no_ubman(log, f'cgpt show -q {fname}') + + # Create a dict (indexed by partition number) containing the above info + for line in out.splitlines(): + start, size, num, name = line.split(maxsplit=3) + parts[int(num)] = Partition(int(start), int(size), name) + + with open(fname, 'rb') as inf: + disk_data = inf.read() + + test_abootimg.AbootimgTestDiskImage(config, log, 'boot.img', + test_abootimg.img_hex) + boot_img = os.path.join(config.result_dir, 'boot.img') + with open(boot_img, 'rb') as inf: + set_part_data(2, inf.read()) + + with open(fname, 'wb') as outf: + outf.write(disk_data) + + print(f'wrote to {fname}') + + return fname \ No newline at end of file diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 36155c76257..d548bae4bd0 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -23,143 +23,9 @@ from img.fedora import setup_fedora_image from img.ubuntu import setup_ubuntu_image from img.armbian import setup_bootmenu_image from img.chromeos import setup_cros_image +from img.android import setup_android_image -def setup_android_image(config, log): - """Create a 20MB disk image with Android partitions - - Args: - config (ArbitraryAttributeContainer): Configuration - log (multiplexed_log.Logfile): Log to write to - """ - Partition = collections.namedtuple('part', 'start,size,name') - parts = {} - disk_data = None - - def set_part_data(partnum, data): - """Set the contents of a disk partition - - This updates disk_data by putting data in the right place - - Args: - partnum (int): Partition number to set - data (bytes): Data for that partition - """ - nonlocal disk_data - - start = parts[partnum].start * sect_size - disk_data = disk_data[:start] + data + disk_data[start + len(data):] - - mmc_dev = 7 - fname = os.path.join(config.source_dir, f'mmc{mmc_dev}.img') - utils.run_and_log_no_ubman(log, f'qemu-img create {fname} 20M') - utils.run_and_log_no_ubman(log, f'cgpt create {fname}') - - ptr = 40 - - # Number of sectors in 1MB - sect_size = 512 - sect_1mb = (1 << 20) // sect_size - - required_parts = [ - {'num': 1, 'label':'misc', 'size': '1M'}, - {'num': 2, 'label':'boot_a', 'size': '4M'}, - {'num': 3, 'label':'boot_b', 'size': '4M'}, - {'num': 4, 'label':'vendor_boot_a', 'size': '4M'}, - {'num': 5, 'label':'vendor_boot_b', 'size': '4M'}, - ] - - for part in required_parts: - size_str = part['size'] - if 'M' in size_str: - size = int(size_str[:-1]) * sect_1mb - else: - size = int(size_str) - utils.run_and_log_no_ubman( - log, - f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t basicdata {fname}") - ptr += size - - utils.run_and_log_no_ubman(log, f'cgpt boot -p {fname}') - out = utils.run_and_log_no_ubman(log, f'cgpt show -q {fname}') - - # Create a dict (indexed by partition number) containing the above info - for line in out.splitlines(): - start, size, num, name = line.split(maxsplit=3) - parts[int(num)] = Partition(int(start), int(size), name) - - with open(fname, 'rb') as inf: - disk_data = inf.read() - - test_abootimg.AbootimgTestDiskImage(config, log, 'bootv4.img', - test_abootimg.boot_img_hex) - boot_img = os.path.join(config.result_dir, 'bootv4.img') - with open(boot_img, 'rb') as inf: - set_part_data(2, inf.read()) - - test_abootimg.AbootimgTestDiskImage(config, log, 'vendor_boot.img', - test_abootimg.vboot_img_hex) - vendor_boot_img = os.path.join(config.result_dir, 'vendor_boot.img') - with open(vendor_boot_img, 'rb') as inf: - set_part_data(4, inf.read()) - - with open(fname, 'wb') as outf: - outf.write(disk_data) - - print(f'wrote to {fname}') - - mmc_dev = 8 - fname = os.path.join(config.source_dir, f'mmc{mmc_dev}.img') - utils.run_and_log_no_ubman(log, f'qemu-img create {fname} 20M') - utils.run_and_log_no_ubman(log, f'cgpt create {fname}') - - ptr = 40 - - # Number of sectors in 1MB - sect_size = 512 - sect_1mb = (1 << 20) // sect_size - - required_parts = [ - {'num': 1, 'label':'misc', 'size': '1M'}, - {'num': 2, 'label':'boot_a', 'size': '4M'}, - {'num': 3, 'label':'boot_b', 'size': '4M'}, - ] - - for part in required_parts: - size_str = part['size'] - if 'M' in size_str: - size = int(size_str[:-1]) * sect_1mb - else: - size = int(size_str) - utils.run_and_log_no_ubman( - log, - f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t basicdata {fname}") - ptr += size - - utils.run_and_log_no_ubman(log, f'cgpt boot -p {fname}') - out = utils.run_and_log_no_ubman(log, f'cgpt show -q {fname}') - - # Create a dict (indexed by partition number) containing the above info - for line in out.splitlines(): - start, size, num, name = line.split(maxsplit=3) - parts[int(num)] = Partition(int(start), int(size), name) - - with open(fname, 'rb') as inf: - disk_data = inf.read() - - test_abootimg.AbootimgTestDiskImage(config, log, 'boot.img', - test_abootimg.img_hex) - boot_img = os.path.join(config.result_dir, 'boot.img') - with open(boot_img, 'rb') as inf: - set_part_data(2, inf.read()) - - with open(fname, 'wb') as outf: - outf.write(disk_data) - - print(f'wrote to {fname}') - - return fname - def setup_cedit_file(config, log): """Set up a .dtb file for use with testing expo and configuration editor -- 2.43.0

From: Simon Glass <sjg@chromium.org> Move setup_efi_image() to its own module. Signed-off-by: Simon Glass <sjg@chromium.org> Co-authored-by: Claude <noreply@anthropic.com> --- test/py/img/efi.py | 37 +++++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 29 +---------------------------- 2 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 test/py/img/efi.py diff --git a/test/py/img/efi.py b/test/py/img/efi.py new file mode 100644 index 00000000000..fbb39c24063 --- /dev/null +++ b/test/py/img/efi.py @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + +"""Create EFI test disk images""" + +import os + +from fs_helper import DiskHelper, FsHelper +from img.common import mkdir_cond + + +def setup_efi_image(config): + """Create a 20MB disk image with an EFI app on it + + Args: + config (ArbitraryAttributeContainer): Configuration + """ + devnum = 1 + fsh = FsHelper(config, 'vfat', 18, 'flash') + fsh.setup() + efi_dir = os.path.join(fsh.srcdir, 'EFI') + mkdir_cond(efi_dir) + bootdir = os.path.join(efi_dir, 'BOOT') + mkdir_cond(bootdir) + efi_src = os.path.join(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()) + + fsh.mk_fs() + + img = DiskHelper(config, devnum, 'flash', True) + img.add_fs(fsh, DiskHelper.VFAT) + img.create() + fsh.cleanup() \ No newline at end of file diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index d548bae4bd0..bb3417ad761 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -24,6 +24,7 @@ from img.ubuntu import setup_ubuntu_image from img.armbian import setup_bootmenu_image from img.chromeos import setup_cros_image from img.android import setup_android_image +from img.efi import setup_efi_image def setup_cedit_file(config, log): @@ -78,34 +79,6 @@ def test_ut_dm_init(ubman): fh.write(data) -def setup_efi_image(config): - """Create a 20MB disk image with an EFI app on it - - Args: - config (ArbitraryAttributeContainer): Configuration - """ - devnum = 1 - fsh = FsHelper(config, 'vfat', 18, 'flash') - fsh.setup() - efi_dir = os.path.join(fsh.srcdir, 'EFI') - mkdir_cond(efi_dir) - bootdir = os.path.join(efi_dir, 'BOOT') - mkdir_cond(bootdir) - efi_src = os.path.join(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()) - - fsh.mk_fs() - - img = DiskHelper(config, devnum, 'flash', True) - img.add_fs(fsh, DiskHelper.VFAT) - img.create() - fsh.cleanup() - - def setup_localboot_image(config, log): """Create a 20MB disk image with a single FAT partition -- 2.43.0

From: Simon Glass <sjg@chromium.org> Move setup_cedit_file() to its own module. Signed-off-by: Simon Glass <sjg@chromium.org> Co-authored-by: Claude <noreply@anthropic.com> --- test/py/img/cedit.py | 25 +++++++++++++++++++++++++ test/py/tests/test_ut.py | 17 +---------------- 2 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 test/py/img/cedit.py diff --git a/test/py/img/cedit.py b/test/py/img/cedit.py new file mode 100644 index 00000000000..dd6c5de44bb --- /dev/null +++ b/test/py/img/cedit.py @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + +"""Create configuration editor test files""" + +import os + +import utils + + +def setup_cedit_file(config, log): + """Set up a .dtb file for use with testing expo and configuration editor + + Args: + config (ArbitraryAttributeContainer): Configuration + log (multiplexed_log.Logfile): Log to write to + """ + infname = os.path.join(config.source_dir, + 'test/boot/files/expo_layout.dts') + inhname = os.path.join(config.source_dir, + 'test/boot/files/expo_ids.h') + expo_tool = os.path.join(config.source_dir, 'tools/expo.py') + outfname = 'cedit.dtb' + utils.run_and_log_no_ubman( + log, f'{expo_tool} -e {inhname} -l {infname} -o {outfname}') \ No newline at end of file diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index bb3417ad761..ec4ef1862ae 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -25,24 +25,9 @@ from img.armbian import setup_bootmenu_image from img.chromeos import setup_cros_image from img.android import setup_android_image from img.efi import setup_efi_image +from img.cedit import setup_cedit_file -def setup_cedit_file(config, log): - """Set up a .dtb file for use with testing expo and configuration editor - - Args: - config (ArbitraryAttributeContainer): Configuration - log (multiplexed_log.Logfile): Log to write to - """ - infname = os.path.join(config.source_dir, - 'test/boot/files/expo_layout.dts') - inhname = os.path.join(config.source_dir, - 'test/boot/files/expo_ids.h') - expo_tool = os.path.join(config.source_dir, 'tools/expo.py') - outfname = 'cedit.dtb' - utils.run_and_log_no_ubman( - log, f'{expo_tool} -e {inhname} -l {infname} -o {outfname}') - @pytest.mark.buildconfigspec('ut_dm') def test_ut_dm_init(ubman): """Initialize data for ut dm tests.""" -- 2.43.0

From: Simon Glass <sjg@chromium.org> Move setup_localboot_image() to a new module Signed-off-by: Simon Glass <sjg@chromium.org> Co-authored-by: Claude <noreply@anthropic.com> --- test/py/img/localboot.py | 27 +++++++++++++++++++++++++++ test/py/tests/test_ut.py | 22 +--------------------- 2 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 test/py/img/localboot.py diff --git a/test/py/img/localboot.py b/test/py/img/localboot.py new file mode 100644 index 00000000000..62a65f33cf0 --- /dev/null +++ b/test/py/img/localboot.py @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + +"""Create localboot test disk images""" + +from img.common import setup_extlinux_image + + +def setup_localboot_image(config, log): + """Create a 20MB disk image with a single FAT partition + + Args: + config (ArbitraryAttributeContainer): Configuration + log (multiplexed_log.Logfile): Log to write to + """ + mmc_dev = 9 + + script = '''DEFAULT local + +LABEL local + SAY Doing local boot... + LOCALBOOT 0 +''' + vmlinux = 'vmlinuz' + initrd = 'initrd.img' + setup_extlinux_image(config, log, mmc_dev, 'mmc', vmlinux, initrd, None, + script) \ No newline at end of file diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index ec4ef1862ae..0acc40ae6aa 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -26,6 +26,7 @@ from img.chromeos import setup_cros_image from img.android import setup_android_image from img.efi import setup_efi_image from img.cedit import setup_cedit_file +from img.localboot import setup_localboot_image @pytest.mark.buildconfigspec('ut_dm') @@ -64,27 +65,6 @@ def test_ut_dm_init(ubman): fh.write(data) -def setup_localboot_image(config, log): - """Create a 20MB disk image with a single FAT partition - - Args: - config (ArbitraryAttributeContainer): Configuration - log (multiplexed_log.Logfile): Log to write to - """ - mmc_dev = 9 - - script = '''DEFAULT local - -LABEL local - SAY Doing local boot... - LOCALBOOT 0 -''' - vmlinux = 'vmlinuz' - initrd = 'initrd.img' - setup_extlinux_image(config, log, mmc_dev, 'mmc', vmlinux, initrd, None, - script) - - @pytest.mark.buildconfigspec('cmd_bootflow') @pytest.mark.buildconfigspec('sandbox') def test_ut_dm_init_bootstd(u_boot_config, u_boot_log): -- 2.43.0
participants (1)
-
Simon Glass