Put ferrochrome image into the app
This CL includes the follwing changes:
* The ferrochrome image is included in the app as an asset. It's not
downloaded.
* The image is a compressed archive having four partition images. The
archive was created as follows:
- chromium_base_image.bin is downloaded
- all 12 partitions are extracted using the unpack_partitions.sh
script
- four partitions (efi, root, kernel, state) are archieved using tar
with the --sparse option
* At runtime, the archive is extracted to /data/local/tmp and the copy
of the archive in /data/media/<user_id>/ferrochrome is deleted to save
space.
* The VM config now specifis a composite disk where partitions are from
the extracted partition images.
* The state.img is rounded up to the multiple of 4K as required by
crosvm.
Note: this change does NOT include the ferrochrome image. It will be
uploaded to the internal gerrit.
Bug: 351973725
Bug: 351904150
Test: run ferrochrome app
Change-Id: I12a6a1efa270065780a1cbdc61a3edd92f4f28aa
diff --git a/ferrochrome_app/custom_vm_setup.sh b/ferrochrome_app/custom_vm_setup.sh
index f007f6a..a5480ff 100644
--- a/ferrochrome_app/custom_vm_setup.sh
+++ b/ferrochrome_app/custom_vm_setup.sh
@@ -1,14 +1,31 @@
#!/system/bin/sh
-function copy_files() {
- cp -u /sdcard/vm_config.json /data/local/tmp
- cp -u /data/media/10/vm_config.json /data/local/tmp
- cp -u /sdcard/chromiumos_test_image.bin /data/local/tmp
- cp -u /data/media/10/chromiumos_test_image.bin /data/local/tmp
- chmod 666 /data/local/tmp/vm_config.json
- chmod 666 /data/local/tmp/chromiumos_test_image.bin
+function round_up() {
+ num=$1
+ div=$2
+ echo $((( (( ${num} / ${div} ) + 1) * ${div} )))
}
+
+function install() {
+ user=$(cmd user get-main-user)
+ src_dir=/data/media/${user}/ferrochrome/
+ dst_dir=/data/local/tmp/
+
+ cat $(find ${src_dir} -name "images.tar.gz*" | sort) | tar xz -C ${dst_dir}
+ cp -u ${src_dir}vm_config.json ${dst_dir}
+ chmod 666 ${dst_dir}*
+
+ # increase the size of state.img to the multiple of 4096
+ num_blocks=$(du -b -K ${dst_dir}state.img | cut -f 1)
+ required_num_blocks=$(round_up ${num_blocks} 4)
+ additional_blocks=$((( ${required_num_blocks} - ${num_blocks} )))
+ dd if=/dev/zero bs=512 count=${additional_blocks} >> ${dst_dir}state.img
+
+ rm ${src_dir}images.tar.gz*
+ rm ${src_dir}vm_config.json
+}
+
setprop debug.custom_vm_setup.done false
-copy_files
+install
setprop debug.custom_vm_setup.start false
setprop debug.custom_vm_setup.done true