kernel里获取uboot的环境变量

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错误

在这里插入图片描述
改造的方法仍然只能是放在built-in的代码中

在linux内核驱动中使用__setup宏提取uboot的bootargs参数

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值