Linux 시스템 용 모듈 및 드라이버를 작성하는 방법을 배우려고합니다. 마찬가지로 this 질문과 마찬가지로 간단한 "Hello World"모듈을 USB 키보드 핫 플러그 (아래 코드)로 실행하려고합니다. insmode
및 modprobe
명령으로 모듈을 초기화하더라도 (dmesg
은 디버깅 메시지를 표시 함) 키보드를 끼우면 모듈이로드되지 않습니다.키보드의 모듈로드 hotplug
내가 무슨 짓을 :
- 실행
make
을hellomodule.ko
파일을 생성 할 수 있습니다. hellomodule.ko
파일을/lib/modules/"my_kernel_version"/depmod -a
comand로 복사하십시오.
이 세 단계를 거친 후 modules.alias
및 modules.dep
파일에 모듈을 추가했습니다. 여전히 작동하지 않습니다.
이 커널 구성 오류 또는 완전히 다른 것이 있습니까?
시스템 : 우분투 14.04 LTS; 커널 : 3.14.0
hellomodule.c :
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/usb.h>
#include <linux/usb/input.h>
#include <linux/hid.h>
MODULE_AUTHOR("author");
MODULE_DESCRIPTION("helloworld module\n");
MODULE_LICENSE("GPL");
static struct usb_device_id hello_id_table [] = {
{ USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID,
USB_INTERFACE_SUBCLASS_BOOT,
USB_INTERFACE_PROTOCOL_KEYBOARD) },
{ } /* Terminating entry */
};
MODULE_DEVICE_TABLE (usb, hello_id_table);
static int hello_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{
pr_debug("HelloModule: USB keyboard probe function called\n");
return 0;
}
static void hello_disconnect(struct usb_interface *interface)
{
pr_debug("HelloModule: USB keyboard disconnect function called\n");
}
static struct usb_driver hello_driver = {
//.owner = THIS_MODULE,
.name = "hello_driver",
.probe = hello_probe,
.disconnect = hello_disconnect,
.id_table = hello_id_table
};
static int __init hello_init(void)
{
int retval = 0;
pr_debug("HelloModule: Hello World!\n");
retval = usb_register(&hello_driver);
if (retval)
pr_debug("HelloModule: usb_register failed. Error number %d", retval);
return 0;
}
static void __exit hello_exit(void)
{
usb_deregister(&hello_driver);
pr_debug("HelloModule: exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
메이크 :
obj-m := hellomodule.o
CFLAGS_hellomodule.o := -DDEBUG
KDIR := /lib/modules/`uname -r`/build
default:
make -C $(KDIR) M=$(PWD) modules
clean:
make -C $(KDIR) M=$(PWD) clean
이 문제를 해결할 수 있었습니까? – bacchus
@bacchus 아니에요. 동일한 시스템을 설치하고 모듈 자체를 변경하지 않고 다른 컴퓨터로 전환했습니다. 문제를 더 조사하지는 않았지만 커널 구성에 문제가 있다고 생각합니다. –