forked from robang74/redfishos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.usb
98 lines (85 loc) · 3.44 KB
/
init.usb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
################################################################################
#
# Generic ramdisk init process for booting a device. Based Marko Saukko's
# initrd for Galaxy Note GT-i9250. Reworked by Roberto A. Foglietta.
#
# Copyright (C) 2014 Jolla Ltd.
# Copyright (C) 2012 Marko Saukko
# Copyright (C) 2023 Roberto A. Foglietta
# Contact: [email protected]
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
################################################################################
# release: 0.0.3
GADGET_DIR="/config/usb_gadget/g1"
ANDROID_USB="/sys/class/android_usb/android0"
USB_FUNCTIONS="rndis"
################################################################################
write()
{
echo -n "$2" > "$1"
}
# This sets up the USB with whatever USB_FUNCTIONS are set to via configfs
usb_setup_configfs() {
G_USB_ISERIAL=$GADGET_DIR/strings/0x409/serialnumber
mkdir $GADGET_DIR
write $GADGET_DIR/idVendor "0x2931"
write $GADGET_DIR/idProduct "0x0A06"
mkdir $GADGET_DIR/strings/0x409
write $GADGET_DIR/strings/0x409/serialnumber "$1"
write $GADGET_DIR/strings/0x409/manufacturer "robang74"
write $GADGET_DIR/strings/0x409/product "recovery"
if echo $USB_FUNCTIONS | grep -q "rndis"; then
mkdir $GADGET_DIR/functions/rndis.rndis0
mkdir $GADGET_DIR/functions/rndis_bam.rndis
fi
mkdir $GADGET_DIR/configs/c.1
mkdir $GADGET_DIR/configs/c.1/strings/0x409
write $GADGET_DIR/configs/c.1/strings/0x409/configuration "$USB_FUNCTIONS"
if echo $USB_FUNCTIONS | grep -q "rndis"; then
ln -s $GADGET_DIR/functions/rndis.rndis0 $GADGET_DIR/configs/c.1
ln -s $GADGET_DIR/functions/rndis_bam.rndis $GADGET_DIR/configs/c.1
fi
echo "$(ls -1 /sys/class/udc)" > $GADGET_DIR/UDC
}
# This sets up the USB with whatever USB_FUNCTIONS are set to via android_usb
usb_setup_android_usb() {
G_USB_ISERIAL=$ANDROID_USB/iSerial
write $ANDROID_USB/enable 0
write $ANDROID_USB/functions ""
write $ANDROID_USB/enable 1
usleep 500000 # 0.5 delay to attempt to remove rndis function
write $ANDROID_USB/enable 0
write $ANDROID_USB/idVendor 2931
write $ANDROID_USB/idProduct 0A06
write $ANDROID_USB/iManufacturer "robang74"
write $ANDROID_USB/iProduct "recovery"
write $ANDROID_USB/iSerial "$1"
write $ANDROID_USB/functions $USB_FUNCTIONS
write $ANDROID_USB/enable 1
}
# This determines which USB setup method is going to be used
usb_setup() {
if [ -f $ANDROID_USB/enable ]; then
usb_setup_android_usb $1
else
usb_setup_configfs $1
fi
}
################################################################################
usb_setup "redfishos"