From 2783f9be9542aad8e9fbef845fc91fa63b56b431 Mon Sep 17 00:00:00 2001 From: Apaczer <94932128+Apaczer@users.noreply.github.com> Date: Thu, 18 Sep 2025 22:35:33 +0200 Subject: [PATCH] BOARD: refactor/simplify & update USB scripts for connection detect (#181) * update USB scripts for connection detect don't remove gadget after running HID, or it is impossible to detect USB connection afterwards * refactor - create unified `usb-mode` script - move it to rootfs /usr/bin - use parrent for mdkir cmds --- board/miyoo/main/apps/usb-hid/usb-hid.sh | 23 -- board/miyoo/main/apps/usb-host/usb-host.sh | 16 -- board/miyoo/main/apps/usb-mtd/remove.sh | 36 --- board/miyoo/main/apps/usb-mtd/usb-mtd.sh | 33 --- .../main/apps/usb-network/usb-network.sh | 55 ---- .../apps/usb-serial-console/usb-serial.sh | 31 --- .../gmenu2x/sections/applications/usb-hid | 4 +- .../gmenu2x/sections/applications/usb-host | 3 +- .../gmenu2x/sections/applications/usb-mtd | 3 +- .../gmenu2x/sections/applications/usb-network | 3 +- .../sections/applications/usb-serial-console | 3 +- .../{apps/usb-hid => manuals}/usb-hid.man.txt | 0 board/miyoo/rootfs/etc/main | 29 +- .../usb-hid => rootfs/usr/bin}/usb-hid.py | 0 board/miyoo/rootfs/usr/bin/usb-mode | 260 ++++++++++++++++++ 15 files changed, 275 insertions(+), 224 deletions(-) delete mode 100755 board/miyoo/main/apps/usb-hid/usb-hid.sh delete mode 100755 board/miyoo/main/apps/usb-host/usb-host.sh delete mode 100755 board/miyoo/main/apps/usb-mtd/remove.sh delete mode 100755 board/miyoo/main/apps/usb-mtd/usb-mtd.sh delete mode 100755 board/miyoo/main/apps/usb-network/usb-network.sh delete mode 100755 board/miyoo/main/apps/usb-serial-console/usb-serial.sh rename board/miyoo/main/{apps/usb-hid => manuals}/usb-hid.man.txt (100%) mode change 100755 => 100644 rename board/miyoo/{main/apps/usb-hid => rootfs/usr/bin}/usb-hid.py (100%) create mode 100755 board/miyoo/rootfs/usr/bin/usb-mode diff --git a/board/miyoo/main/apps/usb-hid/usb-hid.sh b/board/miyoo/main/apps/usb-hid/usb-hid.sh deleted file mode 100755 index 56c40856..00000000 --- a/board/miyoo/main/apps/usb-hid/usb-hid.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/busybox sh -st_error_func(){ - st -k -e "/bin/sh" "-c" "echo -e \"\e[31m${1}\e[0m\"; sleep 2" -} -st_exec_func(){ - st -k -e "/bin/sh" "-c" "${1}" -} -echo peripheral > /sys/devices/platform/soc/1c13000.usb/musb-hdrc.1.auto/mode -killall umtprd umtprd-debug -/mnt/apps/usb-mtd/remove.sh g2 -modprobe usb_f_hid -modprobe evdev -modprobe uinput -mount none /sys/kernel/config -t configfs -gadget-hid -st_exec_func "\ - echo -e \"\e[32m\n\n\n\n\n\n Starting USB-HID mode\e[0m\n\n\n\"; \ - sleep 1; \ - python /mnt/apps/usb-hid/usb-hid.py" -gadget-vid-pid-remove 0x1d6b:0x0104 -modprobe -r usb_f_hid -modprobe -r evdev -modprobe -r uinput diff --git a/board/miyoo/main/apps/usb-host/usb-host.sh b/board/miyoo/main/apps/usb-host/usb-host.sh deleted file mode 100755 index 2a142d20..00000000 --- a/board/miyoo/main/apps/usb-host/usb-host.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/busybox sh -echo host > /sys/devices/platform/soc/1c13000.usb/musb-hdrc.1.auto/mode -sleep 2 - -modprobe evdev -modprobe joydev -modprobe analog -modprobe xpad -modprobe atkbd -modprobe uinput -modprobe psmouse -modprobe synaptics_usb -modprobe mousedev -modprobe usbhid -modprobe hid-generic -modprobe hid \ No newline at end of file diff --git a/board/miyoo/main/apps/usb-mtd/remove.sh b/board/miyoo/main/apps/usb-mtd/remove.sh deleted file mode 100755 index 69a8f2c5..00000000 --- a/board/miyoo/main/apps/usb-mtd/remove.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh - -SYSDIR=/sys/kernel/config/usb_gadget/ -DEVDIR=$SYSDIR/$1 - -[ -d $DEVDIR ] || exit - -echo '' > $DEVDIR/UDC - -echo "Removing strings from configurations" -for dir in $DEVDIR/configs/*/strings/*; do - [ -d $dir ] && rmdir $dir -done - -echo "Removing functions from configurations" -for func in $DEVDIR/configs/*.*/*.*; do - [ -e $func ] && rm $func -done - -echo "Removing configurations" -for conf in $DEVDIR/configs/*; do - [ -d $conf ] && rmdir $conf -done - -echo "Removing functions" -for func in $DEVDIR/functions/*.*; do - [ -d $func ] && rmdir $func -done - -echo "Removing strings" -for str in $DEVDIR/strings/*; do - [ -d $str ] && rmdir $str -done - -echo "Removing gadget" -rmdir $DEVDIR \ No newline at end of file diff --git a/board/miyoo/main/apps/usb-mtd/usb-mtd.sh b/board/miyoo/main/apps/usb-mtd/usb-mtd.sh deleted file mode 100755 index c3636164..00000000 --- a/board/miyoo/main/apps/usb-mtd/usb-mtd.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/busybox sh - -echo peripheral > /sys/devices/platform/soc/1c13000.usb/musb-hdrc.1.auto/mode -modprobe usb_f_fs -killall umtprd umtprd-debug -/mnt/apps/usb-mtd/remove.sh g2 -mount none /sys/kernel/config -t configfs -mkdir /sys/kernel/config/usb_gadget/g2 -cd /sys/kernel/config/usb_gadget/g2 -mkdir configs/c.1 -mkdir functions/ffs.mtp -mkdir strings/0x409 -mkdir configs/c.1/strings/0x409 - -echo 0x0100 > idProduct -echo 0x1D6B > idVendor - -echo "Miyoo Handheld" > strings/0x409/manufacturer -echo "Miyoo CFW 2.0" > strings/0x409/product - -echo "Conf 1" > configs/c.1/strings/0x409/configuration -echo 120 > configs/c.1/MaxPower -ln -s functions/ffs.mtp configs/c.1 -mkdir /dev/ffs-mtp -mount -t functionfs mtp /dev/ffs-mtp -if (grep -q DEBUG_UMTPR\=\1 "${HOME}/options.cfg"); then -umtprd-debug & -else -umtprd & -fi -sleep 1 -ls /sys/class/udc/ > /sys/kernel/config/usb_gadget/g2/UDC - diff --git a/board/miyoo/main/apps/usb-network/usb-network.sh b/board/miyoo/main/apps/usb-network/usb-network.sh deleted file mode 100755 index b5fdfa87..00000000 --- a/board/miyoo/main/apps/usb-network/usb-network.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/busybox sh -st -k -e "/bin/sh" "-c" "echo -e \"Starting USB network, please wait...\"; sleep 2" - -MAC_HOST="12:34:56:78:9a:bd" -MAC_DEV="12:34:56:78:9a:bc" - -echo peripheral > /sys/devices/platform/soc/1c13000.usb/musb-hdrc.1.auto/mode -killall umtprd umtprd-debug -/mnt/apps/usb-mtd/remove.sh g2 -modprobe usb_f_rndis -sleep 1 - -mount none /sys/kernel/config -t configfs -mkdir /sys/kernel/config/usb_gadget/g2 -cd /sys/kernel/config/usb_gadget/g2 -mkdir configs/c.1 -mkdir strings/0x409 - -mkdir functions/rndis.usb0 -mkdir configs/c.1/strings/0x409 - -echo 0x0104 > idProduct -echo 0x1D6B > idVendor -echo "0x0200" > bcdUSB -echo "0x02" > bDeviceClass -echo "0x00" > bDeviceSubClass -echo "0x3066" > bcdDevice -echo "1" > os_desc/use -echo "0xcd" > os_desc/b_vendor_code -echo "MSFT100" > os_desc/qw_sign -echo "RNDIS" > functions/rndis.usb0/os_desc/interface.rndis/compatible_id -echo "5162001" > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id - -echo $MAC_HOST > functions/rndis.usb0/host_addr -echo $MAC_DEV > functions/rndis.usb0/dev_addr - -echo "Miyoo Handheld" > strings/0x409/manufacturer -echo "Miyoo CFW 2.0" > strings/0x409/product - -echo "Conf 1" > configs/c.1/strings/0x409/configuration -echo 120 > configs/c.1/MaxPower -ln -s functions/rndis.usb0 configs/c.1 -ln -s configs/c.1 os_desc -sleep 1 - -#ls /sys/class/udc/ > /sys/kernel/config/usb_gadget/g2/UDC -#sleep 5 -#echo "" > UDC - -echo "0x00" > bDeviceClass -ls /sys/class/udc/ > /sys/kernel/config/usb_gadget/g2/UDC - -ifconfig usb0 up 192.168.137.1 -sleep 10 -/etc/init.d/S80dhcp-server restart diff --git a/board/miyoo/main/apps/usb-serial-console/usb-serial.sh b/board/miyoo/main/apps/usb-serial-console/usb-serial.sh deleted file mode 100755 index e5ff1f2b..00000000 --- a/board/miyoo/main/apps/usb-serial-console/usb-serial.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/busybox sh - -echo peripheral > /sys/devices/platform/soc/1c13000.usb/musb-hdrc.1.auto/mode - -killall umtprd umtprd-debug -/mnt/apps/usb-mtd/remove.sh g2 -mount none /sys/kernel/config -t configfs - -mkdir /sys/kernel/config/usb_gadget/g2 -cd /sys/kernel/config/usb_gadget/g2 - -mkdir configs/c.1 -mkdir functions/acm.usb0 -mkdir strings/0x409 -mkdir configs/c.1/strings/0x409 - -echo 0x0104 > idProduct # Produkt: CDC ACM (Serial) -echo 0x1D6B > idVendor # Producent: Linux Foundation - -echo "Miyoo Handheld" > strings/0x409/manufacturer -echo "Miyoo CFW 2.0" > strings/0x409/product -echo "deadbeef12345678" > strings/0x409/serialnumber - -echo "Conf 1" > configs/c.1/strings/0x409/configuration -echo 120 > configs/c.1/MaxPower - -ln -s functions/acm.usb0 configs/c.1 - -sleep 1 -ls /sys/class/udc/ > /sys/kernel/config/usb_gadget/g2/UDC - diff --git a/board/miyoo/main/gmenu2x/sections/applications/usb-hid b/board/miyoo/main/gmenu2x/sections/applications/usb-hid index 86980a4f..43e6b663 100644 --- a/board/miyoo/main/gmenu2x/sections/applications/usb-hid +++ b/board/miyoo/main/gmenu2x/sections/applications/usb-hid @@ -1,3 +1,5 @@ title=USB HID description=USB HID PC gamepad -exec=/mnt/apps/usb-hid/usb-hid.sh +exec=/usr/bin/usb-mode +params=hid +manual=/mnt/manuals/usb-hid.man.txt \ No newline at end of file diff --git a/board/miyoo/main/gmenu2x/sections/applications/usb-host b/board/miyoo/main/gmenu2x/sections/applications/usb-host index 636c7a41..abb95c34 100644 --- a/board/miyoo/main/gmenu2x/sections/applications/usb-host +++ b/board/miyoo/main/gmenu2x/sections/applications/usb-host @@ -1,3 +1,4 @@ title=USB Host description=USB Host mode -exec=/mnt/apps/usb-host/usb-host.sh +exec=/usr/bin/usb-mode +params=host diff --git a/board/miyoo/main/gmenu2x/sections/applications/usb-mtd b/board/miyoo/main/gmenu2x/sections/applications/usb-mtd index 9e22d086..7e45c1ad 100644 --- a/board/miyoo/main/gmenu2x/sections/applications/usb-mtd +++ b/board/miyoo/main/gmenu2x/sections/applications/usb-mtd @@ -1,3 +1,4 @@ title=USB MTD description=USB MTD mass storage -exec=/mnt/apps/usb-mtd/usb-mtd.sh +exec=/usr/bin/usb-mode +params=mtp umtprd diff --git a/board/miyoo/main/gmenu2x/sections/applications/usb-network b/board/miyoo/main/gmenu2x/sections/applications/usb-network index ef9343f8..b51983a4 100644 --- a/board/miyoo/main/gmenu2x/sections/applications/usb-network +++ b/board/miyoo/main/gmenu2x/sections/applications/usb-network @@ -1,3 +1,4 @@ title=USB Network description=IP:192.168.137.1 -exec=/mnt/apps/usb-network/usb-network.sh +exec=/usr/bin/usb-mode +params=net diff --git a/board/miyoo/main/gmenu2x/sections/applications/usb-serial-console b/board/miyoo/main/gmenu2x/sections/applications/usb-serial-console index fec9d8d5..6b3b79ac 100644 --- a/board/miyoo/main/gmenu2x/sections/applications/usb-serial-console +++ b/board/miyoo/main/gmenu2x/sections/applications/usb-serial-console @@ -1,3 +1,4 @@ title=USB serial console description=USB Serial console -exec=/mnt/apps/usb-serial-console/usb-serial.sh +exec=/usr/bin/usb-mode +params=serial diff --git a/board/miyoo/main/apps/usb-hid/usb-hid.man.txt b/board/miyoo/main/manuals/usb-hid.man.txt old mode 100755 new mode 100644 similarity index 100% rename from board/miyoo/main/apps/usb-hid/usb-hid.man.txt rename to board/miyoo/main/manuals/usb-hid.man.txt diff --git a/board/miyoo/rootfs/etc/main b/board/miyoo/rootfs/etc/main index 94285733..0b435ef0 100755 --- a/board/miyoo/rootfs/etc/main +++ b/board/miyoo/rootfs/etc/main @@ -161,32 +161,10 @@ else export CONSOLE_VARIANT="unknown" fi -# load usb modules - +# load usb modules & gadget modprobe sunxi 2>&1 | tee -a "${LOGS}" -modprobe usb_f_fs 2>&1 | tee -a "${LOGS}" - -# load usb gadget -echo "Loading USB gadget" >> "${LOGS}" -mount none /sys/kernel/config -t configfs 2>&1 | tee -a "${LOGS}" -mkdir -p /sys/kernel/config/usb_gadget/g2 >> "${LOGS}" 2>&1 -cd /sys/kernel/config/usb_gadget/g2 || echo "Failed to cd into /sys/kernel/config/usb_gadget/g2" >> "${LOGS}" 2>&1 -mkdir -p configs/c.1 >> "${LOGS}" 2>&1 -mkdir -p functions/ffs.mtp >> "${LOGS}" 2>&1 -mkdir -p strings/0x409 >> "${LOGS}" 2>&1 -mkdir -p configs/c.1/strings/0x409 >> "${LOGS}" 2>&1 - -echo 0x0100 > idProduct -echo 0x1D6B > idVendor - -echo "Miyoo Handheld" > strings/0x409/manufacturer -echo "Miyoo CFW 2.0" > strings/0x409/product - -echo "Conf 1" > configs/c.1/strings/0x409/configuration -echo 120 > configs/c.1/MaxPower -ln -s functions/ffs.mtp configs/c.1 2>&1 | tee -a "${LOGS}" -mkdir -p /dev/ffs-mtp >> "${LOGS}" 2>&1 -mount -t functionfs mtp /dev/ffs-mtp 2>&1 | tee -a "${LOGS}" +echo "Loading USB default MTP gadget" >> "${LOGS}" +usb-mode 2>&1 | tee -a "${LOGS}" if test "x${DEBUG_UMTPR}" == "xyes"; then umtprd-debug >> "${LOGS_TEMP}" 2>&1 & else @@ -195,6 +173,7 @@ fi sleep 1 ls /sys/class/udc/ > /sys/kernel/config/usb_gadget/g2/UDC +echo "Current UDC list=$(cat /sys/kernel/config/usb_gadget/g2/UDC)" >> "${LOGS}" echo "Boot!" >> "${LOGS}" echo "Handheld type is ${CONSOLE_VARIANT}" >> "${LOGS}" diff --git a/board/miyoo/main/apps/usb-hid/usb-hid.py b/board/miyoo/rootfs/usr/bin/usb-hid.py similarity index 100% rename from board/miyoo/main/apps/usb-hid/usb-hid.py rename to board/miyoo/rootfs/usr/bin/usb-hid.py diff --git a/board/miyoo/rootfs/usr/bin/usb-mode b/board/miyoo/rootfs/usr/bin/usb-mode new file mode 100755 index 00000000..d979eb2f --- /dev/null +++ b/board/miyoo/rootfs/usr/bin/usb-mode @@ -0,0 +1,260 @@ +#!/bin/busybox sh + +# ARGS +USB_MODE="${1}" +MTP_APP="${2}" + +# Global variables +SYSDIR=/sys/kernel/config/usb_gadget +DEVDIR=$SYSDIR/g2 +MAC_HOST="12:34:56:78:9a:bd" +MAC_DEV="12:34:56:78:9a:bc" + +st_error_func(){ + st -k -e "/bin/sh" "-c" "echo -e \"\e[31m${1}\e[0m\"; sleep 2" +} +st_info_func(){ + st -k -e "/bin/sh" "-c" "echo -e \"${1}\"; sleep 2" +} +st_exec_func(){ + st -k -e "/bin/sh" "-c" "${1}" +} + +rm_gadget_func(){ + echo "Removing old gadgets" + if pgrep "umtprd"; then + killall umtprd + elif pgrep "umtprd-debug"; then + killall umtprd-debug + fi + gadget-vid-pid-remove 0x1d6b:0x0104 # simply rm gadget-hid (g_hid/g_multi?) as it isn't part of FunctionFS + + if ! test -d $DEVDIR; then + echo "ERROR: couldn't find ${DEVDIR}" + return + fi + + echo '' > $DEVDIR/UDC + + echo "Removing strings from configurations" + for dir in $DEVDIR/configs/*/strings/*; do + [ -d $dir ] && rmdir $dir + done + + echo "Removing functions from configurations" + for func in $DEVDIR/configs/*.*/*.*; do + [ -e $func ] && rm $func + done + + echo "Removing configurations" + for conf in $DEVDIR/configs/*; do + [ -d $conf ] && rmdir $conf + done + + echo "Removing functions" + for func in $DEVDIR/functions/*.*; do + [ -d $func ] && rmdir $func + done + + echo "Removing strings" + for str in $DEVDIR/strings/*; do + [ -d $str ] && rmdir $str + done + + echo "Removing gadget" + rmdir $DEVDIR +} + +rm_host_modules_func(){ + echo "Removing USB HOST mode's all modules" + modprobe -r evdev + modprobe -r joydev + modprobe -r analog + modprobe -r xpad + modprobe -r atkbd + modprobe -r uinput + modprobe -r psmouse + modprobe -r synaptics_usb + modprobe -r mousedev + modprobe -r usbhid + modprobe -r hid-generic + modprobe -r hid +} + +usb_mode_func(){ + test -z "${1}" \ + || echo "Suggesting USB mode in ../musb-hdrc.1.auto/mode" + _usb_mode_path_="/sys/devices/platform/soc/1c13000.usb/musb-hdrc.1.auto/mode" + _usb_mode_="$(cat ${_usb_mode_path_})" + echo "Current USB mode=${_usb_mode_}" + if (grep -q host "${_usb_mode_path_}" && ! test -z "${1}"); then + rm_host_modules_func + fi + test -z "${1}" \ + || echo "${1}" > ${_usb_mode_path_} # DOES THIS EVEN WORK? + sleep 1 + # _usb_mode_="$(cat ${_usb_mode_path_})" + # echo "NEW usb_mode=${_usb_mode_}" +} + +usb_configs_func(){ + echo "Configuring FunctionFS gadget" + mount none /sys/kernel/config -t configfs + mkdir -p ${DEVDIR} + if ! cd ${DEVDIR}; then + echo "ERROR: couldn't enter ${DEVDIR}" + exit 1 + fi + mkdir -p configs/c.1 + if test "${USB_MODE}" == "mtp" || test -z $USB_MODE; then + mkdir -p functions/ffs.mtp # mtp + elif test "${USB_MODE}" == "serial"; then + mkdir -p functions/acm.usb0 # serial + # else net + fi + mkdir -p strings/0x409 + mkdir -p configs/c.1/strings/0x409 + if test "${USB_MODE}" == "net"; then + mkdir -p functions/rndis.usb0 + fi + if test "${USB_MODE}" == "mtp" || test -z $USB_MODE; then + echo 0x0100 > idProduct # mtp gadget (ptp's extension) + else + echo 0x0104 > idProduct # serial,net (g_multi?), CDC ACM + fi + echo 0x1D6B > idVendor # Linux Foundation + if test "${USB_MODE}" == "net"; then + echo "0x0200" > bcdUSB + echo "0x02" > bDeviceClass + echo "0x00" > bDeviceSubClass + echo "0x3066" > bcdDevice + echo "1" > os_desc/use + echo "0xcd" > os_desc/b_vendor_code + echo "MSFT100" > os_desc/qw_sign + echo "RNDIS" > functions/rndis.usb0/os_desc/interface.rndis/compatible_id + echo "5162001" > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id + echo $MAC_HOST > functions/rndis.usb0/host_addr + echo $MAC_DEV > functions/rndis.usb0/dev_addr + fi + echo "Miyoo Handheld" > strings/0x409/manufacturer + echo "MiyooCFW 2.0" > strings/0x409/product + if test "${USB_MODE}" == "serial"; then + echo "deadbeef12345678" > strings/0x409/serialnumber + fi + + echo "Conf 1" > configs/c.1/strings/0x409/configuration + echo 120 > configs/c.1/MaxPower + if test "${USB_MODE}" == "mtp" || test -z $USB_MODE; then + # mtp + ln -s functions/ffs.mtp configs/c.1 + mkdir -p /dev/ffs-mtp + mount -t functionfs mtp /dev/ffs-mtp + elif test "${USB_MODE}" == "serial"; then + # serial + ln -s functions/acm.usb0 configs/c.1 + elif test "${USB_MODE}" == "net"; then + # net + ln -s functions/rndis.usb0 configs/c.1 + ln -s configs/c.1 os_desc + sleep 1 + + echo "0x00" > bDeviceClass + else + echo "ERROR: Unknown USB_MODE=${USB_MODE}" + fi +} + +### MTP/MTD (default)### +if test "${USB_MODE}" == "mtp" || test -z $USB_MODE; then + echo "Starting USB-MTP mode" + test -z $USB_MODE \ + || usb_mode_func peripheral + modprobe usb_f_fs + if ! test -z $USB_MODE; then + # omit removing gadgets in default non-arg run + rm_gadget_func + fi + + usb_configs_func + if test "${MTP_APP}" == "umtprd"; then + echo "Launching uMTP-Responder app" + if (grep -q DEBUG_UMTPR\=\1 "${HOME}/options.cfg"); then + umtprd-debug & + else + umtprd & + fi + fi + sleep 1 + ls /sys/class/udc/ > ${DEVDIR}/UDC + + usb_mode_func + sleep 1 +fi + +### HID ### +if test "${USB_MODE}" == "hid"; then + echo "Starting USB-HID mode" + usb_mode_func peripheral + rm_gadget_func + modprobe usb_f_hid + modprobe evdev + modprobe uinput + mount none /sys/kernel/config -t configfs + gadget-hid + usb_mode_func + st_exec_func "\ + echo -e \"\e[32m\n\n\n\n\n\n Starting USB-HID mode\e[0m\n\n\n\"; \ + sleep 1; \ + python /usr/bin/usb-hid.py" + modprobe -r usb_f_hid + modprobe -r evdev + modprobe -r uinput +fi + +### Serial Console ### +if test "${USB_MODE}" == "serial"; then + echo "Starting USB-Serial mode" + usb_mode_func peripheral + rm_gadget_func + usb_configs_func + sleep 1 + ls /sys/class/udc/ > ${DEVDIR}/UDC + usb_mode_func +fi + +### Networking ### +if test "${USB_MODE}" == "net"; then + st_info_func "Starting USB-Network mode" + rm_gadget_func + modprobe usb_f_rndis + sleep 1 + usb_configs_func + sleep 1 + ls /sys/class/udc/ > ${DEVDIR}/UDC + ifconfig usb0 up 192.168.137.1 + sleep 10 + /etc/init.d/S80dhcp-server restart +fi + +### Host ## +if test "${USB_MODE}" == "host"; then + echo "Starting USB in HOST state mode" + usb_mode_func host + sleep 2 + + modprobe evdev + modprobe joydev + modprobe analog + modprobe xpad + modprobe atkbd + modprobe uinput + modprobe psmouse + modprobe synaptics_usb + modprobe mousedev + modprobe usbhid + modprobe hid-generic + modprobe hid + usb_mode_func +fi + +echo "Exiting USB mode configuration..."