scull是linux device driver里面的一个例子,模拟了一个位于内存中的字符串设备。因为版本原因,源代码在编译过程中经常有错误,这里记录编译过程中所遇到的问题和解决办法,参考了如下网址:

 

http://www.xue163.com/html/201022/3659066.html

 

1. *** CFLAGS was changed in "/home/wisr/ldd3-samples-1.0.0/ldd3-samples-1.0.0/scull/Makefile". Fix it to use EXTRA_CFLAGS.  Stop.

 

解决方法:进入Makefile, 将CFLAGS修改为EXTRA_CFLAGS

 

2. 没有linux/config.h

 

进入main.c,注释掉这个头文件。新的linux内核中已经没有这个文件了。

 

3.  scull_u_open: dereferencing pointer to incomplete type

 

解决方法:access.c 中添加:#include <linux/sched.h>

 

4. 加载模块

chmod +x scull_load

./scull_load

lsmod |grep scull

 

5. 卸载模块

chmod +x scull_unload

./scull_unload

lsmod | grep scull

 

 

6. 测试模块

查看设备号

cat /proc/devices | grep scull

 

显示为249 scull

 

生成scull0

#mknod /dev/scull0 c 249 0

 

输入字符

echo "this is a test " &gt; /dev/scull0

 

输出字符

cat /dev/scull0

 

下面是我的测试结果:

首先,输入命令insmod scull.ko

然后,查看设备号,cat /proc/devices | grep scull,我的是249

然后,生成scull0,mknod /dev/scull0 c 249 0

然后,我用echo命令无法写入/dev/scull0,总是提示permission denied.

然后,我使用了cp 文件名 /dev/scull0,并且cat /dev/scull0,输出成功

卸载模块是rm /dev/scull0