您尚未登录。

楼主 #1 2020-11-26 21:43:14

歌以咏志
会员
注册时间: 2019-09-21
已发帖子: 219
积分: 210

请问Linux kernel空间和User空间的两个复合 usb gadget 功能怎么玩呢?

https://elinux.org/images/e/ef/USB_Gadget_Configfs_API_0.pdf

FunctionFS added in 2010
○ compositable version of gadgetfs
○ now userspace gadget functions can be combined
with kernel gadget functions in a composite gadget
○ e.g. mass storage (kernel) + MTP (via FunctionFS)


aodzip大佬这个只实现了MTP, 没有mass storage实现


buildroot-tiny200 (F1C100/200s) 开发包近期更新内容 * 已支持DVP摄像头 *
http://whycan.com/t_5221.html
(出处:哇酷开发者社区【全志 V3S/F1C100s/X3】)

离线

#2 2020-11-26 21:56:27

孤星泪
会员
注册时间: 2020-03-18
已发帖子: 235
积分: 231

Re: 请问Linux kernel空间和User空间的两个复合 usb gadget 功能怎么玩呢?

好奇搜了一下, 还真有这玩意: http://www.trivialfeat.com/home/2016/11/17/media-transfer-protocol-in-a-usb-composite-gadget

/etc/init.d/S99-gadget

#!/bin/sh

CONFIGFS="/sys/kernel/config"
GADGET="$CONFIGFS/usb_gadget"
VID="0x0000"
PID="0x0000"
SERIAL="0123456789"
MANUF="Me"
PRODUCT="Radget"

case "$1" in
    start)
        echo "Creating the USB gadget"

        echo "Loading composite module"
        modprobe libcomposite

        echo "Mounting ConfigFS"
        mount -t configfs none $CONFIGFS
        cd $GADGET
        if [ $? -ne 0 ]; then
            echo "Error setting up configfs"
            exit 1;
        fi

        echo "Creating gadget directory"
        mkdir gadget
        cd gadget
        if [ $? -ne 0 ]; then
            echo "Error creating usb gadget in configfs"
            exit 1;
        fi

        echo "Setting Vendor and Product ID's"
        echo $VID > idVendor
        echo $PID > idProduct

        echo "Setting English strings"
        mkdir strings/0x409
        echo $SERIAL > strings/0x409/serialnumber
        echo $MANUF > strings/0x409/manufacturer
        echo $PRODUCT > strings/0x409/product

        echo "Setting configuration"
        mkdir configs/c.1
        mkdir configs/c.1/strings/0x409
        echo "CDC ACM + MTP + Mass Storage" > configs/c.1/strings/0x409/configuration
        echo 120 > configs/c.1/MaxPower

        echo "Creating ACM interface"
        mkdir functions/acm.GS0
        ln -s functions/acm.GS0 configs/c.1

        echo "Creating MTP interface"
        mkdir functions/mtp.mtp
        ln -s functions/mtp.mtp configs/c.1
        mkdir /dev/mtp
        mount -t functionfs mtp /dev/mtp

        echo "Creating Mass Storage interface"  
        mkdir functions/mass_storage.ms0
        echo "/dev/mmcblk0" > functions/mass_storage.ms0/lun.0/file
        echo "1" > functions/mass_storage.ms0/lun.0/removable
        ln -s functions/mass_storage.ms0 configs/c.1/mass_storage.ms0

        echo "Binding USB Device Controller"
        echo `ls /sys/class/udc` > UDC

        echo "Starting the MTP responder daemon"
        mtp-server &
        ;;
    stop)
        echo "Stopping the USB gadget"

        echo "Killing MTP responder daemon"
        killall mtp-server

        cd $GADGET/gadget

        if [ $? -ne 0 ]; then
            echo "Error: no configfs gadget found" 
            exit 1;
        fi

        echo "Unbinding USB Device Controller"
        echo "" > UDC

        echo "Removing Mass Storage interface"
        rm configs/c.1/mass_storage.ms0
        rmdir functions/mass_storage.ms0

        echo "Removing MTP interface"
        umount /dev/mtp
        rmdir /dev/mtp
        rm configs/c.1/mtp.mtp
        rmdir functions/mtp.mtp

        echo "Removing ACM interface"
        rm configs/c.1/acm.GS0
        rmdir functions/acm.GS0

        echo "Clearing English strings"
        rmdir strings/0x409

        echo "Cleaning up configuration"
        rmdir configs/c.1/strings/0x409
        rmdir configs/c.1

        echo "Removing gadget directory"
        cd $GADGET
        rmdir gadget

        cd /

        echo "Unmounting ConfigFS"
        umount $CONFIGFS
        ;;
esac

离线

楼主 #3 2020-11-26 22:05:12

歌以咏志
会员
注册时间: 2019-09-21
已发帖子: 219
积分: 210

Re: 请问Linux kernel空间和User空间的两个复合 usb gadget 功能怎么玩呢?

太棒了, 我要的就是这玩意, 看来还能整一个adbd进去.

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn