免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1978 | 回复: 0

移植u-boot到FL2440开发板(七)——引导linux内核启动 [复制链接]

论坛徽章:
0
发表于 2011-12-20 09:44 |显示全部楼层
8)实现u-boot引导Linux内核启动。
 
在前面几节中,我们讲了u-boot对Nor Flash和Nand Flash的启动支持,那现在我们就再来探讨一下u-boot怎样来引导Linux内核的启动。
 
①、机器码的确定
通常,在u-boot和kernel中都会有一个机器码(即:MACH_TYPE),只有这两个机器码一致时才能引导内核,否则就会出现如下mach的错误信息:(如果没有错误信息则不需要一下修改,我的就没有,这些错误是摘录的)
 
首先,确定u-boot中的MACH_TYPE。在u-boot的include/asm-arm/mach-types.h文件中针对不同的CPU定义了非常多的MACH_TYPE,可以找到下面这个定义:
  1. #define MACH_TYPE_SMDK2440 1008

那么我们就修改u-boot的MACH_TYPE代码引用部分,确定u-boot的MACH_TYPE。如下:

  1. #vim board/samsung/yyq2440/yyq2440.c //修改board_init函数
  2. /* arch number of SMDK2410-Board */
  3. //gd->bd->bi_arch_number = MACH_TYPE_SMDK2410;
  4. 改为:
  5. gd->bd->bi_arch_number = MACH_TYPE_SMDK2440;
其次,确定kernel中的MACH_TYPE。在kernel的arch/arm/tools/mach-types文件中也针对不同的CPU定义了非常多的MACH_TYPE,也可以找到下面这个定义:
  1. smdk2440 MACH_SMDK2440 SMDK2440 1008

那么我们就修改kernel的MACH_TYPE代码引用部分,确定kernel的MACH_TYPE。如下:

  1. #vim arch/arm/mach-s3c2440/mach-smdk2440.c //修改文件最后面

  2. //MACHINE_START(S3C2440, "SMDK2440")
  3. 改为:
  4. MACHINE_START(SMDK2440, "SMDK2440")
  1. #gedit arch/arm/kernel/head.S //在ENTRY(stext)下添加如下代码(红色部分)

  2. ENTRY(stext)
  3.     mov r0, #0
  4.     mov r1, #0x3f0 //上面的MACH_TYPE值1008换成十六进制就是0x3f0
  5.     ldr r2, =0x30000100
  6.     msr cpsr_c, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
  7.     .......

分别重新编译u-boot和kernel。u-boot下载后,记得要saveenv;kernel用tftp下载到内存后使用go命令来测试引导内核,结果可以引导了。如下。

准备能被u-boot直接引导的内核uImage
通常,kernel的启动需要u-boot提供一些参数信息,比如ramdisk在RAM中的地址。经过编译后的u-boot在根目录下的tools目录中,会有个叫做mkimage的工具,他可以给zImage添加一个header,也就是说使得通常我们编译的内核zImage添加一个数据头信息部分,我们把添加头后的image通常叫uImage,uImage是可以被u-boot直接引导的内核镜像。
 
mkimage工具的使用介绍如下:
  1. 使用: 中括号括起来的是可选的
  2. mkimage [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image
  3. 选项:
  4. -A:set architecture to 'arch' //用于指定CPU类型,比如ARM
  5. -O:set operating system to 'os' //用于指定操作系统,比如Linux
  6. -T:set image type to 'type' //用于指定image类型,比如Kernel
  7. -C:set compression type 'comp' //指定压缩类型
  8. -a:set load address to 'addr' (hex) //指定image的载入地址
  9. -e:set entry point to 'ep' (hex) //内核的入口地址,一般为image的载入地址+0x40(信息头的大小)
  10. -n:set image name to 'name' //image在头结构中的命名
  11. -d:use image data from 'datafile' //无头信息的image文件名
  12. -x:set XIP (execute in place)

先将u-boot下的tools中的mkimage复制到主机的/usr/local/bin目录下,这样就可以在主机的任何目录下使用该工具了。现在我们进入kernel生成目录(一般是arch/arm/boot目录),然后执行如下命令,就会在该目录下生成一个uImage.img的镜像文件,把他复制到tftp目录下,这就是我们所说的uImage。

  1. [skywalker@bogon tools]$ sudo cp mkimage /usr/local/bin/
  2. [skywalker@bogon tools]$ cd ..
  3. [skywalker@bogon u-boot-2009.08]$ mkimage -n 'linux-2.6.33.7' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008000 -d zImage uImage.img
  4. Image Name: linux-2.6.33.7
  5. Created: Fri Mar 4 20:35:51 2011
  6. Image Type: ARM Linux Kernel Image (uncompressed)
  7. Data Size: 2026844 Bytes = 1979.34 kB = 1.93 MB
  8. Load Address: 30008000
  9. Entry Point: 30008000
  10. [skywalker@bogon u-boot-2009.08]$

③、Nand Flash的分区。我们查看内核在arch/arm/plat-s3c24xx/common-smdk.c中的分区情况如下

  1.         [0] = {
  2.                 .name = "boot",
  3.                 .size = 0x00020000,
  4.                 .offset = 0
  5.         },
  6.         [1] = {
  7.                 .name = "bootParam",
  8.                 .size = 0x00060000,
  9.                 .offset = 0x00020000,
  10.         },
  11.         [2] = {
  12.                 .name = "Kernel",
  13.                 .size = 0x00300000,
  14.                 .offset = 0x00500000,
  15.         },
  16.         [3] = {
  17.                 .name = "fs_yaffs",
  18.                 .size = 0x03c00000,
  19.                 .offset = 0x00800000,
  20.         },
  21.         [4] = {
  22.                 .name = "eboot",
  23.                 .size = 0x00080000,
  24.                 .offset = 0x04400000,
  25.         },
  26.         [5] = {
  27.                 .name = "WINCE",
  28.                 .size = 0x03b80000,
  29.                 .offset = 0x04480000,
  30.         }

④、设置修改u-boot的启动参数,在u-boot命令行下输入。设置启动参数,意思是将nand中0x500000(offset)-0x00800000(offset+size)(和kernel分区一致)的内容读到内存0x31000000中,然后用bootm命令来执行

  1. U-Boot 2009.08 ( 3.. 03 2011 - 20:48:30)

  2. DRAM: 64 MB
  3. Flash: 512 kB
  4. NAND: NAND_ECC_NONE selected by board driver. This is not recommended !!
  5. 128 MiB
  6. In: serial
  7. Out: serial
  8. Err: serial
  9. Net: dm9000 ' - try 'help'
  10. [yyq2440] # set bootcmd 'nand read 0x31000000 0x500000 0x800000;bootm 0x3100000
  11. [yyq2440] # saveenv
    Saving Environment to NAND...
    Erasing Nand...
    Erasing at 0x2 -- 262144% complete.
    Writing to Nand... done
    [yyq2440] #

⑤、把uImage.img用tftp下载到内存中,然后再固化到Nand Flash中,操作和执行图如下:

  1. [yyq2440] # tftp 0x30000000 uImage.img
  2. dm9000 i/o: 0x20000000, id: 0x90000a46
  3. DM9000: running in 16 bit mode
  4. MAC: 08:00:3e:26:0a:5b
  5. operating at 100M full duplex mode
  6. Using dm9000 device
  7. TFTP from server 192.168.7.11; our IP address is 192.168.7.1
  8. Filename 'uImage.img'.
  9. Load address: 0x30000000
  10. Loading: T T T T T T T #################################T######################
  11.          ##T T ###############################################################
  12.          ##T T #########
  13. done
  14. Bytes transferred = 2026908 (1eed9c hex)
  15. [yyq2440] #

在执行擦除和烧写的时候,却出现了坏块的提示,并失败。

  1. [yyq2440] # nand erase 0x500000 0x800000
  2.                                                                                 
  3. NAND erase: device 0 offset 0x500000, size 0x800000
  4. Skipping bad block at 0x00000000
  5. Skipping bad block at 0x00000000
  6. Skipping bad block at 0x00000000
  7. Skipping bad block at 0x00000000
  8. Skipping bad block at 0x00000000
  9. Skipping bad block at 0x00000000
  10. Skipping bad block at 0x00000000
  11. Skipping bad block at 0x00000000
  12. Skipping bad block at 0x00000000
  13. Skipping bad block at 0x00000000
  14. Skipping bad block at 0x00000000
  15. Skipping bad block at 0x00000000
  16. Skipping bad block at 0x00000000
  17. Skipping bad block at 0x00000000
  18. Skipping bad block at 0x00000000
  19. Erasing at 0x8 -- 13500416% complete.
  20. OK
  21. [yyq2440] # nand write 0x30000000 0x500000 0x800000

  22. NAND write: device 0 offset 0x500000, size 0x800000
  23. Skip bad block 0x00000000
  24. Skip bad block 0x00000000
  25. Skip bad block 0x00000000
  26. Skip bad block 0x00000000
  27. Skip bad block 0x00000000
  28. Skip bad block 0x00000000
  29. Skip bad block 0x00000000
  30. Skip bad block 0x00000000
  31. Skip bad block 0x00000000
  32. Skip bad block 0x00000000
  33. Skip bad block 0x00000000
  34. Skip bad block 0x00000000
  35. Skip bad block 0x00000000
  36. Skip bad block 0x00000000
  37. Skip bad block 0x00000000
  38. NAND write to offset ffffffff failed 13631488
  39.  6422528 bytes written: ERROR
  40. [yyq2440] #

这个时候我擦除了整块的nandflash就好了。

  1. [yyq2440] # nand scrub
  2.                                                                                 
  3. NAND scrub: device 0 whole chip
  4. Warning: scrub option will erase all factory set bad
  5.          There is no reliable way to recover them.
  6.          Use this command only for testing purposes if you
  7.          are sure of what you are
  8.                                                                                 
  9. Really scrub this NAND flash? <y/N>
  10. Erasing at 0x8 -- 24117248% complete..
  11. NAND 128MiB 3,3V 8-bit: MTD Erase failure: -5
  12. Erasing at 0x8000000 -- 52297728% complete.
  13. NAND 128MiB 3,3V 8-bit: MTD Erase failure: -5
  14. Erasing at 0x8000000 -- 134086656% complete.
  15. OK
  16. [yyq2440] # tftp 0x30000000 uImage.img
  17. dm9000 i/o: 0x20000000, id: 0x90000a46
  18. DM9000: running in 16 bit mode
  19. MAC: 08:00:3e:26:0a:5b
  20. operating at 100M full duplex mode
  21. Using dm9000 device
  22. TFTP from server 192.168.7.11; our IP address is 192.168.7.1
  23. Filename 'uImage.img'.
  24. Load address: 0x30000000
  25. Loading: #T T T T T ###################################T #######################
  26.          ###T T ####T ###########################################T #############
  27.          ##T T #######
  28. done
  29. Bytes transferred = 2026908 (1eed9c hex)
  30. [yyq2440] # nand erase 0x500000 0x800000
  31.                                                                                 
  32. NAND erase: device 0 offset 0x500000, size 0x800000
  33. Erasing at 0x8 -- 13500416% complete.
  34. OK
  35. [yyq2440] # nand write 0x30000000 0x500000 0x800000
  36.                                                                                 
  37. NAND write: device 0 offset 0x500000, size 0x800000
  38.  8388608 bytes written: OK
  39. [yyq2440] #

最后,我们重新启动开发板,可以看到,内核被u-boot成功引导起来了,如图:

  1. U-Boot 2009.08 ( 3.. 03 2011 - 20:48:30)
  2.                                                                                 
  3. DRAM: 64 MB
  4. Flash: 512 kB
  5. NAND: NAND_ECC_NONE selected by board driver. This is not recommended !!
  6. 128 MiB
  7. In: serial
  8. Out: serial
  9. Err: serial
  10. Net: dm9000
  11. Hit any key to stop autoboot: 0
  12.                                                                                 
  13. NAND read: device 0 offset 0x500000, size 0x800000
  14.  8388608 bytes read: OK
  15. ## Booting kernel from Legacy Image at 31000000 ...
  16.    Image Name: linux-2.6.33.7
  17.    Created: 2011-03-04 12:35:51 UTC
  18.    Image Type: ARM Linux Kernel Image (uncompressed)
  19.    Data Size: 2026844 Bytes = 1.9 MB
  20.    Load Address: 30008000
  21.    Entry Point: 30008000
  22.    Verifying Checksum ... OK
  23.    Loading Kernel Image ... OK
  24. OK
  25.                                                                                 
  26. Starting kernel ...
  27.                                                                                 
  28. Uncompressing Linux... done, booting the kernel.
  29. Linux version 2.6.33.7 (skywalker@localhost.localdomain) (gcc version 4.3.2 (So1
  30. CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177
  31. CPU: VIVT data cache, VIVT instruction cache
  32. Machine: SMDK2410
  33. Warning: bad configuration page, trying to continue
  34. Memory policy: ECC disabled, Data cache writeback
  35. CPU S3C2440A (id 0x32440001)

 

 

2011-03-04

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP