在Linux内核中定义平台设备
我引用下面的Lik来描述我的嵌入式Arm linux板中作为平台设备使用的所有驱动程序,需要澄清几点。请就这些提出建议 ===================定义平台驱动程序==================在Linux内核中定义平台设备,linux,linux-kernel,embedded-linux,Linux,Linux Kernel,Embedded Linux,我引用下面的Lik来描述我的嵌入式Arm linux板中作为平台设备使用的所有驱动程序,需要澄清几点。请就这些提出建议 ===================定义平台驱动程序================== static struct platform_driver serial_imx_driver = { .probe = serial_imx_probe, .remove = serial_imx_remove, .driver = { .name = "imx-uart", .ow
static struct platform_driver serial_imx_driver = {
.probe = serial_imx_probe,
.remove = serial_imx_remove,
.driver = {
.name = "imx-uart",
.owner = THIS_MODULE,
},
};
static struct platform_device imx_uart1_device = {
.name = "imx-uart",
.id = 0,
.num_resources = ARRAY_SIZE(imx_uart1_resources),
.resource = imx_uart1_resources,
.dev = {
.platform_data = &uart_pdata,
}
};
static struct platform_device *devices[] __initdata = {
&cs89x0_device,
&imx_uart1_device,
&imx_uart2_device,
};
static void __init mx1ads_init(void)
{
[...]
platform_add_devices(devices, ARRAY_SIZE(devices));
[...]
}
MACHINE_START(MX1ADS, "Freescale MX1ADS")
[...]
.init_machine = mx1ads_init,
MACHINE_END
======================定义平台设备================
static struct platform_driver serial_imx_driver = {
.probe = serial_imx_probe,
.remove = serial_imx_remove,
.driver = {
.name = "imx-uart",
.owner = THIS_MODULE,
},
};
static struct platform_device imx_uart1_device = {
.name = "imx-uart",
.id = 0,
.num_resources = ARRAY_SIZE(imx_uart1_resources),
.resource = imx_uart1_resources,
.dev = {
.platform_data = &uart_pdata,
}
};
static struct platform_device *devices[] __initdata = {
&cs89x0_device,
&imx_uart1_device,
&imx_uart2_device,
};
static void __init mx1ads_init(void)
{
[...]
platform_add_devices(devices, ARRAY_SIZE(devices));
[...]
}
MACHINE_START(MX1ADS, "Freescale MX1ADS")
[...]
.init_machine = mx1ads_init,
MACHINE_END
=======内核启动代码位置-/arch/arm/mach imx/mx1ads.c===========
static struct platform_driver serial_imx_driver = {
.probe = serial_imx_probe,
.remove = serial_imx_remove,
.driver = {
.name = "imx-uart",
.owner = THIS_MODULE,
},
};
static struct platform_device imx_uart1_device = {
.name = "imx-uart",
.id = 0,
.num_resources = ARRAY_SIZE(imx_uart1_resources),
.resource = imx_uart1_resources,
.dev = {
.platform_data = &uart_pdata,
}
};
static struct platform_device *devices[] __initdata = {
&cs89x0_device,
&imx_uart1_device,
&imx_uart2_device,
};
static void __init mx1ads_init(void)
{
[...]
platform_add_devices(devices, ARRAY_SIZE(devices));
[...]
}
MACHINE_START(MX1ADS, "Freescale MX1ADS")
[...]
.init_machine = mx1ads_init,
MACHINE_END
===============================
static struct platform_driver serial_imx_driver = {
.probe = serial_imx_probe,
.remove = serial_imx_remove,
.driver = {
.name = "imx-uart",
.owner = THIS_MODULE,
},
};
static struct platform_device imx_uart1_device = {
.name = "imx-uart",
.id = 0,
.num_resources = ARRAY_SIZE(imx_uart1_resources),
.resource = imx_uart1_resources,
.dev = {
.platform_data = &uart_pdata,
}
};
static struct platform_device *devices[] __initdata = {
&cs89x0_device,
&imx_uart1_device,
&imx_uart2_device,
};
static void __init mx1ads_init(void)
{
[...]
platform_add_devices(devices, ARRAY_SIZE(devices));
[...]
}
MACHINE_START(MX1ADS, "Freescale MX1ADS")
[...]
.init_machine = mx1ads_init,
MACHINE_END
在linux/drivers/folder中,如果我有10个文件夹用于10个不同的平台驱动程序。我希望内核源代码中只包含6个驱动程序?
那么,我的内核如何知道要包含哪个驱动程序呢
平台驱动程序是作为模块编译还是在内核中静态编译
当我们调用platform\u add\u devices()
系统调用时会发生什么
在进行平台添加设备()系统调用之前,内核中包含的所有平台驱动程序是否都加载到ram中
在内核源代码中的哪个路径/文件中,我可以定义我的嵌入式linux系统中使用的所有平台设备(意味着描述板上使用的所有平台设备)?基本上,平台驱动程序在板文件中注册(例如
/arch/arm/mach imx/eukrea_mbimx27-baseboard.c
)。现代系统使用这种方法
为了编译驱动程序,必须首先选择它(例如通过makemenuconfig
)。因此,如果选择6个驱动程序,那么将编译6个驱动程序
platform\u add\u devices()
注册平台驱动程序(将它们添加到列表中,请参阅drivers/base/platform.c
),以便内核知道在引导阶段要初始化哪些驱动程序
平台驱动程序是内核的一部分,所以一旦内核映像本身被加载,它们就在RAM中
有关更多详细信息,请参阅此部分。基本上,平台驱动程序注册在板文件中(例如
/arch/arm/mach imx/eukrea_mbimx27-baseboard.c
)。现代系统使用这种方法
为了编译驱动程序,必须首先选择它(例如通过makemenuconfig
)。因此,如果选择6个驱动程序,那么将编译6个驱动程序
platform\u add\u devices()
注册平台驱动程序(将它们添加到列表中,请参阅drivers/base/platform.c
),以便内核知道在引导阶段要初始化哪些驱动程序
平台驱动程序是内核的一部分,所以一旦内核映像本身被加载,它们就在RAM中
更多详细信息,请参见此。平台设备(不是驱动程序,如上文所述)在板文件中声明,如/arch/arm/mach-*
并通过platform\u add\u devices()。
这个板文件是静态编译的,并链接到内核
platform\u add\u devices()
不是系统调用。它是内核APIplatform\u device\u register()
后来与司机联系在一起
平台驱动程序通常与内核静态链接,当调用Platform\u driver\u register()
时,内核会尝试通过匹配Platform\u device
和Platform\u driver
name
属性将驱动程序绑定到设备
如果匹配,则注册驱动程序并调用驱动程序的probe()
函数
显然,在加载驱动程序之前,必须先注册设备
现在使用设备树文件代替板文件。
来自单独设备树blob文件的设备由内核注册,并与具有兼容的
字符串属性的驱动程序匹配。
因此,必须在设备驱动程序结构和
设备树文件中的设备节点
目标是,当您更改设备或其属性时,您必须只重新编译设备树文件,而不是内核本身。平台设备(不是驱动程序,如上所述)在板文件中声明,如/arch/arm/mach-*
并通过platform\u add\u devices()。
这个板文件是静态编译的,并链接到内核
platform\u add\u devices()
不是系统调用。它是内核APIplatform\u device\u register()
后来与司机联系在一起
平台驱动程序通常与内核静态链接,当调用Platform\u driver\u register()
时,内核会尝试通过匹配Platform\u device
和Platform\u driver
name
属性将驱动程序绑定到设备
如果匹配,则注册驱动程序并调用驱动程序的probe()
函数
显然,在加载驱动程序之前,必须先注册设备
现在使用设备树文件代替板文件。
来自单独设备树blob文件的设备由内核注册,并与具有兼容的
字符串属性的驱动程序匹配。
因此,必须在设备驱动程序结构和
设备树文件中的设备节点
目标是,当您更改设备或其属性时,您必须只重新编译设备树文件,而不是内核本身。因此,在现代系统中,板文件包含设备树,或者设备树通过uboot传递到内核。。。还告诉您使用makemenuconfig选择驱动程序。。。假设平台驱动程序不在内核中&我必须添加它,所以在本例中,我必须在内核源代码中通过修改makefile静态地执行它?使用设备树方法,您基本上有两个文件:内核映像和设备树blob(*.dtb
)。这两个文件都将通过u-boot加载。要添加内核驱动程序,请参见以下内容。因此,在现代系统板文件中,包含设备树或设备树是通过uboot传递给内核的。。。还告诉您使用make选择驱动程序