Chinaunix首页 | 论坛 | 博客
  • 博客访问: 388046
  • 博文数量: 115
  • 博客积分: 2501
  • 博客等级: 少校
  • 技术积分: 1009
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-23 17:05
文章分类

全部博文(115)

文章存档

2011年(2)

2010年(86)

2009年(27)

我的朋友

分类: 嵌入式

2010-07-25 20:24:09

一、学习环境

VMware 7.0.0Ubuntu 9.04Linux-2.6.29.1Arm-linux-gcc-4.3.2B usybox-1.13.3

二、cramfs介绍

1cramfs的特点

在嵌入式的环境之下,内存和外存资源都需要节约使用。如果使用RAMDISK方式来使用文件系统,那么在系统运行之后,首先要把外存(Flash)上的映像文件解压缩到内存中,构造起RAMDISK环境,才可以开始运行程序。但是它也有很致命的弱点。在正常情况下,同样的代码不仅在外存中占据了空间(以压缩后的形式存在),而且还在内存中占用了更大的空间(以解压缩之后的形式存在),这违背了嵌入式环境下尽量节省资源的要求。使用cramfs就是一种解决这个问题的方式。cramfs是一个压缩式的文件系统,它并不需要一次性地将文件系统中的所有内容都解压缩到内存之中,而只是在系统需要访问某个位置的数据的时侯,马上计算出该数据在cramfs中的位置,将其实时地解压缩到内存之中,然后通过对内存的访问来获取文件系统中需要读取的数据。cramfs中的解压缩以及解压缩之后的内存中数据存放位置都是由cramfs文件系统本身进行维护的,用户并不需要了解具体的实现过程,因此这种方式增强了透明度,对开发人员来说,既方便,又节省了存储空间。

cramfs拥有以下一些特性:

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

(2)cramfs的数据都是经过处理、打包的,对其进先写操作有一定困难。所以cramfs不支持写操作,这个特性刚好适合嵌入式应用中使用Flash存储文件系统的场合。

(3)、在cramfs中,文件最大不能超过16MB

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

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

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

(7)cramfs中,不会保存文件的时间戳(timestamps)信息。当然,正在使用的文件由于inode保存在内存中,因此其时间可以暂时地变更为最新时间,但是不会保存到cramfs文件系统中去。

(8)、当前版本的cramfs只支持PAGE_CACHE_SIZE4096的内核。因此,如果发现cramfs不能正常读写的时侯,可以检查一下内核的参数设置。

2、使用cramfs

可以从下载cramfs-1.1.tar.gz。然后执行

tar zxvf cramfs-1.1.tar.gz

进入解包之后生成cramfs-1.1目录,执行编译命令:

make

编译完成之后,会生成mkcramfscramfsck两个工具,其中cramfsck工具是用来创建cramfs文件系统的,而mkcramfs工具则用来进行cramfs文件系统的释放以及检查。

下面是mkcramfs的命令格式:

mkcramfs [-h] [-e edition] [-i file] [-n name] dirname outfile

mkcramfs的各个参数解释如下:

-h:显示帮助信息

-e edition:设置生成的文件系统中的版本号

-i file:将一个文件映像插入这个文件系统之中(只能在Linux2.4.0以后的内核版本中使用)

-n name:设定cramfs文件系统的名字

dirname:指明需要被压缩的整个目录树

outfile:最终输出的文件

 

cramfsck的命令格式:

cramfsck [-hv] [-x dir] file

cramfsck的各个参数解释如下:

-h:显示帮助信息

-x dir:释放文件到dir所指出的目录中

-v:输出信息更加详细

file:希望测试的目标文件

 

本段摘自于:《Linux与嵌入式系统》,这本书由李善平 刘文峰 王焕龙等编著。

 

更详细的介绍参考:

CramFSLinux嵌入式環境的應用[]

 

2Cramfs文件系统的应用

 

三、Cramfs文件系统的移植

1U-boot烧写cramfs文件系统的支持

U-boot中,已经包含了使用命令来烧写cramfs文件系统了。

2、内核配置的支持

想要在系统中提供CramFS的能力,我们必须要在编辑liunx内核时把支持CramFS的选项加入。尽管Linux可以以模块的形式加载各种类型的设备驱动上,但我们选择直接把设备驱动及CramFS文件系统静态地编译进内核中。

Memory Technology Devices (MTD)选项中进行配置:

Memory Technology Device (MTD) support[Y/m/n/?] Y    内存技术设备支持

 

MTD partitioning support [Y/m/n/?] Y 支持MTD分区

 

Direct char device access to MTD devices[Y/m/n/?] Y MTD字符设备直接访问

 

Caching block device access to MTD devices[Y/m/n/?] Y MTD块设备缓冲访问

 

File Systems选项中进行配置:

 

Compressed ROM file system support [Y/m/n/?] Y    ROM文件系统的支持

 

完成上述修改并编译后,完成liunx内核对CramFS文件系统的支持。

 

3、生成Cramfs文件系统映像

       使用mkcramfs命令生产cramfs文件系统映像,我在内核中对Nand Flash的分区如下:

        [0] = {

                .name = "bootloader",

                .size =   0x00060000,

                .offset = 0,

        },

        [1] = {

                .name = "params",

                .size =   0x00020000,

                .offset = 0x00060000,

        },

        [2] = {

                .name = "kernel",

                .offset = 0x00080000,

                .size =   0x00500000,

        },

        [3] = {

                .name = "root",

                .size = SZ_32M,

                .offset = 0x01300000,

        }

所以我在U-boot中使用如下命令烧写内核和根文件系统,内核在烧写之前先用mkimage命令处理:

mkimage -n 'mark' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008040 -d zImage zImage.img

烧写文件系统:

nand flash版内核、文件系统烧写

tftp 30008000 zImage.img

nand erase 80000 500000

nand write 30008000 80000 size

 

tftp 30008000 rootfs.cramfs

nand erase 1300000 2000000

nand write 30008000 1300000 size

 

3、系统启动信息

U-Boot 2009.11 (Jun 25 2010 - 08:28:06)

 

DRAM:  64 MB

Flash:  2 MB

NAND:  64 MiB

In:    serial

Out:   serial

Err:   serial

Net:   dm9000

Hit any key to stop autoboot:  0

 

NAND read: device 0 offset 0x80000, size 0x500000

 5242880 bytes read: OK

## Booting kernel from Legacy Image at 30008000 ...

   Image Name:   mark

   Created:      2010-07-02  15:37:07 UTC

   Image Type:   ARM Linux Kernel Image (uncompressed)

   Data Size:    1800624 Bytes =  1.7 MB

   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.29.1 (root@ubuntu) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #64 Fri Jul 2 08:30:03 PDT 2010

CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177

CPU: VIVT data cache, VIVT instruction cache

Machine: Study-S3C2440

Memory policy: ECC disabled, Data cache writeback

CPU S3C2440A (id 0x32440001)

S3C24XX Clocks, (c) 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/mtdblock3 init=/linuxrc console=ttySAC0 mem=64M

irq: clearing subpending status 00000002

PID hash table entries: 256 (order: 8, 1024 bytes)

Console: colour dummy device 80x30

console [ttySAC0] 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: 61120KB available (3248K code, 318K data, 160K init)

SLUB: Genslabs=12, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1

Calibrating delay loop... 201.93 BogoMIPS (lpj=504832)

Mount-cache hash table entries: 512

CPU: Testing write buffer coherency: ok

net_namespace: 296 bytes

NET: Registered protocol family 16

S3C2440: Initialising architecture

S3C2440: IRQ Support

S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics

DMA channel 0 at c4808000, irq 33

DMA channel 1 at c4808040, irq 34

DMA channel 2 at c4808080, irq 35

DMA channel 3 at c48080c0, irq 36

S3C244X: Clock Support, DVS off

bio: create slab at 0

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

NET: Registered protocol family 1

Installing knfsd (copyright (C) 1996 okir@monad.swb.de).

JFFS2 version 2.2. (NAND) 2001-2006 Red Hat, Inc.

msgmni has been set to 119

io scheduler noop registered

io scheduler deadline registered (default)

Console: switching to colour frame buffer device 30x40

fb0: s3c2410fb frame buffer device

backlight       initialized

s3c2440-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440

s3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440

s3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440

loop: module loaded

dm9000 Ethernet Driver, V1.31

dm9000 dm9000.0: eth%d: Invalid ethernet MAC address. Please set using ifconfig

Now use the default MAC address:08:90:90:90:90:90

eth0 (dm9000): not using net_device_ops yet

eth0: dm9000e at c486a000,c486e004 IRQ 51 MAC: 08:90:90:90:90:90 (chip)

Linux video capture interface: v2.00

zc0301: V4L2 driver for ZC0301[P] Image Processor and Control Chip v1:1.10

usbcore: registered new interface driver zc0301

gspca: main v2.4.0 registered

usbcore: registered new interface driver zc3xx

zc3xx: registered

usbcore: registered new interface driver uvcvideo

USB Video Class driver (v0.1.0)

Driver 'sd' needs updating - please use bus_type methods

S3C24XX NAND Driver, (c) 2004 Simtec Electronics

s3c2440-nand s3c2440-nand: Tacls=1, 9ns Twrph0=4 39ns, Twrph1=1 9ns

NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)

Scanning device for bad blocks

Bad eraseblock 353 at 0x000000584000

Bad eraseblock 1203 at 0x0000012cc000

Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":

0x000000000000-0x000000060000 : "bootloader"

0x000000060000-0x000000080000 : "params"

0x000000080000-0x000000580000 : "kernel"

0x000001300000-0x000003300000 : "root"

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

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: S3C24XX OHCI

usb usb1: Manufacturer: Linux 2.6.29.1 ohci_hcd

usb usb1: SerialNumber: s3c24xx

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...

usbcore: registered new interface driver usb-storage

USB Mass Storage support registered.

usbcore: registered new interface driver usbled

mice: PS/2 mouse device common for all mice

s3c2410 TouchScreen successfully loaded

input: s3c2410 TouchScreen as /devices/virtual/input/input0

S3C24XX RTC, (c) 2004,2006 Simtec Electronics

s3c2410-rtc s3c2410-rtc: rtc disabled, re-enabling

s3c2410-rtc s3c2410-rtc: rtc core: registered s3c as rtc0

i2c /dev entries driver

s3c2440-i2c s3c2440-i2c: slave address 0x10

s3c2440-i2c s3c2440-i2c: bus frequency set to 98 KHz

s3c2440-i2c s3c2440-i2c: i2c-0: S3C I2C adapter

S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics

s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled

mapped channel 0 to 0

s3c2440-sdi s3c2440-sdi: powered down.

s3c2440-sdi s3c2440-sdi: initialisation done.

s3c2440-sdi s3c2440-sdi: running at 0kHz (requested: 0kHz).

s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).

s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).

s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).

s3c2440-sdi s3c2440-sdi: CMD[ERR -110] #2 op:8 arg:0x000001aa flags:0x082f5 retries:0 Status:nothing to complete

s3c2440-sdi s3c2440-sdi: CMD[ERR -110] #3 op:5 arg:0x00000000 flags:0x082e1 retries:3 Status:nothing to complete

s3c2440-sdi s3c2440-sdi: CMD[ERR -110] #4 op:5 arg:0x00000000 flags:0x082e1 retries:2 Status:nothing to complete

s3c2440-sdi s3c2440-sdi: CMD[ERR -110] #5 op:5 arg:0x00000000 flags:0x082e1 retries:1 Status:nothing to complete

s3c2440-sdi s3c2440-sdi: CMD[ERR -110] #6 op:5 arg:0x00000000 flags:0x082e1 retries:0 Status:nothing to complete

s3c2440-sdi s3c2440-sdi: CMD[ERR -110] #7 op:55 arg:0x00000000 flags:0x08f5 retries:0 Status:nothing to complete

s3c2440-sdi s3c2440-sdi: CMD[ERR -110] #8 op:55 arg:0x00000000 flags:0x08f5 retries:0 Status:nothing to complete

s3c2440-sdi s3c2440-sdi: CMD[ERR -110] #9 op:55 arg:0x00000000 flags:0x08f5 retries:0 Status:nothing to complete

s3c2440-sdi s3c2440-sdi: CMD[ERR -110] #10 op:55 arg:0x00000000 flags:0x08f5 retries:0 Status:nothing to complete

s3c2440-sdi s3c2440-sdi: CMD[ERR -110] #11 op:1 arg:0x00000000 flags:0x08e1 retries:0 Status:nothing to complete

s3c2440-sdi s3c2440-sdi: powered down.

usbcore: registered new interface driver usbhid

usbhid: v2.6:USB HID core driver

Advanced Linux Sound Architecture Driver Version 1.0.18a.

No device for DAI UDA134X

No device for DAI s3c24xx-i2s

S3C24XX_UDA134X SoC Audio driver

UDA134X SoC Audio Codec

asoc: UDA134X <-> s3c24xx-i2s mapping ok

ALSA device list:

  #0: S3C24XX_UDA134X (UDA134X)

TCP cubic registered

RPC: Registered udp transport module.

RPC: Registered tcp transport module.

s3c2410-rtc s3c2410-rtc: setting system clock to 2006-03-14 13:55:59 UTC (1142344559)

VFS: Mounted root (cramfs filesystem) readonly on device 31:3.

Freeing init memory: 160K

----------munt all----------------

mkdir: cannot create directory '/dev/shm': Read-only file system

mount: mounting tmpfs on /dev/shm failed: No such file or directory

mdev: mknod loop0: Read-only file system

mkdir: cannot create directory '/dev/pts': Read-only file system

mount: mounting devpts on /dev/pts failed: No such file or directory

network interface

start net_set

/sbin/net_set: line 3: can't create /dev/ttySAC0: Read-only file system

/sbin/net_set: line 5: can't create /dev/ttySAC0: Read-only file system

dm9000 dm9000.0: WARNING: no IRQ resource flags set.

eth0: link down

/sbin/net_set: line 5: can't create /dev/ttySAC0: Read-only file system

/sbin/net_set: line 5: can't create /dev/ttySAC0: Read-only file system

/sbin/net_set: line 25: can't create /dev/ttySAC0: Read-only file system

start httpd

[14/Mar/2006:13:56:01 +0000] log.c:74 - unable to dup2 the error log: Bad file descriptor

****************Studying ARM*********************

Kernel version:linux-2.6.29.1

Student:Feng dong rui

Date:2009.07.15

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

 

Please press Enter to activate this console. eth0: link up, 100Mbps, full-duplex, lpa 0x45E1

 

[rootMrFeng]#

[rootMrFeng]#ls

bin      etc      linuxrc  proc     sys      var

boot     home     mnt      root     tmp      www

dev      lib      opt      sbin     usr

[rootMrFeng]#

 

 

 

阅读(1438) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~