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文件中。

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值