如果对linux源码结构不熟悉的话,在linux内核中查找定义是一个很痛苦的事。
对于ARM OMAP平台,linux内核头文件的路径主要有三个 include arch/arm/include arch/arm/palt-omap/include
但是今天追一个定义的时候怎么也找不到,该定义出现在arc/arm/mach-omap2/board-4430sdp.c中,代码如下
MACHINE_START(OMAP_4430SDP, "OMAP4430 4430SDP board")
/* Maintainer: Santosh Shilimkar - Texas Instruments Inc */
.atag_offset = 0x100,
.reserve = omap_reserve,
.map_io = omap4_map_io,
.init_early = omap4430_init_early,
.init_irq = gic_init_irq,
.init_machine = omap_4430sdp_init,
.timer = &omap4_timer,
.restart = omap_prcm_restart,
MACHINE_END
MACHINE_START(OMAP_4430SDP, "OMAP4430 4430SDP board")引用了宏定义,在arch/arm/include/asm/mach/arch.h中定义:
#define MACHINE_START(_type,_name) \
static const struct machine_desc __mach_desc_##_type \
__used \
__attribute__((__section__(".arch.info.init"))) = { \
.nr = MACH_TYPE_##_type, \
.name = _name,
#define MACHINE_END \
};
展开后就是
static const struct machine_desc __mach_desc_OMAP_4430SDP
{
.nr = MACH_TYPE_OMAP_4430SDP,
.name = "OMAP4430 4430SDP board",
...
}
但是MACH_TYPE_OMAP_4430SDP,这个宏定义怎么也找不到,多处grep无果后,只好求助网络
查到其定义是在编译时由脚本生成的,生成工具在arch/arm/tools中,生成文件为arch/arm/include/generated/mach-types.h
该文件被arch/arm/include/asm/mach-types.h包含,而arc/arm/mach-omap2/board-4430sdp.c包含arch/arm/include/asm/mach-types.h
这个变量的具体值可以在arch/arm/tools/mach-types中找到:
omap_4430sdp MACH_OMAP_4430SDP OMAP_4430SDP 2160
该文件是文本文件,脚本通过解析其格式来生成头文件。
最后给各位在内核代码中追函数追变量追结构体的同仁们推荐一个网址:lxr.free-electrons.com/ident?v=3.2&i=+
在这里输入要查找到的变量或者函数,分分中出结果啊~~~
参考:blog.163.com/ericxia_gnikam/blog/static/96920879200811100105417/