linux3.* 内核的__setup函数

本文探讨了Linux内核3.x版本中常见的__setup函数,通过实例分析其起源和作用,特别是在I2C驱动中的应用。
摘要由CSDN通过智能技术生成

在内核代码中经常会看到__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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值