Linux USB 開發指南
1 前言
1.1 文檔簡介
介紹 USB 模塊配置和調試方法。
1.2 目標讀者
USB 模塊開發、維護人員。
1.3 適用范圍
表 1-1: 適用產品列表
內核版本 | 驅動文件 |
---|---|
Linux-4.9 | drivers/usb/* |
Linux-5.4 | drivers/usb/* |
2 模塊介紹
2.1 模塊功能介紹
USB 有主機功能和從設備功能。做主機時,能連接 U 盤、USB 鼠標等 USB 設備;做從設備時,具有 ADB 調試等從設備功能。
2.2 相關術語介紹
表 2-1: 術語介紹
術語 | 說明 |
---|---|
USB | Universal Serial Bus, 通用串行總線 |
OTG | On-The-Go |
ADB | Android Debug Bridge,Android 調試橋 |
Gadget | 小配件 |
HCD | Host Controller Driver,主機控制器驅動 |
UDC | USB Device Controller, USB 設備控制器 |
HCI | Host Controller Interface,主機控制器接口 |
EHCI | Enhanced Host Controller Interface,增強型主機控制器接口 |
OHCI | Open Host Controller Interface,開放式主機控制器接口 |
2.3 模塊配置介紹
2.3.1 Device Tree 配置說明
設備樹中存在的是該類芯片所有平臺的模塊配置,設備樹文件的路徑為:kernel/linux-4.9/arch/arm64(32 位平臺為 arm)/boot/dts/sunxi/xxx.dtsi(xxx 為具體芯片型號,如 sun50iw10p1 等), 設備樹配置如下所示:
? USB0 配置
usbc0:usbc0@0 {
device_type = "usbc0";
compatible = "allwinner,sunxi-otg-manager";
usb_port_type = <2>;
usb_detect_type = <1>;
usb_id_gpio;
usb_det_vbus_gpio;
usb_regulator_io = "nocare";
usb_wakeup_suspend = <0>;
usb_luns = <3>;
usb_serial_unique = <0>;
usb_serial_number = "20080411";
rndis_wceis = <1>;
status = "okay";
};
?
udc:udc-controller@0x05100000 {
compatible = "allwinner,sunxi-udc";
reg = <0x0 0x05100000 0x0 0x1000>, /*udc base*/
<0x0 0x00000000 0x0 0x100>, /*sram base*/
<0x0 0x05200000 0x0 0x1000>; /*usb1 base, for common circuit*/
interrupts = ; /*設備使用的中斷*/
clocks = <&clk_usbphy0>, <&clk_usbotg>, <&clk_usbehci1>, <&clk_usbphy1>; /*設備使用的時鐘*/
status = "okay"; /*是否使能該設備*/
};
?
ehci0:ehci0-controller@0x05101000 {
compatible = "allwinner,sunxi-ehci0";
reg = <0x0 0x05101000 0x0 0xFFF>, /*hci0 base*/
<0x0 0x00000000 0x0 0x100>,
<0x0 0x05100000 0x0 0x1000>,
<0x0 0x07010250 0x0 0x10>, /*prcm base, for usb standby*/
<0x0 0x05200000 0x0 0x1000>; /*usb1 base, for common circuit*/
interrupts = ;
clocks = <&clk_usbphy0>, <&clk_usbehci0>, <&clk_usbehci1>, <&clk_usbphy1>;
hci_ctrl_no = <0>; /*主機控制器的序列*/
status = "okay";
};
?
ohci0:ohci0-controller@0x05101400 {
compatible = "allwinner,sunxi-ohci0";
reg = <0x0 0x05101000 0x0 0xFFF>, /*hci0 base*/
<0x0 0x00000000 0x0 0x100>,
<0x0 0x05100000 0x0 0x1000>,
<0x0 0x07010250 0x0 0x10>, /*prcm base, for usb standby*/
<0x0 0x05200000 0x0 0x1000>;/*usb1 base, for common circuit*/
interrupts = ;
clocks = <&clk_usbphy0>, <&clk_usbohci0>, <&clk_usbohci1>, <&clk_usbphy1>;
hci_ctrl_no = <0>;
status = "okay";
};
? USB1 配置
usbc1:usbc1@0 {
device_type = "usbc1";
usb_regulator_io = "nocare";
usb_wakeup_suspend = <0>;
status = "okay";
};
?
ehci1:ehci1-controller@0x05200000 {
compatible = "allwinner,sunxi-ehci1";
reg = <0x0 0x05200000 0x0 0xFFF>,
<0x0 0x00000000 0x0 0x100>,
<0x0 0x05100000 0x0 0x1000>,
<0x0 0x07010250 0x0 0x10>;
interrupts = ;
clocks = <&clk_usbphy1>, <&clk_usbehci1>;
hci_ctrl_no = <1>;
status = "okay";
};
?
ohci1:ohci1-controller@0x05200400 {
compatible = "allwinner,sunxi-ohci1";
reg = <0x0 0x05200000 0x0 0xFFF>,
<0x0 0x00000000 0x0 0x100>,
<0x0 0x05100000 0x0 0x1000>,
<0x0 0x07010250 0x0 0x10>;
interrupts = ;
clocks = <&clk_usbphy1>, <&clk_usbohci1>, <&clk_usbohci1_12m>, <&clk_osc48md4>, <&clk_hosc>, <&clk_losc>;
hci_ctrl_no = <1>;
status = "okay";
};
2.3.2 board.dts 配置說明
board.dts 用于保存每一個板級平臺的設備信息(如 demo 板,perf1 板等),里面的配置信息會覆蓋上面的 Device Tree 默認配置信息。不同 soc、版型及內核版本對應的 board.dts 具體路徑如下:device/config/chips/soc/conf igs/{board}/${內核版本}/board.dts。
? USB0 配置
usbc0:usbc0@0 {
device_type = "usbc0";
usb_port_type = <0x2>;
usb_detect_type = <0x1>;
usb_id_gpio = <&pio PH 8 0 0 0xffffffff 0xffffffff>;
usb_det_vbus_gpio = "axp_ctrl";
usb_regulator_io = "nocare";
det_vbus_supply = <&usb_power_supply>;
usb_wakeup_suspend = <0>;
usb_luns = <3>;
usb_serial_unique = <0>;
usb_serial_number = "20080411";
rndis_wceis = <1>;
status = "okay";
};
?
注:(1)usb_port_type:usb0口默認的模式。
置0:devcie模式;
置1:host模式;
置2:otg模式。
(2)usb_detect_type:usb0口otg檢測模式。
置0:不做檢測;
置1:vbus/id檢測;
置2:id/dpdm檢測。
(3)usb_wakeup_suspend:standby模式。
置0:super standby模式;
置1:usb standby模式,支持遠程喚醒。
?
udc:udc-controller@0x51000000 {
det_vbus_supply = <&usb_power_supply>
}
?
ehci0:ehci0-controller@0x05101000 {
drvvbus-supply = ;
};
?
ohci0:ohci0-controller@0x05101400 {
drvvbus-supply = ;
};
說明
若使用 usb standby 模式,需注意如下:
1、IC 支持遠程喚醒;
2、若條件 1 滿足,相關硬件部分需嚴格按照《硬件設計文檔》設計;
3、若條件 1、2 滿足,額外添加屬性 “wakeup-source;”, 啟用 usb standby 功能。
? USB1 配置
usbc1:usbc1@0 {
device_type = "usbc1";
usb_regulator_io = "nocare";
usb_wakeup_suspend = <0>;
status = "okay";
};
?
ehci1:ehci1-controller@0x05200000 {
drvvbus-supply = ;
};
?
ohci1:ohci1-controller@0x05200400 {
drvvbus-supply = ;
};
? Vbus 配置
reg_usb1_vbus: usb1-vbus {
compatible = "regulator-fixed";
gpio = <&pio PH 10 1 2 0 1>;
regulator-name = "usb1-vbus";
regulator-min-microvolt = <5000000>;
regulator-max-microvolt = <5000000>;
regulator-enable-ramp-delay = <1000>;
enable-active-high;
};
2.3.3 kernel menuconfig 配置說明
進入內核根目錄,執行 make ARCH=arm menuconfig(64 位平臺為 make ARCH=arm64 menuconfig)進入配置主界面,并按以下步驟操作:
選擇 Device Drivers 選項進入下一級配置,如下圖所示。
圖 2-1: Device Drivers 選項配置
選擇 USB support 選項,進入下一級配置,如下圖所示。
圖 2-2: USB Support 選項配置
打開如下兩圖的選項,如下圖所示。
圖 2-3: USB Support 詳細配置 1
圖 2-4: USB Support 詳細配置 2
選擇 USB Gadget Support,進入下一級配置,如下圖所示。
圖 2-5: USB Gadget Support 選項配置
打開下圖的選項,并在對應配置中打開所需的功能性配置, 如: 需要存儲功能時, 需打開下圖中的 “mass storage” 配置, 如下圖所示。
圖 2-6: USB Gadget Support 詳細配置
進入 USB Peripheral Controller,并打開下圖選項:
圖 2-7: USB Peripheral Controller 詳細配置
返回上一級,即 USB support,進入 SUNXI USB2.0 Dual Role controller support,并打開下圖選項,如下圖所示。
圖 2-8: SUNXI USB2.0 Dual Role Controller Support 詳細配置
若需支持 MTP PTP 等功能需開啟 TYPEC 配置返回上一級,即 USB support,進入 USB Type-C Support,并打開下圖選項,如下圖所示:
圖 2-9: USB Type-C Support 詳細配置
2.4 源碼結構介紹
USB 驅動的源代碼位于內核 drivers/usb 目錄下,如下是 sunxi 平臺相關源碼:
? Host
drivers/usb/host/
├── ehci_sunxi.c
├── ohci_sunxi.c
├── sunxi_hci.c
├── sunxi_hci.h
? UDC 和 Manager
drivers/usb/sunxi_usb/
├── include
│ ├── sunxi_hcd.h
│ ├── sunxi_sys_reg.h
│ ├── sunxi_udc.h
│ ├── sunxi_usb_board.h
│ ├── sunxi_usb_bsp.h
│ ├── sunxi_usb_config.h
│ ├── sunxi_usb_debug.h
│ └── sunxi_usb_typedef.h
├── Kconfig
├── Makefile
├── manager
│ ├── usbc0_platform.c
│ ├── usbc_platform.h
│ ├── usb_hcd_servers.c
│ ├── usb_hcd_servers.h
│ ├── usb_hw_scan.c
│ ├── usb_hw_scan.h
│ ├── usb_manager.c
│ ├── usb_manager.h
│ ├── usb_msg_center.c
│ └── usb_msg_center.h
├── misc
│ └── sunxi_usb_debug.c
├── udc
│ ├── sunxi_udc_board.c
│ ├── sunxi_udc_board.h
│ ├── sunxi_udc.c
│ ├── sunxi_udc_config.h
│ ├── sunxi_udc_debug.c
│ ├── sunxi_udc_debug.h
│ ├── sunxi_udc_dma.c
│ └── sunxi_udc_dma.h
└── usbc
├── usbc.c
├── usbc_dev.c
├── usbc_i.h
└── usbc_phy.c
2.5 驅動框架介紹
Linux 內核提供了完整的 USB 驅動程序框架。USB 總線采用樹形結構,在一條總線上只能有唯一的主機設備。Linux 內核從主機和設備兩個角度觀察 USB 總線結構。下圖是 Linux 內核從主機和設備兩個角度觀察 USB 總線結構的示意圖。
圖 2-10: USB 驅動總體結構
USB 子系統主要任務包括:
a. 注冊和管理設備驅動;
b. USB 設備尋找驅動,并初始化和配置設備;
c. 內核中表現設備的樹形結構;
d. 與設備交互。
2.6 Gadget 配置
Gadget 是指具有 USB 設備控制器的 USB 設備,根據具體的功能配置,連接到 PC 后可以作為 mass storage、uac 等設備。Linux 有原生 gadget 框架,通用的配置流程可參考下文。
2.6.1 打開內核配置
需在 “USB functions configurable through configfs” 下選擇需要的功能。
圖 2-11: linux-4.x usb gadget 配置選擇
2.6.2 linux-4.x/linux-5.4 USB Gadget 配置流程
Linux-4.x/Linux-5.4 使用 configfs 框架實現 composite gadget 功能。具體流程如下:
? 掛載 configs:
mount -t configfs none /sys/kernel/config
掛載完成之后在/sys/kernel/config 目錄下就會生成 usb_gadget/目錄。
? 建立 gadgets:
mkdir /sys/kernel/config/usb_gadget/g1
創建g1/目錄之后,該目錄下會生成很多配置目錄,這里的g1表示 gadget 1,一個 UDC 對應一個 gadget,如果你的 SOC 上有多個 gadget,可以創建多個gx目錄。
? 寫入 gadget 的 PID、VID、序列號等信息:
echo "VID" > /sys/kernel/config/usb_gadget/g1/idVendor echo "PID" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 echo "manufacturer" > /sys/kernel/config/usb_gadget/g1/strings/0x409/manufacturer echo "product" > /sys/kernel/config/usb_gadget/g1/strings/0x409/product
? 建立 gadget 相關配置 configurations
mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 > /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409
? 建立功能 functions
mkdir /sys/kernel/config/usb_gadget/g1/functions/.
:function name :任意字符串
? 建立功能和配置的鏈接
ln -s /sys/kernel/config/usb_gadget/g1/functions/. /sys/kernel/config/ usb_gadget/g1/configs/c.1
? 使能 gadget
echo > UDC
常見 Gadget 功能的配置方式見附錄。
2.7 端點配置
在 Gadget 配置使用過程中,可能出現端點的默認配置方式無法滿足需求的情況,故需對端點進行修改滿足需求。可參考現有的端點進行修改。譬如將批量端點改成中斷端點,參考現有的中斷端點進行修改即可。改動內容包括端點 fifo 大小,端點屬性,端點方向。
2.7.1 端點 fifo 大小
以4k平臺為例: static const struct sw_udc_fifo ep_fifo[] = { {ep0name, 0, 512, 0},/*name, fifo_addr, fifo_size, double_fifo*/ {ep1in_bulk_name, 512, 512, 0}, {ep1out_bulk_name, 1024, 512, 0}, {ep2in_bulk_name, 1536, 512, 0}, {ep2out_bulk_name, 2048, 512, 0}, {ep3_iso_name, 2560, 1024, 0}, {ep4_int_name, 3584, 512, 0}, };
2.7.2 端點的屬性
.ep[2] = { .num = 1, .ep = { .name = ep1out_bulk_name, .ops = &sunxi_udc_ep_ops, .maxpacket = SW_UDC_EP_FIFO_SIZE, .maxpacket_limit = SW_UDC_EP_FIFO_SIZE, .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT), }, .dev = &sunxi_udc, .bEndpointAddress = (USB_DIR_OUT | 1), .bmAttributes = USB_ENDPOINT_XFER_BULK, },
2.7.3 定義端點的方向
/** * ep_fifo_in[i] = {n} i: the physic ep index, n: ep_fifo's index for the ep * * eg: ep_fifo_in[2] = {3} ===> ep2_in is in ep_fifo[3] * * ep3_iso_name and ep4_int_name cannot be tx or rx simultaneously. * */ static const int ep_fifo_in[] = {0, 1, 3, 5, 6, 7}; static const int ep_fifo_out[] = {0, 2, 4, 5, 6, 8};
2.8 調試方法
2.8.1 調試節點
2.8.1.1 USB0 調試節點
查看 USB0 當前 Role
cat /sys/devices/platform/soc/usbc0/otg_role
手動切換到 Host 模式
cat /sys/devices/platform/soc/usbc0/usb_host
手動切換到 Device 模式
cat /sys/devices/platform/soc/usbc0/usb_device
2.8.1.2 USB1 調試節點
卸載主機驅動
通過下述命令找到主機驅動節點及對應路徑
find -name ehci_enable find -name ohci_enable
然后根據上述結果,按如下命令卸載主機驅動 (以 t5 平臺為例)
echo 0 > sys/devices/platform/soc/5200000.ehci1-controller/ehci_enable echo 0 > sys/devices/platform/soc/5200000.ohci1-controller/ohci_enable
加載主機驅動
通過下述命令找到主機驅動節點及對應路徑
find -name ehci_enable find -name ohci_enable
然后根據上述結果,按如下命令加載主機驅動 (以 t5 平臺為例)
echo 1 > sys/devices/platform/soc/5200000.ehci1-controller/ehci_enable echo 1 > sys/devices/platform/soc/5200000.ohci1-controller/ohci_enable
2.8.2 眼圖測試
2.8.2.1 USB Device 眼圖測試
獲取otg_ed_test的路徑path find /sys/ -name otg_ed_test 測試眼圖命令 echo test_pack > path/otg_ed_test
2.8.2.2 USB Host 眼圖測試
獲取ed_test的路徑path find /sys/ -name ed_test 測試眼圖命令 echo test_pack > path/ed_test
3 FAQ
3.1 常見問題
3.1.1 USB 基本功能異常排查
3.1.1.1 USB Host 基本功能異常排查步驟
? 多找幾個 USB 設備試試,排除個別 USB 設備本身的問題。
? 多更換幾根 USB 線纜試試,排除個別 USB 線纜的問題。
? 多找幾個 PC 主機做相同的實驗,作為參考對比。若在 PC 有相同現象,則認為正常。
? 若硬件有多個 USB 口,嘗試同樣條件下測試其他 USB 口的主機功能是否正常。
? 樣機設備 USB 口外接獨立供電的 USB-HUB 設備,再將 USB 設備連接到 USB-HUB 上,確認主機功能是否正常。
? 確認主機驅動是否加載成功。
(1)若為 USB0 口,則可通過如下方式確認:
cat /sys/devices/platform/soc/usbc0/otg_role
(2)若為 USB1 口,可通過如下方式確認:
cat sys/devices/platform/soc/5200000.ehci1-controller/ehci_enable cat sys/devices/platform/soc/5200000.ohci1-controller/ohci_enable
若為0,則沒有加載Host驅動。
? 重新加載 Host 驅動,確認此時功能是否正常。
(1)若為 USB0 口,則可通過如下方式:
方式1:重新插拔OTG線。 方式2:手動切換到Host模式。
(2)若為 USB1 口,則可通過卸載驅動、再加載驅動。
? 對比 SDK 代碼與最新發布的代碼或者補丁, 確認代碼是否更新到最新。
? 同樣條件下,分別打印出功能異常板子和功能正常板子的相關寄存器,并進行對比,確認是否有不同之處。
? 出現異常時,測試 USB 高速眼圖是否正常。
? 若眼圖測試未通過,可嘗試調節眼圖參數。
3.1.1.2 USB Device 基本功能異常排查步驟
? 多換幾個 PC 主機做相同的測試,排除個別 PC 的問題。
? 多更換幾根 USB 線纜做相同的測試,排除個別 USB 線纜的問題。
? 確認 Device 驅動是否加載成功,可通過如下方式:
(1)通過 Log。
[ 104.732695] insmod_device_driver [ 104.732695] device_chose finished!
(2)通過節點查看當前 Role。
? 重新加載 Device 驅動,確認此時功能是否恢復正常。
(1)重新插拔 USB 線。
(2)手動切換到 Device 模式。
? 對比 SDK 代碼與最新發布的代碼或者補丁, 確認代碼是否更新到最新。
? 同樣條件下,分別打印出功能異常板子和功能正常板子的相關寄存器,并進行對比,確認是否有異常。
? 出現異常時,確認 USB 高速眼圖是否正常。
3.1.2 配置其他 gadget 功能前關閉 adb 功能時卻報異常的解決辦法
問題產生的原因是:僅執行./etc/adb_conf.sh stop 只是強制殺死 adb 守護進程,但 adb 功能鏈接仍存,當配置其他 gadget 功能時,便會復合 adb 鏈接導致異常,故在需要配置其他 gadget 功能時,除了強制殺死 adb 守護進程還須移除 adb 功能鏈接,在小機中操作步驟如下:
1、./etc/adb_conf.sh stop 2、umount /sys/kernel/config 3、rm -fr /sys/kernel/config/usb_gadget/g1/configs/c.1/ffs.adb
執行以上操作,正常關閉 adb 后,根據需要的 gadget 功能,參考【附錄】章節進行配置即可。
4 附錄
4.1 Linux-4.x/Linux-5.4 Gadget 配置示例
4.1.1 小機做 mass storage
dd if=/dev/zero of=/dev/a.bin bs=1M count=100 mount -t configfs none /sys/kernel/config mkdir /sys/kernel/config/usb_gadget/g1 echo "0x18d1" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0x0001" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0 echo /dev/a.bin > /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/lun.0/file mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 > /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 ln -s /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/ /sys/kernel/config/ usb_gadget/g1/configs/c.1/ ls /sys/class/udc/ | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC
說明
如果需要增加 lun,在 functions/mass_storage.usb0 下:
mkdir lun.1
mkdir lun.2
4.1.2 小機做 cdrom
mount -t configfs none /sys/kernel/config mkdir /sys/kernel/config/usb_gadget/g1 echo "0x1f3a" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0xa4ac" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 > /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0 echo 1 > /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/lun.0/cdrom echo /tmp/phoenixcard.iso > /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/ lun.0/file ln -s /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/ /sys/kernel/config/ usb_gadget/g1/configs/c.1/mass_storage.usb0 ls /sys/class/udc/ | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC
說明
/tmp/phoenixcard.iso 根據實際情況更改。
4.1.4 小機做 UAC2
mount -t configfs none /sys/kernel/config mkdir /sys/kernel/config/usb_gadget/g1 echo "0x1d61" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0x0101" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/functions/uac2.usb0 mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 > /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 ln -s /sys/kernel/config/usb_gadget/g1/functions/uac2.usb0/ /sys/kernel/config/usb_gadget/ g1/configs/c.1/ ls /sys/class/udc/ | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC
4.1.5 小機做 UVC
mount -t configfs none /sys/kernel/config mkdir /sys/kernel/config/usb_gadget/g1 echo "0x1f3a" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0x100d" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0 mkdir -p /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p echo 1280 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p/wWidth echo 720 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p/ wHeight echo 333333 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p/ dwFrameInterval echo 333333 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p/ dwDefaultFrameInterval echo 442368000 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p /dwMinBitRate echo 442368000 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p /dwMaxBitRate echo 1843200 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p/ dwMaxVideoFrameBufferSize mkdir /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/header/h ln -s /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/ /sys/kernel/ config/usb_gadget/g1/functions/uvc.usb0/streaming/header/h/ ln -s /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/header/h/ /sys/kernel/ config/usb_gadget/g1/functions/uvc.usb0/streaming/class/fs ln -s /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/header/h/ /sys/kernel/ config/usb_gadget/g1/functions/uvc.usb0/streaming/class/hs mkdir /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/control/header/h ln -s /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/control/header/h/ /sys/kernel/ config/usb_gadget/g1/functions/uvc.usb0/control/class/fs/ ln -s /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/control/header/h/ /sys/kernel/ config/usb_gadget/g1/functions/uvc.usb0/control/class/ss/ mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 > /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 ln -s /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/ /sys/kernel/config/usb_gadget/g1 /configs/c.1/ ls /sys/class/udc/ | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC
4.1.6 小機做 HID
mount -t configfs none /sys/kernel/config/ mkdir /sys/kernel/config/usb_gadget/g1 echo 0x0525 >/sys/kernel/config/usb_gadget/g1/idVendor echo 0xa4ac >/sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/functions/hid.usb0 echo 512 >/sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_length echo -ne >/sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_desc mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 >/sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 >/sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 ln -s /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/ /sys/kernel/config/usb_gadget/g1/configs/c.1/ ls /sys/class/udc/ | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC
說明
report_desc 根據需求自定義。
4.1.7 小機做 rndis
mount -t configfs none /sys/kernel/config mkdir /sys/kernel/config/usb_gadget/g1 echo "0x1f3a" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0x200a" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/functions/rndis.usb0 mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 > /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 ln -s /sys/kernel/config/usb_gadget/g1/functions/rndis.usb0/ /sys/kernel/config/usb_gadget/g1/configs/c.1/rndis.usb0 ls /sys/class/udc/ | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC
4.1.8 小機做 acm
mount -t configfs none /sys/kernel/config mkdir /sys/kernel/config/usb_gadget/g1 echo "0x1f3a" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0x0007" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/functions/acm.usb0 mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 > /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 ln -s /sys/kernel/config/usb_gadget/g1/functions/acm.usb0/ /sys/kernel/config/usb_gadget/g1/configs/c.1/acm.usb0 ls /sys/class/udc/ | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC
4.1.9 小機做 adb
mount -t configfs none /sys/kernel/config mkdir /sys/kernel/config/usb_gadget/g1 echo "0x18d1" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0x0002" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 echo "20080411" > /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber echo "Android" > /sys/kernel/config/usb_gadget/g1/strings/0x409/manufacturer mkdir /sys/kernel/config/usb_gadget/g1/functions/ffs.adb mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 > /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 ln -s /sys/kernel/config/usb_gadget/g1/functions/ffs.adb/ /sys/kernel/config/usb_gadget/g1/ configs/c.1/ffs.adb mkdir /dev/usb-ffs mkdir /dev/usb-ffs/adb mount -o uid=2000,gid=2000 -t functionfs adb /dev/usb-ffs/adb/ ls /sys/class/udc/ | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC
4.1.10 小機做 mass storage+adb
mount -t configfs none /sys/kernel/config mkdir /sys/kernel/config/usb_gadget/g1 echo "0x18d1" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0x0003" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 echo "20080411" > /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber echo "Android" > /sys/kernel/config/usb_gadget/g1/strings/0x409/manufacturer mkdir /sys/kernel/config/usb_gadget/g1/functions/ffs.adb mkdir /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0 echo ${BLOCK_PATH} > /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/lun.0/file mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 > /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 ln -s /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/ /sys/kernel/config/ usb_gadget/g1/configs/c.1/mass_storage.usb0 ln -s /sys/kernel/config/usb_gadget/g1/functions/ffs.adb/ /sys/kernel/config/usb_gadget/g1/ configs/c.1/ffs.adb mkdir /dev/usb-ffs mkdir /dev/usb-ffs/adb mount -o uid=2000,gid=2000 -t functionfs adb /dev/usb-ffs/adb/ ls /sys/class/udc/ | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC
4.1.11 小機做 uvc+uac1
mount -t configfs none /sys/kernel/config mkdir /sys/kernel/config/usb_gadget/g1 echo "0x1f3a" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0x100d" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/functions/uac1.usb0 mkdir /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0 mkdir -p /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p echo 1280 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p/wWidth echo 720 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p/wHeight echo 333333 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p/dwFrameInterval echo 333333 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p/dwDefaultFrameInterval echo 442368000 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p/dwMinBitRate echo 442368000 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p/dwMaxBitRate echo 1843200 > /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/720p/dwMaxVideoFrameBufferSize mkdir /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/header/h ln -s /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/mjpeg/m/ /sys/kernel/ config/usb_gadget/g1/functions/uvc.usb0/streaming/header/h/ ln -s /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/header/h/ /sys/kernel/ config/usb_gadget/g1/functions/uvc.usb0/streaming/class/fs ln -s /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/streaming/header/h/ /sys/kernel/ config/usb_gadget/g1/functions/uvc.usb0/streaming/class/hs mkdir /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/control/header/h ln -s /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/control/header/h/ /sys/kernel/ config/usb_gadget/g1/functions/uvc.usb0/control/class/fs/ ln -s /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/control/header/h/ /sys/kernel/ config/usb_gadget/g1/functions/uvc.usb0/control/class/ss/ mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 > /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 ln -s /sys/kernel/config/usb_gadget/g1/functions/uvc.usb0/ /sys/kernel/config/usb_gadget/g1 /configs/c.1/ ln -s /sys/kernel/config/usb_gadget/g1/functions/uac1.usb0/ /sys/kernel/config/usb_gadget/g1/configs/c.1/ ls /sys/class/udc/ | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC
4.1.12 小機做 hid+cdrom
mount -t configfs none /sys/kernel/config mkdir /sys/kernel/config/usb_gadget/g1 echo "0x1f3a" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0xa4ac" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 > /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/functions/hid.usb0 mkdir /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0 echo 512 >/sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_length echo -ne >/sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_desc ln -s /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/ /sys/kernel/config/usb_gadget/g1/configs/c.1/hid.usb0 echo 1 > /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/lun.0/cdrom echo /tmp/phoenixcard.iso > /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/lun.0/file ln -s /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/ /sys/kernel/config/usb_gadget/g1/configs/c.1/mass_storage.usb0 ls /sys/class/udc/ | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC
4.1.13 小機做 rndis+adb
mount -t configfs none /sys/kernel/config mkdir /sys/kernel/config/usb_gadget/g1 echo "0x18d1" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0x0010" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/functions/ffs.adb mkdir /sys/kernel/config/usb_gadget/g1/functions/rndis.usb0 mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 >/sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 >/sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 ln -s /sys/kernel/config/usb_gadget/g1/functions/rndis.usb0/ /sys/kernel/config/usb_gadget/g1/configs/c.1/rndis.usb0 ln -s /sys/kernel/config/usb_gadget/g1/functions/ffs.adb/ /sys/kernel/config/usb_gadget/g1/configs/c.1/ffs.adb mkdir /dev/usb-ffs mkdir /dev/usb-ffs/adb mount -o uid=2000,gid=2000 -t functionfs adb /dev/usb-ffs/adb/ ls/sys/class/udc/|xargs echo>/sys/kernel/config/usb_gadget/g1/UDC
-
內核
+關注
關注
3文章
1375瀏覽量
40311 -
usb
+關注
關注
60文章
7952瀏覽量
264936 -
Linux
+關注
關注
87文章
11313瀏覽量
209748 -
調試
+關注
關注
7文章
580瀏覽量
33968 -
開發指南
+關注
關注
0文章
34瀏覽量
7549
發布評論請先 登錄
相關推薦
評論