Update QEMU build script.

Use debian:11 to get fresh libgbm binary.
Update rutabaga.
Update documentation.

Change-Id: I70dccdfbb39d274fb75d94f6acf7023c50a2b58e
diff --git a/qemu/README.md b/qemu/README.md
index f03c984..24ffe0b 100644
--- a/qemu/README.md
+++ b/qemu/README.md
@@ -4,11 +4,25 @@
 toolchain and sysroot (based on an old glibc-2.17 to ensure the generated
 binaries run on a vast number of distributions).
 
-## Getting the sources and prebuilts:
+## Prerequisite:
 
-The source tree is composed of ~50 multiple git containing source and prebuilt
-tools. This take tens of minutes since it downloads large prebuilts like the
-Clang toolchain or the GCC sysroot.
+Ensure podman is installed with `sudo apt-get install podman`
+
+## Reproducing a build in AOSP
+
+This secion is about rebuilding QEMU with AOSP toolchain (with the `repo` tool).
+Information about how to iterate on this build can be found in the next section.
+
+If you have an AOSP checkout, run:
+
+```sh
+$ANDROID_BUILD_TOP/device/google/cuttlefish_vmm/qemu/scripts/rebuild_in_container.sh
+```
+
+This will create a clean source checkout of QEMU and all relevant
+dependencies, and starts a build isolated in a podman container.
+
+If you don't have an AOSP checkout, run:
 
 ```sh
 mkdir cuttlefish_vmm
@@ -16,55 +30,21 @@
 repo init --manifest-url https://android.googlesource.com/device/google/cuttlefish_vmm \
   --manifest-name=qemu/manifest.xml
 repo sync -j 12
+qemu/scripts/rebuild_in_container.sh --from_existing_sources
 ```
 
-The `qemu/manifest.xml` enumerates the dependencies. For each of them it
-reproduces the hierarchy of git submodules. See below how to regenerate this
-file from git metadata.
+`--from_existing_sources` also makes possible to reuse an existing QEMU source checkout
+to iterate faster.
 
-## Local build (Linux only):
+The result is a portable QEMU archive that can be
+found in `/tmp/qemu-build-output/qemu-portable.tar.gz`
 
-Just call `qemu/scripts/rebuild.sh`, specifying a build directory
-where all build outputs will be placed. In case of success,
-the qemu static binaries will be under
-`$BUILD_DIR/qemu-portable.tar.gz`.
+## Development process
 
-```sh
-qemu/scripts/rebuild.sh --build-dir /tmp/qemu-build
-```
+QEMU assembles many source trees that use git submodules. Hence it is more convenient
+to iterate on a checkout based on `git submodules` for development, and to capture the
+state in a `repo` manifest before submitting the changes to AOSP.
 
-The `--run-tests` option can be used to run the QEMU test
-suite just after the build. Note that this currently hangs.
-
-##  Container build (Linux only):
-
-Ensure podman or docker is installed (podman is preferred
-since it will allow you to run containers without being
-root). See Annex A for important configuration information.
-
-The build has been tested with a small Debian10 image e.g.:
-
-```sh
-mkdir /tmp/qemu-build
-podman run --replace --pids-limit=-1 \
-  --interactive --tty \
-  --name qemu-build \
-  --volume .:/src:O \
-  --volume /tmp/qemu-build:/out \
-  docker.io/debian:10-slim
-apt-get update
-apt-get -qy install autoconf libtool texinfo libgbm-dev
-
-/src/qemu/third_party/python/bin/python3 /src/qemu/scripts/rebuild.py --build-dir /out --run-tests
-```
-
-Note: `/src` is mounted with a file overlay so that cargo can write
-`third_party/crossvm/rutabaga_gfx/ffi/Cargo.lock` file. We didn't find
-a way to prevent cargo from writing it.
-
-## Clone the repository with git submodules
-
-The alternateway to get the source and dependencies is to rely on submodules.
 
 ```sh
 git clone sso://experimental-qemu-build-internal.googlesource.com/qemu-build qemu
@@ -72,6 +52,25 @@
 git submodule update --init --depth 1 --recursive --jobs 4
 ```
 
+You can build without isolation with:
+
+```sh
+qemu/scripts/rebuild.sh --build-dir ~/qemu-build.out
+```
+
+You can also build in a container with:
+
+```sh
+qemu/scripts/rebuild_in_container.sh --from_existing_sources
+```
+
+After sucessfull build the ASOP binaries can be updated with:
+
+```sh
+tar -xvf /tmp/qemu-build-output/qemu-portable.tar.gz \
+  -C $ANDROID_BUILD_TOP/device/google/cuttlefish_vmm/qemu/x86_64-linux-gnu
+```
+
 This makes possible to upvert a dependency such as `qemu` and
 regenerate the repo manifest from the submodule tree.
 
diff --git a/qemu/manifest.xml b/qemu/manifest.xml
index 3e2cd7c..bececc7 100644
--- a/qemu/manifest.xml
+++ b/qemu/manifest.xml
@@ -9,12 +9,12 @@
   <project path="qemu/prebuilts/gcc" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8" revision="f7b0d5b0ee369864d5ac3e96ae24ec9e2b6a52da" clone-depth="1" />
   <project path="qemu/prebuilts/ninja" name="platform/prebuilts/ninja/linux-x86" revision="8a10824f74fe0e22af9bf314a837f5b70e2bb67f" clone-depth="1" />
   <project path="qemu/prebuilts/rust" name="platform/prebuilts/rust" revision="ed6633c7a96144bebd982e15da76295d7d6e2de9" clone-depth="1" />
-  <project path="qemu/third_party/aemu" name="platform/hardware/google/aemu" revision="d6e6b99ba6ec2b6b2502aa46dcb57d6b0fa53787" />
+  <project path="qemu/third_party/aemu" name="platform/hardware/google/aemu" revision="dc4b530a0db8472170feef17106c8ade5f3e1459" />
   <project path="qemu/third_party/bzip2" name="platform/external/bzip2" revision="af971b5524a392944a8fd1423b1860f3ab2919ec" />
-  <project path="qemu/third_party/crosvm" name="platform/external/crosvm" revision="f1829e78f44a10d182c0c33cbe582c3a7247cc35" />
+  <project path="qemu/third_party/crosvm" name="platform/external/crosvm" revision="9feae6a4a8f9c79c124a852bfa578b6ed5cdeb34" />
   <project path="qemu/third_party/egl" name="platform/external/egl-registry" revision="9ab603608d6b165f79f17eee9ee1ced861625893" />
   <project path="qemu/third_party/flatbuffers" name="platform/external/flatbuffers" revision="baf9b3a15e291a0c76850a50f994c5947c3f5e5e" />
-  <project path="qemu/third_party/gfxstream" name="platform/hardware/google/gfxstream" revision="f2ee1247e262efc89d8baeacbce5e4e732d16ffc" />
+  <project path="qemu/third_party/gfxstream" name="platform/hardware/google/gfxstream" revision="1cbeb3cf962b5c6d9844945d5e69f5c4735cd145" />
   <project path="qemu/third_party/glib" name="platform/external/bluetooth/glib" revision="180713772f4e7bcdddf2c793f2f34a498184ed15" />
   <project path="qemu/third_party/glib/subprojects/gvdb" name="platform/external/gvdb" revision="0854af0fdb6d527a8d1999835ac2c5059976c210" />
   <project path="qemu/third_party/googletest" name="platform/external/googletest" revision="276e32ec333e05bff6dc7d20218a8d9152623222" />
@@ -29,7 +29,7 @@
   <project path="qemu/third_party/pixman" name="platform/external/pixman" revision="37216a32839f59e8dcaa4c3951b3fcfc3f07852c" />
   <project path="qemu/third_party/pkg-config" name="platform/external/pkg-config" revision="d97db4fae4c1cd099b506970b285dc2afd818ea2" />
   <project path="qemu/third_party/python" name="platform/prebuilts/python/linux-x86" revision="008e82161a393ca8f7ac80f0683d6650ca03b347" />
-  <project path="qemu/third_party/qemu" name="platform/external/qemu" revision="abf635ddfe3242df907f58967f3c1e6763bbca2d" />
+  <project path="qemu/third_party/qemu" name="platform/external/qemu" revision="039afc5ef7367fbc8fb475580c291c2655e856cb" />
   <project path="qemu/third_party/rust/crates/anyhow" name="platform/external/rust/crates/anyhow" revision="bb04cc54d8262ffe33cba59fa600bfbfe7e1d4ef" />
   <project path="qemu/third_party/rust/crates/bitflags" name="platform/external/rust/crates/bitflags" revision="a28a75e883a06f4d384b555e6a6f9c73bb8e875a" />
   <project path="qemu/third_party/rust/crates/byteorder" name="platform/external/rust/crates/byteorder" revision="3717e50a4895f69a726d1489254d9c4ad612c28b" />
diff --git a/qemu/scripts/rebuild.py b/qemu/scripts/rebuild.py
index 115adf8..df4d714 100755
--- a/qemu/scripts/rebuild.py
+++ b/qemu/scripts/rebuild.py
@@ -881,6 +881,7 @@
   }
   rutabaga_src_dir = build.third_party_dir / "crosvm" / "rutabaga_gfx" / "ffi"
   build.run(cmd_args, rutabaga_src_dir, env)
+
   build.copy_file(
       out_dir / "release" / "librutabaga_gfx_ffi.so",
       build.install_dir / "usr" / "lib" / "librutabaga_gfx_ffi.so",
@@ -891,7 +892,7 @@
       env={}
   )
   build.copy_file(
-      rutabaga_src_dir / "src" / "share" / "rutabaga_gfx_ffi.pc",
+      out_dir / "release" / "rutabaga_gfx_ffi.pc",
       build.install_dir / "usr" / "lib" / "pkgconfig" / "rutabaga_gfx_ffi.pc",
   )
   build.copy_file(
diff --git a/qemu/scripts/rebuild_in_container.sh b/qemu/scripts/rebuild_in_container.sh
index 0643a11..a381736 100755
--- a/qemu/scripts/rebuild_in_container.sh
+++ b/qemu/scripts/rebuild_in_container.sh
@@ -50,12 +50,16 @@
 apt-get -qy install autoconf libtool texinfo libgbm-dev && \
 /src/qemu/third_party/python/bin/python3 /src/qemu/scripts/rebuild.py --build-dir /out"
 
+# Note: `/src` is mounted with a file overlay so that cargo can write
+# `third_party/crossvm/rutabaga_gfx/ffi/Cargo.lock` file. We didn't find
+# a way to prevent cargo from writing it.
+
 podman run --name qemu-build \
     --replace \
     --pids-limit=-1 \
     --volume "${SRC_DIR}:/src:O" \
     --volume "${WORK_DIR}:/out" \
-    docker.io/debian:10-slim \
+    docker.io/debian:11-slim \
     bash -c "${COMMAND}"
 
 if [ "$FROM_EXISTING_SOURCES" -eq 0 ]; then