From d985f1dbddb241c21a9150abf59dd386ba1ffe05 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 6 Jan 2023 08:52:41 -0600 Subject: [PATCH] bootstd: Add a test for the bootstd menu 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 --- 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 dffe10adbf..2e580f980f 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 6921c5667d..faa3a944c0 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 00dfd99068..abafa44b2e 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -11,15 +11,21 @@ #include #include #include +#include #include #ifdef CONFIG_SANDBOX #include #endif +#include #include #include #include #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@J6u_+aW`8~-8B2G301rYP}LjG-Uj!5v5M@cMEp)w7Jy+>!JE+yYjbr*Cj;GV^2Hw z@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;`ilv|L2QbW*>IAi?Ac$V1;eoHwRcj6<3Yj~Om#>)(xD*U9^*iF z(_&Bn;ATGLy(x8wegW)L3qq6kQv=_3Z zx*?Kp$;0{#iDe|0~1!@^T z)sbCy$vmaHvbwE}%8WHO)D1ZmGr2!sS+OWbZF=;oH_jv+}huqHA-6Xk^mvDd5M z(nV_bZUl6s z0M21Xax4^PqqUQB_#oh0zKUmjc`-*=$Yu=#ARfS%t8K^XZk83$pxE{bst#FcVg*`V z50vnrqts+Y9yvx&WN-3m0S*!nB~!7YuX!%)BKGIjHybq_@N8&zRFA>YNjS{Vc4FH4 qtaYK=i8dCo!_rs)w`$8ednHYvC;uhGXMY=J=Xxn0k8v^0002R zICSLp_5uFxGXTI1d#!1VGNTr`mE;p*%0&LKnku_|*GGQJP@UYW>mQ)!S^JbvQYkY( z46W26RjbZTot!9{G(@Wx*b0~aDkttKa_KAZeVurk05wnjsJ_IcR{H{__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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%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.5