os-android: Add support to android platform, built by ndk-r10
RFC PATCH 1/1 os-android: Add support to android platform, built by ndk-r10
From: Houcheng <[email protected]>
This patch is to build qemu in android ndk tool-chain, and has been tested in both x86_64 and x86 android platform with hardware virtualization enabled. This patch is composed of three part:
- configure scripts for android
- OS dependent code for android
- kernel headers for android
The configure scripts add cross-compile options for android, define compile flags and link flags and call android specific pkg-config. A pseudo pkg-config script is added to report correct compile flags for android system.
The OS dependent code for android that implement functions missing in bionic C, including:
- getdtablesize(): call getrlimit() instead.
- sigtimewait(): call __rt_sigtimewait() instead.
- a_ptsname(): call pstname_r() instead.
- lockf(): not see this feature in android, directly return -1.
- shm_open(): not see this feature in android, directly return -1.
The kernel headers for android include two kernel header missing in android: scsi/sg.h and sys/io.h.
How to build android version
----------------------------
1. download the ndk toolchain r10, build the following libraries and install in your toolchain sysroot:
libiconv-1.14
gettext-0.19
libffi-3.0.12
glib-2.34.3
libpng-1.2.52
pixman-0.302. configure the qemu and build:
% export SYSROOT="/opt/android-toolchain64/sysroot"
% CFLAGS=" --sysroot=$SYSROOT -I$SYSROOT/usr/include -I$SYSROOT/usr/include/pixman-1/" \
./configure --prefix="${SYSROOT}/usr" \
--cross-prefix=x86_64-linux-android- \
--enable-kvm --enable-trace-backend=nop --disable-fdt --target-list=x86_64-softmmu \
--disable-spice --disable-vhost-net --disable-libiscsi --audio-drv-list="" --disable-gtk \
--disable-gnutls --disable-libnfs --disable-glusterfs --disable-libssh2 --disable-seccomp \
--disable-usb-redir --disable-libusb
% make -j4
Or, configure qemu to static link version:
% export SYSROOT="/opt/android-toolchain64/sysroot"
% CFLAGS=" --sysroot=$SYSROOT -I$SYSROOT/usr/include -I$SYSROOT/usr/include/pixman-1/" \
./configure --prefix="${SYSROOT}/usr" \
--cross-prefix=x86_64-linux-android- \
--enable-kvm --enable-trace-backend=nop --disable-fdt --target-list=x86_64-softmmu \
--disable-spice --disable-vhost-net --disable-libiscsi --audio-drv-list="" --disable-gtk \
--disable-gnutls --disable-libnfs --disable-glusterfs --disable-libssh2 --disable-seccomp \
--disable-usb-redir --disable-libusb --static
% make -j4--- configure | 30 ++++- include/android/scsi/sg.h | 307 +++++++++++++++++++++++++++++++++++++++++++ include/qemu/osdep.h | 4 + include/sysemu/os-android.h | 35 +++++ kvm-all.c | 3 + scripts/android-pkg-config | 28 ++++ tests/Makefile | 2 + util/osdep.c | 53 ++++++++ util/qemu-openpty.c | 10 +- 9 files changed, 467 insertions(+), 5 deletions(-) create mode 100644 include/android/scsi/sg.h create mode 100644 include/android/sys/io.h create mode 100644 include/sysemu/os-android.h create mode 100755 scripts/android-pkg-config
configure +27 -3
@@ -566,7 +566,6 @@ fi # host *BSD for user mode HOST_VARIANT_DIR="" - case $targetos in CYGWIN*) mingw32="yes"
@@ -692,9 +691,23 @@ Haiku) vhost_net="yes" vhost_scsi="yes" QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES" + case $cross_prefix in + *android*) + android="yes" + guest_agent="no" + QEMU_INCLUDES="-I\$(SRC_PATH)/include/android $QEMU_INCLUDES" + ;; + *) + ;; + esac ;; esac +if [ "$android" = "yes" ] ; then + QEMU_CFLAGS="-DANDROID $QEMU_CFLAGS" + LIBS="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc $LIBS" + libs_qga="-lglib-2.0 -lgthread-2.0 -lz -lpixman-1 -lintl -liconv -lc" +fi if [ "$bsd" = "yes" ] ; then if [ "$darwin" != "yes" ] ; then bsd_user="yes"
@@ -1736,7 +1749,14 @@ fi # pkg-config probe if ! has "$pkg_config_exe"; then - error_exit "pkg-config binary '$pkg_config_exe' not found" + case $cross_prefix in + *android*) + pkg_config_exe=scripts/android-pkg-config + ;; + *) + error_exit "pkg-config binary '$pkg_config_exe' not found" + ;; + esac fi ##########################################
@@ -3764,7 +3784,7 @@ elif compile_prog "" "$pthread_lib -lrt" ; then fi if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \ - "$aix" != "yes" -a "$haiku" != "yes" ; then + "$aix" != "yes" -a "$haiku" != "yes" -a "$android" != "yes" ; then libs_softmmu="-lutil $libs_softmmu" fi
@@ -4709,6 +4729,10 @@ if test "$linux" = "yes" ; then echo "CONFIG_LINUX=y" >> $config_host_mak fi +if test "$android" = "yes" ; then + echo "CONFIG_ANDROID=y" >> $config_host_mak +fi + if test "$darwin" = "yes" ; then echo "CONFIG_DARWIN=y" >> $config_host_mak fi
include/android/scsi/sg.h new file +307 -0
307 lines not on this page · raw message
include/android/sys/io.h new file +0 -0
include/qemu/osdep.h +4 -0
@@ -59,6 +59,10 @@#define WEXITSTATUS (x) (x)#endif +#ifdef ANDROID +#include "sysemu/os-android.h" +#endif +#ifdef _WIN32#include "sysemu/os-win32.h" #endif
include/sysemu/os-android.h new file +35 -0
@@ -0,0 +1,35 @@ +#ifndef QEMU_OS_ANDROID_H +#define QEMU_OS_ANDROID_H + +#include <sys/statvfs.h> + +/* +* For include the basename prototyping in android. +*/ +#include <libgen.h> + +extern int __rt_sigtimedwait (const sigset_t *uthese,siginfo_t *uinfo, \ +const struct timespec *uts,size_t sigsetsize); + +int getdtablesize (void ); +int lockf (int fd,int cmd,off_t len); +int sigtimedwait (const sigset_t *set,siginfo_t *info, \ +const struct timespec *ts); +int shm_open (const char *name,int oflag,mode_t mode); +char *a_ptsname (int fd); + +#define F_TLOCK 0 +#define IOV_MAX 256 +#define __SID ('S' << 8) + +#define I_NREAD (__SID | 1)/* Counts the number of data bytes in the data +block in the first message. */ +#define I_PUSH (__SID | 2)/* Push STREAMS module onto top of the current +STREAM, just below the STREAM head. */ +#define I_POP (__SID | 3)/* Remove STREAMS module from just below the +STREAM head. */ +#define I_LOOK (__SID | 4)/* Retrieve the name of the module just below +the STREAM head and place it in a character +string. */ + +#endif
kvm-all.c +3 -0
@@ -45,6 +45,9 @@#endif /* KVM uses PAGE_SIZE in its definition of COALESCED_MMIO_MAX */ +#ifdef ANDROID +#undef PAGE_SIZE +#endif #define PAGE_SIZE TARGET_PAGE_SIZE//#define DEBUG_KVM
scripts/android-pkg-config new file +28 -0
@@ -0,0 +1,28 @@ +#!/bin/bash +echo $@ >> check.log +for arg in $@; do + case $arg in + --cflags) + cflags=yes + ;; + --libs) + libs=yes + ;; + *) + pkg_name=$arg + ;; + esac +done + + +case $pkg_name in + gthread-2.0) + if test "$libs" = "yes" ; then + echo "" + fi + if test "$cflags" = "yes" ; then + echo -I$SYSROOT/usr/include/glib-2.0 -I$SYSROOT/usr/lib/glib-2.0/include/ + echo -I$SYSROOT/usr/include/glib-2.0 -I$SYSROOT/usr/lib/glib-2.0/include/ >> check.log + fi + ;; +esac
tests/Makefile +2 -0
@@ -418,8 +418,10 @@ tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a libqemustub. tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(block-obj-y) libqemuutil.a libqemustub.a ifeq ($(CONFIG_POSIX),y) +ifneq ($(CONFIG_ANDROID),y) LIBS += -lutil endif +endif # QTest rules
util/osdep.c +53 -0
56 lines not on this page · raw message
util/qemu-openpty.c +8 -2
@@ -51,7 +51,12 @@# include <termios.h> #endif -#ifdef __sun__ +#if defined(__sun__) || defined(ANDROID ) + +#ifdef ANDROID +#define ptsname (a) a_ptsname(a) +#endif +/* Once Solaris has openpty(), this is going to be removed. */ static int openpty (int *amaster,int *aslave,char *name,struct termios *termp,struct winsize *winp)
@@ -93,7 +98,8 @@ err:close (mfd);return -1 ; } - +#endif +#ifdef __sun__static void cfmakeraw (struct termios *termios_p) { termios_p->c_iflag &=
Signature · 1 line
1.7.9.5