1
0

om-fwupgradecfg-gen.sh 2.3 KB

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