1. 程式人生 > >ubi檔案系統製作指令分析

ubi檔案系統製作指令分析

介紹UBIFS檔案系統,鄙人已經親身製作並使用的ti DM3730 linux平臺上。ubifs檔案系統掛載速度相對快,相比其他型別檔案系統,綜合性能狠強啊,不過鄙人實踐及官方也坦白一個事實,就是ubifs檔案系統對系統異常/突然掉電的容忍性不好,資料可能會嚴重損壞。

----------------------------

NAND flash sub-pages

前面提到所有的寫操作都需要對齊,對於NAND則是針對page大小,雖然有些SLC的flash允許更小的單位,在MTD這一層我們稱之為sub-pages,並不是所有的NAND都有sub-pages

  • MLC NANDs do not have sub-pages, at least to the date of writing of this piece of documentation (April 2009).
  • SLC NANDs usually do have sub-pages. E.g., 512-byte NAND pages usually consist of 2x256-byte sub-pages, and 2048-byte NAND pages consist of 4x512-byte sub-pages.
  • SLC OneNAND chips with 2048 bytes NAND page size have 4x512-byte sub-pages.

比如,對於128KiB的block大小,2048-byte page的flash,如果沒有sub-pages,EC header 存於第一個page,VID header儲存於2048偏移處,LEB大小為128KiB-2048-2048=124KiB。如果有sub-pages,那麼EC header儲存於第一個sub-page,VID header儲存於512偏移處(第二個sub-page),LEB大小變為128KiB-2048=126KiB

  • 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.

Sub-pages只是UBI內部用於儲存頭資訊,UBI的API不允許使用者訪問sub-pages,因為為了寫一個sub-page的資料,驅動需要對整個page做寫操作,比如寫4個sub-page的時間會4倍於一個page的時間。

----------------------------

UBIFS

UBIFS may be considered as the next generation of the JFFS2 file-system.

JFFS2 file system works on top of MTD devices, but UBIFS works on top of UBI volumes and cannot operate on top of MTD devices. In other words, there are 3 subsystems involved:

  • MTD subsystem, which provides uniform interface to access flash chips. MTD provides an notion of MTD devices (e.g., /dev/mtd0) which basically represents raw flash;
  • UBI subsystem, which is a wear-leveling and volume management system for flash devices; UBI works on top of MTD devices and provides a notion of UBI volumes; UBI volumes are higher level entities than MTD devices and they are devoid of many unpleasant issues MTD devices have (e.g., wearing and bad blocks); see here for more information;
  • UBIFS file system, which works on top of UBI volumes.

For more information on MTD, refer <<A class="external free" href="http://www.linux-mtd.infradead.org/doc/general.html" rel=nofollow target=_blank>http://www.linux-mtd.infradead.org/doc/general.html>

For more information on UBI, refer <<A class="external free" href="http://www.linux-mtd.infradead.org/doc/ubi.html" rel=nofollow target=_blank>http://www.linux-mtd.infradead.org/doc/ubi.html>

For more information on UBIFS, refer <<A class="external free" href="http://www.linux-mtd.infradead.org/doc/ubifs.html" rel=nofollow target=_blank>http://www.linux-mtd.infradead.org/doc/ubifs.html>

UBIFS User-space tools

UBI user-space tools, as well as other MTD user-space tools, are available from the the following git repository: git://git.infradead.org/mtd-utils.git

The repository contains the following UBI tools:

ubinfo - provides information about UBI devices and volumes found in the system; ubiattach - attaches MTD devices (which describe raw flash) to UBI and creates corresponding UBI devices; ubidetach - detaches MTD devices from UBI devices (the opposite to what ubiattach does); ubimkvol - creates UBI volumes on UBI devices; ubirmvol - removes UBI volumes from UBI devices; ubiupdatevol - updates UBI volumes; this tool uses the UBI volume update feature which leaves the volume in "corrupted" state if the update was interrupted; additionally, this tool may be used to wipe out UBI volumes; ubicrc32 - calculates CRC-32 checksum of a file with the same initial seed as UBI would use; ubinize - generates UBI images; ubiformat - formats empty flash, erases flash and preserves erase counters, flashes UBI images to MTD devices; mtdinfo - reports information about MTD devices found in the system.

All UBI tools support "-h" option and print sufficient usage information.

UBIFS Implementation Details

  • The UBIFS file system is supported with 8-bit BCH ECC scheme by default. The 8-bit BCH ECC scheme is aligned across ROM, U-boot and Kernel.
  • Both UBIFS and 8-bit BCH scheme are enabled in the Uboot and Kernel by default.

Configuration

Note: The following configuration is enabled in the kernel by default.

To enable UBIFS support, start the Linux Kernel Configuration tool:

$ make menuconfig

(1)

  • Select Device Drivers from the main menu.
... ... Power management options ---> [ ] Networking support ---> Device Drivers ---> ...


Select Memory Technology Device (MTD) Supportas shown here:

... ... < > Connector - unified userspace <-> kernelspace linker ---> <*> Memory Technology Device (MTD) support ---> < > Parallel port support ---> ...


Select Enable UBI - Unsorted block images as shown here:

... <*> Enable UBI - Unsorted block images --->


(2)

  • Select Device Drivers from the main menu.
... ... Power management options ---> [ ] Networking support ---> Device Drivers ---> ...


Select Memory Technology Device (MTD) Supportas shown here:

... ... < > Connector - unified userspace <-> kernelspace linker ---> <*> Memory Technology Device (MTD) support ---> < > Parallel port support ---> ...


Select NAND Device Support as shown here:

... ... [ ] NAND ECC Smart Media byte order <*> NAND Device Support ---> ...

Deselect Verify NAND page writes from the main menu.

[ ] Verify NAND page writes ... ...

(3)

  • Select File Systems from the main menu.
... ... Device Drivers ---> File systems ---> ...


Select Miscellaneous filesystemsas shown here:

... ... Pseudo filesystems ---> [*] Miscellaneous filesystems ---> [*] Network File Systems ---> ...


Select UBIFS file system supportas shown here:

... ... <*> UBIFS file system support [ ] Extended attributes support [ ] Advanced compression options [ ] Enable debugging support ...

Compilling UBIFS Tools

The MTD and UBI user-space tools are available from the the following git repository:

git://git.infradead.org/mtd-utils.git

As of writing this wiki, the mtd-utils version is 1.4.8.

For instructions on compiling MTD-utils, refer MTD-Utils Compilation.

Creating UBIFS file system

From information on how to create a UBIFS image. refer create an UBIFS image

  • mkfs.ubifs
mtd-utils# mkfs.ubifs/mkfs.ubifs -r filesystem/ -F -o ubifs.img -m 2048 -e 126976 -c 1580

Where:

-m 2KiB (or 2048)The minimum I/O size of the underlying UBI and MTD devices. In our case, we are running the flash with no sub-page writes, so this is a 2KiB page.-e 124KiB (or 126976)
Erase Block Size: UBI requires 2 minimum I/O units out of each Physical Erase Block (PEB) for overhead: 1 for maintaining erase count information, and 1 for maintaining the Volume ID information. The PEB size for the XO flash is 128KiB, so this leads to each Logical Erase Block (LEB) having 124KiB available for data.
-c 1580
The maximum size, in LEBs, of this file system. See calculation below for how this number is determined.
-r filesystem
Use the contents of the 'filesystem/' directory to generate the initial file system image.

-F

On AM335x, -F option is required when creating ubifs image. If this option is not used, Kernel may crash while loading the Filesystem from UBI partition.

The output of the above command, ubifs.img is fed into the 'ubinize' program to wrap it into a UBI image.

The images produced by mkfs.ubifs must be further fed to the ubinize tool to create a UBI image which must be put to the raw flash to be used a UBI partition.
  • Create ubinize.cfg file and write the contents into it
mtd-utils# vi ubinize.cfg [ubifs] <== Section header mode=ubi <== Volume mode (other option is static) image=ubifs.img <== Source image vol_id=0 <== Volume ID in UBI image vol_size=192MiB <== Volume size vol_type=dynamic <== Allow for dynamic resize vol_name=rootfs <== Volume name vol_flags=autoresize <== Autoresize volume at first mount

[See calculations below to determine the value associated with 'vol_size']

  • ubinize
mtd-utils# ubi-utils/ubinize -o ubi.img -m 2048 -p 128KiB -s 512 -O 2048 ubinize.cfg

Where:
-o ubi.img
Output file
-m 2KiB (or 2048)
Minimum flash I/O size of 2KiB page
-p 128KiB

Size of the physical eraseblock of the flash this UBI image is created for

-O 2048 offset if the VID header from start of the physical eraseblock

The output of the above command, 'ubi.img' is the required image.

Calculations

Usable Size Calculation

As documented here, UBI reserves a certain amount of space for management and bad PEB handling operations. Specifically:

  • 2 PEBs are used to store the UBI volume table
  • 1 PEB is reserved for wear-leveling purposes;
  • 1 PEB is reserved for the atomic LEB change operation;
  • a % of PEBs is reserved for handling bad EBs. The default for NAND is 1%
  • UBI stores the erase counter (EC) and volume ID (VID) headers at the beginning of each PEB. 1 min I/O unit is required for each of these.

To calculate the full overhead, we need the following values:

Symbol Meaning Value for XO test case
SP PEB Size 128KiB
SL LEB Size 128KiB - 2 * 2KiB = 124 KiB
P Total number of PEBs on the MTD device 200MiB / 128KiB = 1600
B Number of PEBs reserved for bad PEB handling 1% of P = 16
O The overhead related to storing EC and VID headers in bytes, i.e. O = SP - SL 4KiB
UBI Overhead = (B + 4) * SP + O * (P - B - 4) = (16 + 4) * 128Kib + 4 KiB * (1600 - 16 - 4) = 8880 KiB = 69.375 PEBs (round to 69)

This leaves us with 1531 PEBs or 195968KiB available for user data.

Note that we used "-c 1580" in the above mkfs.ubifs command line to specify the maximum filesystem size, not "-c 1531" The reason for this is that mkfs.ubifs operates in terms of LEB size (124 KiB), not PEB size (128Kib). 195968KiB / 124 Kib = 1580.39 (round to 1580).

Volume size = 195968KiB (~192MiB)

Using UBIFS file system

Preparing NAND partition

Kindly erase the NAND partition before using it for UBI file system. The partition can be erased from either u-boot or from Linux.

Follow below steps to erase.

  • From U-boot. Assuming NAND partition to be erased starts from "0x780000" and is of size "0xF880000".
u-boot# nand erase 0x00780000 0xF880000
  • From Linux. Assuming MTD partition 7 needs to be erased and used for UBI file system.
[email protected]:~# flash_eraseall /dev/mtd7

Flashing UBIFS image to a NAND partition

We can Flash UBIFS image from either Linux Kernel or U-Boot.

Follow steps mentioned here to create an UBIFS image.

From U-Boot,

Get the UBIFS image to U-Boot from tftp or MMC/SD or UART. Lets consider an example of MMC card.

Since we copy the data to NAND, Empty/Erase the required RAM. Then, get the UBIFS image to U-Boot

u-boot# mw.b 0x82000000 0xFF <=== filesystem image size is upward aligned to NAND block size, This is required to get rid of "Empty Flash" JFFS2 during kernel boot. u-boot# mmc rescan u-boot# fatload mmc 0 0x82000000 ubi.img

Next, erase the and flash the UBIFS image to correct NAND partition.

NOTE

On flashing UBIFS image from U-Boot, make sure that ECC selected is in sync with Linux Example

Assuming

  1. NAND partition to be erased starts from "0x780000",
  2. NAND partition of size "0xF880000" and
  3. File system image size to be flashed is 0xFC0000 which is upward aligned to NAND block size
u-boot# nand erase 0x780000 0xF880000 u-boot# nand write 0x82000000 0x780000 0xFC0000


From Linux,

  • Flash the UBI file system image (ubi.img) to MTD partition "X"
ubiformat /dev/mtd -f ubi.img -s -O 2048

Here subpage size depends MTD driver. Find subpage size of MTD partition using

mtdinfo /dev/mtd

Assuming 7th mtd partition with 2048 byte subpage size, we can use the following command to flash the ubifs image to partition 7.

#ubiformat /dev/mtd7 -f ubi.img -s 2048 -O 2048

Using UBIFS image as root file system

  • Set up the bootargs environment variable as below to use the UBIFS file system image present in a MTD partition:
setenv bootargs 'console=ttyO0,115200n8 noinitrd ip=off mem=256M rootwait=1 rw ubi.mtd=X,YYYY rootfstype=ubifs root=ubi0:rootfs init=/init'

Where X is the MTD partition number being used for file system and YYYY is the NAND page size. make sure that an UBI file system is flashed into this partition before passing it as a boot partition for Linux.

Assuming 7th mtd partition,

#setenv bootargs 'console=ttyO0,115200n8 noinitrd ip=off mem=256M rootwait=1 rw ubi.mtd=7,2048 rootfstype=ubifs root=ubi0:rootfs init=/init'
NOTE

On booting with UBIFS as rootfs, the first boot happens successfully. Before subsequent boot-ups, it is recommended to do a manual "sync" from the console. This allows UBIFS meta data properly updated on the partition. This initial sync will help later recovery.

Mounting UBIFS image as a regular NAND partition

Assuming UBIFS image is already flashed to a NAND Partition, follow below steps to mount the same.

  • Attach MTD device to UBI
ubiattach /dev/ubi_ctrl -m -O 2048

Where "X" is the MTD partition number

Mtd device number 7 can be attached to ubi using

#ubiattach /dev/ubi_ctrl -m 7 -O 2048
  • Mount the UBIFS image
mount -t ubifs ubiX:NAME /mount/point

Where "X" - UBI device number and "NAME" - UBI volume name from ubinize.cfg file.

Assuming ubi device 0 and rootfs is the volume name given in ubinize.cfg, ubifs image can be mounted to /media/card using

#mount -t ubifs ubi0:rootfs /media/card
NOTE

On mounting UBIFS as regular partition, it is recommended to do a manual "sync" from the console after mounting. This allows UBIFS meta data properly updated on the partition. This initial sync will help later recovery.

Mounting a NAND partition using UBIFS

We can mount a particular NAND partition with UBIFS file system in the following way

  • Format and attach the MTD partition
ubiformat /dev/mtd -s -O 2048 ubiattach /dev/ubi_ctrl -m -O 2048

Where "X" is the MTD partition number and "subpagesize" determined using mtdinfo command

MTD partition number 7 with 2048 subpage size can be formatted and attched using

ubiformat /dev/mtd7 -s 2048 -O 2048 #ubiattach /dev/ubi_ctrl -m 7 -O 2048
  • Create an UBI volume - the created volume will be empty
ubimkvol /dev/ubi0 -N 

Where "XX" is the size of the partition to be mounted and "label" is the name for the volume.

10 MB ubi volume can be created with label ubifs_volume as

ubimkvol /dev/ubi0 -N ubifs_volume -s 10MiB

Also, user can create a UBI volume with volume size set to maximum available size

ubimkvol /dev/ubi0 -N 

where "label" is the name for the volume.

ubimkvol /dev/ubi0 -N ubifs_volume –m
  • Mount the MTD partition
mount -t ubifs ubi0:

Make sure that the "label" used during ubimkvol is passed as an argument here.

Mounting of ubi volume can be achieved using

#mount -t ubifs ubi0:ubifs_volume /media/card

相關推薦

ubi檔案系統製作指令分析

介紹UBIFS檔案系統,鄙人已經親身製作並使用的ti DM3730 linux平臺上。ubifs檔案系統掛載速度相對快,相比其他型別檔案系統,綜合性能狠強啊,不過鄙人實踐及官方也坦白一個事實,就是ubifs檔案系統對系統異常/突然掉電的容忍性不好,資料可能會嚴重損壞。 -------------

UBI檔案系統製作和掛載

關於引數可以參考attach的命令輸出: [email protected]:~# ubiattach  /dev/ubi_ctrl -m 4 -d 0 UBI device number 0, total 4000 LEBs (516096000 bytes,

imx6 uboot的mtd分割槽總結(rootfs為ubi檔案系統

轉載地址:https://blog.csdn.net/qq_29729577/article/details/51130209 此文章基於U-Boot 2014.04版本,燒寫工具為mfgtool,開發環境為yocto 前言: JFFS2、YAFFS2等專用檔案系統存在著一些技術瓶頸,如

Linux根檔案系統製作與各種掛載方式的實現

Linux根檔案系統的製作 什麼是檔案系統 計算機的檔案系統是一種儲存和組織計算機資料的方法,它使得對其訪問和查詢變得容易,檔案系統使用檔案和樹形目錄的抽象邏輯概念代替了硬碟和光碟等物理裝置使用資料塊的概念,使用者使用檔案系統來儲存資料不必關心資料實際儲存在硬碟(或者光碟)的地址為多少的資料

cramfs檔案系統製作與移植(二)

[ [email protected] ]# bootm ## Booting kernel from Legacy Image at 30008000 ...    Image Name:   Linux Kernel    Created:      2013-04-23  12:05:15

cpio命令與檔案系統製作

嵌入式開發過程中的檔案系統製作,往往是使用已經定製好的目錄及檔案進行製作,下面以實際的例子進行說明: 假設當前目錄為rootdir,目錄結構如下: [email protected]:~# tree -L 2 rootdir rootdir |-- dev |--

Linux核心移植和根檔案系統製作(詳細步驟精講)

start_kernel是所有 Linux 平臺進入系統核心初始化後的入口函式,它主要完成剩餘的與硬體平臺相關的初始化工作,在進行一系列與核心相關的初始化後,呼叫第一個使用者程序-init 程序並等待使用者程序的執行,這樣整個 Linux 核心便啟動完畢。該函式所做的具體工作有:呼叫 setup_arch

cramfs根檔案系統製作啟動總結

cramfs啟動根檔案系統 Cramfs:Compressed ROM File System   Cramfs是Linux的創始人 Linus Torvalds參與開發的一種只讀的壓縮檔案系統。它也基於MTD驅動程式。   cramfs擁有以下一些特性:  採用實時解壓

jffs2檔案系統製作

U-Boot 2010.09-00000-g1a87d59 (Jun 01 2011 - 21:21:30) Modified by guowenxue for s3c2440/s3c2410 board. DRAM:  64 MiB Flash: 1 MiB NAND:  256 MiB In:    se

cramfs檔案系統製作

參考:http://blog.csdn.net/liukun321/article/details/7256456 1、首先配置核心,開啟對cramfs的支援:  File systems  --->[*] Miscellaneous filesystems  ---

嵌入式Linux---將檔案系統製作系統映象

假設已經制作好檔案系統rootfs,下面就開始製作映像檔案了: 1.建立檔案系統 ramdisk8M.image  ,檔案系統格式為ext2,大小最好不要超過32M dd if=/dev/zero of=ramdisk8M.image bs=1024 count=8192 mke

檔案系統製作(cramfs,jffs2)及busybox編譯

1.cramfs製作 cramfs-1.1.tar.gz >mkcramfs rootfs root.cramfs 2.jffs2製作 下載:mtd-utils-1.5.0.tar.bz2 》cd mtd-utils-1.5.0 >make >make

ubi檔案系統初識

UBI檔案系統 在linux-2.6.27以前,談到Flash檔案系統,大家很多時候多會想到cramfs、jffs2、yaffs2等檔案系統。它們也都是基於檔案系統+mtd+flash裝置的架構。linux-2.6.27後,核心加入了一種新型的flash檔案系統UBI(Unsorted Block Ima

Hadoop_HDFS_hdfs 檔案系統操作指令

本地做個備份, 下面的文章摘自Hadoop官網 下載文件時, 當前最新版本 3.0.0 beta 這裡介紹下常用的hdfs 的檔案操作指令: 檔案系統操作命令的呼叫格式為  hdfs dfs  -OPTION  (2.x-2.7.3) 下面的應該是3.x版本的呼

Tiny4412 ARM開發環境搭建—NFS網路根檔案系統製作

Tiny4412從SD卡啟動的簡單網路檔案系統製作 1. 簡介 嵌入式系統能夠在開發板上正常執行,需要先進行系統配置,一個完整的嵌入式系統應該包含的幾個部分::uboot,kernel,rootfs,appfs。這幾部分在ARM板Flash上的位置關係

Zynq 檔案系統製作

0 擴容 預設xilinx提供的檔案系統可能只有16MB,如果我們想要擴容時,需要重新制作,製作的過程可參考官方wiki(http://www.wiki.xilinx.com/Expanding+File+System)。大致流程可以簡述如下。 Make an 8MBra

ramdisk檔案系統製作和移植

[ [email protected] ]# pri bbl=nand erase 0 100000;tftp 30008000 u-boot-$cpu.bin;nand write 30008000 0 $filesize norbbl=erase bank 1;tftp 30008000 u-b

Linux-2.6.32.2核心在mini2440上的移植(四)---根檔案系統製作(1)

ROMFS MTD (C) 2007 Red Hat, Inc.msgmni has been set to 109 alg: No test for stdrng (krng) io scheduler noop registered io scheduler anticipatory registered

jffs2檔案系統製作(適用於spi nor flash)

mkfs.jffs2: Usage: mkfs.jffs2 [OPTIONS] Make a JFFS2 file system image from an existing directory tree Options: -p, --pad[=SIZE]       用16進位制來表示所要輸出檔案的大小,也

ubifs[ubi檔案系統]

Introduction ============= UBIFS file-system stands for UBI File System. UBI stands for "Unsorted Block Images". UBIFS is a flash file s