在SmartARM3250上使用UBIFS内核配置
使用UBIFS,首先需要在内核中使能MTD_UBI和UBIFS:
在MTD中使能UBI:
<*> Enable UBI
在FS中使能UBIFS:
<*> UBIFS file system support
工具支持
使用UBI,需要UBI的一些工具,如ubiattach ubimkvol等,这些工具都包含在教新版的mtd-utils中,我下载了mtd-utils-1.2.0.tar.bz2,其中就包含了ubi的工具,只需进行交叉编译即可。但是,交叉编译mtd-utils,需要zlib和lzo的支持,我分别下载了zlib-1.2.3.tar.gz和lzo-2.03.tar.gz,分别进行交叉编译并安装到交叉工具链中。
交叉编译zlib-1.2.3.tar.gz
解压后,进行配置编译即可,编译和安装命令:
CC=arm-vfp-linux-gnu-gcc ./configure --shared --prefix=/opt/nxp/gcc-4.3.2-glibc-2.7/arm-vfp-linux-gnu/
make
sudo make install
其中,因为使用普通用户,所以make install需要sudo操作。
交叉编译lzo-2.03.tar.gz
解压后进行配置和编译即可。
CC=arm-vfp-linux-gnu-gcc ./configure --host=arm-linux --prefix=/opt/nxp/gcc-4.3.2-glibc-2.7/arm-vfp-linux-gnu/
make
sudo make install
交叉编译mtd-utils-1.2.0
这需要修改Makefile文件。修改./Makefile,将其中的CROSS指定为:
8 CROSS=arm-vfp-linux-gnu-
9 CC := $(CROSS)gcc
修改下列代码:
ifeq ($(origin CROSS),undefined)
BUILDDIR := .
else
Remove the trailing slash to make the directory name
BUILDDIR := $(CROSS:-=)
endif
为:
#ifeq ($(origin CROSS),undefined)
BUILDDIR := .
#else
# Remove the trailing slash to make the directory name
# BUILDDIR := $(CROSS:-=)
#endif
指定BUILDDIR为当前目录。
修改./ubi-utils/Makefile文件,增加CROSS:
11 CROSS=arm-vfp-linux-gnu-
12 CC := $(CROSS)gcc
修改./ubi-utils/new-utils/Makefile文件,增加CROSS:
12 CROSS=arm-vfp-linux-gnu-
13 CC := $(CROSS)gcc
然后输入 make WITHOUT_XATTR=1 进行编译,编译完毕,可以得到flash_erase等工具。
再进入ubi-utils/目录,输入make,将会得到ubi的工具,将需要的工具复制添加到目标板的根文件系统中即可。我是放在rootfs/usr/bin目录下。
使用ubifs
我是通过NFS启动系统的,在系统启动后操作板子的NAND FLASH分区。
[root@zlg /]# more /proc/partitions
major minor #blocks name
31 0 1536 mtdblock0
31 1 256 mtdblock1
31 2 4096 mtdblock2
31 3 16384 mtdblock3
31 4 239616 mtdblock4
一共有5个mtd分区,我想将mtdblock4做为ubifs分区使用。
先擦除FLASH 分区mtd4:
[root@zlg /]# flash_eraseall /dev/mtd4
然后使用ubiattach:
[root@zlg /]# ubiattach /dev/ubi_ctrl -m 4
UBI: attaching mtd4 to ubi0
UBI: physical eraseblock size: 131072 bytes (128 KiB)
UBI: logical eraseblock size: 129024 bytes
UBI: smallest flash I/O unit: 2048
UBI: sub-page size: 512
UBI: VID header offset: 512 (aligned 512)
UBI: data offset: 2048
UBI: empty MTD device detected
UBI: create volume table (copy #1)
UBI: create volume table (copy #2)
UBI: attached mtd4 to ubi0
UBI: MTD device name: "smartarm3250-rootfs"
UBI: MTD device size: 234 MiB
UBI: number of good PEBs: 1870
UBI: number of bad PEBs: 2
UBI: max. allowed volumes: 128
UBI: wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 0
UBI: available PEBs: 1848
UBI: total number of reserved PEBs: 22
UBI: number of PEBs reserved for bad PEB handling: 18
UBI: max/mean erase counter: 0/0
UBI: background thread "ubi_bgt0d" started, PID 609
UBI device number 0, total 1870 LEBs (241274880 bytes, 230.1 MiB), available 1848 LEBs (238436352 bytes, 227.4 MiB), LEB size 129024 bytes (126.0 KiB)
提示available 1848 LEBs (238436352 bytes, 227.4 MiB),238436352字节可用,但是ubi工具只识别KiB MiB GiB,并且只识别整数,所以需要进行换算。
238436352 bytes = 232848KiB
再使用ubimkvol在ubi设备上创建ubi卷:
[root@zlg /]# ubimkvol /dev/ubi0 -N rootfs -s 232848KiB
Volume ID 0, size 1848 LEBs (238436352 bytes, 227.4 MiB), LEB size 129024 bytes (126.0 KiB), dynamic, name "rootfs", alignment 1
提示创建ubi0成功,卷名为rootfs。
最后挂载:
[root@zlg /]# mount -t ubifs ubi0_0 /mnt 或者
mount -t ubifs ubi0:rootfs /mnt
UBIFS: default file-system created
UBIFS: background thread "ubifs_bgt0_0" started, PID 619
UBIFS: mounted UBI device 0, volume 0, name "rootfs"
UBIFS: file system size: 237017088 bytes (231462 KiB, 226 MiB, 1837 LEBs)
UBIFS: journal size: 11870208 bytes (11592 KiB, 11 MiB, 92 LEBs)
UBIFS: default compressor: LZO
UBIFS: media format 4, latest format 4
挂载上之后可用df查看:
[root@zlg /]# df
Filesystem 1k-blocks Used Available Use% Mounted on
rootfs 39994768 26688892 11274260 70% /
/dev/root 39994768 26688892 11274260 70% /
tmpfs 30636 24 30612 0% /dev
shm 30636 0 30636 0% /dev/shm
df: /mnt/rwfs: No such file or directory
ubi0:rootfs 217224 0 212160 0% /mnt
使用完毕可以卸载:
[root@zlg /]# umount /mnt/
UBIFS: un-mount UBI device 0, volume 0
可以通过NFS启动系统,挂载ubi分区后将根文件系统解压到ubi中,然后设置参数,使用ubifs作为根文件系统,设置参数:
setenv bootargs ubi.mtd=4 root=ubi0:rootfs rootfstype=ubifs console=ttyS0,115200 mem=64M
启动系统即可,如下是启动信息:
U-Boot 1.3.3 (May 5 2009 - 13:04:13)
DRAM: 64 MB
NAND: 256 MiB
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
U-Boot$
U-Boot$ setenv bootargs ubi.mtd=4 root=ubi0:rootfs rootfstype=ubifs console=ttyS0,115200 mem=64M
U-Boot$ ru yboot
NAND read: device 0 offset 0x200000, size 0x1b5968
Reading data from 0x3b5800 -- 100% complete.
1792360 bytes read: OK
## Booting kernel from Legacy Image at 81000000 ...
Image Name: Linux-2.6.27.8
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1792296 Bytes = 1.7 MB
Load Address: 80008000
Entry Point: 80008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Starting kernel ...
Uncompressing Linux..................................................................................... done, booting the kernel.
Linux version 2.6.27.8 (chenxibing@localhost.localdomain) (gcc version 4.3.2 (crosstool-NG-1.3.1) ) #8 PREEMPT Fri Nov 6 05:59:13 CST 2009
CPU: ARM926EJ-S [41069264] revision 4 (ARMv5TEJ), cr=00053177
Machine: SmartARM3250 board with the LPC3250 Microcontroller
Memory policy: ECC disabled, Data cache writeback
CPU0: D VIVT write-back cache
CPU0: I cache: 32768 bytes, associativity 4, 32 byte lines, 256 sets
CPU0: D cache: 32768 bytes, associativity 4, 32 byte lines, 256 sets
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: ubi.mtd=4 root=ubi0:rootfs rootfstype=ubifs console=ttyS0,115200 mem=64M
PID hash table entries: 256 (order: 8, 1024 bytes)
Console: colour dummy device 80x30
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 61096KB available (3416K code, 230K data, 112K init)
Calibrating delay loop... 103.83 BogoMIPS (lpj=519168)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 288 bytes
NET: Registered protocol family 16
Invalid board descriptor!
LPC32XX DMA driver
SCSI subsystem initialized
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
NetWinder Floating Point Emulator V0.97 (double precision)
JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
yaffs Sep 5 2009 09:21:41 Installing.
msgmni has been set to 119
io scheduler noop registered
io scheduler anticipatory registered
io scheduler deadline registered
io scheduler cfq registered (default)
CLCD: ZHIYUAN LCD hardware, QVGA portrait display
Console: switching to colour frame buffer device 40x30
Serial: 8250/16550 driver4 ports, IRQ sharing disabled
serial8250.0: ttyS0 at MMIO 0x40090000 (irq = 9) is a 16550A
console [ttyS0] enabled
serial8250.0: ttyS1 at MMIO 0x40080000 (irq = 7) is a 16550A
serial8250.0: ttyS2 at MMIO 0x40088000 (irq = 8) is a 16550A
serial8250.0: ttyS3 at MMIO 0x40098000 (irq = 10) is a 16550A
lpc32xx_hsuart.0: ttyTX0 at MMIO 0x40014000 (irq = 26) is a lpc32xx_hsuart
lpc32xx_hsuart.0: ttyTX1 at MMIO 0x40018000 (irq = 25) is a lpc32xx_hsuart
lpc32xx_hsuart.0: ttyTX2 at MMIO 0x4001c000 (irq = 24) is a lpc32xx_hsuart
loop: module loaded
LPC32XX_mii_bus: probed
eth0: LPC32XX mac at 0x31060000 irq 29
eth0: attached PHY driver [Generic PHY] (mii_bus:phy_addr=0:00, irq=-1)
Uniform Multi-Platform E-IDE driver
ide0 at 0xc4866020-0xc486602e,0xc486602e on irq 86
Driver 'sd' needs updating - please use bus_type methods
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)