xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | |
| 4 | #########可修改---开始######### |
| 5 | #分区大小,单位MB,可以是带小数 |
| 6 | if [ $# -eq 0 ]; then |
| 7 | INPUT_MTD_SIZE=32 |
| 8 | else |
| 9 | INPUT_MTD_SIZE=$1 |
| 10 | fi |
| 11 | |
| 12 | #擦除块大小 |
| 13 | MTD_ERASE_SIZE=0x40000 |
| 14 | |
| 15 | #flash页大小 |
| 16 | MTD_PAGE_SIZE=4096 |
| 17 | |
| 18 | #子页subpage大小 |
| 19 | MTD_SUBPAGE_SIZE=4096 |
| 20 | |
| 21 | #BEB保留数,每1024预留多少个给坏快 |
| 22 | BEB_RESERVE_LIMIT=20 |
| 23 | #########可修改---结束######### |
| 24 | |
| 25 | function gen_mtd_para() |
| 26 | { |
| 27 | MTD_NAME=$1 |
| 28 | MTD_SIZE_MB=$2 |
| 29 | MTD_SIZE_KB=$(awk "BEGIN { print $MTD_SIZE_MB * 1024 }") |
| 30 | BLOCK_SIZE_KB=$[$MTD_ERASE_SIZE / 1024] |
| 31 | BLOCK_CNT_1MB=$[0x100000 / $MTD_ERASE_SIZE] |
| 32 | MTD_BLOCK_CNT=$(awk "BEGIN { print $MTD_SIZE_MB * $BLOCK_CNT_1MB }") |
| 33 | BEB_RESERVE_CNT=$(awk "BEGIN { print int($BEB_RESERVE_LIMIT * $MTD_BLOCK_CNT / 1024) }") |
| 34 | if [ $BEB_RESERVE_CNT -lt 2 ]; then |
| 35 | BEB_RESERVE_CNT=2 |
| 36 | fi |
| 37 | MAX_LEB_CNT=$[$MTD_BLOCK_CNT - $BEB_RESERVE_CNT - 4] |
| 38 | if [ $MTD_SUBPAGE_SIZE -lt $MTD_PAGE_SIZE ]; then |
| 39 | LEB_SIZE=$[$MTD_ERASE_SIZE - $MTD_PAGE_SIZE] |
| 40 | else |
| 41 | LEB_SIZE=$[$MTD_ERASE_SIZE - $MTD_PAGE_SIZE - $MTD_PAGE_SIZE] |
| 42 | fi |
| 43 | LEB_SIZE_KB=$[$LEB_SIZE / 1024] |
| 44 | VOL_SIZE_KB=$[$LEB_SIZE_KB * $MAX_LEB_CNT] |
| 45 | VOL_SIZE_MB0=$(awk "BEGIN { print $VOL_SIZE_KB / 1024 }") |
| 46 | VOL_SIZE_MB=$(awk "BEGIN { print int($VOL_SIZE_KB / 1024) }") |
| 47 | |
| 48 | echo "$MTD_NAME MKUBIFS_ARGS=\"-m $MTD_PAGE_SIZE -e $LEB_SIZE -c $MAX_LEB_CNT -x zlib -F\"" |
| 49 | echo "$MTD_NAME UBINIZE_ARGS=\"-m $MTD_PAGE_SIZE -p $MTD_ERASE_SIZE -s $MTD_SUBPAGE_SIZE\"" |
| 50 | #echo "$MTD_NAME vol_size=\"${VOL_SIZE_MB}MiB\"" |
| 51 | } |
| 52 | |
| 53 | echo "generate $INPUT_MTD_SIZE MB parameter" |
| 54 | gen_mtd_para ubifs $INPUT_MTD_SIZE |
| 55 | |