[PATCH v3 23/25] bootstd: Add a test for the bootstd menu

Simon Glass sjg at chromium.org
Fri Jan 6 15:52:41 CET 2023


Add a test which checks that two operating systems can be displayed in a
menu, allowing one to be selected.

Enable a few things on snow so that the unit tests build.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v2)

Changes in v2:
- Fix 'touse' typo
- Fix pylint warning in mkdir_cond()

 arch/sandbox/dts/test.dts            |  11 ++
 configs/snow_defconfig               |   4 +
 test/boot/bootflow.c                 |  51 +++++++
 test/py/tests/bootstd/armbian.bmp.xz | Bin 0 -> 1384 bytes
 test/py/tests/bootstd/mmc4.img.xz    | Bin 0 -> 7072 bytes
 test/py/tests/test_ut.py             | 218 ++++++++++++++++++++++++---
 6 files changed, 265 insertions(+), 19 deletions(-)
 create mode 100644 test/py/tests/bootstd/armbian.bmp.xz
 create mode 100644 test/py/tests/bootstd/mmc4.img.xz

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index dffe10adbf4..2e580f980fc 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -94,6 +94,10 @@
 			compatible = "u-boot,distro-efi";
 		};
 
+		theme {
+			font-size = <30>;
+		};
+
 		/*
 		 * This is used for the VBE OS-request tests. A FAT filesystem
 		 * created in a partition with the VBE information appearing
@@ -1013,6 +1017,13 @@
 		non-removable;
 	};
 
+	/* This is used for bootstd bootmenu tests */
+	mmc4 {
+		status = "disabled";
+		compatible = "sandbox,mmc";
+		filename = "mmc4.img";
+	};
+
 	pch {
 		compatible = "sandbox,pch";
 	};
diff --git a/configs/snow_defconfig b/configs/snow_defconfig
index 6921c5667da..faa3a944c02 100644
--- a/configs/snow_defconfig
+++ b/configs/snow_defconfig
@@ -28,7 +28,11 @@ CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
 CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x2050000
 CONFIG_FIT=y
 CONFIG_FIT_BEST_MATCH=y
+CONFIG_BOOTSTD_FULL=y
 CONFIG_SILENT_CONSOLE=y
+CONFIG_BLOBLIST=y
+# CONFIG_SPL_BLOBLIST is not set
+CONFIG_BLOBLIST_ADDR=0x43d00000
 # CONFIG_SPL_FRAMEWORK is not set
 CONFIG_SPL_FOOTPRINT_LIMIT=y
 CONFIG_SPL_MAX_FOOTPRINT=0x3800
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 00dfd990687..abafa44b2ed 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -11,15 +11,21 @@
 #include <bootflow.h>
 #include <bootmeth.h>
 #include <bootstd.h>
+#include <cli.h>
 #include <dm.h>
 #ifdef CONFIG_SANDBOX
 #include <asm/test.h>
 #endif
+#include <dm/device-internal.h>
 #include <dm/lists.h>
 #include <test/suites.h>
 #include <test/ut.h>
 #include "bootstd_common.h"
 
+DECLARE_GLOBAL_DATA_PTR;
+
+extern U_BOOT_DRIVER(bootmeth_script);
+
 static int inject_response(struct unit_test_state *uts)
 {
 	/*
@@ -462,3 +468,48 @@ static int bootflow_cmd_boot(struct unit_test_state *uts)
 	return 0;
 }
 BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+
+/* Check 'bootflow menu' to select a bootflow */
+static int bootflow_cmd_menu(struct unit_test_state *uts)
+{
+	static const char *order[] = {"mmc2", "mmc1", "mmc4", NULL};
+	struct udevice *dev, *bootstd;
+	struct bootstd_priv *std;
+	const char **old_order;
+	char prev[3];
+	ofnode node;
+
+	/* Enable the mmc4 node since we need a second bootflow */
+	node = ofnode_path("/mmc4");
+	ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
+
+	/* Enable the script bootmeth too */
+	ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
+	ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_script),
+				"bootmeth_script", 0, ofnode_null(), &dev));
+
+	/* Change the order to include mmc4 */
+	std = dev_get_priv(bootstd);
+	old_order = std->bootdev_order;
+	std->bootdev_order = order;
+
+	console_record_reset_enable();
+	ut_assertok(run_command("bootflow scan", 0));
+	ut_assert_console_end();
+
+	/* Restore the order used by the device tree */
+	std->bootdev_order = old_order;
+
+	/* Add keypresses to move to and select the second one in the list */
+	prev[0] = CTL_CH('n');
+	prev[1] = '\r';
+	prev[2] = '\0';
+	ut_asserteq(2, console_in_puts(prev));
+
+	ut_assertok(run_command("bootflow menu", 0));
+	ut_assert_nextline("Selected: Armbian");
+	ut_assert_console_end();
+
+	return 0;
+}
+BOOTSTD_TEST(bootflow_cmd_menu, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
diff --git a/test/py/tests/bootstd/armbian.bmp.xz b/test/py/tests/bootstd/armbian.bmp.xz
new file mode 100644
index 0000000000000000000000000000000000000000..ad137ea6e6df5c51d0a98a4be190c4cb4c48fc76
GIT binary patch
literal 1384
zcmV-u1(*8$H+ooF000E$*0e?f03iV!0000G&sfahT|osUT>v2yL`vV4GWns~_Xm1L
zxE>Ubk at J6u_+aW`8~-8B2<e|Au4!68N=d*)`gT$sdsQ6~IO}ImLOcgScjC#+Pwg7i
z%N{PxBxSeP-e!(>G301rYP}LjG-Uj!5v5M at cMEp)w7Jy+>!JE+yYjbr*Cj;GV^2Hw
z at W7BuO=bDneVey~z?{IPxUWVi=>AB+fXkNrMXePTCtS4$20)TF&Ej-}em=4#*uIHD
z1l@)}!B8#S*Y2}K?!cbS0x0Q6+%GVl9r84w9-r^ww#S)^#5L%?tS_gQGFqN4x0;M*
z069Xd{Tg$MBJXPB3ZuxY@@+^>NZzLHs%(t8LBUGbn8_tB+-cv$3n422Xoz1d8hrHM
z(HW_#2QB54kA#LC*EWh*<^|;Iq{oeo2`LwHJ&s-Um&v;`i<Hh_{uQ<aDpBW%)4f3j
z%htcy{*A=zeeIUWny<X_ityCve&sL(46xV?51|w+KZF*%Bj?&`#$%GmZ)*@=?t?-!
zaURO*dr)zuJYIVQADTWr5l1b}?i2otPY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ko|ce>V_bZUl6s
z0M21Xax4^PqqUQB_#oh0zKUmjc`-*=$Yu=#ARfS%t8K^XZk83$pxE{bst#FcVg*`V
z50vnrqts+Y9yvx&WN-3m0S*!nB~!7YuX!%)BKGIjHybq_ at N8&zRFA>YNjS{Vc4FH4
qta<tX0000nxT(en3ebcA0l^Bwx&Z)ZZO2}*#Ao{g000001X)^sXQz_@

literal 0
HcmV?d00001

diff --git a/test/py/tests/bootstd/mmc4.img.xz b/test/py/tests/bootstd/mmc4.img.xz
new file mode 100644
index 0000000000000000000000000000000000000000..f4db011969fa8bea352ee2b8318dfdd72ccf72d8
GIT binary patch
literal 7072
zcmeHMXHXPemhDEeB*{$<O3qP00SQfRGB!aPP%@H(AV?6T$yrcB10Ol3mYf?TXAlq(
z5SpApY at lIgYWK%h?T>YK=i8dCo!_rs)w`$8ednHYvC;uhGXMY=J=Xxn0k8v^0002R
zICSLp_5uFxGXTI1d#!1VGNTr`mE;p*%0&LKnku_|*GGQJP at UYW>mQ)!S^JbvQYkY(
z46W26RjbZTot!9{G(@Wx*b0~aDkttKa_KAZeVurk05wnjsJ_IcR{H{__QF(ucVN)d
z-lkL|MungQ%rzK*PZ?3resA^mSYFFcDUpiomLlbs$1BrccSmp2c);YP*MZAdA4P;r
zx)LHz--dSCq8=FjI!}@k#Vf2iaO-y0Q6rg5x>r_d#oRJh%S~@#`fl6K0NSzbTVcAs
zVU9<L`Mg+pePzJ!J<4LvriA%s`1lv^3nICYVLq4dNVy|ayAZ65TweLbm%fY>|8&%T
zehHBty>Ke+c_zbISABGfV`}TDd7fk`WnO^o*aJOcQsyS>S(b6*O&6LGScxq-nbF&l
z*qMRP8MmRcj(#7Av-nQP<^Upc`t<1=?K~Rt2J!%<2ZDf`%-k at -T&=+>XQBar-B(1t
zIWn5YMc0ek at OGsbLxJFV9r0XZj~xB>g{ATEQ_?k_0UO039vtE!mUDLlehppJo8dgN
z_#G_I+Il8h88;u0 at txv$alb}7m5QSvYx_x at TO6VHAEUJN{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p8Pt at md*
z-v1*=Vn#Q{|7H;deg`<vBtSW+4!U3#`M;4F{F5RG8J-#Vm#O}1mjAom{col^8z}Kx
z6#LKF(VxqM+ at Np;I%tQ0{c>=rb(`3Fy276vh5ddx3j at Crga1XfzmsYqghl{7Kzq!n
pcF<o}Z2;3}KI-mavEBe6Mk*vEgcwDdLRgEkzry+3A+D*}UjQf@%fJ8t

literal 0
HcmV?d00001

diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index bab8b97672b..6958fabfa34 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
 
+import getpass
 import gzip
 import os
 import os.path
@@ -13,34 +14,217 @@ def mkdir_cond(dirname):
     """Create a directory if it doesn't already exist
 
     Args:
-        dirname: Name of directory to create
+        dirname (str): Name of directory to create
     """
     if not os.path.exists(dirname):
         os.mkdir(dirname)
 
-def setup_bootflow_image(u_boot_console):
-    """Create a 20MB disk image with a single FAT partition"""
-    cons = u_boot_console
-    fname = os.path.join(cons.config.source_dir, 'mmc1.img')
+def setup_image(cons, mmc_dev, part_type):
+    """Create a 20MB disk image with a single partition
+
+    Args:
+        cons (ConsoleBase): Console to use
+        mmc_dev (int): MMC device number to use, e.g. 1
+        part_type (int): Partition type, e.g. 0xc for FAT32
+
+    Returns:
+        tuple:
+            str: Filename of MMC image
+            str: Directory name of 'mnt' directory
+    """
+    fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img')
     mnt = os.path.join(cons.config.persistent_data_dir, 'mnt')
     mkdir_cond(mnt)
 
     u_boot_utils.run_and_log(cons, 'qemu-img create %s 20M' % fname)
     u_boot_utils.run_and_log(cons, 'sudo sfdisk %s' % fname,
-                             stdin=b'type=c')
+                             stdin=f'type={part_type:x}'.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, 'sudo losetup --show -f -P %s' % 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 += ' -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, mmc_dev, fname):
+    """Use a prepared image since we cannot create one
+
+    Args:
+        cons (ConsoleBase): Console touse
+        mmc_dev (int): MMC device number
+        fname (str): Filename of MMC image
+    """
+    infname = os.path.join(cons.config.source_dir,
+                           f'test/py/tests/bootstd/mmc{mmc_dev}.img.xz')
+    u_boot_utils.run_and_log(
+        cons,
+        ['sh', '-c', 'xz -dc %s >%s' % (infname, fname)])
+
+def setup_bootmenu_image(cons):
+    """Create a 20MB disk image with a single ext4 partition
+
+    This is modelled on Armbian 22.08 Jammy
+    """
+    mmc_dev = 4
+    fname, mnt = setup_image(cons, mmc_dev, 0x83)
 
     loop = None
     mounted = False
     complete = False
     try:
-        out = u_boot_utils.run_and_log(cons,
-                                       'sudo losetup --show -f -P %s' % fname)
-        loop = out.strip()
-        fatpart = '%sp1' % loop
-        u_boot_utils.run_and_log(cons, 'sudo mkfs.vfat %s' % fatpart)
+        loop = mount_image(cons, fname, mnt, 'ext4')
+        mounted = True
+
+        vmlinux = 'Image'
+        initrd = 'uInitrd'
+        dtbdir = 'dtb'
+        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
+''' % (mmc_dev)
+        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') 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}'])
+
+        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)
+
+        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)
+
         u_boot_utils.run_and_log(
-            cons, 'sudo mount -o loop %s %s -o uid=%d,gid=%d' %
-            (fatpart, mnt, os.getuid(), os.getgid()))
+            cons, f'mkimage -C none -A arm -T script -d {cmd_fname} {scr_fname}')
+        complete = True
+
+    except ValueError as exc:
+        print('Falled to create image, failing back to prepared copy: %s',
+              str(exc))
+    finally:
+        if mounted:
+            u_boot_utils.run_and_log(cons, 'sudo umount %s' % mnt)
+        if loop:
+            u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
+
+    if not complete:
+        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)
+
+    loop = None
+    mounted = False
+    complete = False
+    try:
+        loop = mount_image(cons, fname, mnt, 'vfat')
         mounted = True
 
         vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl'
@@ -90,12 +274,7 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
             u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
 
     if not complete:
-        # Use a prepared image since we cannot create one
-        infname = os.path.join(cons.config.source_dir,
-                               'test/py/tests/bootstd/mmc1.img.xz')
-        u_boot_utils.run_and_log(
-            cons,
-            ['sh', '-c', 'xz -dc %s >%s' % (infname, fname)])
+        copy_prepared_image(cons, mmc_dev, fname)
 
 
 @pytest.mark.buildconfigspec('ut_dm')
@@ -134,6 +313,7 @@ def test_ut_dm_init_bootstd(u_boot_console):
     """Initialise data for bootflow tests"""
 
     setup_bootflow_image(u_boot_console)
+    setup_bootmenu_image(u_boot_console)
 
     # Restart so that the new mmc1.img is picked up
     u_boot_console.restart_uboot()
-- 
2.39.0.314.g84b9a713c41-goog



More information about the U-Boot mailing list