UBI 文件系统移植 sys 设备信息【转】

简介: 转自:http://blog.chinaunix.net/uid-25304914-id-3058647.html cat /sys/class/misc/ubi_ctrl/dev -------------------------------------------- UBI: attac...
cat  /sys/class/misc/ ubi_ctrl/dev
--------------------------------------------
UBI: attaching mtd11 to ubi0
UBI: physical eraseblock size:   262144 bytes (256 KiB)
UBI: logical eraseblock size:    262144 bytes
UBI: smallest flash I/O unit:    4096
UBI: commit max data size:       258048 bytes
UBI: commit max no of records:   3739
UBI: default node Size:          4096 bytes
UBI: el record Size Per Pnum:    69 bytes
UBI: el pebs in one group:       58 
UBI: el group size:              4066 bytes
UBI: el number of groups:        142 bytes
UBI: el number of buds:          3
UBI warning: find_last_sb: bad block at 8191
UBI warning: find_last_sb: bad block at 8190
UBI error: verify_node: bad magic in node
UBI error: verify_node: bad magic in node
UBI error: ubi_get_sb: both super blocks are bad
UBI error: ubil_scan_init: could not get sb
 
---------------------------------------------------
#cat  /sys/class/ubi/ubi0/dev
252:0
===================================================
 
ubi and ubifs应用手记(2009-04-07 15:43:41)
标签: 杂谈 分类: linux

                                  ubi and ubifs应用手记

1.配置ubi and ubifs
in .config
  CONFIG_MTD_UBI=y
    CONFIG_UBIFS_FS=y
    CONFIG_CRYPTO_ALGAPI=y  CONFIG_CRYPTO_DEFLATE=y CONFIG_CRYPTO_LZO=y CONFIG_CRC16=y  CONFIG_LZO_COMPRESS=y CONFIG_LZO_DECOMPRESS=y
注意:如果配置成模块(=m),则可以手动加载   


2.manual attach/detach ubi to mtd
  ./ubiattach /dev/ubi_ctrl -m mtdnumber
  ./ubidetaach /dev/ubi_ctrl -m mtdnumber
 


3.manual create ubi volume
  ./ubimkvol /dev/ubi_device_number -s size -N name
  like:
  ./ubimkvol /dev/ubi0 -s 300MiB -N ubifs1

4.mount ubifs volume
  mount -t ubifs ubi0:ubifs1 /tmp/ubifs1
 


5.ubi node and ubi_ctrl node
#cat /sys/class/misc/ubi_ctrl/dev
10:63
加入/dev下没有ubi_ctrl,则我们可以sudo mknod ubi_ctrl c 10 63创建一个端点

#./ubiattach /dev/ubi_ctrl -m 6
#cat /sys/class/ubi/ubi0/dev
252:0
当我们attach ubi0 to mtd6后,如果/dev下没有ubi0,则创建一个,sudo mknod ubi0 c 252 0


6.我们可以手动create volume,然后手动mount ubifs,也可以在PC上创建ubi.img(创建好volume,volume写有数据)烧录进mtd device
How to generate ubi image and write to mtd device
  ./mkfs.ubifs -r a205_rootdisk -m 4096 -e 516096 -c 40 -o ubifs.img  
  ./ubinize -o ubi.img -m 4096 -p 512KiB  ubinize.cfg     
  ./ubiformat -q /dev/mtd5 -f ubi.img  
 
 
  -m minimum I/O unit size
  -e  maximum logical erase block count
  -c maximum logical erase block count
  -x compression type - "lzo", "favor_lzo", "zlib" or "none" (default: "lzo")
  -p size of the physical eraseblock of the flash this UBI image is created for in bytes,
 
注意:在PC上ubuntu使用mkfs.ubifs and ubinize,则我们要用普通的gcc来编译它们,同时在ubuntu上装上lzo库:sudo apt-get install liblzo2-dev
附录:
1).ubinize.cfg
[ubifs]
mode=ubi
image=ubifs.img
vol_id=0
vol_size=500MiB
vol_type=dynamic                     //if vol_type=static, then ubi volume is read only
vol_name=ubifs0
vol_flags=autoresize

这样这样当./ubiattach /dev/ubi_ctrl -m n后,就可以mount -t ubifs ubi0:ubifs0 /tmp


2)如果是想mount crafms image,只要
./ubinize -o ubi.img -m 4096 -p 512KiB  ubinize.cfg     
./ubiformat -q /dev/mtd5 -f ubi.img
ubinize.cfg
[ubifs]
mode=ubi
image=cramfs.img
vol_id=0
vol_size=500MiB
vol_type=dynamic                    
vol_name=cramfs
vol_flags=autoresize

这样当./ubiattach /dev/ubi_ctrl -m n后就可以从cat /proc/mtd中看到一个ubi volume仿真的mtd device,我们只要mount这个mtd设备对应的mtdblock就可以了(如mount -t cramfs /dev/mtdblock10 /tmp),注意,既然是烧录了cramfs到ubi volume,则我们只能以cramfs方式mount这个volume,不能再以ubifs方式(mount -t ubifs ubi0:cramfs /tmp)mount这个volume.但如果我们用./ubiupdate /dev/ubi0_0 -t wipe out擦干净这个volume后,我们是可以用ubifs方式mount这个volume,但mount起来这个volume,进入mount的目录,是什么内容也没有的。

3)三个volume的ubinize.cfg(注意[]中名字不能一样,vol_id不能一样,vol_name不能一样,另vol_flags=auto_resize只能使用在一个volume上)
[ubifs1]
mode=ubi
image=ubifs.img
vol_id=0
vol_size=20MiB
vol_type=dynamic
vol_name=ubifs0
vol_alignment=1


[cramfs1]
mode=ubi
image=smallroot.cramfs
vol_id=1
vol_size=20MiB
vol_type=dynamic
vol_name=cramfs
vol_alignment=1

[cramfs2]
mode=ubi
image=qtroot.cramfs
vol_id=2
vol_size=50MiB
vol_type=dynamic
vol_name=cramfs2
vol_alignment=1
vol_flags=autoresize

这样当使用./ubiformat写入ubi.img后,则./ubiattach后,我们可以知道多了三个假的mtd device.
第一个可以用mount -t ubifs ubi0:ubifs0 /tmp/ubifs1
第二个可以用mount -t cramfs /dev/mtdblockn /tmp/cramfs1
第二个可以用mount -t cramfs /dev/mtdblockm /tmp/cramfs2
 

7. How to disable compression?
UBIFS compression may be disabled for whole file system during the image creation time using the "-x none" mkfs.ubifs option. However, if UBIFS compression is enabled, it may be disabled for individual files by cleaning the inode compression flag:

$ chattr -c /mnt/ubifs/file
in shell, or


ioctl(fd, FS_IOC_GETFLAGS, &flags);

flags &= ~FS_COMPR_FL;

ioctl(fd, FS_IOC_SETFLAGS, &flags);
in C programs. Similarly, if compression is disabled by default, you may enable if for individual inodes by setting the compression flag. Note, the code which uses the compression flag works fine on other Linux file-systems, because the flag is just ignored in this case.

It might be a good idea to disable compression for say, mp3 or jpeg files which would anyway not compress and UBIFS would just waste CPU time trying to compress them. The compression may also be disabled if one wants faster file I/O, because UBIFS would not need to compress or decompress the data on reads and write. However, I/O speed may actually become slower if compression is disabled. Indeed, in case of a very fast CPU and very slow flash compressed writes are faster, but this is usually not true for embedded systems.


8.mount cramfs on ubi volume
  ubi volume is fake mtd device.
# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 180000 00080000 "Bootloader"
mtd1: 400000 00080000 "Kernel 0"
mtd2: 400000 00080000 "Kernel 1"
mtd3: 80000 00080000 "Boot up screen"
mtd4: a00000 00080000 "Rescue file system"
mtd5: 1400000 00080000 "Root file system"
mtd6: 3e800000 00080000 "Data area1"
mtd7: 3e800000 00080000 "Data area2"
mtd8: 6a400000 00080000 "Data area3"
mtd9: 16380000 00080000 "reserve"
 
 
#./ubiattach /dev/ubi_ctrl -m 6
#./ubimkvol /dev/ubi0 -s 300MiB -N ubifs1
# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 180000 00080000 "Bootloader"
mtd1: 400000 00080000 "Kernel 0"
mtd2: 400000 00080000 "Kernel 1"
mtd3: 80000 00080000 "Boot up screen"
mtd4: a00000 00080000 "Rescue file system"
mtd5: 1400000 00080000 "Root file system"
mtd6: 3e800000 00080000 "Data area1"
mtd7: 3e800000 00080000 "Data area2"
mtd8: 6a400000 00080000 "Data area3"
mtd9: 16380000 00080000 "reserve"
mtd10: 12c3c000 0007e000 "ubifs1"

# cp cramfs.img /dev/mtdblock10
# mount -t cramfs /dev/mtdblock6 /tmp

 

After create fake mtd device(ubi volume), mount jffs2
#mount -t jffs2 /dev/mtdblock10 /mnt

9.ubiupdatevol /dev/ubi0_0 -t   //wipe out volume
  ubiupdatevol /dev/ubi0_0 fs.img  //write image to volume
 
  ./ubiupdatevol /dev/ubi0_0 ubifs.img          //之后we can mount ubifs: mount -t ubifs ubi0:ubifs0 /tmp来挂载这个ubifs
  ./ubiupdatevol /dev/ubi0_1 smallroot.cramfs  //之后我们就可以mount -t cramfs /dev/mtdblockn /tmp来挂载这个cramfs
 

10.挂载vfat
1)制作vfat.img(在PC上制作)
$ dd if=/dev/zero of=vfat.img bs=1M count=20
#losetup /dev/loop0 vfat.img
#mkfs.vfat /dev/loop0
注意:这有一个warnning,但不用理会:Loop device does not match a floppy size, using default hd params
#mount -t vfat /dev/loop0 vfat_mount_point
往vfat_mount_point目录写东西,或copy东西到这目录
#umount vfat_mount_point
#losetup -d /dev/loop0

2)用ubinize打包成ubi.img,然后用ubiformat写入mtd devie。方法二是用ubiupdatevol先wipe out volume,然后用ubiupdatevol将vfat.img
写入volume.

但注意:因为emulate mtd device是不支持写操作的,所以我mount -t /dev/mtdblockn,这个mtdblockn是一个ubi volume emuluate的mtd device,
所以mount的vfat只可以读,写是无法保存的。(测试中写是能完成,ls也能看到,但sync后重启unit,重新mount可以看到写的数据是没有保存如vfat的)
 
 
11.ubifs(read/write/attach/mount)speed,
Wrtie speed -------------------speed=1.66M/s
# time dd if=/dev/zero of=/tmp/ubifs1/zero100M  bs=1M count=100;time sync
100+0 records in
100+0 records out
real    0m 59.13s
user    0m 0.00s
sys     0m 4.62s
real    0m 1.11s
user    0m 0.00s
sys     0m 0.74s

Read speed-----------------------speed=2.27M/s
# time cp ubifs1/zero100M /dev/null;time sync
s3c-nand: 1 bit(s) error detected, corrected successfully
s3c-nand: 1 bit(s) error detected, corrected successfully
s3c-nand: 1 bit(s) error detected, corrected successfully
real    0m 44.06s
user    0m 0.14s
sys     0m 42.67s
real    0m 0.06s
user    0m 0.00s
sys     0m 0.01s


12.配置ubifs as rootfs
in .config:
  CONFIG_CMDLINE="console=ttySAC0 ubi.mtd=5 root=ubi0:rootfs rootfstype=ubifs"
 
then if we had wrote root fs ubi image to mtd5, then we can boot up with ubi root fs.


13.遇到的rw filesystem change to read only filesystem
# ./ubiattach /dev/ubi_ctrl -m 6
UBI: attaching mtd6 to ubi0
UBI: physical eraseblock size:   524288 bytes (512 KiB)
UBI: logical eraseblock size:    516096 bytes
UBI: smallest flash I/O unit:    4096
UBI: VID header offset:          4096 (aligned 4096)
UBI: data offset:                8192
PEB 0 is bad
PEB 32 is bad
UBI: attached mtd6 to ubi0
UBI: MTD device name:            "Data area1"
UBI: MTD device size:            1000 MiB
UBI: number of good PEBs:        1998
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:     3
UBI: available PEBs:             0
UBI: total number of reserved PEBs: 1998
UBI: number of PEBs reserved for bad PEB handling: 19
UBI: max/mean erase counter: 7/0
UBI: background thread "ubi_bgt0d" started, PID 940

./ubiupdatevol /dev/ubi0_0 -t
UBI error: ubi_io_write: error -5 while writing 4096 bytes to PEB 21:4096, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write VID header to LEB 2147479551:0, PEB 21
UBI: try another PEB
UBI error: ubi_io_write: error -5 while writing 4096 bytes to PEB 12:4096, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write VID header to LEB 2147479551:0, PEB 12
UBI: try another PEB
UBI error: ubi_io_write: error -5 while writing 4096 bytes to PEB 1999:4096, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write VID header to LEB 2147479551:0, PEB 1999
UBI: try another PEB
UBI error: ubi_io_write: error -5 while writing 24576 bytes to PEB 1998:8192, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write 24576 bytes at offset 0 of LEB 2147479551:0, PEB 1998
UBI warning: ubi_ro_mode: switch to read-only mode
UBI error: ubi_io_write: read-only mode
UBI error: erase_worker: failed to erase PEB 7, error -30
UBI error: do_work: work failed with error code -30
UBI error: ubi_thread: ubi_bgt0d: work failed with error code -30
ubiupdatevol: error!: cannot truncate volume "/dev/ubi0_0"
              error 30 (Read-only file system)
UBI warning: vol_cdev_release: update of volume 0 not finished, volume is damaged

遇到此问题后,再flash_eraseall /dev/mt6或/dev/mtd7后,再写image to /dev/mtd7 or /dev/mtd6都出错
./ubiformat -q /dev/mtd6 -f ubi.img.20M_none
libmtd: error!: cannot write 32768 bytes to mtd6 (eraseblock 1, offset 0)
        error 5 (Input/output error)
ubiformat: error!: cannot write eraseblock 1
           error 5 (Input/output error)
          
遇到此问题后,我在uboot下执行
NAND erase: device 0 offset 0x600000, size 0x400000
ret:0 erase.addr:600000
Erasing at 0x600000 --  12% complete.ret:0 erase.addr:680000
Erasing at 0x680000 --  25% complete.ret:0 erase.addr:700000
Erasing at 0x700000 --  37% complete.ret:0 erase.addr:780000
Erasing at 0x780000 --  50% complete.ret:0 erase.addr:800000
Erasing at 0x800000 --  62% complete.ret:0 erase.addr:880000
Erasing at 0x880000 --  75% complete.ret:0 erase.addr:900000
Erasing at 0x900000 --  87% complete.ret:0 erase.addr:980000
Erasing at 0x980000 -- 100% complete.
OK
SMDK2450 # nand write c0000000 600000 300000

NAND write: device 0 offset 0x600000, size 0x300000
 0 bytes written: ERROR
 
 
 最后,我重新用笔尖fine tine nand flash的引脚(特别是/WE),终于救回了这片flash
 
 
 结论:好像是此flash已经损坏,或者是引脚接触不好----因为erase是ok的,而且nand read读也是ok的,导致无法写入PEB,会使得
 UBIFS变为只读。
 
 
 
14.mkfs.ubifs -c issus  (注意 fat directory is empty)
dannylo@fs1:~/cram2fs_tools$ ./mkfs.ubifs -r fat  -m 4096 -e 516096 -c 10 -o test.img
Error: too low max. count of LEBs, minimum is 17
dannylo@fs1:~/cram2fs_tools$ ./mkfs.ubifs -r fat  -m 4096 -e 516096 -c 19 -o test.img
Error: too many log LEBs, maximum is 2
dannylo@fs1:~/cram2fs_tools$ ./mkfs.ubifs -r fat  -m 4096 -e 516096 -c 21 -o test.img
Error: too many log LEBs, maximum is 4
dannylo@fs1:~/cram2fs_tools$ ./mkfs.ubifs -r fat  -m 4096 -e 516096 -c 22 -o test.img

结论:即最小的ubifs.img为11M.注意对要烧录进volume的cramfs or cram2fs format的image的size好像没有要求。

 

15.ubi face bad block
我们在uboot中用nand markbad 试过mark bad block(一块在mtd device的首块,一块在中间,一块在最后),测试表面ubi在attach时的scan能认出
bad block nand skip bad block.同时用ubiformat烧写ubi.img时也会自动跳过bad block.

 

 

 
 

 
 
 
内核配置 添加支持
 

自从linux2.6.27以后的内核版本都支持UBI文件系统了,新版本的uboot已经支持UBIFS了。

 

 

关于uboot的移植(移植指的是 本身已经支持UBIFS的uboot的,针对具体板卡的移植)可以参考 嵌入式Linux之我行 uboot的移植,那里写得比较详细。我也是参考了其中的文章

 

1、  ubootUBI的移植

关于ubootUBI的移植几乎没有说明介绍,

移植首先要保证你的flash驱动能够跑起来,我是在nand flash 上跑的UBI

刚开始的时候我也没有什么头绪,只能够从ubootreadme开始查找一些蛛丝马迹。

 

- MTD Support (mtdparts command, UBI support)

              CONFIG_MTD_DEVICE

 

              Adds the MTD device infrastructure from the Linux kernel.

              Needed for mtdparts command support.

 

              CONFIG_MTD_PARTITIONS

 

              Adds the MTD partitioning infrastructure from the Linux

              kernel. Needed for UBI support.

 

因此呢,要UBI支持首先得要MTD支持,因此在配置文件中要添加以上两项的定义。

要移植UBI还要添加:

#define CONFIG_CMD_UBIFS           

#define CONFIG_CMD_UBI         

 

总的关于UBI的部分是以下几个宏

/****MTD Support (mtdparts command, UBI support)****/

#if 1

#define CONFIG_MTD_DEVICE          1

#define CONFIG_MTD_PARTITIONS        1

#define CONFIG_CMD_MTDPARTS         

#define CONFIG_CMD_UBIFS           

#define CONFIG_CMD_UBI         

#define CONFIG_LZO                    1

#define CONFIG_RBTREE                    1

#endif

 

同时呢要给NAND建立个默认的分区。方便以后操作。我的分区如下:

 

#define MTDIDS_DEFAULT                  "nand0=nandflash0"

 

 

#define MTDPARTS_DEFAULT            "mtdparts=nandflash0:320k@0(uboot)," \

                                   "64k(params)," \

                                   "2m(kernel)," \

                                   "-(root)"

 

需要注意的是增加UBI的支持之后uboot会增大到260KB,在NAND中启动,需要修改

 

 

//copy U-Boot to RAM

ldr r0, =TEXT_BASE  //传递给C代码的第一个参数:u-boot在RAM中的起始地址

mov r1, #0x0         //传递给C代码的第二个参数:Nand Flash的起始地址

mov r2, #0x50000    //传递给C代码的第三个参数:u-boot的长度大小(320KB)

bl nand_read_ll    //此处调用C代码中读Nand的函数,现在还没有要自己编写实现

 

如果uboot传给nand_read_ll uboot的参数小于uboot的长度的话,uboot跑不起来,移植的时候被这个问题搞得很郁闷。

另外还有一个地方就是编译的时要求CONFIG_SYS_MALLOC_LEN大于等于512KB,下面两个没有要求我也给改了。

#define CONFIG_SYS_MALLOC_LEN             (CONFIG_ENV_SIZE+  512*1024)

#define CONFIG_SYS_GBL_DATA_SIZE   512 /* size in bytes reserved for initial data */

#define CONFIG_STACKSIZE      (512*1024)   /* regular stack */

如果没改的话会报错。

 

 

这个时候就可以make 了,如果顺利的话会编译出uboot-bin在根目录下。

再通过友善提供的vivi  a命令下载到nand 中,启动如下:

 

U-Boot 2010.06-rc1 (Jul 15 2010 - 16:48:33)

DRAM:  64 MiB

Flash: 2 MiB

NAND:  64 MiB

*** Warning - bad CRC or NAND, using default environment

In:    serial

Out:   serial

 

Err:   serial

Net:   dm9000

Hit any key to stop autoboot:  0

相关的ubi命令如下:

 

...

到这里ubootUBI移植完成了。

 

2. 第二步是内核对UBI的支持

linux-2.6.30.4的内核已经包含UBI

   1)Device Drivers  --->Memory Technology Device (MTD) support  --->UBI - Unsorted block images  --->Enable UBI

   2)File systems  --->Miscellaneous filesystems  --->UBIFS file system support

这样我们的内核就支持UBIFS文件系统了

 

 

3. UBIFS工具的编译

 

我是将ubifs直接作为根文件系统挂载的,需要mkfs.ubifs这个工具我是从git直接下载的最新版的mtd-utils,同时编译mtd-utils还需要两个库。

lzo-2.03,zlib-1.2.3 下载完之后就直接按照默认的方式make。

注意:我们是在x86平台上将rootfs文件系统打包成UBIFS格式的因此呢不能够修改编译工具。

最后在mkfs.ubifs目录下生产mkfs.ubifs。

mkfs.ubifs的使用相关参数,照着它的Examples使用就可以了,具体参数的设置可以查看u-boot ubi分区时候所打印出来的参数。

Usage: mkfs.ubifs [OPTIONS] target

Make a UBIFS file system image from an existing directory tree

 

Examples:

Build file system from directory /opt/img, writting the result in the ubifs.img file

       mkfs.ubifs -m 512 -e 128KiB -c 100 -r /opt/img ubifs.img

The same, but writting directly to an UBI volume

       mkfs.ubifs -r /opt/img /dev/ubi0_0

Creating an empty UBIFS filesystem on an UBI volume

       mkfs.ubifs /dev/ubi0_0

rootfs打包成镜像:

./mtd-utils/mkfs.ubifs/mkfs.ubifs -m 512 -e 15872 -c 3944-r rootfs -o ubifs.img

 

 

Uboot传给内核的启动参数

#define CONFIG_BOOTARGS                   

"ubi.mtd=3 root=ubi0:rootfs rootfstype=ubifs console=ttySAC0 init=/linuxrc rw"

注意:因为还没找到原因挂载之后文件系统是只读的,所以就加了个rw,有人解决之后请联系我,不胜感激。

内核的默认启动参数和uboot传过来的是一样的。

 

4UBI的使用

 

1内核的烧写

 

tftp 0x32000000 zImage 将内核通过tftp下载到内存中

nand erase 0x60000 0x200000

nand write 0x32000000 0x60000 0x200000

 

文件系统的烧写

 

使用默认的分区对nand进行分区:mtdpart default

 

... 

1)擦除root分区 nand erase root

 

2)对root分区进行ubi格式化 ubi part root

 

Creating 1 MTD partitions on "nand0":

 

0x26000033fc64f4-0x400000000000000 : ""

 

UBI: attaching mtd1 to ubi0

 

UBI: physical eraseblock size:   16384 bytes (16 KiB)

 

UBI: logical eraseblock size:    15872 bytes

 

UBI: smallest flash I/O unit:    512

 

UBI: sub-page size:              256

 

UBI: VID header offset:          256 (aligned 256)

 

UBI: data offset:                512

 

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=3"

 

UBI: MTD device size:            261993005056 MiB

 

UBI: number of good PEBs:        3944

 

UBI: number of bad PEBs:         0

 

UBI: max. allowed volumes:       92

 

UBI: wear-leveling threshold:    4096

 

UBI: number of internal volumes: 1

 

UBI: number of user volumes:     0

 

UBI: available PEBs:             3901

 

UBI: total number of reserved PEBs: 43

 

UBI: number of PEBs reserved for bad PEB handling: 39

 

UBI: max/mean erase counter: 1/0

 

3)创建rootfs    YH2440 # ubi create rootfs

 

 

YH2440 # ubi create rootfs

 

Creating dynamic volume rootfs of size 61916672

 

4)将文件系统下载到内存 tftp 0x32000000 ubifs.img

 

YH2440 # tftp ubifs.img

 

dm9000 i/o: 0x20000300, id: 0x90000a46

 

DM9000: running in 16 bit mode

 

MAC: 08:00:3e:26:0a:5b

 

could not establish link

 

Using dm9000 device

 

TFTP from server 192.168.1.80; our IP address is 192.168.1.252

 

Filename 'ubifs.img'.

 

Load address: 0x32000000

 

Loading: #################################################################

 

        #################################################################

 

        #################################################################

 

        ####################################

 

done

 

Bytes transferred = 3380736 (339600 hex)

 

5)将文件系统烧写到rootfs YH2440 # ubi write 0x32000000 rootfs 0x339600

 

YH2440 # ubi write 0x32000000 rootfs 0x339600

 

Volume "rootfs" found at volume id 0

 

之后启动就可以看到UBIFS可以运行了。

YH2440 # boot

 

 

NAND read: device 0 offset 0x60000, size 0x200000

 

 2097152 bytes read: OK

 

## Starting application at 0x32000000 ...

 

Uncompressing Linux............................................................................................................................... done, booting the kernel.

Linux version 2.6.30.4 (root@luoxiaotan.org) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #11 Wed Jul 14 16:24:33 CST 2010

CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177

CPU: VIVT data cache, VIVT instruction cache

Machine: S3C2440

Warning: bad configuration page, trying to continue

Memory policy: ECC disabled, Data cache writeback

CPU S3C2440A (id 0x32440001)

S3C24XX Clocks, (c) 2004 Simtec Electronics

S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz

CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on

Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 4064

Kernel command line: ubi.mtd=3 root=ubi0:rootfs rootfstype=ubifs console=ttySAC0 init=/linuxrc rw

NR_IRQS:85

irq: clearing subpending status 00000003

irq: clearing subpending status 00000002

PID hash table entries: 64 (order: 6, 256 bytes)

Console: colour dummy device 80x30

console [ttySAC0] enabled

Dentry cache hash table entries: 2048 (order: 1, 8192 bytes)

Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)

Memory: 16MB = 16MB total

Memory: 12076KB available (3UBIFS: mounted UBI device 0, volume 0, name "rootfs"

UBIFS: file system size:   61456384 bytes (60016 KiB, 58 MiB, 3872 LEBs)

UBIFS: journal size:       8110592 bytes (7920 KiB, 7 MiB, 511 LEBs)

UBIFS: media format:       w4/r0 (latest is w4/r0)

UBIFS: default compressor: lzo

UBIFS: reserved for root:  0 bytes (0 KiB)

VFS: Mounted root (ubifs filesystem) on device 253:1.

Freeing init memory: 120K

 

Please press Enter to activate this console.

 

 

BusyBox v1.13.3 (2010-07-13 08:51:35 CST) built-in shell (ash)

Enter 'help' for a list of built-in commands

 

 

===============================================================================

 

http://blog.csdn.net/ShowMan/archive/2010/03/17/5390868.aspx

 

2、ubifs
2.1、什么是ubifs?
由IBM、nokia工程师Thomas Gleixner,Artem Bityutskiy等人于2006年发起,致力于开发性能卓越、扩展性高的FLASH专用文件系统,以解决当前嵌入式环境下以FLASH作为MTD设备使用时的技术瓶颈。
关键字:
UBI:一种类似于LVM的 逻辑卷管理层。主要实现损益均衡,逻辑擦除块、卷管理,坏块管理等。
UBIFS:基于UBI的 FLASH日志文件系统
有关ubifs的详细介绍,请参考:
http://www.linux-mtd.infradead.org/doc/ubi.html
http://www.linux-mtd.infradead.org/doc/ubifs.html

2.2、如何得到ubifs?
2.6.22以后,ubifs活跃于git管理工程中:
git://git.infradead.org/ubi-2.6.git
2.6.27以后,ubifs 被整合进内核树中,用户只需下载最新内核即可获取ubifs支持。

2.3、如何使用ubifs?
软件环境:
linux-2.6.28
arm-linux-gcc 3.4.5
硬件环境:
s3c2410
k9f1208

2.4、准备
1、内核
配置的时候选上
1)Device Drivers  --->Memory Technology Device (MTD) support  --->UBI - Unsorted block images  --->Enable UBI
2)File systems  --->Miscellaneous filesystems  --->UBIFS file system support

2、mtd-utils工具(flash_eraseall、ubiattach、ubimkvol)准备
1)下载(mtd-utils、 zlib、lzo)源码
wget http://debian.mirror.inra.fr/debian/pool/main/m/mtd-utils/mtd-utils_20080508.orig.tar.gz
wget http://www.zlib.net/zlib-1.2.3.tar.gz
wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.03.tar.gz

2)编译安装zlib
tar xzvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
CC=arm-linux-gcc ./configure --shared --prefix=/usr/local/arm/3.4.5/arm-linux
make
make install
cd ..

3)编译安装lzo
tar xzvf lzo-2.03.tar.gz
cd lzo-2.03
CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/usr/local/arm/3.4.5/arm-linux
make
make install
cd ..

4)编译mtd-utils
tar xzvf mtd-utils_20080508.orig.tar.gz
cd mtd-utils-20080508

修改Makefile文件:
#CROSS=arm-linux-
修改为  CROSS=arm-linux-
BUILDDIR := $(CROSS:-=)
修改为  BUILDDIR := .

修改ubi-utils/Makefile文件:
添加    CROSS=arm-linux-

修改    ubi-utils/new-utils/Makefile文件:
添加    CROSS=arm-linux-

make WITHOUT_XATTR=1

ubi-utils子目录下生成我们需要的ubiattach、ubimkvol等文件(请确保是交叉编译所得)

3、mtd-utils工具(mkfs.ubifs、ubinize)准备
git-clone git://git.infradead.org/mtd-utils.git
cd mtd-utils/
make

mkfs.ubifs子目录下生成我们需要的mkfs.ubifs工具
ubi-utils/new-utils子目录下生成我们需要的ubinize工具


2.5、使用
1、使用ramfs或nfs启动系统,执行以下命令挂载ubifs:
1)flash_eraseall /dev/mtd4
2)ubiattach /dev/ubi_ctrl -m 4
3)ubimkvol /dev/ubi0 -N rootfs -s 50MiB
4)mount -t ubifs ubi0_0 /mnt或mount -t ubifs ubi0:rootfs /mnt

2、如果你想使用ubifs为rootfs,把文件系统内容解压到ubifs挂载目录下,并修改内核启动参数为:
console=ttySAC0 ubi.mtd=4 root=ubi0:rootfs rootfstype=ubifs

3、如果你想直接在bootloader下烧写ubifs映像,使用以下命令制作ubi烧写映像:
mkfs.ubifs -r rootfs -m 512 -e 15872 -c 3303 -o ubifs.img
ubinize -o ubi.img -m 512 -p 16KiB -s 256 ubinize.cfg

其中:
1)以上命令的参数可从ubifs挂载信息中提取:
UBI: attaching mtd4 to ubi0                                                     
UBI: physical eraseblock size:   16384 bytes (16 KiB)                           
UBI: logical eraseblock size:    15872 bytes                                    
UBI: smallest flash I/O unit:    512                                            
UBI: sub-page size:              256                                            
UBI: VID header offset:          256 (aligned 256)                              
UBI: data offset:                512                                            
UBI: attached mtd4 to ubi0              

2)配置文件ubinize.cfg的内容为:
[ubifs]
mode=ubi
image=ubifs.img
vol_id=0
vol_size=50MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize

 

【作者】 张昺华
【新浪微博】 张昺华--sky
【twitter】 @sky2030_
【facebook】 张昺华 zhangbinghua
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
目录
相关文章
|
3月前
|
存储 Linux Shell
Linux内核追踪(一):proc/sys/debugfs
Linux内核追踪(一):proc/sys/debugfs
59 0
|
12月前
|
Linux
Linux读取设备信息代码编写
Linux读取设备信息代码编写
84 0
uboot引导vxworks--t2080调试记录
uboot引导vxworks--t2080调试记录
372 0
uboot引导vxworks--t2080调试记录
SPI设备标准驱动源码分析(linux kernel 5.18)
SPI设备标准驱动源码分析(linux kernel 5.18)
SPI设备标准驱动源码分析(linux kernel 5.18)
|
算法 数据安全/隐私保护 Android开发
【Android 逆向】Android 系统文件分析 ( cmdline 系统启动参数文件 | crypto 密码算法信息文件 | devices 设备信息文件 )
【Android 逆向】Android 系统文件分析 ( cmdline 系统启动参数文件 | crypto 密码算法信息文件 | devices 设备信息文件 )
594 0
【Android 逆向】Android 系统文件分析 ( cmdline 系统启动参数文件 | crypto 密码算法信息文件 | devices 设备信息文件 )
|
机器学习/深度学习 Linux
linux 高级字符设备驱动 ioctl操作介绍 例程分析实现【转】
转自:http://my.oschina.net/u/274829/blog/285014 1,ioctl介绍 ioctl控制设备读写数据以及关闭等。 用户空间函数原型:int ioctl(int fd,unsinged long cmd,...)   fd-文件描述符 cmd-对设备的发出的控制命令 ...表示这是一个可选的参数,存在与否依赖于cmd,如cmd为修改波特率,那么....就表示波特率的值。
1251 0
|
Linux 虚拟化
浅入分析和Linux内核相关的文件夹/proc和/sys .
近来文章被踩的厉害,我只想把自己从马哥学的知识自己总结下发到博客里,但是没想到昨天一篇文章刚发一上午被踩了9次。。。如果您真的觉得我的文章很烂,请告诉我原因,不胜感激。   这星期,马哥讲了关于Linux内核的编译和Linux的内核模块,浅显易懂,所以写出来和大家一起分享学习成果。
933 0