forked from Anime4000/RTL960x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqemu-test.sh
148 lines (119 loc) · 3.72 KB
/
qemu-test.sh
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
#!/bin/bash
# Anime4000 firmware test
# Purpose of this script to let you test before flash into RTL960x (ONU Stick)
# Try merge or play with V2801F and TWCGPON657
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$DIR"
echo "Anime4000 firmware test for RTL960x"
echo "-----------------------------------"
echo ""
if [ "$EUID" -ne 0 ]; then
echo "Please run as root!"
exit 99
fi
if [ $# -eq 0 ]; then
echo "Usage"
echo " $0 <firmware> <sw_ver>"
echo ""
echo "Options:"
echo " firmware rtl960x firmware file in .tar format"
echo " sw_ver optional, custom software version, space will truncated"
exit 99
fi
echo "Checking Packging: $1"
if [[ ! -f $1 && -z $1 ]]; then
echo "$1 is not found! example: $0 C00R657V00B15_20201222.tar"
exit 99
fi
CHDIR="squashfs-root"
FILEPATH=$(realpath $1)
FILENAME=$(basename -- $1)
echo "Checking Install: QEMU User Static"
(qemu-mips-static --version) < /dev/null > /dev/null 2>&1 || {
echo "QEMU MIPS not installed on /usr/bin"
echo ""
echo "To install, run:"
echo "apt install qemu-user-static"
exit 1
}
echo "Checking Install: chroot"
(chroot --version) < /dev/null > /dev/null 2>&1 || {
echo "chroot not installed on /usr/sbin"
echo ""
echo "To install, run:"
echo "apt install schroot"
exit 2
}
echo "Creating folder: ${FILENAME%.*}"
mkdir ${FILENAME%.*}
echo "Entering folder: ${FILENAME%.*}"
cd ${FILENAME%.*}
echo "Extracting firmware: $FILENAME"
tar -xvf $FILEPATH
echo "Expanding squashfs-root: rootfs"
mv rootfs rootfs.original
unsquashfs rootfs.original
echo "Checking Folder: squashfs-root"
if [ ! -d "$CHDIR" ]; then
echo "$CHDIR not found"
echo ""
echo "To have $CHDIR (extracted rootfs), run:"
echo "unsquashfs rootfs"
exit 3
fi
echo "Checking: chroot /usr/bin"
if [ ! -d "$CHDIR/usr/bin" ]; then
echo "Creating: chroot /usr/bin"
mkdir "$CHDIR/usr/bin"
fi
echo "Checking: chroot QEMU MIPS"
if [ ! -f "$CHDIR/usr/bin/qemu-mips-static" ]; then
echo "Installing: chroot QEMU MIPS"
cp $(which qemu-mips-static) "$CHDIR/usr/bin/"
fi
echo "RTL9601C1 Emulator is Running!"
chroot "$CHDIR" qemu-mips-static "/bin/sh"
echo "User End QEMU..."
echo "chmod +x /bin folder, prevent stick become brick!"
chmod +x "$CHDIR/bin" -R
chmod +x "$CHDIR/etc/*.sh"
chmod +x "$CHDIR/etc/init.d" -R
chmod +x "$CHDIR/etc/scripts" -R
chown 0:0 "$CHDIR/" -R
echo "Change Version, Hardcoded!"
if grep -q "-" fwu_ver; then
STICKVER=`awk -F" " '{print $1}' $CHDIR/etc/version | cut -d - -f 1`
echo "$STICKVER-$(date +'%y%m%d') -- $(date -u +'%a %b %d %H:%I:%M %Z %Y')" > "$CHDIR/etc/version"
echo "$STICKVER-$(date +'%y%m%d')" > fwu_ver
else
STICKVER=`awk -F" " '{print $1}' $CHDIR/etc/version`
echo "$STICKVER -- $(date -u +'%a %b %d %H:%I:%M %Z %Y')" > "$CHDIR/etc/version"
echo "$STICKVER" > fwu_ver
fi
if [ -z "$2" ]; then
echo "No custom version string is set..."
else
echo "Using custom version string..."
echo "$2 -- $(date -u +'%a %b %d %H:%I:%M %Z %Y')" > "$CHDIR/etc/version"
echo "$2" > fwu_ver
fi
echo "Change Default LAN_SDS_MODE"
sed -i 's/<Value Name="LAN_SDS_MODE" Value="5"\/>/<Value Name="LAN_SDS_MODE" Value="1"\/>/g' "$CHDIR/etc/config_default_hs.xml"
echo "Unmounting..."
rm -rf "$CHDIR/usr/bin"
echo "Repacking squashfs-root: rootfs"
mksquashfs squashfs-root rootfs -b 131072 -comp lzma
echo "Regenerate firmware: rtl9601c1_modified.tar"
md5sum fwu.sh > md5.txt
md5sum fwu_ver >> md5.txt
md5sum rootfs >> md5.txt
md5sum uImage >> md5.txt
echo "Repacking firmware: rtl960x_modified.tar"
tar -cvf ../rtl960x_modified.tar fwu.sh fwu_ver md5.txt rootfs uImage
echo ""
echo "Firmware Repacking Complete!"
echo "Location: $(realpath ../rtl960x_modified.tar)"
echo ""
echo "Anime4000 firmware test script, https://github.com/Anime4000/RTL9601C1"
echo ""
exit 0