U-Boot直接引导zImage内核

 

U-Boot直接引导zImage内核

         U-boot1.1.6只能只能就能过mkimage工具加工后的内核镜像文件。mkimage工具给zImage增加了一个64B大小的头。U-Boot是通过bootm命令来引导Linux内核的,bootm命令调用do_bootm函数来mkimage工具增加的头,最后调用do_bootm_linux函数引导去掉了mkimage工具增加的头的Linux内核,也就是zImage,启动的流程可以参考图解U-Boot:引导内核分析这篇博客。

     要让U-Boot直接引导zImage内核,只需在do_bootm函数中去掉对mkimage工具增加的头的分析,直接调用do_bootm_linux函数引导zImage内核即可。下面是经过修改的do_bootm函数,修改的部分用///包围起来了,省略号后面的就不需要改动了。这个函数common/cmd_bootm.c文件中。

  1. int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])  
  2. {  
  3.     ulong   iflag;  
  4.     ulong   addr;  
  5.     ulong   data, len, checksum;  
  6.     ulong  *len_ptr;  
  7.     uint    unc_len = CFG_BOOTM_LEN;  
  8.     int i, verify;  
  9.     char    *name, *s;  
  10.     int (*appl)(int, char *[]);  
  11.     image_header_t *hdr = &header;  
  12.     s = getenv ("verify");  
  13.     verify = (s && (*s == 'n')) ? 0 : 1;  
  14.     if (argc < 2) {  
  15.         addr = load_addr;  
  16.     } else {  
  17.         addr = simple_strtoul(argv[1], NULL, 16);  
  18.     }  
  19.     SHOW_BOOT_PROGRESS (1);  
  20. //  
  21.     //printf ("## Booting image at %08lx ...\n", addr);  
  22.     printf ("## Booting from zImage at %08lx ---by ce123\n", addr);  
  23. #ifdef CONFIG_SILENT_CONSOLE  
  24.         fixup_silent_linux();  
  25. #endif  
  26.         do_bootm_linux  (cmdtp, flag, argc, argv,  
  27.                  addr, len_ptr, verify);  
  28. //  
  29. ......  

接下来还要修改一下lib_arm/armlinux.c中的do_bootm_linux函数。这里主要是修改kernal的加载地址(theKernel = (void (*)(int, int, uint))addr)。这就要求我们将zImage内核下载内存的addr处。并且用bootm addr进行引导,默认的地址是0x30008000,如果直接使用bootm进行引导,则需要将内核下载到0x30008000,否则无法引导内核。

  1. void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],  
  2.              ulong addr, ulong *len_ptr, int verify)  
  3. {  
  4.     ulong len = 0, checksum;  
  5.     ulong initrd_start, initrd_end;  
  6.     ulong data;  
  7.     void (*theKernel)(int zero, int arch, uint params);  
  8.     image_header_t *hdr = &header;  
  9.     bd_t *bd = gd->bd;  
  10.   
  11.   
  12. #ifdef CONFIG_CMDLINE_TAG  
  13.     char *commandline = getenv ("bootargs");  
  14. #endif  
  15.   
  16.   
  17.     //theKernel = (void (*)(int, int, uint))ntohl(hdr->ih_ep);  
  18.     theKernel = (void (*)(int, int, uint))addr;  

下面是引导信息:

U-Boot 1.1.6 (Mar 11 2012 - 14:06:15)


DRAM:  64 MB
Flash:  2 MB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Hit any key to stop autoboot:  0

NAND read: device 0 offset 0x240000, size 0x200000
 2097152 bytes read: OK
## Booting from zImage at 30008000 ---by ce123

Starting kernel ...

Uncompressing Linux.............................................................
............................................................. done, booting the
kernel.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值