U-Boot-2009.8引导Linux的2.6.32.2内核

来源:互联网 发布:get. it 编辑:程序博客网 时间:2024/04/29 17:03
最近一直在做U-boot-2009.08和Linux-2.6.32.2的内核的移植,今天终于可以使用自己移植的U-Boot-2009.08引导自 己修改的Linux-2.6.33.2内核了,还有移植的Yaffs2文件系统,真是太高兴的,现在在把这近两个月内,断断续续的移植做个最后的终结吧! 在这个过程中也有想放弃的时候,不过现在都过来了,哈哈!遇到困难不要放弃,也许当时解决不了,不过可以先放一放,很可能过几天,从新分析时,会发现问题 的所在。这也是我经常不是解决问题的办法的办法!下面开始这篇文章了:
1、机器码的确认:
   U-Boot和Linux中都有一个机器码,只有当这两个机器码一致的时候,才能够正确的引导Linux内核。在这个版本中的U-boot和Linux 中,对MINI2440的板子支持的都很好了,也有了官方的机器码,只要添加上就可以了。在U-Boot中我们可以看到,在u-boot- 2009.08/include/asm-arm/mach-types.h文件中的1985行附近的位置

#define MACH_TYPE_Q2440 1997
#define MACH_TYPE_QQ2440 1998
#define MACH_TYPE_MINI2440 1999  //mini2440的机器码
#define MACH_TYPE_COLIBRI300 2000
#define MACH_TYPE_JADES 2001

而在内核中的kernel/linux-2.6.32.2/arch/arm/tools/mach-typs.h文件中的1989行附近的位置

f5d8231_4_v2        MACH_F5D8231_4_V2    F5D8231_4_V2        1996
q2440            MACH_Q2440        Q2440            1997
qq2440            MACH_QQ2440        QQ2440            1998
mini2440        MACH_MINI2440        MINI2440        1999 //Linux中的MINI2440的机器码
colibri300        MACH_COLIBRI300        COLIBRI300        2000
jades            MACH_JADES        JADES            2001

   从这里我们可以知道MINI2440的机器码就是1999,那么我们就需要修改U-Boot中的机器码,以便和Linux中的机器码一致。在文件u- boot-2009.08/board/frankzfz/mini2440/mini2440.c目录可能会不一样,这是我自己建立的一个目录,大约在 127行附近的位置。在board_init()函数中。

    gpio->GPHUP = 0x000007FF;
    /* arch number of SMDK2410-Board */
    #if defined(CONFIG_S3C2440)
    gd->bd->bi_arch_number = MACH_TYPE_MINI2440; //为u-boot添加机器码
    //gd->bd->bi_arch_number = MACH_TYPE_SMDK2410;
#endif

     还有一个地方也已经在另一篇文章《移植Linux内核》中做了说明,也就是在kernel/linux-2.6.32.2/arch/arm/mach-s3c2440/mach-mini2440.c文件中的230行附近中的MACHINE_START,修改成如下:

MACHINE_START(MINI2440, "FriendlyARM MINI2440 development board")

2、用u-boot引导Linux的镜象文件uImage
   通常,kernel的启动需要u-boot提供一些参数信息,比如ramdisk在RAM中的地址。经过编译后的u-boot在根目录下的tools目录 中,会有个叫做mkimage的工具,他可以给zImage添加一个header,也就是说使得通常我们编译的内核zImage添加一个数据头信息部分, 我们把添加头后的image通常叫uImage,uImage是可以被u-boot直接引导的内核镜像。我们如何使用这个工具生成我们需要的uImage格式的镜像文件呢?
1) 编译u-boot成功后会在u-boot-2009.08/tools下生成mkimage的可执行的文件,为了我们在任何地方都可以使用这个命令,首先 我们可以把这个可执行文件复制到/usr/local/bin.这样就可以在任意的目录下执行这个命令了。复制完以后我们在终端下输入 “mkimage”,并按下回车。可以看到下面的输出的信息,说明我们已经可以使用改命令了。

Usage: mkimage -l image
          -==> list image header information
       mkimage [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image
          -==> set architecture to 'arch' 
//用于指定CPU类型,比如ARM
          -==> set operating system to 'os'
 //用于指定操作系统,比如Linux
          -==> set image type to 'type'
//用于指定image类型,比如Kernelramdisk
          -==> set compression type 'comp'
//指定压缩类型
          -==> set load address to 'addr' (hex)
//指定image的载入地址
          -==> set entry point to 'ep' (hex)
//内核的入口地址,一般是:image的载入地址+0x40(信息头的大小)
          -==> set image name to 'name'
//image在头结构中的命名
          -==> use image data from 'datafile'
//无头信息的image文件名
          -==> set XIP (execute in place)
//设置执行位置即不进行文件的拷贝,在当前位置执行
       mkimage [-D dtc_options] -f fit-image.its fit-image
 

对于ARM Linux我们可以这样使用各个参数:

对于ARM linux内核映象用法:
-A arm -------- 架构是arm
-O linux -------- 操作系统是linux
-T kernel -------- 类型是kernel
-none/bzip/gzip -------- 压缩类型
-a 20008000 ---- image的载入地址(hex),通常为0xX00008000
-e 200080XX---- 内核的入口地址(hex),XX为0x40或者0x00
-n linux-XXX --- image的名字,任意
-d nameXXX ---- 无头信息的image文件名,你的源内核文件
uImageXXX ---- 加了头信息之后的image文件名,任意取

   现在我们可以进入kernel/linux-2.6.32.2/arch/arm/boot目录了,然后执行下面的命令,就会在改目录下面生成uImage.img格式的,u-boot可以引导的内核镜象。

mkimage -'linux-2.6.32.2' -A arm -O linux -T kernel -none -a 0x30008000 -e 0x30008000 -d zImage uImage.img

   现在我们可以把生成的uImage.img格式的镜像文件复制到tftp目录下,使用tftp进行下载了:不过现在下载到以后复制到Nand Flash中u-boot还是无法引导内核,还是需要在u-boot中一些配置。
在u-boot-2009.08/include/configs/mini2440.h文件中

#define CONFIG_BOOTDELAY    3 //自动启动前延时3秒,不过这个要和下面的另一个配置一 

                              //起定义后才会其作用

配置命令行的参数

#define CONFIG_BOOTARGS    "noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0,115200 mem=64M"

// 只有这个宏定义了以后 上面的哪个宏的定义才会生效,否则还是会直接的出现命令行的提示符,不会引导内核的。 root=/dev/mtdblock3 这是有我们Linux中的nand Flash分区所决定的,我的NandFlash的第四个分区为根文件系统所以是mtdblock3,如果不是的话请修改

我的NandFlash的情况是这样的

"U-boot",0x00000000 -- 0x00040000,
"param", 0x00040000--
0x00060000,
 "Kernel", 0x00060000---0x00560000,     
"root",
 0x00560000---结束

还要在该文件中增加下面两个宏的定义:

#define CONFIG_SETUP_MEMORY_TAGS 1 //向内核传递内存分布信息
#define CONFIG_INITRD_TAG 
#define CONFIG_CMDLINE_TAG 1   //向内核传递命令行参数

在该文件中添加下面的定义

#define CONFIG_MTD_NAND_YAFFS2 1
#define MTDIDS_DEFAULT "nand0=nandflash0"
#define MTDPARTS_DEFAULT "mtdparts=nandflash0:256k(bootloader),"\
            "128k(params),"\
            "5m(kernel),"\
            "-(root)"  //这里要和Linux内核中的分区信息相一致

下面的这两个定义也要和分区相一致

#define CONFIG_ENV_OFFSET 0x40000 //将环境变量保存在Nand中的0x30000位置
#define CONFIG_ENV_SIZE 0x20000 //Total Size of Environment Sector

为了使u-boot可以自行引导Linux内核,我们还需要添加下面的这句话。

#define CONFIG_BOOTCOMMAND    "nand read 0x32000000 0x60000 0x560000;bootm 0x32000000"  

//这个宏定义的意思是将nand中0x60000-0x560000(和kernel分区一致)的内容读到内存0x32000000中,然后用bootm命令来执行

3、下载系统到内存
  我们先把内核下载到内存中,然后我们执行bootm命令(同一个地址)看能不能启动系统。在U-Boot下执行:
tftp 0x31000000 uImage.img (或uImage)
    在提示下载完成后再执行:
bootm 0x31000000
    如果成功则证明我们的设置没有问题。
4、下载固化
   在前面我们看到了NandFlash的分区信息。下面我们使用命令,把我们的Linux内核和制作的根文件系统下载到NandFlash中,以便以开始启动就可以引导Linux内核。
                             起始地址             结束地址
   uboot            :       0x00000000      0x00040000      0
   param            :       0x00040000      0x00060000      0
   kernel           :       0x00060000      0x00560000      0
   root             :       0x00560000      0x07FFFFFF     0
这是NandFlash的分区情况;
    在u-boot下输入
tftp 0x30000000 uImage.img(或uImage),稍等即可下载uImage到内存中。
    接着执行 nand erase 0x60000 0x500000 删除掉kernel空间原有的数据。
    执行 nand write 0x30000000 0x50000 0x500000,将内存中的kernel烧入nand flash。
    接下来,输入tftp 30000000 rootfs.img,将根文件系统镜象下载到内存中。
    再输入nand erase 0x560000 0x07FFFFFF 将root空间内原有数据删除。
    再输入nand write.yaffs2 0x30000000 0x560000 0x6ffcc0,其中0x6ffcc0是文件系统镜象的size,一定不能写错,它可以tftp下载完毕后看到。
nand erase[clean][off size] 擦除NANDFlash。加上“clean”时,表示在每个块的第一个扇区的OOB区加写入清除的标记:off size表示要擦除的开始偏移地址和长度,如果省略off size 擦除整个NandFlash。现在可以从新启动开发板,从NandFlash启动可以看到启动的信息了。
下载Linux 镜像

[U-Boot@mini2440]#tftp 0x30000000 uImage.img 
dm9000 i/o: 0x20000300, id: 0x90000a46 
DM9000: running in 16 bit mode 
MAC: 08:00:3e:26:0a:5b 
operating at 100M full duplex mode 
Using dm9000 device 
TFTP from server 10.27.10.48; our IP address is 10.27.10.23 
Filename 'uImage.img'. 
Load address: 0x30000000 
Loading: ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################### 
done 
Bytes transferred = 2092996 (1fefc4 hex) 
[U-Boot@mini2440]#nand erase 0x60000 0x500000 
                                                                                
NAND erase: device 0 offset 0x60000, size 0x500000 
Erasing at 0x54000002800000 -- 0% complete. 
OK 
[U-Boot@mini2440]#nand write 0x30000000 0x60000 0x500000 
                                                                                
NAND write: device 0 offset 0x60000, size 0x500000 
 5242880 bytes written: OK

下载根文件系统

[U-Boot@mini2440]#tftp 30000000 rootfs.img 
dm9000 i/o: 0x20000300, id: 0x90000a46 
DM9000: running in 16 bit mode 
MAC: 08:00:3e:26:0a:5b 
operating at 100M full duplex mode 
Using dm9000 device 
TFTP from server 10.27.10.48; our IP address is 10.27.10.23 
Filename 'rootfs.img'. 
Load address: 0x30000000 
Loading: ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         ################################################################# 
         #### 
done 
Bytes transferred = 7339200 (6ffcc0 hex) 
[U-Boot@mini2440]#nand erase 0x560000 
                                                                                
NAND erase: device 0 offset 0x560000, size 0x7aa0000 
Erasing at 0x7fe000007aa0000 -- 0% complete. 
OK 
[U-Boot@mini2440]#nand write.yaffs2 0x30000000 0x560000 0x6ffcc0 
                                                                                
NAND write: device 0 offset 0x560000, size 0x6ffcc0 
skip first good block 56000000020000 
 Writing at 0xc4000000020000 --100% is complete 7116800 bytes written: OK

引导Linux内核启动

U-Boot 2009.08 ( 4??月 24 2010 - 17:34:23) 
                                                                                
DRAM: 64 MB 
Flash: 2 MB 
NAND Device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-b)
NAND: 128 MiB 
*** Warning - bad CRC or NAND, using default environment 
                                                                                
In: serial 
Out: serial 
Err: serial 
Net: dm9000 
Hit any key to stop autoboot: 0 
                                                                                
NAND read: device 0 offset 0x60000, size 0x500000 
 5242880 bytes read: OK 
## Booting kernel from Legacy Image at 32000000 ... 
   Image Name: linux-2.6.32.
   Created: 2010-04-24 3:25:34 UTC 
   Image Type: ARM Linux Kernel Image (uncompressed) 
   Data Size: 2092932 Bytes = 2 MB 
   Load Address: 30008000 
   Entry Point: 30008000 
   Verifying Checksum ... OK 
   Loading Kernel Image ... OK 
OK 
                                                                                
Starting kernel ... 
                                                                                
Uncompressing Linux.............................................................
Linux version 2.6.32.(zfz@zfz) (gcc version 4.3.(Sourcery G++ Lite 2008q3-70
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177 
CPU: VIVT data cache, VIVT instruction cache 
Machine: FriendlyARM MINI2440 development board 
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=ttySAC0M
PID hash table entries: 256 (order: -2, 1024 bytes) 
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: 60500KB available (3672K code, 418K data, 132K init, 0K highmem) 
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=
Hierarchical RCU implementation. 
NR_IRQS:85 
irq: clearing subpending status 00000002 
Console: colour dummy device 80x30 
console [ttySAC0] enabled 
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832) 
Mount-cache hash table entries: 512 
CPU: Testing write buffer coherency: ok 
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 <bio-0> at 0 
usbcore: registered new interface driver usbfs 
usbcore: registered new interface driver hub 
usbcore: registered new device driver usb 
s3c-i2c s3c2440-i2c: slave address 0x10 
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz 
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter 
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 
RPC: Registered udp transport module. 
RPC: Registered tcp transport module. 
RPC: Registered tcp NFSv4.1 backchannel transport module. 
JFFS2 version 2.2. (NAND) ?&#169; 2001-2006 Red Hat, Inc. 
ROMFS MTD (C) 2007 Red Hat, Inc. 
yaffs Apr 20 2010 11:10:26 Installing. 
msgmni has been set to 118 
alg: No test for stdrng (krng) 
io scheduler noop registered 
io scheduler anticipatory registered (default) 
io scheduler deadline registered 
io scheduler cfq registered 
s3c2410-lcd s3c2410-lcd: no platform data for lcd, cannot attach 
s3c2410-lcd: probe of s3c2410-lcd failed with error -22 
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 
brd: module loaded 
S3C24XX NAND Driver, (c) 2004 Simtec Electronics 
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns 
s3c24xx-nand s3c2440-nand: NAND soft ECC 
NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-b)
Scanning device for bad blocks 
Creating 5 MTD partitions on "NAND 128MiB 3,3V 8-bit": 
0x000000000000-0x000000040000 : "U-boot" 
0x000000040000-0x000000060000 : "param" 
ftl_cs: FTL header not found. 
0x000000060000-0x000000560000 : "Kernel" 
ftl_cs: FTL header not found. 
0x000000560000-0x000040560000 : "root" 
mtd: partition "root" extends beyond the end of device "NAND 128MiB 3,3V 8-bit"0
ftl_cs: FTL header not found. 
0x000000000000-0x000040000000 : "nand" 
mtd: partition "nand" extends beyond the end of device "NAND 128MiB 3,3V 8-bit"0
dm9000 Ethernet Driver, V1.31 
ohci_hcd: USB 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: configuration #1 chosen from 1 choice 
hub 1-0:1.0: USB hub found 
hub 1-0:1.0: 2 ports detected 
usbcore: registered new interface driver libusual 
mice: PS/2 mouse device common for all mice 
S3C24XX RTC, (c) 2004,2006 Simtec Electronics 
i2c /dev entries driver 
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics 
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled 
cpuidle: using governor ladder 
sdhci: Secure Digital Host Controller Interface driver 
sdhci: Copyright(c) Pierre Ossman 
usbcore: registered new interface driver hiddev 
usbcore: registered new interface driver usbhid 
usbhid: v2.6:USB HID core driver 
Advanced Linux Sound Architecture Driver Version 1.0.21. 
No device for DAI UDA134X 
No device for DAI s3c24xx-i2s 
ALSA device list: 
  No soundcards found. 
TCP cubic registered 
NET: Registered protocol family 17 
drivers/rtc/hctosys.c: unable to open rtc device (rtc0) 
yaffs: dev is 32505859 name is "mtdblock3" 
yaffs: passed flags "" 
yaffs: Attempting MTD mount on 31.3, "mtdblock3" 
yaffs: auto selecting yaffs2 
yaffs_read_super: isCheckpointed 0 
VFS: Mounted root (yaffs filesystem) on device 31:3. 
Freeing init memory: 132K 
/etc/init.d/rcS: line 7: echo--------- munt all--------: not found 
************************* 
**********************Frankzfz ARM************** 
Kernel version:linux-2.32.
Student:zfz 
Data:2010,4,19 
*********************** 
                                                                                
Please press Enter to activate this console. 
[root@"Frankzfz"=W]#ls 
bin etc linuxrc proc sys var 
boot home lost+found root tmp 
dev lib mnt sbin usr

   到此整个的嵌入式的基本的移植告一段落了,不过中间还是有很多需要改进的地方,下一不还有驱动的移植。呵呵,就先到这里吧!在这个移植的期间参考了很多的网上资料,也谢谢他们的无私奉献了
原创粉丝点击