Yocto: Enable USB Android Debug Bridge On Raspberry Pi
Some RPi models(like Pi Zero and Pi 4) have OTG capabilities which allowed us to use them as USB gadgets. Since ADB can be connected via USB FFS, we are able to bring up adbd on RPi and connect to it via USB.
Enable systemd
Follow this post to replace sysvinit with systemd in your distribution:
Yocto: Replace sysvinit with systemd
Add android-tools into build
Recipe android-tools
in meta-openembedded/meta-oe
provides android tools like fastboot and adb/adbd. Add it into your bblayers.conf:
1 | bitbake-layers add-layer <path_to_meta-openembedded/meta-oe> |
Then add adbd into image:
1 | IMAGE_INSTALL_append = " android-tools-adbd" |
To automatically setup USB FFS, use android-tools-conf-configfs
as config provider:
1 | # add in local.conf |
android-tools-adbd
will check if file /var/usb-debugging-enabled
exists before running adbd. If you want to connect to device via USB adb once device booted up, implement a bbapend to install /var/usb-debugging-enabled
to target:
android-tools_%.bbappend:
1 | FILESEXTRAPATHS_prepend:="${THISDIR}/${PN}:" |
Enable USB FFS support in kernel
The kernel used by meta-raspberry linux-raspberrypi
doesn’t provide support for USB FFS by default, we need to implement a bbappend to patch kernel config:
1 | recipes-kernel |
enable-ffs.cfg:
1 | CONFIG_USB_FUNCTIONFS=m |
linux-raspberrypi_%.bbappend:
1 | FILESEXTRAPATHS_prepend:="${THISDIR}/files:" |
Enable RPi DWC2
DWC2 is not enabled by default, we need to enable it in machine.conf or local.conf:
1 | ENABLE_DWC2_PERIPHERAL = "1" |
Verify
We can verify it via `` once device is booted up. Connect the USB OTG port:
1 | adb devices |