UBIFS的编译

来源:互联网 发布:中日建交 知乎 编辑:程序博客网 时间:2024/06/06 19:53

摘自:http://blog.chinaunix.net/uid-30016330-id-4611629.html


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方式
参考http://processors.wiki.ti.com/index.php/UBIFS_Support#Creating_UBIFS_file_system的"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:http://processors.wiki.ti.com/index.php/UBIFS_Support#Creating_UBIFS_file_system的"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=ubiimage=rootfs.ubifsvol_id=1vol_type=staticvol_name=rootfsvol_alignment=1[rwdata_volume]mode=ubiimage=data.ubifsvol_id=2vol_type=dynamicvol_name=datavol_alignment=1vol_flags=autoresize
为了产生UBI镜像文件,需要知道物理EraseBlockSzie(PEB)(参数-p)和最小I/O大小(-m)
# ubinize -vv -o  -m   -p KiB 



1..安装mtd-utils
$git clone git://git.infradead.org/mtd-utils.git

$make

$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'
//======================================================
http://processors.wiki.ti.com/index.php/UBIFS_Support#How_to_enable_UBI.2FUBIFS_support_in_u-boot_.3F


//======================================================
http://processors.wiki.ti.com/index.php/UBIFS_Support#Creating_UBIFS_file_system

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

//========================================================


1.Nand flash的大小2Gbit
256M Bytes(0x00000000 ~ 0x0FFF FFFF)

//2014.5.12========================Start
tftp 81000000  rootfs.bin
U-Boot# nand erase 0x00000000 0x00500000U-Boot# nand write 0x82000000 0x0000000 0x500000

U-Boot# nand erase 0x00500000 0xFB00000U-Boot# nand write 0x81000000 0x00500000 0x02000000


//2014.5.12========================End

分区划分
[    1.439392] 0x000000000000-0x000000500000 : "Kernel"
[    1.447937] 0x000000500000-0x000010000000 : "File System"

nand - NAND sub-system

Usage:
nand info - show available NAND devices
nand device [dev] - show or set current device
nand read - addr off|partition size
nand write - addr off|partition size
    read/write 'size' bytes starting at offset 'off'
    to/from memory address 'addr', skipping bad blocks.
nand read.raw - addr off|partition [count]
nand write.raw - addr off|partition [count]
    Use read.raw/write.raw to avoid ECC and access the flash as-is.
nand erase[.spread] [clean] off size - erase 'size' bytes from offset 'off'
    With '.spread', erase enough for given file size, otherwise,
    'size' includes skipped bad blocks.
nand erase.part [clean] partition - erase entire mtd partition'
nand erase.chip [clean] - erase entire chip'
nand bad - show bad blocks
nand dump[.oob] off - dump page
nand scrub [-y] off size | scrub.part partition | scrub.chip
    really clean NAND erasing bad blocks (UNSAFE)
nand markbad off [...] - mark bad block(s) at offset (UNSAFE)
nand biterr off - make a bit error at offset (UNSAFE)

别一篇也重要

//==========================================================
tftp方法烧写
1.确保Uboot环境变量设置好ipaddr和serverip,并且saveenv
2.在服务端(PC)打开tftp服务器,并且知道路径
TFTP the kernel uImage to DDR.
U-Boot# tftp 0x82000000 

Now flash the kernel image to NAND at the appropriate offset (refer to NAND layout section for the offsets)

U-Boot# nand erase 0x00280000 0x00500000U-Boot# nand write 0x82000000 0x00280000 0x500000
NOTE

*Image_size should be aligned to page size of 2048 (0x800) bytes


UBIFS file system flashing

In AM335X, UBIFS file system is used in NAND flash as it is next generation flash file system.

1. Creating and Flashing of UBIFS file system image is described over here 

NOTE

In case of AM335x, file system partition is starting from 0x780000. So flashing offset for file system in U-Boot is 0x780000 and from Linux MTD partition number 7 should used for flashing file file system.
使用命令:
mtdparts default   使用默认分区对Nand Flash进行分区。
使用命令:nand erase 0x00500000 0x04000000 ,擦除root分区。
使用命令:ubi part  root  2048  ,激活root分区进行ubi格式化。
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
最后使用命令:ubi   create  rootfs  ,创建rootfs分区

制作文件系统
qiuweibo@ME-BS1:~/workspace/003.aPM.MPU/003.rootfs$ $ mkfs.ubifs -r arago-base-tisdk-image-am335x-evm/ -m 2048 -e 126976 -c 4096 -o rootfs.ubi


$ mkfs.ubifs -q -r root-fs -m 2048 -e 129024 -c 2047 -o ubifs.img$ ubinize -o ubi.img -m 2048 -p 128KiB -s 512 ubinize.cfg
使用命令:
tftp 0x80200000  rootfs.ubi 下载rootfs到默认内存地址81000000处,
使用命令:ubi   write 0x80200000  rootfs   $filesize,将内存81000000处大小为$filesize的rootfs.bin通过ubi方式烧写到nand flash的对应分区中

检测测试下:
ubifsmount rootfs
ubifsls
ubifsumount


设置启动变量: bootargs ,(bootargs是uboot传给内核的参数,使用命令:
U-Boot# print nandroot
nandroot=ubi0:rootfs rw ubi.mtd=5,2048

内核打印信息为:
"ubi.mtd=3  root=ubi0:rootfs   rootfstype=ubifs  console=ttySAC0  init=/linuxrc   rw " 

 设置启动命令:bootcmd,(bootcmd 是uboot启动的命令,输入命令:
set  bootcmd  " nand  read 81000000   80000  $filesize;  bootm  81000000" 最后使用sav命令保存环境变量)

注意点1:set  bootcmd  " nand  read 81000000   80000  $filesize;  bootm  81000000 " 中的"81000000"是启动内核的地址,内核启动时自动找到81000000这个地方来启动kernel ;而前面用过的tftp   81000000   xxx 中的"81000000"是内存中的地址(存放在内存地址中的数据掉电后就没了
注意点2:如果 bootm后面不跟地址,默认是到30008000处寻在内核启动的;如果bootcmd环境变量写成:set  bootcmd  " nand  read 31000000   80000  $filesize;  bootm   最终这种现象:如图(因为它到30008000没有找到内核,内核原来由80000的内存地址读到了31000000地址处


//==========================================================
Ymodem方法烧写
2.内核烧写

U-Boot# loady 0x82000000
File -> Transfer -> Ymodem-> Send
U-Boot# nand erase 0x0 0x20000U-Boot# nand write 0x82000000 0x0 0x20000

3.烧写文件系统

U-Boot# loady 0x82000000
File -> Transfer -> Ymodem-> Send
U-Boot# nand erase 0x80000 0x40000U-Boot# nand write 0x82000000 0x80000 0x40000


0 0
原创粉丝点击