bootdev: few fixes for automatic boot
v3 cover bootdev: few fixes for automatic boot
This series addresses few findings in bootdev code.
Patch 1 some typo fixes in bootdev header.
Patch 2 fix for automatic boots in case higher-priority bootdevs fail
to be hunted.
Patch 3 adds unit test for patch 2.
CI: https://github.com/u-boot/u-boot/pull/991
Denis Mukhin (3):
bootdev: fix typos
bootdev: scan boot devices at each priority level
test: bootdev: scan with a broken high-priority device
boot/bootdev-uclass.c | 2 -- drivers/block/Makefile | 2 +- drivers/block/host-uclass.c | 17 +++++++++ drivers/block/sandbox-bootdev.c | 62 +++++++++++++++++++++++++++++++++ include/bootdev.h | 8 ++--- include/sandbox_host.h | 18 ++++++++++ test/boot/bootdev.c | 25 +++++++------ test/boot/bootflow.c | 51 +++++++++++++++++++++++++++ test/boot/bootstd_common.h | 2 +- 9 files changed, 168 insertions(+), 19 deletions(-) create mode 100644 drivers/block/sandbox-bootdev.c
Signature · 1 line
2.54.0
PATCH v3 1/3 bootdev: fix typos
From: Denis Mukhin <[email protected]>
---
Changes since v2:
- n/a
Changes since v1:
- added Heinrich's R-b
- added Simon's R-b
--- include/bootdev.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
include/bootdev.h +4 -4
@@ -30,10 +30,10 @@ struct udevice;* 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 +* @BOOTDEVP_4_SCAN_FAST: External 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 +* @BOOTDEVP_5_SCAN_SLOW: External 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
@@ -327,7 +327,7 @@ int bootdev_hunt_and_find_by_label(const char *label, struct udevice **devp,* Bootdev scanners are used as needed. For example a label "mmc1" results in * running the "mmc" bootdrv. * -* @iter: Interation info, containing iter->cur_label +* @iter: Iteration info, containing iter->cur_label * @devp: New bootdev found, if any was found * @method_flagsp: If non-NULL, returns any flags implied by the label * (enum bootflow_meth_flags_t), 0 if none
@@ -342,7 +342,7 @@ int bootdev_next_label(struct bootflow_iter *iter, struct udevice **devp,* This moves @devp to the next bootdev with the current priority. If there is * none, then it moves to the next priority and scans for new bootdevs there. * -* @iter: Interation info, containing iter->cur_prio +* @iter: Iteration info, containing iter->cur_prio * @devp: On entry this is the previous bootdev that was considered. On exit * this is the new bootdev, if any was found * Returns 0 on success (*devp is updated), -ENODEV if there are no more
Signature · 1 line
2.54.0
PATCH v3 2/3 bootdev: scan boot devices at each priority level
In reply to [email protected]From: Denis Mukhin <[email protected]>
Currently, default 'bootflow scan -lb' will stop booting the board if any of higher-priority bootdevs fail to be hunted even if there are bootdevs of lower priority.
For example, if the board has both NVMe (priority 4) and USB MSD devices (priority 5), and if NVMe bootdev hunt fails (in the event of a bad NVMe firmware update), USB (which may be a recovery bootdev) is never hunted automatically, leaving the board at the U-Boot prompt (user intervention is needed, e.g. something like 'bootflow scan usb' to hunt USB).
Fix bootdev_next_prio() to scan bootdevs at the lower priority level by not exiting the scan loop early.
Keep the existing logging verbosity unchanged and rely on the failing subsystem to provide a suitable diagnostic message.
---
Changes since v2:
- added Simon's R-b
Changes since v1:
- corrected the commit message
--- boot/bootdev-uclass.c | 2 -- 1 file changed, 2 deletions(-)
boot/bootdev-uclass.c +0 -2
@@ -664,8 +664,6 @@ int bootdev_next_prio(struct bootflow_iter *iter, struct udevice **devp) BOOTFLOWIF_SHOW);log_debug ("- bootdev_hunt_prio() ret %d\n" , ret); -if (ret) -return log_msg_ret ("hun" , ret); } }else { ret =device_probe (dev);
Signature · 1 line
2.54.0
PATCH v3 3/3 test: bootdev: scan with a broken high-priority device
In reply to [email protected]From: Denis Mukhin <[email protected]>
Add bootdev_hunt_fallthrough() test to verify that 'bootflow scan -l' falls back to a lower-priority bootdev when a higher-priority hunter fails.
Introduce a simple 'sandbox-bootdev' device for the test. The new bootdev can be configured to produce an error at the hunting stage.
Adjust boot{dev,flow} tests which depend on bootdev hunters.
---
Changes since v2:
- dropped 'flags' from 'host_priv'
- added description for 'flags' in host_sb_plat
- switched to log_xxx() calls in sandbox-bootdev.c
- corrected sandbox_bootdev_hunt()
- updated boot{dev,flow} tests which depend on bootdev hunters
Changes since v1:
- new patch
--- drivers/block/Makefile | 2 +- drivers/block/host-uclass.c | 17 +++++++++ drivers/block/sandbox-bootdev.c | 62 +++++++++++++++++++++++++++++++++ include/sandbox_host.h | 18 ++++++++++ test/boot/bootdev.c | 25 +++++++------ test/boot/bootflow.c | 51 +++++++++++++++++++++++++++ test/boot/bootstd_common.h | 2 +- 7 files changed, 164 insertions(+), 13 deletions(-) create mode 100644 drivers/block/sandbox-bootdev.c
drivers/block/Makefile +1 -1
@@ -13,7 +13,7 @@ ifndef CONFIG_XPL_BUILD obj-$(CONFIG_IDE) += ide.o obj-$(CONFIG_RKMTD) += rkmtd.o endif -obj-$(CONFIG_SANDBOX) += sandbox.o host-uclass.o host_dev.o +obj-$(CONFIG_SANDBOX) += sandbox.o sandbox-bootdev.o host-uclass.o host_dev.o obj-$(CONFIG_$(PHASE_)BLOCK_CACHE) += blkcache.o obj-$(CONFIG_$(PHASE_)BLKMAP) += blkmap.o obj-$(CONFIG_$(PHASE_)BLKMAP) += blkmap_helper.o
drivers/block/host-uclass.c +17 -0
@@ -150,6 +150,23 @@ struct udevice *host_find_by_label(const char *label)return NULL ; } +int host_set_flags_by_label (const char *label,unsigned int flags) +{ +struct udevice *dev; +struct uclass *uc; + + uclass_id_foreach_dev(UCLASS_HOST, dev, uc) { +struct host_sb_plat *plat =dev_get_plat (dev); + +if (plat->label && !strcmp (label, plat->label)) { + plat->flags = flags; +return 0 ; + } + } + +return -ENODEV ; +} +struct udevice *host_get_cur_dev (void ) {struct uclass *uc =uclass_find (UCLASS_HOST );
drivers/block/sandbox-bootdev.c new file +62 -0
62 lines not on this page · raw message
include/sandbox_host.h +18 -0
@@ -8,17 +8,26 @@#ifndef __SANDBOX_HOST__#define __SANDBOX_HOST__ +/** +* Device flags. +*/ +enum { +BLK_HOST_BROKEN =BIT (0 ),/* Simulate broken device */ +}; +/** * struct host_sb_plat - platform data for a host device * * @label: Label for this device (allocated) * @filename: Name of file this is attached to, or NULL (allocated) * @fd: File descriptor of file, or 0 for none (file is not open) +* @flags: Device flags (e.g. for unit tests). */ struct host_sb_plat {char *label;char *filename;int fd; +unsigned int flags; };/**
@@ -122,4 +131,13 @@ struct udevice *host_get_cur_dev(void);*/ void host_set_cur_dev (struct udevice *dev); +/** +* host_set_flags_by_label() - Set the host device test flags +* +* @label: Label of the attachment, e.g. "test1" +* @flags: Device flags +* Returns: 0 if OK, -ve on error +*/ +int host_set_flags_by_label (const char *label,unsigned int flags); +#endif /* __SANDBOX_HOST__ */
test/boot/bootdev.c +14 -11
@@ -384,19 +384,20 @@ static int bootdev_test_hunter(struct unit_test_state *uts)ut_assert_nextline (" 2 mmc mmc_bootdev" );ut_assert_nextline (" 4 nvme nvme_bootdev" );ut_assert_nextline (" 4 qfw qfw_bootdev" ); +ut_assert_nextline (" 4 host sandbox_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: 9)" ); +ut_assert_nextline ("(total hunters: 10)" );ut_assert_console_end ();ut_assertok (bootdev_hunt ("usb1" , false));ut_assert_skip_to_line ("Bus usb@1: 5 USB Device(s) found" );ut_assert_console_end (); -/* USB is 8th in the list, so bit 7 */ -ut_asserteq (BIT (7 ), std->hunters_used); +/* USB is 9th in the list, so bit 8 */ +ut_asserteq (BIT (8 ), std->hunters_used);return 0 ; }
@@ -417,7 +418,7 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)ut_assert_nextline ("Prio Used Uclass Hunter" );ut_assert_nextlinen ("----" );ut_assert_nextline (" 6 ethernet eth_bootdev" ); -ut_assert_skip_to_line ("(total hunters: 9)" ); +ut_assert_skip_to_line ("(total hunters: 10)" );ut_assert_console_end ();/* Use the MMC hunter and see that it updates */
@@ -425,7 +426,7 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)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: 9)" ); +ut_assert_skip_to_line ("(total hunters: 10)" );ut_assert_console_end ();/* Scan all hunters */
@@ -441,6 +442,7 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)ut_assert_nextline ("Hunting with: nvme" );ut_assert_nextline ("Hunting with: qfw" ); +ut_assert_nextline ("Hunting with: host" );ut_assert_nextline ("Hunting with: scsi" );ut_assert_nextline ("scanning bus for devices..." );ut_assert_skip_to_line ("Hunting with: spi_flash" );
@@ -458,11 +460,12 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)ut_assert_nextline (" 2 * mmc mmc_bootdev" );ut_assert_nextline (" 4 * nvme nvme_bootdev" );ut_assert_nextline (" 4 * qfw qfw_bootdev" ); +ut_assert_nextline (" 4 * host sandbox_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: 9)" ); +ut_assert_nextline ("(total hunters: 10)" );ut_assert_console_end ();ut_asserteq (GENMASK (MAX_HUNTER ,0 ), std->hunters_used);
@@ -646,8 +649,8 @@ static int bootdev_test_next_label(struct unit_test_state *uts)ut_asserteq_str ("scsi.id0lun0.bootdev" , dev->name);ut_asserteq (BOOTFLOW_METHF_SINGLE_UCLASS , mflags); -/* SCSI is 6th in the list, so bit 5 */ -ut_asserteq (BIT (MMC_HUNTER ) |BIT (5 ), std->hunters_used); +/* SCSI is 7th in the list, so bit 6 */ +ut_asserteq (BIT (MMC_HUNTER ) |BIT (6 ), std->hunters_used);ut_assertok (bootdev_next_label (&iter, &dev, &mflags));ut_assert_console_end ();
@@ -657,7 +660,7 @@ static int bootdev_test_next_label(struct unit_test_state *uts) mflags);/* dhcp: Ethernet is first so bit 0 */ -ut_asserteq (BIT (MMC_HUNTER ) |BIT (5 ) |BIT (0 ), std->hunters_used); +ut_asserteq (BIT (MMC_HUNTER ) |BIT (6 ) |BIT (0 ), std->hunters_used);ut_assertok (bootdev_next_label (&iter, &dev, &mflags));ut_assert_console_end ();
@@ -667,7 +670,7 @@ static int bootdev_test_next_label(struct unit_test_state *uts) mflags);/* pxe: Ethernet is first so bit 0 */ -ut_asserteq (BIT (MMC_HUNTER ) |BIT (5 ) |BIT (0 ), std->hunters_used); +ut_asserteq (BIT (MMC_HUNTER ) |BIT (6 ) |BIT (0 ), std->hunters_used); mflags =123 ;ut_asserteq (-ENODEV ,bootdev_next_label (&iter, &dev, &mflags));
@@ -675,7 +678,7 @@ static int bootdev_test_next_label(struct unit_test_state *uts)ut_assert_console_end ();/* no change */ -ut_asserteq (BIT (MMC_HUNTER ) |BIT (5 ) |BIT (0 ), std->hunters_used); +ut_asserteq (BIT (MMC_HUNTER ) |BIT (6 ) |BIT (0 ), std->hunters_used);return 0 ; }
test/boot/bootflow.c +51 -0
60 lines not on this page · raw message
test/boot/bootstd_common.h +1 -1
@@ -21,7 +21,7 @@#define TEST_VERNUM 0x00010002enum { -MAX_HUNTER =8 , +MAX_HUNTER =9 ,MMC_HUNTER =2 ,/* ID of MMC hunter */ };
Signature · 1 line
2.54.0
Re: [PATCH v3 3/3] test: bootdev: scan with a broken high-priority device
Hi Denis,
Quoted 13 lines · None
test: bootdev: scan with a broken high-priority device
Add
bootdev_hunt_fallthrough()test to verify that 'bootflow scan -l' falls back to a lower-priority bootdev when a higher-priority hunter fails.Introduce a simple 'sandbox-bootdev' device for the test. The new bootdev can be configured to produce an error at the hunting stage.
Adjust boot{dev,flow} tests which depend on bootdev hunters.
Signed-off-by Denis Mukhin <[email protected]>
Quoted 8 lines
drivers/block/Makefile| 2 +-drivers/block/host-uclass.c | 17 +++++++++++ drivers/block/sandbox-bootdev.c | 62 +++++++++++++++++++++++++++++++++++++++++ include/sandbox_host.h | 18 ++++++++++++ test/boot/bootdev.c | 25 +++++++++-------- test/boot/bootflow.c | 51 +++++++++++++++++++++++++++++++++ test/boot/bootstd_common.h | 2 +- 7 files changed, 164 insertions(+), 13 deletions(-)
Thanks for digging into this....sorry quite a bit of minor feedback.
Quoted 8 lines
drivers/block/host-uclass.c +6
-0@@ -150,6 +150,23 @@ struct udevice *host_find_by_label(const char *label) +int host_set_flags_by_label (const char *label,unsigned int flags) +{ +struct udevice *dev; +struct uclass *uc; + + uclass_id_foreach_dev(UCLASS_HOST, dev, uc) {
drivers/block/host-uclass.c struct udevice *host_find_by_label(const char *label) · line 165
Quoted 10 lines
drivers/block/host-uclass.c +10
-0+struct host_sb_plat *plat =dev_get_plat (dev); + +if (plat->label && !strcmp (label, plat->label)) { + plat->flags = flags; +return 0 ; + } + } + +return -ENODEV ; +}
Please reuse host_find_by_label() rather than duplicating the loop:
dev = host_find_by_label(label);
if (!dev)
return -ENODEV;
plat = dev_get_plat(dev);
plat->flags = flags;return 0;
Quoted 13 lines
drivers/block/sandbox-bootdev.c +11
-0@@ -0,0 +1,62 @@ +static int sandbox_bootdev_hunt (struct bootdev_hunter *info,bool show) +{ +struct udevice *dev; +struct uclass *uc; +int ret; + + uclass_id_foreach_dev(UCLASS_HOST, dev, uc) { +struct host_sb_plat *plat =dev_get_plat (dev); + +log_debug ("hunting %s\n" , plat->label); +
drivers/block/sandbox-bootdev.c line 21
Quoted 10 lines
drivers/block/sandbox-bootdev.c +10
-0+if (plat->flags &BLK_HOST_BROKEN ) { + ret = -ETIME ; +log_err ("cannot hunt sandbox device '%s': %d\n" , + plat->label, ret); +return ret; + } + } + +return 0 ; +}
This hunter never binds a bootdev - it only exists to fail. Please add a comment at the top of the file making that clear, so nobody copies it as an example of a real hunter.
I'd also prefer to drop the log_err() - a hunter failing is a legitimate outcome that patch 2 makes the scan loop tolerate, and the caller is the right place to decide whether that warrants user-visible noise. At least for here, log_debug() is sufficient.
drivers/block/sandbox-bootdev.c line 2
Quoted 4 lines
drivers/block/sandbox-bootdev.c +2
-0@@ -0,0 +1,62 @@ +struct bootdev_ops sandbox_bootdev_ops = { +};
Please make this static const - it is only referenced from the U_BOOT_DRIVER() in this file.
include/sandbox_host.h line 13
Quoted 8 lines
include/sandbox_host.h +6
-0@@ -8,17 +8,26 @@ +/** +* Device flags. +*/ +enum { +BLK_HOST_BROKEN =BIT (0 ),/* Simulate broken device */ +};
The BLK_ prefix reads as a block-layer flag, but this lives on host_sb_plat and is consumed by the sandbox bootdev hunter. Please rename to HOST_FLAG_BROKEN or similar and give the enum a tag so it can be used as a type. Also, kerneldoc on an unnamed enum does not generate useful output - either name it or drop the /** */.
test/boot/bootflow.c static int bootstd_images(struct unit_test_state *uts) · line 1538
Quoted 7 lines
test/boot/bootflow.c +5
-0@@ -1532,3 +1534,52 @@ static int bootstd_images(struct unit_test_state *uts) +/* Reset bootstd state */ +ut_assertok (bootstd_get_priv (&std)); + old_order = std->bootdev_order; + std->bootdev_order =NULL ; + std->hunters_used =0 ;
Please use bootstd_test_drop_bootdev_order(uts) rather than open-coding this. As written, any ut_assertok() failure before the 'Clean up' block leaks the modified bootdev_order into subsequent tests.
test/boot/bootflow.c static int bootstd_images(struct unit_test_state *uts) · line 1537
Quoted 6 lines
test/boot/bootflow.c +4
-0@@ -1532,3 +1534,52 @@ static int bootstd_images(struct unit_test_state *uts) +ut_assertok (run_command ("bootflow scan -l" ,0 )); + +/* USB was hunted despite the sandbox hunter failure */ +ut_assert_skip_to_line ("Bus usb@1: 5 USB Device(s) found" );
Good test of the symptom, but please also assert that the sandbox hunter's failure was reached - e.g. check std->hunters_used has the sandbox hunter bit set, or ut_assert_skip_to_line() on its error output before the USB line. Otherwise a regression that simply skips priority 4 entirely would still pass.
test/boot/bootflow.c static int bootstd_images(struct unit_test_state *uts) · line 1536
Quoted 5 lines
test/boot/bootflow.c +3
-0@@ -1532,3 +1534,52 @@ static int bootstd_images(struct unit_test_state *uts) +BOOTSTD_TEST (bootdev_hunt_fallthrough, +UTF_DM |UTF_SCAN_FDT |UTF_SF_BOOTDEV |UTF_CONSOLE ); +#endif /* CONFIG_SANDBOX */
Continuation should use a tab, not spaces. Also, test/boot/ is already only built for sandbox in practice, so please drop the #ifdef CONFIG_SANDBOX guard (or gate it the same way other sandbox-only bits in this file are gated).
Quoted 2 lines
commit
86288522b3f41eb776f9b0c7dc2d342a2ba078d9
Adjust boot{dev,flow} tests which depend on bootdev hunters.
Please mention in the commit message that this also adds a new host_set_flags_by_label() API and a flags field to host_sb_plat - that is not merely an 'adjustment' to existing tests.
Regards,
Simon