———————————————————————————————————————
交叉编译器环境:arm-linux-gcc-4.5.4
开发板平台: FL2440
Linux内核版本: linux-3.0
邮箱:hongfuhaocomon@163.com
———————————————————————————————————————
0.jffs2文件系统简介
FFS文件系统最早是由瑞典Axis Communications公司基于Linux2.0的内核为嵌入式系统开发的文件系统。JFFS2(Journalling Flash FileSystem v2,日志闪存文件系统版本2 )是RedHat公司基于JFFS开发的闪存文件系统,最初是针对RedHat公司的嵌入式产品eCos开发的嵌入式文件系统,所JFFS2也可以用在Linux, uCLinux中。它主要用于NOR型闪存,基于MTD驱动层,特点是:可读写的、支持数据压缩的、基于哈希表的日志型文件系统,并提供了崩溃/掉电安全保护,提供“写平衡”支持等。缺点主要是当文件系统已满或接近满时,因为垃圾收集的关系而使jffs2的运行速度大大放慢。
Jffs2不适合用于NAND闪存主要是因为NAND闪存的容量一般较大,这样导致jffs2为维护日志节点所占用的内存空间迅速增大,另外,jffs2文件系统在挂载时需要扫描整个FLASH的内容,以找出所有的日志节点,建立文件结构,对于大容量的NAND闪存会耗费大量时间。
目前jffs3正在开发中,关于jffs2系列文件系统的使用详细文档,可参考MTD补丁包中mtd-jffs-HOWTO.txt。
1.对根文件系统修改
无修改
2.添加内核对jffs2的支持
[hongfuhao@centos6 linux-3.0]$ export TERM=vt100
[hongfuhao@centos6 linux-3.0]$ make menuconfig
File systems --->
Miscellaneous filesystems --->
<*> Journalling Flash File System v2 (JFFS2) support
(0) JFFS2 debugging verbosity (0 = quiet, 2 = noisy)
[*] JFFS2 write-buffering support
[ ] JFFS2 summary support (EXPERIMENTAL)
[ ] JFFS2 XATTR support (EXPERIMENTAL)
[ ] Advanced compression options for JFFS2
[hongfuhao@centos6 linux-3.0]$ make
3.制作mkfs.jffs2和mkfs.ubifs工具
[hongfuhao@centos6 rootfs]$ mkdir mtd-utiles
[hongfuhao@centos6 rootfs]$ cd mtd-utiles/
[hongfuhao@centos6 mtd-utiles]$ vim build.sh
#!/bin/sh
#+--------------------------------------------------------------------------------------------
#|Description: This shell script used to download lzo,zlib,mtd-utils source code
#| and cross compile it for ARM Linux, all is static cross compile.
#| Author: GuoWenxue <guowenxue@gmail.com>
#| ChangeLog:
#| 1, Initialize 1.0.0 on 2011.04.12
#+--------------------------------------------------------------------------------------------
PRJ_PATH=`pwd`
LZO="lzo-2.04"
ZLIB="zlib-1.2.5"
e2fsprogs_ver=1.42
mtd="mtd-utils-1.4.9"
function decompress_packet()
(
echo "+---------------------------------------------+"
echo "| Decompress $1 now"
echo "+---------------------------------------------+"
ftype=`file "$1"`
case "$ftype" in
"$1: Zip archive"*)
unzip "$1" ;;
"$1: gzip compressed"*)
if [ `expr "$1" : ".*.tar.*" ` ] ; then
tar -xzf $1
else
gzip -d "$1"
fi ;;
"$1: bzip2 compressed"*)
if [ `expr "$1" : ".*.tar.*" ` ] ; then
tar -xjf $1
else
bunzip2 "$1"
fi ;;
"$1: POSIX tar archive"*)
tar -xf "$1" ;;
*)
echo "$1 is unknow compress format";;
esac
)
# Download lzo source code packet
if [ ! -s $LZO.tar.gz ] ; then
wget http://www.oberhumer.com/opensource/lzo/download/$LZO.tar.gz
fi
# Decompress lzo source code packet
if [ ! -d $LZO ] ; then
decompress_packet $LZO.tar.*
fi
# Cross compile lzo
cd $LZO
if [ ! -s src/.libs/liblzo*.a ] ; then
unset LDFLAGS
./configure --enable-static --disable-shared
make
fi
cd -
echo "+----------------------------------------+"
echo "| Cross compile $ZLIB now "
echo "| Crosstool: $CROSS"
echo "+----------------------------------------+"
# Download zlib source code packet
if [ ! -s $ZLIB.tar* ] ; then
#wget http://www.zlib.net/$ZLIB.tar.gz
#wget http://www.imagemagick.org/download/delegates/$ZLIB.tar.bz2
#wget http://down1.chinaunix.net/distfiles/$ZLIB.tar.bz2
wget http://pkgs.fedoraproject.org/repo/pkgs/zlib/zlib-1.2.5.tar.bz2/be1e89810e66150f5b0327984d8625a0/$ZLIB.tar.bz2
fi
# Decompress zlib source code packet
if [ ! -d $ZLIB ] ; then
decompress_packet $ZLIB.tar.*
fi
#Cross compile zlib
cd $ZLIB
if [ ! -s libz.a ] ; then
unset LDFLAGS
./configure --static
make
fi
cd -
echo "+----------------------------------------+"
echo "| Cross compile e2fsprogsV$e2fsprogs_ver now "
echo "| Crosstool: $CROSS"
echo "+----------------------------------------+"
#e2fsprogs is for UBIFS, download e2fsprogs source code packet
if [ ! -s e2fsprogs-$e2fsprogs_ver.tar.gz ] ; then
wget http://nchc.dl.sourceforge.net/project/e2fsprogs/e2fsprogs/$e2fsprogs_ver/e2fsprogs-$e2fsprogs_ver.tar.gz
fi
# Decompress e2fsprogs source code packet
if [ ! -d e2fsprogs-$e2fsprogs_ver ] ; then
decompress_packet e2fsprogs-$e2fsprogs_ver.tar.*
fi
cd e2fsprogs-$e2fsprogs_ver
if [ ! -s lib/libuuid.a ] ; then
./configure --enable-elf-shlibs
make
fi
cd -
echo "+----------------------------------------+"
echo "| Cross compile mtd-utils now "
echo "| Crosstool: $CROSS"
echo "+----------------------------------------+"
if [ ! -s ${mtd}.tar.bz2 ] ; then
wget ftp://ftp.infradead.org/pub/mtd-utils/${mtd}.tar.bz2
fi
decompress_packet ${mtd}.tar.bz2
# download mtd-utils source code
#if [ ! -d mtd-utils* ] ; then
#git clone git://git.infradead.org/mtd-utils.git
#fi
cd ${mtd}
#Add the CROSS tool in file common.mk
line=`sed -n '/CFLAGS ?= -O2 -g/=' common.mk `
if [ ! -z $line ] ; then
sed -i -e ${line}s"|.*|CFLAGS ?= -O2 -g --static|" common.mk
fi
unset LDFLAGS
unset CFLAGS
set -x
export CFLAGS="-DWITHOUT_XATTR -I$PRJ_PATH/$ZLIB -I$PRJ_PATH/$LZO/include -I$PRJ_PATH/e2fsprogs-$e2fsprogs_ver/lib"
export ZLIBLDFLAGS=-L$PRJ_PATH/$ZLIB
export LZOLDFLAGS=-L$PRJ_PATH/$LZO/src/.libs/
export LDFLAGS="-static -L $PRJ_PATH/e2fsprogs-$e2fsprogs_ver/lib $ZLIBLDFLAGS $LZOLDFLAGS"
make
set -x
#strip nandwrite flash_erase nanddump
#sudo cp nandwrite $INST_PATH/.nandwrite
#sudo cp flash_erase $INST_PATH/.flash_erase
#sudo cp nanddump $INST_PATH/.nanddump
[hongfuhao@vboxcentos6 mtd-utiles]$ ls
build.sh
[hongfuhao@vboxcentos6 mtd-utiles]$sh build.sh
过程省略。。。
[hongfuhao@vboxcentos6 mtd-utiles]$ ls
build_ubifs.sh e2fsprogs-1.42.tar.gz lzo-2.04.tar.gz mtd-utils-1.4.9.tar.bz2 zlib-1.2.5.tar.bz2
e2fsprogs-1.42 lzo-2.04 mtd-utils-1.4.9 zlib-1.2.5
[hongfuhao@vboxcentos6 mtd-utiles]$ cd mtd-utils-1.4.9
[hongfuhao@vboxcentos6 mtd-utils-1.4.9]$ ls
common.mk doc_loadbios.c flash_otp_dump.o jffs2dump mkfs.jffs2.o nftldump.c rfdformat.o
compr.c doc_loadbios.o flash_otp_info jffs2dump.c mkfs.ubifs nftldump.o serve_image
compr.h feature-removal-schedule.txt flash_otp_info.c jffs2dump.o mtd_debug nftl_format serve_image.c
compr_lzo.c fectest.c flash_otp_info.o jffs2reader mtd_debug.c nftl_format.c serve_image.o
compr_lzo.o flashcp flash_otp_lock.c jffs2reader.c mtd_debug.o nftl_format.o summary.h
compr.o flashcp.c flash_otp_write.c jffs2reader.o mtd-utils.spec rbtree.c sumtool
compr_rtime.c flashcp.o flash_unlock jffs-dump.c nanddump rbtree.h sumtool.c
compr_rtime.o flash_erase flash_unlock.c lib nanddump.c rbtree.o sumtool.o
compr_zlib.c flash_eraseall flash_unlock.o load_nandsim.sh nanddump.o recv_image tests
compr_zlib.o flash_erase.c ftl_check make_a_release.sh nandtest recv_image.c ubi-utils
COPYING flash_erase.o ftl_check.c MAKEDEV nandtest.c recv_image.o
device_table.txt flash_lock ftl_check.o Makefile nandtest.o rfddump
docfdisk flash_lock.c ftl_format mcast_image.h nandwrite rfddump.c
docfdisk.c flash_lock.o ftl_format.c mkfs.jffs2 nandwrite.c rfddump.o
docfdisk.o flash_otp_dump ftl_format.o mkfs.jffs2.1 nandwrite.o rfdformat
doc_loadbios flash_otp_dump.c include mkfs.jffs2.c nftldump rfdformat.c
[hongfuhao@vboxcentos6 mtd-utils-1.4.9]$ ls mkfs.ubifs/
compr.c compr.o crc16.c crc16.o devtable.c hashtable lpt.c lpt.o mkfs.ubifs.c mkfs.ubifs.o ubifs.h
compr.h COPYING crc16.h defs.h devtable.o key.h lpt.h mkfs.ubifs mkfs.ubifs.h README ubifs-media.h
[hongfuhao@vboxcentos6 mtd-utils-1.4.9]$ file mkfs.jffs2
mkfs.jffs2: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, not stripped
[hongfuhao@vboxcentos6 mtd-utils-1.4.9]$ sudo cp mkfs.jffs2 /usr/local/bin/
[hongfuhao@vboxcentos6 mtd-utils-1.4.9]$ mkfs.jffs2 -V
mkfs.jffs2: error!: revision 1.60
[hongfuhao@vboxcentos6 mtd-utils-1.4.9]$ mkfs.jffs2
mkfs.jffs2: error!: Usage: mkfs.jffs2 [OPTIONS]
Make a JFFS2 file system image from an existing directory tree
Options:
-p, --pad[=SIZE] Pad output to SIZE bytes with 0xFF. If SIZE is
not specified, the output is padded to the end of
the final erase block
-r, -d, --root=DIR Build file system from directory DIR (default: cwd)
-s, --pagesize=SIZE Use page size (max data node size) SIZE (default: 4KiB)
-e, --eraseblock=SIZE Use erase block size SIZE (default: 64KiB)
-c, --cleanmarker=SIZE Size of cleanmarker (default 12)
-m, --compr-mode=MODE Select compression mode (default: priortiry)
-x, --disable-compressor=COMPRESSOR_NAME
Disable a compressor
-X, --enable-compressor=COMPRESSOR_NAME
Enable a compressor
-y, --compressor-priority=PRIORITY:COMPRESSOR_NAME
Set the priority of a compressor
-L, --list-compressors Show the list of the avaiable compressors
-t, --test-compression Call decompress and compare with the original (for test)
-n, --no-cleanmarkers Don't add a cleanmarker to every eraseblock
-o, --output=FILE Output to FILE (default: stdout)
-l, --little-endian Create a little-endian filesystem
-b, --big-endian Create a big-endian filesystem
-D, --devtable=FILE Use the named FILE as a device table file
-f, --faketime Change all file times to '0' for regression testing
-q, --squash Squash permissions and owners making all files be owned by root
-U, --squash-uids Squash owners making all files be owned by root
-P, --squash-perms Squash permissions on all files
-h, --help Display this help text
-v, --verbose Verbose operation
-V, --version Display version information
-i, --incremental=FILE Parse FILE and generate appendage output for it
4.制作映像文件
[hongfuhao@vboxcentos6 rootfs]$ sudo /usr/local/bin/mkfs.jffs2 -n -s 2048 -e 128KiB -d rootfs -o rootfs.jffs2 --pad=0x1400000
[hongfuhao@vboxcentos6 rootfs]$ du -h rootfs.jffs2
20M rootfs.jffs2
5.添加uboot对jffs2支持
DRAM: 64 MiB
NAND: 256 MiB
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
[fl2440@lingyun]# set bjffs2 'tftp 30008000 rootfs.jffs2;nand erase 1000000 4000000;nand write.jffs2 30008000 1000000 1400000'
[fl2440@lingyun]# set bootargs_jffs2 'noinitrd root=/dev/mtdblock2 rootfstype=jffs2 init=/linuxrc console=ttyS0,115200'
[fl2440@lingyun]# set bootargs 'noinitrd root=/dev/mtdblock2 rootfstype=jffs2 init=/linuxrc console=ttyS0,115200'
[fl2440@lingyun]# set bootcmd_jffs2 'nand read 30008000 100000 400000;bootm 30008000'
[fl2440@lingyun]# set bootcmd 'run bootcmd_jffs2'
[fl2440@lingyun]# save
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x60000 -- 100% complete.
Writing to Nand... done
[fl2440@lingyun]# run bkr
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.2; our IP address is 192.168.1.168
Filename 'linuxrom-s3c2440.bin'.
Load address: 0x30008000
Loading: T #################################################################
#################################################################
###############################
done
Bytes transferred = 2354328 (23ec98 hex)
NAND erase: device 0 offset 0x100000, size 0x8000000
Skipping bad block at 0x00700000
Skipping bad block at 0x053a0000
Erasing at 0x80e0000 -- 100% complete.
OK
NAND write: device 0 offset 0x100000, size 0x800000
Skip bad block 0x00700000
8388608 bytes written: OK
[fl2440@lingyun]# run bjffs2
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.2; our IP address is 192.168.1.168
Filename 'rootfs.jffs2'.
Load address: 0x30008000
Loading: #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
################################################################
done
Bytes transferred = 20971520 (1400000 hex)
NAND erase: device 0 offset 0x1000000, size 0x4000000
Erasing at 0x4fe0000 -- 100% complete.
OK
NAND write: device 0 offset 0x1000000, size 0x1400000
20971520 bytes written: OK
## Booting kernel from Legacy Image at 30008000 ...
Image Name: Linux Kernel
Created: 2016-07-22 13:00:43 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2264780 Bytes = 2.2 MiB
Load Address: 30008040
Entry Point: 30008040
Verifying Checksum ... OK
Loading Kernel Image from 30008040 to 30008040... OK
OK
OS entry point: 30008040
Image entry point=30008040
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
Linux version 3.0.0 (leiyuxing@centos6.7.localdomain) (gcc version 4.5.4 (Buildroot 2012.08) ) #7 Fri Jul 22 21:00:28 CST 2016
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: SMDK2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, Copyright 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 on. Total pages: 16256
Kernel command line: noinitrd root=/dev/mtdblock2 rootfstype=jffs2 init=/linuxrc console=ttyS0,115200
PID hash table entries: 256 (order: -2, 1024 bytes)
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: 60184k/60184k available, 5352k reserved, 0K highmem
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
DMA : 0xffc00000 - 0xffe00000 ( 2 MB)
vmalloc : 0xc4800000 - 0xf6000000 ( 792 MB)
lowmem : 0xc0000000 - 0xc4000000 ( 64 MB)
modules : 0xbf000000 - 0xc0000000 ( 16 MB)
.init : 0xc0008000 - 0xc0029000 ( 132 kB)
.text : 0xc0029000 - 0xc0442000 (4196 kB)
.data : 0xc0442000 - 0xc0465d40 ( 144 kB)
.bss : 0xc0465d64 - 0xc049da70 ( 224 kB)
SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS:85
irq: clearing subpending status 00000003
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttyS0] enabled
Calibrating delay loop... 201.52 BogoMIPS (lpj=503808)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
gpiochip_add: gpios 288..303 (GPIOK) failed to register
gpiochip_add: gpios 320..334 (GPIOL) failed to register
gpiochip_add: gpios 352..353 (GPIOM) failed to register
NET: Registered protocol family 16
S3C Power Management, Copyright 2004 Simtec Electronics
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C244X: Clock Support, DVS off
bio: create slab <bio-0> at 0
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
Advanced Linux Sound Architecture Driver Version 1.0.24.
cfg80211: Calling CRDA to update world regulatory domain
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
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
NetWinder Floating Point Emulator V0.97 (extended precision)
NTFS driver 2.1.30 [Flags: R/W].
JFFS2 version 2.2. (NAND) 漏 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 117
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
s3c2440-uart.0: ttyS0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: ttyS1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: ttyS2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
loop: module loaded
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 56 at 0x000000700000
Bad eraseblock 669 at 0x0000053a0000
Bad eraseblock 1800 at 0x00000e100000
Creating 6 MTD partitions on "NAND":
0x000000000000-0x000000100000 : "mtdblock0 u-boot 1MB"
0x000000100000-0x000001000000 : "mtdblock1 kernel 15MB"
0x000001000000-0x000005000000 : "mtdblock2 rootfs 64MB"
0x000005000000-0x00000a000000 : "mtdblock3 apps 80MB"
0x00000a000000-0x00000d000000 : "mtdblock4 data 48MB"
0x00000d000000-0x000010000000 : "mtdblock5 backup 48MB"
dm9000 Ethernet Driver, V1.31
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
s3c2410_udc: debugfs dir creation failed -19
mousedev: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
i2c /dev entries driver
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
ALSA device list:
No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
lib80211: common routines for IEEE802.11 drivers
Registering the dns_resolver key type
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
usb 1-1: new full speed USB device number 2 using s3c2410-ohci
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
VFS: Mounted root (jffs2 filesystem) on device 31:2.
Freeing init memory: 132K
Copyright (C) 2016 Reagan