前言:最終結果根據用戶自主選擇可實現host和device功能的切換。
效果展示:
當插入usb時設備會彈窗
當用戶選擇設備模式時pc端就會出現mtp設備盤符
實現mtp設備
ubuntu架構根文件系統通過uMTP-Responder實現usb的MTP功能
添加服務
/home/flynn/firfly_rootfs/lib/systemd/system/adbd.service
#start
[Unit]
Description= Adbd for linux
Before=rockchip.service[Service]
Type=forking
ExecStart=/etc/init.d/adbd.sh start
ExecStop=/etc/init.d/adbd.sh stop
ExecReload=/etc/init.d/adbd.sh reload[Install]
WantedBy=multi-user.target
#end
鏈接文件:/etc/systemd/system/multi*.want/adbd.service
添加腳本
/home/flynn/firfly_rootfs/etc/init.d/adbd.sh
#!/bin/bash -e
# setup configfs for adbd, usb mass storage and MTP....
MTP_EN=offUSB_ATTRIBUTE=0x409
USB_GROUP=rockchip
USB_SKELETON=b.1CONFIGFS_DIR=/sys/kernel/config
USB_CONFIGFS_DIR=${CONFIGFS_DIR}/usb_gadget/${USB_GROUP}
USB_STRINGS_DIR=${USB_CONFIGFS_DIR}/strings/${USB_ATTRIBUTE}
USB_FUNCTIONS_DIR=${USB_CONFIGFS_DIR}/functions
USB_CONFIGS_DIR=${USB_CONFIGFS_DIR}/configs/${USB_SKELETON}parameter_init()
{while read linedocase "$line" inusb_mtp_en)MTP_EN=onmake_config_string mtp;;usb_rndis_en)RNDIS_EN=onmake_config_string rndis;;esacdone <<