Xavier Drudis Ferran 7a875a8e5c cmd: usb: Prevent reset in usb tree/info command
Commands causing reset in some configs:

When bootflow scan is run, this will cause a UCLASS_BOOTDEV device to
be added as sibling of those UCLASS_BLK devices found in the search
chain defined in environment variable "boot_targets", until boot
succeeds from some device. This can happen automatically as part of
the default boot process on some boards (example: Rock Pi 4) depending
on the board configuration (DISTRO_DEFAULTS, BOOTSTD, BOOTCOMMAND,
etc.) because they have bootcmd=bootflow scan.

If boot doesn't succeed from any device, and usb is in boot_targets,
and an usb storage device is plugged to some usb port at boot time,
its UCLASS_MASS_STORAGE device will have a UCLASS_BOOTDEV device as
child, besides a UCLASS_BLK child.

If once the boot fails the user enters at the U-Boot shell prompt:

usb info

or

usb tree

The code in cmd/usb.c will eventually recurse into the UCLASS_BOOTDEV
device and pass a null usb_device pointer to usb_show_tree_graph() or
usb_show_info() (because it has no parent_priv_).

This causes a reset. The expected behaviour would be to ignore the
UCLASS_BOOTDEV device, continue listing the usb information and return
to the prompt.

   Minimal test:

Another way to trigger this reset as a minimal test or on boards with
a different bootcmd would be:

- make sure "usb" is in environment variable boot_targets (might need
  setenv boot_targets usb; and/or saveenv and reset), then, with a usb
  storage device plugged to a usb port, run:

=> usb reset ; bootflow scan ; usb info

   Solution:

Fix it (twice) by checking for null parent_priv_ and adding
UCLASS_BOOTDEV to the list of ignored class ids before the recursive
call.

This prevents the current particular problem with UCLASS_BOOTDEV, even
in case it ever gets some parent_priv_ struct which is not an
usb_device, despite being the child of a usb_device->dev. And it also
prevents possible future problems if other children are added to usb
devices that don't have parent_priv_ because they are not part of the
usb tree, just abstractions of functionality (like UCLASS_BLK and
UCLASS_BOOTDEV are now).

Signed-off-by: Xavier Drudis Ferran <xdrudis@tinet.cat>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
Tested-by: Marek Vasut <marex@denx.de>
2023-06-21 13:08:30 +02:00
..
2022-10-20 15:22:15 +08:00
2023-02-10 07:41:40 -05:00
2023-04-06 19:10:08 -04:00
2023-04-05 10:54:47 -04:00
2022-09-24 11:34:38 -04:00
2023-02-10 07:41:40 -05:00
2023-05-13 11:09:51 +02:00
2022-09-29 16:07:57 -04:00
2022-10-17 21:17:12 -06:00
2023-02-10 13:45:15 -05:00
2022-09-29 16:07:57 -04:00
2020-05-18 18:36:55 -04:00
2022-10-11 15:40:48 -04:00
2020-05-18 18:36:55 -04:00
2023-02-10 07:41:40 -05:00
2022-08-04 16:18:47 -04:00
2022-08-04 16:18:47 -04:00
2023-04-06 19:10:08 -04:00
2020-05-18 18:36:55 -04:00
2022-09-29 16:07:57 -04:00
2023-02-10 07:41:40 -05:00
2023-03-25 11:07:22 +01:00
2023-02-10 13:45:15 -05:00
2022-09-24 11:34:38 -04:00
2022-03-15 16:19:29 -04:00
2020-05-18 18:36:55 -04:00
2020-05-18 18:36:55 -04:00
2020-05-18 18:36:55 -04:00
2023-05-05 17:48:44 -04:00
2020-10-23 13:33:07 -04:00
2023-04-03 06:53:53 +12:00
2022-08-04 16:18:47 -04:00
2022-09-29 16:07:57 -04:00
2022-05-06 14:39:15 -04:00
2020-05-18 18:36:55 -04:00
2020-05-18 18:36:55 -04:00
2023-04-27 13:51:06 -04:00
2020-05-18 18:36:55 -04:00
2022-08-04 16:18:47 -04:00
2023-05-13 09:52:32 -04:00
2022-09-25 08:30:05 -06:00
2020-05-18 18:36:55 -04:00
2023-04-06 19:10:08 -04:00
2021-11-28 16:51:51 -07:00
2023-01-27 18:31:58 +01:00
2022-06-22 21:29:47 -04:00
2023-04-10 12:18:45 +09:00
2020-10-28 11:49:31 -04:00
2023-02-27 16:28:30 +01:00
2023-06-14 15:48:45 -04:00
2022-10-06 22:54:57 +02:00
2023-03-30 15:09:59 -04:00
2022-09-16 11:05:16 -04:00
2022-05-05 15:06:02 -04:00
2020-07-08 17:21:46 -04:00
2022-09-02 13:40:42 -04:00
2022-01-19 18:11:34 +01:00
2020-05-18 18:36:55 -04:00
2022-09-16 11:05:16 -04:00
2023-03-17 15:44:01 -04:00
2022-09-16 11:05:16 -04:00
2022-09-16 11:05:16 -04:00
2023-02-06 17:10:15 -05:00
2022-01-19 18:11:34 +01:00
2023-01-26 21:05:13 +05:30
2021-09-24 14:30:46 -04:00
2020-08-07 22:31:32 -04:00
2022-10-11 15:40:48 -04:00
2020-05-18 21:19:18 -04:00
2020-05-18 18:36:55 -04:00
2023-06-06 10:37:25 +02:00
2021-10-09 13:09:56 -04:00
2020-05-18 18:36:55 -04:00
2020-05-18 18:36:55 -04:00
2023-01-20 12:27:24 -05:00
2022-10-11 15:40:48 -04:00