Gadget、UDC、Composite 与 ConfigFS

Gadget、UDC、Composite 与 ConfigFS

1. 分层

1
2
3
4
5
FunctionFS / configfs / legacy gadget
-> libcomposite
-> usb_gadget API
-> UDC driver
-> controller device mode

RK3588的主要UDC是DWC3 gadget。

2. UDC

UDC driver提供:

  • gadget ops;
  • endpoint enable/disable;
  • request alloc/free/queue/dequeue;
  • pullup;
  • set_selfpowered/vbus/session;
    -start/stop gadget driver。

3. Request

usb_request是Gadget侧异步I/O:

  • buf/length/dma;
  • zero/short_not_ok;
  • status/actual;
  • complete。

Function在endpoint enable后queue RX/TX request,completion中补充队列。

4. EP0

UDC接收8-byte SETUP,Composite/function处理标准、class或vendor request。无法处理返回stall。SET_CONFIGURATION后启用functions和non-control endpoints。

5. Composite

libcomposite管理:

  • device descriptor;
  • strings;
  • configuration;
  • interface/endpoint自动分配;
  • function实例;
  • setup dispatch;
  • disconnect/reset。

6. ConfigFS

典型:

1
2
3
4
5
mount -t configfs none /sys/kernel/config
mkdir /sys/kernel/config/usb_gadget/g1
# 配置 idVendor/idProduct、strings、configs、functions
ln -s functions/acm.usb0 configs/c.1/
echo <UDC-name> > UDC

写UDC属性才真正bind并拉起soft-connect。

7. 本defconfig functions

列出ACM、Mass Storage、FunctionFS、UVC及uevent支持。是否生成某function仍取决于ConfigFS运行配置。

8. FunctionFS

用户态提供descriptors和endpoint I/O,适合ADB等复杂协议。Daemon退出会影响function启停,需处理restart。

9. Mass Storage

LUN backing file/block device必须避免被Host和本机同时挂载写入,否则文件系统损坏。只读模式更安全。

10. UVC

UVC function需正确formats/frames/streaming descriptors和带宽;SuperSpeed companion descriptor影响burst。

11. 安全

固定受控VID/PID和functions;不要在锁屏/量产默认暴露ADB、网络或可写存储;限制ConfigFS写权限。

文章互动

阅读 --

留言

0 条留言

正在加载留言…