linux UBI文件系统制作与升级【转】

第1章 UBI文件系统制作
预准备工具源代码

[En]

Pre-preparation tool source code

常见的根文件系统rootfs

[En]

The common root file system rootfs

制作工具

[En]

Making tools

交叉编译工具:arm-linux-GCC-4.4.3-20100728.tar.gz

[En]

Cross-compilation tool: arm-linux-gcc-4.4.3-20100728.tar.gz

下载 zlib-1.2.5.tar.gz :http://www.zlib.net/
下载 lzo-2.06.tar.gz :http://www.oberhumer.com/opensource/lzo/download/
下载e2fsprogs-1.41.14.tar.gz: http://e2fsprogs.sourceforge.net/
下载 mtd-utils-1.4.6.tar.bz2: http://debian.mirror.inra.fr/debian/pool/main/m/mtd-utils/
平台工具

[En]

Platform tools

linux平台: VMware Workstation Pro + Ubuntu12
目标平台:imx.6

[En]

Target platform: imx.6

编译工具链:Linux-ARM交叉工具链

[En]

Compilation tool chain: linux-ARM cross tool chain

应注意的事项

[En]

Matters needing attention

2. 制作文件系统时,存放的文件系统及相关文件,要放在ubuntu的家目录’~’下,不能放在共享目录下;
3. 通过shell命令来完成文件系统制作

1.1 编译开发板上使用的UBI工具命令
一些编译参数:

[En]

Some compilation parameters:

–host:编译主机
–target:目标平台
–prefix:安装目录
CC:交叉工具链路径
相关文件的目录位置

[En]

Directory location of related files

根文件系统rootfs:/home/文件系统/armLinux/rootfs

[En]

Root file system rootfs: / home/filesystem/armLinux/rootfs

工具链:/home/文件系统/FriendlyARM

[En]

Tool chain: / home/filesystem/FriendlyARM

工具源代码:/home/文件系统/mtd

[En]

Tool source code: / home/filesystem/mtd

(1) 编译安装 e2fsprogs
tar xzvf e2fsprogs-1.41.14.tar.gz
cd e2fsprogs-1.41.14
./configure –host=i686-linux –target=arm-linux CC=/home/filesystem/FriendlyARM/toolschain/4.4.3/bin/arm-linux-gcc –prefix=/home/filesystem/FriendlyARM/toolschain/4.4.3/ arm-none-linux-gnueabi
make
sudo make install-libs ( 只需要 uuid 库, 所以不需要完全安装)
cd ..

结果:您可以看到uuid/uuid.h文件已经安装在工具链目录/home/filesystem/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi.的Include,libuuid.a目录中它已安装在lib目录中。

[En]

Result: you can see that the uuid/uuid.h file has been installed in the include,libuuid.a directory in the tool chain directory / home/filesystem/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi. It has been installed in the lib directory.

(2) 编译安装 zlib
tar xzvf zlib-1.2.5.tar.gz
cd zlib-1.2.5
./configure –host=i686-linux –target=arm-linux CC=/home/filesystem/FriendlyARM/toolschain/4.4.3/bin/arm-linux-gcc –prefix=/home/filesystem/FriendlyARM/toolschain/4.4.3/ arm-none-linux-gnueabi
make
sudo make install
cd ..

结果:zconf.h和libz.an都安装在工具链目录Include和lib中。

[En]

The result: both zconf.h and libz.an are installed in the tool chain directories include and lib.

(3) 编译安装 lzo
ar xzvf lzo-2.06.tar.gz
cd lzo-2.06
./configure –host=i686-linux –target=arm-linux –prefix=/home/filesystem/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi CC=/home/filesystem/FriendlyARM/toolschain/4.4.3/ bin/arm-linux-gcc
make
sudo make install
cd ..

结果:liblzo2.a已复制到工具链的lib目录。

[En]

Result: liblzo2.a has been copied to the lib directory of the tool chain.

(4) 编译安装 mtd-utils
tar xzvf mtd-utils-1.4.6.tar.gz
cd mtd-utils-1.4.6
export CFLAGS=”-static -O2 -g”
export CROSS=/home/filesystem/FriendlyARM/toolschain/4.4.3/bin/arm-linux-
export DESTDIR=/home/install (这样声明不行,生成的文件在当前文件下的home目录下)
make WITHOUT_XATTR=1
sudo make install

安装过程中出错:

[En]

An error occurred in the installation:

LD ftl_check
CC mkfs.jffs2.o
mkfs.jffs2.c:71:21: 致命错误: sys/acl.h:没有那个文件或目录编译中断。
make:***[/home/filesystem/FriendlyARM/ArmLinux/source/mtd-utils-v1.4.8-d37fcc0/mkfs.jffs2.o] 错误 1。

解决方案:

[En]

Solution:

sudo apt-get install uuid-dev libacl1-dev liblzo2-dev

或者不用管这个错误,我们需要的工具已经生成了。ubi-utils 子目录下生成我们需要的 ubiformat、ubiattach、 ubimkvol 等文件(请确保是交叉编译所得), 将需要的工具复制添加到目标板的根文件系统中即可:

cd ./home/filesystem/FriendlyARM/toolschain/4.4.3/bin/arm-linux
cp * /home/filesystem/armLinux/rootfs/usr/sbin
cd ..

cp share/man/man1 /home/filesystem/armLinux/rootfs/usr/share/man/man1

1.2 编译制作UBI镜像工具命令(ubuntu)
1.2.1 安装UBI编译依赖工具库
在ubuntu中建立home/filesystem/mtd/install 目录,将zlib-1.2.5.tar.gz、tar xvf lzo-2.06.tar.gz、e2fsprogs-1.42.tar.gz这3 个 source code 包拷贝到~/mtd目录下。

(1) zlib
tar xvf zlib-1.2.5.tar.gz
cd zlib-1.2.5/
./configure –prefix=~/mtd/install
make
make install
cd ..

(2) lzo
tar xvf lzo-2.06.tar.gz
cd lzo-2.06/
./configure –prefix=~/mtd/install
make
make install
cd ..

(3) e2fsprogs
tar xvf e2fsprogs-1.42.tar.gz
cd e2fsprogs-1.42/
./configure –prefix=~/mtd/install
make
make install
cd lib/uuid/
make install
cd ../../../

1.2.2 编译MTD Utilite
在编译mtd-utils之前,请修改makfile文件:

[En]

Before compiling mtd-utils, modify the makfile file:

$ vi Makefile
PREFIX = ~/mtd/install
ZLIBCPPFLAGS = -I$(PREFIX)/include
LZOCPPFLAGS = -I$(PREFIX)/include
ZLIBLDFLAGS = -L$(PREFIX)/lib
LZOLDFLAGS = -L$(PREFIX)/lib
LDFLAGS += $(ZLIBLDFLAGS) $(LZOLDFLAGS)
CFLAGS ?= -O2 -g $(ZLIBCPPFLAGS) $(LZOCPPFLAGS)
$ vi common.mk

PREFIX=/usr

然后按照以下说明进行编译:

[En]

Then compile according to the following instructions:

$ WITHOUT_XATTR=1 make
make install DESTDIR=~/mtd/install
cd ..

用于创建ubi文件系统的工具位于以下目录中:

[En]

The tools used to create the ubi file system are in the following directory:

~/mtd/install/home/

(1)NAND FLASH特性
我们可以从NAND闪存手册或内核启动打印信息中获得它的功能。正常启动顶盖时,观察终端打印信息,说明根文件系统为MTD分区的mtd4、NAND闪存特征:

[En]

We can get its features from the NAND FLASH manual or from the kernel startup printing information. When starting the top cover normally, observe the terminal print information, which can account for the mtd4,NAND FLASH feature that the root file system is a MTD partition:

GPMI NAND driver registered.(IMX)
UBI: attaching mtd4 to ubi0
UBI: physical eraseblock size: 262144 bytes (256 KiB)
UBI: logical eraseblock size: 253952 bytes
UBI: smallest flash I/O unit: 4096
UBI: VID header offset: 4096 (aligned 4096)
UBI: data offset: 8192
UBI: max. sequence number: 11

UBI: MTD device size: 480 MiB
UBI: number of good PEBs: 1920
UBI: number of bad PEBs: 0
UBI: number of corrupted PEBs: 0
UBI: max. allowed volumes: 128

您可以获得mtd4分区大小480MiB、I_253952Bytes O单位大小4096Bytes、块物理大小256KiB、块逻辑大小253952Bytes和块总数1920个块。这样,您就可以计算出制作UBI的文件系统的参数:

[En]

You can get the mtd4 partition size 480MiB, the I _ 253952Bytes O unit size 4096Bytes, the block physical size 256KiB, the block logical size 253952Bytes, and the total number of blocks 1920 blocks. In this way, you can calculate the parameters of the file system for making UBI:

(2)UBI镜像制作

mkfs.ubifs -F -r /home/filesystem/armLinux/rootfs/ -m 4096 -e 253952 -c 1919 -o ubifs.img
ubinize -o ubi.img -m 4096 -p 256KiB -s 4096 ubinize.cfg

ubinize.cfg内容如下:
[ubifs]

mode=ubi
image=ubifs.img
vol_id=0
vol_size=464MiB
vol_type=dynamic
vol_alignment=1
vol_name=ubifs0
vol_flags=autoresize

根据使用的NAND闪存功能,在此计算以下参数:

[En]

Based on the NAND FLASH feature used, the following parameters are calculated here:

-m: 4096
-s: 4096
-e: 253952 = 64(页数一般固定)4096 – 2
-c: 1919 = 1920 – 1
制作的UBI文件系统空间大小:464MiB = 1919253952/1024/1024

参数说明:

[En]

Parameter description:

-F:使能自动填补空白空间”white-space-fixup”,通过uboot或者ubiformat/nandwrite工具烧写必须使能此项,不管哪种方式最好都加上。
-r:制作UBI的源文件系统目录
-m:NAND FLASH 的最小读写单元,一般为 page size
-e:LEB size,对于 AM335x 的 NAND driver,为 block size-2x(page size)
-c:文件系统所占用的最大 block 数,一般小于等于 block count -1,文 件 系 统 最 多 可 以 访 问 卷 上 的256KiB*1919=464M空间

第2章 A9 UBI文件系统升级
2.1 u-boot方式烧写
使用ubinize命令生成的带有卷标的UBIFS文件系统映像可以使用NAND闪存的烧录命令直接写入NAND闪存。具体的命令是:

[En]

The UBIFS file system image with volume label made by using ubinize command can be directly written to NAND FLASH using nand flash’s burn command. The specific command is:

tftp 0x10800000 ubi.img
nand erase 0x2000000 0x1E000000
nand write 0x10800000 0x2000000 0x92c0000
1
2
3
0x10800000:下载到的内存地址
0x2000000:A9中文件系统起始地址
0x1E000000:A9 NAND FLASH分区大小(480MiB)
0x8d00000:ubi.img的大小,根据其实际大小来定

结果:烧写成功,显像板重启正常,不同图像的替换也成功,经过多次实验证明是成功的。

[En]

Results: the burning and writing was successful, the restart of the development board was normal, and the replacement of different images was also successful, and it was successful after many experiments.

2.2 挂载U盘方式烧写
准备:将以下工具命令和镜像复制到USB磁盘目录sbin/armTool/(随意更改)。

[En]

Preparation: the following tool commands and images are copied to the USB disk directory sbin/armtool/ (change at will).

UBI文件系统镜像:ubi.img

一种制造的工具。

[En]

A tool made.

ubiformat
(flash_erase)
(nandwrite)
reboot

2.2.1 ubiformat工具烧写UBI镜像
(1) 直接执行命令
./ubiformat -q /dev/mtd4 -f ubi.img

结果:失败,/dev/mtd4忙

[En]

Result: failed, / dev/mtd4 busy

ubiformat: error!: please, first detach mtd4 (/dev/mtd4) from ubi0
$./ubidetach –p /dev/mtd4
ubidetach: error!: cannot detach “/dev/mtd4”
error 16 (Device or resource busy)

结果:失败,错误,命令执行不成功。

[En]

Result: failed, error, command execution was not successful.

(2) 在线升级前先解除掉占用A9文件系统的程序和挂载
根据第一次的错误ubiformat: error!: please, first detach mtd4 (/dev/mtd4) from ubi0,所以先要解除ubi0关联和占用文件系统的程序,即kill掉占用文件系统的应用、umount掉mtd4分区(mtd4分区挂载UBI文件系统)。

killall WorkStationApp //kill掉占用文件系统的应用
sleep 3

cd /mnt/udisk/sda1/sbin/armtool/ //这个只是我U盘放镜像和命令的目录

umount /mnt/rwfs/ //umount挂载的文件系统
umount /tmp/
umount /dev/shm/
umount /dev/pts/
umount /sys/
umount /
sleep 1

./ubiformat -s 4096 /dev/mtd4 -f ./ubi.img //擦除和烧写UBI文件系统镜像
sleep 2

./reboot

防止刻录和写入失败的脚本
[En]

Prevent burning and writing failed scripts

!/bin/sh

echo “## start update ubi image ###”

killall WorkStationApp
if [ $? -ne 0 ]
then
echo “kill WorkStationApp failed!”
exit 1
fi

sleep 5
cd /mnt/udisk/sda1/updateA9FileSystem/

umount /mnt/rwfs/
if test $? -ne 0
then
echo “1 failed!”
./reboot
fi

umount /tmp/
if test $? -ne 0
then
echo “2 failed!”
./reboot
fi

umount /dev/shm/
if test $? -ne 0
then
echo “3 filed!”
./reboot
fi

umount /dev/pts/
if test $? -ne 0
then
echo “4 failed!”
./reboot
fi

umount /sys/
if test $? -ne 0
then
echo “5 failed!”
./reboot
fi

umount /
if test $? -ne 0
then
echo “6 failed!”
./reboot
fi

sleep 1
./ubiformat -s 4096 /dev/mtd4 -f ./ubi.img

sleep 1

./reboot

==========================================================================
结果:刻写成功,开发板重启运行正常,不同图像的替换也成功,经多次实验基本无问题。

[En]

Results: the burning and writing was successful, the restart of the development board was running normally, and the replacement of different images was also successful, which was basically no problem after many experiments.

2.2.2 flah_erase&nandwrite工具烧写UBI镜像
killall WorkStationApp
sleep 3

umount /sys/
umount /

sleep 1
cd /mnt/udisk/sda1/sbin/armtool/

./flash_erse /dev/mtd4 0x0 0x0 //擦除mtd4整个分区
./nandwrite –a /dev/mtd4 ./ubi.img

sleep 2
./reboot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
结果:烧写成功,重启开发板运行正常,经多次测试基本无问题。

[En]

Results: the burning and writing was successful, and the restart development board was running normally, and it was basically no problem after many tests.

说明:需要继续测试和调整执行命令的参数

[En]

Description: you need to continue testing and adjust the parameters for executing the command

第3章遇到的问题
(1)UBI烧写错误问题
UBI文件系统升级失败,主要有以下两个原因:

[En]

The unsuccessful upgrade of the UBI file system is basically due to the following two reasons:

首先,生产的UBI文件系统和NAND闪存参数不匹配。对应于1.3节中的UBI映像的创建。

[En]

First, the production of UBI file system and NAND FLASH parameters do not match. Corresponding to the creation of UBI image in section 1.3.

第二,UBI文件系统镜像没有完全写入或写入错误,这实际上是由于A9中的文件系统被系统中的其他程序占用。

[En]

Second, the UBI file system image is not fully written or written incorrectly, which is actually due to the fact that the file system in A9 is occupied by other programs in the system.

ubi卷(volume)没有创建: 原因其一

UBI error: ubi_read_volume_table: the layout volume was not found
UBI error: ubi_init: cannot attach mtd4
1
2
检查错误:原因之一

[En]

Check error: one of the reasons

UBI error: ubi_io_read: error -74 (ECC error) while reading 253952 bytes from PEB 3:8192, read 253952 bytes
UBI error: ubi_io_read: error -74 (ECC error) while reading 253952 bytes from PEB 3:8192, read 253952 bytes
1
2
读取ubifs节点出错:原因可能是其一,也可能是其二

UBIFS error (pid 1): ubifs_read_node: bad node type (255 but expected 0)
UBIFS error (pid 1): ubifs_read_node:bad node at LEB 552:57664,LEB mapping status1
UBIFS error (pid 1): ubifs_iget: failed to read inode 6066, error -22
UBIFS error (pid 1): ubifs_lookup: dead directory entry ‘utmp’, error -22

挂载ubifs失败:原因可能是其一,也可能是其二

UBI error: vtbl_check: volume table check failed: record 0, error 9
UBI error: ubi_init: cannot attach mtd4
No filesystem could mount root, tried: ubifs
Kernel panic – not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

(2)其他问题
当执行该命令时,MTD设备报告资源忙/与错误关联

[En]

When executing the command, the MTD device reports that the resource is busy / associated with an error

ubiformat: error!: please, first detach mtd4 (/dev/mtd4) from ubi0
$./ubidetach –p /dev/mtd4
ubidetach: error!: cannot detach “/dev/mtd4”
error 16 (Device or resource busy)
1
2
3
4
解决:

[En]

Resolve:

1、 kill应用程序
2、 umount掉该MTD分区挂载操作:
(1)mount查看挂载的文件系统

root@freescale /WorkStationApp$ mount
rootfs on / type rootfs (rw)
ubi0:rootfs on / type ubifs (rw,relatime)
proc on /proc type proc (rw,relatime)
sys on /sys type sysfs (rw,relatime)
tmpfs on /dev type tmpfs (rw,relatime,mode=755)
/dev/sda1 on /mnt/udisk/sda1 type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp936,iocharset=utf8,shortname=mixed,errors=remount-ro)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
shm on /dev/shm type tmpfs (rw,relatime)
rwfs on /mnt/rwfs type tmpfs (rw,relatime,size=512k)
tmpfs on /tmp type tmpfs (rw,relatime,size=65536k)

(2)kill掉应用,解除挂载

killall WorkStationApp
sleep 3

umount /mnt/rwfs/ //umount挂载的文件系统
umount /tmp/
umount /dev/shm/
umount /dev/pts/
umount /sys/
umount /

命令执行

[En]

Command execution

1
2
3
4
5
6
7
8
9
10
11
第4章 参考博客
http://blog.chinaunix.net/uid-15706699-id-2646284.html
http://www.cnblogs.com/leaven/archive/2011/04/19/2021388.html
https://blog.csdn.net/fulinus/article/details/8844127

[En]

版权声明:本文是CSDN博客作者Bill Jenkins的原创文章,符合CC 4.0BY-SA版权协议。请附上原始来源链接和此声明以供转载。

[En]

Copyright notice: this article is the original article of CSDN blogger “Bill Jenkins”, in accordance with the CC 4.0BY-SA copyright Agreement. Please attach the original source link and this statement for reprint.

原文链接:https://blog.csdn.net/lichengjun238/article/details/88821225

Original: https://www.cnblogs.com/sky-heaven/p/16434835.html
Author: sky-heaven
Title: linux UBI文件系统制作与升级【转】

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/7037/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部