• 配置内核,使其支持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。

使用ubifs格式的根文件系统的更多相关文章

  1. 使用ubifs格式的根文件系统---过程记录

    配置内核,使其支持ubifs文件系统 1)Device Drivers  --->Memory Technology Device (MTD) support  --->UBI - Uns ...

  2. rootfs -根文件系统制作

    目录 目录 目录 概述 概念 根文件系统是什么 根文件系统中有什么 根文件系统的形式 Busybox 简介 什么是 linuxrc VFS 简介 Busybox 工具 Busybox 目录结构 Men ...

  3. 内核移植和文件系统制作(4):UBIFS根文件系统制作总结

    UBIFS文件系统简介: 无排序区块图像文件系统(UnsortedBlock Image File System, UBIFS)是用于固态硬盘存储设备上,并与LogFS相互竞争,作为JFFS2的后继文 ...

  4. 使用ubifs作为根文件系统的openwrt如何在进行sysupgrade时保存旧的配置

    1.openwrt的默认方案(squashfs + jffs2) sysupgrade脚本直接调用default_do_upgrade更新设备树.内核.根文件系统,那么它是如何保存旧配置的呢?请看de ...

  5. 如何将根文件系统制作成yaffs格式,并设置从yaffs启动

    1.利用mkyaffs2image 工具,将根文件系统打包成yaffs镜像包 mkyaffs2image-128M root_qtopia root_qtopia.img 2.设置uboot参数boo ...

  6. linux2.6.30.4内核移植(5)——构建根文件系统(yaffs文件系统格式的镜像)

    一.首先编译并安装BusyBox 这里使用的交叉编译器还是3.4.5. 注意:编译内核.编译BusyBox以及编译文件系统中的所有应用程序的交叉编译器要使用同一个版本. 1.获取BusyBox源码 下 ...

  7. Linux之搭建自己的根文件系统

    Hi!大家好,我是CrazyCatJack.又和大家见面了.今天给大家带来的是构建Linux下的根文件系统.希望大家看过之后都能构建出符合自己需求的根文件系统^_^ 1.内容概述 1.构造过程 今天给 ...

  8. Linux学习 :Uboot, Kernel, 根文件系统初步分析

    1.U-Boot启动内核的过程可以分为两个阶段: 1)第一阶段的功能 硬件设备初始化 加载U-Boot第二阶段代码到RAM空间 设置好栈 跳转到第二阶段代码入口 2)第二阶段的功能 初始化本阶段使用的 ...

  9. linux根文件系统制作

    在嵌入式中移植的内核下载到开发板上,是没有办法真正的启动Linux操作系统的,会出现无法加载文件系统的错误. 那么根文件系统在系统启动中到底是什么时候挂载的呢?先将/dev/ram0挂载,而后执行/l ...

随机推荐

  1. CIR,CBS,EBS,PIR,PBS傻傻分不清楚?看这里!—-揭秘令牌桶

    概述 春暖花开的时候,大家都开着汽车外出旅游欣赏美丽的风景,却被堵在高速公路上,你是否为此感到痛苦?但如果有一种机制可以评估高速公路上的车流量.控制车流情况,确保进入高速公路的汽车都能在路上安全畅行, ...

  2. 【CF438E】小朋友和二叉树 解题报告

    [CF438E]小朋友和二叉树 Description ​ 我们的小朋友很喜欢计算机科学,而且尤其喜欢二叉树. ​ 考虑一个含有\(n\)个互异正整数的序列\(c_1,c_2,\dots,c_n\). ...

  3. 洛谷 P2389 电脑班的裁员 解题报告

    题意: 给定一段长为N的序列,选取其中的至多M段使这些子段和最大. 当N=1000时,我们可以采用动态规划解法 令\(dp[i][j][k]\)代表当前选至位置\(i\)处于第\(j\)段当前是否选取 ...

  4. 【bzoj4011】 HNOI2015—落忆枫音

    http://www.lydsy.com/JudgeOnline/problem.php?id=4011 (题目链接) 题意 给出一个拓扑图,再加入一条边,问树形图个数. Solution 右转题解→ ...

  5. Django JSON 时间

    在views.py中导入: from django.core.serializers.json import DjangoJSONEncoder 在返回JSON数据时调用: return HttpRe ...

  6. codeforces.com/contest/251/problem/C

    C. Number Transformation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. 实验一:使用ADO.NET方式读数据

    第一步:创建Asp.net应用程序 在VS中,点击文件->新建->项目,按如图方式选择并输入: 第二步:新建产品浏览网页窗体Listing.aspx: 在项目SportsStoreEx上点 ...

  8. php配置修改后,平滑启动php-fpm

    修改了php配置需要平滑启动php-fpm ps -aux | grep php-fpm 找到phpfpm 的master process的进程id kill -SIGUSR2 31158   实现平 ...

  9. OpenLDAP介绍和安装

    LADP 1.目录服务 目录是一个为查询.浏览和搜索而优化的专业分布式数据库,它呈树状结构组织数据,就好象Linux/Unix系统中的文件目录一样.目录数据库和关系数据库不同,它有优异的读性能,但写性 ...

  10. Docker生产实践(六)

    镜像构建思路 思路:分层设计 最底层:系统层,构建自己适用的不同操作系统镜像: 中间层:根据运行环境,如php.java.python等,构建业务基础运行环境层镜像: 最上层:根据具体的业务模块,构建 ...