Patchwork [U-Boot] USB: add CONFIG_USB_INIT to autoinitialize USB before main_loop

login
register
mail settings
Submitter Allen Martin
Date Dec. 22, 2011, 1:05 a.m.
Message ID <1324515956-1642-1-git-send-email-amartin@nvidia.com>
Download mbox | patch
Permalink /patch/132764/
State Changes Requested
Headers show

Comments

Allen Martin - Dec. 22, 2011, 1:05 a.m.
This allows systems to pause autoboot with USB keyboard.  Tested on
tegra2 seaboard.

Signed-off-by: Allen Martin <amartin@nvidia.com>
---
 README               |    5 +++++
 arch/arm/lib/board.c |    9 +++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)
Marek Vasut - Dec. 22, 2011, 4:04 a.m.
> This allows systems to pause autoboot with USB keyboard.  Tested on
> tegra2 seaboard.
> 
> Signed-off-by: Allen Martin <amartin@nvidia.com>

Can't you just add "usb reset" to preboot env?

M
> ---
>  README               |    5 +++++
>  arch/arm/lib/board.c |    9 +++++++++
>  2 files changed, 14 insertions(+), 0 deletions(-)
> 
> diff --git a/README b/README
> index 882483b..40e8481 100644
> --- a/README
> +++ b/README
> @@ -1132,6 +1132,11 @@ The following options need to be configured:
>  		CONFIG_USB_EHCI_TXFIFO_THRESH enables setting of the
>  		txfilltuning field in the EHCI controller on reset.
> 
> +		CONFIG_USB_INIT causes USB to be initialized
> +		automatically before the main command loop.  This is
> +		useful if you have a USB keyboard and you want to use
> +		it to stop autoboot.
> +
>  - USB Device:
>  		Define the below if you wish to use the USB console.
>  		Once firmware is rebuilt from a serial console issue the
> diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
> index 3d78274..6787048 100644
> --- a/arch/arm/lib/board.c
> +++ b/arch/arm/lib/board.c
> @@ -64,6 +64,10 @@
>  #include "../drivers/net/lan91c96.h"
>  #endif
> 
> +#ifdef CONFIG_USB_INIT
> +#include <usb.h>
> +#endif
> +
>  DECLARE_GLOBAL_DATA_PTR;
> 
>  ulong monitor_flash_len;
> @@ -548,6 +552,11 @@ void board_init_r(gd_t *id, ulong dest_addr)
>  	api_init();
>  #endif
> 
> +#ifdef CONFIG_USB_INIT
> +	/* this needs to be before console init for USB kbd to work as stdin */
> +	usb_init();
> +#endif
> +
>  	console_init_r();	/* fully init console as a device */
> 
>  #if defined(CONFIG_ARCH_MISC_INIT)
Wolfgang Denk - Dec. 22, 2011, 8:06 a.m.
Dear Allen Martin,

In message <1324515956-1642-1-git-send-email-amartin@nvidia.com> you wrote:
> This allows systems to pause autoboot with USB keyboard.  Tested on
> tegra2 seaboard.
> 
> Signed-off-by: Allen Martin <amartin@nvidia.com>
> ---
>  README               |    5 +++++
>  arch/arm/lib/board.c |    9 +++++++++
>  2 files changed, 14 insertions(+), 0 deletions(-)

This modification is in no way ARM specific, so if we accept it, it
must be applied to all supported architectures.

Where exacly is this feature nneded?  You don;t enable it in any of
the board configurations...

Also, should we then not auto-enable this if CONFIG_USB_KEYBOARD is
set?

Best regards,

Wolfgang Denk
Igor Grinberg - Dec. 22, 2011, 8:17 a.m.
Hi Wolfgang,

On 12/22/11 10:06, Wolfgang Denk wrote:
> Dear Allen Martin,
> 
> In message <1324515956-1642-1-git-send-email-amartin@nvidia.com> you wrote:
>> This allows systems to pause autoboot with USB keyboard.  Tested on
>> tegra2 seaboard.
>>
>> Signed-off-by: Allen Martin <amartin@nvidia.com>
>> ---
>>  README               |    5 +++++
>>  arch/arm/lib/board.c |    9 +++++++++
>>  2 files changed, 14 insertions(+), 0 deletions(-)
> 
> This modification is in no way ARM specific, so if we accept it, it
> must be applied to all supported architectures.
> 
> Where exacly is this feature nneded?  You don;t enable it in any of
> the board configurations...
> 
> Also, should we then not auto-enable this if CONFIG_USB_KEYBOARD is
> set?

Right, IMHO, there is no need for a new config option -
just make the USB init depend on CONFIG_USB_KEYBOARD.
Allen Martin - Dec. 22, 2011, 6:54 p.m.
> > This allows systems to pause autoboot with USB keyboard.  Tested on
> > tegra2 seaboard.
> >
> > Signed-off-by: Allen Martin <amartin@nvidia.com>
> 
> Can't you just add "usb reset" to preboot env?

The point is to be able to use USB keyboard to stop autoboot on systems where USB keyboard is the primary (or only) input device.  This needs to happen before BOOTCOMMAND gets parsed.

-Allen
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
Kyle Moffett - Dec. 22, 2011, 7:10 p.m.
--
Curious about my work on the Debian powerpcspe port?
I'm keeping a blog here: http://pureperl.blogspot.com/
>>> This allows systems to pause autoboot with USB keyboard.  Tested on
>>> tegra2 seaboard.
>>> 
>>> Signed-off-by: Allen Martin <amartin@nvidia.com>
>> 
>> Can't you just add "usb reset" to preboot env?
> 
> The point is to be able to use USB keyboard to stop autoboot on systems
> where USB keyboard is the primary (or only) input device.  This needs
> to happen before BOOTCOMMAND gets parsed.

I think the "preboot" environment variable already *is* run before
starting the autoboot timer?

Cheers,
Kyle Moffett
Marek Vasut - Dec. 22, 2011, 7:27 p.m.
> --
> Curious about my work on the Debian powerpcspe port?
> I'm keeping a blog here: http://pureperl.blogspot.com/
> 
> >>> This allows systems to pause autoboot with USB keyboard.  Tested on
> >>> tegra2 seaboard.
> >>> 
> >>> Signed-off-by: Allen Martin <amartin@nvidia.com>
> >> 
> >> Can't you just add "usb reset" to preboot env?
> > 
> > The point is to be able to use USB keyboard to stop autoboot on systems
> > where USB keyboard is the primary (or only) input device.  This needs
> > to happen before BOOTCOMMAND gets parsed.
> 
> I think the "preboot" environment variable already *is* run before
> starting the autoboot timer?

Yep.

M
Allen Martin - Dec. 22, 2011, 8:32 p.m.
> > >> Can't you just add "usb reset" to preboot env?
> > >
> > > The point is to be able to use USB keyboard to stop autoboot on
> > > systems where USB keyboard is the primary (or only) input device.
> > > This needs to happen before BOOTCOMMAND gets parsed.
> >
> > I think the "preboot" environment variable already *is* run before
> > starting the autoboot timer?
> 
> Yep.
> 

I also had to stick it before console init because console makes decisions about the input device based on what's been registered when it initializes (at least with iomux turned on, I didn't try it without).

Maybe a better fix is to have console reevaluate things when the usb keyboard driver registers itself?  I'm open to suggestions.

-Allen
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
Allen Martin - Dec. 22, 2011, 10:40 p.m.
> > > > The point is to be able to use USB keyboard to stop autoboot on
> > > > systems where USB keyboard is the primary (or only) input device.
> > > > This needs to happen before BOOTCOMMAND gets parsed.
> > >
> > > I think the "preboot" environment variable already *is* run before
> > > starting the autoboot timer?
> >
> > Yep.
> >
> 
> I also had to stick it before console init because console makes
> decisions about the input device based on what's been registered when it
> initializes (at least with iomux turned on, I didn't try it without).
> 
> Maybe a better fix is to have console reevaluate things when the usb
> keyboard driver registers itself?  I'm open to suggestions.

I don't fully grok how console/stdin gets assigned, but is this possibly
the problem? (from drv_usb_kbd_init()):

                /* Check if this is the standard input device. */
                if (strcmp(stdinname, DEVNAME))
                        return 1;

                /* Reassign the console */
                if (overwrite_console())
                        return 1;

                error = console_assign(stdin, DEVNAME);

This seems incompatible with iomux, shouldn't these decisions be made in the
console driver?  In my case, stdin is set to "serial,tegra-kbc,usbkbd" so this
strcmp won't match.

-Allen
nvpublic
Wolfgang Denk - Dec. 22, 2011, 11 p.m.
Dear Allen Martin,

In message <3C7A7ACA8617D24290826EC008B5CD083E5DCDAF40@HQMAIL03.nvidia.com> you wrote:
> 
> I don't fully grok how console/stdin gets assigned, but is this possibly
> the problem? (from drv_usb_kbd_init()):
> 
>                 /* Check if this is the standard input device. */
>                 if (strcmp(stdinname, DEVNAME))
>                         return 1;
> 
>                 /* Reassign the console */
>                 if (overwrite_console())
>                         return 1;
> 
>                 error = console_assign(stdin, DEVNAME);
> 
> This seems incompatible with iomux, shouldn't these decisions be made in the
> console driver?  In my case, stdin is set to "serial,tegra-kbc,usbkbd" so this
> strcmp won't match.

Indeed, this code predates the iomux implementation, and nobody
noticed yet that it needs fixing.

Best regards,

Wolfgang Denk

Patch

diff --git a/README b/README
index 882483b..40e8481 100644
--- a/README
+++ b/README
@@ -1132,6 +1132,11 @@  The following options need to be configured:
 		CONFIG_USB_EHCI_TXFIFO_THRESH enables setting of the
 		txfilltuning field in the EHCI controller on reset.
 
+		CONFIG_USB_INIT causes USB to be initialized
+		automatically before the main command loop.  This is
+		useful if you have a USB keyboard and you want to use
+		it to stop autoboot.
+
 - USB Device:
 		Define the below if you wish to use the USB console.
 		Once firmware is rebuilt from a serial console issue the
diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index 3d78274..6787048 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -64,6 +64,10 @@ 
 #include "../drivers/net/lan91c96.h"
 #endif
 
+#ifdef CONFIG_USB_INIT
+#include <usb.h>
+#endif
+
 DECLARE_GLOBAL_DATA_PTR;
 
 ulong monitor_flash_len;
@@ -548,6 +552,11 @@  void board_init_r(gd_t *id, ulong dest_addr)
 	api_init();
 #endif
 
+#ifdef CONFIG_USB_INIT
+	/* this needs to be before console init for USB kbd to work as stdin */
+	usb_init();
+#endif
+
 	console_init_r();	/* fully init console as a device */
 
 #if defined(CONFIG_ARCH_MISC_INIT)