Re: Provide information: All connected USB devices are enumerated at boot time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Greg KH wrote

> On Thu, Oct 15, 2015 at 05:23:21PM +0200, Stefan Reichör wrote:
>> Alan Stern wrote:
>> 
>> > On Thu, 15 Oct 2015, Stefan Reichör wrote:
>> >
>> >> Hi there,
>> >> 
>> >> I am currently working on a problem that I need to know when all
>> >> connected USB devices are enumerated when the system starts up.
>> >> 
>> >> The problem is the following:
>> >> * After the kernel finished booting, some hardware testing is performed
>> >> * This hardware testing involves various USB devices (e.g.: USB memory
>> >>   stick, USB touch controllers, etc.)
>> >> * The problem is that some USB devices appear after the test program has started
>> >> 
>> >> I could add a delay before the test is started. However the test should
>> >> work on a broad range of platforms with different USB devices. Therefore
>> >> it is difficult to find an optimal timeout value.
>> >> 
>> >> The desired solution is to wait on the enumeration of the connected USB
>> >> devices and start the test program.
>> >> 
>> >> I found the following thread:
>> >>   http://thread.gmane.org/gmane.linux.kernel/825135
>> >> 
>> >> In concrete: http://article.gmane.org/gmane.linux.kernel/826216
>> >> ,----
>> >> | From: Alan Stern <stern <at> rowland.harvard.edu>
>> >> | Subject: Re: Wait for console to become available, v3.2
>> >> | Newsgroups: gmane.linux.kernel.embedded, gmane.linux.kernel, gmane.linux.usb.general
>> >> | Date: 2009-04-22 21:24:18 GMT (6 years, 25 weeks, 4 hours and 54 minutes ago)
>> >> | On Wed, 22 Apr 2009, Alan Cox wrote:
>> >> | 
>> >> | > > 2.	All devices have been probed
>> >> | > > If we exit for reason 2, it means that no such device is present,
>> >> | > > and we go on to the do the appropriate thing for that device class.
>> >> | > 
>> >> | > USB has no notion of #2 really
>> >> | 
>> >> | That's true, it doesn't.  But it _does_ rather have a notion of "all 
>> >> | devices that were present at boot time have been probed".  That should 
>> >> | be good enough.
>> >> | 
>> >> | Alan Stern
>> >> `----
>> >> 
>> >> So my question is whether the "all devices that were present at boot time have been probed"
>> >> is already available in the current kernel sources.
>> >
>> > It isn't.  Nobody ever thought it was important enough to implement.
>> >
>> >> If it is not yet available: Is drivers/usb/core/hub.c the correct
>> >> location to start the implementation of such a feature?
>> >
>> > It is the right place to implement "all devices attached to a 
>> > particular hub have been probed".  But you're asking for more than 
>> > that, because you also have to keep track of all the hubs that were 
>> > present at boot time.  You also have to worry about all USB host 
>> > controllers, which are detected outside of the USB stack.
>> 
>> Thanks for your fast response.
>> 
>> My idea is now to have a fixed and known set of USB hubs.
>> This should be doable with my hardware configurations.
>> 
>> Each of these hubs provide the information that "all devices attached to
>> this hub have been probed".
>> 
>> The test program waits for this information to be delivered from all known USB hubs.
>> Then it starts with the tests.
>> 
>> Would you be so kind and give a short idea where to put the code in
>> drivers/usb/core/hub.c that emits this information for me?
>> 
>> Would this kind of patch be useful for the mainline kernel?
>
> You can do this all today in userspace, no need for any kernel changes.
> Just link to libudev and register for all USB device events and then
> start your test code up when you feel that you have seen all of the
> devices you need/want to see.
>
> hope this helps,
>

Thanks for your hint.

My goal is to wait until all connected USB devices at boot time are
usable. The extra condition I'd like to solve is that I don't know what
devices are connected.
Of course this can be handled by a long enough timeout.
However the idea is to wait until all devices are usable.

For example look at two simple cases:

a) no USB device is connected
   Testing should start immediatly
b) A USB memory stick is connected
   We use an udev rule to extract a .zip file from this USB stick
   This .zip file will influence the test routines that will be run
   Therefore it is necessary to wait until the .zip is extracted

I have tried to use hub_events() in drivers/usb/core/hub.c to extract
this information.

However the USB hub provides the "END of hub_events" information more
than 4 seconds before the USB stick is finally mounted.

It is reasonable that the USB hub is not informed about the point in
time when the filesystem is usable. The hub is only responsible for
setting up the basic USB communication.

Here is a kernel log for b)
,----
| <<SNIP>>
| 
| [    2.256845] usb 1-1: New USB device found, idVendor=13fe, idProduct=1f00
| [    2.263582] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
| [    2.305783] usb 1-1: Manufacturer:         
| [    2.309986] usb 1-1: SerialNumber: 078816532889
| [    2.317389] usb-storage 1-1:1.0: USB Mass Storage device detected
| [    2.323989] scsi0 : usb-storage 1-1:1.0
| [    2.328094] usb-storage 1-1:1.0: USB Mass Storage probe done
| [    2.334077] hub 1-0:1.0: END of hub_events, 0
| 
| <<SNIP>>
| 
| [    3.571038] sd 0:0:0:0: [sda] 7708672 512-byte logical blocks: (3.94 GB/3.67 GiB)
| [    3.579150] sd 0:0:0:0: [sda] Write Protect is off
| [    3.584654] sd 0:0:0:0: [sda] No Caching mode page found
| [    3.589993] sd 0:0:0:0: [sda] Assuming drive cache: write through
| [    3.599888] sd 0:0:0:0: [sda] No Caching mode page found
| [    3.605309] sd 0:0:0:0: [sda] Assuming drive cache: write through
| [    3.612443]  sda: sda1
| [    3.618126] sd 0:0:0:0: [sda] No Caching mode page found
| [    3.623467] sd 0:0:0:0: [sda] Assuming drive cache: write through
| [    3.629629] sd 0:0:0:0: [sda] Attached SCSI removable disk
| [    3.635595] Freeing unused kernel memory: 288K (80bc2000 - 80c0a000)
| [    4.537543] udevd[111]: starting version 182
| [    5.017521] EXT4-fs (mmcblk0p2): re-mounted. Opts: data=ordered
| [    6.665951] FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
| [    6.768773] FAT-fs (sda1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
`----

My question is now:
Is there a way find out when all USB devices that are connected at boot time are initialized (without knowing what kind of devices)?

Thanks,
  Stefan.

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux