当前位置: 技术问答>linux和unix
加载ko的时候出现line 1: syntax error: unexpected word (expecting ")")
来源: 互联网 发布时间:2017-05-30
本文导语: makefile是这样写的: KERN_DIR = ../linux-2.6.35.4 all: make -C $(KERN_DIR) M=`pwd` modules clean: make -C $(KERN_DIR) M=`pwd` modules clean rm -rf modules.order obj-m += first_drv.o 代码如下: #include #include #include #include #include ...
makefile是这样写的:
KERN_DIR = ../linux-2.6.35.4
all:
make -C $(KERN_DIR) M=`pwd` modules
clean:
make -C $(KERN_DIR) M=`pwd` modules clean
rm -rf modules.order
obj-m += first_drv.o
代码如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
static struct class *firstdrv_class;
static struct class_device *firstdrv_class_dev;
volatile unsigned long *gpdomd = NULL;
volatile unsigned long *gpdpuen = NULL;
volatile unsigned long *gpddout = NULL;
volatile unsigned long *gpdpin = NULL;
static int first_drv_open(struct inode *inode, struct file *file)
{
printk("first_drv_openn");
/* 配置GPF4,5,6为输出 */
return 0;
}
static ssize_t first_drv_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos)
{
int val;
//printk("first_drv_writen");
return 0;
}
static struct file_operations first_drv_fops = {
.owner = THIS_MODULE,/* 这是一个宏,推向编译模块时自动创建的__this_module变量 */
.open = first_drv_open,
.write = first_drv_write,
};
int major;
static int first_drv_init(void)
{
major = register_chrdev(0, "first_drv", &first_drv_fops); // 注册, 告诉内核
firstdrv_class = class_create(THIS_MODULE, "firstdrv");
firstdrv_class_dev = device_create(firstdrv_class, NULL, MKDEV(major, 0), NULL, "xyz"); /* /dev/xyz */
gpdomd = (volatile unsigned long *)ioremap(0xb8001030, 16);
gpdpuen = gpdomd + 1;
gpddout = gpdomd + 2;
gpdpin = gpdomd + 3;
return 0;
}
static void first_drv_exit(void)
{
unregister_chrdev(major, "first_drv"); // 卸载
device_unregister(firstdrv_class_dev);
class_destroy(firstdrv_class);
iounmap(gpdomd);
iounmap(gpdpuen);
iounmap(gpddout);
iounmap(gpdpin);
}
module_init(first_drv_init);
module_exit(first_drv_exit);
MODULE_LICENSE("GPL");
KERN_DIR = ../linux-2.6.35.4
all:
make -C $(KERN_DIR) M=`pwd` modules
clean:
make -C $(KERN_DIR) M=`pwd` modules clean
rm -rf modules.order
obj-m += first_drv.o
代码如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
static struct class *firstdrv_class;
static struct class_device *firstdrv_class_dev;
volatile unsigned long *gpdomd = NULL;
volatile unsigned long *gpdpuen = NULL;
volatile unsigned long *gpddout = NULL;
volatile unsigned long *gpdpin = NULL;
static int first_drv_open(struct inode *inode, struct file *file)
{
printk("first_drv_openn");
/* 配置GPF4,5,6为输出 */
return 0;
}
static ssize_t first_drv_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos)
{
int val;
//printk("first_drv_writen");
return 0;
}
static struct file_operations first_drv_fops = {
.owner = THIS_MODULE,/* 这是一个宏,推向编译模块时自动创建的__this_module变量 */
.open = first_drv_open,
.write = first_drv_write,
};
int major;
static int first_drv_init(void)
{
major = register_chrdev(0, "first_drv", &first_drv_fops); // 注册, 告诉内核
firstdrv_class = class_create(THIS_MODULE, "firstdrv");
firstdrv_class_dev = device_create(firstdrv_class, NULL, MKDEV(major, 0), NULL, "xyz"); /* /dev/xyz */
gpdomd = (volatile unsigned long *)ioremap(0xb8001030, 16);
gpdpuen = gpdomd + 1;
gpddout = gpdomd + 2;
gpdpin = gpdomd + 3;
return 0;
}
static void first_drv_exit(void)
{
unregister_chrdev(major, "first_drv"); // 卸载
device_unregister(firstdrv_class_dev);
class_destroy(firstdrv_class);
iounmap(gpdomd);
iounmap(gpdpuen);
iounmap(gpddout);
iounmap(gpdpin);
}
module_init(first_drv_init);
module_exit(first_drv_exit);
MODULE_LICENSE("GPL");
|
想用file命令看看ko文件格式是否正确。再检查代码。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。