#brick-fixV2 - a helping hand to do the enhanced mtd hack
SERVER=192.0.0.128
#
# This value will decide if a stage is considered to be complete.
STAGE_STATUS=0
echo "This is the brick-fix and update script which will help you to extract,"
echo "modify and replace mtdblock6 to fix the downgrade block and convert this camera to English updateable."
echo -e "\n** It is no longer necessary to make any changes to mtdblock1 - these have been processed already **"
echo "."
echo "The whole process takes 3 stages."
echo "Stage 1 - mtdblock6 is extracted and sent via tftp to your PC for you to modify."
echo "Stage 2 - the modified mtdblock6 is retrieved by tftp from your PC and applied to the camera."
echo "Stage 3 - the '5.3.0 to 5.2.5 downgrader' firmware is retrieved by tftp from your PC and used to update the camera."
echo "At this point the web GUI in English will be available and allow"
echo "you to do progressive updates from 5.2.5 to 5.3.0 to 5.4.0 to 5.4.5"
echo "."
echo "In each stage, check the content of the logfile fixup_log.txt for the actions taken and the status."
echo "Good luck!"
echo "."
echo "Checking that tftp works OK ..."
echo "Checking that tftp works OK ..." >> /dav/fixup_log.txt
cd /dav
tftp -p -l fixup_log.txt -b 1400 $SERVER
if [ "$?" = "0" ] ; then
echo -e "\ntftp test transfer worked OK."
echo "[stage start] fixup_log.txt successfully transferrred to the PC via tftp" >> /dav/fixup_log.txt
echo "."
fi
#
#
#
#stage3 retrieve and apply the downgrader firmware
if [ -e /dav/fixup_stage3.txt ]; then
cd /
echo "."
tftp -g -r digicap.dav -b 1400 $SERVER
if [ "$?" = "0" ] ; then
echo -e "\nSuccessfully transferred in digicap.dav via tftp"
echo "Successfully transferred in digicap.dav via tftp" >> /dav/fixup_log.txt
echo "."
echo "Attempting a firmware update ..."
echo "Attempting a firmware update ..." >> /dav/fixup_log.txt
echo "."
# The upgrade program gives a return value=0 even on failure, so need to assess the result differently.
/bin/upgrade /digicap.dav > /dav/fixup_upg_ok.txt
UPG=`cat /dav/fixup_upg_ok.txt | awk '/ERROR/ {print $3}'`
if [ "$UPG" = "" ] ; then
echo -e "\nFirmware update appears to be successful.\n"
echo -e "\nFirmware update appears to be successful.\n" >> /dav/fixup_log.txt
cat /dav/fixup_upg_ok.txt
cat /dav/fixup_upg_ok.txt >> /dav/fixup_log.txt
echo -e "\n\nChanging fixup current status to completed ..."
echo -e "\n\nChanging fixup current status to completed ..." >> /dav/fixup_log.txt
echo "Stage3 is completed - the camera should now be full English and updateable."
STAGE_STATUS=2
echo "Fixup stage3 completed - the camera should now be full English and updateable." > /dav/fixup_stages_completed.txt
rm /dav/fixup_stage3.txt
else
echo -e "\n*** error doing the firmware update. ****"
echo "*** error doing the firmware update. ****" >> /dav/fixup_log.txt
fi
else
echo -e "\n*** error transferring digicap.dav via tftp from the PC. ****"
echo "*** error transferring digicap.dav via tftp from the PC. ****" >> /dav/fixup_log.txt
fi
echo "."
fi
#
#
#
#stage2 retrieve and apply the modified mtdblocks
if [ -e /dav/fixup_stage2.txt ]; then
cd /
echo "."
tftp -g -r mtd6ro_mod -b 1400 $SERVER
if [ "$?" = "0" ] ; then
echo -e "\nSuccessfully transferred in mtd6ro_mod via tftp"
echo "Successfully transferred in mtd6ro_mod via tftp" >> /dav/fixup_log.txt
cat mtd6ro_mod > /dev/mtdblock6
echo "Written mtd6ro_mod to mtdblock6 ..."
echo "Written mtd6ro_mod to mtdblock6 ..." >> /dav/fixup_log.txt
# echo -e "\nChecking if there is an mtd1ro_mod to apply ..."
# echo "Checking if there is an mtd1ro_mod to apply ..." >> /dav/fixup_log.txt
# tftp -g -r mtd1ro_mod -b 1400 $SERVER
# if [ "$?" = "0" ] ; then
# echo -e "\nSuccessfully transferred in mtd1ro_mod via tftp"
# echo "Successfully transferred in mtd1ro_mod via tftp" >> /dav/fixup_log.txt
# cat mtd1ro_mod > /dev/mtdblock1
# echo "Written mtd1ro_mod to mtdblock1 ..."
# echo "Written mtd1ro_mod to mtdblock1 ..." >> /dav/fixup_log.txt
# else
# echo -e "\n**** mtd1ro_mod not available via tftp from the PC. ****"
# echo "**** mtd1ro_mod not found via tftp from the PC. ****" >> /dav/fixup_log.txt
# fi
echo "Fixup stage2 is completed - Applied the modified mtdblock"
echo "Fixup stage2 is completed - Applied the modified mtdblock" > /dav/fixup_stage3.txt
echo "Initialising fixup next status to stage3 ..." >> /dav/fixup_log.txt
echo "Initialising fixup next status to stage3 ..."
echo -e "\nPlease ensure that your required firmware update is named digicap.dav and is available for transfer\n"
STAGE_STATUS=1
rm /dav/fixup_stage2.txt
else
echo -e "\n*** error transferring mtd6ro_mod via tftp from the PC. ****"
echo "*** error transferring mtd6ro_mod via tftp from the PC. ****" >> /dav/fixup_log.txt
fi
echo "."
fi
#
#
#
# Stage1 extract the original mtdblocks
if [ -e /dav/fixup_stage1.txt ]; then
echo "Extracting the original mtdblocks ..." >> /dav/fixup_log.txt
cat /dev/mtd6ro > /mtd6ro_orig
echo "Extracted the original mtdblock6 as mtd6ro_orig"
echo "Extracted the original mtdblock6 as mtd6ro_orig" >> /dav/fixup_log.txt
cat /dev/mtd1ro > /mtd1ro_orig
echo "Extracted the original mtdblock1 as mtd1ro_orig"
echo "Extracted the original mtdblock1 as mtd1ro_orig" >> /dav/fixup_log.txt
echo "Transferring out mtd6ro_orig via tftp ..."
echo "Transferring out mtd6ro_orig via tftp ..." >> /dav/fixup_log.txt
cd /
echo "."
tftp -p -l mtd6ro_orig -b 1400 $SERVER
if [ "$?" = "0" ] ; then
echo "Successfully transferred out mtd6ro_orig via tftp" >> /dav/fixup_log.txt
echo -e "\nSuccessfully transferred out mtd6ro_orig via tftp"
rm mtd6ro_orig
echo "Transferring out mtd1ro_orig via tftp ..." >> /dav/fixup_log.txt
tftp -p -l mtd1ro_orig -b 1400 $SERVER
echo -e "\nSuccessfully transferred out mtd1ro_orig via tftp"
echo "Successfully transferred out mtd1ro_orig via tftp" >> /dav/fixup_log.txt
rm mtd1ro_orig
STAGE_STATUS=1
rm /dav/fixup_stage1.txt
echo "Fixup Stage1 is completed - Extracted the original mtdblocks"
echo "Fixup Stage1 is completed - Extracted the original mtdblocks" >> /dav/fixup_log.txt
echo "Fixup Stage1 completed - Extracted the original mtdblocks" > /dav/fixup_stage2.txt
echo "."
echo "Transferring out fixup_log.txt via tftp for you to check ..."
echo "."
echo "Your Stage2 task now is to make a copy of mtd6ro_orig named as mtd6ro_mod"
echo "and to carry out the 'enhanced mtd hack' on it."
echo "This means setting the language byte at 0x10 to 1, checking/changing as needed the devType"
echo "bytes at 0x64,0x65 and recalculating and applying the checksum-16 value at 0x04,0x05"
# echo "Also required is to check mtd1ro_orig for the values at locations 0x0C and 0x8000C"
# echo "If these are 0, make a copy named as mtd1ro_mod, and change those values to 01"
echo "When that has been done, run this /dav/fixup.sh script again for Stage2"
echo "which will transfer the file in and apply it to the camera."
else
echo -e "\n*** error transferring mtd6ro_orig via tftp to the PC. ****"
echo "*** error transferring mtd6ro_orig via tftp to the PC. ****" >> /dav/fixup_log.txt
fi
echo "."
fi
#
#
echo "."
echo "Each stage of the process is carried out by a run of the /dav/fixup.sh script ..."
echo "The next stage is :"
ls -al /dav/fixup_stage*
echo -e ".\n.\n"
echo -e "End of script - ready for the next run.\n." >> /dav/fixup_log.txt
cd /dav
tftp -p -l fixup_log.txt -b 1400 $SERVER
if [ "$STAGE_STATUS" = "0" ] ; then
echo -e "\n*** An error has occurred. Check the on-screen messages and the contents of the logfile ***"
echo "*** fixup_log.txt that was transferred to your PC and after correcting the cause of the ***"
echo "*** error re-run the script /dav/fixup.sh to resume. ***"
/usr/sbin/set_sysflag -m 1
else
if [ "$STAGE_STATUS" = "1" ] ; then
echo -e "\nEnd of script - ready for the next run."
/usr/sbin/set_sysflag -m 1
fi
fi
#
if [ "$STAGE_STATUS" = "2" ] ; then
echo -e "\nmtdblock and firmware updates are completed. Now power cycle the camera and log in to the web GUI for full firmware upgrades."
/usr/sbin/set_sysflag -m 0
fi
#Ends