手机版
你好,游客 登录 注册
背景:
阅读新闻

U-Boot启动Linux内核

[日期:2012-04-23] 来源:Linux社区  作者:tianxiawuzhei [字体:大 中 小]

3、lib_arm/armlinux.c中do_bootm_linux函数源代码:

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);//设置kernal加载地址


/*
* Check if there is an initrd image用户定义了initrd后要加载进来。
*/
if (argc >= 3) {
SHOW_BOOT_PROGRESS (9);


addr = simple_strtoul (argv[2], NULL, 16);


printf ("## Loading Ramdisk Image at %08lx ...\n", addr);


/* Copy header so we can blank CRC field for re-calculation */
#ifdef CONFIG_HAS_DATAFLASH
if (addr_dataflash (addr)) {
read_dataflash (addr, sizeof (image_header_t),
(char *) &header);
} else
#endif
memcpy (&header, (char *) addr,
sizeof (image_header_t));


if (ntohl (hdr->ih_magic) != IH_MAGIC) {
printf ("Bad Magic Number\n");
SHOW_BOOT_PROGRESS (-10);
do_reset (cmdtp, flag, argc, argv);
}


data = (ulong) & header;
len = sizeof (image_header_t);


checksum = ntohl (hdr->ih_hcrc);
hdr->ih_hcrc = 0;


if (crc32 (0, (unsigned char *) data, len) != checksum) {
printf ("Bad Header Checksum\n");
SHOW_BOOT_PROGRESS (-11);
do_reset (cmdtp, flag, argc, argv);
}


SHOW_BOOT_PROGRESS (10);


print_image_hdr (hdr);


data = addr + sizeof (image_header_t);
len = ntohl (hdr->ih_size);


#ifdef CONFIG_HAS_DATAFLASH
if (addr_dataflash (addr)) {
read_dataflash (data, len, (char *) CFG_LOAD_ADDR);
data = CFG_LOAD_ADDR;
}
#endif


if (verify) {
ulong csum = 0;


printf ("   Verifying Checksum ... ");
csum = crc32 (0, (unsigned char *) data, len);
if (csum != ntohl (hdr->ih_dcrc)) {
printf ("Bad Data CRC\n");
SHOW_BOOT_PROGRESS (-12);
do_reset (cmdtp, flag, argc, argv);
}
printf ("OK\n");
}


SHOW_BOOT_PROGRESS (11);


if ((hdr->ih_os != IH_OS_LINUX) ||
   (hdr->ih_arch != IH_CPU_ARM) ||
   (hdr->ih_type != IH_TYPE_RAMDISK)) {
printf ("No Linux ARM Ramdisk Image\n");
SHOW_BOOT_PROGRESS (-13);
do_reset (cmdtp, flag, argc, argv);
}


#if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
/*
*we need to copy the ramdisk to SRAM to let Linux boot
*/
memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
data = ntohl(hdr->ih_load);
#endif /* CONFIG_B2 || CONFIG_EVB4510 */


/*
* Now check if we have a multifile image
*/
} else if ((hdr->ih_type == IH_TYPE_MULTI) && (len_ptr[1])) {
ulong tail = ntohl (len_ptr[0]) % 4;
int i;


SHOW_BOOT_PROGRESS (13);


/* skip kernel length and terminator */
data = (ulong) (&len_ptr[2]);
/* skip any additional image length fields */
for (i = 1; len_ptr[i]; ++i)
data += 4;
/* add kernel length, and align */
data += ntohl (len_ptr[0]);
if (tail) {
data += 4 - tail;
}


len = ntohl (len_ptr[1]);


} else {
/*
* no initrd image
*/
SHOW_BOOT_PROGRESS (14);


len = data = 0;
}


#ifdef DEBUG
if (!data) {
printf ("No initrd\n");
}
#endif


if (data) {
initrd_start = data;
initrd_end = initrd_start + len;
} else {
initrd_start = 0;
initrd_end = 0;
}



SHOW_BOOT_PROGRESS (15);


debug ("## Transferring control to Linux (at address %08lx) ...\n",
      (ulong) theKernel);


#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
    defined (CONFIG_CMDLINE_TAG) || \
    defined (CONFIG_INITRD_TAG) || \
    defined (CONFIG_SERIAL_TAG) || \
    defined (CONFIG_REVISION_TAG) || \
    defined (CONFIG_LCD) || \
    defined (CONFIG_VFD)
setup_start_tag (bd);
#ifdef CONFIG_SERIAL_TAG
setup_serial_tag (&params);
#endif
#ifdef CONFIG_REVISION_TAG
setup_revision_tag (&params);
#endif
#ifdef CONFIG_SETUP_MEMORY_TAGS  //设置memory tags
setup_memory_tags (bd);
#endif

#ifdef CONFIG_CMDLINE_TAG  //设置启动命令行tags
setup_commandline_tag (bd, commandline);
#endif

#ifdef CONFIG_INITRD_TAG  //存在ramdisk时设置initrdtag
if (initrd_start && initrd_end)
setup_initrd_tag (bd, initrd_start, initrd_end);
#endif

#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
setup_videolfb_tag ((gd_t *) gd);
#endif
setup_end_tag (bd);
#endif


/* we assume that the kernel is in place */
printf ("\nStarting kernel ...\n\n");


#ifdef CONFIG_USB_DEVICE
{
extern void udc_disconnect (void);
udc_disconnect ();
}
#endif


cleanup_before_linux ();//启动之前先做一些清理工作


theKernel (0, bd->bi_arch_number, bd->bi_boot_params);
}

调用内核需要传递的参数如下:

(1)R0:必须为0

(2)R1:机器类型ID,bd->bi_arch_number

(3)R2:启动参数列表在内存中的位置bd->bi_boot_params

linux
相关资讯       U-boot 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款