#!/bin/sh
UMS_EN=off
ADB_EN=off
MTP_EN=off
make_config_string()
{
tmp=C O N F I G S T R I N G i f [ − n " CONFIG_STRING if [ -n "CONFIG
S
TRINGif[−n"CONFIG_STRING" ]; then
CONFIG_STRING=KaTeX parse error: Expected group after '_' at position 6: {tmp}_̲{1}
else
CONFIG_STRING=$1
fi
}
parameter_init()
{
while read line
do
case “$line” in
usb_mtp_en)
MTP_EN=on
make_config_string mtp
;;
usb_adb_en)
ADB_EN=on
make_config_string adb
;;
usb_ums_en)
UMS_EN=on
make_config_string ums
;;
esac
done < $DIR/.usb_config
case "$CONFIG_STRING" in
ums)
PID=0x0000
;;
mtp)
PID=0x0001
;;
adb)
PID=0x0006
;;
mtp_adb | adb_mtp)
PID=0x0011
;;
ums_adb | adb_ums)
PID=0x0018
;;
*)
PID=0x0019
esac
}
configfs_init()
{
mount -t configfs none /sys/kernel/config
mkdir /sys/kernel/config/usb_gadget/rockchip -m 0770
echo 0x2207 > /sys/kernel/config/usb_gadget/rockchip/idVendor
echo $PID > /sys/kernel/config/usb_gadget/rockchip/idProduct
mkdir /sys/kernel/config/usb_gadget/rockchip/strings/0x409 -m 0770
echo “0123456789ABCDEF” > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/serialnumber
echo “rockchip” > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/manufacturer
echo “rk3xxx” > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/product
mkdir /sys/kernel/config/usb_gadget/rockchip/configs/b.1 -m 0770
mkdir /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409 -m 0770
echo 500 > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/MaxPower
echo “$CONFIG_STRING” > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409/configuration
}
function_init()
{
if [ $UMS_EN = on ];then
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/mass_storage.0
echo /dev/disk/by-partlabel/userdata > /sys/kernel/config/usb_gadget/rockchip/functions/mass_storage.0/lun.0/file
ln -s /sys/kernel/config/usb_gadget/rockchip/functions/mass_storage.0 /sys/kernel/config/usb_gadget/rockchip/configs/b.1/mass_storage.0
fi
if [ $ADB_EN = on ];then
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/mass_storage.usb0
mkfs.vfat /dev/ram0
mount /dev/ram0 /media/usb0/
echo /dev/ram0 > /sys/kernel/config/usb_gadget/rockchip/functions/mass_storage.usb0/lun.0/file
ln -s /sys/kernel/config/usb_gadget/rockchip/functions/mass_storage.usb0 /sys/kernel/config/usb_gadget/rockchip/configs/b.1/
fi
if [ $MTP_EN = on ];then
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/mtp.gs0
ln -s /sys/kernel/config/usb_gadget/rockchip/functions/mtp.gs0 /sys/kernel/config/usb_gadget/rockchip/configs/b.1/mtp.gs0
fi
}
case “$1” in
start)
DIR=$(cd dirname $0; pwd)
if [ ! -e “$DIR/.usb_config” ]; then
echo “$0: Cannot find .usb_config”
exit 0
fi
parameter_init
if [ -z $CONFIG_STRING ]; then
echo "$0: no function be selected"
exit 0
fi
configfs_init
function_init
UDC=`ls /sys/class/udc/ | awk '{print $1}'`
echo $UDC > /sys/kernel/config/usb_gadget/rockchip/UDC
;;
stop)
echo “none” > /sys/kernel/config/usb_gadget/rockchip/UDC
;;
restart|reload)
;;
*)
echo “Usage: $0 {start|stop|restart}”
exit 1
esac
原作者:jasonnie17
|