RTL960x/Tools/emulator/qemu-test.sh

149 lines
3.7 KiB
Bash
Raw Normal View History

2021-02-17 09:04:04 +00:00
#!/bin/bash
# Anime4000 firmware test
# Purpose of this script to let you test before flash into RTL9601C1 (ONU Stick)
# Try merge or play with V2801F and TWCGPON657
2022-03-01 02:37:17 +00:00
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$DIR"
2021-02-17 09:04:04 +00:00
echo "Anime4000 firmware test for RTL9601C1"
echo "-------------------------------------"
echo ""
2022-05-07 21:44:23 +00:00
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 firmware file in .tar format"
echo " sw_ver optional, custom software version, space will truncated"
2021-02-17 09:04:04 +00:00
exit 99
fi
2022-03-01 02:37:17 +00:00
echo "Checking Packging: $1"
if [[ ! -f $1 && -z $1 ]]; then
2022-05-07 21:44:23 +00:00
echo "$1 is not found! example: $0 C00R657V00B15_20201222.tar"
exit 99
2022-03-01 02:37:17 +00:00
fi
CHDIR="squashfs-root"
FILEPATH=$(realpath $1)
FILENAME=$(basename -- $1)
2021-02-17 09:04:04 +00:00
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
}
2022-03-01 02:37:17 +00:00
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
2021-02-17 09:04:04 +00:00
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
2022-03-01 02:37:17 +00:00
echo "RTL9601C1 Emulator is Running!"
2021-02-17 09:04:04 +00:00
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
2022-03-24 18:26:11 +00:00
chmod +x "$CHDIR/etc/*.sh"
chmod +x "$CHDIR/etc/init.d" -R
chmod +x "$CHDIR/etc/scripts" -R
2022-03-28 15:00:02 +00:00
chown 0:0 "$CHDIR/" -R
2021-02-17 09:04:04 +00:00
2022-05-07 21:44:23 +00:00
echo "Change Version, Hardcoded!"
2022-04-02 00:28:57 +00:00
if grep -q "-" fwu_ver; then
2022-03-28 15:35:24 +00:00
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
2022-05-07 21:44:23 +00:00
if [ -z "$2" ]; then
echo "No custom version string is set..."
else
echo "Using custom version string..."
echo "$2" > "$CHDIR/etc/version"
echo "$2" > fwu_ver
fi
2022-03-28 16:06:23 +00:00
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"
2021-02-17 09:04:04 +00:00
echo "Unmounting..."
rm -rf "$CHDIR/usr/bin"
2022-03-01 02:37:17 +00:00
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
2022-05-07 20:39:58 +00:00
echo "Repacking firmware: rtl960x_modified.tar"
tar -cvf ../rtl960x_modified.tar fwu.sh fwu_ver md5.txt rootfs uImage
2022-03-01 02:37:17 +00:00
echo ""
echo "Firmware Repacking Complete!"
2022-05-07 20:39:25 +00:00
echo "Location: $(realpath ../rtl960x_modified.tar)"
2022-03-01 02:37:17 +00:00
echo ""
echo "Anime4000 firmware test script, https://github.com/Anime4000/RTL9601C1"
echo ""
exit 0