Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1226993
  • 博文数量: 479
  • 博客积分: 12240
  • 博客等级: 上将
  • 技术积分: 4999
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-24 17:12
文章分类

全部博文(479)

文章存档

2014年(1)

2013年(1)

2012年(1)

2011年(95)

2010年(177)

2009年(167)

2008年(16)

2007年(21)

分类: LINUX

2010-09-19 14:43:57


UBIFS文件系统烧写2(1)解压方式
需要工具:flash_eraseall ubiattach ubimkvol 
方法简便明了,需要设置的参数很少,缺点是时间稍长。

flash_eraseall /dev/mtd4
ubiattach /dev/ubi_ctrl -m 4
ubimkvol /dev/ubi1 -N rootfs -s 204800KiB
mount -t ubifs ubi1:rootfs /mnt

mount -t vfat /dev/mmcblk0p1 /tmp
tar xf rootfs.tar -C /mnt/

umount /mnt/
umount /tmp/




(2)ubi工具烧写
需要的工具比较多:
HOST : mkfs.ubifs  ubinize 
TARGET:flash_eraseall ubiformat 

主机相关工具怎么得到呢?在mtd-1.2.0中是没有这个工具的,必须使用新一点的版本,如可用mtd-1.4.2:
wget ftp://ftp.infradead.org/pub/mtd-utils/mtd-utils-1.4.2.tar.bz2

然后在主机上编译。当然,可能会出现一些错误,请根据实际情况解决。


首先在HOST上制作根文件系统的ubifs镜像以及将用于烧写到MTD的ubi镜像。需要的参数比较多,如果参数不正确,得到的结果将是错误的。

获取参数的方法,可以在U-Boot中获取,参考下列信息:

#!/bin/sh
#information about rootfs partion frm U-Boot
#U-Boot$ubi part rootfs
#UBI: mtd1 is detached from ubi0
#Creating 1 MTD partitions on "nand0":
#0x000001600000-0x000010000000 : "mtd=4"
#device_name0:mtd=4
#UBI: attaching mtd1 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
#scanning error 0
#UBI: attached mtd1 to ubi0
#UBI: MTD device name: "mtd=4"
#UBI: MTD device size: 234 MiB
#UBI: number of good PEBs: 1870
#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: 222
#UBI: total number of reserved PEBs: 1648
#UBI: number of PEBs reserved for bad PEB handling: 18
#UBI: max/mean erase counter: 2/1

# -m 2048
# -e 129024
# -c 1872 (1870+2)
# -s 512

mkfs.ubifs -r rootfs -m 2048 -e 129024 -c 1872 -o rootfs.img
ubinize -o ubi.img -m 2048 -p 128KiB -s 512 ubi.cfg


然后启动系统,NFS、ramdisk或者安全文件系统都可以,并将得到的ubi.img放到系统可访问的目录或者介质中。在目标系统中运行下列命令,完成UBI镜像的烧写,然后重启系统即可:

flash_eraseall /dev/mtd4
ubiformat /dev/mtd4 -s 512 -f ubi.img


在主机上用到了一个ubi.cfg文件,如下:

$ cat ubi.cfg
[ubifs]
mode=ubi
image=rootfs.img
vol_id=1
vol_size=200MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize



阅读(1765) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~