- 论坛徽章:
- 0
|
刚开始接触设备模型,下面是源码和出错信息:
源码:
#include <linux/device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/string.h>
MODULE_AUTHOR("David ");
MODULE_LICENSE("Dual BSD/GPL");
static char *Version = "$Revision: 1.9 $";
static int my_match(struct device *dev, struct device_driver *driver)
{
return !strncmp(dev->bus_id, driver->name, strlen(driver->name));
}
static void my_bus_release(struct device *dev)
{
printk(KERN_DEBUG "my bus release\n");
}
struct device my_bus = {
.bus_id = "my_bus0",
.release = my_bus_release
};
struct bus_type my_bus_type = {
.name = "my_bus",
.match = my_match,
};
EXPORT_SYMBOL(my_bus);
EXPORT_SYMBOL(my_bus_type);
/*
* Export a simple attribute.
*/
static ssize_t show_bus_version(struct bus_type *bus, char *buf)
{
return snprintf(buf, PAGE_SIZE, "%s\n", Version);
}
static BUS_ATTR(version, S_IRUGO, show_bus_version, NULL);
static int __init my_bus_init(void)
{
int ret;
/*注册总线*/
ret = bus_register(&my_bus_type);
if (ret)
return ret;
/*创建属性文件*/
if (bus_create_file(&my_bus_type, &bus_attr_version))
printk(KERN_NOTICE "Fail to create version attribute!\n");
/*注册总线设备*/
ret = device_register(&my_bus);
if (ret)
printk(KERN_NOTICE "Fail to register device:my_bus!\n");
return ret;
}
static void my_bus_exit(void)
{
device_unregister(&my_bus);
bus_unregister(&my_bus_type);
}
module_init(my_bus_init);
module_exit(my_bus_exit);
make后出错:
[root@localhost bus]# make
make -C /home/test2/linux-2.6.30.4 M=/home/test/bus modules ARCH=arm CROSS_COMPILE=arm-linux-
make[1]: Entering directory `/home/test2/linux-2.6.30.4'
CC [M] /home/test/bus/bus.o
/home/test/bus/bus.c: In function 'my_match':
/home/test/bus/bus.c:14: error: 'struct device' has no member named 'bus_id'
/home/test/bus/bus.c: At top level:
/home/test/bus/bus.c:23: error: unknown field 'bus_id' specified in initializer
/home/test/bus/bus.c:23: warning: initialization from incompatible pointer type
make[2]: *** [/home/test/bus/bus.o] 错误 1
make[1]: *** [_module_/home/test/bus] 错误 2
make[1]: Leaving directory `/home/test2/linux-2.6.30.4'
make: *** [all] 错误 2
个人困惑:
struct device my_bus 里面明明定义了bus_id,为什么在编译的时候还会出现没有这个成员的信息,导致不能编译成功? |
|