您的位置:首页 > 运维架构 > Linux

linux之early_param()和__setup

2016-08-27 11:14 447 查看
原理:

在linux启动时,调用在init/main.c里面的start_kernel()时,执行到parse_early_param()时,uboot传递的cmdline里面有相应的命令,就会调用early_param()和__setup注册的函数。可以在驱动模块的任何c文件里面用early_param(),__setup()注册,只需要包含include/linux/init.h头文件

用法例子:

如在printk.c里面的:

static int __init boot_delay_setup(char *str)
{
unsigned long lpj;

lpj = preset_lpj ? preset_lpj : 1000000;/* some guess */
loops_per_msec = (unsigned long long)lpj / 1000 * HZ;

get_option(&str, &boot_delay);
if (boot_delay > 10 * 1000)
boot_delay = 0;

pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, "
"HZ: %d, loops_per_msec: %llu\n",
boot_delay, preset_lpj, lpj, HZ, loops_per_msec);
return 0;
}
early_param("boot_delay", boot_delay_setup);


如果uboot传递的cmdline里面有"boot_delay",则函数boot_delay_setup()在linux启动时会被调用

参考:

http://blog.chinaunix.net/uid-27717694-id-3495617.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: