Using gpsd (or parts thereof) on Android

Skip to first unread message

Michael von Glasow

Mar 8, 2011, 3:43:06 PM3/8/11
Hello list,

While working on yet another GPS timestamp bug (see ticket #139 for
details), I also looked into the gpsd code and documentation.

I found a newsgroup post in which someone asked about the possibilities
of porting gpsd to Android, but nothing particular seems to have come
out of it yet. And frankly, I don't much like the idea of running a TCP
listener (gpsd) on a smart phone which happily returns my coordinates to
anyone who asks: Unless extra security is in place, anyone from the
Internet might just connect to the gpsd on my phone and locate me within
a few meters.

Looking deeper, I came across the documentation for the gpsd service
library (libgspd) at [1]. It's the interface which gpsd uses internally
to talk to the various GPSes, and its interface looks functionally
similar to the one exposed by gps_freerunner.c - initialization,
activation, deactivation, polling and handling returned data.

With that, we might be able to use a fork of gpsd for the Android GPS
interface. gps_freerunner.c would be rewritten into a simple translation
layer, which would pass all calls to libgpsd and return data it gets
from there. No TCP daemon on top of that - we would just bypass that
layer. (Anyone who really wants to run a full-blown gpsd could still do
that on top of the same client library).

- this approach would be portable across many Android devices - other
Android projects could use the exact same code, which would increase the
developer base of that code
- gpsd has a mature code base, and any GPS hardware issues we encounter
may already be solved there (chances are the Openmoko guys came across
it before we did)
- if we ever port the code to a future GTAxx generation using a
different GPS, in the best case it means zero effort (if the GPS is
already supported by GPSD); in the worst case (unsupported GPS) we can
still work together with Openmoko (same library, same hardware) rather
than duplicating efforts
- maybe (not sure about this one, though) this would work even with
Bluetooth GPS devices - transparently, apps wouldn't see a difference

- I have no idea if anyone has ever compiled gpsd for Android. Despite
being built on top of a Linux kernel, Android is not a full-blown Linux
system - some libraries may be missing and the kernel has some
modifications in it. All of this may or may not have repercussions on gpsd.

Honestly, though - my work on #139 is at a point at which just a few
routine steps are missing, so for this time, unless I encounter some
unforeseen obstacles and/or additional bugs, I'll carry on with the code
we have and keep this as an idea in case I need to touch the code again.
Input is still welcome - has anyone ever tried to get gpsd components to
run on Android? Successfully?



Michael von Glasow

Mar 8, 2011, 5:58:17 PM3/8/11
Update: I came across the obstacle sooner than I thought - the code to
reconfigure the GPS to speak both NMEA and UBX turns out to be more
complex than I thought it would be. So I'm seriously looking into
porting the gpsd service library now and input is now even more welcome.

> [1]

Mar 10, 2011, 5:47:18 PM3/10/11
to android-on-freerunner
Came across the first problem...

I got the sources for the 2.95 release (the current git revision seems
to have a bug that causes build to fail under some conditions,
reproducible with native build). Since converting from autotools to an
Android-style makefile is nontrivial, I found a way on the net to
build for Android using the usual configure/make business.

I excluded some features which I don't need for my purposes - mostly
because they were throwing errors, like using some data types which
were unavailable. Commands I use:

export ANDROID_ROOT=$HOME/android-on-freerunner

export PATH=$PATH:$ANDROID_ROOT/prebuilt/linux-x86/toolchain/arm-

./configure --disable-libgpsmm --disable-libQgpsmm --disable-ipv6 --
disable-oldstyle --disable-ntpshm --disable-pps --disable-itrax --
disable-rtcm104v2 --disable-rtcm104v3 --host=arm-eabi CC=arm-eabi-gcc
arm/usr/include/" CFLAGS="-nostdlib -march=armv4t" LDFLAGS="-Wl,-rpath-
usr/lib/ -L$HOME/tools/android-ndk-r4b/build/platforms/android-3/arch-
arm/usr/lib/" LIBS="-lc "

Now, build fails during a component on which I badly depend. The error
comes from the linker and complains about the "tcdrain" function not
being available:

libtool: link: arm-eabi-gcc -nostdlib -march=armv4t -Wall -Wcast-align
-Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -
Wpointer-arith -Wreturn-type -D_GNU_SOURCE -Wl,-rpath-link=/home/
lib/ -o gpsctl gpsctl.o -L/home/michael/tools/android-ndk-r4b/build/
platforms/android-3/arch-arm/usr/lib/ ./.libs/libgpsd.a /home/michael/
src/gpsd-release-2.95/.libs/libgps.a ./.libs/libgps.a -lm -lc
warning: cannot find entry symbol _start; defaulting to 00009a20
gpsctl.o: In function `main':
gpsctl.c:(.text+0x115c): undefined reference to `tcdrain'
gpsctl.c:(.text+0x11c4): undefined reference to `tcdrain'
gpsctl.c:(.text+0x1adc): undefined reference to `tcdrain'
./.libs/libgpsd.a(serial.o): In function `gpsd_write':
serial.c:(.text+0x1020): undefined reference to `tcdrain'
./.libs/libgpsd.a(serial.o): In function `gpsd_close':
serial.c:(.text+0x128c): undefined reference to `tcdrain'
./.libs/libgpsd.a(drivers.o):drivers.c:(.text+0xa5c): more undefined
references to `tcdrain' follow
./.libs/libgpsd.a(driver_oncore.o): In function `oncore_msg_navsol':
driver_oncore.c:(.text+0x240): undefined reference to `timegm'
./.libs/libgpsd.a(driver_sirf.o): In function `sirf_write':
driver_sirf.c:(.text+0x174): undefined reference to `tcdrain'
./.libs/libgpsd.a(driver_superstar2.o): In function
driver_superstar2.c:(.text+0x300): undefined reference to `timegm'
./.libs/libgpsd.a(driver_superstar2.o): In function
driver_superstar2.c:(.text+0x1354): undefined reference to `timegm'
./.libs/libgpsd.a(driver_ubx.o): In function `ubx_write':
driver_ubx.c:(.text+0x24bc): undefined reference to `tcdrain'
collect2: ld returned 1 exit status

Looking in bionic/libc/include/termios.h, I find a bunch of tc*
functions but not tcdrain.

1. Apparently I'm including the wrong headers - which may or may not
be a problem, but it's the reason why the compile goes through cleanly
but the linker barfs at the missing function.
2. The code uses the tcdrain function, which is available in libc but
not in bionic.

Anyone have an idea on how I can resolve these two issues?


Carlo Lobrano

Feb 12, 2015, 6:10:14 AM2/12/15
Hi Michael,

I am facing the same issue now (tcdrain symbol is missing). I found out that static function declared in bionic (tcdrain is among them) are not visible in compilation.

Have you solved this problem?

Thanks in advance,

Feb 13, 2015, 5:51:16 PM2/13/15
Hi Carlo,

I haven't looked into it any further as I have since moved away from the Freerunner. My subsequent phones had a proprietary GPS driver stack, and at least one of them has a GPS chip which speaks only a proprietary protocol and thus is unlikely to ever be supported by GPSD. Sorry I can't help you much with this one...


Michael Trimarchi

Mar 2, 2015, 10:02:49 AM3/2/15


Implement using ioctl



You received this message because you are subscribed to the Google Groups "android-on-freerunner" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Carlo Lobrano

Mar 4, 2015, 6:00:16 AM3/4/15
Hi Michael,

yes you're right. I have come to the same solution you proposed.

#define tcdrain(fd) ioctl(fd, TCSBRK, 1)



To unsubscribe from this group and stop receiving emails from it, send an email to

Christopher Friedt

Mar 4, 2015, 6:29:44 AM3/4/15

Just use an internal tcdrain within your own program / library.


Sent from my Android


You received this message because you are subscribed to the Google Groups "android-on-freerunner" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
Reply all
Reply to author
0 new messages