UBI文件系统镜像制作

UBI文件系统镜像制作

ubifs文件系统镜像分为制作分两步,分别是:

1)mkfs.ubifs工具制作UBIFS文件系统镜像

2)ubinize添加UBI卷信息

mkfs.ubifs只是制作了UBIFS文件系统镜像,但其要能通过烧录器烧片,必须使用ubinize工具把UBI卷信息加上。

mkfs.ubifs工具

mkfs.ubifs命令用于制作ubifs文件系统,命令示例如下:

mkfs.ubifs -x lzo -m 2KiB -e 124KiB -c 360 -o ./tmp_ubifs.img -d ./rootfs

参数含义:

  1. -x:指定压缩算法

  2. -m:最小读写单位,也就是页的大小

  3. -e:逻辑擦除块的大小,注:逻辑擦除块不等同于物理擦除块,常用计算方法是:(一个擦除块的页数 - 2)* 页大小,在这里即:(64 - 2) * 2048 = 124KiB

  4. -c:最大的逻辑擦除块个数,这个需要根据分区大小进行计算,常用计算方法是:总块数- 2(volume table) - 1(Wear-leveling) - 1(atomic LEB change) - ?(bad blocks) ,当前的系统中,文件系统分区的大小为:0x3200000 / (64 * 2048) = 400,也就是400个块,如果我们为坏块保留36个块,那么该值即为:400 – 2 -1 -1 -36 = 360

  5. -o:指定输出文件的文件名

  6. -d:指定根文件系统目录

ubinize工具

ubinize配置文件的内容如下:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-i4suW99Y-1647081915409)(file:///C:\Users\IBM\AppData\Local\Temp\ksohtml\wpsA636.tmp.jpg)]

1) [rootfs]:为INI文件SECTION名字,没有特别含义

2) mode=ubi,具体含义未知

3) image=./tmp_ubifs.img:使用mkfs.ubifs生成的镜像文件的路径

4) vol_id=0:卷ID,注意其必须与bootargs参数对应上

5) vol_size=45711360:卷大小,其计算方式是:最大逻辑擦除块个数 * 逻辑块大小,这两个参数就是mkfs.ubifs的参数,360 * 124KiB = 45711360

6) vol_name=rootfs:卷名字,注意其必须与bootargs参数对应上

7) vol_type=dynamic,具体含义未知

8) vol_alignment=1,具体含义未知

注 bootargs中指定rootfs为ubifs:

bootargs=earlyprintk 
console=ttyS0,115200 
rootwait 
nprofile_irq_duration=on 
root=ubi0:rootfs #上面提到的卷ID和卷名称
rootfstype=ubifs 
ubi.fm_autoconvert=1 
init=/linuxrc  
ubi.mtd=6 rw

ubinize命令:

ubinize -o rootfs_ubifs.bin -m 2KiB -p 128KiB -s 2KiB ./ubinize_config

参数含义:

  1. -o rootfs_ubifs.bin:输出的BIN文件名称,后继U-BOOT烧录(nand wirte),应用升级,烧录器烧片,均使用的是此文件

  2. -m 2KiB:最小读写单位,也就是页的大小

  3. -p 128KiB:物理擦除块的大小

  4. -s 2KiB:SUB PAGE的大小

  5. ./ubinize_config:上面的配置文件

分区max leb计算

计算分区max leb的python脚本

#!/usr/bin/python

import sys, os
import math

W = 1000
SP = 128 * 1024
SL = 124 * 1024
BB = 0
O = SP - SL

# UBI uses some amount of flash space for its own purposes, thus reducing the amount of flash space available for UBI users. Namely
# 2 PEBs are used to store the volume table;
# 1 PEB is reserved for wear-leveling purposes;
# 1 PEB is reserved for the atomic LEB change operation;
# some amount of PEBs is reserved for bad PEB handling; this is applicable for NAND flash, but not for NOR flash; the amount of reserved PEBs is configurable and is equal to 20 blocks per 1024 blocks by default;
# UBI stores the EC and VID headers at the beginning of each PEB; the amount of bytes used for these purposes depends on the flash type and is explained below.
# 
# W	- total number of physical eraseblocks on the flash chip (NB: the entire chip, not the MTD partition);
# P	- total number of physical eraseblocks on the MTD partition);
# SP	- physical eraseblock size;
# SL	- logical eraseblock size;
# BB	- number of bad blocks on the MTD partition;
# BR	- number of PEBs reserved for bad PEB handling. it is 20 * W/1024 for NAND by default, and 0 for NOR and other flash types which do not have bad PEBs;
# B	- MAX(BR,BB);
# O	- the overhead related to storing EC and VID headers in bytes, i.e. O = SP - SL.

# in case of NOR flash which has 1 byte minimum input/output unit, O is 128 bytes;
# in case of NAND flash which does not have sub-pages (e.g., MLC NAND), O is 2 NAND pages, i.e. 4KiB in case of 2KiB NAND page and 1KiB in case of 512 bytes NAND page;
# in case of NAND flash which has sub-pages, UBI optimizes its on-flash layout and puts the EC and VID headers at the same NAND page, but different sub-pages; in this case O is only one NAND page;
# for other flashes the overhead should be 2 min. I/O units if the min. I/O unit size is greater or equivalent to 64 bytes, and 2 times 64 bytes aligned to the min. I/O unit size if the min. I/O unit size is less than 64 bytes.

# N.B.: the formula above counts bad blocks as a UBI overhead. The real UBI overhead is: (B - BB + 4) * SP + O * (P - B - 4).


def usage():
        print "Usage: %s PartitionSize(Bytes)" % sys.argv[0]

def get_ubifs_max_leb(partition_size):		#Unit: Bytes
	P = partition_size/SP
	BR = math.ceil(30 * W/float(1024))	# Sync with kernel
	B = max(BB, BR)

	ubi_overhead = (( B - BB + 4 ) * SP + O * ( P - B - 4 ))/float(SP)
	ubi_overhead = math.ceil(ubi_overhead)
	ubi_overhead = math.floor(((P - ubi_overhead) * SP) / float(SL))
	return ubi_overhead * 0.98

def main():
	PTS = int(sys.argv[1])
	print "The MAX LEB is %d" %(get_ubifs_max_leb(PTS))
	

if __name__ == "__main__":
	if (len(sys.argv) < 2)  :
		usage()
		sys.exit(0)

        main()

你可能感兴趣的:(小张学inux内核,linux)