2022-04-25 05:31:24 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Test for bootdev functions. All start with 'bootdev'
|
|
|
|
*
|
|
|
|
* Copyright 2021 Google LLC
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <bootstd.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <bootdev.h>
|
|
|
|
#include <bootflow.h>
|
|
|
|
#include <mapmem.h>
|
|
|
|
#include <os.h>
|
|
|
|
#include <test/suites.h>
|
|
|
|
#include <test/ut.h>
|
|
|
|
#include "bootstd_common.h"
|
|
|
|
|
|
|
|
/* Allow reseting the USB-started flag */
|
2023-01-23 22:07:21 +00:00
|
|
|
#if defined(CONFIG_USB_HOST) || defined(CONFIG_USB_GADGET)
|
2023-05-06 02:03:03 +00:00
|
|
|
extern bool usb_started;
|
2023-01-23 22:07:21 +00:00
|
|
|
#else
|
2023-05-06 02:03:03 +00:00
|
|
|
#include <usb.h>
|
2023-01-23 22:07:21 +00:00
|
|
|
#endif
|
2022-04-25 05:31:24 +00:00
|
|
|
|
|
|
|
/* Check 'bootdev list' command */
|
|
|
|
static int bootdev_test_cmd_list(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
int probed;
|
|
|
|
|
|
|
|
console_record_reset_enable();
|
|
|
|
for (probed = 0; probed < 2; probed++) {
|
|
|
|
int probe_ch = probed ? '+' : ' ';
|
|
|
|
|
|
|
|
ut_assertok(run_command(probed ? "bootdev list -p" :
|
|
|
|
"bootdev list", 0));
|
|
|
|
ut_assert_nextline("Seq Probed Status Uclass Name");
|
|
|
|
ut_assert_nextlinen("---");
|
|
|
|
ut_assert_nextline("%3x [ %c ] %6s %-8s %s", 0, probe_ch, "OK",
|
|
|
|
"mmc", "mmc2.bootdev");
|
|
|
|
ut_assert_nextline("%3x [ %c ] %6s %-8s %s", 1, probe_ch, "OK",
|
|
|
|
"mmc", "mmc1.bootdev");
|
|
|
|
ut_assert_nextline("%3x [ %c ] %6s %-8s %s", 2, probe_ch, "OK",
|
|
|
|
"mmc", "mmc0.bootdev");
|
|
|
|
ut_assert_nextlinen("---");
|
|
|
|
ut_assert_nextline("(3 bootdevs)");
|
|
|
|
ut_assert_console_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_cmd_list, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
|
|
|
|
|
|
|
|
/* Check 'bootdev select' and 'info' commands */
|
|
|
|
static int bootdev_test_cmd_select(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct bootstd_priv *std;
|
|
|
|
|
|
|
|
/* get access to the CLI's cur_bootdev */
|
|
|
|
ut_assertok(bootstd_get_priv(&std));
|
|
|
|
|
|
|
|
console_record_reset_enable();
|
|
|
|
ut_asserteq(1, run_command("bootdev info", 0));
|
|
|
|
ut_assert_nextlinen("Please use");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
/* select by sequence */
|
|
|
|
ut_assertok(run_command("bootdev select 0", 0));
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
ut_assertok(run_command("bootdev info", 0));
|
|
|
|
ut_assert_nextline("Name: mmc2.bootdev");
|
|
|
|
ut_assert_nextline("Sequence: 0");
|
|
|
|
ut_assert_nextline("Status: Probed");
|
|
|
|
ut_assert_nextline("Uclass: mmc");
|
|
|
|
ut_assert_nextline("Bootflows: 0 (0 valid)");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
/* select by bootdev name */
|
|
|
|
ut_assertok(run_command("bootdev select mmc1.bootdev", 0));
|
|
|
|
ut_assert_console_end();
|
|
|
|
ut_assertnonnull(std->cur_bootdev);
|
|
|
|
ut_asserteq_str("mmc1.bootdev", std->cur_bootdev->name);
|
|
|
|
|
|
|
|
/* select by bootdev label*/
|
|
|
|
ut_assertok(run_command("bootdev select mmc1", 0));
|
|
|
|
ut_assert_console_end();
|
|
|
|
ut_assertnonnull(std->cur_bootdev);
|
|
|
|
ut_asserteq_str("mmc1.bootdev", std->cur_bootdev->name);
|
|
|
|
|
|
|
|
/* deselect */
|
|
|
|
ut_assertok(run_command("bootdev select", 0));
|
|
|
|
ut_assert_console_end();
|
|
|
|
ut_assertnull(std->cur_bootdev);
|
|
|
|
|
|
|
|
ut_asserteq(1, run_command("bootdev info", 0));
|
|
|
|
ut_assert_nextlinen("Please use");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_cmd_select, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
|
|
|
|
|
|
|
|
/* Check bootdev labels */
|
|
|
|
static int bootdev_test_labels(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev, *media;
|
2023-01-17 17:48:05 +00:00
|
|
|
int mflags = 0;
|
2022-04-25 05:31:24 +00:00
|
|
|
|
2023-01-17 17:48:05 +00:00
|
|
|
ut_assertok(bootdev_find_by_label("mmc2", &dev, &mflags));
|
2022-04-25 05:31:24 +00:00
|
|
|
ut_asserteq(UCLASS_BOOTDEV, device_get_uclass_id(dev));
|
2023-01-17 17:48:05 +00:00
|
|
|
ut_asserteq(0, mflags);
|
2022-04-25 05:31:24 +00:00
|
|
|
media = dev_get_parent(dev);
|
|
|
|
ut_asserteq(UCLASS_MMC, device_get_uclass_id(media));
|
|
|
|
ut_asserteq_str("mmc2", media->name);
|
|
|
|
|
2023-01-17 17:48:05 +00:00
|
|
|
/* Check method flags */
|
|
|
|
ut_assertok(bootdev_find_by_label("pxe", &dev, &mflags));
|
2023-01-17 17:48:09 +00:00
|
|
|
ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_PXE_ONLY,
|
|
|
|
mflags);
|
2023-01-17 17:48:05 +00:00
|
|
|
ut_assertok(bootdev_find_by_label("dhcp", &dev, &mflags));
|
2023-01-17 17:48:09 +00:00
|
|
|
ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_DHCP_ONLY,
|
|
|
|
mflags);
|
2023-01-17 17:48:05 +00:00
|
|
|
|
2022-04-25 05:31:24 +00:00
|
|
|
/* Check invalid uclass */
|
2023-04-24 01:49:47 +00:00
|
|
|
ut_asserteq(-EPFNOSUPPORT,
|
|
|
|
bootdev_find_by_label("fred0", &dev, &mflags));
|
2022-04-25 05:31:24 +00:00
|
|
|
|
|
|
|
/* Check unknown sequence number */
|
2023-01-17 17:48:05 +00:00
|
|
|
ut_asserteq(-ENOENT, bootdev_find_by_label("mmc6", &dev, &mflags));
|
2022-04-25 05:31:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2023-01-17 17:48:05 +00:00
|
|
|
BOOTSTD_TEST(bootdev_test_labels, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
|
|
|
|
UT_TESTF_ETH_BOOTDEV);
|
2022-04-25 05:31:24 +00:00
|
|
|
|
2023-01-17 17:48:09 +00:00
|
|
|
/* Check bootdev_find_by_any() */
|
|
|
|
static int bootdev_test_any(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev, *media;
|
|
|
|
int mflags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* with ethernet enabled we have 8 devices ahead of the mmc ones:
|
|
|
|
*
|
|
|
|
* ut_assertok(run_command("bootdev list", 0));
|
|
|
|
* Seq Probed Status Uclass Name
|
|
|
|
* --- ------ ------ -------- ------------------
|
|
|
|
* 0 [ + ] OK ethernet eth@10002000.bootdev
|
|
|
|
* 1 [ ] OK ethernet eth@10003000.bootdev
|
|
|
|
* 2 [ ] OK ethernet sbe5.bootdev
|
|
|
|
* 3 [ ] OK ethernet eth@10004000.bootdev
|
|
|
|
* 4 [ ] OK ethernet phy-test-eth.bootdev
|
|
|
|
* 5 [ ] OK ethernet dsa-test-eth.bootdev
|
|
|
|
* 6 [ ] OK ethernet dsa-test@0.bootdev
|
|
|
|
* 7 [ ] OK ethernet dsa-test@1.bootdev
|
|
|
|
* 8 [ ] OK mmc mmc2.bootdev
|
|
|
|
* 9 [ + ] OK mmc mmc1.bootdev
|
|
|
|
* a [ ] OK mmc mmc0.bootdev
|
|
|
|
*/
|
|
|
|
console_record_reset_enable();
|
|
|
|
ut_assertok(bootdev_find_by_any("8", &dev, &mflags));
|
|
|
|
ut_asserteq(UCLASS_BOOTDEV, device_get_uclass_id(dev));
|
|
|
|
ut_asserteq(BOOTFLOW_METHF_SINGLE_DEV, mflags);
|
|
|
|
media = dev_get_parent(dev);
|
|
|
|
ut_asserteq(UCLASS_MMC, device_get_uclass_id(media));
|
|
|
|
ut_asserteq_str("mmc2", media->name);
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
/* there should not be this many bootdevs */
|
|
|
|
ut_asserteq(-ENODEV, bootdev_find_by_any("50", &dev, &mflags));
|
|
|
|
ut_assert_nextline("Cannot find '50' (err=-19)");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
/* Check method flags */
|
|
|
|
ut_assertok(bootdev_find_by_any("pxe", &dev, &mflags));
|
|
|
|
ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_PXE_ONLY,
|
|
|
|
mflags);
|
|
|
|
|
|
|
|
/* Check invalid uclass */
|
|
|
|
mflags = 123;
|
2023-04-24 01:49:47 +00:00
|
|
|
ut_asserteq(-EPFNOSUPPORT, bootdev_find_by_any("fred0", &dev, &mflags));
|
|
|
|
ut_assert_nextline("Cannot find bootdev 'fred0' (err=-96)");
|
2023-01-17 17:48:09 +00:00
|
|
|
ut_asserteq(123, mflags);
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_any, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
|
|
|
|
UT_TESTF_ETH_BOOTDEV);
|
|
|
|
|
2022-04-25 05:31:24 +00:00
|
|
|
/* Check bootdev ordering with the bootdev-order property */
|
|
|
|
static int bootdev_test_order(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct bootflow_iter iter;
|
|
|
|
struct bootflow bflow;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First try the order set by the bootdev-order property
|
|
|
|
* Like all sandbox unit tests this relies on the devicetree setting up
|
|
|
|
* the required devices:
|
|
|
|
*
|
|
|
|
* mmc0 - nothing connected
|
|
|
|
* mmc1 - connected to mmc1.img file
|
|
|
|
* mmc2 - nothing connected
|
|
|
|
*/
|
|
|
|
ut_assertok(env_set("boot_targets", NULL));
|
2023-01-17 17:48:16 +00:00
|
|
|
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
|
2022-04-25 05:31:24 +00:00
|
|
|
ut_asserteq(2, iter.num_devs);
|
2023-01-17 17:48:17 +00:00
|
|
|
ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name);
|
|
|
|
ut_asserteq_str("mmc1.bootdev", iter.dev_used[1]->name);
|
2022-04-25 05:31:24 +00:00
|
|
|
bootflow_iter_uninit(&iter);
|
|
|
|
|
|
|
|
/* Use the environment variable to override it */
|
|
|
|
ut_assertok(env_set("boot_targets", "mmc1 mmc2"));
|
2023-01-17 17:48:16 +00:00
|
|
|
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
|
2023-01-17 17:48:17 +00:00
|
|
|
ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
|
2022-04-25 05:31:24 +00:00
|
|
|
ut_asserteq(2, iter.num_devs);
|
2023-01-17 17:48:17 +00:00
|
|
|
ut_asserteq_str("mmc1.bootdev", iter.dev_used[0]->name);
|
|
|
|
ut_asserteq_str("mmc2.bootdev", iter.dev_used[1]->name);
|
2022-04-25 05:31:24 +00:00
|
|
|
bootflow_iter_uninit(&iter);
|
|
|
|
|
2023-01-17 17:48:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_order, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
|
|
|
|
|
|
|
|
/* Check default bootdev ordering */
|
|
|
|
static int bootdev_test_order_default(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct bootflow_iter iter;
|
|
|
|
struct bootflow bflow;
|
|
|
|
|
2022-04-25 05:31:24 +00:00
|
|
|
/*
|
|
|
|
* Now drop both orderings, to check the default (prioriy/sequence)
|
|
|
|
* ordering
|
|
|
|
*/
|
|
|
|
ut_assertok(env_set("boot_targets", NULL));
|
|
|
|
ut_assertok(bootstd_test_drop_bootdev_order(uts));
|
|
|
|
|
2023-01-17 17:48:16 +00:00
|
|
|
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
|
2023-01-17 17:48:17 +00:00
|
|
|
ut_asserteq(2, iter.num_devs);
|
|
|
|
ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name);
|
|
|
|
ut_asserteq_str("mmc1.bootdev", iter.dev_used[1]->name);
|
2022-04-25 05:31:24 +00:00
|
|
|
|
2023-01-17 17:48:17 +00:00
|
|
|
ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
|
2022-04-25 05:31:24 +00:00
|
|
|
ut_asserteq(3, iter.num_devs);
|
2023-01-17 17:48:17 +00:00
|
|
|
ut_asserteq_str("mmc0.bootdev", iter.dev_used[2]->name);
|
2022-04-25 05:31:24 +00:00
|
|
|
bootflow_iter_uninit(&iter);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2023-01-17 17:48:17 +00:00
|
|
|
BOOTSTD_TEST(bootdev_test_order_default, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
|
2022-04-25 05:31:24 +00:00
|
|
|
|
|
|
|
/* Check bootdev ordering with the uclass priority */
|
|
|
|
static int bootdev_test_prio(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct bootdev_uc_plat *ucp;
|
|
|
|
struct bootflow_iter iter;
|
|
|
|
struct bootflow bflow;
|
|
|
|
struct udevice *blk;
|
|
|
|
|
2023-01-17 17:47:37 +00:00
|
|
|
test_set_skip_delays(true);
|
|
|
|
|
2023-01-17 17:48:17 +00:00
|
|
|
/* disable ethernet since the hunter will run dhcp */
|
|
|
|
test_set_eth_enable(false);
|
|
|
|
|
2022-04-25 05:31:24 +00:00
|
|
|
/* Start up USB which gives us three additional bootdevs */
|
|
|
|
usb_started = false;
|
|
|
|
ut_assertok(run_command("usb start", 0));
|
|
|
|
|
|
|
|
ut_assertok(bootstd_test_drop_bootdev_order(uts));
|
|
|
|
|
|
|
|
/* 3 MMC and 3 USB bootdevs: MMC should come before USB */
|
|
|
|
console_record_reset_enable();
|
2023-01-17 17:48:16 +00:00
|
|
|
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
|
2023-01-17 17:48:17 +00:00
|
|
|
ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
|
2022-04-25 05:31:24 +00:00
|
|
|
ut_asserteq(6, iter.num_devs);
|
2023-01-17 17:48:17 +00:00
|
|
|
ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name);
|
2022-04-25 05:31:24 +00:00
|
|
|
ut_asserteq_str("usb_mass_storage.lun0.bootdev",
|
2023-01-17 17:48:17 +00:00
|
|
|
iter.dev_used[3]->name);
|
2022-04-25 05:31:24 +00:00
|
|
|
|
2023-01-17 17:48:17 +00:00
|
|
|
ut_assertok(bootdev_get_sibling_blk(iter.dev_used[3], &blk));
|
2022-04-25 05:31:24 +00:00
|
|
|
ut_asserteq_str("usb_mass_storage.lun0", blk->name);
|
|
|
|
|
|
|
|
/* adjust the priority of the first USB bootdev to the highest */
|
2023-01-17 17:48:17 +00:00
|
|
|
ucp = dev_get_uclass_plat(iter.dev_used[3]);
|
|
|
|
ucp->prio = BOOTDEVP_1_PRE_SCAN;
|
2022-04-25 05:31:24 +00:00
|
|
|
|
2023-01-17 17:48:17 +00:00
|
|
|
/* try again but enable hunting, which brings in SCSI */
|
2022-04-25 05:31:24 +00:00
|
|
|
bootflow_iter_uninit(&iter);
|
2023-02-22 19:17:03 +00:00
|
|
|
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWIF_HUNT,
|
2023-01-17 17:48:16 +00:00
|
|
|
&bflow));
|
2023-01-17 17:48:17 +00:00
|
|
|
ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
|
|
|
|
ut_asserteq(7, iter.num_devs);
|
2022-04-25 05:31:24 +00:00
|
|
|
ut_asserteq_str("usb_mass_storage.lun0.bootdev",
|
2023-01-17 17:48:17 +00:00
|
|
|
iter.dev_used[0]->name);
|
|
|
|
ut_asserteq_str("mmc2.bootdev", iter.dev_used[1]->name);
|
2022-04-25 05:31:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
|
2023-01-17 17:47:33 +00:00
|
|
|
|
|
|
|
/* Check listing hunters */
|
|
|
|
static int bootdev_test_hunter(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct bootstd_priv *std;
|
|
|
|
|
2023-01-17 17:47:37 +00:00
|
|
|
test_set_skip_delays(true);
|
|
|
|
|
2023-01-17 17:47:33 +00:00
|
|
|
/* get access to the used hunters */
|
|
|
|
ut_assertok(bootstd_get_priv(&std));
|
|
|
|
|
|
|
|
console_record_reset_enable();
|
|
|
|
bootdev_list_hunters(std);
|
|
|
|
ut_assert_nextline("Prio Used Uclass Hunter");
|
|
|
|
ut_assert_nextlinen("----");
|
2023-01-17 17:48:08 +00:00
|
|
|
ut_assert_nextline(" 6 ethernet eth_bootdev");
|
2023-01-17 17:48:13 +00:00
|
|
|
ut_assert_nextline(" 1 simple_bus (none)");
|
2023-01-17 17:48:08 +00:00
|
|
|
ut_assert_nextline(" 5 ide ide_bootdev");
|
|
|
|
ut_assert_nextline(" 2 mmc mmc_bootdev");
|
|
|
|
ut_assert_nextline(" 4 nvme nvme_bootdev");
|
2023-01-28 22:00:28 +00:00
|
|
|
ut_assert_nextline(" 4 qfw qfw_bootdev");
|
2023-01-17 17:48:08 +00:00
|
|
|
ut_assert_nextline(" 4 scsi scsi_bootdev");
|
|
|
|
ut_assert_nextline(" 4 spi_flash sf_bootdev");
|
|
|
|
ut_assert_nextline(" 5 usb usb_bootdev");
|
|
|
|
ut_assert_nextline(" 4 virtio virtio_bootdev");
|
2023-01-28 22:00:28 +00:00
|
|
|
ut_assert_nextline("(total hunters: 10)");
|
2023-01-17 17:47:33 +00:00
|
|
|
ut_assert_console_end();
|
|
|
|
|
2023-01-17 17:47:37 +00:00
|
|
|
ut_assertok(bootdev_hunt("usb1", false));
|
|
|
|
ut_assert_nextline(
|
|
|
|
"Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found");
|
2023-01-17 17:47:34 +00:00
|
|
|
ut_assert_console_end();
|
|
|
|
|
2023-01-28 22:00:28 +00:00
|
|
|
/* USB is 7th in the list, so bit 8 */
|
|
|
|
ut_asserteq(BIT(8), std->hunters_used);
|
2023-01-17 17:47:37 +00:00
|
|
|
|
2023-01-17 17:47:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_hunter, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
|
|
|
|
|
|
|
|
/* Check 'bootdev hunt' command */
|
|
|
|
static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct bootstd_priv *std;
|
|
|
|
|
2023-01-17 17:47:37 +00:00
|
|
|
test_set_skip_delays(true);
|
|
|
|
|
2023-01-17 17:47:33 +00:00
|
|
|
/* get access to the used hunters */
|
|
|
|
ut_assertok(bootstd_get_priv(&std));
|
|
|
|
|
|
|
|
console_record_reset_enable();
|
|
|
|
ut_assertok(run_command("bootdev hunt -l", 0));
|
|
|
|
ut_assert_nextline("Prio Used Uclass Hunter");
|
|
|
|
ut_assert_nextlinen("----");
|
2023-01-17 17:48:08 +00:00
|
|
|
ut_assert_nextline(" 6 ethernet eth_bootdev");
|
2023-01-28 22:00:28 +00:00
|
|
|
ut_assert_skip_to_line("(total hunters: 10)");
|
2023-01-17 17:48:08 +00:00
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
/* Use the MMC hunter and see that it updates */
|
|
|
|
ut_assertok(run_command("bootdev hunt mmc", 0));
|
|
|
|
ut_assertok(run_command("bootdev hunt -l", 0));
|
|
|
|
ut_assert_skip_to_line(" 5 ide ide_bootdev");
|
|
|
|
ut_assert_nextline(" 2 * mmc mmc_bootdev");
|
2023-01-28 22:00:28 +00:00
|
|
|
ut_assert_skip_to_line("(total hunters: 10)");
|
2023-01-17 17:47:33 +00:00
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
/* Scan all hunters */
|
2023-01-17 17:48:10 +00:00
|
|
|
test_set_eth_enable(false);
|
2023-01-17 17:48:08 +00:00
|
|
|
test_set_skip_delays(true);
|
2023-01-17 17:47:33 +00:00
|
|
|
ut_assertok(run_command("bootdev hunt", 0));
|
2023-01-17 17:47:40 +00:00
|
|
|
ut_assert_nextline("Hunting with: ethernet");
|
2023-01-17 17:48:13 +00:00
|
|
|
|
|
|
|
/* This is the extension feature which has no uclass at present */
|
|
|
|
ut_assert_nextline("Hunting with: simple_bus");
|
|
|
|
ut_assert_nextline("Found 2 extension board(s).");
|
2023-01-17 17:47:46 +00:00
|
|
|
ut_assert_nextline("Hunting with: ide");
|
2023-01-17 17:48:08 +00:00
|
|
|
|
|
|
|
/* mmc hunter has already been used so should not run again */
|
|
|
|
|
2023-01-17 17:47:47 +00:00
|
|
|
ut_assert_nextline("Hunting with: nvme");
|
2023-01-28 22:00:28 +00:00
|
|
|
ut_assert_nextline("Hunting with: qfw");
|
2023-01-17 17:47:45 +00:00
|
|
|
ut_assert_nextline("Hunting with: scsi");
|
|
|
|
ut_assert_nextline("scanning bus for devices...");
|
2023-01-17 17:48:03 +00:00
|
|
|
ut_assert_skip_to_line("Hunting with: spi_flash");
|
|
|
|
ut_assert_nextline("Hunting with: usb");
|
2023-01-17 17:47:37 +00:00
|
|
|
ut_assert_nextline(
|
|
|
|
"Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found");
|
2023-01-17 17:48:03 +00:00
|
|
|
ut_assert_nextline("Hunting with: virtio");
|
2023-01-17 17:47:33 +00:00
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
/* List available hunters */
|
|
|
|
ut_assertok(run_command("bootdev hunt -l", 0));
|
|
|
|
ut_assert_nextlinen("Prio");
|
|
|
|
ut_assert_nextlinen("----");
|
2023-01-17 17:48:08 +00:00
|
|
|
ut_assert_nextline(" 6 * ethernet eth_bootdev");
|
2023-01-17 17:48:13 +00:00
|
|
|
ut_assert_nextline(" 1 * simple_bus (none)");
|
2023-01-17 17:48:08 +00:00
|
|
|
ut_assert_nextline(" 5 * ide ide_bootdev");
|
|
|
|
ut_assert_nextline(" 2 * mmc mmc_bootdev");
|
|
|
|
ut_assert_nextline(" 4 * nvme nvme_bootdev");
|
2023-01-28 22:00:28 +00:00
|
|
|
ut_assert_nextline(" 4 * qfw qfw_bootdev");
|
2023-01-17 17:48:08 +00:00
|
|
|
ut_assert_nextline(" 4 * scsi scsi_bootdev");
|
|
|
|
ut_assert_nextline(" 4 * spi_flash sf_bootdev");
|
|
|
|
ut_assert_nextline(" 5 * usb usb_bootdev");
|
|
|
|
ut_assert_nextline(" 4 * virtio virtio_bootdev");
|
2023-01-28 22:00:28 +00:00
|
|
|
ut_assert_nextline("(total hunters: 10)");
|
2023-01-17 17:47:33 +00:00
|
|
|
ut_assert_console_end();
|
|
|
|
|
2023-01-17 17:48:13 +00:00
|
|
|
ut_asserteq(GENMASK(MAX_HUNTER, 0), std->hunters_used);
|
2023-01-17 17:47:33 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_cmd_hunt, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
|
|
|
|
UT_TESTF_ETH_BOOTDEV);
|
2023-01-17 17:47:42 +00:00
|
|
|
|
2023-01-17 17:48:14 +00:00
|
|
|
/* Check searching for bootdevs using the hunters */
|
|
|
|
static int bootdev_test_hunt_scan(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct bootflow_iter iter;
|
|
|
|
struct bootstd_priv *std;
|
|
|
|
struct bootflow bflow;
|
|
|
|
|
|
|
|
/* get access to the used hunters */
|
|
|
|
ut_assertok(bootstd_get_priv(&std));
|
|
|
|
|
|
|
|
ut_assertok(bootstd_test_drop_bootdev_order(uts));
|
2023-01-17 17:48:16 +00:00
|
|
|
ut_assertok(bootflow_scan_first(NULL, NULL, &iter,
|
2023-02-22 19:17:03 +00:00
|
|
|
BOOTFLOWIF_SHOW | BOOTFLOWIF_HUNT |
|
|
|
|
BOOTFLOWIF_SKIP_GLOBAL, &bflow));
|
2023-01-17 17:48:14 +00:00
|
|
|
ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_hunt_scan, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
|
|
|
|
|
2023-01-17 17:47:42 +00:00
|
|
|
/* Check that only bootable partitions are processed */
|
|
|
|
static int bootdev_test_bootable(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct bootflow_iter iter;
|
|
|
|
struct bootflow bflow;
|
|
|
|
struct udevice *blk;
|
|
|
|
|
|
|
|
memset(&iter, '\0', sizeof(iter));
|
|
|
|
memset(&bflow, '\0', sizeof(bflow));
|
|
|
|
iter.part = 0;
|
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_BLK, "mmc1.blk", &blk));
|
|
|
|
iter.dev = blk;
|
|
|
|
ut_assertok(device_find_next_child(&iter.dev));
|
|
|
|
uclass_first_device(UCLASS_BOOTMETH, &bflow.method);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initially we don't have any knowledge of which partitions are
|
|
|
|
* bootable, but mmc1 has two partitions, with the first one being
|
|
|
|
* bootable
|
|
|
|
*/
|
|
|
|
iter.part = 2;
|
|
|
|
ut_asserteq(-EINVAL, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow));
|
|
|
|
ut_asserteq(0, iter.first_bootable);
|
|
|
|
|
|
|
|
/* scan with part == 0 to get the partition info */
|
|
|
|
iter.part = 0;
|
|
|
|
ut_asserteq(-ENOENT, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow));
|
|
|
|
ut_asserteq(1, iter.first_bootable);
|
|
|
|
|
|
|
|
/* now it will refuse to use non-bootable partitions */
|
|
|
|
iter.part = 2;
|
|
|
|
ut_asserteq(-EINVAL, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_bootable, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
|
2023-01-17 17:48:07 +00:00
|
|
|
|
|
|
|
/* Check hunting for bootdev of a particular priority */
|
|
|
|
static int bootdev_test_hunt_prio(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
test_set_skip_delays(true);
|
|
|
|
|
|
|
|
console_record_reset_enable();
|
2023-01-17 17:48:08 +00:00
|
|
|
ut_assertok(bootdev_hunt_prio(BOOTDEVP_4_SCAN_FAST, false));
|
2023-01-17 17:48:07 +00:00
|
|
|
ut_assert_nextline("scanning bus for devices...");
|
|
|
|
ut_assert_skip_to_line(" Type: Hard Disk");
|
|
|
|
ut_assert_nextlinen(" Capacity:");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
/* now try a different priority, verbosely */
|
2023-01-17 17:48:08 +00:00
|
|
|
ut_assertok(bootdev_hunt_prio(BOOTDEVP_5_SCAN_SLOW, true));
|
2023-01-17 17:48:07 +00:00
|
|
|
ut_assert_nextline("Hunting with: ide");
|
|
|
|
ut_assert_nextline("Hunting with: usb");
|
|
|
|
ut_assert_nextline(
|
|
|
|
"Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_hunt_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
|
2023-01-17 17:48:09 +00:00
|
|
|
|
|
|
|
/* Check hunting for bootdevs with a particular label */
|
|
|
|
static int bootdev_test_hunt_label(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev, *old;
|
|
|
|
struct bootstd_priv *std;
|
|
|
|
int mflags;
|
|
|
|
|
|
|
|
/* get access to the used hunters */
|
|
|
|
ut_assertok(bootstd_get_priv(&std));
|
|
|
|
|
|
|
|
/* scan an unknown uclass */
|
|
|
|
console_record_reset_enable();
|
|
|
|
old = (void *)&mflags; /* arbitrary pointer to check against dev */
|
|
|
|
dev = old;
|
|
|
|
mflags = 123;
|
2023-04-24 01:49:47 +00:00
|
|
|
ut_asserteq(-EPFNOSUPPORT,
|
2023-01-17 17:48:09 +00:00
|
|
|
bootdev_hunt_and_find_by_label("fred", &dev, &mflags));
|
|
|
|
ut_asserteq_ptr(old, dev);
|
|
|
|
ut_asserteq(123, mflags);
|
|
|
|
ut_assert_console_end();
|
|
|
|
ut_asserteq(0, std->hunters_used);
|
|
|
|
|
|
|
|
/* scan an invalid mmc controllers */
|
|
|
|
ut_asserteq(-ENOENT,
|
|
|
|
bootdev_hunt_and_find_by_label("mmc4", &dev, &mflags));
|
|
|
|
ut_asserteq_ptr(old, dev);
|
|
|
|
ut_asserteq(123, mflags);
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
ut_assertok(bootstd_test_check_mmc_hunter(uts));
|
|
|
|
|
|
|
|
/* scan for a particular mmc controller */
|
|
|
|
ut_assertok(bootdev_hunt_and_find_by_label("mmc1", &dev, &mflags));
|
|
|
|
ut_assertnonnull(dev);
|
|
|
|
ut_asserteq_str("mmc1.bootdev", dev->name);
|
|
|
|
ut_asserteq(0, mflags);
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
/* scan all of usb */
|
|
|
|
test_set_skip_delays(true);
|
|
|
|
ut_assertok(bootdev_hunt_and_find_by_label("usb", &dev, &mflags));
|
|
|
|
ut_assertnonnull(dev);
|
|
|
|
ut_asserteq_str("usb_mass_storage.lun0.bootdev", dev->name);
|
|
|
|
ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags);
|
|
|
|
ut_assert_nextlinen("Bus usb@1: scanning bus usb@1");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_hunt_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
|
2023-01-17 17:48:10 +00:00
|
|
|
|
|
|
|
/* Check iterating to the next label in a list */
|
|
|
|
static int bootdev_test_next_label(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
const char *const labels[] = {"mmc0", "scsi", "dhcp", "pxe", NULL};
|
|
|
|
struct bootflow_iter iter;
|
|
|
|
struct bootstd_priv *std;
|
|
|
|
struct bootflow bflow;
|
|
|
|
struct udevice *dev;
|
|
|
|
int mflags;
|
|
|
|
|
|
|
|
test_set_eth_enable(false);
|
|
|
|
|
|
|
|
/* get access to the used hunters */
|
|
|
|
ut_assertok(bootstd_get_priv(&std));
|
|
|
|
|
|
|
|
memset(&iter, '\0', sizeof(iter));
|
|
|
|
memset(&bflow, '\0', sizeof(bflow));
|
|
|
|
iter.part = 0;
|
|
|
|
uclass_first_device(UCLASS_BOOTMETH, &bflow.method);
|
|
|
|
iter.cur_label = -1;
|
|
|
|
iter.labels = labels;
|
|
|
|
|
|
|
|
dev = NULL;
|
|
|
|
mflags = 123;
|
|
|
|
ut_assertok(bootdev_next_label(&iter, &dev, &mflags));
|
|
|
|
console_record_reset_enable();
|
|
|
|
ut_assert_console_end();
|
|
|
|
ut_assertnonnull(dev);
|
|
|
|
ut_asserteq_str("mmc0.bootdev", dev->name);
|
|
|
|
ut_asserteq(0, mflags);
|
|
|
|
|
|
|
|
ut_assertok(bootstd_test_check_mmc_hunter(uts));
|
|
|
|
|
|
|
|
ut_assertok(bootdev_next_label(&iter, &dev, &mflags));
|
|
|
|
ut_assert_nextline("scanning bus for devices...");
|
|
|
|
ut_assert_skip_to_line(
|
|
|
|
" Capacity: 1.9 MB = 0.0 GB (4095 x 512)");
|
|
|
|
ut_assert_console_end();
|
|
|
|
ut_assertnonnull(dev);
|
|
|
|
ut_asserteq_str("scsi.id0lun0.bootdev", dev->name);
|
|
|
|
ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags);
|
|
|
|
|
2023-01-28 22:00:28 +00:00
|
|
|
/* SCSI is 7th in the list, so bit 6 */
|
|
|
|
ut_asserteq(BIT(MMC_HUNTER) | BIT(6), std->hunters_used);
|
2023-01-17 17:48:10 +00:00
|
|
|
|
|
|
|
ut_assertok(bootdev_next_label(&iter, &dev, &mflags));
|
|
|
|
ut_assert_console_end();
|
|
|
|
ut_assertnonnull(dev);
|
|
|
|
ut_asserteq_str("eth@10002000.bootdev", dev->name);
|
|
|
|
ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_DHCP_ONLY,
|
|
|
|
mflags);
|
|
|
|
|
|
|
|
/* dhcp: Ethernet is first so bit 0 */
|
2023-01-28 22:00:28 +00:00
|
|
|
ut_asserteq(BIT(MMC_HUNTER) | BIT(6) | BIT(0), std->hunters_used);
|
2023-01-17 17:48:10 +00:00
|
|
|
|
|
|
|
ut_assertok(bootdev_next_label(&iter, &dev, &mflags));
|
|
|
|
ut_assert_console_end();
|
|
|
|
ut_assertnonnull(dev);
|
|
|
|
ut_asserteq_str("eth@10002000.bootdev", dev->name);
|
|
|
|
ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_PXE_ONLY,
|
|
|
|
mflags);
|
|
|
|
|
|
|
|
/* pxe: Ethernet is first so bit 0 */
|
2023-01-28 22:00:28 +00:00
|
|
|
ut_asserteq(BIT(MMC_HUNTER) | BIT(6) | BIT(0), std->hunters_used);
|
2023-01-17 17:48:10 +00:00
|
|
|
|
|
|
|
mflags = 123;
|
|
|
|
ut_asserteq(-ENODEV, bootdev_next_label(&iter, &dev, &mflags));
|
|
|
|
ut_asserteq(123, mflags);
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
/* no change */
|
2023-01-28 22:00:28 +00:00
|
|
|
ut_asserteq(BIT(MMC_HUNTER) | BIT(6) | BIT(0), std->hunters_used);
|
2023-01-17 17:48:10 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_next_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
|
|
|
|
UT_TESTF_ETH_BOOTDEV | UT_TESTF_SF_BOOTDEV);
|
2023-01-17 17:48:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Check iterating to the next prioirty in a list */
|
|
|
|
static int bootdev_test_next_prio(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct bootflow_iter iter;
|
|
|
|
struct bootstd_priv *std;
|
|
|
|
struct bootflow bflow;
|
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
|
2023-01-17 17:48:15 +00:00
|
|
|
test_set_eth_enable(false);
|
2023-01-17 17:48:11 +00:00
|
|
|
test_set_skip_delays(true);
|
|
|
|
|
|
|
|
/* get access to the used hunters */
|
|
|
|
ut_assertok(bootstd_get_priv(&std));
|
|
|
|
|
|
|
|
memset(&iter, '\0', sizeof(iter));
|
|
|
|
memset(&bflow, '\0', sizeof(bflow));
|
|
|
|
iter.part = 0;
|
|
|
|
uclass_first_device(UCLASS_BOOTMETH, &bflow.method);
|
|
|
|
iter.cur_prio = 0;
|
2023-02-22 19:17:03 +00:00
|
|
|
iter.flags = BOOTFLOWIF_SHOW;
|
2023-01-17 17:48:11 +00:00
|
|
|
|
|
|
|
dev = NULL;
|
|
|
|
console_record_reset_enable();
|
|
|
|
ut_assertok(bootdev_next_prio(&iter, &dev));
|
|
|
|
ut_assertnonnull(dev);
|
|
|
|
ut_asserteq_str("mmc2.bootdev", dev->name);
|
|
|
|
|
|
|
|
/* hunt flag not set, so this should not use any hunters */
|
|
|
|
ut_asserteq(0, std->hunters_used);
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
/* now try again with hunting enabled */
|
2023-02-22 19:17:03 +00:00
|
|
|
iter.flags = BOOTFLOWIF_SHOW | BOOTFLOWIF_HUNT;
|
2023-01-17 17:48:11 +00:00
|
|
|
iter.cur_prio = 0;
|
|
|
|
iter.part = 0;
|
|
|
|
|
|
|
|
ut_assertok(bootdev_next_prio(&iter, &dev));
|
|
|
|
ut_asserteq_str("mmc2.bootdev", dev->name);
|
2023-01-17 17:48:13 +00:00
|
|
|
ut_assert_nextline("Hunting with: simple_bus");
|
|
|
|
ut_assert_nextline("Found 2 extension board(s).");
|
2023-01-17 17:48:11 +00:00
|
|
|
ut_assert_nextline("Hunting with: mmc");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
2023-01-17 17:48:13 +00:00
|
|
|
ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used);
|
2023-01-17 17:48:11 +00:00
|
|
|
|
|
|
|
ut_assertok(bootdev_next_prio(&iter, &dev));
|
|
|
|
ut_asserteq_str("mmc1.bootdev", dev->name);
|
|
|
|
|
|
|
|
ut_assertok(bootdev_next_prio(&iter, &dev));
|
|
|
|
ut_asserteq_str("mmc0.bootdev", dev->name);
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
ut_assertok(bootdev_next_prio(&iter, &dev));
|
|
|
|
ut_asserteq_str("spi.bin@0.bootdev", dev->name);
|
|
|
|
ut_assert_skip_to_line("Hunting with: spi_flash");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this scans all bootdevs of priority BOOTDEVP_4_SCAN_FAST before it
|
|
|
|
* starts looking at the devices, so we se virtio as well
|
|
|
|
*/
|
|
|
|
ut_assert_nextline("Hunting with: virtio");
|
|
|
|
ut_assert_nextlinen("SF: Detected m25p16");
|
|
|
|
|
|
|
|
ut_assertok(bootdev_next_prio(&iter, &dev));
|
|
|
|
ut_asserteq_str("spi.bin@1.bootdev", dev->name);
|
|
|
|
ut_assert_nextlinen("SF: Detected m25p16");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
/* keep going until there are no more bootdevs */
|
|
|
|
do {
|
|
|
|
ret = bootdev_next_prio(&iter, &dev);
|
|
|
|
} while (!ret);
|
|
|
|
ut_asserteq(-ENODEV, ret);
|
|
|
|
ut_assertnull(dev);
|
2023-01-17 17:48:13 +00:00
|
|
|
ut_asserteq(GENMASK(MAX_HUNTER, 0), std->hunters_used);
|
2023-01-17 17:48:11 +00:00
|
|
|
|
|
|
|
ut_assert_skip_to_line("Hunting with: ethernet");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BOOTSTD_TEST(bootdev_test_next_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
|
|
|
|
UT_TESTF_SF_BOOTDEV);
|