Configfs使用

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 







  

  

一勤天下无难事。
原文地址:https://www.cnblogs.com/nowroot/p/14105828.html