现在的位置: 首页 > 综合 > 正文

U-Boot直接引导zImage内核

2013年10月16日 ⁄ 综合 ⁄ 共 3334字 ⁄ 字号 评论关闭

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. #ifdef CONFIG_CMDLINE_TAG
  11. char *commandline = getenv ("bootargs");
  12. #endif
  13. //theKernel = (void (*)(int, int, uint))ntohl(hdr->ih_ep);
  14. 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.

抱歉!评论已关闭.