mkfs.ubifs -c 输入的logical erase block count,是指除掉ubi文件系统自身管理和坏块处理后的逻辑可擦除最大块数。
参考信息如下:
logical erase block count 计算工具,实现代码如下:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import xml.sax
import sys
import time
import getopt
import math
class ANSI:
RED = '\033[31m'
RESET = '\033[m'
def print_red(text):
print(ANSI.RED + text + ANSI.RESET)
def contains_chars(s,chars):
for c in chars:
if c in s:
return True
return False
def trams_str_digital(text):
tramsNumber = 0
tramstr = text
if contains_chars(tramstr,'M'):
valueStr = tramstr.replace('M','')
tramsNumber = int(valueStr) * 1024 * 1024
elif contains_chars(tramstr,'m'):
valueStr = tramstr.replace('m','')
tramsNumber = int(valueStr) * 1024 * 1024
elif contains_chars(tramstr,'K'):
valueStr = tramstr.replace('K','')
tramsNumber = int(valueStr) * 1024
elif contains_chars(tramstr,'k'):
valueStr = tramstr.replace('k','')
tramsNumber = int(valueStr) * 1024
else:
tramsNumber = int(tramstr)
return tramsNumber
def show_help():
print("ubi_lebc.py -e <logical erase block size> -s <mtd volume total size>")
print("eg:ubi_lebc.py -e 124K -s 30M")
'''
input:mtd volume total size
input:logical erase block size
input:Physical Erase Block size
out:maximum logical erase block count
'''
if __name__ == "__main__":
peb_size = 128 * 1024
leb_size = 124 * 1024
lebc_max = 0
mtd_total_size=0
try:
opts, args = getopt.getopt(sys.argv[1:],"hb:e:s:",['help',"block_size=","erase_size=","size="])
for opt, arg in opts:
if opt in ('-b',"--block_size="):
peb_size = trams_str_digital(arg)
elif opt in ('-e',"--erase_size="):
leb_size = trams_str_digital(arg)
elif opt in ('-s',"--size="):
mtd_total_size = trams_str_digital(arg)
elif opt in ("-h","--help"):
show_help()
sys.exit(0)
else:
show_help()
sys.exit(0)
except getopt.GetoptError as e:
print(sys.argv)
print(e.msg)
print(e.opt)
show_help()
sys.exit(0)
if mtd_total_size == 0:
show_help()
sys.exit(0)
block_total_number = mtd_total_size//peb_size
bad_block_max = math.ceil(block_total_number * 0.02)
if(bad_block_max < 2):
bad_block_max = 2
over_head = peb_size - leb_size
over_head_total_size = over_head * (block_total_number - bad_block_max - 4)
loss_total_size = (bad_block_max + 4) * peb_size
overhead_manager_size = over_head_total_size + loss_total_size
user_data_size = mtd_total_size - overhead_manager_size
lebc_max = int(user_data_size // leb_size)
#print("hysical Erase Block size:"+ "%dK" % (peb_size/1024) + " logical erase block size:" + "%dK" % (leb_size/1024) + " out logical erase block count:" + "%d" % lebc_max)
print(lebc_max)
sys.exit(0)
python ubi_lebc.py -b 128K -e 124K -s 40M
运行结果为:309