在内核代码中经常会看到__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)
可以清除的看出来__setup函数最后被宏替代成__setup_param函数,去掉纷繁复杂的各种连接。我们利用__setup("reset_devices", set_reset_devices);看看最终的表达形式是什么
static const char __setup_str_omap_i2c_bus_setup[]= "i2c_bus=";
static struct