From: Frieder Schrempf <[email protected]>

Set CONFIG_BOOTMETH_RAUC_PART_NAMES on sandbox and give the
partitions of the RAUC test image (mmc10) matching names. As only GPT
has partition names, DiskHelper now creates the image with GPT instead
of MBR. The existing test passes with or without the option, as the
names match.

Add a second image (mmc13) with the same layout but other names, and
a test that the RAUC bootmeth finds no bootflow on it. The test is
skipped if the option is empty. It needs an #ifdef, since the string
option does not exist without BOOTMETH_RAUC and IS_ENABLED() cannot
check a string.

Assisted-by: LLM
Signed-off-by: Frieder Schrempf <[email protected]>
---
 arch/sandbox/dts/test.dts |  8 ++++++++
 configs/sandbox_defconfig |  1 +
 test/boot/bootflow.c      | 27 +++++++++++++++++++++++++++
 test/py/tests/test_ut.py  | 26 +++++++++++++++++---------
 4 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 02a9ca29b79..c64769c543f 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -51,6 +51,7 @@
                mmc10 = "/mmc10";
                mmc11 = "/mmc11";
                mmc12 = "/mmc12";
+               mmc13 = "/mmc13";
                pci0 = &pci0;
                pci1 = &pci1;
                pci2 = &pci2;
@@ -1406,6 +1407,13 @@
                filename = "mmc12.img";
        };
 
+       /* This is used for RAUC boot tests, with other partition names */
+       mmc13 {
+               status = "disabled";
+               compatible = "sandbox,mmc";
+               filename = "mmc13.img";
+       };
+
        pch {
                compatible = "sandbox,pch";
        };
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index a3fa5246082..b952622b403 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -28,6 +28,7 @@ CONFIG_FIT_VERBOSE=y
 CONFIG_BOOTMETH_ANDROID=y
 CONFIG_BOOTMETH_BLS=y
 CONFIG_BOOTMETH_RAUC=y
+CONFIG_BOOTMETH_RAUC_PART_NAMES="boot_a,root_a boot_b,root_b"
 CONFIG_UPL=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_MEASURED_BOOT=y
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index d2d4edb0add..e0a3c8a28b1 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -1824,6 +1824,33 @@ static int bootflow_bls_prefix(struct unit_test_state 
*uts)
 }
 BOOTSTD_TEST(bootflow_bls_prefix, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT);
 
+static int bootflow_rauc_part_names_check(struct unit_test_state *uts)
+{
+       ut_assertok(run_command("bootflow scan", 0));
+       ut_assert_nextline("No bootflows found; try again with -l");
+       ut_assert_console_end();
+
+       ut_assertok(run_command("bootflow list", 0));
+       ut_assert_skip_to_line("(0 bootflows, 0 valid)");
+       ut_assert_console_end();
+
+       return 0;
+}
+
+/* Test that the RAUC bootmeth ignores a device with other partition names */
+static int bootflow_rauc_part_names(struct unit_test_state *uts)
+{
+       if (!CONFIG_IS_ENABLED(BOOTMETH_RAUC))
+               return -EAGAIN;
+#ifdef CONFIG_BOOTMETH_RAUC_PART_NAMES
+       if (!CONFIG_BOOTMETH_RAUC_PART_NAMES[0])
+               return -EAGAIN;
+#endif
+
+       return bootflow_rauc_run(uts, "mmc13", bootflow_rauc_part_names_check);
+}
+BOOTSTD_TEST(bootflow_rauc_part_names, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT);
+
 /* Check 'bootflow scan' provides a list of images */
 static int bootstd_images(struct unit_test_state *uts)
 {
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index a33f188d984..a1a00c5a716 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -583,10 +583,15 @@ def setup_efi_image(ubman):
     fsh.cleanup()
 
 
-def setup_rauc_image(ubman):
-    """Create a 40MB disk image with an A/B RAUC system on it"""
-    mmc_dev = 10
+def setup_rauc_image(ubman, mmc_dev, part_names):
+    """Create a disk image with an A/B RAUC system on it
 
+    Args:
+        ubman (ConsoleBase): Console to use
+        mmc_dev (int): MMC device number, e.g. 10
+        part_names (tuple of str): GPT names of the boot A, root A, boot B
+            and root B partitions
+    """
     boot = FsHelper(ubman.config, 'fat32', 8, 'rauc_boot')
     boot.setup()
 
@@ -606,11 +611,12 @@ def setup_rauc_image(ubman):
     root = FsHelper(ubman.config, 'ext4', 10, 'rauc_root')
     root.mk_fs()
 
-    img = DiskHelper(ubman.config, mmc_dev, 'mmc', True)
-    img.add_fs(boot, DiskHelper.VFAT, bootable=True)
-    img.add_fs(root, DiskHelper.EXT4)
-    img.add_fs(boot, DiskHelper.VFAT, bootable=True)
-    img.add_fs(root, DiskHelper.EXT4)
+    boot_a, root_a, boot_b, root_b = part_names
+    img = DiskHelper(ubman.config, mmc_dev, 'mmc', True, gpt=True)
+    img.add_fs(boot, DiskHelper.VFAT, bootable=True, name=boot_a)
+    img.add_fs(root, DiskHelper.EXT4, name=root_a)
+    img.add_fs(boot, DiskHelper.VFAT, bootable=True, name=boot_b)
+    img.add_fs(root, DiskHelper.EXT4, name=root_b)
     img.create()
     boot.cleanup()
     root.cleanup()
@@ -626,7 +632,9 @@ def test_ut_dm_init_bootstd(ubman):
     setup_cros_image(ubman)
     setup_android_image(ubman)
     setup_efi_image(ubman)
-    setup_rauc_image(ubman)
+    # The names of mmc10 match CONFIG_BOOTMETH_RAUC_PART_NAMES in sandbox
+    setup_rauc_image(ubman, 10, ('boot_a', 'root_a', 'boot_b', 'root_b'))
+    setup_rauc_image(ubman, 13, ('boot', 'rootfs', 'boot2', 'rootfs2'))
     setup_bls_prefix_image(ubman)
 
     # Restart so that the new mmc1.img is picked up

-- 
2.56.0

Reply via email to