linux3.* 内核的__setup函数
来源:互联网 发布:乐玩编程助手 编辑:程序博客网 时间:2024/05/18 18:00
在内核代码中经常会看到__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 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;}
这里的意思是从__setup_start开始处到__setup_end处中查找一个数据结构,这个数据结构中有str与setup_func这两个数据成员变量. 只要与这里面的str与输入的参数字符串相匹配,就会调用个这个字符串后面所指的内容.意思也就是调用
omap_i2c_bus_setup函数,而这个函数应该在你的代码中体现出来的。自己的初始化函数。
阅读全文
0 0
- linux3.* 内核的__setup函数
- Linux内核代码中的__setup的用途
- Linux内核代码中的__setup的用途
- Linux内核代码中的__setup的用途
- Linux内核中__setup的用途
- 裁剪Linux3.0.8内核遇到的问题
- 基于arm9的linux3.0内核移植
- linux3.4.2内核定时器time_list的使用
- __setup 在内核中的作用
- __setup 在内核中的作用
- __setup 在内核中的作用
- __setup 在内核中的作用
- __setup的作用
- linux __setup的作用
- __setup
- 如何下载Android4.0配套的linux3.x内核源代码
- Linux3.4内核的基本配置和编译
- linux3.1内核移植到S3C2416的过程和问题。
- 什么是IOU
- 计算机视觉中对训练数据处理以提高分类器性能的技巧
- 堆排序
- Select 语句执行顺序以及如何提高Oracle 基本查询效率
- 专业的HTML操作API Aspose.Html 上架 | 附试用版下载
- linux3.* 内核的__setup函数
- 富文本编辑器ueditor的使用实践
- Anaconda 安装程序网址
- 不做高频,量化策略到底能不能战胜抛硬币?
- Kafka vs RocketMQ——单机系统可靠性
- Python--类的高级特性
- 二、MySQL数据库数据迁移
- windows从注册表获取ip配置信息
- Android_监听系统短信