资源描述:
《Linux启动参数及实现》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Linux启动参数及实现__setup与early_param#define__setup_param(str,unique_id,fn,early) / staticchar__setup_str_##unique_id[]__initdata=str; / staticstructobs_kernel_param__setup_##unique_id / __attribute_used__ / __attribute__((__section__(".i
2、nit.setup"))) / __attribute__((aligned((sizeof(long))))) / ={__setup_str_##unique_id,fn,early} #define__setup(str,fn) / __setup_param(str,fn,fn,0) #defineearly_param(str,fn) / __setup_param(str,fn,fn,1)__setup与ea
3、rly_param不同的是,early_param宏注册的内核选项必须要在其他内核选项之前被处理。在函数start_kernel中,parse_early_param处理early_param定义的参数,parse_args处理__setup定义的参数。 parse_early_param(); parse_args("Bootingkernel",static_command_line,__start___param, __stop___param-__start___param, &unknown_bootoption); 1
4、,所有的系统启动参数都是由形如staticint__initfoo(char*str);的函数来支持的注:#define__init __attribute__((__section__(".init.text")))申明所有的启动参数支持函数都放入.init.text段2.1,用__setup宏来导出参数的支持函数__setup("foo=",foo);展开后就是如下的形式staticchar__setup_str_foo[]__initdata="foo="; staticstructobs_kernel_param__set
5、up_foo __attribute_used__ __attribute__((__section__(".init.setup"))) __attribute__((aligned((sizeof(long))))) ={__setup_str_foo,foo,0};//"foo=",foo,0也就是说,启动参数(函数指针)被封装到obs_kernel_param结构中,所有的内核启动参数形成内核映像.init.setup段中的一个obs_kern
6、el_param数组2.2用early_param宏来申明需要'早期'处理的启动参数,例如在arch/i386/kernel/setup.c就有如下的申明:early_param("mem",parse_mem);展开后和__setup是一样的只是early参数不一样,因此会在do_early_param中被处理3,内核对启动参数的解析:下面函数历遍obs_kernel_param数组,调用支持函数staticint__initdo_early_param(char*param,char*val){ structobs_kernel_para
7、m*p; for(p=__setup_start;p<__setup_end;p++){ if(p->early&&strcmp(param,p->str)==0){ if(p->setup_func(val)!=0) printk(KERN_WARNING "Malformedearlyoption'%s'/n",param); } } /*Weaccepteverythingatthisstage.*/ retur
8、n0;}这个函数在parse_early_param中被调用,而parse_early_param在start_kernel中被调用,p