在内核代码中经常会看到__setup函数,这个函数从哪来,到哪去?下面我们逐一分析
例如在I2C驱动中就有这么一个setup函数:
__setup("i2c_bus=", omap_i2c_bus_setup);
#define __setup_param(str, unique_id, fn, early) \
static const char __setup_str_##unique_id[] __initconst \
__aligned(1) = str; \
static struct obs_kernel_param __setup_##unique_id \
__used __section(.init.setup) \
__attribute__((aligned((sizeof(long))))) \
= { __setup_str_##unique_id, fn, early }
#define __setup(str, fn) \
__setup_param(str, fn, fn, 0)
static const char __setup_str_omap_i2c_bus_setup[]= "i2c_bus=";
static struct obs_kernel_param __setup_omap_i2c_bus_setup = { __setup_str_omap_i2c_bus_setup, omap_i2c_bus_setup, 0}
static int __init obsolete_checksetup(char *line)
{
const struct obs_kernel_param *p;
int had_early_param = 0;
p = __setup_start;
do {
int n = strlen(p->str);
if (parameqn(line, p->str, n)) {
if (p->early) {
/* Already done in parse_early_param?
* (Needs exact match on param part).
* Keep iterating, as we can have early
* params and __setups of same names 8( */
if (line[n] == '\0' || line[n] == '=')
had_early_param = 1;
} else if (!p->setup_func) {
printk(KERN_WARNING "Parameter %s is obsolete,"
" ignored\n", p->str);
return 1;
} else if (p->setup_func(line + n))
return 1;
}
p++;
} while (p < __setup_end);
return had_early_param;
}
omap_i2c_bus_setup
函数,而这个函数应该在你的代码中体现出来的。自己的初始化函数。