Linux启动参数及实现 __setup与early_param
linux kernel的cmdline參数解析原理分析
在uboot项目板级配置中添加环境变量到系统,重要,一定要在bootargs里添加,内核才能访问到
diff --git a/include/configs/gxtvbb_p301_v1.h b/include/configs/gxtvbb_p301_v1.h
old mode 100644
new mode 100755
index 1996553..afd3ef4
--- a/include/configs/gxtvbb_p301_v1.h
+++ b/include/configs/gxtvbb_p301_v1.h
@@ -71,6 +71,7 @@
"firstboot=1\0"\
"upgrade_step=0\0"\
"loadaddr=1080000\0"\
+ "mode=WAKEUP_NONE\0" \
"panel_type=lvds_2\0" \
"outputmode=1080p60hz\0" \
"panel_reverse=0\0" \
@@ -109,6 +110,7 @@
"androidboot.selinux=disabled "\
"logo=${display_layer},loaded,${fb_addr} "\
"vout=${outputmode},enable "\
+ "switch_wakeup=${mode} " \
"panel_type=${panel_type} hdmitx= "\
"osd_reverse=${osd_reverse} video_reverse=${video_reverse} "\
"bl_off=${bl_off} "\
storeargs=setenv bootargs rootfstype=ramfs init=/init console=ttyS0,115200 no_console_suspend earlyprintk=aml-uart,0xc81004c0 androidboot.selinux=disabled logo=${display_layer},loaded,${fb_addr} vout=${outputmode},enable switch_wakeup=${mode} panel_type=${panel_type} hdmitx= osd_reverse=${osd_reverse} video_reverse=${video_reverse} bl_off=${bl_off} jtag=${jtag} ramoops.pstore_en=1 ramoops.record_size=0x8000 ramoops.console_size=0x4000 androidboot.firstboot=${firstboot}; setenv bootargs ${bootargs} androidboot.hardware=amlogic;run cmdline_keys;
内核可使用如下接口访问uboot中的环境变量
static int __init switch_wakeup_function(char *s)
{
if(NULL != s)
{
sprintf(switch_wakeup,"%s",s);
uboot_str = s;
}
// printk("%s %d:%s",__FUNCTION__,__LINE__,s);
printk("wakeup_function:%c %c\n",s[0],s[1]);
return 0;
}
__setup("switch_wakeup=", switch_wakeup_function);
函数switch_wakeup_function中的char *s的值即为从uboot传进来的环境变量的值
需要注意,在<linux/init.h>中__setup宏是在MODULE宏无效时起作用的,所以使用__setup宏的源文件在编译时需要使用[*]built-in方式,如果使用[M]module方式编译会报defined but not used错误