Using Android for industrial / RT applications

Using Android for industrial / RT applications
Pierre Ficheux ([email protected])
November 2014
Industrial Android
1
Introduction
●
●
●
●
●
Open Wide Ingénierie (OWI) is a french software service
company specialized in industrial / embedded software
Mostly using embedded Linux
I am a senior developer, Linux enthusiast, author, teacher
for several universities in France...and CTO of OWI
4 books about embedded Linux (Linux embarqué in french)
GNU Linux Magazine and Open Silicium writer
Industrial Android
2
Android vs GNU/Linux
●
●
●
●
Industrials projects currently switch from RTOS
(LynxOS, VxWorks, QNX, ...) to embedded GNU/Linux
Developping for (embedded) GNU/Linux is tricky
–
Heterogenous environment
–
Lots of different tools (the bazaar vs the cathedral)
–
C++ for Qt GUI
–
C for EFL GUI but no GUI builder :(
Nevertheless, Linux includes powerful build systems
such as Buildroot or Yocto/OpenEmbedded
Linux (+ Buildroot and Yocto) are REAL collaborative
projects
Industrial Android
3
Android vs GNU/Linux
●
●
●
●
●
Android is interesting for :
–
Java development → simple and portable
–
Low cost platforms
–
Nice GUI !
–
Marketing → “store”
Android is (partially) “open source”
Someday (today?) more Android platforms than Win$
PCs
Android / Google is a “must” for management people
because of cheap platforms
Could Android be a full GNU/Linux replacement for
industrial and embedded applications ?
Industrial Android
4
Android and industry
●
●
●
Android was designed for tablet and phone
Android needs adaptation for industrial application
–
Security
–
Hardware interface (only Wi-Fi, BT, USB?)
–
Porting if dedicated hardware (though lots of BSP for
SoC are available now)
Google is NOT an “open source company”
→ Android is not the killer open source OS for industry !
Industrial Android
5
Android, open source project ?
●
●
Android sourcecode is available with AOSP
–
Very few “official” platforms (Nexus, Pandaboard)
–
Very few technical documentation :(
Android is not a collaborative project
–
Design and development “behind de doors”
–
No contact with Google developers (Googlers)
–
Lots of proprietary components inside AOSP and lots of
AOSP “fork” projects
–
Google does not like GPL → replacement software
using Apache 2 license (Busybox → Toolbox)
Industrial Android
6
Licensing
●
●
Android includes lots of components
–
Linux kernel (GPL)
–
Google code (Apache 2) → no “derived work”, no
publication
–
External code (various licences, mostly non GPL)
–
Proprietary (binary drivers / HAL)
Most of “Google Play” apps are proprietary (just like
Apple AppStore...)
Industrial Android
7
Architecture (by Google)
Industrial Android
8
Android framework (blue)
●
●
●
●
Provides Java API for app developers
Uses JNI for low level access from Java app (Hardware
Abstraction Layer, HAL)
Use Binder instead of standard IPC, written by Google
from Open Binder (BeOS)
No hardware dependency, thanx to the JVM
Industrial Android
9
Libraries (green)
●
●
Google
–
Bionic, lightweight libC under BSD license, partially
POSIX → porting legacy software is tricky
–
Android “managers” : Surface Manager, Media
Framework, ...
External (external directory in AOSP) :
–
Webkit
–
OpenSSL
–
OpenGL/ES
–
…
Industrial Android
10
HAL
●
●
●
●
●
●
●
●
●
●
HAL is Android specific
Mostly designed because of licensing issues
Access to Linux driver (hardware) from Java
No direct access just like GNU/Linux → open, read,
write, ioctl, ...
Based on JNI (Java Native Interface) API
Each Android “service” includes
–
A system service (Java)
–
HAL definition (library) used by JNI
Hardware should provide a library (.so) to be added to
device directory (hardware definition in AOSP)
Could be proprietary as it's user space !
Kernel driver (GPL) is useless without HAL !
Examples: Lights, Wi-Fi, ...
Industrial Android
11
HAL in AOSP
AOSP directory
/frameworks/base/core/
/frameworks/base/services/java/
AOSP-provided
ASL
/frameworks/base/services/jni/
/hardware/libhardware/
/device/[MANUF.]/[DEVICE]
/sdk/emulator/
Manuf.-provided
Manuf. license
Noyau ou module
Manuf.-provided
GPL-license
© K. Yaghmour
Industrial Android
12
Linux kernel
●
●
●
●
●
●
Initially a “fork” of mainline Linux kernel
–
IPC → Binder
–
Power management
–
Tracing system (logcat)
–
Shared memory
–
...
Android drivers removed from mainline in 2009
Back on drivers/staging/android since 3.3...but all
Goggle stuff is in user space !
“Same” as mainline kernel on recent version (3.8 for BB
Black)
Only binary kernel provided in Google AOSP
Sourcecode available from a dedicated repository
Industrial Android
13
Android architecture (K. Yaghmour)
© K. Yaghmour
Industrial Android
14
AOSP “in a nutshell”
●
●
●
●
Lots of prerequisites for compiling AOSP
Powerful 64 bits system running Ubuntu or Mac OS X
Google provides repo (Python script) to manage more
than 100 Git repositories...
Based on manifest file (repositories index)
$ mkdir work && cd work
$ repo init -u https://android.googlesource.com/platform/manifest
[-b <branch>]
Select branch, such as android-4.3_r2
$ repo sync [-j N]
Synchro with repository, N jobs
●
Select target, compile and test
$ source build/envsetup.sh
$ lunch aosp_arm-eng
Loading variables
Target is Goldfish emulator, engineering version
$ make -j N
$ emulator [-show-kernel -shell] &
Industrial Android
15
AOSP “in a nutshell”
●
●
Directory is more than 30 Go after compiling (did you
say embedded??)
Binaries are only inside out directory (16 Go for JB)
$ ls -1 out/target/product
generic
Goldfish target (emulator)
Industrial Android
16
Porting AOSP
●
●
●
●
●
●
Very few platforms in official AOSP
Build system is not powerful (based on make) compared
with Buildroot or Yocto
Lots on undocumented variables
Hardware makers provide adapted versions (TI,
Freescale, SONY, x86, ...)
Check out BeagleBone Black example !
Some groups on the net and (only) 3 dedicated books
Industrial Android
17
AOSP for BeableBone Black
●
●
Based on AOSP but does not follow AOSP rules !
Get sourcecode (4.2.2 or 4.3)
$ mkdir rowboat-android
$ cd rowboat-android
$ repo init -u git://gitorious.org/rowboat/manifest.git -m rowboat-jbam335x.xml
$ repo sync -j <N>
●
Compile
$ make TARGET_PRODUCT=beagleboneblack OMAPES=4.x -j <N> droid
●
Build filesystems
$ make TARGET_PRODUCT=beagleboneblack OMAPES=4.x sdcard_build
●
Create Micro-SD
$ cd out/target/product/beagleboneblack/beagleboneblack
$ sudo LANG=C ./mkmmc-android.sh /dev/sdb
●
●
Needs some work to support local (CAPE) touchscreen
Only external HDMI support by default
Industrial Android
18
NDK
●
●
●
●
●
Most of Android apps need SDK (Java)
C/C++ needs NDK (Native Development Kit)
–
Legacy code (not supported)
–
HAL and kernel drivers (Linux compatible)
Based on specific Android.mk file
No official Autotools/CMake support
NDK includes cross-compilers, libraries, few JNI
examples (+ documentation/examples...)
Industrial Android
19
Using external toolchain
●
●
●
●
Lots of POSIX issues in NDK :-(
Android Linux kernel includes standard POSIX system
calls
One can use a “standard” cross-compiler
(CodeSourcery, Linaro, …) + install std libraries on
target
Framework integration issue → use local sockets ?
socket
Industrial Android
20
Android and realtime
●
●
●
●
●
●
Android is NOT designed for RT at all
About 20% of industrial projects needs hard realtime
No official support is planned by Google (or any other
company)
POSIX API (including POSIX/RT) is available in
Linux kernel
Linux RT needs “mainline” kernel but Android kernel is
“mainline” right now :-)
Testing RT should be possible
–
PREEMPT-RT (kernel patch)
–
Xenomai (co-kernel approach)
Industrial Android
21
PREEMPT-RT
●
●
●
●
●
●
●
●
Experimental branch for 2.6 et 3.x :
https://rt.wiki.kernel.org
Started by Ingo Molnar & Thomas Gleixner
Mostly used on x86 (based on TSC)
Available on ARM (11 or Cortex), Nios II, Microblaze
with less performances and some porting
Needs a mainline kernel but no official integration
(Linus Torvalds does not care about RT...)
Needs only one (big) patch
Same APIs as standard Linux (user & kernel)
Very close to hard realtime but a 15M LOC RT kernel !
Industrial Android
22
Linux with co-kernel
●
●
●
●
●
●
●
Sharing resources between Linux and another (RT)
kernel (looks like “partionning”)
Each kernel has its own scheduler but shares memory
space
Virtualizing interrupts with higher priority to RT events
Linux kernel is “idle task” of co-kernel
Close to “para virtualization” i.e. adapting kernel to an
hypervisor
Several project starting with RTLinux (1998, obsolete),
RTAI, Xenomai
Better than PREEMPT-RT for embedded and ARM
platform
Industrial Android
23
Initial RTLinux architecture
User space
Linux process
(data fetching)
Linux process (IHM)
Real time
FIFO
Real time task 3
application
Linux
modules
Linux kernel
Real time task 1
Module sched
Real time task 2
Module posixio
Linux interrupt handler
Software interrupt
Real time kernel: RTLinux
Hardware interrupt
Hardware – interrupts controller
Industrial Android
24
Xenomai
●
●
●
●
●
Xenomai is an RT sub-system of Linux kernel → “Realtime sub-system”
–
Programming RT task in user-space
–
Dedicated kernel API (RTDM) but close to Linux API
Includes “skins” for several famous RTOS API, such as
POSIX, VxWorks, VRTX, uITRON, ...
More complex to use than PREEMPT-RT but 5 to 10
times better regarding latency/jitter
Based on ADEOS micro-kernel
Licencing is GPL (kernel), LGPL (user space)
Industrial Android
25
General architecture
●
●
Xenomai use “hypervisor” (ADEOS) to share hardware
with Linux kernel
A process contains RT and standard (Linux) threads
Linux process
RT driver
RT API
RT kernel
“hypervisor”
Industrial Android
26
Xenomai on Android
●
●
●
●
●
●
PREEMPT-RT patch does not apply to BBB kernel (not
“mainline”) but works on Android-x86
Switch to Xenomai test only (PREEMPT-RT needs
some work)
Beaglebone Black (Cortex-A8, 1GHz) running Android
4.2.2
BBB 3.8 kernel with Xenomai 2.6.1
Just have to set Android drivers in kernel configuration
POSIX periodic task compiled with CodeSourcery
Industrial Android
27
Xenomai (or PREEMPT-RT) test
●
●
●
●
Starting a periodic task with latency utility
(cyclictest for PREEMPT-RT)
Heavy system load with stress, hackbench or “flood
ping” (lots of interrupts)
Jitter measurement
Text mode only (no framework integration by default)
Industrial Android
28
Periodic task, Linux based
Industrial Android
29
Same task, Xenomai based
Industrial Android
30
Android vs GNU/Linux
●
Android test (latency with 1 ms period)
RTH|----lat min|----lat avg|----lat max|-overrun|---msw|---lat best|--lat worst
●
RTD|
7.291|
9.499|
43.499|
0|
0|
1.749|
59.708
RTD|
7.041|
9.249|
30.249|
0|
0|
1.749|
59.708
RTD|
7.208|
9.166|
18.166|
0|
0|
1.749|
59.708
RTD|
7.208|
9.166|
23.999|
0|
0|
1.749|
59.708
RTD|
7.249|
9.166|
18.374|
0|
0|
1.749|
59.708
Same test with GNU/Linux
RTH|----lat min|----lat avg|----lat max|-overrun|---msw|---lat best|--lat worst
●
●
RTD|
7.166|
8.583|
18.666|
0|
0|
1.791|
29.166
RTD|
7.249|
8.666|
13.958|
0|
0|
1.791|
29.166
RTD|
2.333|
8.583|
18.041|
0|
0|
1.791|
29.166
RTD|
7.249|
8.624|
14.124|
0|
0|
1.791|
29.166
RTD|
7.249|
8.583|
13.958|
0|
0|
1.791|
29.166
GNU/Linux is (much) better than Android but has no
GUI (text mode distro made with Buildroot)
GUI is painful for RT, check out Xenomai FAQ
regarding X11!
Industrial Android
31
Xenomai framework integration
●
●
●
●
●
No RT support in standard framework
Android / RT communication is based on socket
Use Xenomai XDDP protocol for No-RT / RT domain
communication (setting task period)
Android framework was updated !
Android starting file init.rc updated
service signalRT /system/bin/generateSignalRT
class main
oneshot
service socketServer /system/bin/socketServer
class main
oneshot
Industrial Android
32
Android+Xenomai application
Industrial Android
33
AOSP integration
Industrial Android
34
Android SquareSignal app
Industrial Android
35
Picoscope measurement
Industrial Android
36
References
●
http://source.android.com
●
http://developer.android.com/tools/help/emulator.html
●
https://code.google.com/p/rowboat
●
http://www.ti.com/tool/androidsdk-sitara
●
http://www.opersys.com/training/embedded-android
●
http://free-electrons.com/training/android
●
http://www.cyanogenmod.org/
●
http://www.android-x86.org/
●
https://www.youtube.com/watch?v=LimC0XpeT0k
●
https://www.packtpub.com/application-development/instant-android-systems-development-how-instant
●
http://shop.oreilly.com/product/0636920021094.do
●
http://www.xenomai.org
●
http://rt.wiki.kernel.org
●
Article “Android temps réel” Open Silicium #8, august 2013 (Pierre FICHEUX, in french)
●
Internship report “Investigations Android temps réel”, august 2014 (Michelle LE GRAND, in french)
Industrial Android
37
Conclusions
●
●
●
●
●
Android is not designed for RT but “could” work with
Xenomai with less performances
Lots of industrial inputs about 1 year ago...
But very few “embedded Android” projects right now
–
Lack of documentation
–
Google hegemony
–
Hardware integration
Most of projects use (standard) Android device as
remote GUI
Android is still a very interesting product
Industrial Android
38
Questions ?
Industrial Android
39