1
0

om-fwupgradecfg-gen.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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|OM5PAC|MR600|MR900|MR1750|A60> <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|OM5PAC|MR600|MR900|MR1750|A60)
  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=$(mkhash md5 $KERNEL_PATH)
  39. KERNEL_SHA256=$(mkhash sha256 $KERNEL_PATH)
  40. KERNEL_PART_SIZE=$(size=$(($KERNEL_SIZE / $FLASH_BS)); [ $(($size * $FLASH_BS)) -lt $KERNEL_SIZE ] && size=$(($size + 1)); echo $(($size * $FLASH_BS / 1024)))
  41. ROOTFS_FLASH_ADDR=$(addr=$(($KERNEL_FLASH_ADDR + ($KERNEL_PART_SIZE * 1024))); printf "0x%x" $addr)
  42. ROOTFS_SIZE=$(stat -c%s "$ROOTFS_PATH")
  43. ROOTFS_CHECK_BLOCKS=$((($ROOTFS_SIZE / $CHECK_BS) - $MD5_SKIP_BLOCKS))
  44. ROOTFS_MD5=$(dd if=$ROOTFS_PATH bs=$CHECK_BS count=$ROOTFS_CHECK_BLOCKS 2>&- | mkhash md5)
  45. ROOTFS_MD5_FULL=$(mkhash md5 $ROOTFS_PATH)
  46. ROOTFS_SHA256_FULL=$(mkhash sha256 $ROOTFS_PATH)
  47. ROOTFS_CHECK_SIZE=$(printf '0x%x' $(($ROOTFS_CHECK_BLOCKS * $CHECK_BS)))
  48. ROOTFS_PART_SIZE=$(($MAX_PART_SIZE - $KERNEL_PART_SIZE))
  49. cat << EOF > $CFG_OUT
  50. [vmlinux]
  51. filename=kernel
  52. md5sum=$KERNEL_MD5
  53. filemd5sum=$KERNEL_MD5
  54. filesha256sum=$KERNEL_SHA256
  55. flashaddr=$KERNEL_FLASH_ADDR
  56. checksize=0x0
  57. cmd_success=setenv bootseq 1,2; setenv kernel_size_1 $KERNEL_PART_SIZE; saveenv
  58. cmd_fail=reset
  59. [rootfs]
  60. filename=rootfs
  61. md5sum=$ROOTFS_MD5
  62. filemd5sum=$ROOTFS_MD5_FULL
  63. filesha256sum=$ROOTFS_SHA256_FULL
  64. flashaddr=$ROOTFS_FLASH_ADDR
  65. checksize=$ROOTFS_CHECK_SIZE
  66. cmd_success=setenv bootseq 1,2; setenv kernel_size_1 $KERNEL_PART_SIZE; setenv rootfs_size_1 $ROOTFS_PART_SIZE; saveenv
  67. cmd_fail=reset
  68. EOF