linux初学-内核编译以及文件系统2

linux初学-内核编译以及文件系统2

 

 

前面介绍了内核的编译。最后生成的内核镜象有两种zImage以及uImage。其中zImage下载到目标板中后,可以直接用uboot的命令go来进行直接跳转。这时候内核直接解压启动。但是无法挂载文件系统,因为go命令没有将内核需要的相关的启动参数传递给内核。传递启动参数我们必须使用命令bootm来进行跳转。Bootm命令跳转只处理uImage的镜象。

 

uboot源代码的tools/目录下有mkimage工具,这个工具可以用来制作不压缩或者压缩的多种可启动映象文件。

 

mkimage在制作映象文件的时候,是在原来的可执行映象文件的前面加上一个0x40字节的头,记录参数所指定的信息,这样uboot才能识别这个映象是针对哪个CPU体系结构的,哪个OS的,哪种类型,加载内存中的哪个位置, 入口点在内存的那个位置以及映象名是什么

 

用法如下:

 

./mkimage -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image

 

-A ==> set architecture to 'arch'

 

-O ==> set operating system to 'os'

 

-T ==> set image type to 'type'

 

-C ==> set compression type 'comp'

 

-a ==> set load address to 'addr' (hex)

 

-e ==> set entry point to 'ep' (hex)

 

-n ==> set image name to 'name'

 

-d ==> use image data from 'datafile'

 

-x ==> set XIP (execute in place)

 

参数说明:

 

 

 

-A 指定CPU的体系结构:

 

 

 

取值 表示的体系结构

 

alpha Alpha

 

arm A RM

 

x86 Intel x86

 

ia64 IA64

 

mips MIPS

 

mips64 MIPS 64 Bit

 

ppc PowerPC

 

s390 IBM S390

 

sh SuperH

 

sparc SPARC

 

sparc64 SPARC 64 Bit

 

m68k MC68000

 

 

 

-O 指定操作系统类型,可以取以下值:

 

openbsdnetbsdfreebsd4_4bsdlinuxsvr4esixsolarisirixscodellncrlynxosvxworkspsosqnxu-bootrtemsartos

 

 

 

-T 指定映象类型,可以取以下值:

 

standalonekernelramdiskmultifirmwarescriptfilesystem

 

 

 

-C 指定映象压缩方式,可以取以下值:

 

none 不压缩

 

gzip gzip的压缩方式

 

bzip2 bzip2的压缩方式

 

 

 

-a 指定映象在内存中的加载地址,映象下载到内存中时,要按照用mkimage制作映象时,这个参数所指定的地址值来下载

 

 

 

-e 指定映象运行的入口点地址,这个地址就是-a参数指定的值加上0x40(因为前面有个mkimage添加的0x40个字节的头)

 

 

 

-n 指定映象名

 

 

 

-d 指定制作映象的源文件

 

 

 

我在编译时用到的命令如下:

 

# make zImage      //生成zImage镜象

 

/usr/local/arm/k9uboot/tools/mkimage -n 'Linux 2.4.27 ' -A arm -O linux -T

 

kernel -C none -a 0x20007fc0 -e 0x20008000 -d zImage uImage

 

 

 

内核镜象已经准备好了,这个时候我们就要来准备文件系统了。由于时间缘故,本人暂时采用的是其他人已经好的文件系统k9.img.gz。这个时候我们要做的是,自己写一个简单hello.c的程序,编译通过后加入到该文件系统中,然后下载到目标板中运行。

 

先编写hello.c

 

编译:

 

#/usr/local/arm/2.95.3/bin/arm-linux-gcc  –o start-hello hello.c

 

编译后生成可执行文件start-hello

 

下面我们就必须把该执行文件加入到文件系统中去,步骤如下:

 

#gunzip  k9.img.gz                     //解压缩

 

#mount o loop k9.img  /mnt/new_disk    //挂载

 

#cp start-hello  /mnt/new_disk           //将文件拷贝到文件系统中

 

#cd  /mnt/new_disk

 

#umount /mnt/new_disk                 //卸载

 

#gzip c v9 k9.img > k9.img.gz          //压缩 生成最终的文件系统

 

 

 

下面我们就要下载内核以及准备好文件系统了,这边先说明我的内存分配情况如下:

 

Flash

 

0x10000000 ――― 0x10020000     boot

 

0x10020000 ――― 0x10040000     uboot

 

0x10040000 ――― 0x10060000     uboot env

 

0x10060000 ――― 0x10200000     kernel

 

0x10200000 ――― 0x11000000     ramdisk

 

 

 

Sdram

 

0x20007fc0 ――― 0x 20a 00000     kernel

 

0x 20a 00000 ―――                ramdisk

 

 

 

Loadb  通过串口下载数据到ram

 

cp.b    拷贝ram中的数据到flash中。

 

 

 

kernel以及文件系统ramdisk下载完毕之后,我们还需要设置uboot的环境变量,这样uboot才能够在上电启动的时候启动内核等操作。环境变量设置如下:

 

Set cpfltoram cp.b 10200000 20a 00000 18ffff            //拷贝文件系统到ram

 

Set boot bootm 20007fc0                            //启动kernel

 

Set bootcmd run cpfltoker/;run cpfltoram/;run boot       //uboot复位的执行指令

 

 

 

Set cpfltoker cp.b 10060000 20007fc 0 f 4fff             //拷贝内核到ram

 

Set bootargs root=/dev/ram rw initrd=0x 20a 00000, 4M init=/linuxrc console=ttyS0,11520

 

0,mem= 32m                       //uboot传递给内核的启动参数

 

 

 

设置完毕后,saveenv把环境变量存储起来。

 

 

 

随后就可以上电复位目标板了。Kernel启动成功:

 

## Booting image at 20007fc0 ...                               

 

   Image Name:   Linux 2.6.20                            

 

   Image Type:   ARM Linux Kernel Image (uncompressed)                                                     

 

   Data Size:    974124 Bytes = 951.3 kB                                       

 

   Load Address: 20007fc0                        

 

   Entry Point:  20008000                        

 

   Verifying Checksum ... OK                           

 

   XIP Kernel Image ... OK                         

 

 

 

Starting kernel ...                  

 

 

 

Uncompressing Linux.............................................................                                                                               

 

.. done, booting the kernel.                           

 

Linux version 2.6.20 (root@dengdl) (gcc version 3.4.1) #2 Tue Apr 3 01:35:56 CST                                                                               

 

 2007    

 

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

 

Machine: Atmel AT91RM9200-DK                           

 

Memory policy: ECC disabled, Data cache writeback                                                

 

Clocks: CPU 179 MHz, master 59 MHz, main 18.432 MHz                                                  

 

CPU0: D VIVT write-back cache                            

 

CPU0: I cache: 16384 bytes, associativity 64, 32 byte l                        

 

CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets

 

Built 1 zonelists.  Total pages: 4064

 

Kernel command line: root=/dev/ram rw initrd=0x 20a 00000, 4M init=/linuxrc console

 

=ttyS0,115200,mem= 32m

 

AT91: 128 gpio irqs in 4 banks

 

PID hash table entries: 64 (order: 6, 256 bytes)

 

Console: colour dummy device 80x30

 

Dentry cache hash table entries: 2048 (order: 1, 8192 bytes)

 

Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)

 

Memory: 16MB = 16MB total

 

Memory: 10100KB available (1708K code, 193K data, 96K init)

 

Mount-cache hash table entries: 512

 

CPU: Testing write buffer coherency: ok

 

NET: Registered protocol family 16

 

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: 1024 (order: 0, 4096 bytes)

 

TCP bind hash table entries: 512 (order: -1, 2048 bytes)

 

TCP: Hash tables configured (established 1024 bind 512)

 

TCP reno registered

 

checking if image is initramfs... it isn't (no cpio magic); looks like an initrdted Vendor Command Set found                                               

 

K9

 

Freeing initrd memory: 4096K0020                 

 

physm

 

NetWinder Floating Point Emulator V0.97 (double precision)200000 20a 00000 18ffff                                   

 

io scheduler noop registered                    

 

at91_c

 

io scheduler anticipatory registered (default)  

 

 

 

X

 

boot=bootm 20007fc0OT                

 

at91_spi: Baud rate set to 5990400le                               

 

AT91 SPI driver loaded1_ohci at91_ohci: AT91

 

e

 

eth0: Link down.g random host et

 

eth0: AT91 ethernet at 0xfefbc000 int=24 10-HalfDuplex (00:15:f2:9d:66:80)oot> loadb             

 

usb0: Ethernet Gadget, version: May Day 2005    

 

eth0: Davicom 9161 PHY (Copper)      

 

 

 

i 2c /dev en          

 

physmap platform flash device: 00200000 at 10000000dc, OUT ep 2 IN ep1 STATUS ep4                     

 

physmap-flash.0: Found 1 x16 devices at 0x 0 in 16-bit banka cache writebackMay                                     

 

at91_cf: irqs det #64, io #0lt 1 zonelists.  Total pages

 

usbmon: debugfs is not available     

 

VFS: Mounted root (ext 2 f

 

at91_ohci at91_ohci: AT91 OHCI                   

 

usb usb1: Manufacturer: Linux 2.6.20 ohci_hcd

 

usb usb1: SerialNumber: at91

 

usb usb1: configuration #1 chosen from 1 choice

 

hub 1-0:1.0: USB hub found

 

hub 1-0:1.0: 2 ports detected

 

udc: at91_udc version 3 May 2006

 

ether gadget: using random self ethernet address

 

ether gadget: using random host ethernet address

 

usb0: Ethernet Gadget, version: May Day 2005

 

usb0: using at91_udc, OUT ep 2 IN ep1 STATUS ep4

 

usb0: MAC 02:51: 7f :9d:de:e9

 

usb0: HOST MAC be:fc:84: 2f :85:64

 

usb0: RNDIS ready

 

mice: PS/2 mouse device common for all mice

 

at91_rtc at91_rtc: rtc core: registered at91_rtc as rtc0

 

AT91 Real Time Clock driver.

 

i 2c /dev entries driver

 

at91_i 2c at91_i 2c : AT91 i 2c bus driver.

 

TCP cubic registered

 

NET: Registered protocol family 1

 

NET: Registered protocol family 17

 

at91_rtc at91_rtc: setting the system clock to 1998-01-01 00:00:22 (883612822)

 

RAMDISK: Compressed image found at block 0

 

VFS: Mounted root (ext2 filesystem).

 

Freeing init memory: 96K

 

route: SIOC[ADD|DEL]RT: No such process

 

route: SIOC[ADD|DEL]RT: Network is unreachable

 

 

 

 

 

# usb 1-2: new low speed USB device using at91_ohci and address 2

 

usb 1-2: device descriptor read/64, error -62

 

usb 1-2: device descriptor read/64, error -62

 

usb 1-2: new low speed USB device using at91_ohci and address 3

 

usb 1-2: device descriptor read/64, error -62

 

usb 1-2: device descriptor read/64, error -62

 

usb 1-2: new low speed USB device using at91_ohci and address 4

 

usb 1-2: device not accepting address 4, error -62

 

usb 1-2: new low speed USB device using at91_ohci and address 5

 

usb 1-2: device not accepting address 5, error -62

 

 

 

上面红字标记的错误是由于我们采用的是QFP封装的9200,所以相对于BGA封装的9200来说在usb host上有区别,只有1host。这必须在9200的配置文件中进行相应的修改。本人尚未搞通,后续将继续。

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值