使用ubifs格式的根文件系統


  • 配置內核,使其支持ubifs文件系統

    1)Device Drivers  --->Memory Technology Device (MTD) support  --->UBI - Unsorted block images  --->Enable UBI     2)File systems  --->Miscellaneous filesystems  --->UBIFS file system support

  • 制作ubifs格式的根文件系統鏡像

先說明一下,板子上既有NorFlash,又有NandFlash,其中根文件系統和應用程序放在NandFlash上,uboot和kernel放在NorFlash上,而根文件系統所在的mtd設備為mtd2,分區大小為34MiB

uboot kernel rootfs=34MiB app

 

  • ./mkfs.ubifs -v -r ./rootfs -o rootfs.img -m 2048 -e 129024 -c 272

   -r:制定文件內容的位置      -m:頁面大小      -e:邏輯擦除塊大小      -c:最大的邏輯擦除塊數量

 

mkfs.ubifs -m 2048 -e 129024 -c 1984 -o rootfs.ubifs -x none

-m 2048   (Minimum input/output unit size: 2048 bytes)
-e 129024 (Default UBI LEB size:           129024 bytes, 126.0 KiB)
-c 1984   (Amount of eraseblocks:          1984 (260046848 bytes, 248.0 MiB))
-o rootfs.ubifs (output file)
-x none   (no compression)

 

 

  • ./ubinize -v -o rootfs.ubi -m 2048 -p 128KiB -s 2048 hi.cfg

     -p:物理擦除塊大小 

     -m:頁面大小

      -s: 最小的硬件輸入輸出頁面大小,如:k9f1208為256(上下半頁訪問)

配置文件hi.cfg如下:

 

[ubifs] mode=ubi image=rootfs.img vol_id=0 vol_size=34MiB vol_type=dynamic vol_alignment=1 vol_name=rootfs vol_flag=autoresize

 

 然后修改uboot的環境變量:

setenv bootargs 'mem=288M console=ttyAMA0,115200 root=ubi0:rootfs rw rootflags=sync rootfstype=ubifs ubi.mtd=2 mtdparts=hi_sfc:5M(boot),1M(picture);hinand:34M(rootfs),8M(config),86M(app)';

保存環境變量,執行如下命令

 

setenv ipaddr 192.168.253.132;

setenv serverip 192.168.253.130;

setenv ethaddr 40:61:86:67:33:47;

mw.b 82000000 ff 2200000;

tftp 82000000 rootfs.ubi;

nand erase 0 2200000;

nand write 82000000 0 $(filesize);

sf probe 0;

sf read 0x82000000 0x100000 0x400000;

bootm 0x82000000

 

說明:

其實從上面的燒寫命令可以看出,ubifs格式的鏡像中是不包含oob信息的。 

參見:http://www.cnblogs.com/pengdonglin137/p/3399071.html

 

出現如下錯誤信息:

 

UBI: attaching mtd2 to ubi0 UBI: physical eraseblock size: 131072 bytes (128 KiB) UBI: logical eraseblock size: 126976 bytes UBI: smallest flash I/O unit: 2048 UBI: VID header offset: 2048 (aligned 2048) UBI: data offset: 4096 UBI: max. sequence number: 0 UBI error: vtbl_check: volume table check failed: record 0, error 9 UBI error: ubi_init: cannot attach mtd2 Fixed MDIO Bus: probed

 

原因:

參考     http://wiki.linpert.de/index.php?title=UBIFS#record_0.2C_error_9  

             http://lists.infradead.org/pipermail/linux-mtd/2009-April/025127.html

 

But I took a look into the code, and the following is error 9:

                if (reserved_pebs > ubi->good_peb_count) {
                        dbg_err("too large reserved_pebs %d, good PEBs %d",
                                reserved_pebs, ubi->good_peb_count);
                        err = 9;
                        goto bad;
                }

This means you created a too large UBI volume in the image,
and your real flash is smaller.

Try to enable UBI debugging, and type dmesg, then you'll see
reserved and real eraseblock numbers.

原因就是:在配置文件中,volume設為34MiB,太大了,因為整個mtd2分區總共才34MiB。

解決辦法:將配置文件改為:

[ubifs] mode=ubi image=rootfs.img vol_id=0 vol_size=32MiB vol_type=dynamic vol_alignment=1 vol_name=rootfs vol_flag=autoresize

說明:

vol_id  表示volume的編號,一個ubi設備中可以有多個volume。(這種情況下,/dev下會出現 ubi0 和 ubi0_0)

vol_size 表示ubi0_0的大小,即volume0的大小

vol_type 表示volume0的類型,分為dynamic和static兩種,其中dynamic類型的設備表示可以讀寫,static類型的設備表示只讀

vol_name 表示volume0的名稱,在掛載ubi分區是會使用到,如在bootargs中的root=ubi0:rootfs

然后重新執行:   ./ubinize -v -o rootfs.ubi -m 2048 -p 128KiB -s 2048 hi.cfg

 

當再次重啟后,又出現如下錯誤信息:

 

UBIFS: parse sync UBIFS error (pid 1): validate_sb: LEB size mismatch: 129024 in superblock, 126976 real UBIFS error (pid 1): validate_sb: bad superblock, error 1

 

原因:

參考:http://www.linux-mtd.infradead.org/faq/ubifs.html#L_lebsz_mismatch

 

I see this UBIFS error: "validate_sb: LEB size mismatch: 129024 in superblock, 126976 real"

 

When you create an UBIFS image using the mkfs.ubifs utility, you specify LEB size using the -e option. This is a very important parameter and you should specify it correctly in order to have working UBIFS image. Indeed, LEB size is the major UBIFS storage unit, e.g., UBIFS nodes never cross LEB boundaries, garbage collection is performed on individual LEBs, etc. See this section for more information.

 

The error message means that LEB size information which is stored in the UBIFS superblock does not match the real LEB size, which UBIFS takes from UBI. The superblock was created by the mkfs.ubifs utility, therefore you failed to pass the correct LEB size to the utility. Fix this by passing correct LEB size via the -e option.

 

原因是:邏輯塊的大小與實際的大小不符

解決辦法:

將-e選項的值由129024改成126976

重新執行:

 ./mkfs.ubifs -v -r ./rootfs -o rootfs.img -m 2048 -e 126976 -c 272

 ./ubinize -v -o rootfs.ubi -m 2048 -p 128KiB -s 2048 hi.cfg

重新燒寫並重啟。

還有一個需要注意的問題是,如果將-s選項的值搞錯,如將2048寫成了512,那么會有如下錯誤信息

UBI error: validate_ec_hdr: bad VID header offset 512, expected 2048 UBI error: validate_ec_hdr: bad EC header UBI error: ubi_io_read_ec_hdr: validation failed for PEB 0 UBI error: ubi_init: cannot attach mtd2 Fixed MDIO Bus: probed

從錯誤提示中就可以看到解決方法:將-s選項的值改為2048即可。

參考:http://www.cnblogs.com/pengdonglin137/p/3404685.html

 UBI headers

UBI stores 2 small 64-byte headers at the beginning of each non-bad physical eraseblock:

  • erase counter header (or EC header) which contains the erase counter of the physical eraseblock (PEB) plus some other not so important information;
  • volume identifier header (or VID header) which stores volume ID and logical eraseblock (LEB) number this PEB belongs to (plus some other not so important information).

This is why logical eraseblocks are smaller than physical eraseblock - the headers take some flash space.

 

UBI headers position

The EC header always resides at offset 0 and takes 64 bytes, the VID header resides at the next available min. I/O unit or sub-page, and also takes 64 bytes. For example:

  • in case of NOR flash which has 1 byte min. I/O unit, the VID header resides at offset 64;
  • in case of NAND flash which does not have sub-pages, the VID header resides at the second NAND page;
  • in case of NAND flash which has sub-pages, the VID header resides at the second sub-page.

 

UBI utilizes sub-pages to lessen flash space overhead. The overhead is less if NAND flash supports sub-pages (see here). Indeed, let's consider a NAND flash with 128KiB eraseblocks and 2048-byte pages. If it does not have sub-pages, UBI puts the the VID header at physical offset 2048, so LEB size becomes 124KiB (128KiB minus one NAND page which stores the EC header and minus another NAND page which stores the VID header. In opposite, if the NAND flash does have sub-pages, UBI puts the VID header at physical offset 512 (the second sub-page), so LEB size becomes 126KiB (128KiB minus one NAND page which is used for storing both UBI headers). See this section for more information about where the UBI headers are stored.

 

也就是說,對於上面的例子,如果有subpage(可以到/sys/class/mtd/其中的一個目錄下使用cat命令去查看某個mtd設備的subpagesize參數),如果是512B,這有如下參數搭配(對於塊大小是128KiB,頁大小是2KB的NandFlash來說):

 ./mkfs.ubifs -v -r ./rootfs -o rootfs.img -m 2048 -e 129024 -c 272 

 ./ubinize -v -o rootfs.ubi -m 2048 -p 128KiB -s 512 hi.cfg

 

 其中 -e表示的是邏輯塊的大小,因為subpagesize大小是512(也就是-s選項的值),第一頁的前512存放EC(實際用了前64B),接下來的512B(前64B)存放UBI headers,邏輯塊的大小就是128KiB-2KiB=126KiB,轉化成十進制就是129024。

 假如沒有subpagesize,那么有如下搭配:

 ./mkfs.ubifs -v -r ./rootfs -o rootfs.img -m 2048 -e 126976 -c 272 

 ./ubinize -v -o rootfs.ubi -m 2048 -p 128KiB -s 2048 hi.cfg

 其中,邏輯塊的大小:128KiB-2KiB-2KiB=124KiB,轉換成10進制就是126976,-s后面的值為頁大小,即2048B。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM