Re: [Qemu-devel] [RFC PATCH v4] os-android: Add support to android platform

2015-10-06 Thread Houcheng Lin
Hi,

There are 7 sources still call basename() directly and block/vvfat.c
define its own static basename() function. Please see the grep below:

➜  qemu git:(patch-v4) ✗ grep  "basename(" **/*.c  | grep -v get_basename
fsdev/virtfs-proxy-helper.c:basename(prog));
hw/vfio/pci.c:group_name = basename(iommu_group_path);
hw/vfio/platform.c:group_name = basename(iommu_group_path);
linux-user/elfload.c:base_filename = strdup(basename(filename));
qemu-io.c:progname = basename(argv[0]);
qemu-nbd.c:snprintf(sockpath, 128, SOCKET_PATH, basename(device));
qga/commands-posix.c:driver = g_strdup(basename(buf));
qga/commands-posix.c:fs->name = g_strdup(basename(syspath));

➜  qemu git:(patch-v4) ✗ grep get_basename **/*.c
block/vvfat.c:static const char* get_basename(const char* path)
block/vvfat.c: basename2 = get_basename(path);
block/vvfat.c:basename = get_basename(mapping->path);
block/vvfat.c: const char* basename = get_basename(mapping->path);
block/vvfat.c: const char* basename = get_basename(mapping->path);
block/vvfat.c: const char* basename2 = get_basename(path);
block/vvfat.c: - strlen(get_basename(commit->path)) - 1;
linux-user/elfload.c:base_filename =
g_path_get_basename(ts->bprm->filename);

Directly change all of them to g_path_get_basename ?

2015-10-06 21:22 GMT+08:00 Paolo Bonzini <pbonz...@redhat.com>:
>
>
> On 06/10/2015 14:13, Eric Blake wrote:
>>
>> If you are already writing code to be ported to both Unixy and
>> windows systems, you are better off rolling your own alternative to
>> basename (or better, using something else that has already rolled a
>> portable version for you - while I know gnulib does that, we aren't
>> using gnulib; but I assume glib has something along those lines
>> even though I haven't looked for it).
>
> Yes, there is g_path_get_basename (and g_path_get_dirname).  Added to
> http://wiki.qemu.org/BiteSizedTasks#API_conversion.
>
> Paolo



-- 
Best regards,
Houcheng Lin
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH v3] os-android: Add support to android platform

2015-10-02 Thread Houcheng Lin
2015-09-28 19:40 GMT+08:00 Paolo Bonzini <pbonz...@redhat.com>:
>
>
> On 24/09/2015 15:21, Houcheng Lin wrote:
>> +if [ "$android" = "yes" ] ; then
>> +  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
>
> This change should not be necessary.
>
>> +#define getdtablesize qemu_getdtablesize
>
> Please instead replace all occurrences of getdtablesize with
> qemu_getdtablesize.
>
>>
>> +#ifdef CONFIG_ANDROID
>> +#include "sysemu/os-android.h"
>> +#endif
>> +
>
> Please replace this with
>
> #include 
>
> #ifndef IOV_MAX
> #define IOV_MAX 1024
> #endif
>
> and get rid of os-android.h.
>
>>
>> +#if defined(CONFIG_ANDROID)
>> +char pty_buf[PATH_MAX];
>> +#define ptsname(fd) pty_buf
>> +#endif
>>  const char *slave;
>>  int mfd = -1, sfd = -1;
>>
>> @@ -67,17 +72,21 @@ static int openpty(int *amaster, int *aslave, char *name,
>>
>>  if (grantpt(mfd) == -1 || unlockpt(mfd) == -1)
>>  goto err;
>> -
>> +#if defined(CONFIG_ANDROID)
>> +if (ptsname_r(mfd, pty_buf, PATH_MAX) < 0)
>> +goto err;
>> +#endif
>>  if ((slave = ptsname(mfd)) == NULL)
>>  goto err;
>>
>
>
> Better:
>
> #if defined(CONFIG_ANDROID)
> char slave[PATH_MAX];
> #else
> const char *slave;
> #endif
>
> ...
>
> #if defined(CONFIG_ANDROID)
> if (ptsname_r(mfd, slave, PATH_MAX) < 0)
> goto err;
> #else
> if ((slave = ptsname(mfd)) == NULL)
> goto err;
> #endif

Hi Paolo,
Okay and I will send the patch with these modifications soon. Thanks!

-- 
Best regards,
Houcheng Lin
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC PATCH v4] os-android: Add support to android platform

2015-10-02 Thread Houcheng Lin
Hi,

The v4 patch uses qemu_getdtablesize(), remove os-android.h and
use a local buffer when calling ptsname_r(). This patch is based
on version: 007e620a7576e4ce2ea6955541e87d8ae8ed32ae.

---

Building QEMU on android reqiures android NDK r10 cross-compilation
toolchain with following changes:

- install qemu dependent libraries
- upgrade bionic libc
- add mssing includes, scsi/sg.h, in toolchain
- make a symbolic link x86_64-linux-android-pkg-config that links
  to host's pkg-config.

Then, configure and build static linked qemu by commands:
  $ export SYSROOT="/opt/android-toolchain64/sysroot"
  $ PKG_CONFIG_LIBDIR=/opt/android-toolchain64/sysroot/usr/lib/pkgconfig \
./configure \
--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 \
--disable-guest-agent --static
  $ make -j4

For dynamic build, you can skip the "static" option during configure, copy
dependent so files into android and add "." into LD_LIBRARY_PATH.

How to prepare your cross-compilation toolcahin
---

1. Download NDK r10, install toolchain from NDK and 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.30

2. Download AOSP and apply this patch I made to support posix lockf()
https://android-review.googlesource.com/#/c/172150/

3. Build bionic C and update your toolchain's libc.a and libc.so.

4. Copy kernel header file, scsi/sg.h into toolchain's 
sysroot/usr/includes/scsi/

5. Update these header files in your toolchain to prevent compilation warning,
   includes:
unistd.h for lockf() and related define
sys/uio.h for pread() and pwrite()
signal.h for sigtimedwait()

Signed-off-by: Houcheng Lin <houch...@gmail.com>
---
 configure  | 14 --
 default-configs/pci.mak|  2 +-
 hw/i386/kvm/pci-assign.c   |  1 -
 hw/xenpv/xen_domainbuild.c |  2 +-
 include/qemu/osdep.h   | 10 ++
 kvm-all.c  |  4 
 slirp/misc.c   |  2 +-
 tests/Makefile |  2 ++
 util/oslib-posix.c | 16 
 util/qemu-openpty.c| 21 -
 10 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/configure b/configure
index d7c24cd..cda88c1 100755
--- a/configure
+++ b/configure
@@ -567,7 +567,6 @@ fi
 
 # host *BSD for user mode
 HOST_VARIANT_DIR=""
-
 case $targetos in
 CYGWIN*)
   mingw32="yes"
@@ -693,6 +692,13 @@ 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"
+;;
+*)
+;;
+  esac
 ;;
 esac
 
@@ -3791,7 +3797,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
 
@@ -4737,6 +4743,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
diff --git a/default-configs/pci.mak b/default-configs/pci.mak
index 7e10903..e76dd41 100644
--- a/default-configs/pci.mak
+++ b/default-configs/pci.mak
@@ -35,5 +35,5 @@ CONFIG_SDHCI=y
 CONFIG_EDU=y
 CONFIG_VGA=y
 CONFIG_VGA_PCI=y
-CONFIG_IVSHMEM=$(CONFIG_KVM)
+CONFIG_IVSHMEM=$(call land,$(call lnot,$(CONFIG_ANDROID)),$(CONFIG_KVM))
 CONFIG_ROCKER=y
diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index b1beaa6..44beee3 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -22,7 +22,6 @@
  */
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/hw/xenpv/xen_domainbuild.c b/hw/xenpv/xen_domainbuild.c
index c0ab753..480ee87 100644
--- a/hw/xenpv/xen_domainbuild.c
+++ b/hw/xenpv/xen_domainbuild.c
@@ -170,7 +170,7 @@ static int xen_domain

[RFC PATCH v3] os-android: Add support to android platform

2015-09-24 Thread Houcheng Lin
Hi,

The v3 patch fix ident error and add error checking on
ptsname_r() function. This patch is based on version:
007e620a7576e4ce2ea6955541e87d8ae8ed32ae.

---

Building QEMU on android reqiures android NDK r10 cross-compilation
toolchain with following changes:

- install qemu dependent libraries
- upgrade bionic libc
- add mssing includes, scsi/sg.h, in toolchain
- make a symbolic link x86_64-linux-android-pkg-config that links
  to host's pkg-config.

Then, configure and build static linked qemu by commands:
  $ export SYSROOT="/opt/android-toolchain64/sysroot"
  $ PKG_CONFIG_LIBDIR=/opt/android-toolchain64/sysroot/usr/lib/pkgconfig \
./configure \
--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 \
--disable-guest-agent --static
  $ make -j4

For dynamic build, you can skip the "static" option during configure, copy
dependent so files into android and add "." into LD_LIBRARY_PATH.

How to prepare your cross-compilation toolcahin
---

1. Download NDK r10, install toolchain from NDK and 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.30

2. Download AOSP and apply this patch I made to support posix lockf()
https://android-review.googlesource.com/#/c/172150/

3. Build bionic C and update your toolchain's libc.a and libc.so.

4. Copy kernel header file, scsi/sg.h into toolchain's 
sysroot/usr/includes/scsi/

5. Update these header files in your toolchain to prevent compilation warning,
   includes:
unistd.h for lockf() and related define
sys/uio.h for pread() and pwrite()
signal.h for sigtimedwait()

Signed-off-by: Houcheng Lin <houch...@gmail.com>
---
 configure   | 18 --
 default-configs/pci.mak |  2 +-
 hw/i386/kvm/pci-assign.c|  1 -
 include/qemu/osdep.h|  7 +++
 include/sysemu/os-android.h | 12 
 kvm-all.c   |  4 
 tests/Makefile  |  2 ++
 util/oslib-posix.c  | 12 
 util/qemu-openpty.c | 20 +++-
 9 files changed, 69 insertions(+), 9 deletions(-)
 create mode 100644 include/sysemu/os-android.h

diff --git a/configure b/configure
index d7c24cd..12e3402 100755
--- a/configure
+++ b/configure
@@ -567,7 +567,6 @@ fi
 
 # host *BSD for user mode
 HOST_VARIANT_DIR=""
-
 case $targetos in
 CYGWIN*)
   mingw32="yes"
@@ -693,9 +692,20 @@ 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"
+;;
+*)
+;;
+  esac
 ;;
 esac
 
+if [ "$android" = "yes" ] ; then
+  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"
@@ -3791,7 +3801,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
 
@@ -4737,6 +4747,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
diff --git a/default-configs/pci.mak b/default-configs/pci.mak
index 7e10903..e76dd41 100644
--- a/default-configs/pci.mak
+++ b/default-configs/pci.mak
@@ -35,5 +35,5 @@ CONFIG_SDHCI=y
 CONFIG_EDU=y
 CONFIG_VGA=y
 CONFIG_VGA_PCI=y
-CONFIG_IVSHMEM=$(CONFIG_KVM)
+CONFIG_IVSHMEM=$(call land,$(call lnot,$(CONFIG_ANDROID)),$(CONFIG_KVM))
 CONFIG_ROCKER=y
diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index b1beaa6..44beee3 100644

[RFC PATCH v2] os-android: Add support to android platform

2015-09-20 Thread Houcheng Lin
This is patch to build qemu for android platfrom. The building
uses NDK r10 cross-compilation toolchain with following
changes:

- install qemu dependent libraries
- upgrade bionic libc
- add mssing includes, scsi/sg.h, in toolchain
- make a symbolic link x86_64-linux-android-pkg-config that links
  to host's pkg-config.

Then, configure and build static linked qemu by commands:
  $ export SYSROOT="/opt/android-toolchain64/sysroot"
  $ PKG_CONFIG_LIBDIR=/opt/android-toolchain64/sysroot/usr/lib/pkgconfig \
./configure \
--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 \
--disable-guest-agent --static
  $ make -j4

For dynamic build, you can skip the "static" option during configure, copy
dependent so files into android and add "." into LD_LIBRARY_PATH.

How to prepare your cross-compilation toolcahin
---

1. Download NDK r10, install toolchain from NDK and 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.30

2. Download AOSP and apply this patch I made to support posix lockf()
https://android-review.googlesource.com/#/c/172150/

3. Build bionic C and update your toolchain's libc.a and libc.so.

4. Copy kernel header file, scsi/sg.h into toolchain's 
sysroot/usr/includes/scsi/

5. Update these header files in your toolchain to prevent compilation warning,
   includes:
unistd.h for lockf() and related define
sys/uio.h for pread() and pwrite()
signal.h for sigtimedwait()

Signed-off-by: Houcheng Lin <houch...@gmail.com>
---
 configure   | 18 --
 default-configs/pci.mak |  2 +-
 hw/i386/kvm/pci-assign.c|  1 -
 include/qemu/osdep.h|  7 +++
 include/sysemu/os-android.h | 12 
 kvm-all.c   |  4 
 tests/Makefile  |  2 ++
 util/oslib-posix.c  | 12 
 util/qemu-openpty.c | 19 ++-
 9 files changed, 68 insertions(+), 9 deletions(-)
 create mode 100644 include/sysemu/os-android.h

diff --git a/configure b/configure
index d7c24cd..12e3402 100755
--- a/configure
+++ b/configure
@@ -567,7 +567,6 @@ fi
 
 # host *BSD for user mode
 HOST_VARIANT_DIR=""
-
 case $targetos in
 CYGWIN*)
   mingw32="yes"
@@ -693,9 +692,20 @@ 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"
+;;
+*)
+;;
+  esac
 ;;
 esac
 
+if [ "$android" = "yes" ] ; then
+  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"
@@ -3791,7 +3801,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
 
@@ -4737,6 +4747,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
diff --git a/default-configs/pci.mak b/default-configs/pci.mak
index 7e10903..e76dd41 100644
--- a/default-configs/pci.mak
+++ b/default-configs/pci.mak
@@ -35,5 +35,5 @@ CONFIG_SDHCI=y
 CONFIG_EDU=y
 CONFIG_VGA=y
 CONFIG_VGA_PCI=y
-CONFIG_IVSHMEM=$(CONFIG_KVM)
+CONFIG_IVSHMEM=$(call land,$(call lnot,$(CONFIG_ANDROID)),$(CONFIG_KVM))
 CONFIG_ROCKER=y
diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index b1beaa6..44beee3 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -22,7 +22,6 @@
  */
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/include/qemu/osdep.h b/include/qemu/osd

Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10

2015-09-16 Thread Houcheng Lin
2015-09-16 16:09 GMT+08:00 Paolo Bonzini <pbonz...@redhat.com>:
>
>
>>
>> I'll modify the bionic C library to support these functions and feedback
>> to google's AOSP project. But the android kernel does not support shmem,
>
> It doesn't support tmpfs?  /dev/shm is just a tmpfs.
>
> Paolo

Oh, you are right. The android have shmget, shmat, shmdt functions in
their libc. The POSIX shm_open can built on top of these. I'll fix my
libc to support posix share memory functions.

-- 
Best regards,
Houcheng Lin
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10

2015-09-16 Thread Houcheng Lin
2015-09-16 17:38 GMT+08:00 Paolo Bonzini <pbonz...@redhat.com>:
>
> Actually it's even simpler.  shm_open is basically just
>
> char *s;
> int fd;
>
> asprintf(, "/dev/shm/%s", name);
> fd = open(s, name | O_CLOEXEC, mode);
> free(s);
> return fd;
>
> plus some error checking.  Do Android systems have /dev/shm?
>
> Paolo

It's simple, thanks.
The android have no /dev/shm. Though we can mknod it but need root prividlege to
do it.


-- 
Best regards,
Houcheng Lin
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10

2015-09-15 Thread Houcheng Lin
Hi Paolo,

(Please ignore the previous mail that did not include "qemu-devel")

Thanks for your review and suggestions. I'll fix this patch
accordingly and please see my replies below.

best regards,
Houcheng Lin

2015-09-15 17:41 GMT+08:00 Paolo Bonzini <pbonz...@redhat.com>:

> This is okay and can be done unconditionally (introduce a new
> qemu_getdtablesize function that is defined in util/oslib-posix.c).

Will fix it.
>
>
>> - sigtimewait(): call __rt_sigtimewait() instead.
>> - lockf(): not see this feature in android, directly return -1.
>> - shm_open(): not see this feature in android, directly return -1.
>
> This is not okay.  Please fix your libc instead.

I'll modify the bionic C library to support these functions and feedback
to google's AOSP project. But the android kernel does not support shmem,
so I will prevent compile the ivshmem.c when in android config. The config
for ivshmem in pci.mak will be:

CONFIG_IVSHMEM=$(call land, $(call lnot,$(CONFIG_ANDROID)),$(CONFIG_KVM))

> For sys/io.h, we can just remove the inclusion.  It is not necessary.
>
> scsi/sg.h should be exported by the Linux kernel, so that we can use
> scripts/update-linux-headers.sh to copy it from QEMU.  I've sent a Linux
> kernel patch and CCed you.

It's better to put headers on kernel user headers. Thanks.

>
> You should instead disable the guest agent on your configure command line.
>

Okay.

>
> If you have CONFIG_ANDROID, you do not need -DANDROID.
>

Okay.

>> +  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"
>
> This should not be necessary, QEMU uses pkg-config.
>
>> +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
>
> Neither should this.  Your cross-compilation environment is not
> correctly set up if you do not have a pkg-config executable.  If you
> want to use a wrapper, you can specify it with the PKG_CONFIG
> environment variable.  But it need not be maintained in the QEMU
> repository, because QEMU assumes a complete cross-compilation environment.

I'll use wrapper in next release and specify with environment variable.
Later, I may generate pkg-config data file while building library and install
it into cross-compilation environment.

>
>> + ;;
>> +*)
>> + 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
>> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
>> index ab3c876..1ba22be 100644
>> --- a/include/qemu/osdep.h
>> +++ b/include/qemu/osdep.h
>> @@ -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
>> diff --git a/include/sysemu/os-android.h b/include/sysemu/os-android.h
>> new file mode 100644
>> index 000..7f73777
>> --- /dev/null
>> +++ b/include/sysemu/os-android.h
>> @@ -0,0 +1,35 @@
>> +#ifndef QEMU_OS_ANDROID_H
>> +#define QEMU_OS_ANDROID_H
>> +
>> +#include 
>> +
>>

Re: [RFC PATCH] os-android: Add support to android platform, built by ndk-r10

2015-09-15 Thread Houcheng Lin
Hi Paolo,

Thanks for your review and suggestions. I'll fix this patch accordingly.
Please also see my replies below.

best regards,
Houcheng Lin

2015-09-15 17:41 GMT+08:00 Paolo Bonzini <pbonz...@redhat.com>:
>
> This is okay and can be done unconditionally (introduce a new
> qemu_getdtablesize function that is defined in util/oslib-posix.c).

Will fix it.
>
>
>> - sigtimewait(): call __rt_sigtimewait() instead.
>> - lockf(): not see this feature in android, directly return -1.
>> - shm_open(): not see this feature in android, directly return -1.
>
> This is not okay.  Please fix your libc instead.

I'll modify the bionic C library to support these functions and feedback
to google's AOSP project. But the android kernel does not support shmem,
so I will prevent compile the ivshmem.c when in android config. The config
for ivshmem in pci.mak will be:

CONFIG_IVSHMEM=$(call land, $(call lnot,$(CONFIG_ANDROID)),$(CONFIG_KVM))

> For sys/io.h, we can just remove the inclusion.  It is not necessary.
>
> scsi/sg.h should be exported by the Linux kernel, so that we can use
> scripts/update-linux-headers.sh to copy it from QEMU.  I've sent a Linux
> kernel patch and CCed you.

It's better to put headers on kernel user headers. Thanks.

>
> You should instead disable the guest agent on your configure command line.
>

Okay.

>
> If you have CONFIG_ANDROID, you do not need -DANDROID.
>

Okay.

>> +  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"
>
> This should not be necessary, QEMU uses pkg-config.
>
>> +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
>
> Neither should this.  Your cross-compilation environment is not
> correctly set up if you do not have a pkg-config executable.  If you
> want to use a wrapper, you can specify it with the PKG_CONFIG
> environment variable.  But it need not be maintained in the QEMU
> repository, because QEMU assumes a complete cross-compilation environment.

I'll use wrapper in next release and specify with environment variable.
Later, I may generate pkg-config data file while building library and install
it into cross-compilation environment.

>
>> + ;;
>> +*)
>> + 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
>> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
>> index ab3c876..1ba22be 100644
>> --- a/include/qemu/osdep.h
>> +++ b/include/qemu/osdep.h
>> @@ -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
>> diff --git a/include/sysemu/os-android.h b/include/sysemu/os-android.h
>> new file mode 100644
>> index 000..7f73777
>> --- /dev/null
>> +++ b/include/sysemu/os-android.h
>> @@ -0,0 +1,35 @@
>> +#ifndef QEMU_OS_ANDROID_H
>> +#define QEMU_OS_ANDROID_H
>> +
>> +#include 
>> +
>> +/*
>> + * For include the basename prototyping in android.
>

[RFC PATCH] os-android: Add support to android platform, built by ndk-r10

2015-09-14 Thread Houcheng Lin
From: Houcheng 

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.30

2. 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

Signed-off-by: Houcheng 
---
 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

diff --git a/configure b/configure
index 5c06663..3ff6ffa 100755
--- a/configure
+++ b/configure
@@ -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 

[RFC PATCH] os-android: Add support to android platform, built by ndk-r10

2015-09-14 Thread Houcheng Lin
From: Houcheng 

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.30

2. 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

Signed-off-by: Houcheng 
---
 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

diff --git a/configure b/configure
index 5c06663..3ff6ffa 100755
--- a/configure
+++ b/configure
@@ -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