android-tools-conf: replace sysfs implementation with configfs

The android-tools-conf recipe used /sys/class/android_usb/android0/,
an interface exported by the out-of-tree android.c USB gadget driver
that Google carried in Android kernels but never submitted to mainline
Linux. It was never part of any upstream kernel release.

The configfs-based USB gadget framework (CONFIG_USB_CONFIGFS) was
merged into mainline Linux with kernel 3.10 (June 2013) and is the
correct interface for all upstream kernels since then. Additionally,
Google's Generic Kernel Image (GKI) initiative dropped android.c from
Android common kernels starting with kernel 5.10 (Android 12, 2021),
so even custom BSPs targeting modern Android cannot use this interface.

Remove android-tools-conf and rename android-tools-conf-configfs to
android-tools-conf, since the configfs-based implementation is the
only correct one for any modern kernel. Backward compatibility is
preserved via PROVIDES/RPROVIDES retaining the old
android-tools-conf-configfs name.

AI-Generated: Uses GitHub Copilot (Claude Sonnet 4.6)
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
This commit is contained in:
Etienne Cordonnier
2026-06-15 15:02:11 +02:00
committed by Khem Raj
parent 8d2cbef571
commit 55cc6751e4
8 changed files with 60 additions and 116 deletions
@@ -0,0 +1,7 @@
[Service]
# adbd uses sd_notify to signal readiness; ExecStartPost runs only after
# READY=1 is sent, so no delay is needed before activating the UDC.
Environment=ANDROID_GADGET_UDC_DELAY=0
ExecStartPre=/usr/bin/android-gadget-setup
ExecStartPost=/usr/bin/android-gadget-start
ExecStopPost=/usr/bin/android-gadget-cleanup
@@ -0,0 +1,24 @@
#!/bin/sh
[ -d /sys/kernel/config/usb_gadget ] || exit 0
cd /sys/kernel/config/usb_gadget
cd adb
echo -n "" > UDC || true
killall adbd || true
umount /dev/usb-ffs/adb
rm configs/c.1/ffs.usb0
rmdir configs/c.1/strings/0x409
rmdir configs/c.1
rmdir functions/ffs.usb0
rmdir strings/0x409
cd ..
rmdir adb
@@ -1,37 +1,40 @@
#!/bin/sh
[ ! -e /dev/pts ] && mkdir -p /dev/pts
[ ! -e /dev/pts/0 ] && mount devpts /dev/pts -t devpts
set -e
# TODO enable the lines below once we have support for getprop
# retrieve the product info from Android
# manufacturer=$(getprop ro.product.manufacturer Android)
# model=$(getprop ro.product.model Android)
# serial=$(getprop ro.serialno 0123456789ABCDEF)
conf="Conf 1"
manufacturer=RPB
model="Android device"
product=0xd002
serial=0123456789ABCDEF
vendor=0x18d1
#below are now needed in order to use FunctionFS for ADB, tested to work with 3.4+ kernels
if grep -q functionfs /proc/filesystems; then
mkdir -p /dev/usb-ffs/adb
mount -t functionfs adb /dev/usb-ffs/adb
#android-gadget-setup doesn't provide below 2 and without them it won't work, so we provide them here.
echo adb > /sys/class/android_usb/android0/f_ffs/aliases
echo ffs > /sys/class/android_usb/android0/functions
if [ -r /etc/android-gadget-setup.machine ] ; then
. /etc/android-gadget-setup.machine
fi
manufacturer="$(cat /system/build.prop | grep -o 'ro.product.manufacturer=.*' | cut -d'=' -f 2)"
model="$(cat /system/build.prop | grep -o 'ro.product.model=.*' | cut -d'=' -f 2)"
# get the device serial number from /proc/cmdline directly(since we have no getprop on
# GNU/Linux)
serial="$(cat /proc/cmdline | sed 's/.*androidboot.serialno=//' | sed 's/ .*//')"
[ -d /sys/kernel/config/usb_gadget ] || modprobe libcomposite
echo $serial > /sys/class/android_usb/android0/iSerial
echo $manufacturer > /sys/class/android_usb/android0/iManufacturer
echo $model > /sys/class/android_usb/android0/iProduct
cd /sys/kernel/config/usb_gadget
echo "0" > /sys/class/android_usb/android0/enable
echo "18d1" > /sys/class/android_usb/android0/idVendor
echo "D002" > /sys/class/android_usb/android0/idProduct
echo "adb" > /sys/class/android_usb/android0/functions
echo "1" > /sys/class/android_usb/android0/enable
[ -d adb ] && /usr/bin/android-gadget-cleanup || true
sleep 4
mkdir adb
cd adb
mkdir configs/c.1
mkdir functions/ffs.usb0
mkdir strings/0x409
mkdir configs/c.1/strings/0x409
echo -n "$vendor" > idVendor
echo -n "$product" > idProduct
echo "$serial" > strings/0x409/serialnumber
echo "$manufacturer" > strings/0x409/manufacturer
echo "$model" > strings/0x409/product
echo "$conf" > configs/c.1/strings/0x409/configuration
ln -s functions/ffs.usb0 configs/c.1
mkdir -p /dev/usb-ffs/adb
ADB_UID=$(id -u adb)
ADB_GID=$(id -g adb)
mount -t functionfs usb0 /dev/usb-ffs/adb -o "uid=$ADB_UID,gid=$ADB_GID"
@@ -0,0 +1,16 @@
#!/bin/sh
set -e
# Wait for adbd to open ep0 before activating the UDC. Without systemd
# sd_notify synchronisation there is no other signal that adbd is ready, so
# a fixed delay is used. When this script is invoked via ExecStartPost in a
# Type=notify service, adbd has already sent READY=1 before this runs and
# no delay is needed; set ANDROID_GADGET_UDC_DELAY=0 in that case (e.g. via
# a systemd drop-in Environment= line).
ANDROID_GADGET_UDC_DELAY="${ANDROID_GADGET_UDC_DELAY:-10}"
sleep "$ANDROID_GADGET_UDC_DELAY"
ls /sys/class/udc/ | head -n 1 | xargs echo -n > /sys/kernel/config/usb_gadget/adb/UDC
echo "Setting UDC $(ls /sys/class/udc/ | head -n 1) for USB ADB Gadget usage"