Requirements
In order for this to work configfs must be available, so CONFIGFS_FS must be
‘y’ or ‘m’ in .config. As of this writing USB_LIBCOMPOSITE selects CONFIGFS_FS.
CONFIG_FS:
(1)modprobe libcomposite
(2)mount none $CONFIGFS_HOME -t configfs
(3)創建gadgets
mkdir $CONFIGS_HOME_/usb_gadget/g1
cd $CONFIGFS_HOME/usb_gadget/g1
echo > idVendor
echo > idProduct
mkdir strings/0x409
echo > strings/0x409/serialnumber
echo > strings/0x409/manufacturer
echo > strings/0x409/product
(4)創建配置
mkdir configs/
mkdir configs/c.1 // where can be any string which is legal in a filesystem and the
is the configuration’s number, e.g.
mkdir configs/c.1/strings/0x409 //Each configuration also needs its strings, so a subdirectory must be created
for each language, e.g.:
mkdir configs/c.1/strings/0x409
echo > configs/c.1/strings/0x409/configuration
echo 120 > configs/c.1/MaxPower
(5)創建functions
mkdir functions/.
where corresponds to one of allowed function names and instance name
is an arbitrary string allowed in a filesystem, e.g.:
mkdir functions/ncm.usb0 # usb_f_ncm.ko gets loaded with request_module()
一些attributes
(6)functions assonciating the configrations
ln -s functions/ncm.usb0 configs/c.1
(7) 使能gadget
./configs/c.1/ncm.usb0 -> ../../../../usb_gadget/g1/functions/ncm.usb0
Such a gadget must be finally enabled so that the USB host can enumerate it.
In order to enable the gadget it must be bound to a UDC (USB Device Controller).
ls /sys/class/udc/*
echo s3c-hsotg > UDC
(8) 禁止the gadget
echo “” > UDC
(9)清除配置
rm configfs/c.1/ncm.usb0
rmdir configs/./strings/
rmdir configs/.
rmdir functions/.
rmdir strings/
rmdir g1
//
gadget有它的config組,它有一些屬性(idVendor,idProduct等)和默認子組(配置、函數、字符串)。
寫入屬性會導致信息存儲在適當的位置。在配置、函數和字符串子組中
用戶可以創建子組來表示配置、功能,
以及給定語言中的字符串組。
用戶在配置中創建配置和功能
創建指向函數的符號鏈接。當
gadget的UDC屬性被寫入,這意味着綁定gadget
去UDC。drivers/usb/gadget/configfs.c中的代碼進行迭代
所有的配置,並且在每個配置中迭代所有
函數並綁定它們。這樣整個小工具就被綁定了
小工具的配置組
小工具的默認組(配置、函數、字符串)
將函數與配置相關聯(符號鏈接)
每個USB功能都有自己的想法
已配置,因此定義了特定函數的配置組
在函數實現文件drivers/usb/gadget/f\*.c中。
函數的代碼的編寫方式如下:
usb_get_function_instance(),它反過來調用request_模塊。因此,
只要modprobe正常工作,特定函數的模塊就會自動加載。請注意,反之亦然:
當一個小工具被禁用並被拆除后,模塊仍然被加載。
What: /config/usb-gadget/gadget/functions/uvc.name/control/header/name
Date: Dec 2014
KernelVersion: 3.20
Description: Specific control header descriptors // control value 的header