
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