linux内核驱动ldd3_ldd3 源码编译之 scullc 字符设备驱动

在尝试编译Linux内核驱动ldd3的scullc字符设备驱动时遇到多个错误,包括CFLAGS替换为ccflags-y,类型名称kmem_cache_t的改变,INIT_WORK宏参数问题,ioctl接口更新,以及kmem_cache_create函数原型变化。通过相应修改Makefile和源代码,解决了这些问题并消除了警告。
摘要由CSDN通过智能技术生成

使用内核版本-linux-3.2

错误1:

make -C /lib/modules/3.2.0/build M=/home/wrk/works/drivers/ldd3/examples/scullc LDDINC=/home/wrk/works/drivers/ldd3/examples/scullc modules

make[1]: Entering directory `/home/wrk/works/drivers/linux-kernel/linux-3.2'

scripts/Makefile.build:49: *** CFLAGS was changed in "/home/wrk/works/drivers/ldd3/examples/scullc/Makefile". Fix it to use ccflags-y. Stop.

make[1]: *** [_module_/home/wrk/works/drivers/ldd3/examples/scullc] Error 2

make[1]: Leaving directory `/home/wrk/works/drivers/linux-kernel/linux-3.2'

make: *** [modules] Error 2这个错误还比较好解决,像提示的那样在Makefile中用ccflags-y替换CFLAGS

错误2:

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:52:1: error: unknown type name ‘kmem_cache_t’

这是因为kmem_cache_t结构被换成了kmem_cache。而kmem_cache定义在和。但是你并不需要包含这两个文件中的一个。因为会根据CONFIG_SLUB等来判断具体包含,还是。故例程中需要将

kmem_cache_t *scullc_cache;

改为:

structkmem_cache *scullc_cache;

错误3:

/home/wrk/works/drivers/ldd3/examples/scullc/main.c: In function ‘scullc_defer_op’:

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:437:54: error: macro "INIT_WORK" passed 3 arguments, but takes just 2

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:437:2: error: ‘INIT_WORK’ undeclared (first use in this function)这里需要将

INIT_WORK(&stuff->work, scull_do_deferred_op, stuff);改为:

INIT_WORK(&stuff->work, scull_do_deferred_op);并且将scullc_do_deferred_op函数改为

static void scullc_do_deferred_op(struct work_struct *p)

{

struct async_work *stuff = container_of(p, struct async_work, work);

aio_complete(stuff->iocb, stuff->result, 0);

kfree(stuff);

}错误4:

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:467:2: error: unknown field ‘ioctl’ specified in initializer这里因为内核接口变化需要将.ioctl改为 .unlocked_ioctl

错误5:

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:558:4: error: too many arguments to function ‘kmem_cache_create’函数kmem_cache_create的原型已经改变:struct kmem_cache *kmem_cache_create(const char *, size_t, size_t, unsigned long, void (*)(void *));故调用它的时候应该将参数做出相应的改变。需要将最后一个NULL去掉。

下面来解决warning:

/home/wrk/works/drivers/ldd3/examples/scullc/main.c: In function ‘scullc_defer_op’:

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:437:2: warning: assignment from incompatible pointer type [enabled by default]

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:438:2: warning: passing argument 1 of ‘schedule_delayed_work’ from incompatible pointer type [enabled by default]

include/linux/workqueue.h:363:12: note: expected ‘struct delayed_work *’ but argument is of type ‘struct work_struct *’

/home/wrk/works/drivers/ldd3/examples/scullc/main.c: At top level:

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:467:2: warning: initialization from incompatible pointer type [enabled by default]

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:467:2: warning: (near initialization for ‘scullc_fops.unlocked_ioctl’) [enabled by default]

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:470:2: warning: initialization from incompatible pointer type [enabled by default]

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:470:2: warning: (near initialization for ‘scullc_fops.aio_read’) [enabled by default]

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:471:2: warning: initialization from incompatible pointer type [enabled by default]

/home/wrk/works/drivers/ldd3/examples/scullc/main.c:471:2: warning: (near initialization for ‘scullc_fops.aio_write’) [enabled by default]1.把

struct async_work {

struct kiocb *iocb;

int result;

struct work_struct work;

};改为:

struct async_work {

struct kiocb *iocb;

int result;

struct delayed_work delayed_work;

}然后把:

INIT_WORK(&stuff->work, scull_do_deferred_op, stuff);

schedule_delayed_work(&stuff->work, HZ/100);改为:

INIT_DELAYED_WORK(&(stuff->delayed_work), scullc_do_deferred_op);

schedule_delayed_work(&(stuff->delayed_work), HZ/100);再编译即可通过。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值