bootdev: few fixes for automatic boot
v2 cover bootdev: few fixes for automatic boot
This mini-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.
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 | 18 ++++++++++ drivers/block/sandbox-bootdev.c | 64 +++++++++++++++++++++++++++++++++ include/bootdev.h | 8 ++--- include/sandbox_host.h | 17 +++++++++ test/boot/bootflow.c | 51 ++++++++++++++++++++++++++ 7 files changed, 155 insertions(+), 7 deletions(-) create mode 100644 drivers/block/sandbox-bootdev.c
Signature · 1 line
2.54.0
PATCH v2 1/3 bootdev: fix typos
From: Denis Mukhin <[email protected]>
---
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 v2 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 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
Re: [PATCH v2 2/3] bootdev: scan boot devices at each priority level
Quoted 15 lines · None
bootdev: scan boot devices at each priority level
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.
Quoted 7 lines
Keep the existing logging verbosity unchanged and rely on the failing subsystem to provide a suitable diagnostic message.
Signed-off-by Denis Mukhin <[email protected]>
boot/bootdev-uclass.c| 2 --1 file changed, 2 deletions(-)
PATCH v2 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.
---
Changes since v1:
- new patch
--- drivers/block/Makefile | 2 +- drivers/block/host-uclass.c | 18 ++++++++++ drivers/block/sandbox-bootdev.c | 64 +++++++++++++++++++++++++++++++++ include/sandbox_host.h | 17 +++++++++ test/boot/bootflow.c | 51 ++++++++++++++++++++++++++ 5 files changed, 151 insertions(+), 1 deletion(-) 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 +18 -0
@@ -27,6 +27,7 @@ DECLARE_GLOBAL_DATA_PTR;*/ struct host_priv {struct udevice *cur_dev; +unsigned int flags; }; int host_create_device(const char *label, bool removable, unsigned long blksz,
@@ -150,6 +151,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 +64 -0
64 lines not on this page · raw message
include/sandbox_host.h +17 -0
@@ -8,6 +8,13 @@#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 *
@@ -19,6 +26,7 @@ struct host_sb_plat {char *label;char *filename;int fd; +unsigned int flags; };/**
@@ -122,4 +130,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/bootflow.c +51 -0
60 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v2 3/3] test: bootdev: scan with a broken high-priority device
Hi Denis,
Quoted 20 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.
Signed-off-by Denis Mukhin <[email protected]>
drivers/block/Makefile| 2 +-drivers/block/host-uclass.c | 18 ++++++++++++ drivers/block/sandbox-bootdev.c | 64 +++++++++++++++++++++++++++++++++++++++++ include/sandbox_host.h | 17 +++++++++++ test/boot/bootflow.c | 51 ++++++++++++++++++++++++++++++++ 5 files changed, 151 insertions(+), 1 deletion(-)
drivers/block/host-uclass.c DECLARE_GLOBAL_DATA_PTR; · line 30
Quoted 4 lines
drivers/block/host-uclass.c +1
-0@@ -27,6 +27,7 @@ DECLARE_GLOBAL_DATA_PTR;struct host_priv {struct udevice *cur_dev; +unsigned int flags; };
This flags field is never read or written - the flags that matter are in host_sb_plat::flags, where host_set_flags_by_label() writes them and sandbox_bootdev_hunt() reads them. Please remove it.
drivers/block/sandbox-bootdev.c line 8
Quoted 10 lines
drivers/block/sandbox-bootdev.c +8
-0@@ -0,0 +1,64 @@ +#define LOG_CATEGORY UCLASS_HOST + +#include <bootdev.h> +#include <dm.h> +#include <log.h> +#include <sandbox_host.h> + +static int sandbox_bootdev_bind (struct udevice *dev)
LOG_CATEGORY is defined but sandbox_bootdev_hunt() uses pr_debug() and pr_err(). Please use the log_ family throughout so the category is honoured.
Quoted 6 lines
drivers/block/sandbox-bootdev.c +4
-0@@ -0,0 +1,64 @@ + uclass_id_foreach_dev(UCLASS_HOST, dev, uc) { +struct host_sb_plat *plat =dev_get_plat (dev); + +pr_debug ("hunting %s\n" , plat->label);
drivers/block/sandbox-bootdev.c line 14
Quoted 10 lines
drivers/block/sandbox-bootdev.c +10
-0+ +if (plat->flags &BLK_HOST_BROKEN ) { + ret = -ETIME ; +pr_err ("cannot hunt sandbox device '%s': %d\n" , + plat->label, ret); +return ret; + } + +return 0 ; + }
The unconditional return 0 exits on the first HOST device found, so any further devices are silently ignored. It works for the test since only one device is created, but is misleading. Please use continue after a non-broken device, or add a comment explaining the early return.
Regards,
Simon