Merge "fix extra / in include" into emu-dev
tree: d01c029cfb15dfb3869b170e930dddb1422246d0
  1. .github/
  2. .gitlab/
  3. .gitlab-ci.d/
  4. accel/
  5. audio/
  6. authz/
  7. backends/
  8. block/
  9. bsd-user/
  10. chardev/
  11. common-user/
  12. configs/
  13. contrib/
  14. crypto/
  15. disas/
  16. docs/
  17. dump/
  18. ebpf/
  19. fpu/
  20. fsdev/
  21. gdb-xml/
  22. gdbstub/
  23. google/
  24. host/
  25. hw/
  26. include/
  27. io/
  28. libdecnumber/
  29. linux-headers/
  30. linux-user/
  31. migration/
  32. monitor/
  33. nbd/
  34. net/
  35. pc-bios/
  36. platform/
  37. plugins/
  38. po/
  39. python/
  40. qapi/
  41. qga/
  42. qobject/
  43. qom/
  44. replay/
  45. roms/
  46. scripts/
  47. scsi/
  48. semihosting/
  49. stats/
  50. storage-daemon/
  51. stubs/
  52. subprojects/
  53. system/
  54. target/
  55. tcg/
  56. tests/
  57. tools/
  58. trace/
  59. ui/
  60. util/
  61. .dir-locals.el
  62. .editorconfig
  63. .exrc
  64. .gdbinit
  65. .git-blame-ignore-revs
  66. .gitattributes
  67. .gitignore
  68. .gitlab-ci.yml
  69. .gitmodules
  70. .gitpublish
  71. .mailmap
  72. .patchew.yml
  73. .readthedocs.yml
  74. .travis.yml
  75. _VERSION
  76. block.c
  77. blockdev-nbd.c
  78. blockdev.c
  79. blockjob.c
  80. BUILD.bazel
  81. configure
  82. COPYING
  83. COPYING.LIB
  84. cpu-common.c
  85. cpu-target.c
  86. event-loop-base.c
  87. gitdm.config
  88. hmp-commands-info.hx
  89. hmp-commands.hx
  90. iothread.c
  91. job-qmp.c
  92. job.c
  93. Kconfig
  94. Kconfig.host
  95. LICENSE
  96. MAINTAINERS
  97. Makefile
  98. memory_ldst.c.inc
  99. meson.build
  100. meson_options.txt
  101. module-common.c
  102. os-posix.c
  103. os-win32.c
  104. page-vary-common.c
  105. page-vary-target.c
  106. pythondeps.toml
  107. qemu-bridge-helper.c
  108. qemu-darwin-shim.jsonc
  109. qemu-edid.c
  110. qemu-img-cmds.hx
  111. qemu-img.c
  112. qemu-io-cmds.c
  113. qemu-io.c
  114. qemu-keymap.c
  115. qemu-linux-shim.jsonc
  116. qemu-nbd.c
  117. qemu-options.hx
  118. qemu-windows-shim.jsonc
  119. qemu.nsi
  120. qemu.sasl
  121. README.MD
  122. README.rst
  123. replication.c
  124. trace-events
  125. version.rc
README.MD

QEMU with Android Extensions

This repository contains a modified version of QEMU, tailored for Android emulation, along with instructions for building it using the [Android Open Source Project (AOSP) toolchain].

Contents

  • Base QEMU: The core QEMU functionality.
  • Low-level QEMU Android drivers: Components such as ACPI tables and motherboard configurations that are initialized early in the QEMU configuration process.
  • Android-specific drivers: Drivers for various hardware components (graphics, sound, networking) needed to run Android applications. These drivers are located in //hardware/generic/goldfish/... as plugins loaded during QEMU driver initialization.
  • Platform-specific modifications: Changes to the codebase to ensure successful compilation on supported platforms:
    • Linux x64
    • Mac M1
    • Windows x64

Building QEMU

This repository enables you to build QEMU using the AOSP compiler toolchain.

The Android emulator is a series of plugins that can be loaded into QEMU. Run the Android emulator by providing the correct parameters to QEMU.

While stock QEMU is built using meson, the Android emulator is built using bazel. Bazel build files are generated using an automated script that must be run on every platform of interest. After that, a merge script can be run to generate the final bazel build files. You should never manually edit any of the BUILD.bazel files.

Adding Generic Drivers

To add generic drivers for the wider QEMU community, make the modifications to the meson build scripts and ensure they compile on all platforms of interest. Please try to upstream these drivers, if possible, to make them available to the wider community and reduce maintenance costs.

Once your modifications are successful, you need to generate the bazel build files. See the google/scripts/fetch_bazel/README.md document for details on how to create the bazel build files from the meson build files.

Building stock QEMU

To get started you will need to configure the toolchain this can be done by running the following:

  1. Create a python virtual environment
  2. pip install google/toolchain
  3. Run the amc command to configure the toolchain.

For Mac/Linux:

python -m venv .venv
source .venv/bin/activate
pip install google/toolchain
amc setup build
amc compile build

For Windows:

python -m venv .venv
call .venv\Scripts\activate.bat
pip install google/toolchain
amc setup build
amc compile build

Once this is finished you should be able to run the qemu binaries in the build directory.

Making changes to the QEMU code base

Only QEMU specific changes should be made here.

Upstream first

When making changes that are not specific to Google's implementation, consider upstreaming them to the official QEMU repository.

If you are within Google

  • First, submit your changes to the internal mimik branch (go/qemu). This is the branch Google uses to prepare patches for upstreaming.
  • Once integrated into the mimik branch, the changes will automatically flow back to dependent repositories within Google. Additionally, follow up with the mimik team to make sure that attempts will be made to upstream the changes to the official QEMU repository.

Minimize impact on base QEMU changes

This repository received regulary updates from the remotes/aosp/mirror-qemu-internal-staging-xxx (where xxxx is the current active branch). To minimize conflicts during merging updates, we adhere to the following principles:

  • Build System: We adopt the QEMU meson build system for consistency.
  • Dependencies: Do not introduce new high-level dependencies not already used by upstream QEMU, such as protobuf, gRPC, or WebRTC.
  • Minimal changes: Minimize modifications to the original QEMU source code. Ideally, changes should be upstreamed first.
  • Android-specific code: All code specific to Android and not intended for upstreaming should reside within the google directory.
  • Android-specific changes: Use #ifdef CONFIG_ANDROID ... #endif blocks to isolate code specific to Android, making merges easier and enabling builds of vanilla QEMU by disabling the CONFIG_ANDROID feature. For example:
#ifdef CONFIG_ANDROID
// My changes
int x = 0;
x = x + 1;
#endif

Android changes that cannot be upstreamed should live in google

All Android-specific code resides in the google subdirectory. This includes goldfish drivers, Android-specific CPU boards, scripts, compatibility layers, and toolchain configurators. You should only add drivers that cannot be loaded as plugins (such as motherboards) in this directory.

By following these guidelines, wec can ensure clean and consistent contributions to the codebase, facilitating efficient integration and future maintenance.

Building the Android Emulator release

The android emulator consists of a series of plugins that can be loaded into “stock” qemu. The android emulator itself is built using bazel. You can create a release by running

bazel build //hardware/generic/goldfish/emulator:release

This will produce a zip file for your current architecture. You can unzip this file and launch the emulator. For example on darwin it will produce the following:

bazel build //hardware/generic/goldfish/emulator:release
INFO: Analyzed target //hardware/generic/goldfish/emulator:release (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //hardware/generic/goldfish/emulator:release up-to-date:
  bazel-bin/hardware/generic/goldfish/emulator/sdk-repo-darwin_aarch64-emulator-developer.zip
INFO: Elapsed time: 0.258s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action

You can run the qemu binaries directly, but you will have

Running a development build

You can also run the emulator directly from within bazel:

bazel run //hardware/generic/goldfish/emulator/launcher:goldfish -- @V

This will launch the goldfish emulator with avd V and creates a vnc connection on port 5901. You can now attach your favorite debugger to debug any issues.

Adding emulator functionality

All the code related to emulator can be found in //hardware/generic/goldfish. See the //hardware/generic/goldfish/README.MD for more information on how to debug and build the emulator.