对根文件系统无需修改,只需要添加内核对jffs2文件系统的支持。
[[email protected]]$ vt100
[[email protected]]$ make menuconfig
Filesystems --->
[*]Miscellaneous filesystems --->
<*> Journalling Flash File System v2 (JFFS2)support
(0) JFFS2 debugging verbosity (0 = quiet, 2 =noisy)
[*] JFFS2 write-buffering support
[ ] Verify JFFS2 write-buffer reads
[ ] JFFS2 summary support (EXPERIMENTAL)
[ ] JFFS2 XATTR support (EXPERIMENTAL)
[ ] Advanced compression options for JFFS2
[[email protected]]$ sudo make
[[email protected]]$ cp uImage-s3c2440.gz/tftp/yz_jfs2uImage-2440.gz
制作mkfs.jffs2和mkfs.ubifs工具
[lingyun@localhostyangzheng]$ mkdir mtd-utiles
[lingyun@localhostyangzheng]$ cd mtd-utiles/
[lingyun@localhostmtd-utiles]$ vim build.sh
#!/bin/sh
#+--------------------------------------------------------------------------------------------
#|Description: This shellscript used to download lzo,zlib,mtd-utils source code
#| and crosscompile it for ARM Linux, all is static cross compile.
#| Author: yangzheng <[email protected]>
#| ChangeLog:
#| 1, Initialize 1.0.0on 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: Ziparchive"*)
unzip"$1" ;;
"$1: gzip compressed"*)
if [ `expr"$1" : ".*.tar.*" ` ] ; then
tar -xzf $1
else
gzip -d"$1"
fi ;;
"$1: bzip2compressed"*)
if [ `expr"$1" : ".*.tar.*" ` ] ; then
tar -xjf $1
else
bunzip2"$1"
fi ;;
"$1: POSIX tararchive"*)
tar -xf"$1" ;;
*)
echo "$1 isunknow compress format";;
esac
)
# Download lzo source code packet
if [ ! -s $LZO.tar.gz ] ; then
wgethttp://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
#wgethttp://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 compilee2fsprogsV$e2fsprogs_ver now "
echo "| Crosstool: $CROSS"
echo "+----------------------------------------+"
#e2fsprogs is for UBIFS, download e2fsprogs source code packet
if [ ! -s e2fsprogs-$e2fsprogs_ver.tar.gz ] ; then
wgethttp://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_packete2fsprogs-$e2fsprogs_ver.tar.*
fi
cd e2fsprogs-$e2fsprogs_ver
if [ ! -s lib/libuuid.a ] ; then
./configure--enable-elf-shlibs
make
fi
cd -
echo "+----------------------------------------+"
echo "| Cross compilemtd-utils now "
echo "| Crosstool: $CROSS"
echo "+----------------------------------------+"
if [ ! -s ${mtd}.tar.bz2 ] ; then
wgetftp://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 clonegit://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
[lingyun@localhostmtd-utiles]$ sh build.sh
[lingyun@localhostmtd-utiles]$ ls
build.sh e2fsprogs-1.42.tar.gz lzo-2.04.tar.gz mtd-utils-1.4.9.tar.bz2 zlib-1.2.7.tar.gz
e2fsprogs-1.42 lzo-2.04 mtd-utils-1.4.9 zlib-1.2.7
[[email protected]]$ file mkfs.jffs2
mkfs.jffs2:ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked,not stripped
[[email protected]]$ sudo cp mkfs.jffs2 /usr/local/bin/
制作镜像文件:
[lingyun@localhostyangzheng]$ sudo mkfs.jffs2 -n -s 2048 -e 128KiB -d rootfs -o rootfs.jffs2--pad=0x1400000
[lingyun@localhostyangzheng]$ ls
busybox-1.20.2 linux-3.0 mkimage mtd-utiles rootfs rootfs.jffs2
busybox-1.20.2.tar.bz2 linux-3.0.tar.bz2 mnt ramdisk.gz rootfs.cramfs
[lingyun@localhostyangzheng]$ du -h rootfs.jffs2
20M rootfs.jffs2
[lingyun@localhostyangzheng]$ cp rootfs.jffs2 /tftp/
各参数的意义:
(1)-r :指定根文件系统目录.
(2)-o : 指定输出的根文件系统名.
(3)-s : 指定flash每一页的大小;
(3)-e : 指定flash的檫除块的大小,預設是64KB.
要注意,不同的flash, 其page size和block size會不一樣.,如果是K9F2G08U0M,在它的datasheet上有说明:
1 Page = (2K+64)Bytes
1 Block = (2K+64)Bytes = (128K+4K) Bytes
1 Device = (2K+64)B * 64Pages * 2048 Blocks = 2112 Mbits
所以上面指定:"s 2048 -e 128KiB"。
如果是K9F1208U0C,在它的datasheet上有说明:
则上面指定: "s512 -e 16KiB"
(5)如果挂载后会出现类似:CLEANMARKERnode found at 0x0042c000 has totlen 0xc != normal 0x0 的警告,则加上 -n 就会消失。
(5) -n 指明不添加清除标记(nandflash 有自己的校检块,存放相关的信息。)
如果挂载后会出现类似下面的警告,则加上-n就会消失:
CLEANMARKER node found at0x0042c000 has totlen 0xc != normal 0x0
通过下面的方式可以对rootfs.jffs2映像文件中的内容进行修改,如果没有必要可以不用
[lingyun@localhost yangzheng]$ uname -a
Linux localhost.localdomain 2.6.32-279.el6.x86_64#1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
[lingyun@localhost yangzheng]]$ modprobemtdblock
FATAL: Error inserting mtdblock(/lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/mtd/mtdblock.ko):Operation not permitted
[lingyun@localhost yangzheng]$ sudomodprobe mtdblock
[lingyun@localhost yangzheng]$ sudomodprobe mtdram total_size=20480 erase_size=128
[lingyun@localhost yangzheng]$ ls/dev/mtdblock0 -l
brw-rw---- 1 root disk 31, 0 Apr 28 13:25/dev/mtdblock0
[lingyun@localhost yangzheng]$ sudo ddif=rootfs.jffs2 of=/dev/mtdblock0
40960+0 records in
40960+0 records out
20971520 bytes (21 MB) copied, 0.120246 s,174 MB/s
[lingyun@localhost yangzheng]$ ls
buildroot-2011.11 busybox-1.20.2 dropbear-0.53.1.tar.bz2 mtd pub rootfs rootfs.jffs2
buildroot-2012.08 dropbear-0.53.1 mnt mtd-utiles ramdisk.gz rootfs.cramfs rootfs_tree
[lingyun@localhost yangzheng]$ mkdir mtd
[lingyun@localhost yangzheng]$ ls mtd/
[lingyun@localhost yangzheng]$ sudo mount-t jffs2 /dev/mtdblock0 mtd/
[lingyun@localhost yangzheng]$ ls mtd/
apps bin data dev etc info init lib lingyun linuxrc mnt proc root sbin sys tmp usr var
[lingyun@localhost yangzheng]$ cd mtd
[lingyun@localhost mtd]$ sudo touchlingyun=emb
[lingyun@localhost mtd]$ ls
apps bin data dev etc info init lib lingyun lingyun=emb linuxrc mnt proc root sbin sys tmp usr var
[lingyun@localhost mtd]$ cd ../
[lingyun@localhost yangzheng]$ sudo umount/dev/mtdblock0
[lingyun@localhost yangzheng]$ ls mtd/
[lingyun@localhost yangzheng]$ cprootfs.jffs2 /tftp/
使用该方法更新后得到的文件系统在启动时会出现以下WARNING:
CLEANMARKER node found at 0x01380000 has totlen 0xc != normal 0x0
CLEANMARKER node found at 0x013a0000 has totlen 0xc != normal 0x0
添加u-boot对jffs2文件系统的支持:
[ s3c2440@ yangzheng ]# set bjffs2 'tftp 30008000 rootfs.jffs2;nanderase 1e00000 1400000;nand write.jffs2 30008000 1e00000 1400000'
[ s3c2440@ yangzheng ]# set bootargs_jffs2'noinitrd root=/dev/mtdblock4 rootfstype=jffs2 init=/linuxrcconsole=ttyS0,115200'
[ s3c2440@ yangzheng ]# set bootargs'noinitrd root=/dev/mtdblock4 rootfstype=jffs2 init=/linuxrcconsole=ttyS0,115200'
[ s3c2440@ yangzheng ]# set bootcmd 'runbootcmd_jffs2'
[ s3c2440@ yangzheng ]# set bkr 'tftp30008000 yz_jfs2uImage-2440.gz;nand erase 100000 27c1ac;nandwrite 30008000 100000 27c1ac'
[ s3c2440@ yangzheng ]# set bootcmd_jffs2'nand read 30008000 100000 27c1ac;bootm 30008000'
[ s3c2440@ yangzheng ]# sa
启动linux:
[ s3c2440@ yangzheng ]# boot
NANDread: device 0 offset 0x100000, size 0x27c800
2607104 bytes read: OK
##Booting kernel from Legacy Image at 30008000 ...
Image Name: Linux Kernel
Created: 2013-06-05 3:24:43 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2605420 Bytes = 2.5 MiB
Load Address: 30008000
Entry Point: 30008040
Verifying Checksum ... OK
XIP Kernel Image ... OK
OK
OS entrypoint: 30008040
Imageentry point=30008040
Startingkernel ...
UncompressingLinux... done, booting the kernel.
Linuxversion 3.0.0 ([email protected]) (gccversion 4.5.4 (Buildroot 2012.08) ) #6 Wed Jun 5 11:24:39 CST 2013
CPU:ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVTdata cache, VIVT instruction cache
Machine:SMDK2440
Memorypolicy: ECC disabled, Data cache writeback
CPU S3C2440A(id 0x32440001)
S3C24XX Clocks, Copyright 2004 SimtecElectronics
S3C244X: core 405.000 MHz, memory 101.250MHz, peripheral 50.625 MHz
CLOCK:Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernelcommand line: noinitrd root=/dev/mtdblock4 rootfstype=jffs2 init=/linuxrcconsole=ttyS0,115200
PID hashtable entries: 256 (order: -2, 1024 bytes)
Dentrycache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cachehash table entries: 4096 (order: 2, 16384 bytes)
Memory:64MB = 64MB total
Memory:59488k/59488k available, 6048k reserved, 0K highmem
Virtualkernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xfff00000 - 0xfffe0000 ( 896kB)
DMA : 0xffc00000 - 0xffe00000 ( 2 MB)
vmalloc : 0xc4800000 - 0xf6000000 ( 792 MB)
lowmem : 0xc0000000 - 0xc4000000 ( 64 MB)
modules : 0xbf000000 - 0xc0000000 ( 16MB)
.init : 0xc0008000 - 0xc002e000 ( 152 kB)
.text : 0xc002e000 - 0xc04f0000 (4872 kB)
.data : 0xc04f0000 - 0xc051fb20 ( 191 kB)
.bss : 0xc051fb44 - 0xc054bfa0 ( 178 kB)
NR_IRQS:85
irq:clearing pending ext status 00080000
irq:clearing subpending status 00000003
irq:clearing subpending status 00000002
Console:colour dummy device 80x30
console[ttyS0] enabled
Calibratingdelay loop... 201.52 BogoMIPS (lpj=503808)
pid_max:default: 32768 minimum: 301
Mount-cachehash 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 2004Simtec Electronics
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, Copyright 2003-2006Simtec Electronics
DMAchannel 0 at c4804000, irq 33
DMAchannel 1 at c4804040, irq 34
DMAchannel 2 at c4804080, irq 35
DMAchannel 3 at c48040c0,irq 36
S3C244X: Clock Support, DVS off
s3c-adc s3c24xx-adc: attached adc driver
bio:create slab <bio-0> at 0
SCSIsubsystem initialized
usbcore:registered new interface driver usbfs
usbcore:registered new interface driver hub
usbcore:registered new device driver usb
s3c-i2cs3c2440-i2c: slave address 0x10
s3c-i2cs3c2440-i2c: bus frequency set to 98 KHz
s3c-i2cs3c2440-i2c: i2c-0:S3C I2C adapter
AdvancedLinux Sound Architecture Driver Version 1.0.24.
cfg80211:Calling CRDA to update world regulatory domain
NET:Registered protocol family 2
IP routecache hash table entries: 1024 (order: 0, 4096 bytes)
TCPestablished hash table entries: 2048 (order: 2, 16384 bytes)
TCP bindhash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hashtables configured (established 2048 bind 2048)
TCP reno registered
UDP hashtable entries: 256 (order: 0, 4096 bytes)
UDP-Litehash 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.
NetWinderFloating Point Emulator V0.97 (extended precision)
NTFSdriver 2.1.30 [Flags: R/W].
JFFS2version 2.2. (NAND) 漏 2001-2006 Red Hat, Inc.
msgmnihas been set to 116
ioscheduler noop registered
ioscheduler deadline registered
ioscheduler cfq registered (default)
Console:switching to colour frame buffer device 60x34
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
at24 0-0050:65536 byte 24c512EEPROM, writable, 128 bytes/write
S3C24XX NAND Driver, (c) 2004 SimtecElectronics
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=329ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NANDdevice: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
Scanningdevice for bad blocks
Baderaseblock 421 at 0x0000034a0000
Baderaseblock 1177 at 0x000009320000
Baderaseblock 1727 at 0x00000d7e0000
Creating11 MTD partitions on "NAND":
0x000000000000-0x000000100000: "mtdblock0 u-boot 1MB"
0x000000100000-0x000000500000: "mtdblock1 kernel 4MB"
0x000000500000-0x000000f00000 : "mtdblock2 ramdisk10MB"
0x000000f00000-0x000001e00000 :"mtdblock3 cramfs 15MB"
0x000001e00000-0x000004600000: "mtdblock3 jffs2 40MB"
0x000004600000-0x000006e00000: "mtdblock4 yaffs2 40MB"
0x000006e00000-0x000009600000: "mtdblock5 ubifs 40MB"
0x000009600000-0x000009700000: "mtdblock6 info 1MB"
0x000009700000-0x00000bf00000: "mtdblock7 apps 40MB"
0x00000bf00000-0x00000e700000: "mtdblock8 data 40MB"
0x00000e700000-0x000010000000: "mtdblock9 backup 25MB"
PPPgeneric driver version 2.4.2
PPPDeflate Compression module registered
PPP BSDCompression module registered
PPP MPPECompression module registered
NET:Registered protocol family 24
dm9000Ethernet Driver, V1.31
eth0: dm9000a at c4864300,c4866304 IRQ 51 MAC:08:00:3e:26:0a:6b(chip)
usbcore:registered new interface driver rt2800usb
ohci_hcd:USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XXOHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned busnumber 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1:New USB device found, idVendor=1d6b, idProduct=0001
usb usb1:New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb1:Product: S3C24XXOHCI
usb usb1:Manufacturer: Linux 3.0.0 ohci_hcd
usb usb1:SerialNumber: s3c24xx
hub1-0:1.0: USB hub found
hub1-0:1.0: 2 ports detected
InitializingUSB Mass Storage driver...
usbcore:registered new interface driver usb-storage
USB MassStorage support registered.
usbcore:registered new interface driver usbserial
usbserial:USB Serial Driver core
USBSerial support registered for ch341-uart
usbcore:registered new interface driver ch341
USBSerial support registered for FTDI USB Serial Device
usbcore:registered new interface driver ftdi_sio
ftdi_sio:v1.6.0:USB FTDI Serial Converters Driver
USBSerial support registered for GSM modem (1-port)
usbcore:registered new interface driver option
option: v0.7.2:USBDriver for GSM modems
USBSerial support registered for pl2303
usbcore:registered new interface driver pl2303
pl2303:Prolific PL2303 USB to serial adaptor driver
mousedev:PS/2 mouse device common for all mice
samsung-tss3c2440-ts: driverattached, registering input device
input: S3C24XX TouchScreen as/devices/virtual/input/input0
S3C24XX RTC, (c) 2004,2006 SimtecElectronics
s3c-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
i2c /dev entries driver
s3c-sdi s3c2440-sdi: mmc0 - using pio, sw SDIO IRQ
usbcore:registered new interface driver usbhid
usbhid:USB HID core driver
S3C24XX_UDA134X SoC Audio driver
UDA134XSoC Audio Codec
asoc:uda134x-hifi <-> s3c24xx-iismapping ok
ALSAdevice list:
#0: S3C24XX_UDA134X
Netfiltermessages via NETLINK v0.30.
nf_conntrackversion 0.5.0 (929 buckets, 3716 max)
ctnetlinkv0.93: registering with nfnetlink.
xt_time:kernel timezone is -0000
ip_set:protocol 6
IPVS:Registered protocols (TCP, UDP, AH, ESP)
IPVS:Connection hash table configured (size=4096, memory=32Kbytes)
IPVS:Creating netns size=1008 id=0
IPVS:ipvs loaded.
IPVS:[rr] scheduler registered.
IPVS:[wrr] scheduler registered.
IPVS:[lc] scheduler registered.
IPVS:[wlc] scheduler registered.
IPVS:[lblc] scheduler registered.
IPVS: [lblcr]scheduler registered.
IPVS:[dh] scheduler registered.
IPVS:[sh] scheduler registered.
IPVS:[sed] scheduler registered.
IPVS:[nq] scheduler registered.
ip_tables:(C) 2000-2006 Netfilter Core Team
ipt_CLUSTERIP:ClusterIP Version 0.8 loaded successfully
arp_tables:(C) 2002 David S. Miller
TCP cubicregistered
NET:Registered protocol family 17
lib80211:common routines for IEEE802.11 drivers
Registeringthe dns_resolver key type
s3c-rtc s3c2410-rtc: setting system clock to 2047-03-2108:01:22 UTC (2436768082)
usb 1-1:new full speed USB device number 2 using s3c2410-ohci
usb 1-1:New USB device found, idVendor=05e3, idProduct=0606
usb 1-1:New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-1:Product: USB Hub 2.0
hub1-1:1.0: USB hub found
hub1-1:1.0: 4 ports detected
VFS:Mounted root (jffs2 filesystem) on device 31:4.
Freeinginit memory: 152K
dm9000dm9000.0: eth0: link down
dm9000dm9000.0: eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
Copyright(C) 2013 yangzheng<[email protected]>
rootlogin: root
>: ls
apps data etc info lib mnt root sys usr
bin dev haha init linuxrc proc sbin tmp var
>:
>: