1
0

om-fwupgradecfg-gen.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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|A42|A62> <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=4
  24. SIZE_FACTOR=1
  25. SIZE_FORMAT="%d"
  26. ;;
  27. OM5P|OM5PAC|MR600|MR900|MR1750|A60)
  28. MAX_PART_SIZE=7808
  29. KERNEL_FLASH_ADDR=0xb0000
  30. FLASH_BS=65536
  31. MD5_SKIP_BLOCKS=4
  32. SIZE_FACTOR=1
  33. SIZE_FORMAT="%d"
  34. ;;
  35. A42)
  36. MAX_PART_SIZE=15616
  37. KERNEL_FLASH_ADDR=0x180000
  38. FLASH_BS=65536
  39. MD5_SKIP_BLOCKS=4
  40. SIZE_FACTOR=1024
  41. SIZE_FORMAT="0x%08x"
  42. ;;
  43. A62)
  44. MAX_PART_SIZE=15552
  45. KERNEL_FLASH_ADDR=0x1a0000
  46. FLASH_BS=65536
  47. MD5_SKIP_BLOCKS=4
  48. SIZE_FACTOR=1024
  49. SIZE_FORMAT="0x%08x"
  50. ;;
  51. *)
  52. echo "Error - unsupported ce type: $CE_TYPE"
  53. exit 1
  54. ;;
  55. esac
  56. CHECK_BS=65536
  57. KERNEL_SIZE=$(stat -c%s "$KERNEL_PATH")
  58. KERNEL_MD5=$(mkhash md5 $KERNEL_PATH)
  59. KERNEL_SHA256=$(mkhash sha256 $KERNEL_PATH)
  60. KERNEL_PART_SIZE_KB=$(size=$(($KERNEL_SIZE / $FLASH_BS)); [ $(($size * $FLASH_BS)) -lt $KERNEL_SIZE ] && size=$(($size + 1)); echo $(($size * $FLASH_BS / 1024)))
  61. KERNEL_PART_SIZE=$(printf $SIZE_FORMAT $(($KERNEL_PART_SIZE_KB * $SIZE_FACTOR)))
  62. ROOTFS_FLASH_ADDR=$(addr=$(($KERNEL_FLASH_ADDR + ($KERNEL_PART_SIZE_KB * 1024))); printf "0x%x" $addr)
  63. ROOTFS_SIZE=$(stat -c%s "$ROOTFS_PATH")
  64. ROOTFS_CHECK_BLOCKS=$((($ROOTFS_SIZE / $CHECK_BS) - $MD5_SKIP_BLOCKS))
  65. ROOTFS_MD5=$(dd if=$ROOTFS_PATH bs=$CHECK_BS count=$ROOTFS_CHECK_BLOCKS 2>&- | mkhash md5)
  66. ROOTFS_MD5_FULL=$(mkhash md5 $ROOTFS_PATH)
  67. ROOTFS_SHA256_FULL=$(mkhash sha256 $ROOTFS_PATH)
  68. ROOTFS_CHECK_SIZE=$(printf '0x%x' $(($ROOTFS_CHECK_BLOCKS * $CHECK_BS)))
  69. ROOTFS_PART_SIZE_KB=$(($MAX_PART_SIZE - $KERNEL_PART_SIZE_KB))
  70. ROOTFS_PART_SIZE=$(printf $SIZE_FORMAT $(($ROOTFS_PART_SIZE_KB * $SIZE_FACTOR)))
  71. cat << EOF > $CFG_OUT
  72. [vmlinux]
  73. filename=kernel
  74. md5sum=$KERNEL_MD5
  75. filemd5sum=$KERNEL_MD5
  76. filesha256sum=$KERNEL_SHA256
  77. flashaddr=$KERNEL_FLASH_ADDR
  78. checksize=0x0
  79. cmd_success=setenv bootseq 1,2; setenv kernel_size_1 $KERNEL_PART_SIZE; saveenv
  80. cmd_fail=reset
  81. [rootfs]
  82. filename=rootfs
  83. md5sum=$ROOTFS_MD5
  84. filemd5sum=$ROOTFS_MD5_FULL
  85. filesha256sum=$ROOTFS_SHA256_FULL
  86. flashaddr=$ROOTFS_FLASH_ADDR
  87. checksize=$ROOTFS_CHECK_SIZE
  88. cmd_success=setenv bootseq 1,2; setenv kernel_size_1 $KERNEL_PART_SIZE; setenv rootfs_size_1 $ROOTFS_PART_SIZE; saveenv
  89. cmd_fail=reset
  90. EOF