-
Notifications
You must be signed in to change notification settings - Fork 23
/
linuxrc
executable file
·175 lines (131 loc) · 2.93 KB
/
linuxrc
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
mount -t sysfs none /sys
mount -t proc none /proc
mount -t devtmpfs none /dev
mount -t configfs none /sys/kernel/config
cmdline=`cat /proc/cmdline`
# disable turn off display
echo -e "\033[9;0]" > /dev/tty0
last=0;
UDC_DIR=/sys/class/udc
function launch_dhcpd() {
touch -f /var/lib/misc/udhcpd.leases
echo start 168.1.1.50 > /conf
echo end 168.1.1.253 >> /conf
echo interface usb$1 >>/conf
ifconfig usb$1 168.1.1.1
udhcpd /conf
}
function contains() {
for i in "${files[@]}"
do
if [ "$i" == "$1" ]; then
return 1;
fi
done
return 0
}
function launch_uuc() {
echo $1 $2
mkdir /sys/kernel/config/usb_gadget/$1
cd /sys/kernel/config/usb_gadget/$1
echo 0x066F > idVendor
if [[ ${cmdline} == *nfsroot* ]]; then
echo 0x9CFF > idProduct
else
echo 0x9BFF > idProduct
fi
mkdir strings/0x409
if [ -e /sys/devices/soc0/soc_uid ]; then
cat /sys/devices/soc0/soc_uid > strings/0x409/serialnumber
else
echo 0000000000000000 > strings/0x409/serialnumber
fi
echo "FSL i.MX Board" > strings/0x409/product
mkdir configs/c.1
echo 5 > configs/c.1/MaxPower
echo ffs.utp$2
echo 1 > os_desc/use
echo "MSFT100" > os_desc/qw_sign
echo 0x40 > os_desc/b_vendor_code
if [[ ${cmdline} == *nfsroot* ]]; then
mkdir functions/ncm.1
ln -s functions/ncm.1 configs/c.1/
# mkdir functions/acm.1
# ln -s functions/acm.1 configs/c.1/
echo $1 > UDC
echo "Start config network"
ifconfig usb$2 up
while [ ! -e /find_one ]
do
if [[ `ifconfig usb$2` == *inet6* ]]; then
break;
fi
sleep 1
done
if [ -e /find_one ]; then
exit 0
fi
touch /find_one
launch_dhcpd $2
remote=""
while [[ "$remote" == "" ]];
do
sleep 2
echo retry get remote ipaddress
ping6 -c2 -I usb$2 ff02::1
remote=`ip -6 neighbor show dev usb$2`
remote=(${remote})
remote=${remote[0]}
done
nfs=${cmdline#*nfsroot=}
nfs=($nfs)
nfs=${nfs[0]}
nfs=${nfs##*:}
echo ${remote} ${nfs}
mount -t nfs [${remote}%usb$2]:${nfsroot}/${nfs} /mnt/
cd /
touch /exit_scan
else
mkdir functions/ffs.utp$2
mkdir /dev/usb-utp$2
mount -t functionfs utp$2 /dev/usb-utp$2
ln -s functions/ffs.utp$2 configs/c.1/
ln -s configs/c.1 os_desc
ufb /dev/usb-utp$2/ep0 &
echo run utp at /dev/usb-utp$2/ep0;
while [ ! -e /dev/usb-utp$2/ep1 ]
do
echo "."
sleep 1;
done
echo $1 > UDC
fi
return 0;
}
while true; do
if test "$(ls -A "$UDC_DIR")"; then
cd $UDC_DIR
for entry in *
do
if contains $entry; then
files[$last]=$entry;
id=$last;
last=`expr $last + 1`;
echo "Found New UDC: $entry";
launch_uuc $entry $id &
fi
done
sleep 1
else
echo "No udc Available!"
sleep 5
fi
if [ -e /exit_scan ]; then
echo find one active ncm
exec switch_root /mnt /sbin/init
exit 1;
fi
done
echo bye