1.制作ubi.fs的脚本
$ cat do_mkfs_ubinize
echo "Step1: mkfs.ubifs"
#echo "sub-page support";mkfs.ubifs -F -r arago-base-tisdk-image-am335x-evm/ -m 2048 -e 129024 -c 512 -o rootfs.ubi
echo "no sub-page";mkfs.ubifs -F -r arago-base-tisdk-image-am335x-evm/ -m 2048 -e 126976 -c 512 -o rootfs.ubi
echo "Step2: ubinize"
ubinize -vv -o ubi.img -m 2048 -p 128KiB ubinize.cfg
#ubinize -vv -o ubi.img -m 2048 -p 128KiB -s 512 -O 2048 ubinize.cfg
echo "Step3: cp tftproot, rm ..."
cp ubi.img ~/tftproot/
rm ubi.img rootfs.ubi
echo "End!"
分析:mkfs.ubifs -F -r arago-base-tisdk-image-am335x-evm/ -m 2048 -e 126976 -c 512 -o rootfs.ubi
1)参数-F:表示在u-boot使用nand write方式,而不是ubi write方式
参考的"white-space-fixup"
2)参数-r arago-base-tisdk-image-am335x-evm/,表示文件系统根目录下路径
3)参数-m 2048:表示最小的I/O操作大小(也就是Nand Flash的一个Page的大小)
参考U-boot信息"UBI: smallest flash I/O unit: 2048"
4)参数-e 126976:参数-e
LEB的大小计算:两个Headers分别为erase-header和volume-id-header作为block标识。
a)当不支持sub-page特性时,每个block:eraser-header写入1st page,volume-id-header写入2nd pager
因此,LEB_SIZE=$BLOCK_SIZE - (2 x $PAGE_SIZE)=64pages-2pages=62pages=62*2048Byte=126976
b)支持sub-page特性时,两个headers都写入1st page,而剩下n-1 pages提供用户数据存储
因此,LEB_SIZE=$BLOCK_SIZE - (1 x $PAGE_SIZE)=64pages-1pages=63pages=63*2048byte=129024
1block=128KB=131072Byte
参考1:的"LEB Size Calculations"
参考2:H27U2G8F2CTR-BC X8:[(2K+64)bytesx 64pagesx2048 blocks]
5)参数-c 512:最大逻辑擦除块的数量
例如:本rootfs分区64M,64M/blocksize=64M/(64*2K)=64M/128K=512
6)参数-o rootfs.ubi:最终制作成的根文件镜像的文件名
分析:ubinize -vv -o ubi.img -m 2048 -p 128KiB ubinize.cfg
1)参数-vv (两个v):程序运行时显示详细信息
2)参数-o ubi.img:最终制作成的根文件镜像的文件名
3)参数-m 2048:表示最小的I/O操作大小(也就是Nand Flash的一个Page的大小)
4)参数 -p 128KiB:物理擦除块的大小
5)参数 ubinize.cfg:使用的配置文件名称,文件内容如下
$ cat ubinize.cfg
[ubifs]
mode=ubi
image=rootfs.ubi
vol_id=5
vol_size=60MiB
vol_type=dynamic
vol_name=rootfs
vol_alignment=1
vol_flags=autoresize
2.解决:UBI error: torture_peb的方法:
uboot:drivers/mtd/nand/omap_gpmc.c
omap_read_page_bch里面
//chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, page);//-QWB140514-delete
chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, -1);//-QWB140514-add
//chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, page);//-QWB140514-delete
chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);//-QWB140514-add
kernel:
drivers/mtd/nand/omap2.c
omap_read_page_bch里面
//chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, page);//-QWB140514-delete
chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_pos, -1);//-QWB140514-add
//chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, page);//-QWB140514-delete
chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);//-QWB140514-add
omap_correct_data里面
//if (err_loc[j] < BCH8_ECC_MAX) //-QWB140514-delete
if (byte_pos < BCH8_ECC_BYTES) //-QWB140514-add
//-----------------------------------------调试分界线-------------------------------------------------
>>>>>>>>>>>>>>>>>>>>>U-Boot的信息Start
U-Boot# ubi part rootfs 2048
Creating 1 MTD partitions on "nand0":
0x000000500000-0x000004500000 : "mtd=1"
UBI: attaching mtd1 to ubi0
UBI: physical eraseblock size: 131072 bytes (128 KiB)
UBI: logical eraseblock size: 126976 bytes
UBI: smallest flash I/O unit: 2048
UBI: sub-page size: 512
UBI: VID header offset: 2048 (aligned 2048)
UBI: data offset: 4096
UBI: empty MTD device detected
UBI: create volume table (copy #1)
UBI: create volume table (copy #2)
UBI: attached mtd1 to ubi0
UBI: MTD device name: "mtd=1"
UBI: MTD device size: 64 MiB
UBI: number of good PEBs: 512
UBI: number of bad PEBs: 0
UBI: max. allowed volumes: 128
UBI: wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 0
UBI: available PEBs: 503
UBI: total number of reserved PEBs: 9
UBI: number of PEBs reserved for bad PEB handling: 5
UBI: max/mean erase counter: 1/0
U-Boot#
>>>>>>>>>>>>>>>>>>>>>U-Boot的信息End
注意1:
使用mkfs.ubifs生成文件,对应使用ubi write命令
使用ubinize生成文件,对应使用nand write命令
注意2:
使用nand write方式的,需要添加-F参数,例如:mkfs.ubifs -F
注意3:
当前OMAP NAND驱动不支持subpage,故需要subpage-size=offset-of-vid-header=page-size
注意5:
两个卷标识的ubinize例子
1个名为rootfs,只读(static);另外一个名为data,可读可写(dynamic),而autoresize表示初始化整个分区.
[rootfs_volume]
mode=ubi
image=rootfs.ubifs
vol_id=1
vol_type=static
vol_name=rootfs
vol_alignment=1
[rwdata_volume]
mode=ubi
image=data.ubifs
vol_id=2
vol_type=dynamic
vol_name=data
vol_alignment=1
vol_flags=autoresize
为了产生UBI镜像文件,需要知道物理EraseBlockSzie(PEB)(参数-p)和最小I/O大小(-m)
# ubinize -vv -o
1..安装mtd-utils
$git clone git://git.infradead.org/mtd-utils.git
$sudo make install
生成文件在/usr/sbin/下
错误1:mkfs.jffs2.c:70:21: fatal error: sys/acl.h: No such file or directory
解决措施:
$sudo apt-get install uuid-dev libacl1-dev liblzo2-dev
错误2:
解决措施:compr_zlib.c:39:18: fatal error: zlib.h: No such file or directory
$sudo apt-get install zlib1g-dev
将根文件系统所在目录rootfs制作为ubifs镜像文件rootfs.bin,将该文件拷贝到/tftpboot/目录下等待下载烧写。(注意,你在哪执行这个命令,生成的.bin镜像就在执行此命令的当前目录下生成)
注意点1:
上面指针ubifs镜像文件使用的指令参数是根据开发板所使用的Nand Flash来确定的,我的Nand Flash容量是256MB,可以使用命令mkfs.ubifs -h来查看各个命令选择的意思,简单介绍下:
-r :要制作成镜像的根文件系统路径
-m :最小的I/O操作大小(也就是Nand Flash的一个Page的大小)
-e :逻辑擦除块的大小
-p :物理擦除块的大小
-c :最大逻辑擦除块的数量
-o :最终制作成的根文件镜像的文件名
必须知道的前提信息:
-
the eraseblocks (PEB) ;
-
the pages (or “minimum input/output size”) ;
-
the subpages (it may be the same as the min i/o size) ;
-
逻辑eraseblocks=PEB-(int((Subpage_size+Page_size)/Page_size))*Page_size:128*1024-(2048+2048)/2048*2048=126976
-
其中 subpage+page truncated to page size
# mkfs.ubifs -r -m
-e -c
-o
Booting with UBIFS as root file-system'
u-boot#> setenv bootargs 'console=ttyO0,115200n8 root=ubi0:rootfs rw ubi.mtd=,2048 noinitrd rootfstype=ubifs mem=256M rootwait=1'
The value of PARTITION_ID depends on MTD device which holds the root filesystem. The below example assumes UBIFS file system is flashed on MTD partition 7.
One may instead pass in the name of the partition as set in the partition table for the device.
u-boot> setenv bootargs 'console=ttyO0,115200n8 root=ubi0:rootfs rw ubi.mtd=7,2048 noinitrd rootfstype=ubifs mem=256M rootwait=1'
//
How to enable UBI/UBIFS support in Linux Kernel ?
To enable UBIFS support, start the Linux Kernel Configuration tool:
-
Enabling UBI support on MTD devices.
Device Drivers --->
Memory Technology Device (MTD) support --->
Enable UBI - Unsorted block images --->
-
Enabling UBIFS file-system support.
File systems --->
Miscellaneous filesystems --->
UBIFS file system support
Note: Above configurations are enabled default in omap2plus_defconfig
How to enable UBI/UBIFS support in u-boot ?
The following macros need to be defined in the board config for enabling UBI/UBIFS in uboot
#define CONFIG_CMD_NAND
#define CONFIG_CMD_UBI
#define CONFIG_CMD_UBIFS
#define CONFIG_RBTREE
#define CONFIG_MTD_DEVICE
#define CONFIG_MTD_PARTITIONS
#define CONFIG_CMD_MTDPARTS
#define CONFIG_LZO
Note: Details of UBI command available in u-boot are given in $U-BOOT/doc/README.ubi
//========================================================