jffs2文件系统制作

来源:互联网 发布:left软件安卓版 编辑:程序博客网 时间:2024/05/22 02:20

*****************************************************************************************

环        境:linux系统(centos6.4ubuntu12.10)

开  发  板:飞凌2440或者 天嵌2440

版权所有:郭文学、fulinux

联系方式:fulinux@sina.com

装载声明:http://blog.csdn.net/sonbai/article/details/8797820

*****************************************************************************************


1、JFFS2的特点

可以看看下面的文档:

http://blog.21ic.com/user1/4071/archives/2007/39537.html


2、内核配置使其支持jffs2
Linux "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
           <*> Compressed ROM file system support (cramfs)



3、制作mkfs.jffs2工具
下载最新的mtd-utils,当然也可以从其他地方下载源码压缩包,如:
http://download.chinaunix.net/download/0008000/7062.shtml

下面是我们直接使用git从源码的主线上获取最新的版本并编译的脚步:
[root:/usr/local/apps_src]#mkdir mtd-utils
[root:/usr/local/apps_src]#cd mtd-utils/
[root:/usr/local/apps_src/mtd-utils]#nocvim 
[root:/usr/local/apps_src/mtd-utils]#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 compile.
#|     Author:  GuoWenxue <guowenxue@gmail.com>
#|  ChangeLog:
#|           1, Initialize 1.0.0>......

注:如果上面脚本运行的过程中有些问题的话可以看看mtd-utils/目录下是否有mkfs.jffs2工具,因为我们只需要mkfs.jffs2工具,如果有可以将出现的问题忽略:

jffs2文件系统制作

[root:/usr/local/apps_src/mtd-utils]#file mtd-utils/mkfs.jffs2
mtd-utils/mkfs.jffs2: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped
[root:/usr/local/apps_src/mtd-utils]#cp mtd-utils/mkfs.jffs2 /usr/local/bin/
[root:/usr/local/apps_src/mtd-utils]#mkfs.jffs2 -V
mkfs.jffs2: error!: revision 1.60


[root:/usr/local/apps_src/mtd-utils]#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>当然,我们也可以交叉编译这些工具运行在ARM Linux上,这里我们可以交叉编译得到的常用的工具还有:
flashcp flash_erase flash_eraseall flash_info flash_lock flash_unlock mkfs.jffs2 nandwrite nandtest等

4、制作根文件系统:

注:这里我们假定你已经制作好了根文件系统树,如果没有可以参考这篇文档:

http://blog.csdn.net/sonbai/article/details/8785146 ,教你制作根文件系统树

各参数的意义:
(1)-r :指定根文件系统目录.
(2)-o : 指定输出的根文件系统名.
(3)-s : 指定flash每一页的大小;
(3)-e : 指定flash的檫除块的大小,預設是64KB.
要注意,不同的flash, 其page size和block size會不一樣.,如果是K9F1208U0C,在它的datasheet上有说明:

jffs2文件系统制作

则下面指定: "s 512 -e 16KiB"

如果是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"

这里我们用的是K9F2G08U0M.

[root:/opt]#mkfs.jffs2 -n -s 2048 -e 128KiB -d rootfs -o rootfs.jffs2 --pad=0x1400000
[root:/opt]#du -h rootfs.jffs2 
20M     rootfs.jffs2

如果这里的block size设置不对的话(如将上面的-e 128Kib改成-e 0x4000),则系统启动时会给出如下警告信息:
Empty flash at 0x00003ffc ends at 0x00004000
Empty flash at 0x00007ffc ends at 0x00008000
Empty flash at 0x0000bffc ends at 0x0000c000
Empty flash at 0x0000fffc ends at 0x00010000
Empty flash at 0x00013ffc ends at 0x00014000
Empty flash at 0x00017ffc ends at 0x00018000
Empty flash at 0x0001bffc ends at 0x0001c000


(4)--pad (-p): 用16进制表示输出根文件系统image的大小,也就是rootfs.jffs2的size。很重要的是, 在Linux内核里划分
的区为多大,这个size就为多大,因为我们的Linux划分的该区为20M,所里这里大小为0x1400000.
如果指定的大小小于我们划分的分区大小,则系统启动时会打印:
Further such events for this erase block will not be printed
jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x009e0000: 0x5555 instead
jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x009e0004: 0x5555 instead
jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x009e0008: 0x7755 instead
jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x009e000c: 0x1d57 instead
jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x009e0010: 0x1551 instead
jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x009e0014: 0x64d5 instead
jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x009e0018: 0x45d5 instead
jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x009e001c: 0xdc5c instead
jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x009e0020: 0x5c45 instead
jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x009e0024: 0x7555 instead

*****************************************************************************************

环        境:linux系统(centos6.4ubuntu12.10)

开  发  板:飞凌2440或者 天嵌2440

版权所有:郭文学

联系方式:fulinux@sina.com

装载声明:http://blog.csdn.net/sonbai/article/details/8797820

*****************************************************************************************


建议在内核中的jffs2分区给20M左右,因为如果是用tftp将rootfs.jffs2下载到nandflash上的话,太大了很可能将uboot覆盖掉。


(5)如果挂载后会出现类似:CLEANMARKER node found at 0x0042c000 has totlen 0xc != normal 0x0  的警告,则加上 -n 就会消失。


(5) -n 指明不添加清除标记(nand flash 有自己的校检块,存放相关的信息。)
       如果挂载后会出现类似下面的警告,则加上-n就会消失:
       CLEANMARKER node found at 0x0042c000 has totlen 0xc != normal 0x0


5、在linux的PC上挂载jffs2根文件系统映像

注:在linux的PC上挂载jffs2根文件系统映像主要是对jffs2文件系统进行修改,你可以跳过这一步。

因为jffs2是构建于MTD设备上的文件系统,所以无法通过loop设备来挂载,但是可以通过mtdram设备来挂载。mtdram是在用RAM实现
的MTD设备,可以通过mtdblock设备来访问。使用mtdram设备很简单,只要加载mtdram和mtdblock两个内核模块即可。这两个内核模块
一般的linux内核发行版都有编译好的,直接用modprobe命令加载。
下面是具体步骤,主机环境为CentOS 6.4:
[root:/opt]#uname -a
Linux localhost 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010 i686 i686 i386 GNU/Linux


(1).加载mtdblock内核模块
[root:/opt]#modprobe mtdblock
(2).加载mtdram内核模块,将该设备的大小指定为jffs2根文件系统映像的大小,块擦除大小(即flash的块大小)指定为制作该jffs2
根文件系统时“-e”参数指定的大小,缺省为64KB。下面两个参数的单位都是KB:
[root:/opt]#modprobe mtdram total_size=20480 erase_size=128


(3).这时将出现MTD设备/dev/mtdblock0,使用dd命令将jffs2根文件系统拷贝到/dev/mtdblock0设备中:
[root:/opt]#ls /dev/mtdblock0 -l
brw-r----- 1 root disk 31, 0 Jun  1 21:59 /dev/mtdblock0
[root:/opt]#sudo dd if=rootfs.jffs2 of=/dev/mtdblock0 
40960+0 records in
40960+0 records out
20971520 bytes (21 MB) copied, 0.59659 seconds, 35.2 MB/s


(4).将保存了jffs2根文件系统的MTD设备挂载到指定的目录上。
[root:/opt]#mkdir mtd
[root:/opt]#mount -t jffs2 /dev/mtdblock0 ./mtd/




这之后就可以到/mnt/mtd目录查看、修改挂载的jffs2根文件系统了,修改后的jffs2根文件系统可以通过dd命令拷贝为一个jffs2的
映像文件。
[root:/opt]#ls mtd/
apps  bin  data  dev  etc  info  lib  linuxrc  mnt  proc  root  sbin  sys  tmp  usr  var
[root:/opt]#mkdir mtd/test
[root:/opt]#ls mtd/
apps  bin  data  dev  etc  info  lib  linuxrc  mnt  proc  root  sbin  sys  test  tmp  usr  var
[root:/opt]#dd if=/dev/mtdblock0 of=rootfs.jffs2     
40960+0 records in
40960+0 records out
20971520 bytes (21 MB) copied, 0.291989 seconds, 71.8 MB/s
[root:/opt]#umount /dev/mtdblock0
再挂载测试:
[root:/opt]#mount -t jffs2 /dev/mtdblock0 mtd/
[root:/opt]#ls mtd/
apps  bin  data  dev  etc  info  lib  linuxrc  mnt  proc  root  sbin  sys  test  tmp  usr  var
[root:/opt]#umount /dev/mtdblock0


使用该方法更新后得到的文件系统在启动时会出现以下WARNING:
CLEANMARKER node found at 0x01380000 has totlen 0xc != normal 0x0
CLEANMARKER node found at 0x013a0000 has totlen 0xc != normal 0x0




6、烧录并启动:

修改分区是在arch/arm/plat-s3c24xx/common-smdk.c文件中,可以参考这篇文档:

http://blog.csdn.net/sonbai/article/details/8717574

参考内核分区:
0x00000000-0x00100000 : "mtdblock0 uboot 1MB, 0x100000"
0x00100000-0x00600000 : "mtdblock1 kernel 5MB, 0x500000"
0x00600000-0x01000000 : "mtdblock2 ramdisk 10MB, 0xa00000"
0x01000000-0x01a00000 : "mtdblock3 cramfs 10MB, 0xa00000"
0x01a00000-0x02e00000 : "mtdblock4 yaffs 20MB, 0x1400000"
0x02e00000-0x04200000 : "mtdblock5 jffs 20MB, 0x1400000"   
0x04200000-0x05600000 : "mtdblock6 apps 20MB, 0x1400000"
0x05600000-0x06a00000 : "mtdblock7 info 20MB, 0x1400000"
0x06a00000-0x09200000 : "mtdblock8 data 40MB, 0x2800000"


这里说明下关于nand flash操作的几个常用命令的含义
nand write:向Nand Flash写入数据,如果NandFlash相应的区域有坏块,则直接报错。
nand write.jffs2:向Nand Flash写入数据,如果NandFlash相应的区域有坏块,可以跳过坏块。
nand read:读取Nand Flash相应区域的数据,如果NandFlash相应的区域有坏块,则直接报错。
nand read.jffs2s:读取Nand Flash相应区域的数据,如果NandFlash相应的区域有坏块,将对应坏块区域的缓冲填充0xff,然后跳过此坏块继续读取。
nand read.jffs2:读取Nand Flash相应区域的数据,如果NandFlash相应的区域有坏块,直接跳过坏块。
具体的参考代码参看U-BOOT源码:common/cmd_nand.c文件。

以下是用tftp烧录的方法介绍:

uboot中的参数设置,对于这次jffs2移植关注这么几个参数:

serverip=192.168.1.79#这是tftp服务器地址,

bkr=tftp 30008000 linuxrom-fulinux.bin;nand erase 100000 500000;nand write 30008000 100000 500000#这是tftp下载内核的参数(根据你的内核分区表请自行设置nand erase 和nand write后面的参数)

bjffs2=tftp 30008000 rootfs.jffs2;nand erase 2e00000 1400000;nand write 30008000 2e00000 1400000#这是tftp下载jffst2文件系统的参数(同样根据自己的情况修改)

bootargs=noinitrd root=/dev/mtdblock5 rootfstype=jffs2 init=/linuxrc console=ttyS0,115200#这是uboot传递给内核的参数

U-boot环境变量及其启动:
U-Boot 2010.09-00000-g1a87d59 (Jun 01 2011 - 21:21:30)


Modified by guowenxue for s3c2440/s3c2410 board.
DRAM:  64 MiB
Flash: 1 MiB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0 
[ s3c2440@guowenxue ]# run bkr
dm9000 i/o: 0x20000300, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:6b
could not establish link
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.155; our IP address is 192.168.1.244
Filename 'uImage-s3c2440.gz'.
Load address: 0x30008000
Loading: T #################################################################
         ############################################################
done
Bytes transferred = 1828496 (1be690 hex)


NAND erase: device 0 offset 0x100000, size 0x300000
Erasing at 0x3e0000 -- 100% complete.
OK


NAND write: device 0 offset 0x100000, size 0x300000
 3145728 bytes written: OK
[ s3c2440@guowenxue ]# run bjffs2
dm9000 i/o: 0x20000300, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:6b
could not establish link
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.155; our IP address is 192.168.1.244
Filename 'rootfs.jffs2'.
Load address: 0x30800000
Loading: T #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ######################T ###########################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ##########################################################T ######
done
Bytes transferred = 20971520 (1400000 hex)


NAND erase: device 0 offset 0x2e00000, size 0x1400000
Skipping bad block at  0x03340000                                          
Erasing at 0x41e0000 -- 100% complete.
OK


NAND write: device 0 offset 0x2e00000, size 0x1400000
Skip bad block 0x03340000
 20971520 bytes written: OK
[ s3c2440@guowenxue ]# boot


NAND read: device 0 offset 0x100000, size 0x300000
 3145728 bytes read: OK
## Booting kernel from Legacy Image at 30008000 ...
   Image Name:   Linux Kernel
   Created:      2011-05-25  12:19:50 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1828432 Bytes = 1.7 MiB
   Load Address: 30008000
   Entry Point:  30008040
   Verifying Checksum ... OK
   XIP Kernel Image ... OK
OK


Starting kernel ...


Uncompressing Linux.................................................................................................................... done, booting the kernel.
Linux version 2.6.24 (root@localhost) (gcc version 4.3.5 (Buildroot 2011.02) ) #2 Wed May 25 20:19:45 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
Machine: SMDK2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
S3C24XX Clocks, (c) 2004 Simtec Electronics
CLOCK: Slow mode (1.500 MHz), fast, MPLL>>: 


*****************************************************************************************

环        境:linux系统(centos6.4ubuntu12.10)

开  发  板:飞凌2440或者 天嵌2440

版权所有:郭文学

联系方式:fulinux@sina.com

装载声明:http://blog.csdn.net/sonbai/article/details/8797820

*****************************************************************************************

0 0