Re: g_mass_storage emulation of flash drive - difficulties with passing vendor/product ID

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

 



On Sat, Jul 8, 2017 at 4:52 PM, Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote:
> On Sat, 8 Jul 2017, Alan Robertson wrote:
>
>> On Sat, Jul 8, 2017 at 2:04 AM, Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote:
>> > On Fri, 7 Jul 2017, Alan Robertson wrote:
>> >
>> >> Sorry to return to this topic & appreciate it might be either specific
>> >> to either the Pi or the system(s) I'm connecting it to, but have now
>> >> had time to try a few more combinations out and would appreciate any
>> >> thoughts from the experts here.
>> >>
>> >> To give some extra background - I've got the Pi configured to
>> >> automatically overwrite the mass storage device filestore upon boot,
>> >> so it is always presenting a fresh filesystem.  Each system below is
>> >> made by a different manufacturer and is a closed system, so I have no
>> >> ability to perform any diagnostics at that end.
>> >>
>> >> System 1 - Always works
>> >> System 2 - Shows no USB stick connected
>> >> System 3 - Gives error when trying to save (memory error)
>> >> System 4 - Says unidentified USB
>> >> (Windows PC - Always works)
>> >> (Linux PC - Always works)
>> >>
>> >> At first I thought this was due to minor subtleties of how the
>> >> g_mass_storage device was being presented as a standard Sandisk USB
>> >> memory stick works fine in all systems.
>> >>
>> >> However I then started to notice some unusual behaviour, if rather
>> >> than doing a reboot (and wiping it fresh), I kept the power running
>> >> and moved it between machines.
>> >>
>> >> If I started with System 1 first, then systems 2, 3, 4 would all
>> >> recognise/write to it OK.
>> >>
>> >> I then copied a backup of the filesystem after it had been in System 1
>> >> - however that still didn't seem to solve the problem after a reboot.
>> >> What I did then notice though was that if I powered the Pi up and then
>> >> first connected it to a Windows system it then worked fine when
>> >> plugged in to the others.  To be clear I didn't read/write any files
>> >> to the device, just started it up, then plugged it into Windows, saw
>> >> the home directory on the USB open, then unplugged it and plugged it
>> >> into one of the other systems - they all now recognised it.
>> >>
>> >> I tried starting/stopping g_mass_storage but that in itself didn't
>> >> seem to do it.
>> >
>> > Sorry, this is unclear.
>> >
>> >      1. By starting/stopping g_mass_storage, do you mean doing:
>> >
>> >                 rmmod g_mass_storage
>> >                 modprobe g_mass_storage file=...
>>
>> Yes - at least I believe I've effectively been doing the same albeit a
>> slightly different version of stopping...
>> sudo modprobe -rv g_mass_storage
>
> That's basically the same as rmmod g_mass_storage.

Good, that's what I hoped.

>> and then to start...
>> sudo modprobe g_mass_storage file=/home/pi/piusb.bin stall=0
>> removable=1 idVendor=0x0781 idProduct=0x5572 bcdDevice=0x0126
>> iManufacturer="SanDisk" iProduct="Cruzer Switch"
>> iSerialNumber="4C597515973308202393"
>>
>>
>> >      2. Did you start/stop g_mass_storage after plugging the device
>> >         into a Windows system or System 1?  Or did you do this after
>> >         booting the device but not plugging it into anything?
>>
>> Upon startup it mounts the filesystem as read-only:
>> sudo losetup -o 1048576 /dev/loop0 /home/pi/piusb.bin
>> sudo mount -t vfat -r /dev/loop0 /mnt
>>
>> Then copies contents off, unmounts it, overwrites pisub.bin with
>> backup blank filesystem, then remounts the filesystem read-only again
>> and starts USB.
>
> This does not answer the question I asked.  Had you plugged the device
> into a Windows system or System 1 before you stopped/started
> g_mass_storage?

Ah, sorry - I was providing this info to help answer the second part
of your question 'did you do this after booting the device'.

I did not start/stop g_mass_storage before or after plugging it into a
Windows system or System 1.  I simply let it run through its normal
boot process, then plugged it into Windows PC (or System 1), then
unplugged from there and plugged into any of the other systems.  If I
omitted the step of plugging into WPC/Sys1 it would then not be
recognised by Sys2/3/4.

>> I didn't do anything when plugging into Windows system or System 1 -
>> just started up, plugged into one of those, unplugged and then plugged
>> into one of the other systems.
>
> What happens if you plug the device into either a Windows system or
> System 1, then unplug it, then stop/start g_mass_storage, and then plug
> the device into one of systems 2-4?

Good question - the systems are at work so will need to do that on
Monday, but I hadn't tried that permutation.

>> >      3. By "that in itself didn't seem to do it", do you mean that
>> >         starting/stopping g_mass_storage resulted in no change to the
>> >         behavior?  Or did it always lead to a failure when the device
>> >         was attached to systems 2 - 4, even if it had been plugged into
>> >         System 1 before the start/stop?
>>
>> Correct
>
> I don't understand this answer.  I asked which of two possible
> behaviors you observed, and you replied "Correct".  What does that
> mean?

I was meaning that it resulted in no change to behaviour, but will
double-check that again on Monday - by last thing Friday evening I was
getting slightly frustrated(!) and may not have tried all
permutations.

>> - the only way I could get it to work with systems 2-4 was if
>> it had been initially started up then plugged into PC or system 1.
>> Obviously not ideal given I was hopeful a unit could remain plugged
>> into each system, just starting up whenever the system booted.
>>
>> >> To be honest I'm now a bit flummoxed!  It is clearly able to work with
>> >> all 4 systems (I've been able to save files from them), but it seems
>> >> to want to be plugged into either a PC or System 1 first before then
>> >> working with the others.  Can anyone think of anything that is
>> >> happening when I do this?  Unfortunately the idea of doing it this way
>> >> is just not workable for what I'm wanting to do.  Ideally I would have
>> >> 1 Pi for each system, plugged into it just by the one USB data/power
>> >> cable such that when the system powered on the Pi booted and then the
>> >> USB was available to it to read/write.
>> >
>> > Did you try enabling verbose debugging in g_mass_storage?  This
>> > requires setting CONFIG_USB_GADGET_DEBUG and CONFIG_USB_GADGET_VERBOSE
>> > in the kernel configuration and then rebuilding g_mass_storage.ko.
>> > And at runtime you may need to enable dynamic debugging by doing
>> >
>> >         echo 'module g_mass_storage =p' >/sys/kernel/dynamic_debug/control
>> >
>> > before plugging the device into anything.  Then compare the contents of
>> > the dmesg log for the different scenarios.  In particular, look for
>> > differences between plugging it into System 2 (say) right after boot
>> > vs. after plugging it into System 1.
>>
>> OK interesting - I'll need to do some searching to understand how to
>> change that and rebuild g_mass_storage.ko but I like the idea of
>> seeing more detail about what is happening as the systems are closed
>> so I'm unable to do any troubleshooting at that end.
>
> Do you have any experience in building a kernel for the Raspberry Pi?
> The procedure is explained on several web sites, but you have to know
> what you're doing.

No I don't - I'll have a read over things to see what I can suss out.
--
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