使用__setup从cmd命令行获取参数

灰太狼 2022-11-15 12:28 273阅读 0赞

内核组件用__setup宏来注册关键字及相关联的处理函数,__setup宏在include/linux/init.h中定义,其原型如下:
__setup(string, function_handler)
其 中:string是关键字,function_handler是关联处理函数。__setup只是告诉内核在启动时输入串中含有string时,内核要去执行function_handler。String必须以“=”符结束以使parse_args更方便解析。紧随“=”后的任何文本都会作为输入传给 function_handler。

(1)如果是读取数据,用如下方式:
static int g_ledCurrPulseCount = 1; //bklt pulse count from u-boot

  1. static int __init bklt_pulse_get(char *str)
  2. {
  3. int len = 0;
  4. if (str != NULL)
  5. len = kstrtou32(str, 10, &g_ledCurrPulseCount);
  6. pr_info("[LED] bklt pulse from uboot: %d\n", g_ledCurrPulseCount);
  7. return 0;
  8. }

__setup(“bklt_pulse=”, bklt_pulse_get);

(2)如果是读取字符串,可以用如下方式:
static unsigned int pinctrl_autotest;

  1. static __init int sprd_pinctrl_autotest_mode(char *str)
  2. {
  3. if (strcmp(str, "autotest"))
  4. pinctrl_autotest = 0;
  5. else
  6. pinctrl_autotest = 1;
  7. return 0;
  8. }

__setup(“androidboot.mode=”, sprd_pinctrl_autotest_mode);

这样就可以在驱动的probe函数中去使用pinctrl_autotest了。

发表评论

表情:
评论列表 (有 0 条评论,273人围观)

还没有评论,来说两句吧...

相关阅读

    相关 node命令获取参数

    node命令行获取参数 随着前端工程化的演变,在项目中时常会需要自己写一些脚本来方便完成一些自动化的流程操作,而对于前端开发来说,`node`可能是首选了,为了我们脚本使