[PATCH 1/3] usb: Tidy up the usb_start flag

This should be declared in a header file so that type-checking works correctly.
Add a single declaration to usb.h and remove the others.
Signed-off-by: Simon Glass sjg@chromium.org ---
cmd/usb.c | 1 - common/usb.c | 2 +- drivers/usb/host/usb-uclass.c | 1 - include/usb.h | 3 +++ test/boot/bootdev.c | 4 ++-- test/dm/blk.c | 3 --- 6 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/cmd/usb.c b/cmd/usb.c index 73addb04c498..619372838409 100644 --- a/cmd/usb.c +++ b/cmd/usb.c @@ -620,7 +620,6 @@ static int do_usb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct usb_device *udev = NULL; int i; - extern char usb_started;
if (argc < 2) return CMD_RET_USAGE; diff --git a/common/usb.c b/common/usb.c index ae9253dfc0ed..836506dcd9e9 100644 --- a/common/usb.c +++ b/common/usb.c @@ -43,7 +43,7 @@ #define USB_BUFSIZ 512
static int asynch_allowed; -char usb_started; /* flag for the started/stopped USB status */ +bool usb_started; /* flag for the started/stopped USB status */
#if !CONFIG_IS_ENABLED(DM_USB) static struct usb_device usb_dev[USB_MAX_DEVICE]; diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index 28f7ca9654db..02c0138a2065 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -18,7 +18,6 @@ #include <dm/lists.h> #include <dm/uclass-internal.h>
-extern bool usb_started; /* flag for the started/stopped USB status */ static bool asynch_allowed;
struct usb_uclass_priv { diff --git a/include/usb.h b/include/usb.h index 80cb84672030..42b001c3dd5e 100644 --- a/include/usb.h +++ b/include/usb.h @@ -11,12 +11,15 @@ #ifndef _USB_H_ #define _USB_H_
+#include <stdbool.h> #include <fdtdec.h> #include <usb_defs.h> #include <linux/usb/ch9.h> #include <asm/cache.h> #include <part.h>
+extern bool usb_started; /* flag for the started/stopped USB status */ + /* * The EHCI spec says that we must align to at least 32 bytes. However, * some platforms require larger alignment. diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 8cf3f30e0f75..606bf4fcc1c1 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -19,9 +19,9 @@
/* Allow reseting the USB-started flag */ #if defined(CONFIG_USB_HOST) || defined(CONFIG_USB_GADGET) -extern char usb_started; +extern bool usb_started; #else -char usb_started; +#include <usb.h> #endif
/* Check 'bootdev list' command */ diff --git a/test/dm/blk.c b/test/dm/blk.c index 0aa04c64ef7e..446c4423e6f5 100644 --- a/test/dm/blk.c +++ b/test/dm/blk.c @@ -16,9 +16,6 @@
DECLARE_GLOBAL_DATA_PTR;
-/* Allow resetting the USB-started flag */ -extern char usb_started; - /* Test that block devices can be created */ static int dm_test_blk_base(struct unit_test_state *uts) {

This causes crashes on some boards, e.g. rockpro64. In any case, we should not do it.
Check the usb_started flag to avoid this.
Signed-off-by: Simon Glass sjg@chromium.org ---
drivers/usb/host/usb_bootdev.c | 3 +++ test/boot/bootdev.c | 5 +++++ 2 files changed, 8 insertions(+)
diff --git a/drivers/usb/host/usb_bootdev.c b/drivers/usb/host/usb_bootdev.c index 32919f992865..06e8f61aa1c5 100644 --- a/drivers/usb/host/usb_bootdev.c +++ b/drivers/usb/host/usb_bootdev.c @@ -22,6 +22,9 @@ static int usb_bootdev_bind(struct udevice *dev)
static int usb_bootdev_hunt(struct bootdev_hunter *info, bool show) { + if (usb_started) + return 0; + return usb_init(); }
diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 606bf4fcc1c1..6b29213416db 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -306,6 +306,7 @@ static int bootdev_test_hunter(struct unit_test_state *uts) { struct bootstd_priv *std;
+ usb_started = false; test_set_skip_delays(true);
/* get access to the used hunters */ @@ -346,6 +347,7 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts) struct bootstd_priv *std;
test_set_skip_delays(true); + usb_started = false;
/* get access to the used hunters */ ut_assertok(bootstd_get_priv(&std)); @@ -474,6 +476,7 @@ BOOTSTD_TEST(bootdev_test_bootable, UT_TESTF_DM | UT_TESTF_SCAN_FDT); /* Check hunting for bootdev of a particular priority */ static int bootdev_test_hunt_prio(struct unit_test_state *uts) { + usb_started = false; test_set_skip_delays(true);
console_record_reset_enable(); @@ -502,6 +505,8 @@ static int bootdev_test_hunt_label(struct unit_test_state *uts) struct bootstd_priv *std; int mflags;
+ usb_started = false; + /* get access to the used hunters */ ut_assertok(bootstd_get_priv(&std));

Hi Simon,
On 2023-05-06 04:03, Simon Glass wrote:
This causes crashes on some boards, e.g. rockpro64. In any case, we should not do it.
Check the usb_started flag to avoid this.
Signed-off-by: Simon Glass sjg@chromium.org
drivers/usb/host/usb_bootdev.c | 3 +++ test/boot/bootdev.c | 5 +++++ 2 files changed, 8 insertions(+)
This fixes the crash related to usbkbd in stdin env on my rockpro64, so:
Tested-by: Jonas Karlman jonas@kwiboo.se
Regards, Jonas

On Sat, May 06, 2023 at 03:59:57PM +0000, Jonas Karlman wrote:
Hi Simon,
On 2023-05-06 04:03, Simon Glass wrote:
This causes crashes on some boards, e.g. rockpro64. In any case, we should not do it.
Check the usb_started flag to avoid this.
Signed-off-by: Simon Glass sjg@chromium.org
drivers/usb/host/usb_bootdev.c | 3 +++ test/boot/bootdev.c | 5 +++++ 2 files changed, 8 insertions(+)
This fixes the crash related to usbkbd in stdin env on my rockpro64, so:
Tested-by: Jonas Karlman jonas@kwiboo.se
I'm also testing things out on my rockpro64 finally. Are you able to boot distributions from uSD on yours or only USB, automatically?

On 2023-05-06 18:00, Tom Rini wrote:
On Sat, May 06, 2023 at 03:59:57PM +0000, Jonas Karlman wrote:
Hi Simon,
On 2023-05-06 04:03, Simon Glass wrote:
This causes crashes on some boards, e.g. rockpro64. In any case, we should not do it.
Check the usb_started flag to avoid this.
Signed-off-by: Simon Glass sjg@chromium.org
drivers/usb/host/usb_bootdev.c | 3 +++ test/boot/bootdev.c | 5 +++++ 2 files changed, 8 insertions(+)
This fixes the crash related to usbkbd in stdin env on my rockpro64, so:
Tested-by: Jonas Karlman jonas@kwiboo.se
I'm also testing things out on my rockpro64 finally. Are you able to boot distributions from uSD on yours or only USB, automatically?
Was able to boot Armbian after enable of script bootmeth support, distro/extlinux.conf bootmeth seem to work fine, just tried debian-11.7.0-arm64-netinst.iso and got following crash.
I have avoided efi boot thus far, not sure this was supposed to work or not. Was however not expecting a crash, possibly jumping to next bootflow.
** Booting bootflow 'mmc@fe320000.bootdev.part_1' with efi Card did not respond to voltage select! : -110 No EFI system partition No EFI system partition Failed to persist EFI variables Booting /efi\boot\bootaa64.efi No EFI system partition Failed to persist EFI variables "Synchronous Abort" handler, esr 0x96000010, far 0x4c elr: fffffffffd13f3e0 lr : fffffffffd13f41c (reloc) elr: 00000000f0e6a3e0 lr : 00000000f0e6a41c x0 : 000000000000004c x1 : 00000000f1f10060 x2 : 0000000000000000 x3 : 0000000000000000 x4 : 00000000000000ff x5 : 0000000000000000 x6 : 00000000f0bec000 x7 : 0000000000000007 x8 : 0000000000000002 x9 : fffffffffffffff0 x10: 00000000f0f01000 x11: 00000000f0e04040 x12: 00000000f0e6d518 x13: 00000000f3f2b000 x14: 00000000f1f10578 x15: 00000000f0df8040 x16: 00000000f3f8e788 x17: 000000000a68740b x18: 0000000000000000 x19: 00000000f1f10060 x20: 00000000f1f10330 x21: 00000000f0e99c00 x22: 0000000000010020 x23: 00000000f0e99caa x24: 00000000f1f104f0 x25: 00000000f0e84d40 x26: 000000000000012f x27: 00000000f0e862f4 x28: 00000000000043b0 x29: 00000000f1f0ffe0
Code: 38626800 91000442 f9000422 d65f03c0 (78627800) UEFI image [0x00000000f0e05000:0x00000000f0ed90a9] pc=0x653e0 '/efi\boot\bootaa64.efi' Resetting CPU ...
Regards, Jonas

On 2023-05-06 18:24, Jonas Karlman wrote:
On 2023-05-06 18:00, Tom Rini wrote:
On Sat, May 06, 2023 at 03:59:57PM +0000, Jonas Karlman wrote:
Hi Simon,
On 2023-05-06 04:03, Simon Glass wrote:
This causes crashes on some boards, e.g. rockpro64. In any case, we should not do it.
Check the usb_started flag to avoid this.
Signed-off-by: Simon Glass sjg@chromium.org
drivers/usb/host/usb_bootdev.c | 3 +++ test/boot/bootdev.c | 5 +++++ 2 files changed, 8 insertions(+)
This fixes the crash related to usbkbd in stdin env on my rockpro64, so:
Tested-by: Jonas Karlman jonas@kwiboo.se
I'm also testing things out on my rockpro64 finally. Are you able to boot distributions from uSD on yours or only USB, automatically?
Was able to boot Armbian after enable of script bootmeth support, distro/extlinux.conf bootmeth seem to work fine, just tried debian-11.7.0-arm64-netinst.iso and got following crash.
I have avoided efi boot thus far, not sure this was supposed to work or not. Was however not expecting a crash, possibly jumping to next bootflow.
With Fedora-Server-38-1.6.aarch64.raw.xz on uSD, and u-boot in eMMC, the efi bootflow does work. Crash only happen with debian thus far.
Regards, Jonas
** Booting bootflow 'mmc@fe320000.bootdev.part_1' with efi Card did not respond to voltage select! : -110 No EFI system partition No EFI system partition Failed to persist EFI variables Booting /efi\boot\bootaa64.efi No EFI system partition Failed to persist EFI variables "Synchronous Abort" handler, esr 0x96000010, far 0x4c elr: fffffffffd13f3e0 lr : fffffffffd13f41c (reloc) elr: 00000000f0e6a3e0 lr : 00000000f0e6a41c x0 : 000000000000004c x1 : 00000000f1f10060 x2 : 0000000000000000 x3 : 0000000000000000 x4 : 00000000000000ff x5 : 0000000000000000 x6 : 00000000f0bec000 x7 : 0000000000000007 x8 : 0000000000000002 x9 : fffffffffffffff0 x10: 00000000f0f01000 x11: 00000000f0e04040 x12: 00000000f0e6d518 x13: 00000000f3f2b000 x14: 00000000f1f10578 x15: 00000000f0df8040 x16: 00000000f3f8e788 x17: 000000000a68740b x18: 0000000000000000 x19: 00000000f1f10060 x20: 00000000f1f10330 x21: 00000000f0e99c00 x22: 0000000000010020 x23: 00000000f0e99caa x24: 00000000f1f104f0 x25: 00000000f0e84d40 x26: 000000000000012f x27: 00000000f0e862f4 x28: 00000000000043b0 x29: 00000000f1f0ffe0
Code: 38626800 91000442 f9000422 d65f03c0 (78627800) UEFI image [0x00000000f0e05000:0x00000000f0ed90a9] pc=0x653e0 '/efi\boot\bootaa64.efi' Resetting CPU ...
Regards, Jonas

On Fri, May 05, 2023 at 08:03:04PM -0600, Simon Glass wrote:
This causes crashes on some boards, e.g. rockpro64. In any case, we should not do it.
Check the usb_started flag to avoid this.
Signed-off-by: Simon Glass sjg@chromium.org
Tested-by: Tom Rini trini@konsulko.com

On Fri, May 05, 2023 at 08:03:04PM -0600, Simon Glass wrote:
This causes crashes on some boards, e.g. rockpro64. In any case, we should not do it.
Check the usb_started flag to avoid this.
Signed-off-by: Simon Glass sjg@chromium.org Tested-by: Jonas Karlman jonas@kwiboo.se Tested-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Armbian uses a script which needs the HUSH parser. It is likely that other distros will do the same. Enable it by default, just in case.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/Kconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/boot/Kconfig b/boot/Kconfig index 8c27f52ec3ed..9882812eecb8 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -638,6 +638,7 @@ config BOOTMETH_SANDBOX config BOOTMETH_SCRIPT bool "Bootdev support for U-Boot scripts" default y if BOOTSTD_FULL + select HUSH_PARSER help Enables support for booting a distro via a U-Boot script. This makes the bootdevs look for a 'boot/boot.scr' file which can be used to

Hi Simon,
On 2023-05-06 04:03, Simon Glass wrote:
Armbian uses a script which needs the HUSH parser. It is likely that other distros will do the same. Enable it by default, just in case.
Signed-off-by: Simon Glass sjg@chromium.org
boot/Kconfig | 1 + 1 file changed, 1 insertion(+)
With this and following two config options it is now possible to boot Armbian_23.02.1_Rockpro64_bullseye_current_5.15.96_minimal using bootstd.
CONFIG_BOOTMETH_SCRIPT=y CONFIG_LEGACY_IMAGE_FORMAT=y
Tested-by: Jonas Karlman jonas@kwiboo.se
Regards, Jonas

Hi Jonas,
On Sat, 6 May 2023 at 10:03, Jonas Karlman jonas@kwiboo.se wrote:
Hi Simon,
On 2023-05-06 04:03, Simon Glass wrote:
Armbian uses a script which needs the HUSH parser. It is likely that other distros will do the same. Enable it by default, just in case.
Signed-off-by: Simon Glass sjg@chromium.org
boot/Kconfig | 1 + 1 file changed, 1 insertion(+)
With this and following two config options it is now possible to boot Armbian_23.02.1_Rockpro64_bullseye_current_5.15.96_minimal using bootstd.
CONFIG_BOOTMETH_SCRIPT=y CONFIG_LEGACY_IMAGE_FORMAT=y
Tested-by: Jonas Karlman jonas@kwiboo.se
The second one looks like it is already set for that board.
Tom suggested a new BOOTSTD_DISTRO which I am going to try, to cover every conceivable thing that might be used by distros.
Regards, Simon

On Fri, May 05, 2023 at 08:03:05PM -0600, Simon Glass wrote:
Armbian uses a script which needs the HUSH parser. It is likely that other distros will do the same. Enable it by default, just in case.
Signed-off-by: Simon Glass sjg@chromium.org Tested-by: Jonas Karlman jonas@kwiboo.se
Applied to u-boot/master, thanks!

On 5/6/23 04:03, Simon Glass wrote:
This should be declared in a header file so that type-checking works correctly.
Add a single declaration to usb.h and remove the others.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Marek Vasut marex@denx.de

Hi,
On 5/6/23 04:03, Simon Glass wrote:
This should be declared in a header file so that type-checking works correctly.
Add a single declaration to usb.h and remove the others.
Signed-off-by: Simon Glass sjg@chromium.org
cmd/usb.c | 1 - common/usb.c | 2 +- drivers/usb/host/usb-uclass.c | 1 - include/usb.h | 3 +++ test/boot/bootdev.c | 4 ++-- test/dm/blk.c | 3 --- 6 files changed, 6 insertions(+), 8 deletions(-)
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks Patrick

On Fri, May 05, 2023 at 08:03:03PM -0600, Simon Glass wrote:
This should be declared in a header file so that type-checking works correctly.
Add a single declaration to usb.h and remove the others.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Marek Vasut marex@denx.de Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Applied to u-boot/master, thanks!
participants (5)
-
Jonas Karlman
-
Marek Vasut
-
Patrick DELAUNAY
-
Simon Glass
-
Tom Rini