From 0578d8975ebc92930e662fa5818e8dd44dc6b984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Thu, 31 Jan 2019 00:00:01 +0000 Subject: [PATCH] android: understand that rw are qcow2 --- README.adoc | 54 ++++++++++++++++++++++++++++++++++++++++++----------- common.py | 3 +-- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/README.adoc b/README.adoc index 65be40b..34d1912 100644 --- a/README.adoc +++ b/README.adoc @@ -11488,6 +11488,8 @@ The messy AOSP generates a ton of images instead of just one. When the emulator launches, we can see them through QEMU `-drive` arguments: .... +emulator: argv[21] = "-initrd" +emulator: argv[22] = "/data/aosp/8.1.0_r60/out/target/product/generic_x86_64/ramdisk.img" emulator: argv[23] = "-drive" emulator: argv[24] = "if=none,index=0,id=system,file=/path/to/aosp/8.1.0_r60/out/target/product/generic_x86_64/system-qemu.img,read-only" emulator: argv[25] = "-device" @@ -11510,7 +11512,15 @@ emulator: argv[41] = "-device" emulator: argv[42] = "virtio-blk-pci,drive=vendor,iothread=disk-iothread,modern-pio-notify" .... -which tells us that the order is: +The root directory is the <> given on the QEMU CLI, which `/proc/mounts` reports at: + +.... +rootfs on / type rootfs (ro,seclabel,size=886392k,nr_inodes=221598) +.... + +This contains the <>, which through `.rc` must be mounting mounts the drives int o the right places TODO find exact point. + +The drive order is: .... system @@ -11536,19 +11546,15 @@ gives: and we see that the order of `vda`, `vdb`, etc. matches that in which `-drive` were given to QEMU. -I think the root is the <> given on the QEMU CLI: - -.... -rootfs on / type rootfs (ro,seclabel,size=886392k,nr_inodes=221598) -.... - Tested on: `8.1.0_r60`. ===== Android images read-only From `mount`, we can see that some of the mounted images are `ro`. -In order to make `/system` and `/vendor` writable, we must use the `-writable-system` option: +Basically, every image that was given to QEMU as qcow2 is writable, and that qcow2 is an overlay over the actual original image. + +In order to make `/system` and `/vendor` writable by using qcow2 for them as well, we must use the `-writable-system` option: .... ./run-android -- -writable-system @@ -11565,7 +11571,19 @@ mount -o rw,remount /system date >/system/a .... -`/system` and vendor can be nuked quickly with: +Now reboot, and relaunch with `-writable-system` once again to pick up the modified qcow2 images: + +.... +./run-android -- -writable-system +.... + +and the newly created file is still there: + +.... +date >/system/a +.... + +`/system` and `/vendor` can be nuked quickly with: .... ./build-android --extra-args snod @@ -11615,7 +11633,7 @@ we see: which confirms the suspicion that this data goes in `userdata-qemu.img`. -TODO: how to reset `userdata-qemu.img`? https://stackoverflow.com/questions/54446680/how-to-reset-the-userdata-image-when-building-android-aosp-and-running-it-on-the +To reset images to their original state, just remove the qcow2 overlay and regenerate it: https://stackoverflow.com/questions/54446680/how-to-reset-the-userdata-image-when-building-android-aosp-and-running-it-on-the Tested on: `8.1.0_r60`. @@ -11665,7 +11683,21 @@ import /init.usb.configfs.rc import /init.${ro.zygote}.rc .... -TODO: how is `ro.hardware` determined? https://stackoverflow.com/questions/20572781/android-boot-where-is-the-init-hardware-rc-read-in-init-c-where-are-servic +TODO: how is `ro.hardware` determined? https://stackoverflow.com/questions/20572781/android-boot-where-is-the-init-hardware-rc-read-in-init-c-where-are-servic It is a system property and can be obtained with: + +.... +getprop ro.hardware +.... + +This gives: + +.... +ranchu +.... + +which is the codename for the QEMU virtual platform we are running on: https://www.oreilly.com/library/view/android-system-programming/9781787125360/9736a97c-cd09-40c3-b14d-955717648302.xhtml + +TODO: is it possible to add a custom `.rc` file without modifying the initrd that <>? https://stackoverflow.com/questions/9768103/make-persistent-changes-to-init-rc Tested on: `8.1.0_r60`. diff --git a/common.py b/common.py index 2c9d4f6..6571e44 100644 --- a/common.py +++ b/common.py @@ -720,8 +720,7 @@ Valid emulators: {} env['android_build_dir'] = join(env['android_dir'], 'out') env['repo_path'] = join(env['android_base_dir'], 'repo') env['repo_path_base64'] = env['repo_path'] + '.base64' - - env['android_shell_setup'] = ''' + env['android_shell_setup'] = '''\ . build/envsetup.sh lunch aosp_{}-eng '''.format(self.env['android_arch'])