怎么制作cramfs文件系统

如何制作cramfs文件系统

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

作        者:郭文学、fulinux

版权所有:郭文学、fulinux

装载声明:

http://blog.****.net/sonbai/article/details/8785038

http://blog.****.net/sonbai/article/details/8785146

http://blog.****.net/sonbai/article/details/8784808

http://blog.****.net/sonbai/article/details/8784046

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

cramfs的特点



在嵌入式的环境之下,内存和外存资源都需要节约使用。如果使用RAMDISK方式来使用文件系统,那么在系 


统运行之后,
首先要把外存(Flash)上的映像文件解压缩到内存中,构造起RAMDISK环境,才可以开始运行程序。但是它也


有很致命的弱点
。在正常情 况下,同样的代码不仅在外存中占据了空间(以压缩后的形式存在),而且还在内存中占用了更大


的空间
(以解压缩之后的形式存在),这违背了嵌入式环境下尽量 节省资源的要求。


使用cramfs就是一种解决这个问题的方式。cramfs是一个压缩式的文件系统,它并不需要一次性地将文件系


统中的所有内容
都解压缩到内存之中,而只是在系统需要访问某个位置的数据的时侯,马上计算出该数据在cramfs中的位置


,将其实时地解
压缩到内存之中,然后通 过对内存的访问来获取文件系统中需要读取的数据。cramfs中的解压缩以及解压缩


之后的内存中
数据存放位置都是由cramfs文件系统本身进行维护的, 用户并不需要了解具体的实现过程,因此这种方式增


强了透明度,
对开发人员来说,既方便,又节省了存储空间。


cramfs拥有以下一些特性:


采用实时解压缩方式,但解压缩的时侯有延迟。


cramfs的数据都是经过处理、打包的,对其进先写操作有一定困难。所以cramfs不支持写操作,这个特性刚


好适合嵌入式
应用中使用Flash存储文件系统的场合。


在cramfs中,文件最大不能超过16MB。


支持组标识(gid),但是mkcramfs只将gid的低8位保存下来,因此只有这8位是有效的。


支持硬链接。但是cramfs并没有完全处理好,硬链接的文件属性中,链接数仍然为1.


cramfs的目录中,没有“.”和“..”这两项。因此,cramfs中的目录的链接数通常也仅有一个。


cramfs中,不会保存文件的时间戳(timestamps)信息。当然,正在使用的文件由于inode保存在内存中,因此


其时间可以暂时地
变更为最新时间,但是不会保存到cramfs文件系统中去。


当前版本的cramfs只支持PAGE_CACHE_SIZE为4096的内核。因此,如果发现cramfs不能正常读写的时侯,可以


检查一下内核的参数设置。










Linux "make menuconfig"选择
  File systems  --->
      Miscellaneous filesystems  --->
           <*> Compressed ROM file system support (cramfs)




下载cramfs-1.1.tar.gz(网上能找到的版本) 
http://download.chinaunix.net/download/0002000/1832.shtml 
http://sourceforge.net/projects/cramfs/files/cramfs/


[root:/usr/local/apps_src]#tar -xzf ~/winxp/apps_packet/cramfs-1.1.tar.gz 
[root:/usr/local/apps_src]#cd cramfs-1.1/
[root:/usr/local/apps_src/cramfs-1.1]#ls
COPYING  cramfsck.c  GNUmakefile  linux  mkcramfs.c  NOTES  README
[root:/usr/local/apps_src/cramfs-1.1]#make
gcc -W -Wall -O2 -g -I.   mkcramfs.c  -lz -o mkcramfs
mkcramfs.c: In function 'parse_directory':
mkcramfs.c:287: warning: pointer targets in assignment differ in signedness
mkcramfs.c: In function 'write_superblock':
mkcramfs.c:399: warning: pointer targets in passing argument 1 of '__builtin_strncpy' differ in 


signedness
mkcramfs.c:401: warning: pointer targets in passing argument 1 of '__builtin_strncpy' differ in 


signedness
mkcramfs.c: In function 'write_directory_structure':
mkcramfs.c:480: warning: pointer targets in passing argument 1 of 'strlen' differ in signedness
mkcramfs.c: In function 'do_compress':
mkcramfs.c:598: warning: pointer targets in passing argument 1 of 'compress2' differ in 


signedness
mkcramfs.c:598: warning: pointer targets in passing argument 3 of 'compress2' differ in 


signedness
mkcramfs.c: In function 'write_data':
mkcramfs.c:647: warning: pointer targets in passing argument 3 of 'do_compress' differ in 


signedness
mkcramfs.c: In function 'main':
mkcramfs.c:825: warning: pointer targets in passing argument 2 of 'crc32' differ in signedness
gcc -W -Wall -O2 -g -I.   cramfsck.c  -lz -o cramfsck
[root:/usr/local/apps_src/cramfs-1.1]#ls
COPYING  cramfsck  cramfsck.c  GNUmakefile  linux  mkcramfs  mkcramfs.c  NOTES  README
[root:/usr/local/apps_src/cramfs-1.1]#file mkcramfs
mkcramfs: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, 


dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
[root:/usr/local/apps_src/cramfs-1.1]#mv mkcramfs /usr/local/bin/
[root:/usr/local/apps_src/cramfs-1.1]#mkcramfs 
usage: mkcramfs [-h] [-e edition] [-i file] [-n name] dirname outfile
 -h         print this help
 -E         make all warnings errors (non-zero exit status)
 -e edition set edition number (part of fsid)
 -i file    insert a file image into the filesystem (requires >= 2.4.0)
 -n name    set name of cramfs filesystem
 -p         pad by 512 bytes for boot code
 -s         sort directory entries (old option, ignored)
 -v         be more verbose
 -z         make explicit holes (requires >= 2.3.39)
 dirname    root of the directory tree to be compressed
 outfile    output file
 [root:/usr/local/apps_src/cramfs-1.1]#




注:
如果编译出现下面错误:
[lingyun@localhost cramfs-1.1]$ make
gcc -W -Wall -O2 -g -I.   mkcramfs.c  -lz -o mkcramfs
mkcramfs.c:37:18: error: zlib.h: No such file or directory
这是因为cramfs依赖zlib这个第三方库,这时我们可以使用yum来安装它:
sudo yum install -y zlib*


制作根文件系统:


参考制作根文件系统的howto文档,制作根文件系统/opt/rootfs:
[root:/opt]#ls rootfs
apps  bin  data  dev  etc  info  lib  linuxrc  mnt  proc  root  sbin  sys  tmp  usr  var
[root:/opt]#cd rootfs/dev/
[root:dev]#sudo mknod mtdblock0 b 31 0
[root:dev]#sudo mknod mtdblock1 b 31 1
[root:dev]#sudo mknod mtdblock2 b 31 2
[root:dev]#sudo mknod mtdblock3 b 31 3
注:
以上mtdblockx的个数是根据你内核中分区表信息来创建的,看下这个
http://blog.****.net/sonbai/article/details/8717574


[root:dev]#sudo mknod -m 755 mtd0 c 90 0
。。。。。。
。。。。。。
[root:dev]#ll
total 4
crwxr-xr-x 1 root root  5,  1 Mar 28 14:11 console
crwxr-xr-x 1 root root  1, 11 Apr 10 15:49 kmsg
crw-r--r-- 1 root root  1,  1 Apr 10 15:24 mem
crwxr-xr-x 1 root root 90,  0 Apr 10 15:46 mtd0
crwxr-xr-x 1 root root 90,  1 Apr 10 15:46 mtd0ro
crwxr-xr-x 1 root root 90,  2 Apr 10 15:46 mtd1
crwxr-xr-x 1 root root 90,  3 Apr 10 15:47 mtd1ro
crwxr-xr-x 1 root root 90,  4 Apr 10 15:47 mtd2
crwxr-xr-x 1 root root 90,  5 Apr 10 15:47 mtd2ro
brw-r--r-- 1 root root 31,  0 Apr 10 15:12 mtdblock0
brw-r--r-- 1 root root 31,  1 Apr 10 15:13 mtdblock1
brw-r--r-- 1 root root 31,  2 Apr 10 15:13 mtdblock2
crwxr-xr-x 1 root root  1,  3 Mar 28 14:12 null
drwxr-xr-x 2 root root   4096 Apr 10 15:49 pts
crw-r--r-- 1 root root  1,  8 Apr 10 15:24 random
crw-r--r-- 1 root root  5,  0 Apr 10 15:23 tty
crwxr-xr-x 1 root root  4,  0 Apr 10 15:51 tty0
crwxr-xr-x 1 root root  4,  1 Apr 10 15:51 tty1
crwxr-xr-x 1 root root  4,  2 Apr 10 15:51 tty2
crwxr-xr-x 1 root root  4,  3 Apr 10 15:51 tty3
crwxr-xr-x 1 root root  4,  4 Apr 10 15:51 tty4
crwxr-xr-x 1 root root  4, 64 Mar 28 14:12 ttyS0
crwxr-xr-x 1 root root  4, 64 Mar 28 14:12 ttySAC0
crw-r--r-- 1 root root  1,  9 Apr 10 15:24 urandom
crw-r--r-- 1 root root  1,  5 Apr 10 15:23 zero
注:
以上设备节点都要创建,可以根据上面的信息自行创建


[root:/opt]#mkcramfs rootfs rootfs.cramfs
Directory data: 6688 bytes
Everything: 1496 kilobytes
Super block: 76 bytes
CRC: 20b31044
[root:/opt]#du -h rootfs.cramfs 
1.5M    rootfs.cramfs






烧录并启动:




参考内核分区:
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"




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 ]# pri
baudrate=115200
ethaddr=08:00:3e:26:0a:6b
ethact=dm9000
bootdelay=1
filesize=176000
fileaddr=30800000
netmask=255.255.255.0
ipaddr=192.168.1.244
serverip=192.168.1.155
bkr=tftp 30008000 uImage-s3c2440.gz;nand erase 100000 300000;nand write 30008000 100000 300000
bcramfs=tftp 30800000 rootfs.cramfs;nand erase 01000000 a00000;nand write 30800000 01000000 


a00000
bootcmd=nand read 30008000 100000 300000;bootm 30008000
bootargs=noinitrd root=/dev/mtdblock3 rootfstype=cramfs init=/linuxrc console=ttyS0,115200 


mem=64M loglevel=7
stdin=serial
stdout=serial
stderr=serial


Environment size: 569/131068 bytes
[ 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 bcramfs
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.cramfs'.
Load address: 0x30800000
Loading: T #################################################################
         ########################################
done
Bytes transferred = 1531904 (176000 hex)


NAND erase: device 0 offset 0x1000000, size 0xa00000
Skipping bad block at  0x01860000                                          
Erasing at 0x19e0000 -- 100% complete.
OK


NAND write: device 0 offset 0x1000000, size 0xa00000
Skip bad block 0x01860000
 10485760 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 on, UPLL on
CPU0: D VIVT write-back cache
CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: noinitrd root=/dev/mtdblock3 rootfstype=cramfs init=/linuxrc 


console=ttyS0,115200 mem=64M loglevel=7
irq: clearing pending ext status 00080000
irq: clearing subpending status 00000003
irq: clearing subpending status 00000002
PID hash table entries: 256 (order: 8, 1024 bytes)
timer tcon=00500000, tcnt a4ca, tcfg 00000200,00000000, usec 00001e57
Console: colour dummy device 80x30
console [ttyS0] enabled
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: 61068KB available (3336K code, 307K data, 132K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 64 bytes
NET: Registered protocol family 16
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C2440: Clock Support, DVS off
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4800000, irq 33
DMA channel 1 at c4800040, irq 34
DMA channel 2 at c4800080, irq 35
DMA channel 3 at c48000c0, irq 36
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
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
NetWinder Floating Point Emulator V0.97 (extended precision)
Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
JFFS2 version 2.2. (NAND) (SUMMARY)  ?? 2001-2006 Red Hat, Inc.
io scheduler noop registered
io scheduler anticipatory registered
io scheduler deadline registered
io scheduler cfq registered (default)
Console: switching to colour frame buffer device 30x40
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
RAMDISK driver initialized: 1 RAM disks of 16384K size 1024 blocksize
loop: module loaded
PPP generic driver version 2.4.2
PPP Deflate Compression module registered
PPP BSD Compression module registered
PPP MPPE Compression module registered
NET: Registered protocol family 24
PPPoL2TP kernel driver, V1.0
tun: Universal TUN/TAP device driver, 1.6
tun: (C) 1999-2004 Max Krasnyansky <maxk@qualcomm.com>
dm9000 Ethernet Driver
eth0: dm9000 at c485e300,c4860304 IRQ 51 MAC: 08:00:3e:26:0a:6b
Loading iSCSI transport class v2.0-724.
Driver 'sd' needs updating - please use bus_type methods
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 195 at 0x01860000
Bad eraseblock 410 at 0x03340000
Bad eraseblock 989 at 0x07ba0000
Bad eraseblock 1047 at 0x082e0000
Creating 9 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x00000000-0x00100000 : "mtdblock0 uboot 1MB"
0x00100000-0x00600000 : "mtdblock1 kernel 5MB"
0x00600000-0x01000000 : "mtdblock2 ramdisk 10MB"
0x01000000-0x01a00000 : "mtdblock3 cramfs 10MB"
0x01a00000-0x02e00000 : "mtdblock4 yaffs 20MB"
0x02e00000-0x04200000 : "mtdblock5 jffs 20MB"
0x04200000-0x05600000 : "mtdblock6 apps 20MB"
0x05600000-0x06a00000 : "mtdblock7 info 20MB"
0x06a00000-0x09200000 : "mtdblock8 data 40MB"
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
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
Initializing USB Mass Storage driver...
usb 1-1: new full speed USB device using s3c2410-ohci and address 2
usb 1-1: configuration #1 chosen from 1 choice
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usbcore: registered new interface driver libusual
usbcore: registered new interface driver usbserial
drivers/usb/serial/usb-serial.c: USB Serial Driver core
drivers/usb/serial/usb-serial.c: USB Serial support registered for GSM modem (1-port)
usbcore: registered new interface driver option
drivers/usb/serial/option.c: USB Driver for GSM modems: v0.7.1
mice: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
Advanced Linux Sound Architecture Driver Version 1.0.15 (Tue Nov 20 19:16:42 2007 UTC).
ASoC version 0.13.1
ALSA device list:
  No soundcards found.
TCP cubic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
ieee80211: 802.11 data/management/control stack, git-1.1.13
ieee80211: Copyright (C) 2004-2005 Intel Corporation <jketreno@linux.intel.com>
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
VFS: Mounted root (cramfs filesystem) readonly.
Freeing init memory: 132K
eth0: link down


eth0: link up, 100Mbps, full-duplex, lpa 0x45E1


Copyright (C) 2011 GuoWenxue<guowenxue@gmail.com>


root login: root
Password: 
>: ls
apps     data     etc      lib      mnt      root     sys      usr
bin      dev      info     linuxrc  proc     sbin     tmp      var

>: 


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

作        者:郭文学、fulinux

版权所有:郭文学、fulinux

装载声明:

http://blog.****.net/sonbai/article/details/8785038

http://blog.****.net/sonbai/article/details/8785146

http://blog.****.net/sonbai/article/details/8784808

http://blog.****.net/sonbai/article/details/8784046

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