ºìÁªLinuxÃÅ»§
Linux°ïÖú

½ÌÄãÈçºÎѧϰlinuxÄÚºË

·¢²¼Ê±¼ä:2012-04-11 10:12:18À´Ô´:ºìÁª×÷Õß:empast
ºÁ²»¿äÕŵØ˵£¬Kconfig ºÍMakefile ÊÇÎÒÃÇä¯ÀÀÄں˴úÂëʱ×îΪÒÀÕ̵ÄÁ½¸öÎļþ¡£»ù±¾ÉÏ£¬LinuxÄÚºËÖÐÿһ¸öĿ¼Ï±߶¼»áÓÐÒ»¸öKconfig ÎļþºÍÒ»¸öMakefile Îļþ¡£¶ÔÓÚÒ»¸öÏ£ÍûÄܹ»ÔÚLinux Äں˵ÄÍôÑó´úÂëÀï¿´µ½Ò»Ë¿Êï¹âµÄÈËÀ´Ëµ£¬½«ËüÃÇ·ÅÔÚÔõôÖØÒªµÄµØλ¶¼²»¹ý·Ö¡£

ÎÒÃÇÈ¥Ïã¸Û£¬Í¨¹ýº£¹ØµÄʱºò£¬×Ü»áÓÐÃâ·ÑµÄµØͼºÍ¸÷ÖÖÖ¸ÄÏÄã¬ÓÐÁËËüÃÇÔÚÊÖÀïÎÒÃDzŲ»ÖÁÓÚÎÞÍ·²ÔÓ¬°ãÃÔ㯵ÄÐÐ×ßÔÚÄ°ÉúµÄ½ÖµÀÉÏ¡£¼´Ê¹ÔÚÄڵسöÈ¥ÂÃÓεÄʱºòÒ»°ãÀ´ËµÒ²×ÜÊÇ»áÊ×ÏÈÕҷݵØͼ£¬µ±È»ÁË£¬Õâʱ¾ÍÊÇҪȥÂòÁË£¬ÄÃÊÇÄò»µ½µÄ£¬²»Í¬µÄµØ·½Óв»Í¬µÄÌØÉ«£¬ Ö»²»¹ýÓеÄÌØÉ«ÊÇ·þÎñ£¬ÓеÄÌØÉ«ÊÇË÷È¡¡£

Kconfig ºÍMakefile ¾ÍÊÇLinux Kernel ÃÔ¹¬ÀïµÄµØͼ¡£µØͼÒýµ¼ÎÒÃÇÈ¥ÈÏʶһ¸ö³ÇÊУ¬¶øKconfigºÍMakefile Ôò¿ÉÒÔÈÃÎÒÃÇÁ˽âÒ»¸öKernel Ŀ¼ÏÂÃæµÄ½á¹¹¡£ÎÒÃÇÿ´Îä¯ÀÀkernel Ñ°ÕÒÊôÓÚ×Ô¼ºµÄÄÇÒ»¶Î´úÂëʱ£¬¶¼Ó¦¸ÃÊ×ÏÈ¿´¿´Ä¿Â¼ÏµÄÕâÁ½¸öÎļþ¡£

ÀûÓÃKconfig ºÍMakefile Ñ°ÕÒÄ¿±ê´úÂë

¾ÍÏñÀûÓõØͼѰÕÒÄ¿µÄµØÒ»Ñù£¬ÎÒÃÇÐèÒªÀûÓÃKconfig ºÍMakefile À´Ñ°ÕÒËùÒªÑо¿µÄÄ¿±ê´úÂë¡£±ÈÈçÎÒÃÇ´òËãÑо¿U ÅÌÇý¶¯µÄʵÏÖ£¬ÒòΪU ÅÌÊÇÒ»ÖÖstorage É豸£¬ËùÒÔÎÒÃÇÓ¦¸ÃÏȽøÈëµ½drivers/usb/storage/Ŀ¼¡£µ«ÊǸÃĿ¼ÏµÄÎļþºÜ¶à£¬ÄÇô¾¿¾¹ÄÄЩÎļþ²ÅÊÇÎÒÃÇÐèÒª¹Ø×¢µÄ?Õâʱ¾ÍÓбØÒªÏÈÈ¥ÔĶÁKconfig ºÍMakefile Îļþ¡£¶ÔÓÚKconfig Îļþ£¬ÎÒÃÇ¿ÉÒÔ¿´µ½ÏÂÃæµÄÑ¡Ïî¡£

config USB_STORAGE_DATAFAB
bool "Datafab Compact Flash Reader support (EXPERIMENTAL)"
depends on USB_STORAGE && EXPERIMENTAL
help
Support for certain Datafab CompactFlash readers.
Datafab has a web page at <http://www.datafabusa.com/>.

ÏÔÈ»£¬Õâ¸öÑ¡ÏîºÍÎÒÃǵÄÄ¿µÄûÓйØϵ¡£Ê×ÏÈËüרÃÅÕë¶ÔDatafab ¹«Ë¾µÄ²úÆ·£¬Æä´ÎËäÈ»CompactFlash reader ÊÇÒ»ÖÖflash É豸£¬µ«ÏÔÈ»²»ÊÇU ÅÌ¡£ÒòΪdrivers/usb/storage Ŀ¼ÏµĴúÂëÊÇÕë¶Ôusb mass storage ÕâÒ»ÀàÉ豸£¬¶ø²»ÊÇÕë¶ÔijһÖÖÌض¨µÄÉ豸¡£U ÅÌÖ»ÊÇusb mass storageÉ豸ÖеÄÒ»ÖÖ¡£ÔÙ±ÈÈ磺

config USB_STORAGE_SDDR55
bool "SanDisk SDDR-55 SmartMedia support (EXPERIMENTAL)"
depends on USB_STORAGE && EXPERIMENTAL
help
Say Y here to include additional code to support the Sandisk SDDR-55
SmartMedia reader in the USB Mass Storage driver.

ºÜÏÔÈ»Õâ¸öÑ¡ÏîÊÇÓйØSanDisk ²úÆ·µÄ£¬²¢ÇÒÕë¶ÔµÄÊÇSM ¿¨£¬Í¬Ñù²»ÊÇU ÅÌ£¬ËùÒÔÎÒÃÇÒ²²»ÐèҪȥ¹Ø×¢¡£

ÊÂʵÉÏ£¬ºÜÈÝÒ×È·¶¨£¬Ö»ÓÐÑ¡ÏîCONFIG_USB_STORAGE ²ÅÊÇÎÒÃÇÕæÕýÐèÒª¹Ø×¢µÄ¡£

9 config USB_STORAGE
10 tristate "USB Mass Storage support"
11 depends on USB && SCSI
12 ---help---
13 Say Y here if you want to connect USB mass storage devices to your
14 computer's USB port. This is the driver you need for USB
15 floppy drives, USB hard disks, USB tape drives, USB CD-ROMs,
16 USB flash devices, and memory sticks, along with
17 similar devices. This driver may also be used for some cameras
18 and card readers.
19
20 This option depends on 'SCSI' support being enabled, but you
21 probably also need 'SCSI device support: SCSI disk support'
22 (BLK_DEV_SD) for most USB storage devices.
23
24 To compile this driver as a module, choose M here: the
25 module will be called usb-storage.

½ÓÏÂÀ´ÔĶÁMakefile Îļþ¡£

0 #
1 # Makefile for the USB Mass Storage device drivers.
2 #
3 # 15 Aug 2000, Christoph Hellwig
4 # Rewritten to use lists instead of if-statements.
5 #
6
7 EXTRA_CFLAGS := -Idrivers/scsi
8
9 obj-$(CONFIG_USB_STORAGE) += usb-storage.o
10
11 usb-storage-obj-$(CONFIG_USB_STORAGE_DEBUG) += debug.o
12 usb-storage-obj-$(CONFIG_USB_STORAGE_USBAT) += shuttle_usbat.o
13 usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR09) += sddr09.o
14 usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR55) += sddr55.o
15 usb-storage-obj-$(CONFIG_USB_STORAGE_FREECOM) += freecom.o
16 usb-storage-obj-$(CONFIG_USB_STORAGE_DPCM) += dpcm.o
17 usb-storage-obj-$(CONFIG_USB_STORAGE_ISD200) += isd200.o
18 usb-storage-obj-$(CONFIG_USB_STORAGE_DATAFAB) += datafab.o
19 usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o
20 usb-storage-obj-$(CONFIG_USB_STORAGE_ALAUDA) += alauda.o
21 usb-storage-obj-$(CONFIG_USB_STORAGE_ONETOUCH) += onetouch.o
22 usb-storage-obj-$(CONFIG_USB_STORAGE_KARMA) += karma.o
23
24 usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \
25 initializers.o $(usb-storage-obj-y)
26
27 ifneq ($(CONFIG_USB_LIBUSUAL),)
28 obj-$(CONFIG_USB) += libusual.o
29 endif

Ç°Ãæͨ¹ýKconfig ÎļþµÄ·ÖÎö£¬ÎÒÃÇÈ·¶¨ÁËÖ»ÐèҪȥ¹Ø×¢CONFIG_USB_STORAGE Ñ¡Ïî¡£ÔÚMakefile ÎļþÀï²éÕÒCONFIG_USB_STORAGE£¬´ÓµÚ9 ÐеÃÖª£¬¸ÃÑ¡Ïî¶ÔÓ¦µÄÄ£¿éΪusbstorage¡£ÒòΪKconfig ÎļþÀïµÄÆäËûÑ¡ÏîÎÒÃǶ¼²»ÐèÒª¹Ø×¢£¬ËùÒÔMakefile µÄ11~22 ÐпÉÒÔºöÂÔ¡£µÚ24 ÐÐÒâζ×ÅÎÒÃÇÖ»ÐèÒª¹Ø×¢ scsiglue.c¡¢protocol.c¡¢transport.c¡¢usb.c¡¢initializers.c ÒÔ¼°ËüÃÇͬÃûµÄ.h Í·Îļþ¡£

Kconfig ºÍMakefile ºÜºÃµÄ°ïÖúÎÒÃǶ¨Î»µ½ÁËËùÒª¹Ø×¢µÄÄ¿±ê£¬¾ÍÏñÎÒÃǵ½Ò»¸öÄ°ÉúµÄµØ·½ÒªËæÉíЯ´øµØͼ£¬µ±ÎÒÃÇѧϰLinux ÄÚºËʱ£¬Ò²Òª½÷¼ÇÑ°ÇóKconfig ºÍMakefile µÄ°ïÖú¡£

͸¹ýÏÖÏó¿´±¾ÖÊ£¬ÊÞÊÞÃÅÎ޷ǾÍÊÇһЩÈËÌåÒÕÊõչʾ¡£Í¬ÑùÍù±¾ÖÊÀï¿´¹ýÈ¥£¬Ñ§Ï°Äںˣ¬¾ÍÊÇѧϰÄں˵ÄÔ´´úÂ룬ÈκÎÄÚºËÓйصÄÊé¼®¶¼ÊÇ»ùÓÚÄںˣ¬¶øÓÖ²»¸ßÓÚÄں˵ġ£

¼ÈȻҪѧϰÄÚºËÔ´Â룬¾ÍÒª¾­³£¶ÔÄں˴úÂë½øÐзÖÎö£¬¶øÄں˴úÂëǧǧÍò£¬»¹Ç°Æͺó¼ÌµÄ²»¶ÏÍùÀï¼Ó£¬Õâ¾ÍÈô󲿷ÖÈ˶¼ÓÐÖÖÎíÀï¿´»¨»¨²»¼ûµÄÎÞÖú¸Ð¡£²»¹ý ²»ÒªÅ£¬¿×ÀÏ·ò×ÓÔç¾ÍÁô¸øÎÒÃÇÁËÓ¦¶ÔÖ®²ß£ºÃôÓÚʶøÉ÷ÓÚÑÔ£¬¾ÍÓеÀ¶øÕýÑÉ£¬¿ÉνºÃѧҲÒÑ¡£Õâ¾ÍÊÇ˵£¬×öÊÂҪ̤ʵ²ÅÊǺÃѧÉúºÃͬ־£¬Òª×ñÑ­ÑϽ÷µÄ̬¶È£¬È¥Àí ½âÿһ¶Î´úÂëµÄʵÏÖ£¬¶àÎʶàÏë¶à¼Ç¡£Èç¹û±§×Å×ßÂí¹Û»¨£¬µÃ¹ýÇÒ¹ýµÄ̬¶È£¬½á¹û¼«ÓпÉÄܾÍÊÇÒ»±ß¿´Ò»±ß¶ª£¬Ã»Óжà´óµÄÊÕ»ñ¡£

¼ÙÉèÈ«¹ú·¿¼ÛÉÏÕÇ1.5%£¬¼ÙÉè80 ºó¾Ö³¤ÊÇÅ©Ãñ×ÓµÜ??£¬¼ÈÈ»ÎÒÃǵÄÈËÉú³äÂúÁ˼ÙÉ裬ÄÇôÎÒÔÚÕâÀï¼ÙÉèÄãÏÖÔÚ¾ÍÆȲ»¼°´ýµÄÏ£ÍûÑо¿ÄÚºËÖÐUSB ×ÓϵͳµÄʵÏÖ£¬Ó¦¸ÃûÓÐÒâ¼û°É?ÄǺã¬ÏÂÃæ¾ÍÒÔUSB×ÓϵͳµÄʵÏÖ·ÖÎöΪ±ê±¾¿´¿´·ÖÎöÄÚºËÔ´ÂëÓ¦¸ÃÈçºÎÈëÊÖ¡£

·ÖÎöREADME

ÄÚºËÖÐUSB ×ÓϵͳµÄ´úÂëλÓÚĿ¼drivers/usb£¬Õâ¸ö½áÂÛ²¢²»ÐèÒª¼ÙÉè¡£ÓÚÊÇÎÒÃǽøÈëµ½¸ÃĿ¼£¬Ö´ÐÐÃüÁîls£¬½á¹ûÏÔʾÈçÏ£º

atm class core gadget host image misc mon serial storage Kconfig
Makefile README usb-skeleton.c

Ŀ¼drivers/usb ¹²°üº¬ÓÐ10 ¸ö×ÓĿ¼ºÍ4 ¸öÎļþ£¬usb-skeleton.c ÊÇÒ»¸ö¼òµ¥µÄUSB driverµÄ¿ò¼Ü£¬¸ÐÐËȤµÄ¿ÉÒÔÈ¥¿´¿´£¬Ä¿Ç°À´Ëµ£¬Ëü»¹ÎüÒý²»ÁËÎÒÃǵÄÑÛÇò¡£ÄÇôÊ×ÏÈÓ¦¸Ã¹Øעʲô?Èç¹ûÓ­Ãæ×ßÀ´Ò»¸öppmm£¬Äã»áÊ×ÏÈ¿´Á³¡¢½Å»¹ÊÇÆä Ëü?µ±È»´ð°¸ÒÀ¾Ýÿ¸öÈ˵Äñ±ºÃ»áÓÐËù²»Í¬¡£²»¹ýÕâÀïµÄÎÊÌâÓ¦¸ÃÖ»ÓÐÒ»¸ö´ð°¸£¬ÄǾÍÊÇKconfig¡¢Makefile¡¢README¡£

README ÀïÓйØÓÚÕâ¸öĿ¼ÏÂÄÚÈݵÄÒ»°ãÐÔÃèÊö£¬Ëü²»Êǹؼü£¬Ö»ÊÇ°ïÖúÄãÁ˽⡣ÔÙ˵ÁË£¬Ãæ¶Ô¡°readÎÒ°Éread ÎÒ°É¡±ÕâôÈÈÇé±¼·ÅµÄºô»½£¬ÉÆÁ¼µÄÎÒÃÇÊDz»¿ÉÄÜÎÞ¶¯ÓÚÖԵģ¬ËùÒÔÏÈÀ´¿´¿´ÀïÃ涼ÓÐЩʲôÄÚÈÝ¡£

23 Here is a list of what each subdirectory here is, and what is contained in
24 them.
25
26 core/ - This is for the core USB host code, including the
27 usbfs files and the hub class driver ("khubd").
28
29 host/ - This is for USB host controller drivers. This
30 includes UHCI, OHCI, EHCI, and others that might
31 be used with more specialized "embedded" systems.
32
33 gadget/ - This is for USB peripheral controller drivers and
34 the various gadget drivers which talk to them.
35
36
37 Individual USB driver directories. A new driver should be added to the
38 first subdirectory in the list below that it fits into.
39
40 image/ - This is for still image drivers, like scanners or
41 digital cameras.
42 input/ - This is for any driver that uses the input subsystem,
43 like keyboard, mice, touchscreens, tablets, etc.
44 media/ - This is for multimedia drivers, like video cameras,
45 radios, and any other drivers that talk to the v4l
46 subsystem.
47 net/ - This is for network drivers.
48 serial/ - This is for USB to serial drivers.
49 storage/ - This is for USB mass-storage drivers.
50 class/ - This is for all USB device drivers that do not fit
51 into any of the above categories, and work for a range
52 of USB Class specified devices.
53 misc/ - This is for all USB device drivers that do not fit
54 into any of the above categories.

Õâ¸öREADME ÎļþÃèÊöÁËÇ°±ßʹÓÃls ÃüÁîÁгöµÄÄÇ10 ¸öÎļþ¼ÐµÄÓÃ;¡£ÄÇôʲôÊÇUSB Core?Linux Äں˿ª·¢ÕßÃÇ£¬×¨ÃÅдÁËһЩ´úÂ룬¸ºÔðʵÏÖһЩºËÐĵŦÄÜ£¬Îª±ðµÄÉ豸Çý¶¯³ÌÐòÌṩ·þÎñ£¬±ÈÈçÉêÇëÄڴ棬±ÈÈçʵÏÖһЩËùÓеÄÉ豸¶¼»á ÐèÒªµÄ¹«¹²µÄº¯Êý£¬²¢ÃÀÆäÃûÔ»USB Core¡£Ê±´ú×ÜÔÚ·¢Õ¹£¬µ±ÄêÅÖÑî¹óåúÕÕÑùÃÔËÀÌÆÃ÷»Ê£¬¶øÈç½ñÈËÃÇÐÀÉ͵ÄÔòÊÇÁÖÖ¾ÁáÕâÑùµÄħ¹íÉí²Ä¡£Í¬Ñù£¬ÔçÆÚµÄLinux Äںˣ¬Æä½á¹¹²¢²»ÊÇÈç½ñÌìÕâ°ãÓв㠴θУ¬Ô¶²»Ïñ½ñÌìÕâ°ã´íÂäÓÐÖ£¬ÄÇʱºòdrivers/usb/Õâ¸öĿ¼Ï±߷ÅÁ˺ܶàºÜ¶àÎļþ£¬USB Core ÓëÆäËû¸÷ÖÖÉ豸µÄÇý¶¯³ÌÐòµÄ´úÂ붼¶ÑÆöÔÚÕâÀºóÀ´£¬ÔõÄÎÊÀ¼äÍòǧµÄ±ä»Ã£¬×Ü°®°ÑÓÐÇéµÄÈË·ÖÁ½¶Ë¡£ÓÚÊÇÔÚdrivers/usb/Ŀ¼ÏÂÃæ³öÀ´ÁËÒ»¸öcore Ŀ¼£¬¾ÍרÃÅ·ÅһЩºËÐĵĴúÂ룬±ÈÈç³õʼ»¯Õû¸öUSB ϵͳ£¬³õʼ»¯Root Hub£¬³õʼ»¯Ö÷»ú¿ØÖÆÆ÷µÄ´úÂ룬ÔÙºóÀ´ÉõÖÁ°ÑÖ÷»ú¿ØÖÆÆ÷Ïà¹ØµÄ´úÂëÒ²µ¥¶À½¨ÁËÒ»¸öĿ¼£¬½Ðhost Ŀ¼£¬ÕâÊÇÒòΪUSBÖ÷»ú¿ØÖÆÆ÷Ëæ×Åʱ´úµÄ·¢Õ¹£¬Ò²¿ª ʼÓÐÁ˺ü¸ÖÖ£¬²»ÔÙÏñ¸Õ¿ªÊ¼ÄÇÑùÖ»ÓÐÒ»ÖÖ£¬ËùÒÔÄØ£¬Éè¼ÆÕßÃÇ°ÑһЩÖ÷»ú¿ØÖÆÆ÷¹«¹²µÄ´úÂëÈÔÈ»ÁôÔÚcore Ŀ¼Ï£¬¶øһЩ¸÷Ö÷»ú¿ØÖÆÆ÷µ¥¶ÀµÄ´úÂëÔòÒƵ½ host Ŀ¼ÏÂÃæÈøº
Ôð¸÷ÖÖÖ÷»ú¿ØÖÆÆ÷µÄÈËȥά»¤¡£

ÄÇôUSB gadget ÄÇ?gadget °×ÁË˵¾ÍÊÇÅä¼þµÄÒâ˼£¬Ö÷Òª¾ÍÊÇһЩÄÚ²¿ÔËÐÐLinux µÄǶÈëʽÉ豸£¬±ÈÈçPDA£¬É豸±¾ÉíÓÐUSB É豸¿ØÖÆÆ÷(USB Device Controller)£¬¿ÉÒÔ½«PC£¬Ò²¾ÍÊÇÎÒÃǵÄÖ÷»ú×÷Ϊmaster ¶Ë£¬½«ÕâÑùµÄÉ豸×÷Ϊslave ¶ËºÍÖ÷»úͨ¹ýUSB ½øÐÐͨÐÅ¡£´ÓÖ÷»úµÄ¹ÛµãÀ´¿´£¬ Ö÷»úϵͳµÄUSBÇý¶¯³ÌÐò¿ØÖƲåÈëÆäÖеÄUSB É豸£¬¶øUSB gadget µÄÇý¶¯³ÌÐò¿ØÖÆÍâΧÉ豸ÈçºÎ×÷Ϊһ¸öUSB É豸ºÍÖ÷»úͨ__________ÐÅ¡£±ÈÈ磬ÎÒÃǵÄǶÈëʽ°å×ÓÉÏÖ§³ÖSD ¿¨£¬Èç¹ûÎÒÃÇÏ£ÍûÔÚ½«°å×Óͨ¹ýUSB Á¬½Óµ½PC Ö®ºó£¬Õâ¸öSD ¿¨±»Ä£Äâ³ÉU ÅÌ£¬ÄÇô¾ÍҪͨ¹ýUSB gadget ¼Ü¹¹µÄÇý¶¯¡£

ʣϵļ¸¸öĿ¼·ÖÃűðÀàµÄ·ÅÁ˸÷ÖÖUSB É豸µÄÇý¶¯£¬±ÈÈçU Å̵ÄÇý¶¯ÔÚstorage Ŀ¼Ï£¬´¥ÃþÆÁºÍUSB ¼üÅÌÊó±êµÄÇý¶¯ÔÚinput Ŀ¼Ï£¬µÈµÈ¡£

ÎÒÃÇÏìÓ¦ÁËREADME µÄÈÈÇéºô»½£¬Ëü±ã¸øÓèÁËÎÒÃÇÏëÒªµÄ£¬Í¨¹ýËüÎÒÃÇÁ˽âÁËUSB Ŀ¼ÀïµÄÄÇЩÎļþ¼Ð¶¼ÓÐ×ÅʲôÑùµÄ½ÇÉ«¡£µ½ÏÖÔÚΪֹ£¬¾ÍֻʣÏÂÄں˵ĵØͼ----Kconfig ÓëMakefile Á½¸öÎļþÁË¡£ÓеØͼÔÚÊÖ£¬¶ÔÓÚÔÚÄÚºËÖÐÓε´µÄÎÒÃÇÀ´Ëµ£¬ÊǼþºÜÓäÔõÄÊÂÇ飬²»¹ý£¬ÒòΪÎÒÃǵÄÄ¿µÄÊÇÑо¿Äں˶ÔUSB ×ÓϵͳµÄʵÏÖ£¬¶ø²»ÊÇÌض¨É豸»òhost controller µÄÇý¶¯£¬ËùÒÔÕâÀïµÄ¶¨Î»ºÜÃ÷ÏÔ£¬USB Core¾ÍÊÇÎÒÃÇÐèÒª¹Ø×¢µÄ¶ÔÏó£¬ÄÇô½ÓÏÂÀ´¾ÍÊÇÒª¶Ôcore Ŀ¼ÖеÄÄÚÈݽøÐж¨Î»ÁË¡£

·ÖÎöKconfig ºÍMakefile

½øÈëµ½drivers/usb/core Ŀ¼£¬Ö´ÐÐÃüÁîls£¬½á¹ûÏÔʾÈçÏ£º

Kconfig Makefile buffer.c config.c devices.c devio.c driver.c
endpoint.c file.c generic.c hcd-pci.c hcd.c hcd.h hub.c hub.h
inode.c message.c notify.c otg_whitelist.h quirks.c sysfs.c urb.c
usb.c usb.h

È»ºóÖ´ÐÐwc ÃüÁÈçÏÂËùʾ¡£

# wc -l ./*
148 buffer.c
607 config.c
706 devices.c
1677 devio.c
1569 driver.c
357 endpoint.c
248 file.c
238 generic.c
1759 hcd.c
458 hcd.h
433 hcd-pci.c
3046 hub.c
195 hub.h
758 inode.c
144 Kconfig
21 Makefile
1732 message.c
68 notify.c
112 otg_whitelist.h
161 quirks.c
710 sysfs.c
589 urb.c
984 usb.c
160 usb.h
16880 total

drivers/usb/core Ŀ¼¹²°üÀ¨24 ¸öÎļþ£¬16880 ÐдúÂë¡£core ²»À¢ÊÇcore£¬Îª´ó¼ÒĬĬµÄ×öÕâô¶àÊ¡£²»¹ýÕâô¶àÎļþÀï²»Ò»¶¨¶¼ÊÇÎÒÃÇËùÐèÒª¹Ø×¢µÄ£¬ÏÈÄÃÔÛÃǵĵØͼÀ´¿´¿´½ÓÏÂÀ´¸ÃÔõô×ß¡£ÏÈ¿´¿´Kconfig Îļþ£¬¿ÉÒÔ¿´µ½ÏÂÃæµÄÑ¡Ïî¡£

15 config USB_DEVICEFS
16 bool "USB device filesystem"
17 depends on USB
18 ---help---
19 If you say Y here (and to "/proc file system support" in the "File
20 systems" section, above), you will get a file /proc/bus/usb/devices
21 which lists the devices currently connected to your USB bus or
22 busses, and for every connected device a file named
23 "/proc/bus/usb/xxx/yyy", where xxx is the bus number and yyy the
24 device number; the latter files can be used by user space programs
25 to talk directly to the device. These files are "virtual", meaning
26 they are generated on the fly and not stored on the hard drive.
27
28 You may need to mount the usbfs file system to see the files, use
29 mount -t usbfs none /proc/bus/usb
30
31 For the format of the various /proc/bus/usb/ files, please read
32 .
33
34 Usbfs files can't handle Access Control Lists (ACL), which are the
35 default way to grant access to USB devices for untrusted users of a
36 desktop system. The usbfs functionality is replaced by real
37 device-nodes managed by udev. These nodes live in /dev/bus/usb and
38 are used by libusb.

Ñ¡ÏîUSB_DEVICEFS Óëusbfs ÎļþϵͳÓйء£usbfs Îļþϵͳ¹ÒÔØÔÚ/proc/bus/usb Ŀ¼£¬ÏÔʾÁ˵±Ç°Á¬½ÓµÄËùÓÐUSB Éè ±¸¼°×ÜÏߵĸ÷ÖÖÐÅÏ¢£¬Ã¿¸öÁ¬½ÓµÄUSB É豸ÔÚÆäÖж¼»áÓÐÒ»¸ö¶ÔÓ¦µÄÎļþ½øÐÐÃèÊö¡£±ÈÈçÎļþ/proc/bus/usb/xxx/yyy£¬xxx ±íʾ×Ü__________ÏßµÄ ÐòºÅ£¬yyy ±íʾÉ豸ËùÔÚ×ÜÏߵĵØÖ·¡£²»¹ý²»Äܹ»ÒÀÀµËüÃÇÀ´Îȶ¨µØ·ÃÎÊÉ豸£¬ÒòΪͬһÉ豸Á½´ÎÁ¬½Ó¶ÔÓ¦µÄÃèÊöÎļþ¿ÉÄܻ᲻ͬ£¬±ÈÈ磬µÚÒ»´ÎÁ¬½ÓÒ»¸öÉ豸 ʱ£¬Ëü¿ÉÄÜÊÇ002/027£¬Ò»¶Îʱ¼äºóÔÙ´ÎÁ¬½Ó£¬Ëü¿ÉÄܾÍÒѾ­¸Ä±äΪ002/048¡£¾ÍºÃ±ÈºÃ²»ÈÝÒ×Äã°µÁµµÄmm ½ñÌì¼ûÄãµÄʱºò¶ÔÄãÅ×Á˸öÃÄÑÛ£¬ÄãÐÄ»¨Å­·Å£¬¸Ï¿ìÈ¥ÂòÁË100 ¿é²ÊƱÇì×££¬µ½µÚ¶þÌìÔÙ¼ûµ½ËýµÄʱºò£¬Ëý¶ÔÄã˵ÄãÊÇË­°¡£¬Ä㱯ʹÓû¾øµÄ¹Î¿ªÄÇ100 ¿é²ÊƱ£¬ÉÏÃæÇåһɫµÄллÄã¡£

ÒòΪusbfs Îļþϵͳ²¢²»ÊôÓÚUSB ×ÓϵͳʵÏֵĺËÐIJ¿·Ö£¬ÓëÖ®Ïà¹ØµÄ´úÂëÎÒÃÇ¿ÉÒÔ²»±Ø¹Ø×¢¡£

74 config USB_SUSPEND
75 bool "USB selective suspend/resume and wakeup (EXPERIMENTAL)"
76 depends on USB && PM && EXPERIMENTAL
77 help
78 If you say Y here, you can use driver calls or the sysfs
79 "power/state" file to suspend or resume individual USB
80 peripherals.
81
82 Also, USB "remote wakeup" signaling is supported, whereby some
83 USB devices (like keyboards and network adapters) can wake up
84 their parent hub. That wakeup cascades up the USB tree, and
85 could wake the system from states like suspend-to-RAM.
86
87 If you are unsure about this, say N here.

ÕâÒ»ÏîÊÇÓйØUSB É豸µÄ¹ÒÆðºÍ»Ö¸´¡£¿ª·¢USB µÄÈ˶¼Êǽڵç½ÚÄܵĺú¢×Ó£¬ËùÒÔЭÒéÀï¾Í¹æ¶¨ÁË£¬ËùÓеÄÉ豸¶¼±ØÐëÖ§³Ö¹ÒÆð״̬£¬¾ÍÊÇ˵ΪÁË´ïµ½½Ú µçµÄÄ¿µÄ£¬µ±É豸ÔÚÖ¸¶¨µÄʱ¼äÄÚ£¬Èç¹ûûÓз¢Éú×ÜÏß´«Ê䣬¾ÍÒª½øÈë¹ÒÆð״̬¡£µ±ËüÊÕµ½Ò»¸önon-idle µÄÐźÅʱ£¬¾Í»á±»»½ÐÑ¡£½ÚÔ¼Óõç´ÓUSB ×öÆð¡£ ²»¹ýÕâ¸öÓëÖ÷ÌâҲû̫´ó¹Øϵ£¬Ïà¹Ø´úÂëÒ²¿ÉÒÔ²»ÓùØ×¢ÁË¡£Ê£ÏµĻ¹Óм¸Ï²»¹ýËƺõÓëÔÛÃǹØϵҲ²»´ó£¬»¹ÊÇÈ¥¿´¿´Makefile¡£

5 usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \
6 config.o file.o buffer.o sysfs.o endpoint.o \
7 devio.o notify.o generic.o quirks.o
8
9 ifeq ($(CONFIG_PCI),y)
10 usbcore-objs += hcd-pci.o
11 endif
12
13 ifeq ($(CONFIG_USB_DEVICEFS),y)
14 usbcore-objs += inode.o devices.o
15 endif
16
17 obj-$(CONFIG_USB) += usbcore.o
18
19 ifeq ($(CONFIG_USB_DEBUG),y)
20 EXTRA_CFLAGS += -DDEBUG
21 endif

Makefile ¿É±ÈKconfig ¼òÂÔ¶àÁË£¬ËùÒÔ¿´ÆðÀ´Ò²¸üÇ×Çе㣬ÔÛÃÇ×ÜÊÇÄõÄmoney Ô½¶àÔ½ºÃ£¬¿´µÄ´úÂëÔ½ÉÙÔ½ºÃ¡£ÕâÀïÖ®ËùÒÔ»á³öÏÖ CONFIG_PCI£¬ÊÇÒòΪͨ³£USB µÄRoot Hub °üº¬ÔÚÒ»¸öPCI É豸ÖС£hcd-pci ºÍhcd ¹ËÃû¶ø˼Òå¾ÍÖªµÀÊÇ˵Ö÷»ú¿ØÖÆÆ÷µÄ£¬ËüÃÇʵÏÖÁËÖ÷»ú¿ØÖÆÆ÷¹«¹²²¿·Ö£¬°´Ð­ÒéÀïµÄ˵·¨ËüÃǾÍÊÇ HCDI(HCD µÄ¹«¹²½Ó¿Ú)£¬host Ŀ¼ÏÂÔòʵÏÖÁ˸÷ÖÖ²»Í¬µÄÖ÷»ú¿ØÖÆÆ÷¡£CONFIG_USB_DEVICEFS Ç°ÃæµÄKconfig ÎļþÀïÒ²¼ûµ½ÁË£¬¹ØÓÚusbfs µÄ£¬ÓëÔÛÃǵÄÖ÷ÌâÎ޹أ¬inode.cºÍdevices.c Á½¸öÎļþÒ²¿ÉÒÔ²»ÓùÜÁË¡£

ÄÇôÎÒÃÇ¿ÉÒԵóö½áÂÛ£¬ÎªÁËÀí½âÄں˶ÔUSB ×ÓϵͳµÄʵÏÖ£¬ÎÒÃÇÐèÒªÑо¿

buffer.c¡¢config.c¡¢driver.c¡¢ endpoint.c¡¢file.c¡¢generic.c¡¢hcd.chcd.h¡¢hub.c¡¢message.c¡¢notify.c¡¢otg_whitelist.h¡¢quirks.c¡¢sysfs.c¡¢urb.c ºÍusb.cÎļþ¡£

Õâô¿´À´£¬ºÃÏñ´ó¶¼ÐèÒª¹Ø×¢µÄÑù×Ó£¬Ã»ÓмõÇá¶àÉÙѹÁ¦£¬²»¹ýÕâÀï±¾Éí¾ÍÊÇUSB Core ²¿·Ö£¬ÊÇÒª×öºÜ¶àµÄÊÂΪÔÛÃÇ·ÖÓǵģ¬ËùÒÔ¶àµãÒ²ÊÇ¿ÉÒÔÀí½âµÄ¡£ÏÂÃæµÄ·ÖÎö£¬Ã׬½ÌÁ·ËµÁË£¬ÄÚÈݲ»ÖØÒª£¬ÖØÒªµÄÊÇ̬¶È¡£¾ÍÏñº«¾Ö³¤¶Ô´ýÈռǵÄ̬¶ÈÄÇÑù£¬ÑϽ÷¶øϸÖ¡£

Ö»ÒªÄãʹÓÃÕâÑùµÄ̬¶È¿ªÊ¼·ÖÎöÄںˣ¬ÄÇôÎÞÂÛÄãÑ¡ÔñÄں˵ÄÄĸö²¿·Ö×÷ΪÇÐÈëµã£¬±ÈÈçUSB£¬±ÈÈç½ø³Ì¹ÜÀí£¬ÔÚ»¨·ÑÏà¶Ô²»ËãºÜ¶àµÄʱ¼äÖ®ºó£¬Äã¾Í»á·¢ ÏÖÄã¶ÔÄں˵ÄÀí½â»áÉÏÉýµ½ÁíÍâÒ»¸ö¸ß¶È£¬Ò»¸ö±§×ÅÇé¾°·ÖÎö£¬±§×Å0.1 ÄÚºËÍêȫעÊÍ£¬±§×Ÿ÷ÖÖ¸÷ÑùµÄÄÚºËÊé¼®·­À´¸²È¥µÄ¿´ºÜ¶à±éÓÖÍüºÜ¶à±é¶¼ÎÞ·¨´ïµ½µÄ¸ß ¶È¡£ÇëÏàÐÅÎÒ!ÈÃÎÒÃÇÔÚLinux ÉçÇøÀï·¢³öºÅÕÙ£ºÑ§Ï°ÄÚºËÔ´Â룬´Óѧϰº«¾Ö³¤¿ªÊ¼!

̬¶È¾ö¶¨Ò»ÇУº´Ó³õʼ»¯º¯Êý¿ªÊ¼

ÈÎСǿÃÇ˵·¿¼Û¸ßÕÇ´ÓÏÖÔÚ¿ªÊ¼£¬¹ÉÆÀ¼ÒÃÇ˵ţÊдÓ5000 µã¿ªÊ¼¡£ËûÃǵĿªÊ¼ÐèÒªÎÒÃǵÄÇ®´ü£¬ÎÒÃǵĿªÊ¼Ö»ÐèҪһ̨µçÄÔ£¬×îºÃÔÙÓÐÒ»±­²è£¬°é׿¸Ö§Ð¡Çú¶ù£¬²»¶¢×ÅÇ®×ÜÊÇ»á±È½Ïã«ÒâµÄ¡£ÉúÈÝÒ×£¬»îÈÝÒ×£¬Éú»î²»ÈÝÒ×£¬ÒòΪ×ÜÒª¶¢×ÅÇ®¡£

ÓÐÁ˵ØͼKconfig ºÍMakefile£¬ÎÒÃÇ¿ÉÒÔÔÚÅÓ´ó¸´ÔÓµÄÄں˴úÂëÖж¨Î»ÒÔ¼°ËõСÁËÄ¿±ê´úÂëµÄ·¶Î§¡£ÄÇôÏÖÔÚ£¬ÎªÁËÑо¿Äں˶ÔUSB ×ÓϵͳµÄʵÏÖ£¬ÎÒÃÇ»¹ÐèÒªÔÚÄ¿±ê´úÂëÖÐÕÒµ½Ò»¸öÍ»ÆÆ¿Ú£¬Õâ¸öÍ»ÆÆ¿Ú¾ÍÊÇUSB ×ÓϵͳµÄ³õʼ»¯´úÂë¡£

Õë¶Ôij¸ö×Óϵͳ»òij¸öÇý¶¯£¬ÄÚºËʹÓÃsubsys_initcall »òmodule_init ºêÖ¸¶¨³õʼ»¯º¯Êý¡£ÔÚdrivers/usb/core/usb.c ÎļþÖУ¬ÎÒÃÇ¿ÉÒÔ·¢ÏÖÏÂÃæµÄ´úÂë¡£

940 subsys_initcall(usb_init);
941 module_exit(usb_exit);

ÎÒÃÇ¿´µ½Ò»¸ösubsys_initcall£¬ËüÒ²ÊÇÒ»¸öºê£¬ÎÒÃÇ¿ÉÒÔ°ÑËüÀí½âΪmodule_init£¬Ö»²»¹ýÒòΪÕⲿ·Ö´úÂë±È½ÏºËÐÄ£¬¿ª·¢ÕßÃÇ °ÑËü¿´×÷Ò»¸ö×Óϵͳ£¬¶ø²»½ö½öÊÇÒ»¸öÄ£¿é¡£ÕâÒ²ºÜºÃÀí½â£¬usbcore Õâ¸öÄ£¿éËü´ú±íµÄ²»ÊÇijһ¸öÉ豸£¬¶øÊÇËùÓÐUSB É豸ÀµÒÔÉú´æµÄÄ£¿é£¬Linux ÖУ¬ÏñÕâÑùÒ»¸öÀà±ðµÄÉ豸Çý¶¯±»½áΪһ¸ö×Óϵͳ¡£±ÈÈçPCI ×Óϵͳ£¬±ÈÈçSCSI ×Óϵͳ£¬»ù±¾ÉÏ£¬drivers/Ŀ¼ÏÂÃæµÚÒ»²ãµÄÿ¸öĿ¼¶¼ËãÒ»¸ö×Ó ÏµÍ³£¬ÒòΪËüÃÇ´ú±íÁËÒ»ÀàÉ豸¡£

subsys_initcall(usb_init)µÄÒâ˼¾ÍÊǸæËßÎÒÃÇusb_init ÊÇUSB ×ÓϵͳÕæÕýµÄ³õʼ»¯º¯Êý£¬¶øusb_exit() ½«ÊÇÕû¸öUSB ×ÓϵͳµÄ½áÊøʱµÄÇåÀíº¯Êý¡£ÓÚÊÇΪÁËÑо¿USB ×ÓϵͳÔÚÄÚºËÖеÄʵÏÖ£¬ÎÒÃÇÐèÒª´Óusb_init º¯Êý¿ªÊ¼¿´Æð¡£

865 static int __init usb_init(void)
866 {
867 int retval;
868 if (nousb) {
869 pr_info("%s: USB support disabled\n", usbcore_name);
870 return 0;
871 }
872
873 retval = ksuspend_usb_init();
874 if (retval)
875 goto out;
876 retval = bus_register(&usb_bus_type);
877 if (retval)
878 goto bus_register_failed;
879 retval = usb_host_init();
880 if (retval)
881 goto host_init_failed;
882 retval = usb_major_init();
883 if (retval)
884 goto major_init_failed;
885 retval = usb_register(&usbfs_driver);
886 if (retval)
887 goto driver_register_failed;
888 retval = usb_devio_init();
889 if (retval)
890 goto usb_devio_init_failed;
891 retval = usbfs_init();
892 if (retval)
893 goto fs_init_failed;
894 retval = usb_hub_init();
895 if (retval)
896 goto hub_init_failed;
897 retval = usb_register_device_driver(&usb_generic_driver, THIS_MODULE);
898 if (!retval)
899 goto out;
900
901 usb_hub_cleanup();
902 hub_init_failed:
903 usbfs_cleanup();
904 fs_init_failed:
905 usb_devio_cleanup();
906 usb_devio_init_failed:
907 usb_deregister(&usbfs_driver);
908 driver_register_failed:
909 usb_major_cleanup();
910 major_init_failed:
911 usb_host_cleanup();
912 host_init_failed:
913 bus_unregister(&usb_bus_type);
914 bus_register_failed:
915 ksuspend_usb_cleanup();
916 out:
917 return retval;
918 }
(1)__init ±ê¼Ç¡£

¹ØÓÚusb_init£¬µÚÒ»¸öÎÊÌâÊÇ£¬µÚ865 ÐеÄ__init ±ê¼Ç¾ßÓÐʲôÒâÒå?

д¹ýÇý¶¯µÄÓ¦¸Ã²»»áÄ°Éú£¬Ëü¶ÔÄÚºËÀ´Ëµ¾ÍÊÇÒ»ÖÖ°µÊ¾£¬±íÃ÷Õâ¸öº¯Êý½öÔÚ³õʼ»¯ÆÚ¼äʹÓã¬ÔÚÄ£¿é±»×°ÔØÖ®ºó£¬ËüÕ¼ÓõÄ×ÊÔ´¾Í»áÊͷŵôÓÃ×÷Ëü´¦¡£ËüµÄ°µ ʾÄ㶮£¬¿ÉÄãµÄ°µÊ¾£¬ËýÈ´²»¶®»òÕ߶®×°²»¶®£¬¶àôÈÃÈ˸ÐÉË¡£ËüÔÚ×Ô¼º¶ÌÔݵÄÒ»ÉúÖÐÒ»Ö±´ÓÊ·±ÖصŤ×÷£¬³ÔµÄÊDzÝͳöµÄÊÇÅ£ÄÌ£¬ÁôϵÄÊÇÕû¸öUSB×ÓϵͳµÄ·±ÈÙ¡£

ÊÜÕâÖÖ¾«ÉñËù¸ÐȾ£¬ÎÒ¾õµÃ__________ÓбØҪΪËü˵µÄ¸ü¶àЩ¡£__init µÄ¶¨ÒåÔÚ

include/linux/init.h ÎļþÀï43 #define __init __attribute__ ((__section__ (".init.text")))

ºÃÏñÕâÀïÒý³öÁ˸ü¶àµÄÒÉÎÊ£¬__attribute__ÊÇʲô?Linux Äں˴úÂëʹÓÃÁË´óÁ¿µÄGNU C À©Õ¹£¬ÒÔÖÁÓÚGNU C ³ÉΪÄܹ»±àÒëÄں˵ÄΨһ±àÒëÆ÷£¬GNU C µÄÕâЩÀ©Õ¹¶Ô´úÂëÓÅ»¯¡¢Ä¿±ê´úÂë²¼¾Ö¡¢°²È«¼ì²éµÈ·½ÃæÒ²ÌṩÁ˺ÜÇ¿µÄÖ§³Ö¡£¶ø__attribute__¾ÍÊÇÕâЩÀ©Õ¹ÖеÄÒ»¸ö£¬ËüÖ÷Òª±»ÓÃÀ´ÉùÃ÷һЩÌØÊâµÄÊôÐÔ£¬ÕâЩÊôÐÔÖ÷Òª±»ÓÃÀ´Ö¸Ê¾±àÒëÆ÷½øÐÐÌض¨·½ÃæµÄÓÅ»¯ºÍ¸ü×ÐϸµÄ´úÂë¼ì²é¡£GNU C Ö§³ÖÊ®¼¸¸öÊôÐÔ£¬section ÊÇÆäÖеÄÒ»¸ö£¬ÎÒÃDz鿴GCC µÄÊÖ²á¿ÉÒÔ¿´µ½ÏÂÃæµÄÃèÊö

¡®section ("section-name")'
Normally, the compiler places the code it generates in the `text' section. Sometimes,
however, you need additional sections, or you need certain particular functions to appear in
special sections.The `section' attribute specifies that a function lives in a particular section.
For example, the declaration:extern void foobar (void) __attribute__ ((section ("bar")));puts
the function ¡®foobar' in the ¡®bar' section.Some file formats do not support arbitrary sections so
the ¡®section' attribute is not available on all platforms. If you need to map the entire
contents of a module to a particular section, consider using the facilities of the linker instead.

ͨ³£±àÒëÆ÷½«º¯Êý·ÅÔÚ.text ½Ú£¬±äÁ¿·ÅÔÚ.data »ò.bss ½Ú£¬Ê¹ÓÃsection ÊôÐÔ£¬¿ÉÒÔÈñàÒëÆ÷½«º¯Êý»ò±äÁ¿·ÅÔÚÖ¸¶¨µÄ½ÚÖС£ÄÇôǰÃæ ¶Ô__init µÄ¶¨Òå±ã±íʾ½«ËüÐÞÊεĴúÂë·ÅÔÚ.init.text ½Ú¡£Á¬½ÓÆ÷¿ÉÒÔ°ÑÏàͬ½ÚµÄ´úÂë»òÊý¾Ý°²ÅÅÔÚÒ»Æ𣬱ÈÈç__init ÐÞÊεÄËùÓдúÂ붼»á ±»·ÅÔÚ.init.text ½ÚÀ³õʼ»¯½áÊøºó¾Í¿ÉÒÔÊÍ·ÅÕⲿ·ÖÄÚ´æ¡£

ÎÊÌâ¿ÉÒÔµ½´ËΪֹ£¬Ò²¿ÉÒÔ¸üÉîÈ룬¼´ÄÚºËÓÖÊÇÈçºÎµ÷Óõ½ÕâЩ__init ÐÞÊεijõʼ»¯º¯Êý?Òª»Ø´ðÕâ¸öÎÊÌ⣬»¹ÐèÒª»Ø¹ËÒ»ÏÂsubsys_initcall ºê£¬ËüÒ²ÔÚinclude/linux/init.h ÀﶨÒå

125 #define subsys_initcall(fn) __define_initcall("4",fn,4)

ÕâÀïÓÖ³öÏÖÁËÒ»¸öºê__define_initcall£¬ËüÓÃÓÚ½«Ö¸¶¨µÄº¯ÊýÖ¸Õëfn ·Åµ½initcall.init ½ÚÀï ¶ø¶ÔÓÚ¾ßÌåµÄsubsys_initcall ºê£¬ÔòÊÇ°Ñfn ·Åµ½.initcall.init µÄ×Ó½Ú.initcall4.init ÀҪŪÇå³þ.initcall.init¡¢.init.text ºÍ.initcall4.init ÕâÑùµÄ¶«¶«£¬ÎÒÃÇ»¹ÐèÒªÁ˽âÒ»µãÄں˿ÉÖ´ÐÐÎļþÏà¹ØµÄ¸ÅÄî¡£Äں˿ÉÖ´ÐÐÎļþÓÉÐí¶àÁ´½ÓÔÚÒ»ÆðµÄ¶ÔÏóÎļþ×é³É¡£¶ÔÏóÎļþÓÐÐí¶à½Ú£¬ÈçÎı¾¡¢Êý¾Ý¡¢init Êý¾Ý¡¢bass µÈµÈ¡£ÕâЩ¶ÔÏóÎļþ¶¼ÊÇ__________ÓÉÒ»¸ö³ÆΪÁ´½ÓÆ÷ ½Å±¾µÄÎļþÁ´½Ó²¢×°ÈëµÄ¡£Õâ¸öÁ´½ÓÆ÷½Å±¾µÄ¹¦ÄÜÊǽ«ÊäÈë¶ÔÏóÎļþµÄ¸÷½ÚÓ³Éäµ½Êä³öÎļþÖÐ;»»¾ä»°Ëµ£¬Ëü½«ËùÓÐÊäÈë¶ÔÏóÎļþ¶¼Á´½Óµ½µ¥Ò»µÄ¿ÉÖ´ÐÐÎļþÖУ¬½«¸Ã¿ÉÖ´ÐÐÎļþµÄ¸÷½Ú×°Èëµ½Ö¸¶¨µØÖ·´¦¡£ vmlinux.lds ÊÇ´æÔÚÓÚarch// Ŀ¼ÖеÄÄÚºËÁ´½ÓÆ÷½Å±¾£¬Ëü¸ºÔðÁ´½ÓÄں˵ĸ÷¸ö½Ú²¢½«ËüÃÇ×°ÈëÄÚ´æÖÐÌض¨Æ«ÒÆÁ¿´¦¡£

ÎÒ¿ÉÒÔ¸ºÔðÈεĸæËßÄ㣬Ҫ¿´¶®vmlinux.lds Õâ¸öÎļþÊÇÐèÒªÒ»·¬¹¦·òµÄ£¬²»¹ý´ó¼Ò¶¼ÊÇ´ÏÃ÷ÈË£¬´ÏÃ÷ÈË×ö´ÏÃ÷Ê£¬ËùÒÔÄãÐèÒª×öµÄÖ»ÊÇËÑË÷initcall.init£¬È»ºó±ã»á¿´µ½ËÆÔøÏàʶµÄÄÚÈÝ

__inicall_start = .;
.initcall.init : AT(ADDR(.initcall.init) - 0xC0000000)
*(.initcall1.init)
*(.initcall2.init)
*(.initcall3.init)
*(.initcall4.init)
*(.initcall5.init)
*(.initcall6.init)
*(.initcall7.init)
}
__initcall_end = .;

ÕâÀïµÄ__initcall_start Ö¸Ïò.initcall.init ½ÚµÄ¿ªÊ¼£¬__initcall_end Ö¸ÏòËüµÄ½áβ¡£¶ø.initcall.init½ÚÓÖ±»·ÖΪÁË7 ¸ö×Ó½Ú£¬·Ö±ðÊÇ

.initcall1.init
.initcall2.init
.initcall3.init
.initcall4.init
.initcall5.init
.initcall6.init
.initcall7.init

ÎÒÃǵÄsubsys_initcall ºê±ãÊǽ«Ö¸¶¨µÄº¯ÊýÖ¸Õë·ÅÔÚÁË.initcall4.init ×Ó½Ú¡£ÆäËüµÄ±ÈÈçcore_initcall ½«º¯ÊýÖ¸Õë·ÅÔÚ.initcall1.init ×Ó½Ú£¬device_initcall ½«º¯ÊýÖ¸Õë·ÅÔÚÁË.initcall6.init ×ӽڵȵȣ¬¶¼¿ÉÒÔ´Ó include/linux/init.h ÎļþÕÒµ½ËüÃǵĶ¨Òå¡£¸÷¸ö×Ö½ÚµÄ˳ÐòÊÇÈ·¶¨µÄ£¬¼´Ïȵ÷ÓÃ.initcall1.init ÖеÄÖ¸ÕëÔÙµ÷ ÓÃ.initcall2.init Öеĺ¯ÊýÖ¸Õ룬µÈµÈ¡£__init ÐÞÊεijõʼ»¯º¯ÊýÔÚÄں˳õʼ»¯¹ý³ÌÖе÷ÓõÄ˳ÐòºÍ.initcall.init ½ÚÀﺯ ÊýÖ¸ÕëµÄ˳ÐòÓйأ¬²»Í¬µÄ³õʼ»¯º¯Êý±»·ÅÔÚ²»Í¬µÄ×Ó½ÚÖУ¬Òò´ËÒ²¾Í¾ö¶¨ÁËËüÃǵĵ÷ÓÃ˳Ðò¡£

ÖÁÓÚʵ¼ÊÖ´Ðк¯Êýµ÷Óõĵط½£¬¾ÍÔÚ/init/main.c ÎļþÀÄں˵ijõʼ»¯Ã´£¬²»ÔÚÄÇÀﻹÄÜÔÚÄÄÀÀïÃæµÄdo_initcalls º¯Êý»áÖ±½ÓÓõ½ÕâÀïµÄ__initcall_start¡¢__initcall_end À´½øÐÐÅжϡ£(2)Ä£¿é²ÎÊý¡£

¹ØÓÚusb_init º¯Êý£¬µÚ¶þ¸öÎÊÌâÊÇ£¬µÚ868 ÐеÄnousb ±íʾʲô?

ÖªµÀC ÓïÑÔµÄÈ˶¼»áÖªµÀnousb ÊÇÒ»¸ö±êÖ¾£¬Ö»ÊDz»Í¬µÄ±êÖ¾Óв»Ò»ÑùµÄ¾«²Ê£¬ÕâÀïµÄnousb ÊÇÓÃÀ´ÈÃÎÒÃÇÔÚÆô¶¯Äں˵Äʱºòͨ¹ýÄں˲ÎÊýÈ¥µô USB ×ÓϵͳµÄ£¬Linux Éç»áÊÇÒ»¸öºÜÈËÐÔ»¯µÄÊÀ½ç£¬Ëü²»»áÈ¥±ÆÆÈÎÒÃǽÓÊÜUSB£¬Ò»Çж¼Ö»¹ØºõÎÒÃÇ×Ô¼ºµÄÐèÒª¡£²»¹ýÎÒÏëÎÒÃÇÒ»°ãÀ´ËµÊDz»»áÈ¥Ö¸¶¨nousb µÄ°É¡£Èç¹ûÄãÕæµÄÖ¸¶¨ÁËnousb£¬ÄÇËü¾ÍÖ»»áÓÄÔ¹µÄ˵һ¾ä¡°USB support disabled¡±£¬È»ºóÍ˳öusb_init¡£

nousb ÔÚdrivers/usb/core/usb.c ÎļþÖж¨ÒåΪ£º

static int nousb; /* Disable USB when built into kernel image */
module_param_named(autosuspend, usb_autosuspend_delay, int, 0644);
MODULE_PARM_DESC(autosuspend, "default autosuspend delay");

´ÓÖпÉÖªnousb ÊǸöÄ£¿é²ÎÊý¡£¹ØÓÚÄ£¿é²ÎÊý£¬ÎÒÃǶ¼ÖªµÀ¿ÉÒÔÔÚ¼ÓÔØÄ£¿éµÄʱºò¿ÉÒÔÖ¸¶¨£¬µ«ÊÇÈçºÎÔÚÄÚºËÆô¶¯µÄʱºòÖ¸¶¨?

´ò¿ªÏµÍ³µÄgrub Îļþ£¬È»ºóÕÒµ½kernel ÐУ¬±ÈÈ磺

kernel /boot/vmlinuz-2.6.18-kdb root=/dev/sda1 ro splash=silent vga=0x314

ÆäÖеÄroot£¬splash£¬vga µÈ¶¼±íʾÄں˲ÎÊý¡£µ±Ä³Ò»Ä£¿é±»±àÒë½øÄں˵Äʱºò£¬ËüµÄÄ£¿é²ÎÊý±ãÐèÒªÔÚkernel ÐÐÀ´Ö¸¶¨£¬¸ñʽΪ¡°Ä£¿éÃû.²ÎÊý=Öµ¡±£¬±ÈÈ磺

modprobe usbcore autosuspend=2

¶ÔÓ¦µ½kernel ÐУ¬¼´Îª £º

usbcore.autosuspend=2

ͨ¹ýÃüÁî¡°modinfo -p ${modulename}¡±¿ÉÒÔµÃÖªÒ»¸öÄ£¿éÓÐÄÄЩ²ÎÊý¿ÉÒÔʹÓá£Í¬Ê±£¬¶ÔÓÚÒѾ­¼ÓÔص½ÄÚºËÀïµÄÄ£¿é£¬ËüÃǵÄÄ£¿é²ÎÊý»áÁоÙÔÚ/sys/module /${modulename}/parameters/Ŀ¼ÏÂÃ棬¿ÉÒÔʹÓá°echo -n ${value} > /sys/module/${modulename}/parameters/${parm}¡±ÕâÑùµÄÃüÁîÈ¥Ð޸ġ£

(3)¿É±ä²ÎÊýºê¡£
¹ØÓÚusb_init º¯Êý£¬µÚÈý¸öÎÊÌâÊÇ£¬pr_info ÈçºÎʵÏÖÓëʹÓÃ?pr_info Ö»ÊÇÒ»¸ö´òÓ¡ÐÅÏ¢µÄ¿É±æ²ÎÊýºê£¬printk µÄ±äÌ壬ÔÚinclude/linux/kernel.h ÀﶨÒ壺

242 #define pr_info(fmt,arg...) \
243 printk(KERN_INFO fmt,##arg)

99 ÄêµÄISO C ±ê×¼Àï¹æ¶¨Á˿ɱä²ÎÊýºê£¬ºÍº¯ÊýÓï·¨ÀàËÆ£¬±ÈÈç

#define debug(format, ...) fprintf (stderr, format, __VA_ARGS__)ÀïÃæµÄ¡°¡­¡±¾Í±íʾ¿É±ä²ÎÊý£¬µ÷ÓÃʱ£¬ËüÃǾͻáÌæ´úºêÌåÀïµÄ__VA_ARGS__¡£GCC ×ÜÊÇ»áÏÔµÃÌØÁ¢¶ÀÐÐһЩ£¬ËüÖ§³Ö¸ü¸´ÔÓµÄÐÎʽ£¬¿ÉÒÔ¸ø¿É±ä²ÎÊýÈ¡¸öÃû×Ö£¬±ÈÈç#define debug(format, args...) fprintf (stderr, format, args)ÓÐÁËÃû×Ö×ÜÊÇ»áÈÝÒ×½»Á÷һЩ¡£ÊDz»ÊÇÓëpr_info ±È½Ï½Ó½üÁË?³ýÁË¡®##¡¯£¬ËüÖ÷ÒªÊÇÕë¶Ô¿Õ²ÎÊýµÄÇé¿ö¡£¼ÈȻ˵Êǿɱä²ÎÊý£¬ÄÇ´«µÝ¿Õ²ÎÊýÒ²×ÜÊÇ¿ÉÒԵģ¬¿Õ¼´ÊǶ࣬¶à¼´ÊÇ¿Õ£¬¹ÉÊÐÀïµÄÕÜÀíÕâÀïͬÑùÒ²ÊÇÊʺϵġ£Èç¹ûûÓС®##¡¯£¬´«µÝ¿Õ²ÎÊýµÄʱºò£¬±ÈÈçdebug ("A message");Õ¹¿ªºó£¬ÀïÃæµÄ×Ö·û´®ºóÃæ»á¶à¸ö¶àÓàµÄ¶ººÅ¡£Õâ¸ö¶ººÅÄãÓ¦¸Ã²»»áϲ»¶£¬¶ø¡®##¡¯Ôò»áʹԤ´¦ÀíÆ÷È¥µôÕâ¸ö¶àÓàµÄ¶ººÅ¡£

¹ØÓÚusb_init º¯Êý£¬ÉÏÃæµÄÈý¸öÎÊÌâÖ®Í⣬ÓàϵĴúÂë·Ö±ðÍê³Éusb ¸÷²¿·ÖµÄ³õʼ»¯£¬½ÓÏÂÀ´¾ÍÐèҪΧÈÆËüÃÇ·Ö±ð½øÐÐÉîÈë·ÖÎö¡£ÒòΪÕâÀïÖ»ÊÇÑÝʾÈçºÎÈëÊÖ·ÖÎö£¬Õ¹Ê¾µÄÖ»ÊÇÒ»ÖÖ̬¶È£¬ËùÒÔ¾ßÌåµÄÉîÈë·ÖÎö¾ÍÃâÁË°É¡£

¶ÔÓÚѧϰÀ´Ëµ£¬ÎÞÂÛÊÇÔÚѧУµÄ¿ÎÌÃѧϰ£¬»¹ÊÇÕâÀï˵µÄÄÚºËѧϰ£¬Ð§¹ûºÃ»òÕß»µ£¬×îÖ÷Ҫȡ¾öÓÚÁ½¸ö·½Ãæ----·½·¨ÂÛºÍÐÄÀí¡£×¢Ò⣬ÎÒÎÞÊÓÁËÖÇÉ̵IJîÒ죬ÕâÍæÒâ¶ùÐþÖ®ÓÖÐþ£¬²í¿ªÁË˵£¬ÊôÓÚÃÔÐŵķ¶³ë¡£Ç°ÃæÓÖÊÇKernel µØͼ£¬ÓÖÊÇÈçºÎÈëÊÖ£¬ËµµÄ¶¼ÊÇ·½·¨ÂÛµÄÎÊÌ⣬ÄÇôÕâÀïÒªÃæ¶ÔµÄ¾ÍÖ÷ÒªÊÇÐÄÀíÉϵÄÎÊÌâ¡£

¶øÐÄÀíÉϵÄÎÊÌâÖ÷ÒªÓÐÁ½¸ö£¬Ò»¸öÊÇäĿ£¬¾ÍÊÇÔÚÄܹ»ÊìÁ·ÊÊÓÃLinux ֮ǰ£¬¶ÔLinux ΪºÎÎﻹ˵²»³ö¸öµÀµÀÀ´£¬¾ÍÆȲ»¼°´ýµÄäĿµÄÈ¥Ñо¿ÄÚºËµÄ Ô´´úÂë¡£ÕâÒ»²¿·ÖÈË»á¾õµÃ¼ÈÈ»ÊÇѧϰÄںˣ¬ÄÇôºÄ·Ñʱ¼äÔÚÊìϤLinux µÄ»ù±¾²Ù×÷ÉÏ´¿´âÊÇÀ˷ѱ¦¹óµÄʱ¼äºÍ¸ÐÇé¡£²»¹ýÕâÑùËäÈ»ºÜÓк«·åͬ־µÄÈÈÇéºÍ¸É¾¢¶ù£¬µ«Ã÷ÏÔ×ßÈëÁËÒ»ÖÖÐÄÀíÎóÇø¡£ÖØÊöLinus µÄÄǾ仰£ºÒªÏÈ»áʹÓÃËü¡£

µÚ¶þ¸ö¾ÍÊǿ־塣ÈËÀà½ø»¯Õâô¶àÄ꣬Ãæ¶Ô¸´ÔÓµÄÎïÌåºÍÊÂÇ黹ÊÇ×Ü»áÓÐÌìÉúµÄ¾åÅ¸У¬ÌåÏÖÔÚÄÚºËѧϰÉÏÃæ¾ÍÊÇ£ºÄÇôÅÓ´ó¸´ÔÓµÄÄں˴úÂ룬ÈÃÈËÃæ¶ÔÆðÀ´¸ÃÇéºÎÒÔ¿°°¡!ÓÐÁËÕâÖÖ¿Ö¾åÎÞÁ¦¸Ð´æÔÚ£¬ÐÄÀíÉϾͻáÈ¥ÅųâÃæ¶Ô½Ó´¥ÄÚºËÔ´Â룬ÄþԸȥ±§×ÅÇé¾°·ÖÎö£¬ËѼ¯¸÷ÖÖ¸÷ÑùÎ廨°ËÃŵÄÄÚºËÊé¼®·ÅÔÚÄÇÀïÍÍ×Å£¬¿´ÁËÓÖÍü£¬ÍüÁËÓÖ¿´£¬Ò²²»´óÇéԸȥÈÏÕæϸÖµÃä¯ÀÀÔ´Âë¡£

Õâ¸öʱºò£¬ÎÒÃÇÔÚÐÄÀíÉÏÊÇ´àÈõµÃ£¬ÎÒÃÇÍü¼ÇÁËܽÈؽã½ã£¬¹¤ÐÐŮ֮ËùÒÔºìÆðÀ´£¬²»ÊÇËýÃÇÓжàºÃ£¬¶øÊÇÒòΪËýÃǵÃÐÄÀí×ã¹»¼áÇ¿¡£Êǵģ¬³ýÁËÏòº«¾Ö³¤Ñ§Ï°Ì¬¶È£¬ÎÒÃÇ»¹ÒªÏòÓ¿ÏÖ³öÀ´µÄÎÞÊý¸öܽÈؽã½ãºÍ¹¤ÐÐŮѧϰ¼áÇ¿µÄÐÄÀí¡£

ÓбØÒªÔÙÇ¿µ÷Ò»´Î£¬Ñ§Ï°Äںˣ¬¾ÍÊÇѧϰÄں˵ÄÔ´´úÂ룬ÈκÎÄÚºËÓйصÄÊé¼®¶¼ÊÇ»ùÓÚÄںˣ¬¶øÓÖ²»¸ßÓÚÄں˵ġ£ÄÚºËÔ´Âë±¾Éí¾ÍÊÇ×îºÃµÄ²Î¿¼×ÊÁÏ£¬ÆäËûÈκξ­µä»ò·Ç¾­µäµÄÊé×î¶àÖ»ÊÇÆ𵽸ö¸¨Öú×÷Ó㬲»ÄÜÒ²²»Ó¦¸ÃÈ¡´úÄں˴úÂëÔÚÎÒÃÇѧϰ¹ý³ÌÖеÄÖ÷µ¼µØλ¡£

¡°ÊÀ½çÉÏ×îȱµÄ²»ÊǽðÇ®£¬¶øÊÇ×ÊÔ´¡£¡±µ±ÎÒÔÚÒ»·Ý±¨Ö½ÉÏ¿´µ½Õâ¾ä´ó´ó±êÌâʱ£¬ÎҵĵÚÒ»·´Ó¦ÊÇ----×÷ÕßÒ»¶¨ÊǸö×ÔÈ»»·±£Ö÷ÒåÕߣ¬È»ºóÎÒÔÚÐßÀ¢µÃ·´Ê¡×ÔÉíµÄͬʱÓÍÈ»Éú³öÒ»¹É¶ÔÕâÑùµÄÎÞ²úÖ÷ÒåÀíÏëÕßÎޱȳ羴µÄÇéÐ÷À´¡£ÓÚÊÇ£¬ÎÒ¼ÌÐøÍùÏ¿´£¬¡°Òò´ËÔÚXXX »¹Î´ÕýʽÃæÊÐ֮ʱ£¬Ç°À´×ÉѯµÄ¿Í»§ÒѾ­²»ÉÙ£¬ÕâЩÓÐÑÛ¹âµÄ¹º·¿ÕßÃ÷°×£¬Ë­ÄÜÔÚÄ¿Ç°×îºÃµÄ¹º·¿»ú»áÏÂ×î´ó»¯µØÕ¼Óоø°æ×Ê Ô´£¬Ë­¾ÍÕÆ¿ØÁËδÀ´²Æ¸»Á÷Ïò¡£¡±(ΪÁ˱ÜÃâ×ö¹ã¸æµÄÏÓÒÉ£¬ÇëÔÊÐíÎÒʹÓÃXXX ´úÌæ¸ÃÂ¥Å̵ÄÃû×Ö¡£)¶Ùʱ£¬ÎÒÎòµÀÁË!

Æäʵ£¬º«·åͬ־ÒѾ­ÔÚÈÕ¼ÇÀï¸æËßÁËÎÒÃÇ×ÊÔ´µÄÖØÒªÐÔ£¬Òò´ËÎÒÃÇÔÚѧϰº«·åͬ־ÑϽ÷ϸÖµÄ̬¶Èͬʱ£¬»¹ÒªÁìÎòËû¶Ô×ÊÔ´µÄÁé»îÔËÓá£Ö»ÓÐÔÚÒÔÄÚºËÔ´ÂëΪÖÐÐÄ£¬¼á³Ö¸÷ÖÖѧϰ×ÊÔ´µÄ³¤ÆÚ½¨Éè²»¶¯Ò¡£¬²ÅÄÜ´ïµ½º«¾Ö³¤ÄÇÑùµÄ¸ß¶È£¬¸©ÊÓLinux ÄÚºËÊÀ½çÀïµÄÈËÉú°Ù̬¡£

×¢Ò⣬Õâ¸ö¹ÛµãÓëÇ°ÃæËù˵µÄѧϰЧ¹ûÖ÷Ҫȡ¾öÓÚ·½·¨ÂÛºÍÐÄÀíÁ½¸ö·½Ãæ²¢²»Ã¬¶Ü£¬ËüÃÇÊôÓÚ²»Í¬²ã´ÎÉϵÄÎÊÌâ¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 6 ÌõÆÀÂÛ

  1. su319 ÓÚ 2012-06-13 17:24:36·¢±í:

    Ç¿´ó°¡

  2. daway320 ÓÚ 2012-06-11 13:49:27·¢±í:

    ºÃÎÄÕ£¬ÉîÊÜÆäÒ棡
    лл¥Öí£¡

  3. projim ÓÚ 2012-06-03 12:27:30·¢±í:

    Ç¿´ó°¡

  4. calvein ÓÚ 2012-05-29 21:27:42·¢±í:

    ÁíÍâÄã½Ì¸øµÄ·½·¨ÂÛÒ²»áÈÃÎÒÒÔºóµÄѧϰµÀ·ºÃ×ߺܶà

  5. calvein ÓÚ 2012-05-29 21:26:38·¢±í:

    ʵÔÚÊÇÌ«Ç¿º·ÁË£¬ÔÚÄãÓÄĬµÄ·ç¸ñÒýµ¼Ï£¬ÎÒϸÐĶÁÍêÁËÄãµÄÎÄÕ£¬¾¡¹ÜÎÒÖ»ÊǸö²ËÄñ£¬¿´µ½C¾ÍÍ·´ó£¬È´¿´µÃºÜÊæÐÄ£¬ÌìÉúµÄ¿Ö¾å¸ÐÏûʧÁË¡£¸Ðл£¬ÄãµÄ·ç¸ñºÜºÃ£¬Ïë±ØÒÔºóѧϰʱֻҪÏëµ½ÄãµÄÎÄÕ£¬ÎÒ»áЦһÏ£¬È»ºó¼ÌÐø£¬Ð§¹ûÒ»¶¨ºÜºÃ¡£¡£¡£

  6. sourcehappy ÓÚ 2012-04-19 11:29:51·¢±í:

    àÅ£¬½â»óÁË