]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
bootstd: Add a new pre-scan priority for bootdevs
authorSimon Glass <sjg@chromium.org>
Tue, 17 Jan 2023 17:48:08 +0000 (10:48 -0700)
committerTom Rini <trini@konsulko.com>
Mon, 23 Jan 2023 23:11:41 +0000 (18:11 -0500)
We need extensions to be set up before we start trying to boot any of the
bootdevs. Add a new priority before all the others for tht sort of thing.
Also add a 'none' option, so that the first one is not 0.

While we are here, comment enum bootdev_prio_t fully and expand the test
for the 'bootdev hunt' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
12 files changed:
boot/bootdev-uclass.c
doc/develop/bootstd.rst
drivers/block/ide.c
drivers/mmc/mmc_bootdev.c
drivers/mtd/spi/sf_bootdev.c
drivers/nvme/nvme-uclass.c
drivers/scsi/scsi_bootdev.c
drivers/usb/host/usb_bootdev.c
drivers/virtio/virtio-uclass.c
include/bootdev.h
net/eth_bootdev.c
test/boot/bootdev.c

index e8686159f2b1baed5522f3873ec6fbbb39f0e2e5..5ed310c554f74e01a0969d883cda1fae15ac2589 100644 (file)
@@ -630,6 +630,7 @@ static int build_order(struct udevice *bootstd, struct udevice **order,
 int bootdev_setup_iter_order(struct bootflow_iter *iter, struct udevice **devp)
 {
        struct udevice *bootstd, *dev = *devp, **order;
+       bool show = iter->flags & BOOTFLOWF_SHOW;
        struct uclass *uc;
        int count, upto;
        int ret;
@@ -640,6 +641,13 @@ int bootdev_setup_iter_order(struct bootflow_iter *iter, struct udevice **devp)
                return log_msg_ret("std", ret);
        }
 
+       /* hunt for any pre-scan devices */
+       if (iter->flags & BOOTFLOWF_HUNT) {
+               ret = bootdev_hunt_prio(BOOTDEVP_1_PRE_SCAN, show);
+               if (ret)
+                       return log_msg_ret("pre", ret);
+       }
+
        /* Handle scanning a single device */
        if (dev) {
                iter->flags |= BOOTFLOWF_SINGLE_DEV;
index 1ccc49424ebd1869346fbdf85e9082549f6fc009..bfa8cbd75613f284e19c63b25058a6aa7b4b5e47 100644 (file)
@@ -211,7 +211,7 @@ A bootdev driver is typically fairly simple. Here is one for mmc::
     {
         struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
 
-        ucp->prio = BOOTDEVP_0_INTERNAL_FAST;
+        ucp->prio = BOOTDEVP_2_INTERNAL_FAST;
 
         return 0;
     }
index 80c8b64de2f92e58aeda82f8021cda7233d3740f..1ad9b6c1267ef10c482af69b59e3c3d0cadd145f 100644 (file)
@@ -1060,7 +1060,7 @@ static int ide_bootdev_bind(struct udevice *dev)
 {
        struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
 
-       ucp->prio = BOOTDEVP_3_SCAN_SLOW;
+       ucp->prio = BOOTDEVP_5_SCAN_SLOW;
 
        return 0;
 }
@@ -1089,7 +1089,7 @@ U_BOOT_DRIVER(ide_bootdev) = {
 };
 
 BOOTDEV_HUNTER(ide_bootdev_hunter) = {
-       .prio           = BOOTDEVP_3_SCAN_SLOW,
+       .prio           = BOOTDEVP_5_SCAN_SLOW,
        .uclass         = UCLASS_IDE,
        .hunt           = ide_bootdev_hunt,
        .drv            = DM_DRIVER_REF(ide_bootdev),
index 300208f0c71c2fcd34a5b495969fba380239af40..b57b8a62276d8bbfc5d3b50a803be71efbe886a0 100644 (file)
@@ -15,7 +15,7 @@ static int mmc_bootdev_bind(struct udevice *dev)
 {
        struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
 
-       ucp->prio = BOOTDEVP_0_INTERNAL_FAST;
+       ucp->prio = BOOTDEVP_2_INTERNAL_FAST;
 
        return 0;
 }
@@ -37,7 +37,7 @@ U_BOOT_DRIVER(mmc_bootdev) = {
 };
 
 BOOTDEV_HUNTER(mmc_bootdev_hunter) = {
-       .prio           = BOOTDEVP_0_INTERNAL_FAST,
+       .prio           = BOOTDEVP_2_INTERNAL_FAST,
        .uclass         = UCLASS_MMC,
        .drv            = DM_DRIVER_REF(mmc_bootdev),
 };
index 2272e8567ce6310cb68d24d0f675ec8422a41ab9..d6b47b11ce451e430463a5a18d4469562b9f70de 100644 (file)
@@ -53,7 +53,7 @@ static int sf_bootdev_bind(struct udevice *dev)
 {
        struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
 
-       ucp->prio = BOOTDEVP_2_SCAN_FAST;
+       ucp->prio = BOOTDEVP_4_SCAN_FAST;
 
        return 0;
 }
@@ -76,7 +76,7 @@ U_BOOT_DRIVER(sf_bootdev) = {
 };
 
 BOOTDEV_HUNTER(sf_bootdev_hunter) = {
-       .prio           = BOOTDEVP_2_SCAN_FAST,
+       .prio           = BOOTDEVP_4_SCAN_FAST,
        .uclass         = UCLASS_SPI_FLASH,
        .drv            = DM_DRIVER_REF(sf_bootdev),
 };
index 7a8ff06e78cf9e2cecec758507aee869767a82b4..f3af6a27b63bdb70db7f77e2ababe942255760e0 100644 (file)
@@ -17,7 +17,7 @@ static int nvme_bootdev_bind(struct udevice *dev)
 {
        struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
 
-       ucp->prio = BOOTDEVP_2_SCAN_FAST;
+       ucp->prio = BOOTDEVP_4_SCAN_FAST;
 
        return 0;
 }
@@ -62,7 +62,7 @@ U_BOOT_DRIVER(nvme_bootdev) = {
 };
 
 BOOTDEV_HUNTER(nvme_bootdev_hunter) = {
-       .prio           = BOOTDEVP_2_SCAN_FAST,
+       .prio           = BOOTDEVP_4_SCAN_FAST,
        .uclass         = UCLASS_NVME,
        .hunt           = nvme_bootdev_hunt,
        .drv            = DM_DRIVER_REF(nvme_bootdev),
index 2367b33da9cb2bfa95709c79e6265fb7f1ea468d..991013fe1ef25df63645269a6dff601a82f02745 100644 (file)
@@ -16,7 +16,7 @@ static int scsi_bootdev_bind(struct udevice *dev)
 {
        struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
 
-       ucp->prio = BOOTDEVP_2_SCAN_FAST;
+       ucp->prio = BOOTDEVP_4_SCAN_FAST;
 
        return 0;
 }
@@ -55,7 +55,7 @@ U_BOOT_DRIVER(scsi_bootdev) = {
 };
 
 BOOTDEV_HUNTER(scsi_bootdev_hunter) = {
-       .prio           = BOOTDEVP_2_SCAN_FAST,
+       .prio           = BOOTDEVP_4_SCAN_FAST,
        .uclass         = UCLASS_SCSI,
        .hunt           = scsi_bootdev_hunt,
        .drv            = DM_DRIVER_REF(scsi_bootdev),
index 66d0b6ae8f5ee019f6b6b4d9ec221940741ee7b0..32919f99286501b64d6cc140fc78f0757ddae4a4 100644 (file)
@@ -15,7 +15,7 @@ static int usb_bootdev_bind(struct udevice *dev)
 {
        struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
 
-       ucp->prio = BOOTDEVP_3_SCAN_SLOW;
+       ucp->prio = BOOTDEVP_5_SCAN_SLOW;
 
        return 0;
 }
@@ -42,7 +42,7 @@ U_BOOT_DRIVER(usb_bootdev) = {
 };
 
 BOOTDEV_HUNTER(usb_bootdev_hunter) = {
-       .prio           = BOOTDEVP_3_SCAN_SLOW,
+       .prio           = BOOTDEVP_5_SCAN_SLOW,
        .uclass         = UCLASS_USB,
        .hunt           = usb_bootdev_hunt,
        .drv            = DM_DRIVER_REF(usb_bootdev),
index 27efac0d48e9044adef5b2f5ace1198e76d900d5..91af412ec1d6b01f0182e1939d87ad25636bbd7e 100644 (file)
@@ -360,7 +360,7 @@ static int virtio_bootdev_bind(struct udevice *dev)
 {
        struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
 
-       ucp->prio = BOOTDEVP_2_SCAN_FAST;
+       ucp->prio = BOOTDEVP_4_SCAN_FAST;
 
        return 0;
 }
@@ -405,7 +405,7 @@ U_BOOT_DRIVER(virtio_bootdev) = {
 };
 
 BOOTDEV_HUNTER(virtio_bootdev_hunter) = {
-       .prio           = BOOTDEVP_2_SCAN_FAST,
+       .prio           = BOOTDEVP_4_SCAN_FAST,
        .uclass         = UCLASS_VIRTIO,
        .hunt           = virtio_bootdev_hunt,
        .drv            = DM_DRIVER_REF(virtio_bootdev),
index b7973fa57603adcf31aefa4027611f5d37c4f3b0..65d14f246860d3fabfe198a2d3b8b5fa4b025916 100644 (file)
@@ -21,15 +21,36 @@ struct udevice;
  *
  * Smallest value is the highest priority. By default, bootdevs are scanned from
  * highest to lowest priority
+ *
+ * BOOTDEVP_0_NONE: Invalid value, do not use
+ * @BOOTDEVP_6_PRE_SCAN: Scan bootdevs with this priority always, before
+ * starting any bootflow scan
+ * @BOOTDEVP_2_INTERNAL_FAST: Internal devices which don't need scanning and
+ * generally very quick to access, e.g. less than 100ms
+ * @BOOTDEVP_3_INTERNAL_SLOW: Internal devices which don't need scanning but
+ * take a significant fraction of a second to access
+ * @BOOTDEVP_4_SCAN_FAST: Extenal devices which need scanning or bus
+ * enumeration to find, but this enumeration happens quickly, typically under
+ * 100ms
+ * @BOOTDEVP_5_SCAN_SLOW: Extenal devices which need scanning or bus
+ * enumeration to find. The enumeration takes significant fraction of a second
+ * to complete
+ * @BOOTDEVP_6_NET_BASE: Basic network devices which are quickly and easily
+ * available. Typically used for an internal Ethernet device
+ * @BOOTDEVP_7_NET_FALLBACK: Secondary network devices which require extra time
+ * to start up, or are less desirable. Typically used for secondary Ethernet
+ * devices. Note that USB ethernet devices are found during USB enumeration,
+ * so do not use this priority
  */
 enum bootdev_prio_t {
-       BOOTDEVP_0_INTERNAL_FAST        = 10,
-       BOOTDEVP_1_INTERNAL_SLOW        = 20,
-       BOOTDEVP_2_SCAN_FAST            = 30,
-       BOOTDEVP_3_SCAN_SLOW            = 40,
-       BOOTDEVP_4_NET_BASE             = 50,
-       BOOTDEVP_5_NET_FALLBACK         = 60,
-       BOOTDEVP_6_SYSTEM               = 70,
+       BOOTDEVP_0_NONE,
+       BOOTDEVP_1_PRE_SCAN,
+       BOOTDEVP_2_INTERNAL_FAST,
+       BOOTDEVP_3_INTERNAL_SLOW,
+       BOOTDEVP_4_SCAN_FAST,
+       BOOTDEVP_5_SCAN_SLOW,
+       BOOTDEVP_6_NET_BASE,
+       BOOTDEVP_7_NET_FALLBACK,
 
        BOOTDEVP_COUNT,
 };
index bcbb35a74cd6a5a83c25070bf3bf87ddab82fd9c..13e5fcd3bdfe7542c30c169e4f4e8e9f1e4169ca 100644 (file)
@@ -60,7 +60,7 @@ static int eth_bootdev_bind(struct udevice *dev)
 {
        struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
 
-       ucp->prio = BOOTDEVP_4_NET_BASE;
+       ucp->prio = BOOTDEVP_6_NET_BASE;
 
        return 0;
 }
@@ -112,7 +112,7 @@ U_BOOT_DRIVER(eth_bootdev) = {
 };
 
 BOOTDEV_HUNTER(eth_bootdev_hunt) = {
-       .prio           = BOOTDEVP_4_NET_BASE,
+       .prio           = BOOTDEVP_6_NET_BASE,
        .uclass         = UCLASS_ETH,
        .hunt           = eth_bootdev_hunt,
        .drv            = DM_DRIVER_REF(eth_bootdev),
index f9653633a68d9884207d4614030d7bafc859f678..86607f7695e3cee2e3ee62be916e6a24ad22b5fe 100644 (file)
@@ -247,14 +247,14 @@ static int bootdev_test_hunter(struct unit_test_state *uts)
        bootdev_list_hunters(std);
        ut_assert_nextline("Prio  Used  Uclass           Hunter");
        ut_assert_nextlinen("----");
-       ut_assert_nextline("  50        ethernet         eth_bootdev");
-       ut_assert_nextline("  40        ide              ide_bootdev");
-       ut_assert_nextline("  10        mmc              mmc_bootdev");
-       ut_assert_nextline("  30        nvme             nvme_bootdev");
-       ut_assert_nextline("  30        scsi             scsi_bootdev");
-       ut_assert_nextline("  30        spi_flash        sf_bootdev");
-       ut_assert_nextline("  40        usb              usb_bootdev");
-       ut_assert_nextline("  30        virtio           virtio_bootdev");
+       ut_assert_nextline("   6        ethernet         eth_bootdev");
+       ut_assert_nextline("   5        ide              ide_bootdev");
+       ut_assert_nextline("   2        mmc              mmc_bootdev");
+       ut_assert_nextline("   4        nvme             nvme_bootdev");
+       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");
        ut_assert_nextline("(total hunters: 8)");
        ut_assert_console_end();
 
@@ -284,17 +284,28 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
        ut_assertok(run_command("bootdev hunt -l", 0));
        ut_assert_nextline("Prio  Used  Uclass           Hunter");
        ut_assert_nextlinen("----");
+       ut_assert_nextline("   6        ethernet         eth_bootdev");
+       ut_assert_skip_to_line("(total hunters: 8)");
+       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");
        ut_assert_skip_to_line("(total hunters: 8)");
        ut_assert_console_end();
 
        /* Scan all hunters */
        sandbox_set_eth_enable(false);
-
+       test_set_skip_delays(true);
        ut_assertok(run_command("bootdev hunt", 0));
        ut_assert_nextline("Hunting with: ethernet");
        ut_assert_nextline("Hunting with: ide");
        ut_assert_nextline("Bus 0: not available  ");
-       ut_assert_nextline("Hunting with: mmc");
+
+       /* mmc hunter has already been used so should not run again */
+
        ut_assert_nextline("Hunting with: nvme");
        ut_assert_nextline("Hunting with: scsi");
        ut_assert_nextline("scanning bus for devices...");
@@ -309,14 +320,14 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
        ut_assertok(run_command("bootdev hunt -l", 0));
        ut_assert_nextlinen("Prio");
        ut_assert_nextlinen("----");
-       ut_assert_nextline("  50     *  ethernet         eth_bootdev");
-       ut_assert_nextline("  40     *  ide              ide_bootdev");
-       ut_assert_nextline("  10     *  mmc              mmc_bootdev");
-       ut_assert_nextline("  30     *  nvme             nvme_bootdev");
-       ut_assert_nextline("  30     *  scsi             scsi_bootdev");
-       ut_assert_nextline("  30     *  spi_flash        sf_bootdev");
-       ut_assert_nextline("  40     *  usb              usb_bootdev");
-       ut_assert_nextline("  30     *  virtio           virtio_bootdev");
+       ut_assert_nextline("   6     *  ethernet         eth_bootdev");
+       ut_assert_nextline("   5     *  ide              ide_bootdev");
+       ut_assert_nextline("   2     *  mmc              mmc_bootdev");
+       ut_assert_nextline("   4     *  nvme             nvme_bootdev");
+       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");
        ut_assert_nextline("(total hunters: 8)");
        ut_assert_console_end();
 
@@ -370,14 +381,14 @@ static int bootdev_test_hunt_prio(struct unit_test_state *uts)
        test_set_skip_delays(true);
 
        console_record_reset_enable();
-       ut_assertok(bootdev_hunt_prio(BOOTDEVP_2_SCAN_FAST, false));
+       ut_assertok(bootdev_hunt_prio(BOOTDEVP_4_SCAN_FAST, false));
        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 */
-       ut_assertok(bootdev_hunt_prio(BOOTDEVP_3_SCAN_SLOW, true));
+       ut_assertok(bootdev_hunt_prio(BOOTDEVP_5_SCAN_SLOW, true));
        ut_assert_nextline("Hunting with: ide");
        ut_assert_nextline("Bus 0: not available  ");
        ut_assert_nextline("Hunting with: usb");