请教!设备驱动加载模块时出现错误如何解决?
sophiazhang
请教!设备驱动加载模块时出现错误如何解决?
ubuntu 8.04 内核版本2.6.24-18
makefile文件如下 :
obj-m := char_dev.o
KERNELBUILD :=/lib/modules/2.6.24-18-generic/build
default:
make -C $(KERNELBUILD) M=$(shell pwd) modules
clean:
rm -rf *.o *.ko *.mod.c .*.cmd .tmp_versions
char_dev.c文件如下 :
#ifndef MODULE
#define MODULE
#endif
/*必要的头文件*/
#include <linux/module.h>
#include <linux/kernel.h> /* printk() */
#include <linux/init.h>
#include <asm/timex.h>
/* 字符设备所需*/
#include <linux/fs.h>
#include <linux/slab.h>
#include <asm/system.h>
#include <linux/proc_fs.h>
#include <linux/fcntl.h>
#include <asm/uaccess.h>
#include <asm/segment.h>
#define status 0
/* 设备定义,定义设备的名字为mychardev*/
#define DEVICE_NAME "mychardev"
/* 该设备最大信息长度为80*/
#define BUF_LEN 80
/* 设备否打开?利用它防止当前进程使用同一设备*/
static int open_count = 0;
/* 对设备里面的内容进行初始化 */
char content[BUF_LEN]="Welcome to use this device./n";
/* 进程读取的信息的指针 */
char *content_Ptr;
/* 当进程试图打开设备文件时调用该函数,参数指出文件的地址以及具体打开方式*/
static int device_open(struct inode *inode, struct file *file)
{
/* 两个进程不得同时对同一设备操作,设备被打开后不得被再次打开*/
if (open_count)
{
/*打开操作失败的返回信息*/
return -EBUSY;
}
/*记录设备被打开的次数,加1*/
open_count++;
/*设备里的指针指向具体的数组,该数组的内容就是该设备里的内容*/
content_Ptr = content;
/*成功打开操作的返回信息*/
return status;
}
/* 当一个进程要关闭这个设备时,该函数被调用,这个调用不允许失败,参数与打开设备的参数相同*/
static int device_release(struct inode *inode, struct file *file)
{
/*记录设备被打开的次数,减1*/
open_count --;
return 0;
}
/* 当一进程要从已打开的设备文件读数据时该函数被调用,file指具体的被打开的设备,buffer是获得填充数据的缓冲区,length是缓冲区中的数据长度 */
static ssize_t device_read(struct file *file, char *buffer,size_t length,loff_t *fops)
{
/* 用于记录写入到缓冲区buffer中的确切字节数*/
int num = 0;
/*指向设备的存放数据的数组*/
char *ptr=content_Ptr;
/*记录设备里的字符的个数,初始化为0*/
int len=0;
/* 如果已位于设备内部信息的尾部,返回0*/
if (*content_Ptr == 0)
{
return 0;
}
len=0;
/*计算设备里字符串的长度*/
while (*(ptr++))
{ len++;}
/*如果要读出的字符串的长度大于设备里字符串的长度,则将真正的读出长度设为设备的字符串的长度*/
if (length<len)
{
len=length;
}
/* 准确地把数据送到缓冲区buffer*/
copy_to_user(buffer,content_Ptr,len);
num=len;
/* 返回读取的实际字节数据 */
return num;
}
/* 当进程向这设备写时调用本函数*/
static ssize_t device_write(struct file *file,const char *buffer, size_t length,loff_t *fops)
{
printk(" write/n");
/* 用于记录写入到设备中的确切字符数*/
int len ;
/*如果用户的参数大于设备里数组的最大长度,则仅写满数组即可,否则写入的长度就是用户传进来的参数*/
if (length>80)
{
len=80;
}
else
{
len=length;
}
/*将用户的数据写入设备*/
copy_from_user(content_Ptr,buffer,len);
/*返回真正写入到设备里的字符的长度*/
return len;
}
/* 模块定义 */
/* 设备的主设备号*/
static int Major;
/* 当进程要对创建的设备进行某些操作时,这个结构存放了要调用的函数的入口
这个结构有系统设备表的指针指向。NULL 表示未实现该功能。*/
struct file_operations Fops = {
read: device_read,
write: device_write,
open: device_open,
release:device_release
};
/* 初始化模块--注册字符设备 */
int init_module()
{
/* 注册字符设备(至少一次) */
Major = register_chrdev(0, DEVICE_NAME, &Fops);
/* 负值意味出错 */
if (Major < 0)
{
printk ("Sorry, registering the character device failed with %d/n", Major);
return Major;
}
printk ("Registeration is a success. The major device number is %d./n", Major);
printk ("If you want to talk to the device driver, you'll have to/n");
printk ("create a device file. We suggest you use:/n");
printk ("mknod <name> c %d 0/n", Major);
return 0;
}
/* 清除模块 --从 /proc 中注销合适的文件*/
void cleanup_module()
{
int ret;
/* 注销设备 */
ret = unregister_chrdev(Major, DEVICE_NAME);
/* 如果出错,报告错误*/
if (ret < 0)
{
printk("Error in module_unregister_chrdev: %d/n", ret);
}
MODULE_LICENSE("GPL");
}
在终端输入 sudo make后 出现如下错误:
make -C /lib/modules/2.6.24-18-generic/build M=/home/sophiazhang/桌面/2 modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.24-18-generic'
CC [M] /home/sophiazhang/桌面/2/char_dev.o
/home/sophiazhang/桌面/2/char_dev.c: 在函数‘device_write’中:
/home/sophiazhang/桌面/2/char_dev.c:103: 警告: ISO C90 不允许混合使用声明和代码
/home/sophiazhang/桌面/2/char_dev.c: 在函数‘cleanup_module’中:
/home/sophiazhang/桌面/2/char_dev.c:162: 错误: void 值未如预期地被忽略
/home/sophiazhang/桌面/2/char_dev.c:169: 警告: ISO C90 不允许混合使用声明和代码
make[2]: *** [/home/sophiazhang/桌面/2/char_dev.o] 错误 1
make[1]: *** [_module_/home/sophiazhang/桌面/2] 错误 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-18-generic'
make: *** [default] 错误 2
请哪位高手指教下如何解决阿 ??????
anhongkui
把声明放前边去
printk(" write/n");
/* 用于记录写入到设备中的确切字符数*/
int len ;
把int len;放到printk前边。
sophiazhang
我将 .c文件改了,仍有错误
static ssize_t device_write(struct file *file,const char *buffer, size_t length,loff_t *fops)
{
int len ;
printk(" write/n");
/* 用于记录写入到设备中的确切字符数*/
make -C /lib/modules/2.6.24-18-generic/build M=/home/sophiazhang/桌面/2 modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.24-18-generic'
CC [M] /home/sophiazhang/桌面/2/char_dev.o
/home/sophiazhang/桌面/2/char_dev.c: 在函数‘cleanup_module’中:
/home/sophiazhang/桌面/2/char_dev.c:165: 错误: void 值未如预期地被忽略
/home/sophiazhang/桌面/2/char_dev.c:172: 警告: ISO C90 不允许混合使用声明和代码
make[2]: *** [/home/sophiazhang/桌面/2/char_dev.o] 错误 1
make[1]: *** [_module_/home/sophiazhang/桌面/2] 错误 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-18-generic'
make: *** [default] 错误 2
void cleanup_module()
{
int ret;
/* 注销设备 */
ret = unregister_chrdev(Major, DEVICE_NAME);
//165
/* 如果出错,报告错误*/
if (ret < 0)
{
printk("Error in module_unregister_chrdev: %d/n", ret);
}
MODULE_LICENSE("GPL"); //172
}
似乎是这部分代码的问题?
anhongkui
MODULE_LICENSE("GPL");
放到函数外边
sophiazhang
make -C /lib/modules/2.6.24-18-generic/build M=/home/sophiazhang/桌面/2 modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.24-18-generic'
CC [M] /home/sophiazhang/桌面/2/char_dev.o
/home/sophiazhang/桌面/2/char_dev.c: 在函数‘cleanup_module’中:
/home/sophiazhang/桌面/2/char_dev.c:165: 错误: void 值未如预期地被忽略
make[2]: *** [/home/sophiazhang/桌面/2/char_dev.o] 错误 1
make[1]: *** [_module_/home/sophiazhang/桌面/2] 错误 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-18-generic'
make: *** [default] 错误 2
放到外面了 ,169的警告解决了 ,那个 165的错误怎么办阿?
anhongkui
unregister_chrdev(Major, DEVICE_NAME);
这个函数没有返回值
sophiazhang
我现在用的书是 边干边学-linux内核指导,这个书很老 ,上面的unregister_chrdev是有返回值的 ,是不是版本更新了之后就没有返回值了呢 ?
既然没有返回值 我,是不是就不用考虑注销出错的问题了呢?
把这段代码这样改 可以吗?
void cleanup_module()
{
/* 注销设备 */
unregister_chrdev(Major, DEVICE_NAME); //162
}
sophiazhang
我照着上面自己改的代码运行了下
make -C /lib/modules/2.6.24-18-generic/build M=/home/sophiazhang/桌面/2 modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.24-18-generic'
CC [M] /home/sophiazhang/桌面/2/char_dev.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/sophiazhang/桌面/2/char_dev.mod.o
LD [M] /home/sophiazhang/桌面/2/char_dev.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-18-generic'
这样是不是说明已经加载成功了呢?
anhongkui
编译成功,还没有加载
建议lz看看基础知识再来实践
sophiazhang
汗,我的确是急用这个程序,基本没有基础~~~~~~
在加载模块时为什么会出现error?????
sophiazhang@sophiazhang-laptop:~/桌面/2$ sudo insmod ./char_dev.ko
insmod: error inserting './char_dev.ko': -1 File exists
anhongkui
已经加载过,先rmmod char_dev
sophiazhang
make -C /lib/modules/2.6.24-18-generic/build M=/home/sophiazhang/桌面/2 modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.24-18-generic'
CC [M] /home/sophiazhang/桌面/2/char_dev.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/sophiazhang/桌面/2/char_dev.mod.o
LD [M] /home/sophiazhang/桌面/2/char_dev.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-18-generic'
sophiazhang@sophiazhang-laptop:~/桌面/2$ rmmod char_dev
ERROR: Removing 'char_dev': Operation not permitted
sophiazhang@sophiazhang-laptop:~/桌面/2$ sudo insmod ./char_dev.ko
insmod: error inserting './char_dev.ko': -1 File exists
sophiazhang@sophiazhang-laptop:~/桌面/2$ rmmod char_dev
ERROR: Removing 'char_dev': Operation not permitted
我的文档上是这样写的:
编译好 Makefile 文件后,产生 char_dev.ko 目标文件,然后开始加载模块,输入:
sudo insmod ./char_dev.ko
然后用 dmesg 命令查看模块加载成功后的信息,输入
dmesg
屏幕显示中可看到:
Registeration is a success. The major device number is 253.
If you want to talk to the device driver, you'll have to
create a device file. We suggest you use:
mknod <name> c 253 0
为什么上面终端显示的完全不一样?
anhongkui
ERROR: Removing 'char_dev': Operation not permitted
哥哥,这里写着没有权限了!!
使用sudo rmmod char_dev
sophiazhang
dmesg
之后 出现的
Drivers/b43#devicefirmware and download the correct firmware (version 4).
[ 419.835356] input: b43-phy0 as /devices/virtual/input/input40
[ 419.860914] evdev: no more free evdev devices
[ 419.860929] input: failed to attach handler evdev to device input40, error: -23
[ 419.897368] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 419.897377] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 428.228069] input: b43-phy0 as /devices/virtual/input/input41
[ 428.256326] evdev: no more free evdev devices
[ 428.256343] input: failed to attach handler evdev to device input41, error: -23
[ 428.286930] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 428.286940] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 432.933885] input: b43-phy0 as /devices/virtual/input/input42
[ 432.951314] evdev: no more free evdev devices
[ 432.951329] input: failed to attach handler evdev to device input42, error: -23
[ 432.999754] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 432.999762] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 435.496772] input: b43-phy0 as /devices/virtual/input/input43
[ 435.526209] evdev: no more free evdev devices
[ 435.526224] input: failed to attach handler evdev to device input43, error: -23
[ 435.555684] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 435.555693] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 439.823218] input: b43-phy0 as /devices/virtual/input/input44
[ 439.844353] evdev: no more free evdev devices
[ 439.844363] input: failed to attach handler evdev to device input44, error: -23
[ 439.893347] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 439.893357] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 441.923347] input: b43-phy0 as /devices/virtual/input/input45
[ 441.939473] evdev: no more free evdev devices
[ 441.939488] input: failed to attach handler evdev to device input45, error: -23
[ 441.984944] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 441.984958] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 450.303955] input: b43-phy0 as /devices/virtual/input/input46
[ 450.335864] evdev: no more free evdev devices
[ 450.335875] input: failed to attach handler evdev to device input46, error: -23
[ 450.373460] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 450.373468] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 455.020502] input: b43-phy0 as /devices/virtual/input/input47
[ 455.049848] evdev: no more free evdev devices
[ 455.049864] input: failed to attach handler evdev to device input47, error: -23
[ 455.087012] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 455.087021] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 457.579324] input: b43-phy0 as /devices/virtual/input/input48
[ 457.599752] evdev: no more free evdev devices
[ 457.599769] input: failed to attach handler evdev to device input48, error: -23
[ 457.645947] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 457.645957] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 461.917683] input: b43-phy0 as /devices/virtual/input/input49
[ 461.946888] evdev: no more free evdev devices
[ 461.946904] input: failed to attach handler evdev to device input49, error: -23
[ 461.980609] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 461.980623] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 464.014725] input: b43-phy0 as /devices/virtual/input/input50
[ 464.046013] evdev: no more free evdev devices
[ 464.046028] input: failed to attach handler evdev to device input50, error: -23
[ 464.083802] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 464.083816] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 472.397820] input: b43-phy0 as /devices/virtual/input/input51
[ 472.429409] evdev: no more free evdev devices
[ 472.429426] input: failed to attach handler evdev to device input51, error: -23
[ 472.461092] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 472.461107] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 477.111168] input: b43-phy0 as /devices/virtual/input/input52
[ 477.139382] evdev: no more free evdev devices
[ 477.139393] input: failed to attach handler evdev to device input52, error: -23
[ 477.177991] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 477.178000] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 479.670033] input: b43-phy0 as /devices/virtual/input/input53
[ 479.699285] evdev: no more free evdev devices
[ 479.699294] input: failed to attach handler evdev to device input53, error: -23
[ 479.739894] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 479.739904] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 484.008182] input: b43-phy0 as /devices/virtual/input/input54
[ 484.025441] evdev: no more free evdev devices
[ 484.025454] input: failed to attach handler evdev to device input54, error: -23
[ 484.075158] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 484.075171] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 486.107319] input: b43-phy0 as /devices/virtual/input/input55
[ 486.136532] evdev: no more free evdev devices
[ 486.136546] input: failed to attach handler evdev to device input55, error: -23
[ 486.169611] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 486.169619] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 494.484730] input: b43-phy0 as /devices/virtual/input/input56
[ 494.512942] evdev: no more free evdev devices
[ 494.512958] input: failed to attach handler evdev to device input56, error: -23
[ 494.546638] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 494.546653] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 499.195918] input: b43-phy0 as /devices/virtual/input/input57
[ 499.217925] evdev: no more free evdev devices
[ 499.217936] input: failed to attach handler evdev to device input57, error: -23
[ 499.264536] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 499.264545] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 501.765559] input: b43-phy0 as /devices/virtual/input/input58
[ 501.793827] evdev: no more free evdev devices
[ 501.793844] input: failed to attach handler evdev to device input58, error: -23
[ 501.827517] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 501.827533] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 506.095382] input: b43-phy0 as /devices/virtual/input/input59
[ 506.123983] evdev: no more free evdev devices
[ 506.123999] input: failed to attach handler evdev to device input59, error: -23
[ 506.156616] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 506.156626] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 508.072917] eth0: link down
[ 508.186929] input: b43-phy0 as /devices/virtual/input/input60
[ 508.207086] evdev: no more free evdev devices
[ 508.207095] input: failed to attach handler evdev to device input60, error: -23
[ 508.244700] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 508.244709] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 513.415115] eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
[ 513.419097] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 514.420340] eth0: link down
[ 516.571279] input: b43-phy0 as /devices/virtual/input/input61
[ 516.595510] evdev: no more free evdev devices
[ 516.595524] input: failed to attach handler evdev to device input61, error: -23
[ 516.641054] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 516.641062] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 516.936653] eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
[ 516.940635] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 521.284209] input: b43-phy0 as /devices/virtual/input/input62
[ 521.313471] evdev: no more free evdev devices
[ 521.313488] input: failed to attach handler evdev to device input62, error: -23
[ 521.347197] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 521.347213] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 522.673066] eth0: link down
[ 523.852131] input: b43-phy0 as /devices/virtual/input/input63
[ 523.880380] evdev: no more free evdev devices
[ 523.880394] input: failed to attach handler evdev to device input63, error: -23
[ 523.917917] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 523.917925] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 524.273198] eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
[ 524.277204] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 528.181298] input: b43-phy0 as /devices/virtual/input/input64
[ 528.210522] evdev: no more free evdev devices
[ 528.210538] input: failed to attach handler evdev to device input64, error: -23
[ 528.243084] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 528.243094] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 530.275885] input: b43-phy0 as /devices/virtual/input/input65
[ 530.305987] evdev: no more free evdev devices
[ 530.305998] input: failed to attach handler evdev to device input65, error: -23
[ 530.338193] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 530.338203] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 538.664921] input: b43-phy0 as /devices/virtual/input/input66
[ 538.694029] evdev: no more free evdev devices
[ 538.694046] input: failed to attach handler evdev to device input66, error: -23
[ 538.726603] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 538.726613] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 542.748268] eth0: no IPv6 routers present
[ 543.370451] input: b43-phy0 as /devices/virtual/input/input67
[ 543.399019] evdev: no more free evdev devices
[ 543.399036] input: failed to attach handler evdev to device input67, error: -23
[ 543.428529] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 543.428539] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 545.950670] input: b43-phy0 as /devices/virtual/input/input68
[ 545.978924] evdev: no more free evdev devices
[ 545.978935] input: failed to attach handler evdev to device input68, error: -23
[ 546.015407] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 546.015416] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 550.267856] input: b43-phy0 as /devices/virtual/input/input69
[ 550.296066] evdev: no more free evdev devices
[ 550.296077] input: failed to attach handler evdev to device input69, error: -23
[ 550.326700] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 550.326711] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 552.367280] input: b43-phy0 as /devices/virtual/input/input70
[ 552.399166] evdev: no more free evdev devices
[ 552.399183] input: failed to attach handler evdev to device input70, error: -23
[ 552.433817] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 552.433833] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 560.752139] input: b43-phy0 as /devices/virtual/input/input71
[ 560.779586] evdev: no more free evdev devices
[ 560.779604] input: failed to attach handler evdev to device input71, error: -23
[ 560.811907] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 560.811923] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 565.453341] input: b43-phy0 as /devices/virtual/input/input72
[ 565.474574] evdev: no more free evdev devices
[ 565.474585] input: failed to attach handler evdev to device input72, error: -23
[ 565.508250] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 565.508260] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 568.044059] input: b43-phy0 as /devices/virtual/input/input73
[ 568.072447] evdev: no more free evdev devices
[ 568.072459] input: failed to attach handler evdev to device input73, error: -23
[ 568.110949] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 568.110958] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 572.354161] input: b43-phy0 as /devices/virtual/input/input74
[ 572.383603] evdev: no more free evdev devices
[ 572.383619] input: failed to attach handler evdev to device input74, error: -23
[ 572.417291] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 572.417307] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 574.461306] input: b43-phy0 as /devices/virtual/input/input75
[ 574.490700] evdev: no more free evdev devices
[ 574.490716] input: failed to attach handler evdev to device input75, error: -23
[ 574.523306] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 574.523316] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
sophiazhang
[ 589.179162] input: b43-phy0 as /devices/virtual/input/input76
[ 589.207410] evdev: no more free evdev devices
[ 589.207426] input: failed to attach handler evdev to device input76, error: -23
[ 589.237142] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 589.237150] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 611.258579] input: b43-phy0 as /devices/virtual/input/input77
[ 611.286965] evdev: no more free evdev devices
[ 611.286980] input: failed to attach handler evdev to device input77, error: -23
[ 611.324441] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 611.324449] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 633.348288] input: b43-phy0 as /devices/virtual/input/input78
[ 633.376531] evdev: no more free evdev devices
[ 633.376548] input: failed to attach handler evdev to device input78, error: -23
[ 633.411083] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 633.411091] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 655.436358] input: b43-phy0 as /devices/virtual/input/input79
[ 655.455052] evdev: no more free evdev devices
[ 655.455064] input: failed to attach handler evdev to device input79, error: -23
[ 655.492867] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 655.492878] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 677.517649] input: b43-phy0 as /devices/virtual/input/input80
[ 677.538582] evdev: no more free evdev devices
[ 677.538591] input: failed to attach handler evdev to device input80, error: -23
[ 677.576530] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 677.576538] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 682.795055] input: b43-phy0 as /devices/virtual/input/input81
[ 682.823324] evdev: no more free evdev devices
[ 682.823339] input: failed to attach handler evdev to device input81, error: -23
[ 682.854841] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 682.854855] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 687.496995] input: b43-phy0 as /devices/virtual/input/input82
[ 687.525297] evdev: no more free evdev devices
[ 687.525307] input: failed to attach handler evdev to device input82, error: -23
[ 687.555775] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 687.555784] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 690.091869] input: b43-phy0 as /devices/virtual/input/input83
[ 690.120209] evdev: no more free evdev devices
[ 690.120224] input: failed to attach handler evdev to device input83, error: -23
[ 690.151696] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 690.151710] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 694.399025] input: b43-phy0 as /devices/virtual/input/input84
[ 694.427347] evdev: no more free evdev devices
[ 694.427365] input: failed to attach handler evdev to device input84, error: -23
[ 694.460893] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 694.460910] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 696.501094] input: b43-phy0 as /devices/virtual/input/input85
[ 696.530454] evdev: no more free evdev devices
[ 696.530472] input: failed to attach handler evdev to device input85, error: -23
[ 696.562918] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 696.562928] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 699.599818] input: b43-phy0 as /devices/virtual/input/input86
[ 699.629121] evdev: no more free evdev devices
[ 699.629138] input: failed to attach handler evdev to device input86, error: -23
[ 699.662640] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 699.662656] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 704.881133] input: b43-phy0 as /devices/virtual/input/input87
[ 704.890892] evdev: no more free evdev devices
[ 704.890908] input: failed to attach handler evdev to device input87, error: -23
[ 704.929528] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 704.929542] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 709.580791] input: b43-phy0 as /devices/virtual/input/input88
[ 709.608858] evdev: no more free evdev devices
[ 709.608872] input: failed to attach handler evdev to device input88, error: -23
[ 709.649156] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 709.649170] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 712.174655] input: b43-phy0 as /devices/virtual/input/input89
[ 712.202749] evdev: no more free evdev devices
[ 712.202763] input: failed to attach handler evdev to device input89, error: -23
[ 712.233257] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 712.233265] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 716.484664] input: b43-phy0 as /devices/virtual/input/input90
[ 716.513894] evdev: no more free evdev devices
[ 716.513911] input: failed to attach handler evdev to device input90, error: -23
[ 716.546463] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 716.546473] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 718.588783] input: b43-phy0 as /devices/virtual/input/input91
[ 718.612009] evdev: no more free evdev devices
[ 718.612024] input: failed to attach handler evdev to device input91, error: -23
[ 718.647639] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 718.647647] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 721.686074] input: b43-phy0 as /devices/virtual/input/input92
[ 721.706680] evdev: no more free evdev devices
[ 721.706695] input: failed to attach handler evdev to device input92, error: -23
[ 721.749142] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 721.749150] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 726.953191] input: b43-phy0 as /devices/virtual/input/input93
[ 726.976435] evdev: no more free evdev devices
[ 726.976452] input: failed to attach handler evdev to device input93, error: -23
[ 727.015963] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 727.015976] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 831.631836] input: b43-phy0 as /devices/virtual/input/input94
[ 831.660595] evdev: no more free evdev devices
[ 831.660612] input: failed to attach handler evdev to device input94, error: -23
[ 831.693290] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 831.693300] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 834.214283] input: b43-phy0 as /devices/virtual/input/input95
[ 834.243485] evdev: no more free evdev devices
[ 834.243503] input: failed to attach handler evdev to device input95, error: -23
[ 834.276192] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 834.276202] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 838.528421] input: b43-phy0 as /devices/virtual/input/input96
[ 838.557636] evdev: no more free evdev devices
[ 838.557652] input: failed to attach handler evdev to device input96, error: -23
[ 838.590211] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 838.590222] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 840.628526] input: b43-phy0 as /devices/virtual/input/input97
[ 840.651801] evdev: no more free evdev devices
[ 840.651817] input: failed to attach handler evdev to device input97, error: -23
[ 840.687442] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 840.687451] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 843.734031] input: b43-phy0 as /devices/virtual/input/input98
[ 843.762413] evdev: no more free evdev devices
[ 843.762429] input: failed to attach handler evdev to device input98, error: -23
[ 843.792988] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 843.792997] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 848.996157] input: b43-phy0 as /devices/virtual/input/input99
[ 849.024162] evdev: no more free evdev devices
[ 849.024177] input: failed to attach handler evdev to device input99, error: -23
[ 849.054897] b43-phy0 ERROR: Firmware file "b43/ucode5.fw" not found or load failed.
[ 849.054905] b43-phy0 ERROR: You must go to [url]http://linuxwireless.org/en/users/Drivers/b43#devicefirmware[/url] and download the correct firmware (version 4).
[ 5885.168765] Registeration is a success. The major device number is 251.
[ 5885.168776] If you want to talk to the device driver, you'll have to
[ 5885.168780] create a device file. We suggest you use:
[ 5885.168785] mknod <name> c 251 0
[ 7395.174114] Registeration is a success. The major device number is 251.
[ 7395.174124] If you want to talk to the device driver, you'll have to
[ 7395.174129] create a device file. We suggest you use:
[ 7395.174133] mknod <name> c 251 0
sophiazhang@sophiazhang-laptop:~/桌面/5$ mknod mychardev c 251 0
mknod: “mychardev”: 操作不允许
sophiazhang@sophiazhang-laptop:~/桌面/5$
sophiazhang
sophiazhang@sophiazhang-laptop:~/桌面/5$ sudo mknod mychardev c 251 0
sophiazhang@sophiazhang-laptop:~/桌面/5$ gcc main.c -o main
sophiazhang@sophiazhang-laptop:~/桌面/5$ ./main
The open operation to read succeed!
How many chars do you want to read:(1-80)80
The operation to read failed!
sophiazhang
前面的问题都已经解决了 ,我这个地方不太明白:
main.c
/*以只读方式打开设备*/
f=open("/home/sophiazhang/桌面/5",0);
open的第一个路径应该是所有代码存在的路径吗 ?
i=read(f,buffer,num);
/*判断读操作是否成功,i>=0表示成功,否则表示失败*/
为什么当 num 大小合法的时候,i返回为负值呢(也就是说读操作失败了)?
sophiazhang
/*以只读方式打开设备*/
f=open("/home/sophiazhang/桌面/5/mychardev",0);
/*以只写的方式打开设备*/
f=open("/home/sophiazhang/桌面/5/mychardev",1);
/*判断打开是否成功,f>=0表示成功,否则表示失败*/
if(f>=0)
{
printf("The open operation to write succeed! /n");
}
else
{
printf("The open operation to write failed! /n");
return 0;
}
How many chars do you want to read:(1-80)80
The operation to read succeed!
The actual number of chars which has been read is 28
Welcome to use this device.
The open operation to write failed!
为什么以只读方式打开设备成功,而以只写方式打开设备时失败呢?