天天看點

基于linux核心4.12 編譯 scullc程式遇到的一些問題

字元裝置驅動程式 scullc 基于linux 核心 4.12 由于Linux核心4.12 相比與 2.6 資料結構,接口都發生巨大變化,是以這個驅動程式需要做許多修改。

1. main.c 18行, 注釋 #include <linux/config.h> 因為4.12下不包含config.h檔案

2. main.c 30行 将#include <asm/uaccess.h> 改為: #include <linux/uaccess.h>

3. 52 行 将:kmem_cache_t *scullc_cache; 改為:struct kmem_cache *scullc_cache;

4. 275行 将 int scullc_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) 改為: long scullc_ioctl (struct file *filp, unsigned int cmd, unsigned long arg)

5. 404 行 将 struct work_struct work; 改為:struct delayed_work dwork;

6. 由于異步io 部分牽連比較多,雖然修改了很多地方,但是碰到疊代器我就放棄了,暫時就不深究異步io了,直接注釋異步io部分。 比如 strcut file_opration 結構體中 ioctrl ,aio_read, aio_write都發生了變化,, , aio_complete 接口也已經變為static函數了,不能直接調用,暫時由于對struct iov_iter等資料結構還不熟悉,是以還不能完成異步IO接口的實作,隻能暫時注釋該功能。 再 410 行 static void scullc_do_deferred_op(void *p) 上面 加上 #if 0 在 444 行 加上 #endif 在 449 行 将 return scullc_defer_op(0, iocb, buf, count, pos); 改為://return scullc_defer_op(0, iocb, buf, count, pos); return 0; 在 455行 将 return scullc_defer_op(1, iocb, (char __user *) buf, count, pos); 改為://return scullc_defer_op(1, iocb, (char __user *) buf, count, pos); return 0; 在 446 行 将 接口: static ssize_t scullc_aio_read(struct kiocb *iocb, char __user *buf, size_t count, loff_t pos) { return scullc_defer_op(0, iocb, buf, count, pos); }

static ssize_t scullc_aio_write(struct kiocb *iocb, const char __user *buf, size_t count, loff_t pos) { return scullc_defer_op(1, iocb, (char __user *) buf, count, pos); }

改為: static ssize_t scullc_aio_read(struct kiocb *iocb, struct iov_iter *iter) { //return scullc_defer_op(0, iocb, buf, count, pos); return 0; }

static ssize_t scullc_aio_write(struct kiocb *iocb, struct iov_iter *iter) { //return scullc_defer_op(1, iocb, (char __user *) buf, count, pos); return 0; }

7. 在470 行 将 .ioctl = scullc_ioctl, 改為:.unlocked_ioctl = scullc_ioctl,

在473 , 474 行 将 .aio_read = scullc_aio_read, .aio_write = scullc_aio_write, 改為:.read_iter = scullc_aio_read, .write_iter = scullc_aio_write,

8. 在560 行, 将 scullc_cache = kmem_cache_create("scullc", scullc_quantum, 0, SLAB_HWCACHE_ALIGN, NULL, NULL); 改為: scullc_cache = kmem_cache_create("scullc", scullc_quantum, 0, SLAB_HWCACHE_ALIGN, NULL);

8. 最後修改一下腳本 scullc_load 将18行的, -f 參數去掉。 這裡如果不去掉,我在安裝子產品時提示: ERROR: could not insert module ./scullc.ko: Invalid module format