scull的编译
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 " > /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
轉載于:https://blog.51cto.com/zhaopk/327026
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
- 上一篇: BCGControlBar菜单编程方法详
- 下一篇: mysql 用一条sql语句修改两个表里