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
-1
View File
@@ -53,7 +53,6 @@ LICENSE_PATH += "${LAYERDIR}/licenses"
PREFERRED_RPROVIDER_libdevmapper = "lvm2"
PREFERRED_RPROVIDER_libdevmapper-native = "lvm2-native"
PREFERRED_RPROVIDER_nativesdk-libdevmapper = "nativesdk-lvm2"
PREFERRED_PROVIDER_android-tools-conf ?= "android-tools-conf"
# Those lines configure whether coreutils or uutils-coreutils is used.
PREFERRED_PROVIDER_coreutils = "coreutils"
PREFERRED_PROVIDER_coreutils-native = "coreutils-native"
@@ -1,40 +0,0 @@
#!/bin/sh
set -e
conf="Conf 1"
manufacturer=RPB
model="Android device"
product=0xd002
serial=0123456789ABCDEF
vendor=0x18d1
if [ -r /etc/android-gadget-setup.machine ] ; then
. /etc/android-gadget-setup.machine
fi
[ -d /sys/kernel/config/usb_gadget ] || modprobe libcomposite
cd /sys/kernel/config/usb_gadget
[ -d adb ] && /usr/bin/android-gadget-cleanup || true
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"
@@ -1,38 +0,0 @@
DESCRIPTION = "Different utilities from Android - corressponding configuration files for using ConfigFS"
SECTION = "console/utils"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
S = "${UNPACKDIR}"
SRC_URI = " \
file://android-gadget-setup \
file://android-gadget-start \
file://android-gadget-cleanup \
file://10-adbd-configfs.conf \
"
PACKAGE_ARCH = "${MACHINE_ARCH}"
do_install() {
install -d ${D}${bindir}
install -m 0755 ${UNPACKDIR}/android-gadget-setup ${D}${bindir}
install -m 0755 ${UNPACKDIR}/android-gadget-start ${D}${bindir}
install -m 0755 ${UNPACKDIR}/android-gadget-cleanup ${D}${bindir}
if [ -r ${UNPACKDIR}/android-gadget-setup.machine ] ; then
install -d ${D}${sysconfdir}
install -m 0644 ${UNPACKDIR}/android-gadget-setup.machine ${D}${sysconfdir}
fi
install -d ${D}${systemd_unitdir}/system/android-tools-adbd.service.d
install -m 0644 ${UNPACKDIR}/10-adbd-configfs.conf ${D}${systemd_unitdir}/system/android-tools-adbd.service.d
}
FILES:${PN} += " \
${systemd_unitdir}/system/ \
"
PROVIDES += "android-tools-conf"
RPROVIDES:${PN} = "android-tools-conf"
BBCLASSEXTEND = "native"
@@ -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"
@@ -1,20 +1,40 @@
DESCRIPTION = "Different utilities from Android - corresponding configuration files"
DESCRIPTION = "Different utilities from Android - corresponding configuration files for using ConfigFS"
SECTION = "console/utils"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://android-gadget-setup"
S = "${UNPACKDIR}"
SRC_URI = " \
file://android-gadget-setup \
file://android-gadget-start \
file://android-gadget-cleanup \
file://10-adbd-configfs.conf \
"
PACKAGE_ARCH = "${MACHINE_ARCH}"
do_install() {
install -d ${D}${bindir}
install -m 0755 ${UNPACKDIR}/android-gadget-setup ${D}${bindir}
install -m 0755 ${UNPACKDIR}/android-gadget-start ${D}${bindir}
install -m 0755 ${UNPACKDIR}/android-gadget-cleanup ${D}${bindir}
if [ -r ${UNPACKDIR}/android-gadget-setup.machine ] ; then
install -d ${D}${sysconfdir}
install -m 0644 ${UNPACKDIR}/android-gadget-setup.machine ${D}${sysconfdir}
fi
install -d ${D}${systemd_unitdir}/system/android-tools-adbd.service.d
install -m 0644 ${UNPACKDIR}/10-adbd-configfs.conf ${D}${systemd_unitdir}/system/android-tools-adbd.service.d
}
python () {
pn = d.getVar('PN')
profprov = d.getVar("PREFERRED_PROVIDER_" + pn)
if profprov and pn != profprov:
raise bb.parse.SkipRecipe("PREFERRED_PROVIDER_%s set to %s, not %s" % (pn, profprov, pn))
}
FILES:${PN} += " \
${systemd_unitdir}/system/ \
"
PROVIDES += "android-tools-conf-configfs"
RPROVIDES:${PN} = "android-tools-conf-configfs"
RREPLACES:${PN} = "android-tools-conf-configfs"
RCONFLICTS:${PN} = "android-tools-conf-configfs"
BBCLASSEXTEND = "native"