ÉîÈë̽Ë÷LinuxÄÚºËÔ´´úÂëÂþÑÜ
ÕâÊÇÒ»¸öÉî¶È̽Ë÷LinuxÄÚºËÔ´´úÂëÂþÑܵĹØÓÚ1500×ÖµÄÎÄÕ¡£ÓÉÓÚƪ·ùÓÐÏÞ£¬ÎÒÃǽ«ÖصãÏÈÈÝLinuxÄÚºËÔ´´úÂëµÄ×éÖ¯½á¹¹£¬²¢ÌṩһЩÏêϸµÄ´úÂëʾÀý£¬ÒÔ×ÊÖú¶ÁÕ߸üºÃµØÃ÷È·¡£
LinuxÄÚºËÊÇÒ»¸ö¿ªÔ´µÄ²Ù×÷ϵͳÄںˣ¬ÆäÔ´´úÂëÍйÜÔÚGitHubÉÏ¡£Õû¸öLinuxÄÚºËÔ´´úÂëÂþÑܺÜÊÇÖش󣬰üÀ¨Á˼¸Ê®ÍòÐдúÂ룬Éæ¼°µ½¶à¸ö²î±ðµÄ×ÓϵͳºÍÄ£¿é¡£ÒªÉîÈëÏàʶLinuxÄÚºËÔ´´úÂëÂþÑÜ£¬Ê×ÏÈÐèÒªÊìϤÆäÕûÌåµÄ×éÖ¯½á¹¹¡£
ÔÚLinuxÄÚºËÔ´´úÂëµÄ¸ùĿ¼Ï£¬¿ÉÒÔ¿´µ½Ò»ÏµÁеÄ×ÓĿ¼ºÍÎļþ£¬ÆäÖÐһЩÖ÷ÒªµÄ×ÓĿ¼°üÀ¨£º
arch£º°üÀ¨ÁËÕë¶Ô²î±ðϵͳ½á¹¹µÄÌض¨´úÂ룬ºÃ±Èx86¡¢ARMµÈ¡£
block£º°üÀ¨ÁËÓë¿é×°±¸Ïà¹ØµÄ´úÂë¡£
drivers£º°üÀ¨ÁËÖÖÖÖ×°±¸Çý¶¯³ÌÐòµÄ´úÂë¡£
fs£º°üÀ¨ÁËÎļþϵͳÏà¹ØµÄ´úÂë¡£
include£º°üÀ¨ÁËÖÖÖÖÍ·Îļþ¡£
kernel£º°üÀ¨ÁËÓëÄÚºË×Ô¼ºÏà¹ØµÄ´úÂ룬Èçµ÷Àí¡¢ÄÚ´æÖÎÀíµÈ¡£
net£º°üÀ¨ÁËÍøÂç×ÓϵͳµÄ´úÂë¡£
³ýÁËÕâЩÖ÷ÒªµÄ×ÓĿ¼Í⣬ÉÐÓÐÐí¶àÆäËû×ÓĿ¼ºÍÎļþ£¬Ã¿¸ö¶¼ÓÐÆäÌض¨µÄ¹¦Ð§ºÍ×÷Óá£ÏÂÃæÎÒÃÇÒÔÒ»¸öÏêϸµÄÀý×ÓÀ´ÏÈÈÝLinuxÄÚºËÔ´´úÂëµÄÂþÑÜ¡£
ÒÔUSB×°±¸Çý¶¯³ÌÐòΪÀý£¬Ëüͨ³£Î»ÓÚdrivers/usbĿ¼Ï¡£ÔÚÕâ¸öĿ¼ÖУ¬ÎÒÃÇ¿ÉÒÔÕÒµ½Ò»Ð©ÓëUSB×°±¸Çý¶¯Ïà¹ØµÄÎļþ£¬Èçusb.c¡¢usb.hµÈ¡£ÕâЩÎļþ°üÀ¨ÁËUSB×°±¸Çý¶¯³ÌÐòµÄÏêϸʵÏÖ£¬Èç×°±¸³õʼ»¯¡¢Êý¾Ý´«ÊäµÈ¡£
½Ó×Å£¬ÎÒÃÇÀ´¿´Ò»¸ö¼òÆÓµÄUSB×°±¸Çý¶¯³ÌÐò´úÂëʾÀý£º
#include <linux/module.h> #include <linux/usb.h> static struct usb_device_id my_usb_device_id_table[] = { { USB_DEVICE(0x1234, 0x5678) }, {} }; MODULE_DEVICE_TABLE(usb, my_usb_device_id_table); static int my_usb_probe(struct usb_interface *interface, const struct usb_device_id *id) { // ÔÚ´Ë´¦±àдװ±¸³õʼ»¯´úÂë return 0; } static void my_usb_disconnect(struct usb_interface *interface) { // ÔÚ´Ë´¦±àдװ±¸¶Ï¿ªÅþÁ¬µÄ´¦Àí´úÂë } static struct usb_driver my_usb_driver = { .name = "my_usb_driver", .id_table = my_usb_device_id_table, .probe = my_usb_probe, .disconnect = my_usb_disconnect, }; module_usb_driver(my_usb_driver); MODULE_LICENSE("GPL");
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¶Î´úÂëÖУ¬ÎÒÃǽç˵ÁËÒ»¸ö¼òÆÓµÄUSB×°±¸Çý¶¯³ÌÐò¡£ÆäÖÐmy_usb_device_id_tableÓÃÓÚÖ¸¶¨Ö§³ÖµÄUSB×°±¸µÄVendor IDºÍProduct ID£¬my_usb_probeº¯ÊýÓÃÓÚ×°±¸³õʼ»¯£¬my_usb_disconnectº¯ÊýÓÃÓÚ´¦Àí×°±¸¶Ï¿ªÅþÁ¬Ê±µÄ²Ù×÷¡£×îºó£¬Í¨¹ýmodule_usb_driverºê×¢²áÁËÕâ¸öÇý¶¯³ÌÐò¡£
ͨ¹ýÕâ¸öÀý×Ó£¬ÎÒÃÇ¿ÉÒÔ¿´µ½LinuxÄÚºËÔ´´úÂëµÄÂþÑܽṹÒÔ¼°Ò»¸ö¼òÆÓµÄ×°±¸Çý¶¯³ÌÐòµÄʵÏÖ¡£ÉîÈë̽Ë÷LinuxÄÚºËÔ´´úÂëÂþÑÜ£¬ÓÐÖúÓÚÎÒÃǸüºÃµØÃ÷È·²Ù×÷ϵͳÄں˵ÄʵÏÖÔÀí£¬ÌáÉýÎÒÃǵıà³ÌÄÜÁ¦ºÍϵͳµ÷ÊÔÊÖÒÕ¡£
ÒÔÉϾÍÊÇÉîÈë̽Ë÷LinuxÄÚºËÔ´´úÂëÂþÑܵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡