Skip to content

Commit baea7ec

Browse files
committed
bootstd: Refactor mmc prep to allow a different scan
Adjust scan_mmc4_bootdev() and related function so that the caller can do its own 'bootflow scan' command. This allows it to change the flags if needed. Signed-off-by: Simon Glass <[email protected]>
1 parent a75cf70 commit baea7ec

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

test/boot/bootflow.c

+40-9
Original file line numberDiff line numberDiff line change
@@ -511,19 +511,27 @@ BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
511511
/**
512512
* prep_mmc_bootdev() - Set up an mmc bootdev so we can access other distros
513513
*
514+
* After calling this function, set std->bootdev_order to *@old_orderp to
515+
* restore normal operation of bootstd (i.e. with the original bootdev order)
516+
*
514517
* @uts: Unit test state
515-
* @mmc_dev: MMC device to use, e.g. "mmc4"
518+
* @mmc_dev: MMC device to use, e.g. "mmc4". Note that this must remain valid
519+
* in the caller until
520+
* @bind_cros: true to bind the ChromiumOS bootmeth
521+
* @old_orderp: Returns the original bootdev order, which must be restored
516522
* Returns 0 on success, -ve on failure
517523
*/
518524
static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
519-
bool bind_cros)
525+
bool bind_cros, const char ***old_orderp)
520526
{
521-
const char *order[] = {"mmc2", "mmc1", mmc_dev, NULL};
527+
static const char *order[] = {"mmc2", "mmc1", NULL, NULL};
522528
struct udevice *dev, *bootstd;
523529
struct bootstd_priv *std;
524530
const char **old_order;
525531
ofnode root, node;
526532

533+
order[2] = mmc_dev;
534+
527535
/* Enable the mmc4 node since we need a second bootflow */
528536
root = oftree_root(oftree_default());
529537
node = ofnode_find_subnode(root, mmc_dev);
@@ -546,26 +554,49 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
546554
std = dev_get_priv(bootstd);
547555
old_order = std->bootdev_order;
548556
std->bootdev_order = order;
557+
*old_orderp = old_order;
558+
559+
return 0;
560+
}
561+
562+
/**
563+
* scan_mmc_bootdev() - Set up an mmc bootdev so we can access other distros
564+
*
565+
* @uts: Unit test state
566+
* @mmc_dev: MMC device to use, e.g. "mmc4"
567+
* @bind_cros: true to bind the ChromiumOS bootmeth
568+
* Returns 0 on success, -ve on failure
569+
*/
570+
static int scan_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
571+
bool bind_cros)
572+
{
573+
struct bootstd_priv *std;
574+
struct udevice *bootstd;
575+
const char **old_order;
576+
577+
ut_assertok(prep_mmc_bootdev(uts, mmc_dev, bind_cros, &old_order));
549578

550579
console_record_reset_enable();
551580
ut_assertok(run_command("bootflow scan", 0));
552581
ut_assert_console_end();
553582

554583
/* Restore the order used by the device tree */
584+
ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
585+
std = dev_get_priv(bootstd);
555586
std->bootdev_order = old_order;
556587

557588
return 0;
558589
}
559590

560591
/**
561-
* prep_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian
592+
* scan_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian
562593
*
563594
* @uts: Unit test state
564595
* Returns 0 on success, -ve on failure
565596
*/
566-
static int prep_mmc4_bootdev(struct unit_test_state *uts)
597+
static int scan_mmc4_bootdev(struct unit_test_state *uts)
567598
{
568-
ut_assertok(prep_mmc_bootdev(uts, "mmc4", false));
599+
ut_assertok(scan_mmc_bootdev(uts, "mmc4", false));
569600

570601
return 0;
571602
}
@@ -575,7 +606,7 @@ static int bootflow_cmd_menu(struct unit_test_state *uts)
575606
{
576607
char prev[3];
577608

578-
ut_assertok(prep_mmc4_bootdev(uts));
609+
ut_assertok(scan_mmc4_bootdev(uts));
579610

580611
/* Add keypresses to move to and select the second one in the list */
581612
prev[0] = CTL_CH('n');
@@ -681,7 +712,7 @@ static int bootflow_menu_theme(struct unit_test_state *uts)
681712
ofnode node;
682713
int i;
683714

684-
ut_assertok(prep_mmc4_bootdev(uts));
715+
ut_assertok(scan_mmc4_bootdev(uts));
685716

686717
ut_assertok(bootflow_menu_new(&exp));
687718
node = ofnode_path("/bootstd/theme");
@@ -996,7 +1027,7 @@ BOOTSTD_TEST(bootflow_cmdline_special, 0);
9961027
/* Test ChromiumOS bootmeth */
9971028
static int bootflow_cros(struct unit_test_state *uts)
9981029
{
999-
ut_assertok(prep_mmc_bootdev(uts, "mmc5", true));
1030+
ut_assertok(scan_mmc_bootdev(uts, "mmc5", true));
10001031
ut_assertok(run_command("bootflow list", 0));
10011032

10021033
ut_assert_nextlinen("Showing all");

0 commit comments

Comments
 (0)