I want to make the Beagle board to look like a USB Mass Storage Device when it is connected to the host PC.

Hello All

I have configured beagleboard with angstrom linux on it .Now i want a
some computation to be done on beagle board and I want to send
the computed data to the PC through the USB Port…

Please suggest me suitable methods to achieve it.

Is it possible to send the computed data to the SD card and then read the
data from the SD card to the PC using USB Port i.e. Beagle Board acting as
a USB Mass storage device?

Has any one done such effort or written such program or indicate any suitable
reference to fulfill this requirement. Please help me … thanks a lot!!!

Is it possible to send the computed data to the SD card and then read the
data from the SD card to the PC using USB Port i.e. Beagle Board acting as
a USB Mass storage device?

See:

http://www.linux-usb.org/gadget/file_storage.html

Use the OTG port on the xM. The device has to have just one master at a time.

To access the storage from BB firmware, create a loop device with losetup and mount as described in the link above.

To access the storage from a USB host, detach the loop device with umount and losetup -r.

I found it necessary to use stall=0 with modprobe:

modprobe g_file_storage stall=0 file=/root/data/backing_file

I'm using Ubuntu on an xM, and the OTG port doesn't autoswitch between host and device functions. To load the USB host driver, I need to do:

modprobe g_zero

and to enable functioning as a mass-storage drive:

modprobe -r g_zero

This is a patch for this problem:

http://kernel.ubuntu.com/git?p=roc/ubuntu-maverick.git;a=commit;h=de34d10927f1ce3a0027f2751165f16d2e841d9c

I'm hoping this patch will make it into the distributions.

Jan

Hi,

"I have configured beagleboard with angstrom linux on it .Now i want a
some computation to be done on beagle board and I want to send
the computed data to the PC through the USB Port...."

Okay first things first, using USB to send data is not a small feat.
The main problem being USB itself. As you know USB utilizes the
changing states method of transmitting data instead of the simpler
modulation used in UART. In order to transmit bits, states of the the
D0 and D1 lines are changed. So its hard to send data over USB. It
requires a certain level of expertise in messing around with the
Kernel and writing simple character/block drivers.

You could look into that and create custom hardware and write custom
device drivers in order to interact with your end user equipment.
Here's something to get you started with that

http://www.freesoftwaremagazine.com/articles/drivers_linux

http://www.roma1.infn.it/SIC/_OLD_documentazione/unix/migr/digital-unix-doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut3.html#buses

The simpler solution would be to use a FT232 chip to isolate the RX
and TX and transmit data over RS232. Its a matter of using a simple
usb-ttl converter. But this will modify the end user circuit with
another usb-ttl circuit. But its much easier.

I hope this helps

Jan Axelson wrote:

Is it possible to send the computed data to the SD card and then read the
data from the SD card to the PC using USB Port i.e. Beagle Board acting as
a USB Mass storage device?

See:

MSG Backing Storage

Use the OTG port on the xM. The device has to have just one master at a time.

To access the storage from BB firmware, create a loop device with
losetup and mount as described in the link above.

To access the storage from a USB host, detach the loop device with
umount and losetup -r.

I found it necessary to use stall=0 with modprobe:

modprobe g_file_storage stall=0 file=/root/data/backing_file

Instead of a loop device, you can also export a normal sdcard
partition over usb gadget, of course it has to be unmounted
on the linux side 1st, so it better not be the rootfs...

Dear Jan,

I am trying to do what you have said and then send you a reply asap…

thanks and regards,

mohit

pronoyc@gmail.com wrote:

Hi,

"I have configured beagleboard with angstrom linux on it .Now i want a
some computation to be done on beagle board and I want to send
the computed data to the PC through the USB Port...."

Okay first things first, using USB to send data is not a small feat.
The main problem being USB itself. As you know USB utilizes the
changing states method of transmitting data instead of the simpler
modulation used in UART. In order to transmit bits, states of the the
D0 and D1 lines are changed. So its hard to send data over USB. It
requires a certain level of expertise in messing around with the
Kernel and writing simple character/block drivers.

You could look into that and create custom hardware and write custom
device drivers in order to interact with your end user equipment.
Here's something to get you started with that

http://www.freesoftwaremagazine.com/articles/drivers_linux

http://www.roma1.infn.it/SIC/_OLD_documentazione/unix/migr/digital-unix-doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut3.html#buses

The simpler solution would be to use a FT232 chip to isolate the RX
and TX and transmit data over RS232. Its a matter of using a simple
usb-ttl converter. But this will modify the end user circuit with
another usb-ttl circuit. But its much easier.

I hope this helps

you are not aware that linux drivers for USB exist since years?

Hi,

If I use beagle board as USB mass stroage device I might face a problem.

In order to avoid a file system crash on sd card, only one i.e. host or beagle board can read or write sd card at one time. Other one cannot read or write at the same time. Now this causes problem in my operation:

My steps of operation are as follows:

Step 1 : I acquire some data on beagle board through ADC and send to SD Card by mounting it on Beagle Board. Now I unmount the card from beagle board and use gadget driver to mount the sd card on host.

Step2 : Now after Host acquires the data from the sd card, I again want to do some configuration settings for the ADC through host and then begin a fresh acquisition of data using beagle board and ADC.

But How will the beagle board know when to again unmount the gadget driver and again mount sd card on beagle board. Is there some concept of composite driver where mass storage class can be used along side say : uart interface using the same physical usb communication path to send commands from host to beagle board which can aid the above operation. Please help me if I am thinking wrong. Please suggest.

regards

mohit

In order to avoid a file system crash on sd card, only one i.e. host or beagle board can read or write sd card at one time. Other one cannot read or write at the same time. Now this causes problem in my operation:

My steps of operation are as follows:

Step 1 : I acquire some data on beagle board through ADC and send to SD Card by mounting it on Beagle Board. Now I unmount the card from beagle board and use gadget driver to mount the sd card on host.

Step2 : Now after Host acquires the data from the sd card, I again want to do some configuration settings for the ADC through host and then begin a fresh acquisition of data using beagle board and ADC.

But How will the beagle board know when to again unmount the gadget driver and again mount sd card on beagle board. Is there some concept of composite driver where mass storage class can be used along side say : uart interface using the same physical usb communication path to send commands from host to beagle board which can aid the above operation. Please help me if I am thinking wrong. Please suggest.

I wouldn't use the USB mass storage class at all for this. Another way to do it is to collect the data and store it in a file or a data structure. The file will be on the SD card, but you don't need to use a gadget drive. To send the data to the USB host, read the data from the file or get it from the data structure and send the data using a driver such as USB virtual serial port or libusb. Use the same driver to send configuration data, etc.

I have a basic virtual serial port example here:

http://www.lvr.com/beagleboard.htm

Jan

yes you can do a composite MSC + something driver, see e.g. the android
MSC driver that does MSC and adb at the same time.

maybe you can also detect over the MSC link if the host is done reading
the data, it could be that "eject safely" on the host ends up in
specific commands being sent over MSC on which you could trigger on
the device side.

[snip]

yes you can do a composite MSC + something driver, see e.g. the android
MSC driver that does MSC and adb at the same time.

maybe you can also detect over the MSC link if the host is done reading
the data, it could be that "eject safely" on the host ends up in
specific commands being sent over MSC on which you could trigger on
the device side.

  It'll typically do a SCSI STOP which you can use to cue off - indeed,
if you don't then reply to TUNs with 'UNIT NOT READY' you will find
that Win7, for one, remounts your drive after a few sceonds ..

Richard.

In order to avoid a file system crash on sd card, only one i.e. host or beagle board can read or write sd card at one time. Other one cannot read or write at the same time. Now this causes problem in my operation:

My steps of operation are as follows:

Step 1 : I acquire some data on beagle board through ADC and send to SD Card by mounting it on Beagle Board. Now I unmount the card from beagle board and use gadget driver to mount the sd card on host.

Step2 : Now after Host acquires the data from the sd card, I again want to do some configuration settings for the ADC through host and then begin a fresh acquisition of data using beagle board and ADC.

But How will the beagle board know when to again unmount the gadget driver and again mount sd card on beagle board. Is there some concept of composite driver where mass storage class can be used along side say : uart interface using the same physical usb communication path to send commands from host to beagle board which can aid the above operation. Please help me if I am thinking wrong. Please suggest.

I wouldn’t use the USB mass storage class at all for this. Another way to do it is to collect the data and store it in a file or a data structure. The file will be on the SD card, but you don’t need to use a gadget drive. To send the data to the USB host, read the data from the file or get it from the data structure and send the data using a driver such as USB virtual serial port or libusb. Use the same driver to send configuration data, etc.

I have a basic virtual serial port example here:

http://www.lvr.com/beagleboard.htm

Jan

-----------Hello

I would want to try libusb option …pl help …

Could you please send me some helpful link for using libusb in this case …?


1)usb_control_msg(..... )

This is one function i dont understand how will i set parameters
as in my case its not a standard usb device.?

my conceptual doubts in case i use libusb and connect pc to BB using usb port …

BB will act as a device or a host in this case …as far as i know PC has to be host always is it ?

if BB acts as device …then do we have to write some program ob BB to emulate BB as USB device or libusb will suffice dat purpose ?

I have windows on PC side …that program on PC has to use some API available with windows …is libusb still available ?

Nidhi


Hi …
if i want to capture the status of ejection of usb from BB …
then
Does g_file_storage driver provides some callback function …or ioctl may be…through which i can know the status
of usb device whether its ejected or still connected ?

OR
filtering messages from dmesg …is the way ?
?

Nidhi

Hi Richard,

I have windows xp as my host and not windows 7. Now If i proceed with MSC and then
after my data is been read by the host, I eject the SD card from host side. Now on the beagle board side I have to
read whether SCSI STOP command is coming or not. If It does not come, I can proceed
with acquiring data through ADC and storing it on my SD Card (Now again mounted on beagle board).

Please tell me how to capture the SCSI STOP command on beagle board??? I have not
done this before. If you have some useful link through which i can proceed. I am trying from my side.

regards

mohit

I wouldn’t use the USB mass storage class at all for this. Another way to do it is to collect the data and store it in a file or a data structure. The file will be on the SD card, but you don’t need to use a gadget drive. To send the data to the USB host, read the data from the file or get it from the data structure and send the data using a driver such as USB virtual serial port or libusb. Use the same driver to send configuration data, etc.

Hi, Jan,

I will certainly explore your option but it will be on the slower side (I think so). So this will remain a second option.
Or may be the last option can be to send the data on the USB and send commands on UART 33D.gif.

regards

mohit

BB will act as a device or a host in this case ..as far as i know PC has to be host always is it ?

Yes, I was thinking "host" (because that's what's been on my mind) and you need a device port and firmware to connect to a PC.

Have you considered using the BB's Ethernet port?

Jan

Hi ..
if i want to capture the status of ejection of usb from BB ...
then
Does g_file_storage driver provides some callback function ..or ioctl may be...through which i can know the status
of usb device whether its ejected or still connected ?

  I've never used g_file_storage, however a quick look inside drivers/usb/gadget/file_storage.c @
be152079b26269a25c792b8f31b3abb8fa7a6c69 suggests that it doesn't, sadly.

  The way to do this appears to be to use inotify(IN_OPEN, ) on the underlying file and spot
storage_common.c opening and closing it. With luck, you can use mandatory file locking to
prevent storage_common.c opening the file until you're ready to use it - if that fails,
a bit of snarky link()/unlink() locking should do the trick - call your file f_a ; start
inotify() and link() it to f_b which is what file_storage sees.

  When file_storage opens the file, unlink(f_b). When file_storage closes the file you can
now operate on it and when you're ready, link(f_b) it again. There are some nasty races
which you'll need to check against, but that should just about work.

OR
filtering messages from dmesg ...is the way ?
?

  Filtering messages from dmesg is never the way :slight_smile:

Richard.

it should not be too hard to export the current "connection state" of
the MSC gadget driver over e.g. sysfs.

that is not part of the current driver, you would need to add that.

Hello all /Jan ,

As suggested by you , for showing my BB as a usb pendrive to a PC through OTG usb port ,

mohit hada wrote:

Hello all /Jan ,

As suggested by you , for showing my BB as a usb pendrive to a PC through OTG usb port ,

==============================

The steps i followed ------------

Now the backing file i am using is ---
-------dd count=64 bs=1M if=/dev/zero of=backing_file.img

then formatted using mkdosfs command of linux.----------------
-------mkdosfs backing_file.img

this way you directly create a file system on the backing file,
no partition table

Now when i connect BB to *PC with ubuntu on it* through usb OTG ...Its perfectly shown as a pendrive on ubuntu
But
when i connect BB to *PC with WINDOWS XP on it ......BB is detected as a mass storage device connected to windows XP
but no drive is visible in windows explorer !!!!!!!!!!!!!
*please tell me how to access my drive...................................

yes, for unknown reasons, XP does not like a "super floppy" formatted usb stick
and expects a standard drive with a partition table.
We ran into the same issue and finally exported a drive with a partition table
to fix it.

Hi ,
Thanks for your suggestion , Now my BB as MSC is visible in windows xp after partiotiong sdcard .

As discussed earlier …
I need to capture event " eject of usb from windows XP" on BB to handle this event.

As i found that if i remove usb cable from PC then i find a disconnected message on dmesg given by g_File_storage.

but if i just do …"safely remove from windows XP " then i dont get any message on BB …??

as suggestions i have got yet are

1)capture some scsi commands continuously sent by windows xp …if they stop coming means its ejected safely.

----------please give me some pointers how to do this …i have no idea how to capture scsi commands on BB linux.

The way to do this appears to be to use inotify(IN_OPEN, ) on the underlying file and spot storage_common.c opening and closing it. With luck, you can use mandatory file locking to prevent storage_common.c opening the file until you’re ready to use it - if that fails,a bit of snarky link()/unlink() locking should do the trick - call your file f_a ; start
inotify() and link() it to f_b which is what file_storage sees.

When file_storage opens the file, unlink(f_b). When file_storage closes the file you can
now operate on it and when you’re ready, link(f_b) it again. There are some nasty races
which you’ll need to check against, but that should just about work

m really sorry ,…i am not able to understand it … could you please provide me some link to understand it …

or any other solution please would be really helping …
or otherwise i have to put another uart chaneel just for sending eject signal from PC to BB …dats really awakward …pl help !!

thanks
Nidhi