How to change the USB slave directory with Debian BBB

When the BBB is plugged into a host PC via USB it appears as a removeable drive that points to /boot/uboot. It is possible to configure the BBB to point somewhere else when used as a slave device?

If you wish to use only to the ethernet or serial aspect of the driver you may disable g_multi and then . . .

  1. enable g_ether for ethernet over USB
  2. enable g_serial for serial over USB

Note: only one gadget ( g_* ) driver can be used at a time. Hence g_ multi to encompass all 3 drivers in one.

Disabling one driver, and then enabling another can be tricky depending on which init daemon you’re using. If you’re using SYSV, then simply using modprobe can / should work. To make the change persistent across reboots, put the driver ( name ) into /etc/modules. As for systemd, I’ll leave that up to you, and your search engine of choice. As an exercise.

Search terms:

  1. g_multi
  2. g_mass_storage
  3. g_ether
  4. g_serial

Now, if using a Windows host, and wishing to change what directory / partition the BBB is pointing to, you have a couple problems. First, Windows has no idea how to read Linux file systems - Out of the box. Second, Since the only real common file system shared between Linux, and Windows is of type FAT( which probably means FAT 32 and exFAT as well ). Well the FAT filesystem has no concept of file permissions. Which means such a file system / partition can not be set as read only, or have files accessible only by certain users. e.g. a potential security issue.

Oh, and before anyone tries getting smart and saying that Linux and Windows can both read NTFS file systems . . . Try running Linux on an NTFS file system.

Hi William,

Thank you for the reply. I understand that when used as a USB slave, there will be no security for the portion of the file system that appears as a thumb drive.

Is it possible to plug the BBB in as a slave device and have the PC see the SD card instead of the default BeagleBone Getting Started location?

Ted

Just specify the drive when loading g_multi

You'll find it under: /opt/scripts/boot/am335x_evm.sh

file=xyz (partition you want to share over usb as a flash drive)

https://github.com/RobertCNelson/boot-scripts/blob/master/boot/am335x_evm.sh#L100

Regards,

Thanks Robert. I knew it had to be something easy.
Ted

Yeap, as Robert said. Which is also in the g_mass_storage kernel module documentation :wink: The only reason why I did not write it myself, as I was unsure of the exact syntax, and you could have read the doc file as easily as I . . .

Hi Mr. Nelson,

I have a spent a lot of time trying to make the SD card visible as a USB mass storage but it still doesn’t work.
The OS is installed on the internall eMMC, which is mmcblk1p1. (The SD card is mmcblk0p1).

I have edited am335x_evm.sh as follows:

#usb_image_file="/var/local/usb_mass_storage.img"

usb_image_file="/dev/mmcblk0p1"

#*.iso priority over *.img #if [ -f /var/local/bb_usb_mass_storage.iso ] ; then # usb_image_file="/var/local/bb_usb_mass_storage.iso" #elif [ -f /var/local/bb_usb_mass_storage.img ] ; then # usb_image_file="/var/local/bb_usb_mass_storage.img" #fi

The BBB boots and works fine but it is not detected anymore when connecting by USB.
Most of the doc I find on this topic is from 2014-2015 and I guess am335x_evm.sh could have changed in the meantime.
My SD card is formatted to NTFS and is not detected on Linux or Windows platforms even if I unmount it from the BBB.

I am using the latest OS available: Debian 9.5, Linux 4.14.71-ti-r80 #1 SMP PREEMPT Fri Oct 5 23:50:11 UTC 2018 armv7l GNU/Linux
on a BBB rev C.

Note that I am quite new to Linux so it’s not all obvious for me haha

Thanks a lot!

Guillaume

use fat32...

Regards,

Hi,

I also tried with FAT32 previously, but the problem was elsewhere.
However, I reformatted to FAT32 to eliminate the risk.

Here is how I finally made it work with my version:

#Allow the USB mass storage to be “not read only”. Be careful…
usb_ms_ro=0

usb_image_file="/dev/mmcblk0p1"

#Do not use the .img or .iso file on boot.
#*.iso priority over *.img
#if [ -f /var/local/bb_usb_mass_storage.iso ] ; then

usb_image_file="/var/local/bb_usb_mass_storage.iso"

#elif [ -f /var/local/bb_usb_mass_storage.img ] ; then

usb_image_file="/var/local/bb_usb_mass_storage.img"

#fi


#in run_libcomposite, force has_img_file to true so it works everytime:

has_img_file=“true”
if [ “x${has_img_file}” = “xtrue” ] ; then
echo “${log} enable USB mass_storage ${usb_image_file}”

in use_libcomposite:

Allow to share mmcblk0p1 over USB

#if [ “x${root_drive}” = “x/dev/mmcblk0p1” ] || [ “x${root_drive}” = “x/dev/mmcblk1p1” ] ; then

echo “${log} FIXME: no valid drive to share over usb”

#else

actual_image_file="${root_drive%?}1"

#fi


actual_image_file="/dev/mmcblk0p1"

This is not super clean but it does what I want, as long as the boot device is the eMMC.
Note that this is with Debian 9.5, Linux 4.14.71-ti-r80 #1 SMP PREEMPT Fri Oct 5 23:50:11 UTC 2018 armv7l GNU/Linux.

I can’t attach files here but if it could be useful to anyone, just e-mail me.

Guillaume