资源描述:
《U-Boot启动引导内核分析(二)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、U-Boot启动引导内核分析(二)2011-03-2309:20:00
2、分类:默认分类
3、标签:
4、字号大中小订阅也许细心的你会问:我在用UBoot的时候并没有直接进入用户命令界面呀,而是在倒计时结束后自动引导kernel。这是怎么回事呢?在main_loop()函数当中有如下一段代码:#ifdefined(CONFIG_BOOTDELAY)&&(CONFIG_BOOTDELAY>=0)???s=getenv("bootcmd");/*获取bootcmd的内容*//*bootcmd=nandread0x220000000xB00000x
5、200000;bootm*/??#ifndefCFG_HUSH_PARSERrun_command(s,0);/*运行s包含的命令*//*运行nandread0x220000000xB00000x200000表示将NANDFLASH0xB0000处数据读取放于0x22000000处,读取长度为0x200000*//*运行bootm命令,引导内核启动*/#elseparse_string_outer(s,FLAG_PARSE_SEMICOLON
6、FLAG_EXIT_FROM_LOOP);#endif???#endif/*CONFIG_
7、BOOTDELAY*/bootm命令是什么?它是怎样引导内核的?要知道想解决这个问题,就要分析common/cmd_bootm.c中的函数do_bootm,因为引导kernel就是bootm这条命令的工作,do_bootm是命令bootm的执行函数。现在我们来分析一下common/cmd_bootm.c中的函数do_bootm,这是bootm命令的处理函数。intdo_bootm(cmd_tbl_t*cmdtp,intflag,intargc,char*argv[]){ulongiflag;constchar*type_name;u
8、intunc_len=CFG_BOOTM_LEN;uint8_tcomp,type,os;void*os_hdr;ulongos_data,os_len;ulongimage_start,image_end;ulongload_start,load_end;ulongmem_start;phys_size_tmem_size;structlmblmb;memset((void*)&images,0,sizeof(images));images.verify=getenv_yesno("verify");images.lmb=&lmb
9、;lmb_init(&lmb);mem_start=getenv_bootm_low();mem_size=getenv_bootm_size();lmb_add(&lmb,(phys_addr_t)mem_start,mem_size);board_lmb_reserve(&lmb);/*getkernelimageheader,startaddressandlength*//*获取内核镜像头信息*//*打印“##BootingkernelfromLegacyImageat22000000...ImageName:Linux-2.
10、6.30ImageType:ARMLinuxKernelImage(uncompressed)DataSize:1507760Bytes=1.4MBLoadAddress:20008000EntryPoint:20008000VerifyingChecksum...OK”*/os_hdr=boot_get_kernel(cmdtp,flag,argc,argv,&images,&os_data,&os_len);if(os_len==0){puts("ERROR:can'tgetkernelimage!");return1;}/
11、*getimageparameters*//*获取内核镜像格式*/switch(genimg_get_format(os_hdr)){caseIMAGE_FORMAT_LEGACY:/*获取内核镜像参数*/type=image_get_type(os_hdr);comp=image_get_comp(os_hdr);os=image_get_os(os_hdr);image_end=image_get_image_end(os_hdr);load_start=image_get_load(os_hdr);break;}image_s
12、tart=(ulong)os_hdr;load_end=0;type_name=genimg_get_type_name(type);/*禁止所有中断*/iflag=disable_interrupts();#ifdefCONFIG_