USB驅動程序設計(3)—Linux USB系統架構

1.軟件系統架構

  • 軟件的系統架構分爲2中,一種是主機架構,就是說運行Linux的設備是一個主機,可以插入U盤等設備。
    • 最底部是一個USB主控制器,這是一個硬件,在芯片裏面都會帶有的。爲了讓這個主控制器工作起來,Linux需要有一個USB主控制器驅動
    • 爲了方便用戶設計USB設備驅動,Linux內核裏面實現了一些USB核心,這裏面主要是一些Linux協議之類的。USB設備驅動就是針對插入到Linux主機上的設備來設計的。

  • 另一種模型是設備端軟件架構,這裏運行Linux的設備變成了一個USB設備,它和PC機連接起來
    • 同樣它需要USB控制器硬件。同時需要一個UDC驅動來實現Linux設備作爲USB設備。在Linux內核中提供了一些Gadget API來方便用戶實現Gadget驅動。Gadget驅動是用來幹嘛的呢?它是用來實現把Linux設備變成一個USB網卡、串口的。

2.Mass Storage驅動體驗

(1)首先選擇主控制器驅動

  • make menuconfig ARCH=arm
  • device drivers->usb support->[*]support for host-side usb-><*>ohci hcd support

(2)配置設備驅動

  • device drivers->usb support->[*]support for host-side usb->
  • usb mass storage support

(3)配置熱插拔

  • general setup->[*]configure standard kernel features(for small systems)->[*]support for hot-pluggable devices

(4)配置塊設備

  • device drivers->[*]block devices-><*>low performance usb block driver
  • device drivers->scsi device support-><*>scsi device support
  • device drivers->scsi device support-><*>scsi disk suppport
  • device drivers->scsi device support-><*>scsi generic support

(5)配置文件系統

  • file systems->dos/fat/nt filesystems-><*>msdos fs support
  • file systems->dos/fat/nt filesystems-><*>vfat(windows-95)fs support
  • file systems->dos/fat/nt filesystems->(936)default codepage for fat
  • file systems->dos/fat/nt filesystems->(cp936)default iocharset for fat
  • file systems->partition types->[*]advance partition selection->
  • [*]pc bios(msdos partition tables) support
  • file systems->native language support->
  • <*>simplified chinese charset(cp936,gb2312)
  • file systems->native language support-><*>NLS UTF8

(6)編譯內核

  • make uImage ARCH=arm CROSS_COMPILE=arm-linux-
  • 將內核代碼下載到開發板並運行後插入U盤,提示如下:

  • 提示生成了一個uba的設備文件,這個就是U盤的設備文件了,把它掛在到mnt目錄下

(7)掛載塊設備

  • mount /dev/uba /mnt
  • 查看U盤的內容

  • 這個就是我的U盤裏面的內容了,但是很奇怪爲什麼選擇了utf-8,顯示中文還是亂碼,查了一些資料也沒有解決。

3.rndis驅動體驗

  • 可以使USB端口模擬成網卡使用

(1)配置控制器驅動

  • make menuconfig ARCH=arm
  • device drivers->usb support-><*>usb gadget support->
  • usb peripheral controller(s3c2410 usb device controller)

(2)配置gadget驅動

  • device drivers->usb support-><*>usb gadget support->[M]usb gadget drivers
  • device drivers->usb support-><*>usb gadget support->
  • [M]ethernet gadget(with cdc ethernet support)->[*]rndis support

(3)編譯內核

  • make uImage ARCH=arm CROSS_COMPILE=arm-linux-

(4)編譯模塊

  • make modules ARCH=arm CROSS_COMPILE=arm-linux-
  • cp drivers/usb/gadget/g_ether.ko .../rootfs

(5)安裝模塊

  • insmod g_ether.ko

(6)啓動usb網卡

  • ifconfig usb0 192.168.30.1

(7)安裝usb網卡驅動

  • 打開Windows設備管理器->更新驅動程序軟件->從計算機的設備驅動程序表中選擇->網絡適配器->Microsoft Corporation->Remote NDIS Compatible Device

(8)設置usb網卡地址

(9)測試usb網卡

  • ping 192.168.30.1
發佈了222 篇原創文章 · 獲贊 226 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章