加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

UBIFS文件系统的移植

发布时间:2020-12-15 06:45:01 所属栏目:百科 来源:网络整理
导读:? 作者: piaozhiye86@126.com 首次做 UBIFS 的移植,不足之处欢迎批评指正。 2010-7-15 ? ? 自从 linux2.6.27 以后的内核版本都支持 UBI 文件系统了,新版本的 uboot 已经支持 UBIFS 了。 软件平台 VMware Fedora-10 使用源码: linux-2.6.30.4.tar.bz2 u-b
?

作者:piaozhiye86@126.com

首次做UBIFS的移植,不足之处欢迎批评指正。

2010-7-15

?

?

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

软件平台

VMware

Fedora-10

使用源码:

linux-2.6.30.4.tar.bz2

u-boot-2010.06-rc1.tar.bz2

硬件环境mini2440—64M NAND

关于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

?

2 文件系统的烧写

?

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

?

1)擦除root分区 nand erase root

?

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

?

Creating 1 MTD partitions on "nand0":

?

0x26000033fc64f4-0x400000000000000 : "<NULL>"

?

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读