summaryrefslogtreecommitdiffstats
path: root/recipes-qt/b2qt-addons/qdbd/qdbd-init.sh
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-qt/b2qt-addons/qdbd/qdbd-init.sh')
-rwxr-xr-xrecipes-qt/b2qt-addons/qdbd/qdbd-init.sh117
1 files changed, 117 insertions, 0 deletions
diff --git a/recipes-qt/b2qt-addons/qdbd/qdbd-init.sh b/recipes-qt/b2qt-addons/qdbd/qdbd-init.sh
new file mode 100755
index 0000000..446ea3f
--- /dev/null
+++ b/recipes-qt/b2qt-addons/qdbd/qdbd-init.sh
@@ -0,0 +1,117 @@
1#! /bin/sh
2###############################################################################
3## Copyright (C) 2016 The Qt Company Ltd.
4## Contact: http://www.qt.io/licensing/
5##
6## This file is part of the Boot to Qt meta layer.
7##
8## $QT_BEGIN_LICENSE:BSD$
9## You may use this file under the terms of the BSD license as follows:
10##
11## "Redistribution and use in source and binary forms, with or without
12## modification, are permitted provided that the following conditions are
13## met:
14## * Redistributions of source code must retain the above copyright
15## notice, this list of conditions and the following disclaimer.
16## * Redistributions in binary form must reproduce the above copyright
17## notice, this list of conditions and the following disclaimer in
18## the documentation and/or other materials provided with the
19## distribution.
20## * Neither the name of The Qt Company Ltd nor the names of its
21## contributors may be used to endorse or promote products derived
22## from this software without specific prior written permission.
23##
24##
25## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36##
37## $QT_END_LICENSE$
38###############################################################################
39MANUFACTURER="The Qt Company"
40PRODUCT_STRING="Boot2Qt Ethernet/RNDIS connection"
41
42DAEMON=/usr/bin/qdbd
43CONFIGFS_PATH=/sys/kernel/config
44
45GADGET_CONFIG=$CONFIGFS_PATH/usb_gadget/g1
46
47. /etc/default/qdbd
48
49function initialize_gadget() {
50 # Initialize gadget with first UDC driver
51 for driverpath in /sys/class/udc/*; do
52 drivername=`basename $driverpath`
53 echo "$drivername" > $GADGET_CONFIG/UDC
54 break
55 done
56}
57
58function disable_gadget() {
59 echo "" > $GADGET_CONFIG/UDC
60}
61
62case "$1" in
63start)
64 modprobe libcomposite
65 # Gadget configuration
66 mkdir -p $GADGET_CONFIG
67 echo $VENDOR > $GADGET_CONFIG/idVendor
68 echo $PRODUCT > $GADGET_CONFIG/idProduct
69 mkdir -p $GADGET_CONFIG/strings/0x409
70 echo $MANUFACTURER > $GADGET_CONFIG/strings/0x409/manufacturer
71 echo $PRODUCT_STRING > $GADGET_CONFIG/strings/0x409/product
72 echo ${SERIAL:0:32} > $GADGET_CONFIG/strings/0x409/serialnumber
73 mkdir -p $GADGET_CONFIG/configs/c.1/strings/0x409
74 echo "USB Ethernet + QDB" > $GADGET_CONFIG/configs/c.1/strings/0x409/configuration
75 mkdir -p $GADGET_CONFIG/functions/rndis.usb0
76 mkdir -p $GADGET_CONFIG/functions/ffs.qdb
77 ln -sf $GADGET_CONFIG/functions/rndis.usb0 $GADGET_CONFIG/configs/c.1
78 ln -sf $GADGET_CONFIG/functions/ffs.qdb $GADGET_CONFIG/configs/c.1
79 # Function fs mountpoints
80 mkdir -p /dev/usb-ffs
81 chmod 770 /dev/usb-ffs
82 mkdir -p /dev/usb-ffs/qdb
83 chmod 770 /dev/usb-ffs/qdb
84 mount -t functionfs qdb /dev/usb-ffs/qdb -o uid=0,gid=0
85 shift
86 start-stop-daemon --start --quiet --exec $DAEMON -- $@ &
87 sleep 1
88 initialize_gadget
89 ;;
90stop)
91 disable_gadget
92 start-stop-daemon --stop --quiet --exec $DAEMON
93 sleep 1
94 umount /dev/usb-ffs/qdb
95 rm $GADGET_CONFIG/configs/c.1/rndis.usb0
96 rm $GADGET_CONFIG/configs/c.1/ffs.qdb
97 rmdir $GADGET_CONFIG/configs/c.1/strings/0x409
98 rmdir $GADGET_CONFIG/configs/c.1
99 rmdir $GADGET_CONFIG/functions/rndis.usb0
100 rmdir $GADGET_CONFIG/functions/ffs.qdb
101 rmdir $GADGET_CONFIG/strings/0x409
102 rmdir $GADGET_CONFIG
103 ;;
104restart)
105 disable_gadget
106 start-stop-daemon --stop --quiet --exec $DAEMON
107 sleep 1
108 shift
109 start-stop-daemon --start --quiet --exec $DAEMON -- $@ &
110 sleep 1
111 initialize_gadget
112 ;;
113*)
114 echo "Usage: $0 {start|stop|restart}"
115 exit 1
116esac
117exit 0