From 301ce08839c459912e209db36ba0af4e786bd590 Mon Sep 17 00:00:00 2001 From: Bruce Po Date: Sat, 30 Jul 2022 00:03:43 +0000 Subject: [PATCH 1/4] Add TARGET_PRODUCT variable to aoc daemon build Add TARGET_PRODUCT variable to aoc daemon build. This will be useful for including/excluding certain features depending on product type, e.g. T6 hotword AP offload. BUG: 240748763 Change-Id: I412309789279830e2380764bb475a9c65b39c355 --- device.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/device.mk b/device.mk index d3725496..cb7a7e65 100644 --- a/device.mk +++ b/device.mk @@ -1036,6 +1036,7 @@ PRODUCT_SOONG_NAMESPACES += \ vendor/google/whitechapel/aoc $(call soong_config_set,aoc,target_soc,$(TARGET_BOARD_PLATFORM)) +$(call soong_config_set,aoc,target_product,$(TARGET_PRODUCT)) # ## Audio properties From 214b76abd3b9ac7a7d1479376f07b3a97528af6e Mon Sep 17 00:00:00 2001 From: Konstantin Vyshetsky Date: Fri, 29 Jul 2022 11:05:13 -0700 Subject: [PATCH 2/4] gs201: add script to migrate persist to ext4 Bug: 239632964 Signed-off-by: Konstantin Vyshetsky Change-Id: If3ac021dec5b25968e83f926518e2881c92d2275 --- conf/init.gs201.rc | 7 +- convert_to_ext4.sh | 176 +++++++++++++++++++++++++++++++++++++++++++++ device.mk | 4 ++ 3 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 convert_to_ext4.sh diff --git a/conf/init.gs201.rc b/conf/init.gs201.rc index 57631ccc..5d945a59 100644 --- a/conf/init.gs201.rc +++ b/conf/init.gs201.rc @@ -2,7 +2,12 @@ import /vendor/etc/init/hw/init.gs201.usb.rc import android.hardware.drm@1.2-service.widevine.rc import init.exynos.sensorhub.rc -on early-init +on early-init && property:ro.debuggable=1 + # Convert /dev/block/by-name/persist to ext4 on userdebug builds only + exec -- /system_ext/bin/convert_to_ext4.sh /dev/block/by-name/persist false + mount_all /vendor/etc/fstab.persist --early + +on early-init && property:ro.debuggable=0 mount_all /vendor/etc/fstab.persist --early on init diff --git a/convert_to_ext4.sh b/convert_to_ext4.sh new file mode 100644 index 00000000..244d86b7 --- /dev/null +++ b/convert_to_ext4.sh @@ -0,0 +1,176 @@ +#!/bin/sh + +PERSIST_BLK='/dev/block/by-name/persist' +EFS_BLK='/dev/block/by-name/efs' +MNT_BASE='/mnt/product' +MNT_OLD="$MNT_BASE/convert_old" +MNT_NEW="$MNT_BASE/convert_new" + +function log() { + if [ ! -z "$1" ]; then + echo "partition_convert: $1" > /dev/kmsg + fi +} + +function check_success() { + RES=$? + if [ $RES -ne 0 ]; then + log "Failed: $1" + else + log "Success: $1" + fi + return $RES +} + +function get_fs_type() +{ + BLOCK=$1 + EXT4_MAGIC=$(xxd $BLOCK -s 0x438 -l 2 -p) + if [ "$EXT4_MAGIC" = "53ef" ]; then + echo "ext4" + else + F2FS_MAGIC=$(xxd $BLOCK -s 0x400 -l 4 -p) + if [ "$F2FS_MAGIC" = "1020f5f2" ]; then + echo "f2fs" + else + echo "unknown" + fi + fi +} + +# Flow: +# 1. If persist is f2fs we need to make efs ext4 and copy out the files. Once files are copied +# successfully, format persist as ext4 to mark completion of step. +# 2. If persist is ext4 and efs is ext4, we need to copy from efs to persist (use dd). Once +# everything is copied successfully, erase efs to allow it to be formatted to f2fs later. +# 3. If persist is ext4 and efs is not ext4, we have already migrated - do nothing. + +# If persist is already ext4 and efs is not ext4 we have already migrated. +PERSIST_FS=$(get_fs_type $PERSIST_BLK) +EFS_FS=$(get_fs_type $EFS_BLK) +if [ "$PERSIST_FS" = "ext4" ]; then + if [ "$EFS_FS" != "ext4" ]; then + log "persist ext4 migration already done" + exit 0 + fi +fi + +if [ "$PERSIST_FS" = "unknown" ]; then + log "persist partition hasn't been initialized" + exit 0 +fi + +RETRIES=10 +while [[ $RETRIES -gt 0 ]]; do + # Sleep for 1 second here, as other failure points will trigger continue + sleep 1 + RETRIES=$((RETRIES-1)) + + # If persist is still f2fs, we need to copy to efs. + if [ "$PERSIST_FS" = "f2fs" ]; then + # Format efs as ext4 + /system/bin/mke2fs -t ext4 -b 4096 $EFS_BLK + check_success "/system/bin/mke2fs -t ext4 -b 4096 $EFS_BLK" + if [ $? -ne 0 ]; then + continue + fi + + #Create directory to mount persist partition + mkdir -p $MNT_OLD + check_success "mkdir $MNT_OLD" + if [ $? -ne 0 ]; then + continue + fi + + # Create directory to mount efs partition + mkdir -p $MNT_NEW + check_success "mkdir $MNT_NEW" + if [ $? -ne 0 ]; then + rm -rf $MNT_OLD + continue + fi + + # Mount persist + mount -t f2fs $PERSIST_BLK $MNT_OLD + check_success "mount -t f2fs $PERSIST_BLK $MNT_OLD" + if [ $? -ne 0 ]; then + rm -rf $MNT_NEW + rm -rf $MNT_OLD + continue + fi + + # Mount efs + mount -t ext4 $EFS_BLK $MNT_NEW + check_success "mount -t ext4 $EFS_BLK $MNT_NEW" + if [ $? -ne 0 ]; then + umount $MNT_OLD + rm -rf $MNT_NEW + rm -rf $MNT_OLD + continue + fi + + cp -rp $MNT_OLD/* $MNT_NEW/ + check_success "cp -rp $MNT_OLD/* $MNT_NEW/" + if [ $? -ne 0 ]; then + umount $MNT_NEW + umount $MNT_OLD + rm -rf $MNT_NEW + rm -rf $MNT_OLD + continue + fi + + # Calculate md5sum of all files and compare between persist and efs + (cd $MNT_NEW; find . -type f | xargs md5sum | sort) > $MNT_NEW/md5sums + (cd $MNT_OLD; find . -type f | xargs md5sum | sort) > $MNT_OLD/md5sums + diff -q $MNT_NEW/md5sums $MNT_OLD/md5sums + check_success "diff -q $MNT_NEW/md5sums $MNT_OLD/md5sums" + RES=$? + + umount $MNT_NEW + umount $MNT_OLD + rm -rf $MNT_NEW + rm -rf $MNT_OLD + + if [ $RES -ne 0 ]; then + continue + fi + + /system/bin/mke2fs -t ext4 -b 4096 $PERSIST_BLK + check_success "/system/bin/mke2fs -t ext4 -b 4096 $PERSIST_BLK" + if [ $? -ne 0 ]; then + continue + fi + + PERSIST_FS="ext4" + fi + + # copy efs to persist + dd if=$EFS_BLK of=$PERSIST_BLK + check_success "dd if=$EFS_BLK of=$PERSIST_BLK" + if [ $? -ne 0 ]; then + continue + fi + + sync + check_success "sync" + if [ $? -ne 0 ]; then + continue + fi + + # compare md5sum for integrity + EFS_MD5SUM=$(dd if=$EFS_BLK 2>/dev/null | md5sum) + PERSIST_MD5SUM=$(dd if=$PERSIST_BLK 2>/dev/null | md5sum) + if [ "$PERSIST_MD5SUM" != "$EFS_MD5SUM" ]; then + log "dd md5sum mismatch" + continue + fi + + dd if=/dev/zero of=$EFS_BLK bs=1M count=64 + check_success "dd if=/dev/zero of=$EFS_BLK bs=1M count=64" + if [ $? -ne 0 ]; then + continue + fi + + log "Migration succeeded" + break +done diff --git a/device.mk b/device.mk index ead6eafb..627fee5c 100644 --- a/device.mk +++ b/device.mk @@ -337,6 +337,10 @@ PRODUCT_PACKAGES += \ tune2fs.vendor_ramdisk \ resize2fs.vendor_ramdisk +# Filesystem: convert /dev/block/by-name/persist to ext4 (b/239632964) +PRODUCT_COPY_FILES += \ + device/google/gs201/convert_to_ext4.sh:$(TARGET_COPY_OUT_SYSTEM_EXT)/bin/convert_to_ext4.sh \ + # Userdata Checkpointing OTA GC PRODUCT_PACKAGES += \ checkpoint_gc From 83e0b84caf41c42fd3f0b6494017570bd88f6e6e Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Thu, 21 Jul 2022 17:19:34 -0700 Subject: [PATCH 3/4] Use EXT4 for /persist Bug: 239632964 Signed-off-by: Jaegeuk Kim Change-Id: Idf41e3b71fec50029b77951550def1b8c750a42d --- BoardConfig-common.mk | 2 +- conf/fstab.persist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BoardConfig-common.mk b/BoardConfig-common.mk index 34620e75..9ca97737 100644 --- a/BoardConfig-common.mk +++ b/BoardConfig-common.mk @@ -184,7 +184,7 @@ BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE := ext4 TARGET_COPY_OUT_SYSTEM_EXT := system_ext # persist.img -BOARD_PERSISTIMAGE_FILE_SYSTEM_TYPE := f2fs +BOARD_PERSISTIMAGE_FILE_SYSTEM_TYPE := ext4 ######################## # Video Codec diff --git a/conf/fstab.persist b/conf/fstab.persist index ab0631b6..b9dda71a 100644 --- a/conf/fstab.persist +++ b/conf/fstab.persist @@ -1,5 +1,5 @@ # Android fstab file. # # Keep persist in an fstab file, since we need to run fsck on it after abnormal shutdown. -/dev/block/platform/14700000.ufs/by-name/persist /mnt/vendor/persist f2fs noatime,nosuid,nodev,sync wait,check,formattable /dev/block/platform/14700000.ufs/by-name/persist /mnt/vendor/persist ext4 noatime,nosuid,nodev,data=journal,commit=1 wait,check,formattable,metadata_csum +/dev/block/platform/14700000.ufs/by-name/persist /mnt/vendor/persist f2fs noatime,nosuid,nodev,sync wait,check,formattable From b108713200e91992aafb45f3d69f3241c9cac3cb Mon Sep 17 00:00:00 2001 From: Andrew Chant Date: Fri, 22 Jul 2022 16:52:51 -0700 Subject: [PATCH 4/4] gs201: convert_to_ext4: copy .files, fix md5sum Copy files in persist/.* Don't leave md5sums file in the persist folder. Bug: 239632964 Signed-off-by: Andrew Chant Change-Id: I7d351806f95ccc28fcfec4d45ecf3bda488e7e15 --- convert_to_ext4.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/convert_to_ext4.sh b/convert_to_ext4.sh index 244d86b7..a349df96 100644 --- a/convert_to_ext4.sh +++ b/convert_to_ext4.sh @@ -109,6 +109,7 @@ while [[ $RETRIES -gt 0 ]]; do continue fi + cp -rp $MNT_OLD/.* $MNT_NEW/ cp -rp $MNT_OLD/* $MNT_NEW/ check_success "cp -rp $MNT_OLD/* $MNT_NEW/" if [ $? -ne 0 ]; then @@ -120,11 +121,12 @@ while [[ $RETRIES -gt 0 ]]; do fi # Calculate md5sum of all files and compare between persist and efs - (cd $MNT_NEW; find . -type f | xargs md5sum | sort) > $MNT_NEW/md5sums - (cd $MNT_OLD; find . -type f | xargs md5sum | sort) > $MNT_OLD/md5sums - diff -q $MNT_NEW/md5sums $MNT_OLD/md5sums - check_success "diff -q $MNT_NEW/md5sums $MNT_OLD/md5sums" + (cd $MNT_NEW; find . -type f | xargs md5sum | sort) > $MNT_BASE/new.md5sums + (cd $MNT_OLD; find . -type f | xargs md5sum | sort) > $MNT_BASE/old.md5sums + diff $MNT_BASE/new.md5sums $MNT_BASE/old.md5sums + check_success "diff $MNT_BASE/new.md5sums $MNT_BASE/old.md5sums" RES=$? + rm $MNT_BASE/new.md5sums $MNT_BASE/old.md5sums umount $MNT_NEW umount $MNT_OLD