If you are developing/porting a new Linux kernel for some android platform, the first thing we need is a debug support. When we are porting very basic kernel, we might have UART for debugging purpose, but those have dependencies over limited UART cables and since we normally have more USB cables as those are required to charging mobiles, its always better to have some kind of debugging over USB cable. Android allows us to connect to device shell using its own Android Debug Bridge (ADB) protocol.
Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device. Reference Android Studio
The first step we need to do is to make sure, we have USB ADB gadget support enabled in Linux kernel.
Before KERNEL version 3.10, the Android had a separate ADB driver at drivers/usb/gadget/f_adb.c and can be enable from menuconfig. After 3.10, Android has deprecated f_adb.c and has replaced with Accessory driver at drivers/usb/gadget/function/f_accessory.c
For compiling kernel, Follow steps from “Compile custom Linux kernel for Android / AOSP on Ubuntu”
Flash and connect USB cable to Host
dmesg looks like..
[11621.761441] usb 2-1: new high speed USB device using ehci_hcd and address 27
[11621.912445] usb 2-1: configuration #1 chosen from 1 choice
[11621.959123] Initializing USB Mass Storage driver…
[11621.959341] scsi6 : SCSI emulation for USB Mass Storage devices
[11621.959551] usbcore: registered new interface driver usb-storage
[11621.959555] USB Mass Storage support registered.
[11621.964209] usb-storage: device found at 27
[11621.964212] usb-storage: waiting for device to settle before scanning
[11626.961587] usb-storage: device scan complete
[11626.962259] scsi 6:0:0:0: Direct-Access <NULL> <NULL> 0000 PQ: 0 ANSI: 2
[11626.963870] sd 6:0:0:0: Attached scsi generic sg1 type 0
[11626.966200] sd 6:0:0:0: [sdb] Attached SCSI removable disk
$ lsusb
Bus 002 Device 027: ID 18d1:0002
$ lsusb -v -d 18d1:0002
Bus 002 Device 027: ID 18d1:0002
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x18d1
idProduct 0x0002
bcdDevice 2.16
iManufacturer 1
iProduct 2
iSerial 3
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 55
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0 ( Self Powered, Remote Wakeup)
MaxPower 2mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 8 Mass Storage
bInterfaceSubClass 6 SCSI
bInterfaceProtocol 80 Bulk (Zip)
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 1
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 66
bInterfaceProtocol 1
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
3) add a udev rule of your Host with following information
$ vim /etc/udev/rules.d/51-android.rules
SUBSYSTEM==”usb”, SYSFS{idVendor}==”18d1″, MODE=”0666″
4) Change the permissions
$ chmod 777 /etc/udev/rules.d/51-android.rules
5) Now disconnect and reconnect USB cable and run “adb devices”
$ adb kill-server
(may be need to kill adb server if was already running)
$ adb devices
List of devices attached
0123456789ABCDEF device
$ adb shell
On device
=========
# ls -l /dev/android*
crw-rw—- adb adb 10, 60 2010-07-01 07:20 android_adb
crw-rw—- adb adb 10, 61 2010-07-01 07:20 android_adb_enable
adbd process running
# root 883 1 3364 156 ffffffff 0000f444 S /sbin/adbd
** Modifications for conencting with adb if using another USB Vendor ID.
==============================================================
1) Modify system/core/adb/usb_vendors.c as following.
+++ b/adb/usb_vendors.c
@@ -69,6 +69,7 @@
#define VENDOR_ID_PANTECH 0x10A9
// Qualcomm’s USB Vendor ID
#define VENDOR_ID_QUALCOMM 0x05c6
+#define VENDOR_ID_CORPORATION 0xabcd
/** built-in vendor list */
@@ -90,6 +91,7 @@ int builtInVendorIds[] = {
VENDOR_ID_KYOCERA,
VENDOR_ID_PANTECH,
VENDOR_ID_QUALCOMM,
+ VENDOR_ID_CORPORATION,
};
2) change udev rule(/etc/udev/rules.d/51-android.rules) as following,
SUBSYSTEM==”usb”, SYSFS{idVendor}==”abcd”, MODE=”0666″
then recompile android, and used recompiled “out/host/linux-x86/bin/adb” binary for getting adb shell.
# ./out/host/linux-x86/bin/adb devices
List of devices attached
0123456789ABCDEF offline
Here, “0123456789ABCDEF” is the sring from usb descriptor “Serial Number” String descriptor as a part of “usb device descriptor”
Hi,
I am trying to enable the USB ADB support in the 4.9 kernel, but i didn’t found and ADB support in USB gadget, can you please help me out where I can find the dependent files for USB ADB.
There is a adb.c file in drivers/macintosh folder but i didn’t found any link there to USB ADB. Is that the file to compile or is there any other way to enable the USB ADB in the latest kernels.
Thanks in advance for the support
The ADB driver from linux kernel 3.10 seems to have been replaced with Android Accessories driver and is available at drivers/usb/gadget/function/f_accessory.c
So, for 4.9 enable this Accessory driver with CONFIG_USB_F_ACC in “make menuconfig” and recompile kernel.