Skip to content

Instantly share code, notes, and snippets.

@a740122
Forked from fcicq/flash.sh
Last active August 29, 2015 14:15
Show Gist options
  • Save a740122/68872e260507e64ac0f2 to your computer and use it in GitHub Desktop.
Save a740122/68872e260507e64ac0f2 to your computer and use it in GitHub Desktop.
#!/bin/sh
#high chance need have a change ...
if [ ! $# -eq 2 ]; then
echo "usage: $0 UBOOTFILE MD5"
exit
fi
UBOOT_NAME=$1
MD5SUM_SHOULD_BE=$2
if [ ! -f $UBOOT_NAME ]; then
echo "u-boot file $UBOOT_NAME not exists"
exit
fi
grep "u-boot image" $UBOOT_NAME >/dev/null || (echo "not an u-boot image"; exit)
#need check the md5sum,any one byte in bootloader should be right ...
CURRENT_MD5SUM_VAL=$( md5sum $UBOOT_NAME |awk '{print $1 }' )
echo "$UBOOT_NAME md5sum : $CURRENT_MD5SUM_VAL"
if [ $MD5SUM_SHOULD_BE = $CURRENT_MD5SUM_VAL ]; then
echo "$UBOOT_NAME md5sum check pass"
else
echo "###############$UBOOT_NAME md5sum check fail###############"
exit
fi
dd if=$UBOOT_NAME of=uboot_130048.bin bs=130048 count=1
RAW_UBOOT_LEN=`wc -c uboot_130048.bin | awk '{print $1 }'`
NEED_PAD_LEN=$((0x1fc00-$RAW_UBOOT_LEN))
#Generate a file used as pad ...
dd if=/dev/zero of=pad.bin bs=1 count=$NEED_PAD_LEN
echo "Backuping to uboot_backup.bin"
cat /dev/mtdblock0 > uboot_backup.bin
if [ ! -f ./uboot-mac.bin ]; then
echo "Backup some config first,just like MAC address ..."
dd if=/dev/mtdblock0 of=uboot-mac.bin bs=1 skip=$((0x1fc00))
else
echo "Old uboot-mac backup is found, skipping, are you doing reflashing?"
fi
cat uboot_130048.bin pad.bin uboot-mac.bin >uboot_0x20000.bin
UBOOT_LEN=`wc -c uboot_0x20000.bin | awk '{print $1 }'`
if [ ! $UBOOT_LEN -eq 131072 ]; then
echo "uboot size error $UBOOT_LEN, stop!"
exit
fi
echo "Flashing"
cat uboot_0x20000.bin >/dev/mtdblock0
sync
sync
sync
echo "Sync Finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment