From d34345da77bc1b2812bcfd0ac2385ffba0a4d3ba Mon Sep 17 00:00:00 2001 From: Ming Liu Date: Mon, 8 May 2023 17:01:34 +0200 Subject: libusbgx: drop recipe Let's use the libusbgx recipe from meta-openembedded, move Toradex related g1.schema to libusbgx-config recipe. The following fixes have been made to libusbgx-config: - Add 'idProduct' and 'serialnumber' to /etc/usbgx/g1.schema by pkg_postinst_ontarget function, it would runs only once at the first boot, no need to write them to /sys/kernel/config/usb_gadget/g1 everytime in ExecStartPost. With these meta-openembedded MRs: https://patchwork.yoctoproject.org/project/oe/patch/20230516133052.2071705-1-liu.ming50@gmail.com/ https://patchwork.yoctoproject.org/project/oe/patch/20230516133257.2072092-1-liu.ming50@gmail.com/ https://patchwork.yoctoproject.org/project/oe/patch/20230509113620.786170-4-liu.ming50@gmail.com/ https://patchwork.yoctoproject.org/project/oe/patch/20230509113620.786170-3-liu.ming50@gmail.com/ https://patchwork.yoctoproject.org/project/oe/patch/20230509113620.786170-2-liu.ming50@gmail.com/ the following changes have been made: - Drop '/sbin/modprobe libcomposite' and '/bin/mount -t configfs configfs /sys/kernel/config' from ExecStartPre, they are redundant since libcomposite would be automatically loaded during system starting up due to the following setting in linux-toradex recipe: KERNEL_MODULE_AUTOLOAD += "libcomposite", insteadly, now let usbgx.service require and run after sys-kernel-config.mount. - Since we have "WantedBy=usb-gadget.target" in systemd service, that ensures when udev trigger UDC rules, usbgx.service would run as well so the "Before=systemd-networkd.service" condition could be dropped from usbgx.service of meta-oe, since that is a ETH gadget specific condition. - Use "Type=simple" rather than "Type=oneshot", this ensures usbgx.service would not hang on failures, failures could happen in many conditions, like if the end user has manually configured something in configfs, or start usbgx.service twice, or someting wrong in /etc/default/usbgx or /etc/usbgx/*.schema. Signed-off-by: Ming Liu --- ...d-interface-name-for-NCM-Feature-Descript.patch | 52 ---------------------- recipes-support/libusbgx/files/setup-board.sh | 11 +++++ recipes-support/libusbgx/files/usbg.service | 19 -------- recipes-support/libusbgx/libusbgx-config.bbappend | 19 ++++++++ recipes-support/libusbgx/libusbgx_git.bb | 51 --------------------- 5 files changed, 30 insertions(+), 122 deletions(-) delete mode 100644 recipes-support/libusbgx/files/0001-libusbgx-Add-interface-name-for-NCM-Feature-Descript.patch create mode 100755 recipes-support/libusbgx/files/setup-board.sh delete mode 100644 recipes-support/libusbgx/files/usbg.service create mode 100644 recipes-support/libusbgx/libusbgx-config.bbappend delete mode 100644 recipes-support/libusbgx/libusbgx_git.bb diff --git a/recipes-support/libusbgx/files/0001-libusbgx-Add-interface-name-for-NCM-Feature-Descript.patch b/recipes-support/libusbgx/files/0001-libusbgx-Add-interface-name-for-NCM-Feature-Descript.patch deleted file mode 100644 index 9f01f33..0000000 --- a/recipes-support/libusbgx/files/0001-libusbgx-Add-interface-name-for-NCM-Feature-Descript.patch +++ /dev/null @@ -1,52 +0,0 @@ -From 4f3f2ad08e6ca132bd1dd388e02b57223bf4219d Mon Sep 17 00:00:00 2001 -From: Ming Liu -Date: Sun, 11 Dec 2022 14:11:49 +0100 -Subject: [PATCH] libusbgx: Add interface name for NCM Feature Descriptors - -In commit: abf422bffca4a4767e7e242c44910dbf5ef7094f -[ -Author: Stefan Agner -Date: Tue Jan 24 14:22:25 2017 -0800 - - libusbgx: Add interface name for Feature Descriptors - - This adds interface name required for "Feature Descriptors". If - specified, we can assume that a Feature Descriptor with the - interface name of the specified string is understood by the - kernel (e.g. interface.rndis). -] - -it only added Feature Descriptors for RNDIS, NCM also needs that, or -else it could not be recognized by Windows systems. - -Add Feature Descriptors interface name for NCM. - -Upstream-Status: Submitted [https://github.com/linux-usb-gadgets/libusbgx/pull/73] - -Signed-off-by: Ming Liu ---- - src/function/ether.c | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git a/src/function/ether.c b/src/function/ether.c -index b1fe1d2..a9eaf33 100644 ---- a/src/function/ether.c -+++ b/src/function/ether.c -@@ -184,8 +184,14 @@ struct usbg_function_type usbg_f_type_subset = { - ETHER_FUNCTION_OPTS - }; - -+static char *ncm_os_desc_ifnames[] = { -+ "ncm", -+ NULL -+}; -+ - struct usbg_function_type usbg_f_type_ncm = { - .name = "ncm", -+ .os_desc_iname = ncm_os_desc_ifnames, - ETHER_FUNCTION_OPTS - }; - --- -2.25.1 - diff --git a/recipes-support/libusbgx/files/setup-board.sh b/recipes-support/libusbgx/files/setup-board.sh new file mode 100755 index 0000000..03f5af4 --- /dev/null +++ b/recipes-support/libusbgx/files/setup-board.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +if [ -f /proc/device-tree/toradex,product-id ]; then + product_id=$(printf "0x%X\n" $((0x4000 + 0x$(tr -d "\0" < /proc/device-tree/toradex,product-id)))) + echo $product_id > /sys/kernel/config/usb_gadget/g1/idProduct +fi + +if [ -f /proc/device-tree/serial-number ]; then + serial_number=$(tr -d "\0" < /proc/device-tree/serial-number) + echo $serial_number > /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber +fi diff --git a/recipes-support/libusbgx/files/usbg.service b/recipes-support/libusbgx/files/usbg.service deleted file mode 100644 index 860587b..0000000 --- a/recipes-support/libusbgx/files/usbg.service +++ /dev/null @@ -1,19 +0,0 @@ -[Unit] -Description=Load default USB gadget schema g1.schema -ConditionPathExists=/etc/usbg/g1.schema -Before=systemd-networkd.service - -[Service] -Type=oneshot -ExecStartPre=-/sbin/modprobe libcomposite -ExecStartPre=-/bin/mount -t configfs configfs /sys/kernel/config -ExecStart=/usr/bin/gadget-import g1 /etc/usbg/g1.schema -ExecStartPost=/bin/sh -c '/bin/echo $((0x4000+$(expr $(tr -d "\0" < /proc/device-tree/toradex,product-id) + 0))) > \ - /sys/kernel/config/usb_gadget/g1/idProduct' -ExecStartPost=/bin/sh -c '/bin/cat /proc/device-tree/serial-number > \ - /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber' -ExecStartPost=/bin/sh -c '/bin/echo `ls /sys/class/udc/` > \ - /sys/kernel/config/usb_gadget/g1/UDC' - -[Install] -WantedBy=usb-gadget.target diff --git a/recipes-support/libusbgx/libusbgx-config.bbappend b/recipes-support/libusbgx/libusbgx-config.bbappend new file mode 100644 index 0000000..33ef5b7 --- /dev/null +++ b/recipes-support/libusbgx/libusbgx-config.bbappend @@ -0,0 +1,19 @@ +FILESEXTRAPATHS:prepend := "${THISDIR}/files:" + +PACKAGE_ARCH:tdx = "${MACHINE_ARCH}" + +SRC_URI:append:tdx = " \ + file://g1.schema.in \ + file://setup-board.sh \ +" + +do_install:append:tdx() { + sed -e "s:@@PRODUCT_NAME@@:${MACHINE}:" ${WORKDIR}/g1.schema.in > ${WORKDIR}/g1.schema + sed -i "s:IMPORT_SCHEMAS=.*:IMPORT_SCHEMAS=\"g1\":" ${D}${sysconfdir}/default/usbgx + + install -d ${D}${sysconfdir}/usbgx + install -m 0644 ${WORKDIR}/g1.schema ${D}${sysconfdir}/usbgx/g1.schema + + install -d ${D}${sysconfdir}/usbgx.d + install -m 0755 ${WORKDIR}/setup-board.sh ${D}${sysconfdir}/usbgx.d +} diff --git a/recipes-support/libusbgx/libusbgx_git.bb b/recipes-support/libusbgx/libusbgx_git.bb deleted file mode 100644 index b7c248a..0000000 --- a/recipes-support/libusbgx/libusbgx_git.bb +++ /dev/null @@ -1,51 +0,0 @@ -SUMMARY = "USB Gadget neXt Configfs Library" - -LICENSE = "GPL-2.0-only & LGPL-2.1-only" -LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \ - file://COPYING.LGPL;md5=4fbd65380cdd255951079008b364516c" - -inherit autotools pkgconfig systemd - -DEPENDS = "libconfig" - -EXTRA_OECONF = "--includedir=${includedir}/usbgx" - -PV = "0.2.0+git${SRCPV}" -SRCREV = "36e71e1e1ea9fb18d4765d0376329dcde90c8c91" -SRCBRANCH = "master" -SRC_URI = " \ - git://github.com/libusbgx/libusbgx.git;branch=${SRCBRANCH};protocol=https \ - file://0001-libusbgx-Add-interface-name-for-NCM-Feature-Descript.patch \ - file://usbg.service \ - file://g1.schema.in \ -" - -S = "${WORKDIR}/git" - -MACHINE_NAME ?= "${MACHINE}" -do_compile:append () { - sed -e "s:@@PRODUCT_NAME@@:${MACHINE_NAME}:" ${WORKDIR}/g1.schema.in > ${WORKDIR}/g1.schema -} - -do_install:append () { - if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then - install -d ${D}${systemd_unitdir}/system/ - install -m 0644 ${WORKDIR}/usbg.service ${D}${systemd_unitdir}/system - fi - - install -d ${D}${sysconfdir}/usbg/ - install -m 0644 ${WORKDIR}/g1.schema ${D}${sysconfdir}/usbg/g1.schema -} - -SYSTEMD_PACKAGES = "${PN}-examples" -SYSTEMD_SERVICE:${PN}-examples = "usbg.service" - -PACKAGES =+ "${PN}-examples" -PACKAGE_ARCH = "${MACHINE_ARCH}" - -FILES:${PN}-examples = " \ - ${bindir}/gadget-* \ - ${bindir}/show-gadgets \ - ${bindir}/show-udcs \ - ${sysconfdir}/usbg/g1.schema \ -" -- cgit v1.2.3