networkimprov / arch-packages

1 stars 0 forks source link

enable usb read-only file-store #20

Open networkimprov opened 10 years ago

networkimprov commented 10 years ago

o.020 enable usb read-only file-store For PC drivers, helper apps, docs. Tony suggested this pseudocode:

# dd if=/dev/zero of=/tmp/storage1 bs=1M count=32
# mkfs.vfat /tmp/storage1
# mount -oloop /tmp/storage1 /mnt
# cp /media/data/doc/* /mnt
# echo /tmp/storage1 > /sys/configfs/whatever/storage/file

And then /tmp/storage1 appears as a disk on the PC.

thomasdziedzic commented 10 years ago

Can't this just be accomplished with the samba task, where we store documents under a docs folder? Is there a reason why we need it to show up as a file store?

networkimprov commented 10 years ago

This file-store would provide setup files to a PC that's not yet configured to find the anvl via wifi p2p or usb-ethernet.

thomasdziedzic commented 10 years ago

I tried to configure the following:

I used the following as a reference: https://www.kernel.org/doc/Documentation/ABI/testing/configfs-usb-gadget-mass-storage

I created a vfat partition on /tmp/storage1

mkdir /sys/kernel/config/usb_gadget/g1/functions/mass_storage.0
echo /tmp/storage1 > /sys/kernel/config/usb_gadget/g1/functions/mass_storage.0/lun.0/file
ln -s  /sys/kernel/config/usb_gadget/g1/functions/mass_storage.0 /sys/kernel/config/usb_gadget/g1/configs/Anvl.1

NOTE: I'm reusing the same folder as your other configs, namely "Anvl.1", not sure if that matters.

I got the following in dmesg on the anvl:

[ 2403.496917] Number of LUNs=8
[ 2403.500244] Mass Storage Function, version: 2009/09/11
[ 2403.505645] LUN: removable file: (no medium)
[ 2428.265655] mass_storage.0/lun.0: open backing file: /tmp/storage1

The anvl is connected to my computer (linux box) but it didn't create any news nodes under /dev/sd* I'm probably missing something obvious, ideas?

networkimprov commented 10 years ago

@tmlind?

tmlind commented 10 years ago

Well the storage is working as the installer is working :) Probably you have to first disable the gadget by doing echo "" > /sys/kernel/config/UDC, then do the configuration, then echo musb-hdrc.0.auto > UDC to enable it again.

thomasdziedzic commented 10 years ago

So I tried the following:

#!/usr/bin/bash

set -x

echo '' > /sys/kernel/config/usb_gadget/g1/UDC 

dd if=/dev/zero of=/tmp/storage1 bs=1M count=32
mkfs.vfat /tmp/storage1
mount -oloop /tmp/storage1 /mnt
echo test > /mnt/tom
umount /mnt

mkdir /sys/kernel/config/usb_gadget/g1/functions/mass_storage.0
echo /tmp/storage1 > /sys/kernel/config/usb_gadget/g1/functions/mass_storage.0/lun.0/file

mkdir /sys/kernel/config/usb_gadget/g1/configs/Anvl.1
ln -s  /sys/kernel/config/usb_gadget/g1/functions/mass_storage.0 /sys/kernel/config/usb_gadget/g2/configs/Anvl.1

echo 'musb-hdrc.0.auto' > /sys/kernel/config/usb_gadget/g1/UDC 

And the script gets stuck with a constant white light on:

+ echo ''

cu: Got hangup signal

Disconnected.

I was wondering, could we have multiple gadgets that use the same UDC driver? I don't think so but it might be worth asking to see if we can separate out the usb-manager related functions from the filestore function. I tried to run the same script but with g2, and when I did the final echo to /sys/kernel/config/usb_gadget/g1/UDC it said the device or resource was busy.

thomasdziedzic commented 10 years ago

Just as a remark, another option is to use the usb-manager to bring up the mass_storage gadget if it turns out that you can't add functions to gadgets that have already been started.

tmlind commented 10 years ago

Yeah we should use usb-manager to configure the mass storage except not configure any backend file for it. Then all the script has to do is echo the backend file name to /sys/kernel/config and it should show up on the PC.

thomasdziedzic commented 10 years ago

Looks like libusbg does not support mass storage after looking through the code. We will have to add this functionality.

@tmlind I think you might be the better person for implementing this since you've already written usb-manager and should be much more familiar with libusbg than I am.

Also, will echoing the file after bringing up the driver work?

tmlind commented 10 years ago

Sure I'll take a look at it a bit later if no huge rush on this. It's removable media, so yes it at least used to work.

thomasdziedzic commented 9 years ago

@tmlind any status on this?

tmlind commented 9 years ago

Sorry have not had a chance to look into this yet.