7 Replies Latest reply on Apr 14, 2015 6:02 PM by ghawkins1969

    Disable mass storage behavior when Edison is attached?

    ghawkins1969

      Is there a way to prevent the Edison from claiming to be a USB mass storage device when it's connected to another computer?

       

      I'm using the Edison with the mini-breakout and when I connect it via J16, i.e. the lower right USB port, it advertises itself as various things - including a mass storage device.

       

      Can I disable the mass storage bit? I need to demo the Edison and want to avoid having to click away USB drive related dialogs whenever I plug it into a new computer.

       

      When I plug in the Edison I see this kind of chatter in syslog (I'm using Ubuntu):

       

      kernel: [748845.607657] usb 3-1.4: USB disconnect, device number 116

      kernel: [748852.888320] usb 3-1.4: new high-speed USB device number 117 using xhci_hcd

      kernel: [748852.904672] usb 3-1.4: New USB device found, idVendor=8087, idProduct=0a9e

      kernel: [748852.904675] usb 3-1.4: New USB device strings: Mfr=2, Product=3, SerialNumber=4

      kernel: [748852.904676] usb 3-1.4: Product: Edison

      kernel: [748852.904677] usb 3-1.4: Manufacturer: Intel

      kernel: [748852.904678] usb 3-1.4: SerialNumber: 67bdabe9c29990795492188ae6a143e8


      kernel: [748852.906556] usb-storage 3-1.4:2.4: USB Mass Storage device detected

      kernel: [748852.906625] scsi32 : usb-storage 3-1.4:2.4


      kernel: [748854.611608] scsi 32:0:0:0: Direct-Access    Linux    File-CD Gadget  0310 PQ: 0 ANSI: 2   

      kernel: [748854.611858] sd 32:0:0:0: Attached scsi generic sg2 type 0

      kernel: [748854.613758] sd 32:0:0:0: [sdb] 1572864 512-byte logical blocks: (805 MB/768 MiB)

      kernel: [748854.614014] sd 32:0:0:0: [sdb] Write Protect is off

      kernel: [748854.614016] sd 32:0:0:0: [sdb] Mode Sense: 0f 00 00 00

      kernel: [748854.614418] sd 32:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA

      kernel: [748854.615820]  sdb: sdb1

      kernel: [748854.616827] sd 32:0:0:0: [sdb] Attached SCSI disk


      udisksd[2058]: Mounted /dev/sdb1 at /media/ghawkins/Edison on behalf of uid 1000


      I tried looking for the product ID etc. in my Edison image to see if I could spot e.g. something easy to comment out in some config file but didn't find anything obvious.


      I hope it doesn't require a kernel mod to disable the mass storage behavior!


      Thanks for any insights,


      /George

        • 1. Re: Disable mass storage behavior when Edison is attached?
          DiegoV_Intel

          Hi ghawkins1969,

           

          I'm not sure how it can be done. I found a thread http://www.linuxquestions.org/questions/linux-newbie-8/how-to-disable-usb-mass-storage-device-usb-drive-in-linux-651262/ about this same question. Please check it, you might find it useful.

           

          I will try to find a way to perform this. If I get something useful I will post it here.

           

          Regards,

          Diego.

          • 2. Re: Disable mass storage behavior when Edison is attached?
            ghawkins1969

            Hi Diego --

             

            Thanks for the reply. The thread you point to is about getting a system to not handle USB mass storage devices, i.e. effectively ignore them.

             

            This isn't what I want. I don't want to change the systems to which I connect the Edison (to make them ignore its USB mass storage behavior).

             

            I want to change the Edison so that it doesn't advertise itself as having USB mass storage behavior in the first place.

             

            When you plug a USB device, in our case an Edison, into a system it communicates a set of class codes to the host system telling it what kind of thing it is.

             

            The Edison communicates a number of class codes, including the one for mass storage (code 0x08).

             

            I want to stop it communicating this class code.

             

            http://en.wikipedia.org/wiki/USB#Device_classes

             

            Regards,

             

            /George

            • 3. Re: Disable mass storage behavior when Edison is attached?
              ghawkins1969

              After some further investigation I find that the module that seems to handle all this is called g_multi - it takes care of both mass storage over USB and the ethernet over USB.


              Location: /lib/modules/3.10.17-poky-edison+/kernel/drivers/usb/gadget/g_multi.ko


              In /usr/bin/configure_edison I can see that 'rmmod g_multi' is called to temporarily disconnect the Edison while it accesses /dev/disk/by-partlabel/update in order to update the system image.


              So I'm guessing something somewhere is telling g_multi to make /dev/disk/by-partlabel/update available as USB mass storage.


              However I can't find any configuration file that seems to do that.


              All I've found is /etc/modprobe.d/g_multi.conf which refers to a different file:

               

                  options g_multi file=/dev/mmcblk0p9 stall=0 idVendor=0x8087 idProduct=0x0A9E iProduct=Edison iManufacturer=Intel


              Note: I guess g_multi uses the mass storage gadget - http://www.linux-usb.org/gadget/file_storage.html


              You can see the mass storage code for the gadget in git: http://git.yoctoproject.org/cgit.cgi/linux-yocto-3.19/tree/drivers/usb/gadget/function/f_mass_storage.c

              • 4. Re: Disable mass storage behavior when Edison is attached?
                ghawkins1969

                Ah... if I use readlink I see that /dev/disk/by-partlabel/update is just a soft link to /dev/mmcblk0p9:

                 

                    # readlink -f /dev/disk/by-partlabel/update

                    /dev/mmcblk0p9

                 

                So I guess (wildly) that if I remove 'file=/dev/mmcblk0p9' from /etc/modprobe.d/g_multi.conf it'll disable the mass storage behavior of g_multi (when I reload the module or reboot).

                 

                Let's try it and see if I brick my Edison I wish I could find some documentation relating to this .conf file to give me some confidence that this is the right thing to do.

                • 5. Re: Disable mass storage behavior when Edison is attached?
                  DiegoV_Intel

                  Hi ghawkins1969,

                   

                  I don't recommend you to do that, the module could be damaged because it might cause Edison not to boot correctly.

                   

                  I will suggest you bulding a custom image and modify the partition table instead.

                   

                  Regards,

                  Diego.

                  • 6. Re: Disable mass storage behavior when Edison is attached?
                    ghawkins1969

                    OK - I finally worked it out after an hour or so of trawling through the kernel sources. It doesn't involve custom images or anything complicated.

                     

                    If you don't want to hear all the exciting details just jump down to the TL;DR section below.

                     

                    The module that controls all this is called g_multi - it allows you to configure multiple LUNs - http://en.wikipedia.org/wiki/Logical_unit_number

                     

                    Essentially multiple logical drives.

                     

                    This is documented here - http://git.yoctoproject.org/cgit.cgi/linux-yocto-3.10/tree/Documentation/usb/mass-storage.txt

                     

                    The relevant configuration file is - /etc/modprobe.d/g_multi.conf

                     

                    By default it contains:

                     

                    options g_multi file=/dev/mmcblk0p9 stall=0 idVendor=0x8087 idProduct=0x0A9E iProduct=Edison iManufacturer=Intel

                     

                    If we look at the documentation we can see that this is just configuring one LUN. You could configure multiple LUNs by specifying multiple backing files like so:

                     

                    file=/path/to/file1,/path/to/file2

                     

                    OK - now let's see if we can track down how the file name is used... We find something interesting if we look at line 2716 onward of:

                     

                    http://git.yoctoproject.org/cgit.cgi/linux-yocto-3.10/tree/drivers/usb/gadget/f_mass_storage.c

                     

                    if (lcfg->filename) {

                        ...

                    } else if (!curlun->removable) {

                        ...

                     

                    From this we see that we can either specify a backing file or specify that the device is removable.

                     

                    If we go back to the documentation it all becomes clear.

                     

                    Instead of file=... we can specify removable=y and then on jumping down to the section "sysfs entries" it's clear we can start off as if our virtual drive were ejected and then, if required, mount it from userspace by echoing the required backing file name into a special configuration file (confusingly called "file" way down in /sys).

                     

                    A bit more digging and we can find that file like so:

                     

                    # find /sys/devices -name gadget

                    /sys/devices/pci0000:00/0000:00:11.0/dwc3-device.1/gadget

                    # cd /sys/devices/pci0000:00/0000:00:11.0/dwc3-device.1/gadget

                    # ls

                    lun0  net  power  suspended  uevent

                    # cd lun0

                    # ls

                    file  nofua  power  ro  uevent

                    # cat file

                    /dev/mmcblk0p9

                     

                    So lun0 corresponds to the single LUN that was configured in /etc/modprobe.d/g_multi.conf and as expected "file" contains the name of the configured backing store file.

                     

                    TL;DR:

                     

                    So finally this is all that needs to be done:

                     

                    # vi /etc/modprobe.d/g_multi.conf

                    Replace file=/dev/mmcblk0p9 with removable=y

                    # systemctl reboot

                     

                    Ta-da - the Edison reboots fine but doesn't advertise a USB mass storage device to the system to which it's connected.

                     

                    If I do now want to expose the usual backing file to the connected system I can just do:

                     

                    # find /sys/devices -name gadget

                    /sys/devices/pci0000:00/0000:00:11.0/dwc3-device.1/gadget

                    # cd /sys/devices/pci0000:00/0000:00:11.0/dwc3-device.1/gadget

                    # cd lun0

                    # echo /dev/mmcblk0p9 > file

                     

                    And - cool - up it pops now on the connected system.

                    1 of 1 people found this helpful