summaryrefslogtreecommitdiffstats
path: root/meta-boot2qt/recipes-qt/boot2qt-addons/qdb/qdbd-init.sh
diff options
context:
space:
mode:
Diffstat (limited to 'meta-boot2qt/recipes-qt/boot2qt-addons/qdb/qdbd-init.sh')
-rwxr-xr-xmeta-boot2qt/recipes-qt/boot2qt-addons/qdb/qdbd-init.sh120
1 files changed, 120 insertions, 0 deletions
diff --git a/meta-boot2qt/recipes-qt/boot2qt-addons/qdb/qdbd-init.sh b/meta-boot2qt/recipes-qt/boot2qt-addons/qdb/qdbd-init.sh
new file mode 100755
index 0000000..15981b0
--- /dev/null
+++ b/meta-boot2qt/recipes-qt/boot2qt-addons/qdb/qdbd-init.sh
@@ -0,0 +1,120 @@
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
49initialize_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
58disable_gadget() {
59 echo "" > $GADGET_CONFIG/UDC
60}
61
62case "$1" in
63start)
64 b2qt-gadget-network.sh --reset
65 modprobe libcomposite
66 sleep 1
67 # Gadget configuration
68 mkdir -p $GADGET_CONFIG
69 echo $VENDOR > $GADGET_CONFIG/idVendor
70 echo $PRODUCT > $GADGET_CONFIG/idProduct
71 mkdir -p $GADGET_CONFIG/strings/0x409
72 echo $MANUFACTURER > $GADGET_CONFIG/strings/0x409/manufacturer
73 echo $PRODUCT_STRING > $GADGET_CONFIG/strings/0x409/product
74 echo ${SERIAL:0:32} > $GADGET_CONFIG/strings/0x409/serialnumber
75 mkdir -p $GADGET_CONFIG/configs/c.1/strings/0x409
76 echo "USB Ethernet + QDB" > $GADGET_CONFIG/configs/c.1/strings/0x409/configuration
77 mkdir -p $GADGET_CONFIG/functions/rndis.usb0
78 mkdir -p $GADGET_CONFIG/functions/ffs.qdb
79 ln -sf $GADGET_CONFIG/functions/rndis.usb0 $GADGET_CONFIG/configs/c.1
80 ln -sf $GADGET_CONFIG/functions/ffs.qdb $GADGET_CONFIG/configs/c.1
81 # Function fs mountpoints
82 mkdir -p /dev/usb-ffs
83 chmod 770 /dev/usb-ffs
84 mkdir -p /dev/usb-ffs/qdb
85 chmod 770 /dev/usb-ffs/qdb
86 mount -t functionfs qdb /dev/usb-ffs/qdb -o uid=0,gid=0
87 shift
88 start-stop-daemon --start --quiet --exec $DAEMON -- $@ &
89 sleep 1
90 initialize_gadget
91 ;;
92stop)
93 disable_gadget
94 start-stop-daemon --stop --quiet --exec $DAEMON
95 sleep 1
96 umount /dev/usb-ffs/qdb
97 rm $GADGET_CONFIG/configs/c.1/rndis.usb0
98 rm $GADGET_CONFIG/configs/c.1/ffs.qdb
99 rmdir $GADGET_CONFIG/configs/c.1/strings/0x409
100 rmdir $GADGET_CONFIG/configs/c.1
101 rmdir $GADGET_CONFIG/functions/rndis.usb0
102 rmdir $GADGET_CONFIG/functions/ffs.qdb
103 rmdir $GADGET_CONFIG/strings/0x409
104 rmdir $GADGET_CONFIG
105 ;;
106restart)
107 disable_gadget
108 start-stop-daemon --stop --quiet --exec $DAEMON
109 b2qt-gadget-network.sh --reset
110 sleep 1
111 shift
112 start-stop-daemon --start --quiet --exec $DAEMON -- $@ &
113 sleep 1
114 initialize_gadget
115 ;;
116*)
117 echo "Usage: $0 {start|stop|restart}"
118 exit 1
119esac
120exit 0