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文件中。
int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { ulong iflag; ulong addr; ulong data, len, checksum; ulong *len_ptr; uint unc_len = CFG_BOOTM_LEN; int i, verify; char *name, *s; int (*appl)(int, char *[]); image_header_t *hdr = &header; s = getenv ("verify"); verify = (s && (*s == 'n')) ? 0 : 1; if (argc < 2) { addr = load_addr; } else { addr = simple_strtoul(argv[1], NULL, 16); } SHOW_BOOT_PROGRESS (1); ////////////////////////////////////////////////////////////////////////////////// //printf ("## Booting image at %08lx ...\n", addr); printf ("## Booting from zImage at %08lx ---by ce123\n", addr); #ifdef CONFIG_SILENT_CONSOLE fixup_silent_linux(); #endif do_bootm_linux (cmdtp, flag, argc, argv, addr, len_ptr, verify); ////////////////////////////////////////////////////////////////////////////////// ......
接下来还要修改一下lib_arm/armlinux.c中的do_bootm_linux函数。这里主要是修改kernal的加载地址(theKernel = (void (*)(int, int, uint))addr)。这就要求我们将zImage内核下载内存的addr处。并且用bootm addr进行引导,默认的地址是0x30008000,如果直接使用bootm进行引导,则需要将内核下载到0x30008000,否则无法引导内核。
void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], ulong addr, ulong *len_ptr, int verify) { ulong len = 0, checksum; ulong initrd_start, initrd_end; ulong data; void (*theKernel)(int zero, int arch, uint params); image_header_t *hdr = &header; bd_t *bd = gd->bd; #ifdef CONFIG_CMDLINE_TAG char *commandline = getenv ("bootargs"); #endif //theKernel = (void (*)(int, int, uint))ntohl(hdr->ih_ep); 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.