OpenWrt Forum Archive

Topic: ADB android debug bridge

The content of this topic has been archived on 7 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

https://gist.github.com/swiftgeek/05d22fd75329685a47fc
#This is my first package ever for openwrt

• Seems to work fine on x86 (tested under vbox)
• Breaks on ar71xx (ADB_TRACE=1 is useful here):
      USB: ID of device is recognized successfully but device is marked as offline
      TCP/IP: daemon nearly immediately fails
      It fails with and without debian-sid patches

It would be great if somebody would try this package on other platforms
——————————————————
Update: https://gist.github.com/swiftgeek/05d22 … 6589f4bced
Big endian is now detected and -DHAVE_BIG_ENDIAN=1 is passed to makefile
Both TCP/IP and USB do work now for x86 / mips be (eg. ar71xx) / mipsel

(Last edited by swiftgeek on 7 Jan 2015, 08:45)

I've tried to cross-compile this package changing dependencies without any result, please could you guide us a little bit.
Mi system is an mr3040 with barrier braker, would be awesome this could be ported

Looks like I was able to compile adb_android.4.4.2_r2-1_ar71xx.ipk for the ar71xx architecture using the OpenWrt trunk SDK. I have not tested whether the software inside the package is working, yet.

Here is what I did:

wget "https://downloads.openwrt.org/snapshots/trunk/ar71xx/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2"
tar xjf OpenWrt-SDK-*.tar.bz2
cd OpenWrt-SDK-*/package/
mkdir -p adb ; cd adb/
wget "https://gist.githubusercontent.com/swiftgeek/05d22fd75329685a47fc/raw/1629938039056ade4e03b3a68ea61cace3d43dbb/Makefile"
wget "https://gist.githubusercontent.com/swiftgeek/05d22fd75329685a47fc/raw/c51dcef941301e72144a15d5a41cc4f0430aa034/adbMakefile"
cd ../../
./scripts/feeds update packages
make V=s
# The package is created at bin/ar71xx/packages/base/adb_android.4.4.2_r2-1_ar71xx.ipk

thanks a lot, i will try it right now!!!

I installed the package and I can apparently see an Android device attached via USB, but it is reported as "offline". So I can confirm the original poster's issue.

List of devices attached 
<serial number>    offline

yes, same issue, ican not communicate with any android device, just recognizes it bot notworking for me either

I got this error:
make  V=s
#
# configuration written to .config
#
make[1]: Entering directory `/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2'
make[2]: Entering directory `/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2'
make[3]: Entering directory `/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2/package/adb'
make -C /root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2/build_dir/target-mips_34kc_uClibc-0.9.33.2/adb-e65b7ea8801145626504c724c28aedd0e5038a28/adb/ AR="mips-openwrt-linux-uclibc-gcc-ar" AS="mips-openwrt-linux-uclibc-gcc -c -Os -pipe -mno-branch-likely -mips32r2 -mtune=34kc -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -msoft-float" LD=mips-openwrt-linux-uclibc-ld NM="mips-openwrt-linux-uclibc-gcc-nm" CC="mips-openwrt-linux-uclibc-gcc" GCC="mips-openwrt-linux-uclibc-gcc" CXX="mips-openwrt-linux-uclibc-g++" RANLIB="mips-openwrt-linux-uclibc-gcc-ranlib" STRIP=mips-openwrt-linux-uclibc-strip OBJCOPY=mips-openwrt-linux-uclibc-objcopy OBJDUMP=mips-openwrt-linux-uclibc-objdump SIZE=mips-openwrt-linux-uclibc-size TARGET=Linux CFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=34kc -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -msoft-float -mips16 -minterlink-mips16" LDFLAGS="-L/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib -L/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2/staging_dir/target-mips_34kc_uClibc-0.9.33.2/lib -L/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/usr/lib -L/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib"
make[4]: Entering directory `/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2/build_dir/target-mips_34kc_uClibc-0.9.33.2/adb-e65b7ea8801145626504c724c28aedd0e5038a28/adb'
mips-openwrt-linux-uclibc-gcc -Os -pipe -mno-branch-likely -mips32r2 -mtune=34kc -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -msoft-float -mips16 -minterlink-mips16 -DADB_HOST=1 -DHAVE_FORKEXEC=1 -I. -I../include  -c -o usb_linux.o usb_linux.c
{standard input}: Assembler messages:
{standard input}:750: Error: unrecognized opcode `wsbh $2,$2'
{standard input}:783: Error: unrecognized opcode `wsbh $5,$5'
make[4]: *** [usb_linux.o] Error 1
make[4]: Leaving directory `/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2/build_dir/target-mips_34kc_uClibc-0.9.33.2/adb-e65b7ea8801145626504c724c28aedd0e5038a28/adb'
make[3]: *** [/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2/build_dir/target-mips_34kc_uClibc-0.9.33.2/adb-e65b7ea8801145626504c724c28aedd0e5038a28/.built] Error 2
make[3]: Leaving directory `/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2/package/adb'
make[2]: *** [package/adb/compile] Error 2
make[2]: Leaving directory `/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2'
make[1]: *** [/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2/staging_dir/target-mips_34kc_uClibc-0.9.33.2/stamp/.package_compile] Error 2
make[1]: Leaving directory `/root/openwrt/openwrt/bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.8-linaro_uClibc-0.9.33.2'
make: *** [world] Error 2

swiftgeek wrote:

https://gist.github.com/swiftgeek/05d22fd75329685a47fc
#This is my first package ever for openwrt

• Seems to work fine on x86 (tested under vbox)
• Breaks on ar71xx (ADB_TRACE=1 is useful here):
      USB: ID of device is recognized successfully but device is marked as offline
      TCP/IP: daemon nearly immediately fails
      It fails with and without debian-sid patches

It would be great if somebody would try this package on other platforms

Please note that the adb 4.2.2 is secure (i.e. a signature is requested from the handset to the adb host in order to activate the debug connection).
It is possible that adb 4.2.2 may be incompatible with older devices.
May need to try a pre-compiled version of adb 4.2.2 against the handset first.

See link below:
http://nelenkov.blogspot.com/2013/02/se … d-422.html

(Last edited by toinech on 3 Jan 2015, 01:36)

Sorry, this forum failed me once more with providing notifications -.-
@toinech, don't want to be rude but… #1 post already states that it works on x86 -.-
This is a mips-only issue
nobody has adb (not the target) running on top of mips machine, thus weird stuff happens during execution

and that avr thing is some badly executed sarcasm, right?

So since nobody actually read #1, nor offers gdb skills, i'm going to finally debug this with qemu sad

In case if somebody doesn't know this - mips/malta emulation works fully only since qemu 2.2.x (released 3 weeks ago)

@sunbytez I asked for help with debugging, so just wait till package gets fixed and pushed to git
——————
For now i'm trying to create some stable VM with writable rootfs - just like images for x86 - so i don't have reconfigure whole openwrt every time
——————
As there is seemingly no way to get anything writable on malta - i guesstimate that it could be endianness issue and i should rule it out with mipsel vm

(Last edited by swiftgeek on 6 Jan 2015, 21:59)

Sorry swiftgeek - I misread the intend of the post.

I was just looking for a solution to communicate with some Android app using through the ADB port
- not the full ADB host support. I posted in the wrong location.

swiftgeek wrote:

Sorry, this forum failed me once more with providing notifications -.-
@toinech, don't want to be rude but… #1 post already states that it works on x86 -.-
This is a mips-only issue
nobody has adb (not the target) running on top of mips machine, thus weird stuff happens during execution

and that avr thing is some badly executed sarcasm, right?

So since nobody actually read #1, nor offers gdb skills, i'm going to finally debug this with qemu sad

In case if somebody doesn't know this - mips/malta emulation works fully only since qemu 2.2.x (released 3 weeks ago)

@sunbytez I asked for help with debugging, so just wait till package gets fixed and pushed to git
——————
For now i'm trying to create some stable VM with writable rootfs - just like images for x86 - so i don't have reconfigure whole openwrt every time
——————
As there is seemingly no way to get anything writable on malta - i guesstimate that it could be endianness issue and i should rule it out with mipsel vm

Which will be possible soon™
Sooner if somebody will actually help (like with having nice mips images in http://downloads.openwrt.org/barrier_br … /malta/be/ that can actually be used - or if it is actually possible - document it on wiki)

Endianness issue confirmed - works fine on mipsel
Which in return slaps me with this commit https://android.googlesource.com/platfo … 8c98b1e967

So now the question is how to detect endianness of the target from package's makefile?

—————————————————————

And it indeed works… now i only need to solve how to detect endianness from the adbMakefile
If you want to compile - add line below in obvious place in adbMakefile

CPPFLAGS+= -DHAVE_BIG_ENDIAN=1

Binary for ar71xx/mipsbe http://h5ai.swiftgeek.net/OpenWRT/adb_a … ar71xx.ipk
—————————————————————
Final fix in package's Makefile:

ifeq ($(CONFIG_BIG_ENDIAN),y)
TARGET_CFLAGS+= -DHAVE_BIG_ENDIAN=1
beinfo: $(info *** Big endian detected, look for -DHAVE_BIG_ENDIAN=1 ***)
endif

https://gist.github.com/swiftgeek/05d22 … 6589f4bced

So now it can be tested, before i create pull request in github wink

—————————————————————
One issue still remains - compilation of 5.x series which fixes eg. https://code.google.com/p/android/issue … l?id=65857
• OpenWRT related:  usb_linux.c:173:46: error: 'O_CLOEXEC' undeclared (first use in this function)
EDIT: Compiles fine on ArchLinux, it may be related to µClibc
Adding line below to package's makefile fixes this part

TARGET_CFLAGS+= -D_GNU_SOURCE

• adbMakefile related: files have changed slightly so it also have to be updated (hopefully aur will have it updated it soon wink )
already fixed in adb-git package
• wtf related - every commit fails with something different since 5.0 preview
i haven't noticed missing $(CC)
• upstream related (lseek64), master compiles fine ( fdb3da5953b70dc87a05d28c31cb0dc06b8181aa )
• endianness strikes again -.-
https://android.googlesource.com/platfo … 81%5E!/#F0
Works great on commit before - 6fe92d1a3fb17545d82d020a3c995f32e6b71f9d
Even better than on 4.x

https://code.google.com/p/android/issue … l?id=93881
Star this issue if you wish to have future versions of adb without fork -.-

---
Last good commit, as described above: https://gist.github.com/swiftgeek/05d22 … 9324c62bff
Binary package for ar71xx: http://h5ai.swiftgeek.net/OpenWRT/adb_a … ar71xx.ipk

(Last edited by swiftgeek on 7 Jan 2015, 11:10)

I hoped for slightly more testing (more completely different platforms)
Also you can see what AOSP/google did

EDIT/BUMP: Found nice script that employs two ways (rndis_init() - cmdline, will break state of networking on android || tether-toggle() - a touchy way by inserting key events)
https://github.com/medvid/android-tethe … ter/tether

Touch way could be potentially used as a way to unlock device by unauthorized person so i wish there was a better way to do that (like some nice intent that could be used directly from adb)
Perhaps somebody with nicer android skills could write an app that would do the same thing from intent and push it to F-droid repository? Or Xposed module?

Also udev is an issue for devices with limited memory - is there an other way to achieve hotplug for usb

Without that resolved there is not much need for adb in repo (bloat) sad

EDIT2: http://stackoverflow.com/questions/2022 … e-terminal
While it doesn't work on all devices ( http://android.stackexchange.com/questi … 8775#98775 ) It at least contains all never devices (> 4.x)
So i should now write most of the service files for openwrt and udev rules and perhaps other hotplug ways
Config will have to contain options:
Toggle_way:
• rndis (like rndis_init). device-side script will need to be added to make it revert settings on device unplug
• touch - pointing mostly to other file with touch script
• modern - >=4.x devices , version detection is needed, preferably a future-proof solution that extracts method number from device. Version detection: adb shell getprop ro.build.version.release
blacklist: 0 - whitelist , 1 - blacklist
id_list: list of white/blacklisted IDs (adb devices)
wifi_toggle: 0/1 whether to toggle wifi on android when plugging in (This could be more complicated because of 1. hotplug 2. [Multi]WAN status. 2nd should be probably done by MultiWAN anyway, this would allow for powering down 3G/4G dongles when emergency connection is not needed)
polling: (in seconds) periodic checks when not using udev, especially if i wont find alternative hotplug detection method
TODO: compare lsusb/kernel + VID/PID lists and adb devices polling efficiency/memory usage

Gingerbread should be also possible somehow… sadly my device has such functionality broken ^^' but i can at least check if it toggles on cyanogenmod7.2
https://github.com/CyanogenMod/android_ … nager.aidl (I'm not sure which method should be used no idea if even available)

As for patching adb - there has to be a better way to have app compile properly on big and lil endian without crazy ifdefs, especially since performance is not an issue for us

EDIT 2015-05-22: Package should be pushed to packages.git net/ (like ssh/mosh) or utils/ (like minicom and openocd)
Even though hotplug2 was replaced by procd, same scripts for usb hotplug have to be used

EDIT 2015-06-20: There is some issue again with signed adb - when replugging, device thinks that host is unauthorized even though it has whitelisted fingerprint. Using adbkey(.pub) generated on PC might help

(Last edited by swiftgeek on 20 Jun 2015, 01:25)

Hi, In the same way can we compile adbd device daemon instead of adb? I am trying to do using same makefile but with source files of adbd daemon .c files.

Please let me know how can it be compiled.

Thanks,

Target daemon side on OpenWRT? You would need to write code for adb actually to make that happen. Also pretty sure it would require some kernel elements too

(Last edited by swiftgeek on 7 Jul 2015, 04:52)

yes, Target daemon adbd.
I need to port that adbd daemon on openwrt. So, Just changing this make file wont help right? I can use the same Makefile for compiling the files for adbd right? chnaging the SRCS and CPPFLAGS should make it compile?
Kernel chnages also required?

Thnaks,

Nice and thank you.

@chetancr9 take your any android device and see how adb works there (try enabling adb by hand)
And why using crappy adb while you could just use usbnet and ssh/dropbear? Android Debug Bridge is not written to be portable and upstream is hostile against portability (eg. they even removed existing mipsbe support)
If you wish to continue this discussion please move it to other topic as it is totally off-topic here.
I'm also available at freenode (use /query swiftgeek)

@mazilo if that's to my package state your platform/architecture, and perhaps device where it works (eg. mipsbe ar71xx) [edit your comment ofc]

@swiftgeek:

I am mostly using Marvell Kirkwood. In the coming months, I will be migrating the OXNAS (that is if I can get it to work) on some PogoPlug Pro. So, I am in a no rush situation.

FYI, I have not done anything else with adb and am awaiting it to be ported to OpenWRT.

@mazilo: Now i'm confused thanks to chetancr9
The adb part that lets you debug android phone from router (or from other machine but while having phone connected to router) works, just support for big endian was dropped after some commit (can't do anything about it upstream is hostile - i can only fork). But your platform is naidne elttiL so you don't care and you can use even the most recent git.

The reverse - using adb to debug OpenWRT is plain WTF and outside of the scope of this topic/packaging attempt - there are much simpler and more powerful ways to achieve debugging/shell via usb gadget than adb

(Last edited by swiftgeek on 7 Jul 2015, 21:32)

@swiftgeek Thx for the code , and i could make android 5.0.2.ipk,but if i change the sourcecode form 5.0.2 ot 5.1.1, i got this error

In file included from ../libzipfile/centraldir.c:6:0:
../include/utils/Compat.h:30:23: error: static declaration of 'lseek64' follows non-static declaration
static inline off64_t lseek64(int fd, off64_t offset, int whence) {
                       ^
In file included from ../include/utils/Compat.h:20:0,
                 from ../libzipfile/centraldir.c:6:
/home/eastwoodnet/barrier_breaker/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/include/unistd.h:312:18: note: previous declaration of 'lseek64' was here
extern __off64_t lseek64 (int __fd, __off64_t __offset, int __whence)
                  ^
make[4]: *** [centraldir.o] Error 1

https://code.google.com/p/android/issue … l?id=93881  <-- is about this issues ??

(Last edited by eastwoodnet on 28 Aug 2015, 09:57)

Probably not, anyway don't even try with big endian platform because of android devs being hostile.

thank you very much !

The discussion might have continued from here.