原理:
在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启动时会被调用
参考: