Path: blob/master/tools/usb/usbip/vudc/vudc_server_example.sh
26285 views
#!/bin/bash12################################################################################3# This is free and unencumbered software released into the public domain.4#5# Anyone is free to copy, modify, publish, use, compile, sell, or6# distribute this software, either in source code form or as a compiled7# binary, for any purpose, commercial or non-commercial, and by any8# means.9#10# In jurisdictions that recognize copyright laws, the author or authors11# of this software dedicate any and all copyright interest in the12# software to the public domain. We make this dedication for the benefit13# of the public at large and to the detriment of our heirs and14# successors. We intend this dedication to be an overt act of15# relinquishment in perpetuity of all present and future rights to this16# software under copyright law.17#18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,19# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF20# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.21# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR22# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,23# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR24# OTHER DEALINGS IN THE SOFTWARE.25#26# For more information, please refer to <https://unlicense.org/>27################################################################################2829################################################################################30# This is a sample script which shows how to use vUDC with ConfigFS gadgets31################################################################################3233# Stop script on error34set -e3536################################################################################37# Create your USB gadget38# You may use bare ConfigFS interface (as below)39# or libusbgx or gt toool40# Instead of ConfigFS gadgets you may use any of legacy gadgets.41################################################################################42CONFIGFS_MOUNT_POINT="/sys/kernel/config"43GADGET_NAME="g1"44ID_VENDOR="0x1d6b"45ID_PRODUCT="0x0104"4647cd ${CONFIGFS_MOUNT_POINT}/usb_gadget48# Create a new USB gadget49mkdir ${GADGET_NAME}50cd ${GADGET_NAME}5152# This gadget contains one function - ACM (serial port over USB)53FUNC_DIR="functions/acm.ser0"54mkdir ${FUNC_DIR}5556# Just one configuration57mkdir configs/c.158ln -s ${FUNC_DIR} configs/c.15960# Set our gadget identity61echo ${ID_VENDOR} > idVendor62echo ${ID_PRODUCT} > idProduct6364################################################################################65# Load vudc-module if vudc is not available66# You may change value of num param to get more than one vUDC instance67################################################################################68[[ -d /sys/class/udc/usbip-vudc.0 ]] || modprobe usbip-vudc num=16970################################################################################71# Bind gadget to our vUDC72# By default we bind to first one but you may change this if you would like73# to use more than one instance74################################################################################75echo "usbip-vudc.0" > UDC7677################################################################################78# Let's now run our usbip daemon in a USB device mode79################################################################################80usbipd --device &8182################################################################################83# Now your USB gadget is available using USB/IP protocol.84# To prepare your client, you should ensure that usbip-vhci module is inside85# your kernel. If it's not then you can load it:86#87# $ modprobe usbip-vhci88#89# To check availability of your gadget you may try to list devices exported90# on a remote server:91#92# $ modprobe usbip-vhci93# $ usbip list -r $SERVER_IP94# Exportable USB devices95# ======================96# usbipd: info: request 0x8005(6): complete97# - 127.0.0.198# usbip-vudc.0: Linux Foundation : unknown product (1d6b:0104)99# : /sys/devices/platform/usbip-vudc.0100# : (Defined at Interface level) (00/00/00)101#102# To attach this device to your client you may use:103#104# $ usbip attach -r $SERVER_IP -d usbip-vudc.0105#106################################################################################107108109