加载ko的时候出现line 1: syntax error: unexpected word (expecting ")")

darwinmarx 2014-10-10 05:32:57
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 <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <linux/device.h>



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_open\n");
/* 配置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_write\n");
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");
...全文
1319 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
darwinmarx 2014-10-11
  • 打赏
  • 举报
回复
多谢帮助 问题解决 已经结贴给分
darwinmarx 2014-10-11
  • 打赏
  • 举报
回复
引用 2 楼 awsqsh 的回复:
想用file命令看看ko文件格式是否正确。再检查代码。
用file命令查看了一下,打印出的结果如下 first_drv.ko: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped 在网上找了一下说是relocatable文件,不是可执行文件,不知道怎么改makefile,请指点一下,谢谢!
awsqsh 2014-10-10
  • 打赏
  • 举报
回复
想用file命令看看ko文件格式是否正确。再检查代码。
awsqsh 2014-10-10
  • 打赏
  • 举报
回复
交叉编译问题 大小端问题 -EL 代码问题

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧