27
1 Reusing your existing software on Android Tetsuyuki Kobayashi 2010.9.3 2011.8.5 updated

Reusing your existing software on Android

Embed Size (px)

DESCRIPTION

Reusing your existing software on Android 1. Runnig the existing software on Android 1.1 Rebuilding by Android tool chain 1.2 Running the binary as is 2. Running Android on your existing Linux environment I show you 'Android on Ubuntu server'

Citation preview

Page 1: Reusing your existing software on Android

1

Reusing your existing software on

Android

Tetsuyuki Kobayashi

2010.9.32011.8.5 updated

Page 2: Reusing your existing software on Android

2

Who am I? 20+ years involved in embedded systems

10 years in real time OS, such as iTRON 10 years in embedded Java Virtual Machine Now GCC, Linux, QEMU, Android, …

Blogs http://d.hatena.ne.jp/embedded/ (Personal) http://blog.kmckk.com/ (Corporate) http://kobablog.wordpress.com/(English)

Twitter @tetsu_koba

new

Page 3: Reusing your existing software on Android

3

Today's topic

Introduction Running your software on

Android No rebuild, binary as is Rebuild

Running Android on your existing linux environment

Page 4: Reusing your existing software on Android

4

Audience

Already using Linux in your project Have interest in Android Thinking how to migrate to

Android

Page 5: Reusing your existing software on Android

5

Why Android?

Clear separation between system and application

Download-able application 3rd party, community Easy upgrade, bug fix

Web service using HTML5 browser core

And more ...

Page 6: Reusing your existing software on Android

6

Why reuse?

Don't discard all your existing software resource.

But don't think all your software resource is reusable.

What is your strength? Select wisely

Page 7: Reusing your existing software on Android

7

Let's try prototyping

Anyway, port Android on your board.

I show you some techniques for a quick hack in this session.

Page 8: Reusing your existing software on Android

8

Things to consider

Execution overhead Memory/Storage usage Easiness to follow version up of

Android

Page 9: Reusing your existing software on Android

9

3 topics Running existing binary on

Android Rebuilding for Android Running Android on your Linux

Page 10: Reusing your existing software on Android

Running existing binary on Android

Just copy If the same ABI (EABI on ARM)

You have to copy all files you need

'ldd' to identify dynamic library dependency

Fortunately, Android does not have /lib, /bin, /usr/*. Don't worry about conflict

Page 11: Reusing your existing software on Android

11

Example : bash

user@arm-lucid:~$ ldd /bin/bashlibncurses.so.5 => /lib/libncurses.so.5 (0x40006000)libdl.so.2 => /lib/libdl.so.2 (0x40039000)libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x40045000)libc.so.6 => /lib/libc.so.6 (0x40057000)/lib/ld-linux.so.3 (0x2a000000)

user@arm-lucid:~$

Copy these files and not change file path.Or make symblic link as looks like.

See Alsohttp://blog.kmckk.com/archives/2936886.html

Page 12: Reusing your existing software on Android

12

Running existing binary on Android

Pros Easy!

Good for experiment Cons

Duplicate libraries increase memory/storage usage

May not work for all cases Not good for product.

Not applicable for libraries to link with DalvikVM

Page 13: Reusing your existing software on Android

13

Rebuilding for Android

Making Android.mk Build your project as a part of the whole Android system

Using configure script Build independently Use NDK for compiler, system library and include headers

Page 14: Reusing your existing software on Android

14

Making Androd.mk

Get whole android source tree by 'repo sync'

Copy simple project and use it as template Remove unused files and add your files Modify Android.mk Build your project as a part of Android

Page 15: Reusing your existing software on Android

15

Using configure script Set environment variables before run

configure CC, CFLAGS, LDFLAGS

Options for gcc -mandroid, --sysroot=$SYSROOT

See this page for detail http://blog.kmckk.com/archives/2918745.html http://blog.kmckk.com/archives/3867590.html

Page 16: Reusing your existing software on Android

16

Caveats

System lib doesn't support C++ exceptions and RTTI. Static link GNU libstdc++.

Multi byte char support is minimal. No system V IPC. IPv6 seems not yet supported. GCC TLS extension (__thread) doesn't work.

Page 17: Reusing your existing software on Android

Rebuilding for Android

Pros The best for Memory/Storage usage Only solution for libraries to link with DalvikVM

Cons Hard to rebuild because ... Bionic(Android libc) Caveats Some header files missing

Page 18: Reusing your existing software on Android

18

Running Android on your Linux

Running whole Android system framework on your existing Linux environment.

I show you a quick hack to do this. Of cource, there is some limitation.

Page 19: Reusing your existing software on Android

19

Running Android on your Linux

Android-patched Linux kernelAndroid-patched Linux kernel

AndroidAndroid

Your existing Linux user land

Page 20: Reusing your existing software on Android

20

How to run Android on Ubuntu

1.Port Android to your board2.Run ARM Ubuntu on your board

with Android-patched Linux kernel3.Put all Android files into /android

on Ubuntu4.Invoke 'sudo chroot /android /init'

on Ubuntu

Page 21: Reusing your existing software on Android

21

Trouble shooting Some processes caused SEGV

In my case, vold and netd Patch is in my blog

http://blog.kmckk.com/archives/3520227.html

Page 22: Reusing your existing software on Android

22

Android lunched successfully

You can browse internet by Android browser. You can use Eclipse to install and debug Java

applications. SMP kernel works fine on KZM-CA9-01

board(Quad-Core Cortex-A9) and KZM-A9-Dual (Dual-Core Cortex-A9)

Page 23: Reusing your existing software on Android

23

Result of ps commanduser@arm-lucid:~$ ps ax PID TTY STAT TIME COMMAND 1 ? SLs 0:01 /sbin/init 2 ? S< 0:00 [kthreadd] 3 ? S< 0:00 [migration/0] 4 ? S< 0:00 [ksoftirqd/0] 5 ? S< 0:00 [watchdog/0] 6 ? S< 0:00 [migration/1] 7 ? S< 0:00 [ksoftirqd/1] 8 ? S< 0:00 [watchdog/1] 9 ? S< 0:00 [migration/2] 10 ? S< 0:00 [ksoftirqd/2] 11 ? S< 0:00 [watchdog/2] 12 ? S< 0:00 [migration/3] 13 ? S< 0:00 [ksoftirqd/3] 14 ? S< 0:00 [watchdog/3] 15 ? S< 0:00 [events/0] 16 ? S< 0:00 [events/1] 17 ? S< 0:00 [events/2] 18 ? S< 0:00 [events/3] 19 ? S< 0:00 [work_on_cpu/0] 20 ? S< 0:00 [work_on_cpu/1] 21 ? S< 0:00 [work_on_cpu/2] 22 ? S< 0:00 [work_on_cpu/3] 23 ? S< 0:00 [khelper] 24 ? S< 0:00 [suspend] 25 ? S< 0:00 [kblockd/0] 26 ? S< 0:00 [kblockd/1] 27 ? S< 0:00 [kblockd/2] 28 ? S< 0:00 [kblockd/3] 29 ? S< 0:00 [ksuspend_usbd] 30 ? S< 0:00 [khubd] 31 ? S< 0:00 [kmmcd] 32 ? S 0:00 [pdflush] 33 ? S 0:00 [pdflush] 34 ? S< 0:00 [kswapd0] 35 ? S< 0:00 [aio/0] 36 ? S< 0:00 [aio/1] 37 ? S< 0:00 [aio/2] 38 ? S< 0:00 [aio/3] 39 ? S< 0:00 [nfsiod] 40 ? S< 0:01 [rpciod/0] 41 ? S< 0:00 [rpciod/1] 42 ? S< 0:00 [rpciod/2] 43 ? S< 0:00 [rpciod/3] 2297 ? SL 0:00 upstart-udev-bridge --daemon 2300 ? SLl 0:00 rsyslogd -c4 2301 ? S<Ls 0:00 udevd --daemon 2378 ? SLs 0:00 /usr/sbin/sshd

2417 tty4 SLs+ 0:00 /sbin/getty -8 38400 tty4 2418 tty5 SLs+ 0:00 /sbin/getty -8 38400 tty5 2421 tty2 SLs+ 0:00 /sbin/getty -8 38400 tty2 2422 tty3 SLs+ 0:00 /sbin/getty -8 38400 tty3 2424 tty6 SLs+ 0:00 /sbin/getty -8 38400 tty6 2428 ? SLs 0:00 cron 2454 tty1 SLs+ 0:00 /sbin/getty -8 38400 tty1 2470 ? SLs 0:00 sshd: user [priv] 2483 ? SL 0:00 sshd: user@pts/0 2484 pts/0 SLs 0:00 -bash 2497 ? SLs 0:00 sshd: user [priv] 2511 ? SL 0:00 sshd: user@pts/1 2512 pts/1 SLs 0:00 -bash 2520 pts/0 SL+ 0:00 /init 2551 ? S<L 0:00 udevd --daemon 2552 ? S<L 0:00 udevd --daemon 2596 ? SLs 0:00 /system/bin/sh 2597 pts/0 SL 0:00 /system/bin/servicemanager 2598 pts/0 SL 0:00 /system/bin/debuggerd 2599 pts/0 SLl 0:00 /system/bin/rild 2600 pts/0 SL 0:05 zygote /bin/app_process -Xzygote /system/bin --zygote --start-s 2601 pts/0 SLl 0:00 /system/bin/mediaserver 2602 pts/0 SL 0:00 /system/bin/dbus-daemon --system --nofork 2603 pts/0 SL 0:00 /system/bin/installd 2604 pts/0 SL 0:00 /system/bin/keystore /data/misc/keystore 2605 pts/0 SLl 0:00 /sbin/adbd 2613 pts/0 SLl 0:08 system_server 2668 pts/0 SLl 0:00 com.android.inputmethod.latin 2671 pts/0 SLl 0:00 com.android.phone 2672 pts/0 SLl 0:01 com.android.launcher 2673 pts/0 SLl 0:00 com.android.settings 2701 pts/0 SLl 0:00 android.process.acore 2728 pts/0 SLl 0:00 com.android.bluetooth 2735 pts/0 SLl 0:00 com.android.mms 2744 pts/0 SLl 0:00 android.process.media 2764 pts/0 SLl 0:00 com.android.providers.calendar 2776 pts/0 SLl 0:00 com.android.deskclock 2786 pts/0 SLl 0:00 com.android.email 2796 pts/0 SLl 0:00 com.android.quicksearchbox 2807 pts/0 SLl 0:00 com.android.protips 2814 pts/0 SLl 0:00 com.android.music 2821 pts/0 SLl 0:00 com.cooliris.media 2831 pts/1 RL+ 0:00 ps axuser@arm-lucid:~$

Page 24: Reusing your existing software on Android

24

Result of ps commanduser@arm-lucid:~$ ps ax PID TTY STAT TIME COMMAND 1 ? SLs 0:01 /sbin/init 2 ? S< 0:00 [kthreadd] 3 ? S< 0:00 [migration/0] 4 ? S< 0:00 [ksoftirqd/0] 5 ? S< 0:00 [watchdog/0] 6 ? S< 0:00 [migration/1] 7 ? S< 0:00 [ksoftirqd/1] 8 ? S< 0:00 [watchdog/1] 9 ? S< 0:00 [migration/2] 10 ? S< 0:00 [ksoftirqd/2] 11 ? S< 0:00 [watchdog/2] 12 ? S< 0:00 [migration/3] 13 ? S< 0:00 [ksoftirqd/3] 14 ? S< 0:00 [watchdog/3] 15 ? S< 0:00 [events/0] 16 ? S< 0:00 [events/1] 17 ? S< 0:00 [events/2] 18 ? S< 0:00 [events/3] 19 ? S< 0:00 [work_on_cpu/0] 20 ? S< 0:00 [work_on_cpu/1] 21 ? S< 0:00 [work_on_cpu/2] 22 ? S< 0:00 [work_on_cpu/3] 23 ? S< 0:00 [khelper] 24 ? S< 0:00 [suspend] 25 ? S< 0:00 [kblockd/0] 26 ? S< 0:00 [kblockd/1] 27 ? S< 0:00 [kblockd/2] 28 ? S< 0:00 [kblockd/3] 29 ? S< 0:00 [ksuspend_usbd] 30 ? S< 0:00 [khubd] 31 ? S< 0:00 [kmmcd] 32 ? S 0:00 [pdflush] 33 ? S 0:00 [pdflush] 34 ? S< 0:00 [kswapd0] 35 ? S< 0:00 [aio/0] 36 ? S< 0:00 [aio/1] 37 ? S< 0:00 [aio/2] 38 ? S< 0:00 [aio/3] 39 ? S< 0:00 [nfsiod] 40 ? S< 0:01 [rpciod/0] 41 ? S< 0:00 [rpciod/1] 42 ? S< 0:00 [rpciod/2] 43 ? S< 0:00 [rpciod/3] 2297 ? SL 0:00 upstart-udev-bridge --daemon 2300 ? SLl 0:00 rsyslogd -c4 2301 ? S<Ls 0:00 udevd --daemon 2378 ? SLs 0:00 /usr/sbin/sshd

2417 tty4 SLs+ 0:00 /sbin/getty -8 38400 tty4 2418 tty5 SLs+ 0:00 /sbin/getty -8 38400 tty5 2421 tty2 SLs+ 0:00 /sbin/getty -8 38400 tty2 2422 tty3 SLs+ 0:00 /sbin/getty -8 38400 tty3 2424 tty6 SLs+ 0:00 /sbin/getty -8 38400 tty6 2428 ? SLs 0:00 cron 2454 tty1 SLs+ 0:00 /sbin/getty -8 38400 tty1 2470 ? SLs 0:00 sshd: user [priv] 2483 ? SL 0:00 sshd: user@pts/0 2484 pts/0 SLs 0:00 -bash 2497 ? SLs 0:00 sshd: user [priv] 2511 ? SL 0:00 sshd: user@pts/1 2512 pts/1 SLs 0:00 -bash 2520 pts/0 SL+ 0:00 /init 2551 ? S<L 0:00 udevd --daemon 2552 ? S<L 0:00 udevd --daemon 2596 ? SLs 0:00 /system/bin/sh 2597 pts/0 SL 0:00 /system/bin/servicemanager 2598 pts/0 SL 0:00 /system/bin/debuggerd 2599 pts/0 SLl 0:00 /system/bin/rild 2600 pts/0 SL 0:05 zygote /bin/app_process -Xzygote /system/bin --zygote --start-s 2601 pts/0 SLl 0:00 /system/bin/mediaserver 2602 pts/0 SL 0:00 /system/bin/dbus-daemon --system --nofork 2603 pts/0 SL 0:00 /system/bin/installd 2604 pts/0 SL 0:00 /system/bin/keystore /data/misc/keystore 2605 pts/0 SLl 0:00 /sbin/adbd 2613 pts/0 SLl 0:08 system_server 2668 pts/0 SLl 0:00 com.android.inputmethod.latin 2671 pts/0 SLl 0:00 com.android.phone 2672 pts/0 SLl 0:01 com.android.launcher 2673 pts/0 SLl 0:00 com.android.settings 2701 pts/0 SLl 0:00 android.process.acore 2728 pts/0 SLl 0:00 com.android.bluetooth 2735 pts/0 SLl 0:00 com.android.mms 2744 pts/0 SLl 0:00 android.process.media 2764 pts/0 SLl 0:00 com.android.providers.calendar 2776 pts/0 SLl 0:00 com.android.deskclock 2786 pts/0 SLl 0:00 com.android.email 2796 pts/0 SLl 0:00 com.android.quicksearchbox 2807 pts/0 SLl 0:00 com.android.protips 2814 pts/0 SLl 0:00 com.android.music 2821 pts/0 SLl 0:00 com.cooliris.media 2831 pts/1 RL+ 0:00 ps axuser@arm-lucid:~$

Processes of Android

Init of Ubuntu

Init of Android

Page 25: Reusing your existing software on Android

25

Summary of this hack

Use Android patched kernel Nothing to modify in Ubuntu Screen(framebuffer device) and

key & touch input are used only from Android

Very easy. Try it!

Page 26: Reusing your existing software on Android

26

Next step How manage I/O devices?

Frame buffer Layered frame buffer and set transparency /dev/fb0 for Android, /dev/fb1 for Ubuntu

How communicate between Ubuntu & Android? At least, socket is available. Ashmem for shared memory? Binder?

Page 27: Reusing your existing software on Android

27

Q & A

Thank you for listening!Any comments to blogs are welcome.

@tetsu_koba