jffs2文件系统制作

内核:                linux-3.0

uboot:             2010.09

开发板:             fl2440

交叉编译器:         2011.11

 

1.对根文件系统进行修改

无修改

2.添加内核对jffs2的支持

 

[weishusheng@localhost linux-3.0-jffs2]$ vt100
[weishusheng@localhost linux-3.0-jffs2]$ sudo 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 
                   [ ] Verify JFFS2 write-buffer reads 
                   [ ] JFFS2 summary support (EXPERIMENTAL)
                   [ ] JFFS2 XATTR support (EXPERIMENTAL)

 

                   [ ]     Advanced compression options for JFFS

[weishusheng@localhost linux-3.0-jffs2]$ sudo make

[weishusheng@localhost linux-3.0-jffs2]$ sudo cp linuxrom-mini2440-wei.bin /tftp

3.制作mkfs.jffs2和mkfs.ubifs工具

[weishusheng@localhost rootfs_tree]$ mkdir mtd-utiles

[weishusheng@localhost rootfs_tree]$ cd mtd-utiles/

[weishusheng@localhost mtd-utiles]$ sudo 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

 

 

 

[weishusheng@localhost mtd-utiles]$ ls
build.sh

 

[weishusheng@localhost mtd-utiles]$ sh build.sh

......

CC ubi-utils/ubiformat.o
CC ubi-utils/libscan.o
AR ubi-utils/libscan.a
LD ubi-utils/ubiformat
CC ubi-utils/ubirename.o
LD ubi-utils/ubirename
CC ubi-utils/mtdinfo.o
LD ubi-utils/mtdinfo
CC ubi-utils/ubirsvol.o
LD ubi-utils/ubirsvol
+ set -x
[weishusheng@localhost mtd-utiles]$ ls
build.sh e2fsprogs-1.42.tar.gz lzo-2.04.tar.gz mtd-utils-1.4.9.tar.bz2 zlib-1.2.5
e2fsprogs-1.42 lzo-2.04 mtd-utils-1.4.9 zlib-1.2.5.tar.bz2

 

[weishusheng@localhost 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

[weishusheng@localhost mtd-utils-1.4.9]$ sudo cp mkfs.jffs2 /usr/local/bin/

 

[weishusheng@localhost mtd-utils-1.4.9]$ ls /usr/local/bin/
busybox glib-mkenums lrb lsb m4 mkfs.ubifs ubinize vsyasm
glib-genmarshal gobject-query lrx lsx mkcramfs mkyaffs2image uImage-s3c2440.gz yasm
glib-gettextize iptables-xml lrz lsz mkfs.jffs2 tftp useradd.sh ytasm

4.制作映像文件

[weishusheng@localhost rootfs_tree]$ ls
build_ubifs.sh mtd-utiles rootfs-ubifs sysmnt
install_shared_library.sh ramdisk.gz rootfs-wei.cramfs ubifs-s3c2440.rootfs
mkimage rootfs 

 

[weishusheng@localhost rootfs_tree]$ sudo mkfs.jffs2 -n -l -s 2048 -e 128KiB -d rootfs -o rootfs.jffs2 --pad=0x1400000

生成了rootfs.jffs2 

 

各参数的意义:
(1)-r :指定根文件系统目录.
(2)-o : 指定输出的根文件系统名.
(3)-s : 指定flash每一页的大小;
(4)-e : 指定flash的檫除块的大小,預設是64KB.

(5)-l :小端字节存储,一般都是小端字节
要注意,不同的flash, page sizeblock size會不一樣.,如果是K9F2G08U0M,在它的datasheet上有说明:

 

[weishusheng@localhost rootfs_tree]$ mv rootfs.jffs2 rootfs-wei.jffs2 

[weishusheng@localhost rootfs_tree]$ du -h rootfs-wei.jffs2
20M rootfs-wei.jffs2

5.添加ubootjffs2支持

我的启动信息中

Creating 9 MTD partitions on "NAND":
0x000000000000-0x000000100000 : "mtdblock0 u-boot 1MB"
0x000000100000-0x000001000000 : "mtdblock1 kernel 15MB"
0x000001000000-0x000002400000 : "mtdblock2 ramdisk 20MB"
0x000002400000-0x000003800000 : "mtdblock3 cramfs 20MB"
0x000003800000-0x000006000000 : "mtdblock4 jffs2 20MB"
0x000006000000-0x000008800000 : "mtdblock5 yaffs2 40MB"
0x000008800000-0x00000b000000 : "mtdblock6 ubifs 40MB"
0x00000b000000-0x00000d800000 : "mtdblock7 apps 40MB"
0x00000d800000-0x000010000000 : "mtdblock8 data 40MB"

根据自己的分区地址及大小来做

[fl2440@weishusheng]# set bjffs2 'tftp 30008000 rootfs-wei.jffs2;nand erase 3800000 1400000;nand write.jffs2 30008000 3800000 1400000'

[fl2440@weishusheng]#set bootargs_jffs2 'noinitrd root=/dev/mtdblock4 rootfstype=jffs2 init=/linuxrc console=ttyS0,115200'

[fl2440@weishusheng]#set bootargs 'noinitrd root=/dev/mtdblock4 rootfstype=jffs2 init=/linuxrc console=ttyS0,115200'

[fl2440@weishusheng]#set bootcmd_jffs2 'nand read 30008000 100000 400000;bootm 30008000'
[fl2440@weishusheng]#set bootcmd 'run bootcmd_jffs2'

[fl2440@weishusheng]#save
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x60000 -- 100% complete.
Writing to Nand... done

 

注:上述写的大小与实际文件大小一致更好。

6.下载内核和rootfs-wei.jffs2映像文件

 

[fl2440@weishusheng]#pri
bootdelay=5
baudrate=115200
ethaddr=08:00:3e:26:0a:6b
ethact=dm9000
bcramfs=tftp 30800000 rootfs-wei.cramfs;nand erase 1300000 800000;nand write 30800000 1300000 800000
bootcmd_cramfs=nand read 30008000 100000 400000;bootm 30008000
brdfs=tftp 30008000 ramdisk.gz;nand erase 1000000 a00000;nand write 30008000 1000000 a00000
bootcmd_ramdisk=nand read 30008000 100000 400000;nand read 30800000 1000000 a00000;bootm 30008000
bootargs_ubifs=console=ttyS0,115200 mem=64M ubi.mtd=6 root=ubi0:rootfs rootwait rootfstype=ubifs rw
bootcmd_rootfs=nand read 30008000 100000 400000;bootm 30008000
filesize=3A0000
fileaddr=30008000
netmask=255.255.255.0
ipaddr=192.168.1.23
bubifs=tftp 30008000 ubifs-s3c2440.rootfs;nand erase 8800000 500000;nand write 30008000 8800000 500000
serverip=192.168.1.3
bootargs_nfs=noinitrd console=ttyS0,115200 init=/linuxrc mem=64M loglevel=7 root=/dev/nfs rw nfsroot=192.168.1.3:/home/weishusheng/rootfs_tree/rootfs ip=192.168.1.23:192.168.1.3:192.168.1.1:255.255.255.0:localhost.com:eth0:off
bkr=tftp 30008000 linuxrom-mini2440-wei.bin;nand erase 100000 800000;nand write 30008000 100000 800000
stdin=serial
stdout=serial
stderr=serial
bjffs2=tftp 30008000 rootfs-wei.jffs2;nand erase 3800000 1400000;nand write.jffs2 30008000 3800000 1400000
bootargs_jffs2=noinitrd root=/dev/mtdblock4 rootfstype=jffs2 init=/linuxrc console=ttyS0,115200
bootargs=noinitrd root=/dev/mtdblock4 rootfstype=jffs2 init=/linuxrc console=ttyS0,115200
bootcmd=run bootcmd_jffs2
bootcmd_jffs2=nand read 30008000 100000 400000;bootm 30008000

 

Environment size: 1538/131068 bytes

[fl2440@weishusheng]#run bkr

.....

[fl2440@weishusheng]#run bjffs2

.....

[fl2440@weishusheng]#boot

.....

 

 

Copyright (C) 2014 weishusheng
root login: root
Password:
>: ls
apps etc linuxrc sbin usr
bin info mnt sys var
data init proc sysmnt weishusheng
dev lib root tmp
>:

 

jffs2文件系统制作成功。

 

jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x02480000: 0x19f7 instead

遇到该问题,可能的情况有以下几种:

1、编译jffs2文件系统时eraseblock size设置的问题(即-e -s --pad等),调节就好,最后根据官方文档改为128;

2、flash有问题;

3、flash在烧写之前,并未擦除干净flash上的数据,导致脏内存出现,烧写JFFS2 镜像后,第一次启动内核会格式化没有被占用但属于那个块设备的空间,所以第一次启动要等5分钟,让内核完成这个过程。

我就是第三点,因为烧写的时候cfe会默认擦除,结果后来一跟踪代码,发现并未擦除,后来自己增加了一个擦除的命令,问题解决。

posted @ 2014-09-01 12:59  wssheng  阅读(2241)  评论(0编辑  收藏  举报