From: Frieder Schrempf <[email protected]> Set CONFIG_BOOTMETH_RAUC_BOOTCMD on sandbox to run a test variable, and add a test that boots the RAUC bootflow on mmc10 with it. It checks that the command sees the slot's partitions and raucargs, that slot B is booted once slot A has no tries left, and that a failing command uses up a try.
Booting saves the environment, which sandbox keeps nowhere by default. Set CONFIG_ENV_FAT_DEVICE_AND_PART to the first partition of mmc10, which has a FAT filesystem, and select it during the test. No other test uses the FAT environment. The test is skipped unless the command is the one it sets up. As with the partition name test, this needs an #ifdef, since the string option does not exist without BOOTMETH_RAUC. Assisted-by: LLM Signed-off-by: Frieder Schrempf <[email protected]> --- configs/sandbox_defconfig | 2 ++ test/boot/bootflow.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index b952622b403..a79012b5a21 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -29,6 +29,7 @@ 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_BOOTMETH_RAUC_BOOTCMD="run rauc_test_boot" CONFIG_UPL=y CONFIG_LEGACY_IMAGE_FORMAT=y CONFIG_MEASURED_BOOT=y @@ -167,6 +168,7 @@ CONFIG_ENV_IS_IN_SPI_FLASH=y CONFIG_ENV_SECT_SIZE_AUTO=y CONFIG_ENV_REDUNDANT=y CONFIG_ENV_REDUNDANT_UPGRADE=y +CONFIG_ENV_FAT_DEVICE_AND_PART="a:1" CONFIG_ENV_EXT4_INTERFACE="host" CONFIG_ENV_EXT4_DEVICE_AND_PART="0:0" CONFIG_ENV_IMPORT_FDT=y diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index e0a3c8a28b1..38a6eb66fcc 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -1851,6 +1851,84 @@ static int bootflow_rauc_part_names(struct unit_test_state *uts) } BOOTSTD_TEST(bootflow_rauc_part_names, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT); +/* Scan and boot the RAUC bootflow, which saves the environment first */ +static int bootflow_rauc_boot(struct unit_test_state *uts) +{ + ut_assertok(run_command("bootflow scan", 0)); + ut_assertok(run_command("bootflow select 0", 0)); + ut_asserteq(1, run_command("bootflow boot", 0)); + ut_assert_nextline("** Booting bootflow 'mmc10.bootdev.whole' with rauc"); + ut_assert_nextline("Saving Environment to FAT... OK"); + + return 0; +} + +static int bootflow_rauc_bootcmd_check(struct unit_test_state *uts) +{ + /* Start with the default tries, also when running a second time */ + ut_assertok(env_set("BOOT_A_LEFT", NULL)); + ut_assertok(env_set("BOOT_B_LEFT", NULL)); + ut_assertok(env_set("rauc_test_boot", + "echo rauc boot: ${raucargs} ${distro_bootpart} ${distro_rootpart}")); + + /* The command returns instead of booting, so the boot fails */ + ut_assertok(bootflow_rauc_boot(uts)); + ut_assert_skip_to_line("rauc boot: rauc.slot=A 1 2"); + ut_assert_nextline("Boot failed (err=-14)"); + ut_assert_console_end(); + ut_asserteq_str("2", env_get("BOOT_A_LEFT")); + + /* Slot B is booted once slot A has no tries left */ + ut_assertok(env_set("BOOT_A_LEFT", "0")); + ut_assertok(bootflow_rauc_boot(uts)); + ut_assert_skip_to_line("rauc boot: rauc.slot=B 3 4"); + ut_assert_nextline("Boot failed (err=-14)"); + ut_assert_console_end(); + ut_asserteq_str("2", env_get("BOOT_B_LEFT")); + + /* A failing command uses up a try as well */ + ut_assertok(env_set("rauc_test_boot", "false")); + ut_assertok(bootflow_rauc_boot(uts)); + ut_assert_skip_to_line("Boot failed (err=1)"); + ut_assert_console_end(); + ut_asserteq_str("1", env_get("BOOT_B_LEFT")); + + ut_assertok(env_set("BOOT_A_LEFT", NULL)); + ut_assertok(env_set("BOOT_B_LEFT", NULL)); + ut_assertok(env_set("rauc_test_boot", NULL)); + + return 0; +} + +/* Test booting a slot with the built-in boot command of the RAUC bootmeth */ +static int bootflow_rauc_bootcmd(struct unit_test_state *uts) +{ + int ret; + + if (!CONFIG_IS_ENABLED(BOOTMETH_RAUC) || + !IS_ENABLED(CONFIG_ENV_IS_IN_FAT) || + !IS_ENABLED(CONFIG_CMD_NVEDIT_SELECT)) + return -EAGAIN; +#ifdef CONFIG_BOOTMETH_RAUC_BOOTCMD + if (strcmp(CONFIG_BOOTMETH_RAUC_BOOTCMD, "run rauc_test_boot")) + return -EAGAIN; +#endif + + /* Save the environment to the first partition of mmc10 */ + ut_assertok(run_command("env select FAT", 0)); + ut_assert_nextline("Select Environment on FAT: OK"); + + ret = bootflow_rauc_run(uts, "mmc10", bootflow_rauc_bootcmd_check); + run_command("env select nowhere", 0); + if (ret) + return ret; + ut_assert_nextline("Select Environment on nowhere: OK"); + ut_assert_console_end(); + + return 0; +} +BOOTSTD_TEST(bootflow_rauc_bootcmd, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT); + /* Check 'bootflow scan' provides a list of images */ static int bootstd_images(struct unit_test_state *uts) { -- 2.56.0
