From b196a9f6ce8ef7d6b09d20ef79ffcf464d1a15ab Mon Sep 17 00:00:00 2001 From: Chuanhong Guo Date: Sun, 19 Nov 2023 20:56:52 +0800 Subject: package: new package for usb gadget setup Setting up usb gadgets using g_* kernel modules are considered a legacy approach, but the usb_gadget configfs is a bit annoying to use directly. The usb_gadget configfs works by creating magic directories and writing to magic files under /sys/kernel/config/usbgadget. This new package is an init script to setup usb_gadget configfs using uci. In the config file, gadget/configuration/function sections create corresponding directories. UCI options are magic files available in the configfs and strings/0x409 directories, grabbed with a 'find' command. UDC option in gadget writes the UDC file under the 'gadget' directory to attach the generated gadget config. It's also possible to apply pre-made config templates under /usr/share/usbgadget. The templates use the same UCI config format, with the 'gadget' entry named 'g1'. Currently, there are templates for CDC-ACM and CDC-NCM gadgets written based on existing g_*.ko module code. Certain SBCs come with only a USB device port (e.g. Raspberry Pi Zero). With this script, it's now possible to perform initial setup on them by adding a default NCM gadget. Signed-off-by: Chuanhong Guo --- package/utils/usbgadget/Makefile | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 package/utils/usbgadget/Makefile (limited to 'package/utils/usbgadget/Makefile') diff --git a/package/utils/usbgadget/Makefile b/package/utils/usbgadget/Makefile new file mode 100644 index 0000000000..d3a68ea9df --- /dev/null +++ b/package/utils/usbgadget/Makefile @@ -0,0 +1,54 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=usbgadget +PKG_RELEASE:=1 + +PKG_LICENSE:=BSD-2-Clause + +PKG_MAINTAINER:=Chuanhong Guo + +include $(INCLUDE_DIR)/package.mk + +define Package/$(PKG_NAME) + SECTION:=utils + CATEGORY:=Utilities + DEPENDS:=@USB_GADGET_SUPPORT +kmod-usb-gadget +kmod-usb-lib-composite + TITLE:=init script to create USB gadgets +endef + +define Build/Compile +endef + +define Package/$(PKG_NAME)/install + $(INSTALL_DIR) $(1)/etc/config $(1)/etc/init.d + $(INSTALL_CONF) ./files/usbgadget.conf $(1)/etc/config/usbgadget + $(INSTALL_BIN) ./files/usbgadget.init $(1)/etc/init.d/usbgadget +endef + +$(eval $(call BuildPackage,$(PKG_NAME))) + +# 1: short name +# 2: description +# 3: dependencies on other packages +define GadgetPreset + define Package/$(PKG_NAME)-$(1) + SECTION:=utils + CATEGORY:=Utilities + TITLE+= $(2) gadget preset + DEPENDS+= $(3) + endef + + define Package/$(PKG_NAME)-$(1)/description + This package contains the USB gadget preset for $(3). + endef + + define Package/$(PKG_NAME)-$(1)/install + $(INSTALL_DIR) $$(1)/usr/share/usbgadget + $(INSTALL_CONF) ./files/presets/$(1) $$(1)/usr/share/usbgadget + endef + + $$(eval $$(call BuildPackage,$(PKG_NAME)-$(1))) +endef + +$(eval $(call GadgetPreset,ncm,CDC-NCM,+kmod-usb-gadget-ncm)) +$(eval $(call GadgetPreset,acm,CDC-ACM,+kmod-usb-gadget-serial)) \ No newline at end of file -- cgit v1.2.3