om-fwupgradecfg-gen.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #/bin/sh
  2. #
  3. # Copyright (C) 2011 OpenWrt.org
  4. #
  5. # This is free software, licensed under the GNU General Public License v2.
  6. # See /LICENSE for more information.
  7. #
  8. usage() {
  9. echo "Usage: $0 <OM2P|OM5P|MR600|MR900> <out file path> <kernel path> <rootfs path>"
  10. rm -f $CFG_OUT
  11. exit 1
  12. }
  13. [ "$#" -lt 4 ] && usage
  14. CE_TYPE=$1
  15. CFG_OUT=$2
  16. KERNEL_PATH=$3
  17. ROOTFS_PATH=$4
  18. case $CE_TYPE in
  19. OM2P)
  20. MAX_PART_SIZE=7168
  21. KERNEL_FLASH_ADDR=0x1c0000
  22. FLASH_BS=262144
  23. MD5_SKIP_BLOCKS=1
  24. ;;
  25. OM5P|MR600|MR900)
  26. MAX_PART_SIZE=7808
  27. KERNEL_FLASH_ADDR=0xb0000
  28. FLASH_BS=65536
  29. MD5_SKIP_BLOCKS=4
  30. ;;
  31. *)
  32. echo "Error - unsupported ce type: $CE_TYPE"
  33. exit 1
  34. ;;
  35. esac
  36. CHECK_BS=65536
  37. KERNEL_SIZE=$(stat -c%s "$KERNEL_PATH")
  38. KERNEL_MD5=$(md5=$(md5sum $KERNEL_PATH); echo ${md5%% *})
  39. KERNEL_PART_SIZE=$(size=$(($KERNEL_SIZE / $FLASH_BS)); [ $(($size * $FLASH_BS)) -lt $KERNEL_SIZE ] && size=$(($size + 1)); echo $(($size * $FLASH_BS / 1024)))
  40. ROOTFS_FLASH_ADDR=$(addr=$(($KERNEL_FLASH_ADDR + ($KERNEL_PART_SIZE * 1024))); printf "0x%x" $addr)
  41. ROOTFS_SIZE=$(stat -c%s "$ROOTFS_PATH")
  42. ROOTFS_CHECK_BLOCKS=$((($ROOTFS_SIZE / $CHECK_BS) - $MD5_SKIP_BLOCKS))
  43. ROOTFS_MD5=$(md5=$(dd if=$ROOTFS_PATH bs=$CHECK_BS count=$ROOTFS_CHECK_BLOCKS 2>&- | md5sum); echo ${md5%% *})
  44. ROOTFS_CHECK_SIZE=$(printf '0x%x' $(($ROOTFS_CHECK_BLOCKS * $CHECK_BS)))
  45. ROOTFS_PART_SIZE=$(($MAX_PART_SIZE - $KERNEL_PART_SIZE))
  46. cat << EOF > $CFG_OUT
  47. [vmlinux]
  48. filename=kernel
  49. md5sum=$KERNEL_MD5
  50. flashaddr=$KERNEL_FLASH_ADDR
  51. checksize=0x0
  52. cmd_success=setenv bootseq 1,2; setenv kernel_size_1 $KERNEL_PART_SIZE; saveenv
  53. cmd_fail=reset
  54. [rootfs]
  55. filename=rootfs
  56. md5sum=$ROOTFS_MD5
  57. flashaddr=$ROOTFS_FLASH_ADDR
  58. checksize=$ROOTFS_CHECK_SIZE
  59. cmd_success=setenv bootseq 1,2; setenv kernel_size_1 $KERNEL_PART_SIZE; setenv rootfs_size_1 $ROOTFS_PART_SIZE; saveenv
  60. cmd_fail=reset
  61. EOF