android10.0.0_rxx : lunch qemu_trusty_arm64-userdebug fails

2,025 views
Skip to first unread message

Julien Robin

unread,
Mar 1, 2020, 5:40:47 PM3/1/20
to Android Building
Hi there,

I see that starting from branch android-10.0.0_r1, lunch offers a choice called qemu_trusty_arm64-userdebug, in which I'm interested

However, I got the following error, no matter which OS I'm using for building (be it Ubuntu 18.048 or Debian 10). I have this error on r1, r20 and r29.

[ 62% 16150/26047] Create system-qemu.img now
FAILED
: out/target/product/trusty/system-qemu.img
/bin/bash -c "(export SGDISK=out/host/linux-x86/bin/sgdisk SIMG2IMG=out/host/linux-x86/bin/simg2img;      device/generic/goldfish/tools/mk_combined_img.py -i out/target/product/trusty/system-qemu-config.txt -o out/target/product/trusty/system-qemu.img)"
1+0 records in
2048+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0063128 s, 166 MB/s
Traceback (most recent call last):
 
File "device/generic/goldfish/tools/mk_combined_img.py", line 163, in <module>
    main
()
 
File "device/generic/goldfish/tools/mk_combined_img.py", line 135, in main
   
if check_sparse(partition["path"]):
 
File "device/generic/goldfish/tools/mk_combined_img.py", line 12, in check_sparse
   
with open(filename, 'rb') as i:
IOError: [Errno 2] No such file or directory: 'out/target/product/trusty/vbmeta.img'
13:44:11 ninja failed with: exit status 1

#### failed to build some targets (19:41 (mm:ss)) ####

What should I do to get qemu_trusty_arm64-userdebug building successfully?

Thank you in advance!

Best regards,
Julien ROBIN

Julien Robin

unread,
Mar 2, 2020, 3:51:54 PM3/2/20
to Android Building
I succeeded to find a workaround for the issue I signaled here, editing device/generic/trusty/BoardConfig.mk and putting BUILD_QEMU_IMAGES to false, which still gives vendor.img, system.img and userdata.img

I then found this kernel https://android.googlesource.com/kernel/common/+/refs/heads/android-trusty-4.19, and using arch/arm64/configs/trusty_qemu_defconfig, I successfully built it.

Also, I'm able to start most of this Android build on Debian 10 provided qemu-system-aarch64 the following way :

qemu-system-aarch64
   
-M virt
   
-cpu cortex-a57
   
-smp 1
   
-m 2048
   
-monitor none
   
-parallel none
   
-serial mon:stdio
   
-kernel Image -append "root=/dev/vda rootfstype=ext4 ro init=/init loglevel=8 selinux=1 checkreqprot=1 androidboot.selinux=permissive androidboot.hardware=qemu_trusty console=ttyAMA0"
   
-device virtio-gpu-pci
   
-drive format=raw,file=system-custom.img
   
-drive format=raw,file=userdata-custom.img

userdata-custom.img is just a bigger userdata.img (1024MB instead of 4) in which I used resize2fs, system-custom.img is just a system.img in which the placeholder folder "vendor" now embeds the content of vendor.img, copied by "cp -a". Finally, still into system-custom.img, fstab.qemu_trusty only contains
LABEL=data              /data               ext4      noatime,nosuid,nodev,errors=panic    wait
So that /data (available at /dev/vdb) is mounted by its label, while system-custom.img embeding root system and vendor is already mounted by kernel cmdline (by /dev/vda). ramdisk.img is not used as system.img already contains everything needed to start init.

However, I guess I should use a slightly modified version of qemu, available here https://android.googlesource.com/trusty/external/qemu/+/refs/heads/master
Because using Debian 10 qemu version, I get the following output, and no display :

init: init first stage started!
[...]
init
: Loading SELinux policy
[...]
selinux
: SELinux: Loaded policy from /vendor/etc/selinux/precompiled_sepolicy

selinux
: SELinux: Loaded file_contexts

random
: init: uninitialized urandom read (40 bytes read)
random
: init: uninitialized urandom read (40 bytes read)
init
: init second stage started!
[...]
ueventd
: Coldboot took 1.344 seconds
[...]
init
: starting service 'storageproxyd'...
libprocessgroup
: CgroupMap::FindController called for [1] failed, RC file was not initialized properly
libprocessgroup
: Failed to make and chown /uid_0: Read-only file system
libprocessgroup
: CgroupMap::FindController called for [829] failed, RC file was not initialized properly
init
: createProcessGroup(0, 829) failed for service 'storageproxyd': Read-only file system
init
: cpuset cgroup controller is not mounted!
init
: Service 'storageproxyd' (pid 829) exited with status 1
init
: Sending signal 9 to service 'storageproxyd' (pid 829) process group...
libprocessgroup
: CgroupMap::FindController called for [1] failed, RC file was not initialized properly
libprocessgroup
: CgroupMap::FindController called for [1] failed, RC file was not initialized properly


init
: starting service 'storageproxyd'...
libprocessgroup
: CgroupMap::FindController called for [1] failed, RC file was not initialized properly
libprocessgroup
: Failed to make and chown /uid_0: Read-only file system
init
: createProcessGroup(0, 830) failed for service 'storageproxyd': Read-only file system
libprocessgroup
: CgroupMap::FindController called for [830] failed, RC file was not initialized properly
init
: cpuset cgroup controller is not mounted!
init
: Service 'storageproxyd' (pid 830) exited with status 1
init
: Sending signal 9 to service 'storageproxyd' (pid 830) process group...

...and so on in loop

However I'm still not sure to proceed correctly, as I'm doing everything alone with no documentation (I may have missed it?)

Is here some documentation available? If there isn't, is someone able to provide an example of working qemu command line (even old or unoptimized), or just few explanations so that I can be placed on the right track?

Thank you very much in advance

Dan Willemsen

unread,
Mar 2, 2020, 4:35:05 PM3/2/20
to Android Building, Matthew Maurer
+Matthew Maurer Do we have any documentation on this target? I think the last time we talked about this target it was only minimally functional.

- Dan

--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com
To unsubscribe from this group, send email to
android-buildi...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to the Google Groups "Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-buildi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-building/a30c5a05-6134-43a5-8f3b-32313e32bac0%40googlegroups.com.

Matthew Maurer

unread,
Mar 3, 2020, 12:21:24 AM3/3/20
to Dan Willemsen, Android Building
This target is a testing target used for evaluating our reference TrustZone implementation. "storageproxyd" is continuously resetting there because it is not being launched by our test script which would attach a virtual RPMB resource.

A few notes about this target:
* It does not have a GUI
* Running Java is not supported and unlikely to work
* It requires a custom EL3 and Trusty running alongside it to work

The manifest for these components is at https://android.googlesource.com/trusty/manifest, and that manifest contains a checked in prebuilt of the qemu_trusty_arm64-userdebug target that we are currently testing against.

If you tell me more about what you're trying to make the target do, I may be able to give you further help with getting it to do what you want. If you aren't trying to use or inspect the Trusty TZ implementation, this target probably isn't the one you're looking for.

Julien ROBIN

unread,
Mar 3, 2020, 10:18:37 AM3/3/20
to android-...@googlegroups.com, mma...@google.com, dwill...@google.com

Many thanks for your answers

In fact what I'm trying to do is using QEMU files into AOSP source code to get Android (with GUI) built and running on a standard/upstream QEMU version.

This would give the ability of running Android and its future releases without real "porting", on any device running a Linux kernel (be it upstream or not) and having KVM working on it. Which would be extremely interesting.

From what you write, it seems qemu-trusty-arm64 is not really for me. So what I'm trying to do is probably more about using device/generic/qemu/qemu_arm64.mk (and others archs) files included into AOSP. So I'll continue into this other subject : https://groups.google.com/forum/?hl=bn#!topic/android-building/kbiEg5OxBGU


While talking with you, I noticed that AVD Emulator is different from upstream QEMU, probably about goldfish and ranchu related things. Things working fine with the emulator (aosp_x86_64-eng for example and android-goldfish-4.14-dev which seems mandatory to get Android 10 working with AVD Emulator) does not seems to be working with upstream QEMU (at least I can't get the GUI). Therefore the documentation about AVD Emulator builds https://source.android.com/setup/create/avd didn't really help me for upstream QEMU.

Can you confirm it's possible to use modern versions of AOSP on upstream QEMU? Someone did succeed in the past with Android 6 / untouched AOSP and a extended compatibility kernel (I have one based on android-goldfish-4.14-dev), this is why I'm trying with newer versions of AOSP. This was documented here, but it's not up to date anymore : https://www.collabora.com/news-and-blog/blog/2016/09/02/building-android-for-qemu-a-step-by-step-guide/

Thank you in advance

Julien

You received this message because you are subscribed to a topic in the Google Groups "Android Building" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-building/fY-gdZQ-67M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-buildi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-building/CAGSQo01HoD%2B8b1LdOrqaqmnQK5Fa1Ys9REVZ9Rt-85E4WrYRaw%40mail.gmail.com.

郁进

unread,
Jun 29, 2020, 12:41:01 AM6/29/20
to Android Building
Hi,

I found another tickets you submitted to run arm64 android via qemu.

I tried to lunch aosp_arm64-eng project, run with android emulator, with qemu args:

emulator -kernel ../Android_kernel/out/android-mainline/common/arch/arm64/boot/Image -system xxx ...... -qemu --monitor tcp:127.0.0.1:2222,server,nowait -gdb tcp::4444 -S

But the Android kernel panic occurred since no init found, and I try to dump guest memory via qemu monitor, can't parsed by crash tools.

Have you build and run arm64 android via qemu successfully?  How ?

Looking forward to your reply, many thanks.


在 2020年3月3日星期二 UTC+8下午11:18:37,Julien ROBIN写道:

Many thanks for your answers

In fact what I'm trying to do is using QEMU files into AOSP source code to get Android (with GUI) built and running on a standard/upstream QEMU version.

This would give the ability of running Android and its future releases without real "porting", on any device running a Linux kernel (be it upstream or not) and having KVM working on it. Which would be extremely interesting.

From what you write, it seems qemu-trusty-arm64 is not really for me. So what I'm trying to do is probably more about using device/generic/qemu/qemu_arm64.mk (and others archs) files included into AOSP. So I'll continue into this other subject : https://groups.google.com/forum/?hl=bn#!topic/android-building/kbiEg5OxBGU


While talking with you, I noticed that AVD Emulator is different from upstream QEMU, probably about goldfish and ranchu related things. Things working fine with the emulator (aosp_x86_64-eng for example and android-goldfish-4.14-dev which seems mandatory to get Android 10 working with AVD Emulator) does not seems to be working with upstream QEMU (at least I can't get the GUI). Therefore the documentation about AVD Emulator builds https://source.android.com/setup/create/avd didn't really help me for upstream QEMU.

Can you confirm it's possible to use modern versions of AOSP on upstream QEMU? Someone did succeed in the past with Android 6 / untouched AOSP and a extended compatibility kernel (I have one based on android-goldfish-4.14-dev), this is why I'm trying with newer versions of AOSP. This was documented here, but it's not up to date anymore : https://www.collabora.com/news-and-blog/blog/2016/09/02/building-android-for-qemu-a-step-by-step-guide/

Thank you in advance

Julien


On 3/2/20 10:51 PM, 'Matthew Maurer' via Android Building wrote:
This target is a testing target used for evaluating our reference TrustZone implementation. "storageproxyd" is continuously resetting there because it is not being launched by our test script which would attach a virtual RPMB resource.

A few notes about this target:
* It does not have a GUI
* Running Java is not supported and unlikely to work
* It requires a custom EL3 and Trusty running alongside it to work

The manifest for these components is at https://android.googlesource.com/trusty/manifest, and that manifest contains a checked in prebuilt of the qemu_trusty_arm64-userdebug target that we are currently testing against.

If you tell me more about what you're trying to make the target do, I may be able to give you further help with getting it to do what you want. If you aren't trying to use or inspect the Trusty TZ implementation, this target probably isn't the one you're looking for.

On Mon, Mar 2, 2020 at 1:34 PM Dan Willemsen <dwill...@google.com> wrote:
+Matthew Maurer Do we have any documentation on this target? I think the last time we talked about this target it was only minimally functional.

- Dan


For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to the Google Groups "Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-...@googlegroups.com.
--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to a topic in the Google Groups "Android Building" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-building/fY-gdZQ-67M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-...@googlegroups.com.

Julien Robin

unread,
Jul 3, 2020, 12:35:32 PM7/3/20
to Android Building
Hi 郁进,

Recently I focused on making the untouched Android code base working with standard/upstream QEMU (which is a little bit different from the AOSP's emulator, which is a QEMU derivative), focusing on x86_64 builds and "android-x86" project build configurations; the work is still in progress. But from what I know :

When building aosp_XXXX-eng project, the "emulator" command line is made available so that just typing "emulator" into your terminal is (normally) enough to get it starting with the correct parameters set. Most of the time I use "emulator -verbose -show-kernel -no-snapshot" when running the AOSP's emulator. So that you have all the default parameters shown into your terminal, then kernel debug information, then Android's "init" output into your terminal. The kernel used to run those builds is called "kernel-ranchu" : it's a customised and prebuilt version of the 4.14 kernel, intended for use with the aosp's emulator virtual hardware and drivers (called goldfish in its original version, then ranchu).

If you build aosp then close the terminal window, and you want the "emulator" command to be available again, you should just type "source build/envsetup.sh && lunch" commands again (no need to rebuild everything).

But for arm64 builds its horribly slow, like several minutes for booting (upstream qemu is making the following option "-accel tcg,thread=multi" available so that the performance using an AMD 3700X is almost similar to using KVM on a native arm64 Raspberry Pi 4. But unfortunately this accel option does not seem to be used by the "emulator" command, and seems not to work on AOSP's emulator, at least last time I tried). Be aware that emulator is a derivative of QEMU, recognizing some AOSP specific commands, and not recognizing some orginal QEMU commands.

About having the kernel finding and starting "init" :

Lot of things can be confusing about having your emulator or qemu finding and running "init" process. I will give you everything I discovered so that hopefully you will be able to understand and debug anything that happens to you

On really old versions of Android, "init" executable was only available into the ramdisk, and "system" partition was just containing the /system subfolder (this is the opposite of "system as root"). In this case, Linux kernel absolutely needed to load the ramdisk, because init was into this ramdisk. I guess fstab file was into the ramdisk too, in order to find and mount partitions once init started.

Some more recent version of android using "system as root" (8 or 9 maybe) gave some ramdisk file as parameter to the emulator, despite the fact this ramdisk wasn't actually used anymore by the emulator : the content of the ramdisk was already into system.img. And the kernel was already able to access the system.img partition without the need of anything into the ramdisk - so the ramdisk wasn't used anymore. "init" file was at the root of the system.img partition image. In this case, you should ensure your machine and kernel are able to find your ext4 root (when in trouble, look into the kernel messages to find an ext4 file system at /dev/sda, or /dev/vda, or even sda1, vda1, etc, so that you can be sure about the kernel ability to see the partition you need).

But Android 10 introduced a new partition/image format that can be dynamically expanded and physically fragmented (so that devices sold with a too small system partition for being updated, can be updated anyway). This is cool feature, but a little bit more complex to handle. When using this kind of system images, android requires a brand new specific ramdisk with a specific "init" executable in order to read and mount this new system partition format created by android. I believe emulator is using it with Android 10 (to be confirmed). But in order to focus on my work, I'm still using the previous way : an ext4 system.img with everything into it ;) so that qemu boots it directly.


For example, on my x86_64 custom builds using "system as root", and having the vendor files included into system.img, as a standard ext4 image, I run the following command to start it using QEMU :

kvm -m 4096 -smp 4 -kernel bzImage  -append "root=/dev/sda rootfstype=ext4 ro init=/init selinux=1 checkreqprot=1 androidboot.selinux=permissive console=ttyS0 androidboot.hardware=luoss loglevel=8" -serial mon:stdio -drive format=raw,file=system.img -vga std
-m 4096 ask for 4GB RAM
bzImage is a custom 5.4 kernel
root=/dev/sda rootfstype=ext4 ro init=/init is telling my kernel to mount what it sees as "/dev/sda" and to run the "init" executable which is located into it
selinux=1 checkreqprot=1 androidboot.selinux=permissive are selinux parameters : when you want to disable selinux, you can't (init absolutely wants your kernel to have selinux running) but you set it to androidboot.selinux=permissive, so that no operation is actually blocked.
console=ttyS0 ask the kernel to print its messages into the serial port
androidboot.hardware=HW_NAME is used to tell init process to load init.HW_NAME.rc configuration file (that should be into  /init.HW_NAME.rc or /vendor/etc/init/hw/init.HW_NAME.rc). For aosp emulator builds, it is /vendor/etc/init/hw/init.ranchu.rc
loglevel=8 ask for the kernel, then init, to be as verbose as possible

-serial mon:stdio is a qemu parameter I use to redirect the virtual serial port (on which the kernel talks) to the terminal in which qemu is running. So that I can use this terminal as a read/write terminal with the virtual machine.


The system image i'm using to do so is an ext4 partition image, on which i placed everything needed, and an init.luoss.rc and fstab.luoss files - mainly just to mount a /data tmpfs instead of using a real userdata.img partiton - yes, I'm cheating ;) normally system.img is not enough, and in most case, /vendor subfolder is into a vendor.img partition.

I guess that when I'll be trying to run arm64 builds on qemu, some parameters will need to be changed.

I hope that all this information will help you to successfully dig, understand and solve your issues!

Best regards

Julien

郁进

unread,
Jul 24, 2020, 11:21:35 AM7/24/20
to Android Building
This is tremendously helpful. Thanks a lot.

My work is focusing on kernel, base on arm architecture,  I want have whole view of the running kernel. 

With qemu & qemu monitor & gdb & crash tools, I can stop kernel anywhere, read phy/virt address, registers even system register(with last qemu release).

Thanks for sharing your experience, It does greate help.

Hope to hear that you successfully run last AOSP on upstream QEMU.

在 2020年7月4日星期六 UTC+8上午12:35:32,Julien Robin写道:

Victor

unread,
May 17, 2021, 5:14:48 PM5/17/21
to Android Building
Hi Julien, 郁进,

Did either of you manage to run AOSP on upstream QEMU?

Thanks

Victor

unread,
May 17, 2021, 5:17:01 PM5/17/21
to Android Building
Hi Mathew,

I managed to 'make dist' after working around some errors in build/make and frameworks/base/tools/aapt.

Thanks

Victor

unread,
May 17, 2021, 5:17:06 PM5/17/21
to Android Building
Hi Matthew,

Can you please provide some guidance for creating the prebuilt, e.g. https://android.googlesource.com/trusty/prebuilts/aosp/+/refs/heads/master/pristine/qemu_trusty_arm64-target_files-7152458.zip? Seems to be related to build/make/tools/releasetools, and tried 'make dist', but getting errors.

Thanks

On Tuesday, March 3, 2020 at 2:21:24 PM UTC+9 mma...@google.com wrote:

Julien ROBIN

unread,
May 18, 2021, 4:48:56 PM5/18/21
to android-...@googlegroups.com, victor...@linaro.org

Hi Victor,

Indeed yes I succeeded in running AOSP 10, then AOSP 11 few time after it was made available, on upstream QEMU (at least on Debian 10's QEMU). I succeeded in both x86_64 and arm64. Here's some information I kept and remember from this work.

  • For AOSP 10, using "lunch aosp_x86_64-eng" or "lunch aosp_arm64-eng" can build something that, once having its files tweaked enough, will run on QEMU. Swiftshader library is built-in and can be used fine.
  • For AOSP 11, before building, the "goldfish" specific build configuration files used by "aosp_x86_64" and "aosp_arm64" have to be modified* (so it's a little more complicated compared with AOSP 10). Modified* or duplicated, renamed, edited so that you can create a proper / separated set of configuration files ;) I ended up doing so.

In both case, aosp_xxxxx builds are really "emulator specific". Emulator which is called ranchu, but was previously called goldfish in its previous versions, so this is why we will use and tweak ranchu and goldfish files in the process.


Let's start from AOSP 10 (aosp_x86_64-eng)

  • lunch aosp_x86_64-eng
  • after having mounted "system.img", using "cp -a", place the content of "system.img" into a partition image file, let's say "rootfs.img" (created with qemu-img create rootfs.img 5G for example, and mounted with losetup /dev/loop0 rootfs.img for example)
  • after having mounted "vendor.img", using "cp -a", place the content of "vendor.img" into the /vendor folder of the same rootfs partition
  • tweak the fstab file : If using "android-x86" kernel, userdata and cache (/cache and /data mount points) can be mounted as tmpfs. If using a more standard android kernel, cache.img and data.img file images should be created and ext4 formatted if I remember. Android x86 kernel is modified because if I remember well, on standard kernels, sqlitedb writes are encountering errors if userdata or cache are mounted as tmpfs
  • my fstab.ranchu for tmpfs using android-x86 kernel

none            /cache        tmpfs    nosuid,nodev,noatime    defaults
none            /data        tmpfs    nosuid,nodev,noatime    defaults

/devices/*/block/sr*        auto    auto    defaults        voldmanaged=cdrom:auto
/devices/*/usb*/*        auto    auto    defaults        voldmanaged=usb:auto,encryptable=userdata
/devices/*/mmc0:a*/*        auto    auto    defaults        voldmanaged=sdcard1:auto,encryptable=userdata
/devices/*/*sdmmc*/*        auto    auto    defaults        voldmanaged=sdcard1:auto,encryptable=userdata
/devices/*/80860F14:01/mmc_*    auto    auto    defaults        voldmanaged=sdcard1:auto,encryptable=userdata
/devices/*/80860F14:02/mmc_*    auto    auto    defaults        voldmanaged=sdcard1:auto,encryptable=userdata
/devices/*/80860F16:00/mmc_*    auto    auto    defaults        voldmanaged=sdcard1:auto,encryptable=userdata
/devices/*/PNP0FFF:00/mmc_*    auto    auto    defaults        voldmanaged=sdcard1:auto,encryptable=userdata

  • my fstab.ranchu for a more standard android kernel (beware of sdb and sdc, it will depend on which order you put your disk images in your QEMU command line)
/dev/block/sdb          /data           ext4    noatime,nosuid,nodev,nomblk_io_submit,errors=panic   wait,check,quota,reservedsize=128M,first_stage_mount
/dev/block/sdc          /cache          ext4    noatime,nosuid,nodev,nomblk_io_submit,errors=panic   wait,check,quota,reservedsize=128M,first_stage_mount

/devices/*/block/sr*        auto    auto    defaults        voldmanaged=cdrom:auto
/devices/*/usb*/*        auto    auto    defaults        voldmanaged=usb:auto,encryptable=userdata
/devices/*/mmc0:a*/*        auto    auto    defaults        voldmanaged=sdcard1:auto,encryptable=userdata
/devices/*/*sdmmc*/*        auto    auto    defaults        voldmanaged=sdcard1:auto,encryptable=userdata
/devices/*/80860F14:01/mmc_*    auto    auto    defaults        voldmanaged=sdcard1:auto,encryptable=userdata
/devices/*/80860F14:02/mmc_*    auto    auto    defaults        voldmanaged=sdcard1:auto,encryptable=userdata
/devices/*/80860F16:00/mmc_*    auto    auto    defaults        voldmanaged=sdcard1:auto,encryptable=userdata
/devices/*/PNP0FFF:00/mmc_*    auto    auto    defaults        voldmanaged=sdcard1:auto,encryptable=userdata
  • By using "androidboot.hardware=ranchu" in the kernel command line, there are things that are needed for running Android on QEMU that will be automatically loaded (like the soft gatekeeper, gatekeeper.ranchu), but also others that aren't working with QEMU. I searched for files containing vulkan.ranchu, gralloc.ranchu, hwcomposer.ranchu in their name and deleted those files from the rootfs
  • Edit init.ranchu.rc to use "swiftshader".

on boot
    setprop ro.hardware.egl swiftshader
    setprop debug.hwui.renderer opengl
    setprop debug.hwui.renderer ${ro.kernel.qemu.uirenderer}
    setprop ro.opengles.version ${ro.kernel.qemu.opengles.version}
    setprop ro.zygote.disable_gl_preload 1
    [...]

  • The QEMU line I used to run the thing was
kvm -m 4096 -smp 4 -kernel bzImage  -append "root=/dev/sda rootfstype=ext4 ro init=/init selinux=1 checkreqprot=1 androidboot.selinux=permissive console=ttyS0 androidboot.hardware=ranchu loglevel=8" -serial mon:stdio -drive format=raw,file=system.img -vga std
  • The "bzImage" file was, in this example, a 5.4 kernel taken from android-x86 source, built using x86_64_defconfig + android config additions from https://android.googlesource.com/kernel/configs/, apart from CONFIG_AIO, which was causing troubles by just rebooting almost as soon as "init" was executed, without giving any explanation. It was maybe related to https://source.android.com/devices/tech/ota/apex#kernel_command_line_parameter_requirements but I believe I never took the time to check that.

    Using a kernel built from https://android.googlesource.com/kernel/common turned to be possible by just adding -drive format=raw,file=userdata.img and -drive format=raw,file=cache.img (of course after having created them, formatted ext4, and using the right lines into fstab.ranchu)

    At that time I was disabling "CONFIG_MODULES" so that everything was embedded into the kernel. But if building modules separated from bzImage file, I believe they simply have to be placed into /vendor/lib/modules/  without using a 5.4.xx/ subfolder for example. So unlike in most Linux based OS on which modules are placed into /lib/modules/$(uname -a)

    I'm not using any initramfs : everything is into the rootfs (init and its configuration files), so the kernel needs to succeed to access /dev/sda on its own before being able to reach the loadable modules. If not, needed modules (SATA and Ext4 related) should be built with "y" (in kernel menuconfig it's *) instead of "m".

    Also, there is requirement about SELinux, which should be enabled, and kernel cmdline parameters like selinux=1 checkreqprot=1 androidboot.selinux=permissive should be taken into account (I remember that when using the wrong build option, init may early fail and reboot).

    I marked some more menuconfig notes, into some files, and .config options, probably because I needed them (I don't remember very well), so here it is:

Add CONFIG_NETFILTER_ADVANCED=y before adding "android-base" config options

Device Drivers  --->
    Virtio drivers (check everything just in case),
    Graphics support
        Cirrus driver for QEMU emulated device
        DRM Support for bochs dispi vga interface (qemu stdvga)
        Virtio GPU driver
  
        Console display driver support
            Framebuffer Console support

CONFIG_INPUT_MOUSE=y
CONFIG_MOUSE_PS2=y
CONFIG_MOUSE_PS2_ALPS=y
CONFIG_MOUSE_PS2_BYD=y
CONFIG_MOUSE_PS2_LOGIPS2PP=y
CONFIG_MOUSE_PS2_SYNAPTICS=y
CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS=y
CONFIG_MOUSE_PS2_CYPRESS=y
CONFIG_MOUSE_PS2_LIFEBOOK=y
CONFIG_MOUSE_PS2_TRACKPOINT=y
CONFIG_MOUSE_PS2_FOCALTECH=y
CONFIG_MOUSE_PS2_SMBUS=y


CONFIG_VT=y
CONFIG_CONSOLE_TRANSLATIONS=y
CONFIG_VT_CONSOLE=y
CONFIG_VT_CONSOLE_SLEEP=y
CONFIG_HW_CONSOLE=y
CONFIG_VT_HW_CONSOLE_BINDING=y

ARM64

For AOSP 10 using aosp_arm64, I believe it was exactly the same approach, but I had to remove some services that were failing in loop during the android boot logo, and possibly remove them from "manifest.xml" so that Android doesn't try (and fail) to find them. I don't remember which ones, as I'm not finding back my notes about that. The command line I used to run it was different from x86_64 kvm one :

qemu-system-aarch64 -M virt -cpu cortex-a72 -accel tcg,thread=multi -smp 4 -m 4096 -kernel Image.gz.ax86 -monitor none -parallel none -append "root=/dev/vda rootfstype=ext4 ro init=/init selinux=1 checkreqprot=1 androidboot.selinux=permissive console=ttyAMA0 androidboot.hardware=ranchu loglevel=8" -serial mon:stdio -vga std -device ramfb -drive format=raw,file=system.img -device nec-usb-xhci -device usb-kbd -device usb-mouse -bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd

And from an arm64 machine with enough RAM, using kvm as arm64 :

kvm -M virt -cpu host -accel kvm -smp 4 -m 4096 -kernel Image.gz.ax86 -monitor none -parallel none -append "root=/dev/vda rootfstype=ext4 ro init=/init selinux=1 checkreqprot=1 androidboot.selinux=permissive console=ttyAMA0 androidboot.hardware=ranchu loglevel=8" -serial mon:stdio -vga std -device ramfb -drive format=raw,file=system.img -device nec-usb-xhci -device usb-kbd -device usb-mouse -bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd

At that time I was using the android-x86 kernel (which can be built for arm64 too) and my fstab.ranchu file was

none            /cache        tmpfs    nosuid,nodev,noatime    defaults
none            /data        tmpfs    nosuid,nodev,noatime    defaults

If building a kernel from standard android kernel code, and using ext4 partitions files for these, beware, it's not sda sdb sdc anymore, but vda vdb vdc...


AOSP 11 : I clearly need to play again with QEMU and AOSP 11 and look into all my files with Meld in order to be able to give you a working/verified list of everything to do in order to have AOSP 11 running on QEMU (x86_64 and arm64), I'll have some time tomorrow to do that! I'm sure enough swiftshader related things aren't included anymore into AOSP 11 Goldfish/ranchu build configuration files (so those things should be added).

Recently while playing with Glodroid, Pinephone and RPi 4, Swiftshader then real Mesa, I noticed that some things related to Goldfish and Audio suddenly changed on AOSP 11, requiring some more modifications compared to when AOSP 11 was made available.


Best regards,

Julien


For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to a topic in the Google Groups "Android Building" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-building/fY-gdZQ-67M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-buildi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-building/a52e9878-7432-4b28-b011-3e58d706491cn%40googlegroups.com.

v..@gmail.com

unread,
May 24, 2021, 2:14:31 PM5/24/21
to Android Building
Hi Julien,

Wow, that's awesome! Thank you very much for the detailed info and description! It'll be a very useful reference for us when trying this out!

Again, thanks!
Br

Julien Robin

unread,
May 24, 2021, 2:14:31 PM5/24/21
to Android Building
Here is an more precise/checked guide to AOSP 10 (aosp_x86_64-eng) on QEMU, kernel build and detailed configuration steps included (5.10, let's be up to date!)

repo init -u https://android.googlesource.com/platform/manifest -b android-10.0.0_r47
repo sync
source build/envsetup.sh
lunch aosp_x86_64-eng
m -j $(nproc)

The interesting files are :
# out/target/product/generic_x86_64/system.img
# out/target/product/generic_x86_64/vendor.img

Create (and ext4 format) the partition image files that we will use with QEMU:
    qemu-img create rootfs.img 5G
    qemu-img create userdata.img 1G
    qemu-img create cache.img 500M

    losetup /dev/loop0 rootfs.img
    losetup /dev/loop1 userdata.img
    losetup /dev/loop2 cache.img

    mkfs -t ext4 /dev/loop0
    mkfs -t ext4 /dev/loop1
    mkfs -t ext4 /dev/loop2

    losetup -d /dev/loop1
    losetup -d /dev/loop2

Mouting the rootfs partition
    mount -t ext4 /dev/loop0 /where/you/want
   
Placing and changing the right files :
cp -a [system.img mount point] [rootfs/mount/point]
The content of system.img may be copied inside a folder which is named like the mount point. Move everything 1 folder back.

cp -a [vendor.img mount point] [rootfs/mount/point]
If the name of the "vendor.img" mount point is "vendor", everything should now be inside the "/vendor" folder of the rootfs mount point. If not, you have to move it to the /vendor folder

Delete :

    /vendor/lib64/hw/camera.ranchu.so
    /vendor/lib/hw/camera.ranchu.so
    /vendor/lib64/hw/camera.ranchu.jpeg.so
    /vendor/lib/hw/camera.ranchu.jpeg.so
    /vendor/lib64/hw/gralloc.ranchu.so
    /vendor/lib/hw/gralloc.ranchu.so
    /vendor/lib64/hw/hwcomposer.ranchu.so
    /vendor/lib/hw/hwcomposer.ranchu.so
    /vendor/lib64/hw/vulkan.ranchu.so
    /vendor/lib/hw/vulkan.ranchu.so
   
Change /vendor/etc/fstab.ranchu, those 2 lines should be enough:


    /dev/block/sdb          /data           ext4    noatime,nosuid,nodev,nomblk_io_submit,errors=panic   wait,check,quota,reservedsize=128M,first_stage_mount
    /dev/block/sdc          /cache          ext4    noatime,nosuid,nodev,nomblk_io_submit,errors=panic   wait,check,quota,reservedsize=128M,first_stage_mount

Change /vendor/etc/init/hw/init.ranchu.rc by changing this line:
    setprop ro.hardware.egl emulation
  to
    setprop ro.hardware.egl swiftshader

Manufacturing an up to date 5.10 Android kernel:


git clone https://android.googlesource.com/kernel/configs

/!\ From configs/android-5.10/android-recommended.config, if you want to use a mouse, remove the following line : # CONFIG_INPUT_MOUSE is not set

git clone https://android.googlesource.com/kernel/common -b android12-5.10

Start from copying "arch/x86/configs/x86_64_defconfig" file to the root of the kernel tree, name it ".config",  and append to it:
    CONFIG_NETFILTER_ADVANCED=y
    Content of configs/android-5.10/android-base.config
    Content of configs/android-5.10/android-recommended.config
    Content of configs/android-5.10/android-recommended-x86.config
   
make menuconfig, exit, save: yes.

By looking with some tools, some of the things included into x86_64_defconfig, android-base.config, android-recommended.config are not included into the resulting ".config".
It works anyway, but it would be nice to know why theese option aren't enabling.

    Still missing from x86_64_defconfig
        CONFIG_SYSVIPC=y
        CONFIG_PREEMPT_VOLUNTARY=y
        CONFIG_MODULE_FORCE_UNLOAD=y
        CONFIG_NF_CONNTRACK_SIP=y
        CONFIG_NFS_FS=y
        CONFIG_NFS_V3_ACL=y
        CONFIG_NFS_V4=y
        CONFIG_ROOT_NFS=y

    Still missing from android-base.config:
        CONFIG_INET_DIAG_DESTROY=y
        CONFIG_INET_UDP_DIAG=y
        CONFIG_TRACE_GPU_MEM=y

    Still missing from android-recommended.config:
        CONFIG_BACKLIGHT_LCD_SUPPORT=y
        CONFIG_ENABLE_DEFAULT_TRACERS=y
        CONFIG_REFCOUNT_FULL=y
        CONFIG_SDCARD_FS=y

Now, 3 options that are still disabled, but should be enabled according to android-base-conditional.xml:
    CONFIG_KFENCE=y
    CONFIG_USERFAULTFD=y
    CONFIG_BPF_JIT_ALWAYS_ON=y


CONFIG_AIO and CONFIG_ANDROID_BINDERFS options (from android-base.config) are causing early reboot without explanations. Would be nice to know why, to keep them enabled and have something running... Until so, disable them by adding at the end of .config:
    # CONFIG_AIO is not set
    # CONFIG_ANDROID_BINDERFS is not set

Adding VirtIO things:

    CONFIG_VIRTIO=y
    CONFIG_VIRTIO_PCI=y
    CONFIG_VIRTIO_PCI_LEGACY=y
    CONFIG_VIRTIO_BALLOON=y
    CONFIG_VIRTIO_INPUT=y
    CONFIG_VIRTIO_MMIO=y
    CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
    CONFIG_VIRTIO_DMA_SHARED_BUFFER=y
    CONFIG_BLK_MQ_VIRTIO=y
    CONFIG_MEMORY_BALLOON=y
    CONFIG_BALLOON_COMPACTION=y
    CONFIG_PAGE_REPORTING=y
    CONFIG_DRM_GEM_SHMEM_HELPER=y
    CONFIG_DRM_VIRTIO_GPU=y
   
Above options are enough if you use "-vga virtio" option into QEMU/KVM command line.
If wanting to use "-vga std" instead, in order to have the display initializing itself, I had to add:

    CONFIG_DRM_BOCHS=y
    CONFIG_VT=y
    CONFIG_VT_CONSOLE=y
    CONFIG_FRAMEBUFFER_CONSOLE=y
   

make menuconfig, exit, save: yes.
make -j $(nproc)
make INSTALL_MOD_PATH=/home/user/Desktop/ INSTALL_MOD_STRIP=1 modules_install

Take the resulting kernel files:
Take the arch/x86/boot/bzImage file
Place the content of /home/user/Desktop/lib/modules/5.10.37+/ into /vendor/lib/modules/

Unmount rootfs.img:
    umount /its/mount/point
    losetup -d /dev/loop0

Ready to go: from where the "rootfs.img", "userdata.img" and "cache.img", and "bzImage" files are located, type:

kvm -m 4096 -smp 4 -kernel bzImage  -append "root=/dev/sda rootfstype=ext4 ro init=/init selinux=1 checkreqprot=1 androidboot.selinux=permissive console=ttyS0 androidboot.hardware=ranchu loglevel=8" -serial mon:stdio -drive format=raw,file=rootfs.img -drive format=raw,file=userdata.img -drive format=raw,file=cache.img -vga virtio

Here with Debian 11 it worked all fine. With the right kernel options, -vga std works fine too. There is a little color glitch about RGB being shown as BGR (or BGR shown as RGB, not sure ^^), probably one line about graphic stack / swiftshader things somewhere (but I don't know where).

I'll now go back to arm64, then AOSP 11. Having QEMU running these AOSP versions is based on almost the same approach but needs more things to tweak, so I'll detail it properly after I get them working again

Julien Robin

unread,
May 24, 2021, 2:14:44 PM5/24/21
to Android Building
Hi again,

Here is the AOSP 10 on ARM64 QEMU version of the procedure I follow. Andoid 5.10 arm64 kernel build included, like for x86_64.
Appart from using "vdb" and "vdc" into fstab instead of sdb and sdc, and removing some "rild.rc" file, the approach is the same. With some additionnal information at the end

repo init -u https://android.googlesource.com/platform/manifest -b android-10.0.0_r47
repo sync
source build/envsetup.sh
lunch
m -j $(nproc)

# out/target/product/generic_arm64/system.img
# out/target/product/generic_arm64/vendor.img

Create and ext4 format the partition image files:

    qemu-img create rootfs.img 5G
    qemu-img create userdata.img 1G
    qemu-img create cache.img 500M

    losetup /dev/loop0 rootfs.img
    losetup /dev/loop1 userdata.img
    losetup /dev/loop2 cache.img

    mkfs -t ext4 /dev/loop0
    mkfs -t ext4 /dev/loop1
    mkfs -t ext4 /dev/loop2

    losetup -d /dev/loop1
    losetup -d /dev/loop2

Mouting the rootfs partition
    mount -t ext4 /dev/loop0 /where/you/want
   
cp -a [system.img mount point] [rootfs/mount/point]
The content of system.img may be copied inside a folder which is named like the mount point. Move everything 1 folder above.


cp -a [vendor.img mount point] [rootfs/mount/point]
If the name of the "vendor.img" mount point is "vendor", everything should now be inside the "/vendor" folder of the rootfs. If not, you have to move it to /vendor folder


Delete these files:

    /vendor/lib/hw/camera.ranchu.so
    /vendor/lib/hw64/camera.ranchu.so
    /vendor/lib/hw/camera.ranchu.jpeg.so
    /vendor/lib/hw64/camera.ranchu.jpeg.so
    /vendor/lib/hw/vendor/lib/hw/gralloc.ranchu
    /vendor/lib/hw64/gralloc.ranchu
    /vendor/lib/hw/hwcomposer.ranchu
    /vendor/lib/hw64/hwcomposer.ranchu
    /vendor/lib/hw/vulkan.ranchu.so
    /vendor/lib/hw64/vulkan.ranchu.so
    /vendor/etc/init/rild.rc

   
Change /vendor/etc/fstab.ranchu, those 2 lines should be enough:

    /dev/block/vdb          /data           ext4    noatime,nosuid,nodev,nomblk_io_submit,errors=panic   wait,check,quota,reservedsize=128M,first_stage_mount
    /dev/block/vdc          /cache          ext4    noatime,nosuid,nodev,nomblk_io_submit,errors=panic   wait,check,quota,reservedsize=128M,first_stage_mount


Change /vendor/etc/init/hw/init.ranchu.rc by changing this line:
    setprop ro.hardware.egl emulation
  to
    setprop ro.hardware.egl swiftshader


Manufacturing an up to date 5.10 ARM64 Android kernel:


git clone https://android.googlesource.com/kernel/configs

/!\ From configs/android-5.10/android-recommended.config, if you want to use a mouse, remove the following line : # CONFIG_INPUT_MOUSE is not set

git clone https://android.googlesource.com/kernel/common -b android12-5.10

Start from copying "arch/arm64/configs/defconfig" file to the root of the kernel tree, name it ".config",  and append to it:

    CONFIG_NETFILTER_ADVANCED=y
    Content of configs/android-5.10/android-base.config
    Content of configs/android-5.10/android-recommended.config
    Content of configs/android-5.10/android-recommended-arm64.config

make ARCH=arm64 menuconfig, exit, save: yes.


By looking with some tools, some of the things included into x86_64_defconfig, android-base.config, android-recommended.config are not included into the resulting ".config".
It works anyway, but it would be nice to know why theese option aren't enabling.

    Still missing from arm64/configs/defconfig
        CONFIG_SYSVIPC=y
        CONFIG_ACPI_APEI_PCIEAER=y
        CONFIG_KSM=y
        CONFIG_IP6_NF_NAT=m
        CONFIG_IP6_NF_TARGET_MASQUERADE=m
        CONFIG_LEGACY_PTY_COUNT=16
        CONFIG_POWER_AVS=y
        CONFIG_BACKLIGHT_GENERIC=m
        CONFIG_QCOM_IOMMU=y
        CONFIG_NFS_FS=y
        CONFIG_NFS_V4=y
        CONFIG_NFS_V4_1=y
        CONFIG_NFS_V4_2=y

        CONFIG_ROOT_NFS=y

    Still missing from android-base.config:
        CONFIG_TRACE_GPU_MEM=y

    Still missing from android-recommended.config:
        CONFIG_BACKLIGHT_LCD_SUPPORT=y
        CONFIG_REFCOUNT_FULL=y
        CONFIG_SDCARD_FS=y

Now, some options that are still disabled, but should be enabled according to android-base-conditional.xml:
    CONFIG_ARMV8_DEPRECATED=y
    CONFIG_CP15_BARRIER_EMULATION=y
    CONFIG_SETEND_EMULATION=y
    CONFIG_SHADOW_CALL_STACK=y
    CONFIG_SWP_EMULATION=y
    CONFIG_BPF_JIT_ALWAYS_ON=y
    CONFIG_KFENCE=y
    CONFIG_USERFAULTFD=y



CONFIG_AIO and CONFIG_ANDROID_BINDERFS options (from android-base.config) are causing early reboot without explanations. Would be nice to know why, to keep them enabled and have something running... Until so, disable them by adding at the end of .config:
    # CONFIG_AIO is not set
    # CONFIG_ANDROID_BINDERFS is not set

Adding VirtIO things:

    CONFIG_VIRTIO=y
    CONFIG_VIRTIO_PCI=y
    CONFIG_VIRTIO_PCI_LEGACY=y
    CONFIG_VIRTIO_BALLOON=y
    CONFIG_VIRTIO_INPUT=y
    CONFIG_VIRTIO_MMIO=y
    CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
    CONFIG_VIRTIO_DMA_SHARED_BUFFER=y
    CONFIG_BLK_MQ_VIRTIO=y
    CONFIG_MEMORY_BALLOON=y
    CONFIG_BALLOON_COMPACTION=y
    CONFIG_PAGE_REPORTING=y
    CONFIG_DRM_GEM_SHMEM_HELPER=y
    CONFIG_DRM_VIRTIO_GPU=y


make ARCH=arm64 menuconfig, exit, save: yes.
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j $(nproc)
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=/home/user/Desktop/ INSTALL_MOD_STRIP=1 modules_install

"Installing" the kernel:
Place the the arch/arm64/boot/Image.gz file at the same place as the rootfs.img, userdata.img and cache.img files

Place the content of /home/user/Desktop/lib/modules/5.10.37+/ into /vendor/lib/modules/

Unmount rootfs.img
    umount /its/mount/point
    losetup -d /dev/loop0

Ready to go:

From an x86_64 computer:
    qemu-system-aarch64 -M virt -cpu cortex-a72 -accel tcg,thread=multi -smp 4 -m 2048 -kernel Image.gz -monitor none -parallel none -append "root=/dev/vda rootfstype=ext4 ro init=/init selinux=1 checkreqprot=1 androidboot.selinux=permissive console=ttyAMA0 androidboot.hardware=ranchu loglevel=8" -serial mon:stdio -vga std -device ramfb -device nec-usb-xhci -device usb-kbd -device usb-mouse -bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd -drive format=raw,file=rootfs.img -drive format=raw,file=userdata.img -drive format=raw,file=cache.img

If you are lucky enough to have an arm64 machine with KVM available on it, and enough RAM, into the above command line, remplace:
    qemu-system-aarch64 -M virt -cpu cortex-a72 -accel tcg,thread=multi -smp 4 -m 2048
by
    kvm -M virt -cpu host -accel kvm -smp 4 -m 2048

In summary, from an arm64 computer :
    kvm -M virt -cpu host -accel kvm -smp 4 -m 2048 -kernel Image.gz -monitor none -parallel none -append "root=/dev/vda rootfstype=ext4 ro init=/init selinux=1 checkreqprot=1 androidboot.selinux=permissive console=ttyAMA0 androidboot.hardware=ranchu loglevel=8" -serial mon:stdio -vga std -device ramfb -device nec-usb-xhci -device usb-kbd -device usb-mouse -bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd -drive format=raw,file=rootfs.img -drive format=raw,file=userdata.img -drive format=raw,file=cache.img

Bits of additionnal information:
Having ARM64 AOSP running on QEMU from x86_64, even with "-accel tcg,thread=multi" which makes things much better, you still need to wait 30 seconds before having "android" boot logo (on an AMD 3700X) and 350 seconds (almost 6 minutes) on first boot before having the android main screen with icons and all stuff (2 minutes at the following boots).

There are some repeated messages about camera 2.4 stuff and radio@1.0. You may remove the /vendor/etc/init/android.hardware...@2.4-service.rc, but messages about "android.hardware.camera.provider@2.4" will still appear, so you may remove the associated entries (camera and radio) from /vendor/manifext.xml. Then no more messages about it.

In case of need to debug, you may type "logcat" in the console: this give way too much informations but you may spot information on what you are looking for, or few lines above some service crashing (sometimes some messages contains usefull information to tell you why it is going to crash just after). Into the "userdata.img" partition you may also find "/tombstones" folder, containing crash logs of services.

In order to cleanly poweroff your emulated system you can type "reboot -p" so that the "userdata.img" is kept as clean as possible.

Janne Karhunen

unread,
Jun 23, 2021, 1:06:32 AM6/23/21
to Android Building
Hi,

I tried something like this out of interest on arm64 with my own hypervisor (custom kvm, https://github.com/jkrh/kvms) and indeed I get the android vm up. Thanks!

In order to get the AOSP up I first started to port the 'ranchu' machine to qemu6, but the 'android-emu' library I'd need to hack in the qemu6 main loop just does not feel 'clean', so this remains unfinished in that regard:

That being said, would be nice to make it do GPU too and I'm new to the graphics pipeline.  From the hypervisor point of view I'd need it to do full VIRTIO since my hypervisor only opens the virtio channels between the host and the guest. Besides, I'm not entirely sure what to think of the 'pipe'. 

First attempt with that was to see if it would do 'gltransport=virtio':
KERNEL_OPTS="root=/dev/vda rootfstype=ext4 ro init=/init selinux=1 checkreqprot=1 androidboot.selinux=permissive console=ttyAMA0 androidboot.hardware=ranchu qemu.uirenderer=skiagl qemu.gltransport=virtio qemu.gles=1 qemu.opengles.version=131072 qemu.dalvik.vm.heapsize=192m loglevel=8"

and then for the QEMU:
SCREEN="-nographic -device virtio-gpu-pci -spice $SPICESOCK,disable-ticketing=on $VDAGENT"

Thoughts if something like this is supposed to be supported? Certainly it does not work:

[   36.445042] DEBUG: Build fingerprint: 'Android/aosp_arm64/generic_arm64:10/QT/eng.jmk.20210614.160415:userdebug/test-keys'
[   36.450901] DEBUG: Revision: '0'
[   36.458537] DEBUG: ABI: 'arm64'
[   36.462533] DEBUG: Timestamp: 2021-06-01 11:28:17+0000
[   36.465839] DEBUG: pid: 219, tid: 219, name: surfaceflinger  >>> /system/bin/surfaceflinger <<<
[   36.468971] DEBUG: uid: 1000
[   36.474921] DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10
[   36.476737] DEBUG: Cause: null pointer dereference
[   36.481510] DEBUG:     x0  0000000000000000  x1  0000e23fdddf66c0  x2  0000e23fd08b59f4  x3  0000e23fddcef5f8
[   36.484085] DEBUG:     x4  0000000000000002  x5  0000000000000000  x6  0000000000000000  x7  000000000000a000
[   36.490734] DEBUG:     x8  0000e23fddeef0e0  x9  0000000000000001  x10 0000e23fddeef060  x11 0000000000000000
[   36.497538] DEBUG:     x12 0000000000000000  x13 0000000000000000  x14 0000000000000020  x15 0200000000000000
[   36.502861] DEBUG:     x16 0000e23fd081da70  x17 0000e23fd08b4168  x18 0000e23fdf142000  x19 0000000000000000
[   36.509025] DEBUG:     x20 0000e23fddd192d0  x21 0000000000000001  x22 0000000000000000  x23 0000000000000000
[   36.514828] DEBUG:     x24 0000e23fddeef020  x25 0000e23fddd19280  x26 0000000000000000  x27 0000e23fddd90000
[   36.520535] DEBUG:     x28 0000e23fdc3b7070  x29 0000ffffdf3749e0
[   36.528408] DEBUG:     sp  0000ffffdf3749d0  lr  0000e23fd0813464  pc  0000e23fd08b4178
[   36.610037] DEBUG: 
[   36.615637] DEBUG: backtrace:
[   36.616452] DEBUG:       #00 pc 0000000000005178  /vendor/lib64/libOpenglSystemCommon.so (HostConnection::gl2Encoder()+16) (BuildId: 8ca38ff3265c54f31e1f70e8a19c683f)
[   36.618386] DEBUG:       #01 pc 0000000000013460  /vendor/lib64/egl/libGLESv2_emulation.so (glGetString+24) (BuildId: 1bc4a27ae3f25fffe3541af804629511)
[   36.628225] DEBUG:       #02 pc 0000000000018d20  /system/lib64/libEGL.so (android::egl_context_t::onMakeCurrent(void*, void*)+112) (BuildId: 5abb3faa9d72952310ca01a9da8941e3)
[   36.636811] DEBUG:       #03 pc 0000000000016450  /system/lib64/libEGL.so (android::egl_display_t::makeCurrent(android::egl_context_t*, android::egl_context_t*, void*, void*, void*, void*, void*, void*)+268) (BuildId: 5abb3faa9d72952310ca01a9da8941e3)
[   36.646320] DEBUG:       #04 pc 000000000001ff94  /system/lib64/libEGL.so (android::eglMakeCurrentImpl(void*, void*, void*, void*)+384) (BuildId: 5abb3faa9d72952310ca01a9da8941e3)
[   36.660598] DEBUG:       #05 pc 0000000000113d58  /system/lib64/libsurfaceflinger.so (android::renderengine::gl::GLESRenderEngine::create(int, unsigned int, unsigned int)+380) (BuildId: becfe6218fde450840f4bc3f14cb68c5)
[   36.670297] DEBUG:       #06 pc 0000000000113aa4  /system/lib64/libsurfaceflinger.so (android::renderengine::RenderEngine::create(int, unsigned int, unsigned int)+164) (BuildId: becfe6218fde450840f4bc3f14cb68c5)
[   36.681625] DEBUG:       #07 pc 00000000000ce97c  /system/lib64/libsurfaceflinger.so (android::SurfaceFlinger::init()+1164) (BuildId: becfe6218fde450840f4bc3f14cb68c5)
[   36.694419] DEBUG:       #08 pc 00000000000031bc  /system/bin/surfaceflinger (main+364) (BuildId: ff9215aa2c7b96de71b0a256004edc79)
[   36.703441] DEBUG:       #09 pc 000000000007d798  /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+108) (BuildId: 676a709a0ee633ec9cf6ab05ec6410ae)


--
Janne

Janne Karhunen

unread,
Jun 24, 2021, 4:19:29 PM6/24/21
to Android Building
Hi,

I might be wrong, but maybe the graphics pipeline from the guest to the host GPU with QEMU could look something like this:

1) virgl-gallium, https://gitlab.freedesktop.org/mesa/mesa. Android.mk: BOARD_GPU_DRIVERS=virgl
2) virtio-gpu (guest)
3) virtio-gpu (host)
4) virglrenderer (upstream version; not AVDVirglrenderer)
5) host drivers (via libhybris if not a bionic qemu)
6) QEMU display: -spice ...,gl=on

Aka. pretty much the standard Linux way of doing things. Since QEMU is such a great development tool for almost all the imaginable targets out there, I'm really surprised Google does not enable this by default. Anyone tried above or is there an easier alternative? I think I'll give it a spin.

That said, looks like I got the 'qemu.gltransport' wrong in the prior post. 'virtio-gpu' was the right answer.


--
Janne

FCLC

unread,
Jun 29, 2021, 7:32:02 PM6/29/21
to Android Building
Hi Julien,

First of all thank you for provinding the detailed documentation- I'm in the process of attempting to replicate it for my own needs.

An issue/concern of mine is the generation of vendor.img after having executed m/make within AOSP and it not creating a vendor.img file.

Per the AOSP documentation, a vendor image is normally only created via proprietary binaries that aren't a part of AOSP.

I think I might be missing something but I'm not sure what.

I read back to your posts from a few months back but I'm not sure if that's what's causing the difference

any guidance?

Felix CLC

Jake Brown

unread,
Jun 29, 2021, 7:32:17 PM6/29/21
to Android Building
Hi Julien,

Just joining this conversation and I have some questions.

I actually do have a physical arm64 device that I am trying to act as a hypervisor to run multiple androids on. I am running Ubuntu 20.04 on the aarch64 host and I believe what you have outlined is of great help, but I am running into some issues....

Here's what I've done to recap
- Generated the empty userdata.img and cache.img
- Generated rootfs.img and placed the contents of /vendor and /system into the block that were generated from running lunch from AOSP 10 arm64
- I moved contents of /system to be on the same level as /vendor within rootfs
- I made the /vendor/etc/fstab.ranchu to include only the two lines you mention above removing any defaults
- combined the defconfig, android-base, recommended and recommended-arm64 config files.
- created a directory in /vendor/lib called /modules and added all the modules.* files and kernel directory that was generated from running the following commands
make ARCH=arm64 menuconfig, exit, save: yes.
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j $(nproc)
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=/home/user/Desktop/ INSTALL_MOD_STRIP=1 modules_install

- Made the Image.gz, rootfs.img, userdata.img, cache.img all be incorporated into the kvm command which is identical to what you have. I didn't change anything regarding the qemu command.


So I think I followed the instructions but I am getting a "Kernel panic - not syncing: Requested init /init failed" error when I try and boot.


A few questions regarding the section on "Manufacturing an up to date 5.10 ARM64 Android kernel" 

- When you said "root" of the kernel file tree, did you mean to place the '.config' file in 'arch/arm64/configs/'? or in root of the project where the .config file gets generated after running make
- Do I need to append the configs you mention that are missing before I run 'make ARCH=arm64 menuconfig'? I assume so since it generates a new .config file.

From my understanding from reading previous conversation about "init", it's not able to find it that executable so how can I work through this issue?

Appreciate any help anyone can provide,

Thanks!





On Monday, May 24, 2021 at 2:14:44 PM UTC-4 julien....@gmail.com wrote:

Jake Brown

unread,
Jun 30, 2021, 4:36:49 PM6/30/21
to Android Building
I figured out my issue from when I last posted.

The problem was I didn't keep the super partitions inside fstab.ranchu which this documentation states is necessary


So my fstab includes
  • System
  • Vendor
  • Product
  • /dev/block/vdb
  • /dev/block/vdc
which seems to get me further, I can now interact with the console and I get the android splash screen (presumably because there's no graphics being emulated, but that's fine)

I am getting the errors @Julien mentioned with services defined by rc scripts in /vendor/etc/init/android.hardware...@*.rc
I systematically tried removing them, and changing manifest.xml but now I get new errors that tell my hwservicemanager is trying to start them. Anyone have any ideas how to stop hwservicemanager from running or fix these warnings? Console still works and I can interact with the filesystem for now though.

Julien Robin

unread,
Jun 30, 2021, 4:36:52 PM6/30/21
to android-...@googlegroups.com, Jake Brown

Hi Jake,

In order for everybody to compare what differs in case of problems, I uploaded here the results (for both AOSP 10 from today and 11 from yesterday)

Kernel included (with .config file)

Looks like the kernel panic says that the "/init" executable file (stated into the kernel parameters "root=/dev/vda rootfstype=ext4 ro init=/init") wasn't found by the kernel (so the kernel was unable to start the actual operating once ready). It can be because it didn't find the "/dev/vda " disk, because it failed to mount it as "ext4" or because the "/init" file (or link) isn't at the right place.

Here's attached a screen capture to show how I placed my files into the rootfs.img partition (sometimes pictures are easier to understand than my complicated explanations 😁). "/init" is a symbolic link that drives to "/system/bin/init", which is an android tailored init executable (completely configured by "/system/etc/init/hw/init.rc" file, which itself includes a lot of others *.rc files addresses). Just for comparison, on most Linux distributions, the init process is a link to "systemd" executable which will start all the services.


For the "defconfig" file copied as ".config" file, I place it at the root of the kernel tree, for example I have "/home/user/Desktop/work/kernel-src/arch/arm64/configs/defconfig" copied here : "/home/user/Desktop/work/kernel-src/.config"

Running menuconfig and saving, is taking into account and automatically mixing the parameters sets that have been placed into the ".config" files, in a way that gives the same results as when using the "scripts/kconfig/merge_config.sh" method described here https://source.android.com/devices/architecture/kernel/config (if you prefer using only files and command lines instead of editing .config manually, this other approach is interesting).

During my attempts, I firstly ran menuconfig after having appended together the content of defconfig, CONFIG_NETFILTER_ADVANCED=y, android base and recommended configs files to .config. Then I ran it a second time after having added the things from android-base-conditional.xml, virtio things and removed the 2 options (CONFIG_AIO and ANDROID_BINDERFS) that were causing trouble on android's boot; but I wouldn't be too surprised to see the same results if running menuconfig only once after everything has been added.

Without the "menuconfig" steps (or the use of merge_config.sh script), the build process would be asking an almost endless stream of "yes/no" questions. After menuconfig if only asks few questions before starting to work.


Hope this will help!

Good luck and have a nice day

Julien

--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com
To unsubscribe from this group, send email to
android-buildi...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to a topic in the Google Groups "Android Building" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-building/fY-gdZQ-67M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-buildi...@googlegroups.com.
rootfs-files-placement.png

Jake Brown

unread,
Jul 8, 2021, 5:47:35 PM7/8/21
to Android Building
Hi,

I'd really love to be able to send commands via adb from the host to the guest, but when I run
adb devices

it says 
emulator-5554 offline

Any ideas? A lot of what I've come across mentions to turn on USB debugging, but I'm not sure how to do that given our environment Julien walked through.

I've tried forwarding tcp traffic and usb connectivity by adding the following lines to the kvm command. I know the forwarding works as the emulator adbd can be seen by the host adb server, but I can't seem to start it or figure out USB debugging.

I've also tried adb reconnect offline and it just says reconnecting emulator-5554 but isn't actually able to turn it on.


I have a netdev argument in my qemu command that is set up:
-device e1000,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::5555-:5555

From my understanding this forwards tcp traffic on port 5555 between host and guest.

I also have a usb device added to your qemu command
-device usb-ehci,id=ehci \
-device usb-host,bus=ehci.0,vendorid=0x0bda,productid=0x5411 
(vendorid and productid from running lsub)

I have another issue that came up in my pursuit of figuring this out, I noticed I can't run any services inside the guest such as pm (package install)
it says cmd: Can't find service: package
I'm not sure what is going on here, any ideas with this?

I'd like to try and get python installed on this device 2.7 or 3 would be fine which is why I was trying to get pm working.


Thanks!
Jake
Reply all
Reply to author
Forward
0 new messages