blob: 26f11f470b2b5a5151981afa4bc99d9e554a5820 [file] [log] [blame]
xf.li7ccf8372024-03-07 00:08:02 -08001#!/bin/bash
2
3
4#########可修改---开始#########
5#分区大小,单位MB,可以是带小数
6if [ $# -eq 0 ]; then
7 INPUT_MTD_SIZE=32
8else
9 INPUT_MTD_SIZE=$1
10fi
11
12#擦除块大小
13MTD_ERASE_SIZE=0x40000
14
15#flash页大小
16MTD_PAGE_SIZE=4096
17
18#子页subpage大小
19MTD_SUBPAGE_SIZE=4096
20
21#BEB保留数,每1024预留多少个给坏快
22BEB_RESERVE_LIMIT=20
23#########可修改---结束#########
24
25function 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
53echo "generate $INPUT_MTD_SIZE MB parameter"
54gen_mtd_para ubifs $INPUT_MTD_SIZE
55