湖水连天天连水,秋来分外澄清
分类: 嵌入式
2016-11-14 16:21:21
平台:tiny210v2
uboot版本:1.3.4(其他版本也使用)
正文;网络上找了一下支持zImage的移植方法,流传最多的就是上一篇博客里面的,但是对于s5pv210不适用,自己改了一个,其实道理很简单,从uboot启动参数位置找到合适的参数,传给内核即可。
在U-boot的common/目录下添加cmd_bootzImage.c文件。
在common/Makefile中添加COBJS-$(CONFIG_CMD_BOOTZIMAGE) += cmd_bootzImage.o
在配置文件中添加#define CONFIG_CMD_BOOTZIMAGE
通过以上的修改我们就可以用bootzImage来启动内核了,我的自启动是
#define CONFIG_BOOTCOMMAND "tftp 0x20008000 zImage;bootzImage"
代码如下:
#include
#include
#define LINUX_MACHINE_ID 2456//根据平台修改
static void setup_linux_param(long param_base)
{
/* start of tags */
struct tag *params = (struct tag *)param_base;
params->hdr.tag = ATAG_CORE;
params->hdr.size = tag_size (tag_core);
params->u.core.flags = 0;
params->u.core.pagesize = 0;
params->u.core.rootdev = 0;
params = tag_next (params);
/* importart set SDRAM */
params->hdr.tag = ATAG_MEM;
params->hdr.size = tag_size (tag_mem32);
params->u.mem.start = 0x20000000;
params->u.mem.size = 0x20000000;
params = tag_next (params);
/* set bootargs */
char *commandline = getenv ("bootargs");
if (!commandline)
goto end;
params->hdr.tag = ATAG_CMDLINE;
params->hdr.size = (sizeof (struct tag_header) + strlen (commandline) + 1 + 4) >> 2;
strcpy (params->u.cmdline.cmdline, commandline);
params = tag_next (params);
end:
/* end of tags */
params->hdr.tag = ATAG_NONE;
params->hdr.size = 0;
}
void do_bootzImage(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
int i;
u32 addr;
ulong to=0x20008000; //内核在SDRAM中的起始地址
char *cmdline = getenv("bootargs");
void(*run)(int zero, int arch);
void(*kernel)(int zero, int arch, uint params);
setup_linux_param(0x20000100);
printf("NOW, Booting Linux……\n");
kernel = (void(*)(int, int, uint))(to);
kernel(0, LINUX_MACHINE_ID,0x20000100);
}
U_BOOT_CMD(
bootzImage, 2, 1, do_bootzImage,
"bootzImage --boot zImage from ram./n",
"boot zImage from 0x20008000."
);