Enabling adb support with Linux kernel for new platform / Compiling Linux kernel to add adb support

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 dependancies 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. [ TODO – updake kernel compilation commands ]

1) compile kernel with adb + mass storage gadget support

2) 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

SHUFFLED :   Identify android device information WiFi Mac Address , Product Model, Serial Number using adb

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) 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”

Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home JAVA Programs Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply