Post by badboy1985ro on Jan 14, 2009 22:11:23 GMT 7
This is the update code from the thecus firmware.
#!/bin/sh
/img/bin/service stop
cd /raid/tmp/upgrade
MSG="/raid/tmp/upgrade/message"
DBG="/raid/tmp/upgrade/debug"
DEBUG=1
/usr/bin/md5sum -c uramdisk.md5
OK1=$?
/usr/bin/md5sum -c uImage.md5
OK2=$?
/usr/bin/md5sum -c hdroot.new.gz.md5
OK3=$?
if [ $OK1 -eq 0 ] && [ $OK2 -eq 0 ] && [ $OK3 -eq 0 ]; then
echo "Busy 2" > /proc/thecus_io
ubootv1=`/opt/bin/fw_printenv version|cut -d"=" -f2`
ubootv2=`cat ./u-boot.version`
if [ ${ubootv2} -gt ${ubootv1} ]; then
echo "Upgrading u-boot ... please wait ..." > "${MSG}"
/usr/bin/md5sum -c u-boot.bin.md5
OK1=$?
if [ $OK1 -eq 0 ]; then
/sbin/flashcp -v u-boot.bin /dev/mtd0
OK=$?;
/bin/sync
if [ $OK -eq 1 ]; then
echo "Upgrade u-boot fail!" > "${MSG}"
echo "Upgrade u-boot fail!" > "${DBG}"
exit 1
fi
/opt/bin/fw_setenv version ${ubootv2}
else
echo "u-boot MD5 checksum error" >> "${DBG}"
exit 1
fi
fi
echo "Upgrading ramdisk ... please wait ..." > "${MSG}"
#upgrade ramdisk mtd
/sbin/flashcp -v uramdisk /dev/mtd4
OK=$?
/bin/sync
if [ $OK -eq 1 ]; then
echo "Upgrade ramdisk fail!" > "${MSG}"
echo "Upgrade ramdisk fail!" > "${DBG}"
exit 1
fi
echo "Upgrading kernel ... please wait ..." > "${MSG}"
#upgrade kernel mtd
/sbin/flashcp -v uImage /dev/mtd3
OK=$?
/bin/sync
if [ $OK -eq 1 ]; then
echo "Upgrade kernel fail!" > "${MSG}"
echo "Upgrade kernel fail!" > "${DBG}"
exit 1
fi
echo "Upgrading Disk firmware ... please wait ..." > "${MSG}"
#upgrade firmware in disk
mv hdroot.new.gz hdroot.new.md5 /initrd/boot/
cd /initrd/boot
gunzip hdroot.new.gz
OK=$?
/bin/sync
if [ $OK -eq 1 ]; then
echo "Upgrade disk's firmware fail!" > "${MSG}"
echo "Upgrade disk's firmware fail!" > "${DBG}"
exit 1
fi
/bin/sync
# I does not do this, because I trust gunzip.
# /usr/bin/md5sum -c hdroot.new.md5
# OK3=$?
# if [ $OK3 -ne 0 ]; then
# echo "Disk's firmware MD5 checksum fail!" > "${MSG}"
# echo "Disk's firmware MD5 checksum fail!" > "${DBG}"
# exit 1
# fi
touch /initrd/boot/hdroot.new.md5.ok
cd -
/bin/sync
echo "Upgrading configuration ... please wait ... " > "${MSG}"
#check conf.db
/opt/bin/sqlite "/etc/cfg/conf.db" "select k from conf" | sort > ./conf.db.org.list
/opt/bin/sqlite "./conf.db" "select k from conf" | sort > ./conf.db.up.list
./diff ./conf.db.org.list ./conf.db.up.list >> "${DBG}"
./diff --brief ./conf.db.org.list ./conf.db.up.list
if [ $? -ne 0 ]; then
awk -f ./conf.db.awk >> "${DBG}"
fi
#check rc file
filename="rc"
./diff /etc/cfg/$filename ./$filename
if [ $? -ne 0 ]; then
echo "Upgrade $filename" >> "${DBG}"
cp ./$filename /etc/cfg/$filename
fi
filename="rc.factory"
./diff /etc/cfg/$filename ./$filename
if [ $? -ne 0 ]; then
echo "Upgrade $filename" >> "${DBG}"
cp ./$filename /etc/cfg/$filename
fi
#check manifest.txt file
filename="manifest.txt"
./diff /etc/$filename ./$filename
if [ $? -ne 0 ]; then
echo "Upgrade $filename" >> "${DBG}"
cp ./$filename /etc/$filename
fi
#check crond.conf
filename="crond.conf"
./diff /etc/cfg/$filename ./$filename
if [ $? -ne 0 ]; then
echo "upgrade $filename" >> "${DBG}"
cat /app/cfg/$filename | grep 'DL_Center.sh' >> ./$filename
cp ./$filename /etc/cfg/$filename
fi
#check php.ini
filename="php.ini"
./diff /etc/httpd/conf/$filename ./$filename
if [ $? -ne 0 ]; then
echo "upgrade $filename" >> "${DBG}"
cp ./$filename /etc/httpd/conf/$filename
fi
#check ca-bundle.crt
filename="ca-bundle.crt"
./diff /etc/httpd/conf/ssl.crt/$filename ./$filename
if [ $? -ne 0 ]; then
echo "upgrade $filename" >> "${DBG}"
cp ./$filename /etc/httpd/conf/ssl.crt/$filename
fi
filename="server.crt"
./diff /etc/httpd/conf/ssl.crt/$filename ./$filename
if [ $? -ne 0 ]; then
echo "upgrade $filename" >> "${DBG}"
cp ./$filename /etc/httpd/conf/ssl.crt/$filename
fi
#check server.key
filename="server.key"
./diff /etc/httpd/conf/ssl.key/$filename ./$filename
if [ $? -ne 0 ]; then
echo "upgrade $filename" >> ${DBG}
cp ./$filename /etc/httpd/conf/ssl.key/$filename
fi
#check scsi.agent
filename="scsi.agent"
./diff /etc/hotplug/$filename ./$filename
if [ $? -ne 0 ]; then
echo "upgrade $filename" >> "${DBG}"
cp ./$filename /etc/hotplug/$filename
fi
rm -f /etc/hotplug/usb.agent
if [ $DEBUG -eq 1 ]; then
cp ${DBG} /tmp/upgrade.debug
fi
sync
sync
sync
PID=`ps|grep '/bin/sh /img/bin/updfw.sh'|grep -v grep|awk '{print $1}'`
echo "success" > "${MSG}"
kill $PID
echo "success" >> "${DBG}"
echo "Buzzer 1" > /proc/thecus_io
sleep 3
echo "Buzzer 0" > /proc/thecus_io
exit 0
else
echo "MD5 checksum fail" > "${MSG}"
echo "MD5 checksum fail" >> "${DBG}"
if [ $DEBUG -eq 1 ]; then
cp "${DBG}" /tmp/upgrade.debug
fi
exit 1
fi
they used md5sum to check the images and the used flash cp to cpopy them onto the flash after decrypting the bin file.
So i was write. It can easily revert the original ramdrive.
The problem is timim. Can u please tell me Why did u used dd with bs=1k when write the ubuntu kernel on thecus? Should i use the bs=1k parametre when i write back the ramdisk? I suppose flashcp is no longer supported in foonas
#!/bin/sh
/img/bin/service stop
cd /raid/tmp/upgrade
MSG="/raid/tmp/upgrade/message"
DBG="/raid/tmp/upgrade/debug"
DEBUG=1
/usr/bin/md5sum -c uramdisk.md5
OK1=$?
/usr/bin/md5sum -c uImage.md5
OK2=$?
/usr/bin/md5sum -c hdroot.new.gz.md5
OK3=$?
if [ $OK1 -eq 0 ] && [ $OK2 -eq 0 ] && [ $OK3 -eq 0 ]; then
echo "Busy 2" > /proc/thecus_io
ubootv1=`/opt/bin/fw_printenv version|cut -d"=" -f2`
ubootv2=`cat ./u-boot.version`
if [ ${ubootv2} -gt ${ubootv1} ]; then
echo "Upgrading u-boot ... please wait ..." > "${MSG}"
/usr/bin/md5sum -c u-boot.bin.md5
OK1=$?
if [ $OK1 -eq 0 ]; then
/sbin/flashcp -v u-boot.bin /dev/mtd0
OK=$?;
/bin/sync
if [ $OK -eq 1 ]; then
echo "Upgrade u-boot fail!" > "${MSG}"
echo "Upgrade u-boot fail!" > "${DBG}"
exit 1
fi
/opt/bin/fw_setenv version ${ubootv2}
else
echo "u-boot MD5 checksum error" >> "${DBG}"
exit 1
fi
fi
echo "Upgrading ramdisk ... please wait ..." > "${MSG}"
#upgrade ramdisk mtd
/sbin/flashcp -v uramdisk /dev/mtd4
OK=$?
/bin/sync
if [ $OK -eq 1 ]; then
echo "Upgrade ramdisk fail!" > "${MSG}"
echo "Upgrade ramdisk fail!" > "${DBG}"
exit 1
fi
echo "Upgrading kernel ... please wait ..." > "${MSG}"
#upgrade kernel mtd
/sbin/flashcp -v uImage /dev/mtd3
OK=$?
/bin/sync
if [ $OK -eq 1 ]; then
echo "Upgrade kernel fail!" > "${MSG}"
echo "Upgrade kernel fail!" > "${DBG}"
exit 1
fi
echo "Upgrading Disk firmware ... please wait ..." > "${MSG}"
#upgrade firmware in disk
mv hdroot.new.gz hdroot.new.md5 /initrd/boot/
cd /initrd/boot
gunzip hdroot.new.gz
OK=$?
/bin/sync
if [ $OK -eq 1 ]; then
echo "Upgrade disk's firmware fail!" > "${MSG}"
echo "Upgrade disk's firmware fail!" > "${DBG}"
exit 1
fi
/bin/sync
# I does not do this, because I trust gunzip.
# /usr/bin/md5sum -c hdroot.new.md5
# OK3=$?
# if [ $OK3 -ne 0 ]; then
# echo "Disk's firmware MD5 checksum fail!" > "${MSG}"
# echo "Disk's firmware MD5 checksum fail!" > "${DBG}"
# exit 1
# fi
touch /initrd/boot/hdroot.new.md5.ok
cd -
/bin/sync
echo "Upgrading configuration ... please wait ... " > "${MSG}"
#check conf.db
/opt/bin/sqlite "/etc/cfg/conf.db" "select k from conf" | sort > ./conf.db.org.list
/opt/bin/sqlite "./conf.db" "select k from conf" | sort > ./conf.db.up.list
./diff ./conf.db.org.list ./conf.db.up.list >> "${DBG}"
./diff --brief ./conf.db.org.list ./conf.db.up.list
if [ $? -ne 0 ]; then
awk -f ./conf.db.awk >> "${DBG}"
fi
#check rc file
filename="rc"
./diff /etc/cfg/$filename ./$filename
if [ $? -ne 0 ]; then
echo "Upgrade $filename" >> "${DBG}"
cp ./$filename /etc/cfg/$filename
fi
filename="rc.factory"
./diff /etc/cfg/$filename ./$filename
if [ $? -ne 0 ]; then
echo "Upgrade $filename" >> "${DBG}"
cp ./$filename /etc/cfg/$filename
fi
#check manifest.txt file
filename="manifest.txt"
./diff /etc/$filename ./$filename
if [ $? -ne 0 ]; then
echo "Upgrade $filename" >> "${DBG}"
cp ./$filename /etc/$filename
fi
#check crond.conf
filename="crond.conf"
./diff /etc/cfg/$filename ./$filename
if [ $? -ne 0 ]; then
echo "upgrade $filename" >> "${DBG}"
cat /app/cfg/$filename | grep 'DL_Center.sh' >> ./$filename
cp ./$filename /etc/cfg/$filename
fi
#check php.ini
filename="php.ini"
./diff /etc/httpd/conf/$filename ./$filename
if [ $? -ne 0 ]; then
echo "upgrade $filename" >> "${DBG}"
cp ./$filename /etc/httpd/conf/$filename
fi
#check ca-bundle.crt
filename="ca-bundle.crt"
./diff /etc/httpd/conf/ssl.crt/$filename ./$filename
if [ $? -ne 0 ]; then
echo "upgrade $filename" >> "${DBG}"
cp ./$filename /etc/httpd/conf/ssl.crt/$filename
fi
filename="server.crt"
./diff /etc/httpd/conf/ssl.crt/$filename ./$filename
if [ $? -ne 0 ]; then
echo "upgrade $filename" >> "${DBG}"
cp ./$filename /etc/httpd/conf/ssl.crt/$filename
fi
#check server.key
filename="server.key"
./diff /etc/httpd/conf/ssl.key/$filename ./$filename
if [ $? -ne 0 ]; then
echo "upgrade $filename" >> ${DBG}
cp ./$filename /etc/httpd/conf/ssl.key/$filename
fi
#check scsi.agent
filename="scsi.agent"
./diff /etc/hotplug/$filename ./$filename
if [ $? -ne 0 ]; then
echo "upgrade $filename" >> "${DBG}"
cp ./$filename /etc/hotplug/$filename
fi
rm -f /etc/hotplug/usb.agent
if [ $DEBUG -eq 1 ]; then
cp ${DBG} /tmp/upgrade.debug
fi
sync
sync
sync
PID=`ps|grep '/bin/sh /img/bin/updfw.sh'|grep -v grep|awk '{print $1}'`
echo "success" > "${MSG}"
kill $PID
echo "success" >> "${DBG}"
echo "Buzzer 1" > /proc/thecus_io
sleep 3
echo "Buzzer 0" > /proc/thecus_io
exit 0
else
echo "MD5 checksum fail" > "${MSG}"
echo "MD5 checksum fail" >> "${DBG}"
if [ $DEBUG -eq 1 ]; then
cp "${DBG}" /tmp/upgrade.debug
fi
exit 1
fi
they used md5sum to check the images and the used flash cp to cpopy them onto the flash after decrypting the bin file.
So i was write. It can easily revert the original ramdrive.
The problem is timim. Can u please tell me Why did u used dd with bs=1k when write the ubuntu kernel on thecus? Should i use the bs=1k parametre when i write back the ramdisk? I suppose flashcp is no longer supported in foonas