Gentoo On Android

This project is about running Gentoo natively on Android devices.

I am going to develop libc support and root permission handling in Gentoo Prefix, and deploy the enhanced Gentoo Prefix in parallel to Android userland in mobile devices, such as smart phones and tablets. This will provide a full-featured native GNU userland to Android systems.

Provided libc is integrated into Gentoo Prefix seamlessly, cross-compiled bootstrapping of Gentoo Prefix will be investigated to ease the deployment process of Gentoo on Android.

Table of Contents

1 libc in Gentoo Prefix

Gentoo Prefix is a variant of Gentoo meta-distribution which installs under normal user privilege a full Gentoo in a directory offset of a Unix-like OS, such as HPUX, AIX, GNU/Linux, Interix, Mac OS X, Solaris, *BSD, and Cygwin.

Traditionally, Gentoo Prefix uses the kernel/libc and in some cases compiler/linker from the host OS. Problems arise in Linux/glibc based OS when the version of glibc is too old, like RHEL/CentOS 5 and many ancient GNU/Linux still in duty1, 2, 3. Therefore it has been a dream of the Gentoo Prefix community to have a bleeding edge libc to further reduce dependence on host while still being a Prefix (as opposed to a virtual machine). It is technically accessible as Debian multi-arch4 and patchelf from nixOS5 demonstrated the use of the ELF interp field to locate the dynamic linker.

Around late 2012, Ruud Koolen (redlizard) made a first attempt to have libc in Gentoo Prefix6, and successfully made a functional system7. It is, however, still in need of much work of maintenance designs to co-exist with the present rpath mechanism.

The present rpath mechanism is implemented with sys-devel/binutils-config in Gentoo Prefix, which includes an ld wrapper injecting LDFLAGS like "-rpath=${EPREFIX}/usr/lib". Though we could patch gcc headers to redefine the default standard run time linker location, the same ld-wrapper mechanism can be used to inject things as "–dynamic-linker=${EPREFIX}/lib/ld-linux.so.2". The latter solution will make switching between rpath and prefix-libc variants of Gentoo Prefix easier.

2 ARM keyword in Gentoo Prefix

There has been discussions in the Prefix team on how to treat Gentoo Prefix on ARM Linux.

The most straightforward way is to introduce a new keyword "arm-linux" like before. The problem is that we have too many keywords to look after in Prefix, and adding a new one will make things worse.

To save ourselves from too many keywords, we could interpret keyword "arm" as both Prefix and vanilla Gentoo. Being a new architecture, packages with "arm" keywords are recent and have a higher probability to be trivially Prefix ready. The problem is that there are corner cases, the keyword can become vague when a package can be used in vanilla Gentoo and not Prefix (though there is no such example yet).

Provided we seamlessly support using glibc from Prefix on Linux boxes, it is more favored to have "arm" representing both Prefix and vanilla: under the same glibc, a package is unlikely to break on Prefix but not vanilla or vice versa.

Similarly, a package with has keyword "amd64 x86 amd64-linux", will almost certainly be ready for "x86-linux". So we do have the possibility to reduce the keywords maintained by Prefix by digging out such extrapolation after Prefix begins to use its own libc.

3 Root privilege in Gentoo Prefix

One of the amazing features of Gentoo Prefix is not needing root privilege to use portage, the Gentoo package manager. However in some cases, the user does have root privilege and still want to install a Gentoo Prefix as normal user and give it root privilege when necessary, such as setting suid root to some tools8. At present it will result in failure as portage run as normal user will refuse to do anything requiring root.

We want to add such a feature to portage: call sudo/su before performing things requiring root, in such a way that this feature can be disabled by configuration or USE flags. Rooted Android will benefit from this feature via, for example, Superuser App9.

4 GNU on Android

Android is a Linux-based mobile operating system developed by Google. It features a Java engine Dalvik as the central. The purpose of Bionic, libc of Android, is to get the Java engine compiled out. Therefore Bionic is very thin and lacks many features expected in a GNU/Linux system. As a consequence, though Android has a Linux kernel, it is non-trivial to have a GNU environment along with it.

Mobile devices are getting more and more powerful. At the time of writing (March 2013), dual/quadro-core GHz-clocked ARM driven mobile devices are widely available in the market. To unleash the full potential, a complete GNU userland would be very useful and crucial to provide desktop level user experience, with laptop docks (Motorola Lapdock10, ASUS Transformer11) and/or desktop monitor via HDMI12.

Several attempts exist and are surveyed as followed.

  1. busybox. It uses statically linked busybox to provide main tools expected in a GNU environment13. It is straightforward to deploy and accessible as an App in Google Play14. But the features provided are limited.
  2. chrooted full distribution. We could install full a GNU/Linux distribution in a chroot environment, and even have a desktop environment within a VNC server. We could access the local VNC server with a VNC client from Android. It is well-received and also available as an App in Google Play15, 16. The drawback of this solution, however, is the overhead imposed by the chroot and VNC server. Furthermore, this approach needs root permission to the Android system.
  3. native full distribution. Because the Android system lies in the /system directory, top directories like /usr, /lib, /var, /etc required by a typical GNU/Linux distribution are available. We can install a full distribution to / in parallel to Android. This approach, for example, Motorola Webtop and Debian17, 18, is not yet wide spread yet, but it is at present the best solution we have. It needs root permission to operate.

Gentoo Prefix, if powered with its own glibc, will give another native solution here, and (surprise!) without the need of root permission. It is also clean in the sense that all the GNU programs are installed in a subdirectory.

It could be hard to bootstrap Gentoo Prefix on Android. One possible way is to install a native full distribution or a chrooted one and then bootstrap a Gentoo Prefix with libc from within. We could distribute precompiled Gentoo Prefix on Google Play for the general public.

5 Cross Bootstrapping Gentoo Prefix

While users would access Gentoo via Google Play easily, to attract more developer an easy way to get Gentoo Prefix for Android out is very helpful.

At present, Gentoo Prefix can only be bootstrapped on systems on which it will run. It would be hard for users to bootstrap Gentoo Prefix in environments lacking of compiler, linker, and featured libc, like Android.

It is possible, however, to install a native full distribution and then bootstrap a Gentoo Prefix with libc. It would be better if we could cross-compile out a Gentoo Prefix from faster servers.

At present, we can bootstrap a new Gentoo Prefix from an existing one by doing,

env PORTAGE_OVERRIDE_EPREFIX=/new/location/ emerge -e @system

But cross compiling Gentoo Prefix or bootstrap by cross-compilation is still a dream.

redlizard's gentoo-prefix-libc has cross bootstraping in mind, with the hope of running uclibc-based Gentoo Prefix on Android. The details, however, still call for much effort.

6 Cross Toolchain in Gentoo Prefix

In order to cross bootstrap Gentoo Prefix, we should have a set of cross toolchains at the first place.

In vanilla Gentoo, a nice tool, crossdev19, is readily available. Cross development naturally includes the concept of "prefix" almost by definition, which is usually named "sysroot" and handled by the variable ${ROOT} in Gentoo. This "prefix", however, is easily confused with ${EPREFIX} used in Gentoo Prefix. (See? I am saying prefix too many times already.) Therefore it is not trivial to port crossdev and glibc to Gentoo Prefix in a consistent manner.

The author has tried to make cross toolchains manually20. It would be very nice if crossdev could produce cross toolchains in Gentoo Prefix by a single command as

$ crossdev -t armv7a-hardfloat-linux-gnueabi

In the mean time, there is still confusion around cross compiling and Gentoo Prefix21, 22. A firm policy is needed to carry cooperative effort on.

7 Deliverables

The tasks in this project can be categorized into two types.

  1. Work involving intensive coding

    They are tagged as coding. They require concentration and relatively easy to predict timetime.

  2. Discussion of policy, clearification of concepts with a wide audience in Gentoo community

    They are tagged as policy. They call for consensus with cooreponding teams. Discussion time is hard to control, and should be done in parallel to coding as soon as possible.

Dates in the following items represent deadlines.

7.1 (coding) libc of Gentoo Prefix 2013-06-30 Sun

  1. glibc ported to Gentoo Prefix 2013-06-07 Fri
  2. Merge redlizard's work of libc into mainstream Gentoo Prefix, and work with Gentoo Prefix community for anything left. 2013-06-21 Fri
  3. Give user an option to choose and switch between host libc and Prefix libc on Linux. Write easy documentation to guide the switching process. 2013-06-30 Sun

7.2 (policy) Optimize keywords in Prefix

  1. new keyword scheme after libc inclusion (depends on libc coding)
  2. new prefix profiles for version 13.0 (no dependence)

7.3 (policy) Root privilege in Gentoo Prefix

  1. Patch of portage for the feature of being able to escalate itself to root privilege. (no dependence)

7.4 (coding) Gentoo Prefix on Android 2013-07-28 Sun

  1. Distribute a native Gentoo installer (requiring root) as App on Google Play. 2013-07-14 Sun
  2. Distribute a Gentoo Prefix installer (not needing root) as App on Google Play. 2013-07-28 Sun

Both being able to use HDMI output of Android device to run Xorg. For Gentoo Prefix, this feature will require root privilege.

7.5 (coding) Cross Bootstrapping Gentoo Prefix 2013-09-15 Sun

  1. Solution to bootstrap Gentoo Prefix for Android on a amd64 server. 2013-08-20 Tue
  2. Gentoo Prefix for Android with uclibc. 2013-09-15 Sun

7.6 (policy) Cross Toolchain on Gentoo Prefix

  1. Discuss with toolchain, portage and prefix team and file a GLEP pinning a policy for support cross development under Gentoo Prefix, mostly for clearifying different kinds of "prefix".
  2. a working crossdev in Gentoo Prefix

8 Biography

I am born in China and now studying particle physics in Japan as a graduate student. I like tweaking electronic devices and computer programs. Right now I am really fond of travelling around the world and learning different languages.

As a GNU/Linux user for 9 years since 2003, I use Debian for desktop and Gentoo Prefix for servers. I live in Emacs and stumpwm. I started to love Gentoo Prefix in 2010 and joined gentoo in Dec. 201123.

8.1 experiences

2005translated Debian Sarge Release Note into Simplified Chinese14
2007–2009system administrator for student associations and dormitory in Tsinghua University, China
2009intern in Lava Inc at Beijing, video streaming
2011short intern at Intel China
2011–nowConsultant for Tsinghua University student group of campus network administrators
2012Google Summer of Code: Daemons in Gentoo Prefix with OpenRC24

8.2 toys at hand

  1. mips architecture
    • Planex MZK-W04NU running OpenWrt
    • TP-Link WR1043ND running OpenWrt
  2. arm architecture
    • Buffalo LS-VL running stock system with Gentoo Prefix
    • Motorola Droid Razr (XT910) with lapdock, Gentoo Prefix and Debian Squeeze running arm hardfloat ABI
    • ASUS Transformer, native Debian Squeeze arm hardfloat ABI
  3. powerpc architecture
    • Xilinx Virtex II PRO evaluation board, minimal Debian25
    • SONY PlayStation 3, jailbroken (planning to deploy Gentoo by otherOS under Rebug26)
    • Microsoft Xbox 360
  4. microblaze architecture
    • Xilinx Spartan 3 Starter Kit, minimal busybox

8.3 activities involved in Gentoo

I will just give a few links to my activities

9 Reference

  1. GenTop2 http://forum.xda-developers.com/showthread.php?t=1617684
  2. linux-on-android: Port linux distributions to android-based phones http://code.google.com/p/linux-on-android/

Footnotes:

1 problems with bootstrapping in Gentoo-prefix http://thread.gmane.org/gmane.linux.gentoo.alt/6459

2 emerge gcc 4.4.x/4.5.x fails on CentOS 5.5 http://thread.gmane.org/gmane.linux.gentoo.alt/6110

3 >=sys-devel/gcc-4.3 fails with USE="-vanilla fortran" with some glibc's due to fortify patch https://bugs.gentoo.org/289757

4 Multiarch http://wiki.debian.org/Multiarch

5 PatchELF http://nixos.org/patchelf.html

6 An expermental version of gentoo-prefix that uses a local libc https://github.com/redlizard/gentoo-prefix-libc

7 glibc with prefix http://article.gmane.org/gmane.linux.gentoo.alt/6543

8 prefix-portage as root http://thread.gmane.org/gmane.linux.gentoo.alt/3405

9 superuser https://play.google.com/store/apps/details?id=com.noshufou.android.su

10 Android Smart Phone Lapdock http://www.motorola.com/us/consumers/Motorola-Lapdock-100/73945,en_US,pd.html

11 Transformer Pad Infinity http://eee.asus.com/en/transformer-infinity/features

12 Webtop Achieved On Atrix Via HDMI Without A Dock http://www.xda-developers.com/android/webtop-achieved-on-atrix-via-hdmi-without-a-dock/

13 A Busybox binary that is ready to be integrated into your Android project https://github.com/Gnurou/busybox-android

14 BusyBox https://play.google.com/store/apps/details?id=stericson.busybox

15 Linux Deploy https://play.google.com/store/apps/details?id=ru.meefik.linuxdeploy

16 Linux on Android http://linuxonandroid.org/

17 Debian Kit for Android http://sven-ola.dyndns.org/repo/debian-kit-en.html

18 Debian Kit for Android https://play.google.com/store/apps/details?id=org.dyndns.sven_ola.debian_kit

19 Gentoo Cross Development Guide http://www.gentoo.org/proj/en/base/embedded/cross-development.xml

20 Cross Toolchain on Gentoo Prefix http://www.awa.tohoku.ac.jp/~benda/projects/gpCross.html

21 prefix-portage-2.2.01.19981 fails with EPREFIX='' emerge https://bugs.gentoo.org/395633

22 meaning of EROOT http://article.gmane.org/gmane.linux.gentoo.devel/83525

23 New Developer: Xu "heroxbd" Benda http://archives.gentoo.org/gentoo-project/msg_c752a3d5119130dd715ebc587536e00c.xml

24 Daemons in Gentoo Prefix with OpenRC http://www.awa.tohoku.ac.jp/~benda/projects/openrc.html

25 Virtex2p Linux http://www.awa.tohoku.ac.jp/~benda/projects/virtex2p.html

26 Codename: REBUG http://rebug.me

Date: 2013-04-30T13:55+0900

Author: heroxbd

Org version 7.9.2 with Emacs version 24

Validate XHTML 1.0