2、将一个MTD分区4挂载为UBIFS格式
● flash_eraseall /dev/mtd4 //擦除mtd4
● ubiattach /dev/ubi_ctrl -m 4 //和mtd4关联
● ubimkvol /dev/ubi0 -N rootfs -s 100MiB //设定volume 大小(不是固定值,可以用工具改变)及名称
● mount -t ubifs ubi0_0 /mnt/ubi或mount -t ubifs ubi0:rootfs /mnt/ubi 3、制作UBIFS文件系统
在制作UBI镜像时,需要首先确定以下几个参数: MTD partition size; //对应的FLASH分区大小 flash physical eraseblock size; // FLASH物理擦除块大小
minimum flash input/output unit size; //最小的FLASH输入输出单元大小 for NAND flashes - sub-page size; //对于nand flash来说,子页大小 logical eraseblock size.//逻辑擦除块大小 参数可以由几种方式得到
1)如果使用的是2.6.30以后的内核,这些信息可以通过工具从内核获得,如:mtdinfo –u。
2)之前的内核可以通过以下方法:
● MTD partition size:从内核的分区表或cat /proc/mtd获得
● flash physical eraseblock size:从flash芯片手册中可以得到FLASH物理擦除块大小,或cat /proc/mtd
● minimum flash input/output unit size:
1)nor flash:通常是1个字节 2)nand falsh:一个页面
● sub-page size:通过flash手册获得
● logical eraseblock size:对于有子页的NAND FLASH来说,等于“物理擦除块大小-1页的大小”
3)也可以通过ubi和mtd连接时的产生的信息获取,如: #modprobe ubi mtd=4 //ubi作为模块加载 或
#ubiattach /dev/ubi_ctrl -m 4 //通过ubiattach关联MTD UBI: attaching mtd4 to ubi0
UBI: physical eraseblock size: 131072 bytes (128 KiB) UBI: logical eraseblock size: 129024 bytes UBI: smallest flash I/O unit: 2048
UBI: sub-page size: 512
UBI: VID header offset: 512 (aligned 512) UBI: data offset: 2048
UBI: attached mtd4 to ubi0
更详细的解释参见http://www.linux-mtd.infradead.org/doc/ubi.html#L_overhead #mkfs.ubifs -r rootfs -m 2048 -e 129024 -c 812 -o ubifs.img
#ubinize -o ubi.img -m 2048 -p 128KiB -s 512 /home/lht/omap3530/tools/ubinize.cfg -r:制定文件内容的位置 -m:页面大小
-e:逻辑擦除块大小
-p:物理擦除块大小
-c:最大的逻辑擦除块数量
对我们这种情况,文件系统最多可以访问卷上的129024*812=100M空间 -s:最小的硬件输入输出页面大小,如:k9f1208为256(上下半页访问) 其中,ubinize.cfg的内容为:
[ubifs] mode=ubi image=ubifs.img vol_id=0
vol_size=100MiB vol_type=dynamic vol_name=rootfs
vol_flags=autoresize
4、利用uboot烧写、启动UBIFS镜像 1)烧写UBIFS镜像
OMAP3 DevKit8000 # mmcinit
OMAP3 DevKit8000 # fatload mmc 0:1 81000000 ubi.img reading ubi.img
12845056 bytes read
OMAP3 DevKit8000 # nand unlock device 0 whole chip
nand_unlock: start: 00000000, length: 268435456! NAND flash successfully unlocked OMAP3 DevKit8000 # nand ecc sw
OMAP3 DevKit8000 # nand erase 680000 7980000
NAND erase: device 0 offset 0x680000, size 0x7980000 Erasing at 0x7fe0000 -- 100% complete.
OK
OMAP3 DevKit8000 # nand write.i 81000000 680000 $(filesize) NAND write: device 0 offset 0x680000, size 0xc40000
Writing data at 0x12bf800 -- 100% complete. 12845056 bytes written: OK
烧写过程和烧写内核镜像的过程一致,所以UBI文件系统应该不像yaffs文件系统那样用到了nand的OOB区域。
2)设置UBIFS文件系统作为根文件系统启动的参数
OMAP3 DevKit8000 # setenv bootargs console=ttyS2,115200n8 ubi.mtd=4 root=ubi0:rootfs
rootfstype=ubifs video=omapfb:mode:4.3inch_LCD
OMAP3 DevKit8000 # setenv bootcmd nand read.i 80300000 280000 200000\\;bootm 80300000
根文件系统的位置在MTD4上 系统启动时会打印出如下和UBI相关的信息: Creating 5 MTD partitions on \ 0x00000000-0x00080000 : \
0x00080000-0x00260000 : \
0x00260000-0x00280000 : \ 0x00280000-0x00680000 : \
0x00680000-0x08000000 : \ UBI: attaching mtd4 to ubi0
UBI: physical eraseblock size: 131072 bytes (128 KiB) UBI: logical eraseblock size: 129024 bytes UBI: smallest flash I/O unit: 2048 UBI: sub-page size: 512
UBI: VID header offset: 512 (aligned 512) UBI: data offset: 2048 UBI: attached mtd4 to ubi0
UBI: MTD device name: \ UBI: MTD device size: 121 MiB UBI: number of good PEBs: 970 UBI: number of bad PEBs: 2 UBI: max. allowed volumes: 128 UBI: wear-leveling threshold: 4096 UBI: number of internal volumes: 1 UBI: number of user volumes: 1 UBI: available PEBs: 0
UBI: total number of reserved PEBs: 970
UBI: number of PEBs reserved for bad PEB handling: 9 UBI: max/mean erase counter: 2/0
ubifs (2011-11-30 17:58) 分类: android
http://www.sakoman.com/OMAP/how-to-write-an-ubifs-rootfs-image-to-nand.html
How to write an UBIFS rootfs image to NAND The images on this site are normally run from a bootable SD card. For OMAP boards with NAND, it is also possible to boot from a NANDimage. To boot from NAND you will need to write four different binary images to NAND:
X-loader U-boot Linux kernel Root file system
This article covers the fourth step of that process, the root file system. Click on each of the other links above for instructions on how to write the other images to NAND. UBIFS
It is highly recommended that you use the Unsorted Block Image File System (UBFS) for your NAND root file system. UBIFS is a successor to JFFS2. It offers improved performance and stability and scales better to systems with large NAND storage. You can learn more about it at the project home page.
Unfortunately these advantages come at a small cost -- creating an UBIFS image is a bit more complicated than other file systems.
This article will discuss two methods to prepare a NAND ubifs image from a rootfs tarball. Both of these methods use the Linux comman
line to write the rootfs. While it is also possible to write an UBIFS file system from u-boot, the Linux command line methods are preferred
These instructions assume you are running a bootable SD image from this site. You will also need a tarball of the rootfs you want to writ2 lines for web page aesthetics!): # wget \\
> http://feeds.sakoman.com/feeds/gnome-r13/images/omap3-multi/current/sakoman-console-image.tar.bz2METHOD 1: UBIMKVOL The first method creates a blank ubifs volume in NAND, then mounts it, and extracts the desired rootfs to the mounted volume. First let's erase the NAND roofs partition: # flash_erase /dev/mtd4 0 0
to NAND. For this example we will download a console image tarball from this site and use that for our ubifs image (command broken int
If your NAND has any bad blocks (a small number are normal and not a cause for concern) you may see messages indicating that someblocks could not be erased. You can safely ignore these messages. Next we create an empty UBIFS file system: # ubiattach /dev/ubi_ctrl -m 4 # ubimkvol /dev/ubi0 -N rootfs -m
Again, if your NAND has a few bad blocks you will see messages indicating that these blocks are being marked as \ look too.
Now we will mount the newly created UBIFS files system and extract our rootfs tarball onto it: mkdir /mnt/nand
mount -t ubifs ubi0:rootfs /mnt/nand
sudo tar xvf sakoman-console-image.tar.bz2 -C /mnt/nandMETHOD 2: UBIFORMAT
closely you will see that these are the same blocks that were listed in the nand_erase step above. You can safely ignore these message
The second method uses mkfs to create an ubifs binary image that is then written to NAND using ubiformat. We'll start by untarring our rootfs tarball: mkdir rootfs
sudo tar xvf sakoman-console-image.tar.bz2 -C rootfs
Then, using the text editor of your choice, create a file called ubinize.cfg with the following contents: [ubifs] mode=ubi image=rootfs.ubifs vol_id=0
vol_type=dynamic vol_name=rootfs vol_flags=autoresize
Next create an ubifs binary image with mkfs.ubifs and %ubinize: sudo mkfs.ubifs -v -r rootfs -o rootfs.ubifs -m 2048 -e 129024 -c 1996 sudo ubinize -v -o rootfs.ubi -m 2048 -p 128KiB -s 512 ubinize.cfg And finally write the ubinized image to NAND using ubiformat: sudo ubiformat -y /dev/mtd4 -f rootfs.ubi
You might want to use this second method if you are developing a production tool to flash NAND since the initial steps can be done oncein advance and only the ubiformat command would be needed per unit. This is much faster than Method 1.
Note: The GNOME r13 and later releases on this site are pre-configured to support UBIFS. Earlier releases do not support UBIFS.
U-BOOT ENVIRONMENT SETUP
The u-boot images on this site are pre-configured to use UBIFS when booting from NAND. In particular, the following 2 u-boot environment variables are initialized as follows: # printenv nandrootfstype nandrootfstype=ubifs # printenv nandroot
nandroot=ubi0:rootfs ubi.mtd=4