From 60dc6764094175a241bdccd7af7d783a2cbdd334 Mon Sep 17 00:00:00 2001 From: Juan Yescas Date: Sat, 17 Aug 2024 12:22:14 -0700 Subject: [PATCH] Copy files on efs/efs_backup/modem_userdata/persist partitions to /data in 16kb mode There are 4 partitions that are flashed at the factory and use F2FS fs with 4kb block size: - /dev/block/by-name/efs - /dev/block/by-name/efs_backup - /dev/block/by-name/modem_userdata - /dev/block/by-name/persist These partitions can NOT be mounted by 16kb kernels because F2FS expects BLOCK_SIZE == PAGE_SIZE. In order to access the files in these partitions by 16kb kernels, the dump.f2fs tool is used. This change will perform these steps at boot time ONLY for 16kb mode. For every partition (efs/efs_backup/modem_userdata/persist): 1. Use dump.f2fs to copy the content of the partition to /data/vendor/copied/.img. 2. If the copy was succesfull, rename /data/vendor/copied/.img to /data/vendor/copied/ 3. fsync the content of the directory /data/vendor/copied/. After the content of the partitions is in /data/vendor/copied, bind-mount the partitions to the directory /mnt/vendor. See conf/fstab.efs.from_data. Note: This change ONLY applies to 16kb kernels. This change does not modify the original partitions. Bug: 347015136 Bug: 362368691 Test: $ source build/envsetup.sh $ lunch [zumapro]-trunk_staging-userdebug $ m $ ./vendor/google/tools/flashall -w Flag: EXEMPT bugfix Change-Id: Idf46a2a3a4f0b2e91ee4a0322a0c469e055684c8 --- Android.bp | 10 +++++++ conf/fstab.efs.from_data | 10 +++++++ conf/init.efs.16k.rc | 24 +++++++++++++++++ conf/{init.efs.rc => init.efs.4k.rc} | 0 copy_efs_files_to_data.sh | 39 ++++++++++++++++++++++++++++ device.mk | 13 +++++++++- 6 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 conf/fstab.efs.from_data create mode 100644 conf/init.efs.16k.rc rename conf/{init.efs.rc => init.efs.4k.rc} (100%) create mode 100644 copy_efs_files_to_data.sh diff --git a/Android.bp b/Android.bp index 7156389..b79b895 100644 --- a/Android.bp +++ b/Android.bp @@ -41,3 +41,13 @@ sh_binary { vendor: true, sub_dir: "hw", } + +// Filesystem: Copy the content of the efs/efs_backup/modem_userdata/persist +// partitions to /data partition so that they can be accessed by 16kb kernels. +// By default, these partitions are F2FS formatted with 4kb block size, +// which can't be mounted by 16kb kernels. +sh_binary { + name: "copy_efs_files_to_data", + src: "copy_efs_files_to_data.sh", + vendor: true, +} diff --git a/conf/fstab.efs.from_data b/conf/fstab.efs.from_data new file mode 100644 index 0000000..57aac9c --- /dev/null +++ b/conf/fstab.efs.from_data @@ -0,0 +1,10 @@ +# Android fstab file. +# +# Create the specific fstab file for efs/modem_userdata/persist partitions for flexibility +/data/vendor/copied/efs /mnt/vendor/efs none bind latemount + +/data/vendor/copied/efs_backup /mnt/vendor/efs_backup none bind latemount + +/data/vendor/copied/modem_userdata /mnt/vendor/modem_userdata none bind latemount + +/data/vendor/copied/persist /mnt/vendor/persist none bind latemount diff --git a/conf/init.efs.16k.rc b/conf/init.efs.16k.rc new file mode 100644 index 0000000..c2a2eab --- /dev/null +++ b/conf/init.efs.16k.rc @@ -0,0 +1,24 @@ +service copy_efs_files_to_data /vendor/bin/copy_efs_files_to_data + user root + group root radio system audio media graphics camera + stdio_to_kmsg + oneshot + disabled + +on post-fs-data + mkdir /data/vendor/copied 0775 radio system + restorecon_recursive /data/vendor/copied + exec_start copy_efs_files_to_data + mount_all /vendor/etc/fstab.efs.from_data + restorecon_recursive /mnt/vendor/persist + restorecon_recursive /data/vendor/ss + setprop ro.vendor.persist.status mounted + +on late-fs + # for modem related functions + restorecon_recursive /mnt/vendor/efs + chown radio system /mnt/vendor/efs + restorecon_recursive /mnt/vendor/efs_backup + chown radio system /mnt/vendor/efs_backup + restorecon_recursive /mnt/vendor/modem_userdata + chown radio system /mnt/vendor/modem_userdata diff --git a/conf/init.efs.rc b/conf/init.efs.4k.rc similarity index 100% rename from conf/init.efs.rc rename to conf/init.efs.4k.rc diff --git a/copy_efs_files_to_data.sh b/copy_efs_files_to_data.sh new file mode 100644 index 0000000..b6b7a9d --- /dev/null +++ b/copy_efs_files_to_data.sh @@ -0,0 +1,39 @@ +#!/vendor/bin/sh + +CHECKPOINT_DIR=/data/vendor/copied + +export BIN_DIR=/vendor/bin + +$BIN_DIR/mkdir -p $CHECKPOINT_DIR + +function copy_files_to_data() +{ + block_device=$1 + partition_name=$(basename $1) + mount_point=$2 + tmpdir=$CHECKPOINT_DIR/$partition_name.img + build_checkpoint=$CHECKPOINT_DIR/$partition_name + if [ ! -e $build_checkpoint ]; then + $BIN_DIR/rm -rf $tmpdir + $BIN_DIR/mkdir -p $tmpdir + $BIN_DIR/dump.f2fs -rfPo $tmpdir $block_device + if [ $? -ne 0 ]; then + echo "Failed to $BIN_DIR/dump.f2fs -rfPo $tmpdir $block_device" + return + fi + $BIN_DIR/mv $tmpdir $build_checkpoint + if [ $? -ne 0 ]; then + echo "mv $tmpdir $build_checkpoint" + return + fi + $BIN_DIR/fsync `dirname $build_checkpoint` + fi + echo "Successfully copied $mount_point to $build_checkpoint" +} + +copy_files_to_data "/dev/block/by-name/efs" "/mnt/vendor/efs" +copy_files_to_data "/dev/block/by-name/efs_backup" "/mnt/vendor/efs_backup" +copy_files_to_data "/dev/block/by-name/modem_userdata" "/mnt/vendor/modem_userdata" +copy_files_to_data "/dev/block/by-name/persist" "/mnt/vendor/persist" + +$BIN_DIR/fsync /data/vendor/copied diff --git a/device.mk b/device.mk index 34e2975..9091393 100644 --- a/device.mk +++ b/device.mk @@ -451,9 +451,20 @@ PRODUCT_COPY_FILES += \ device/google/zumapro/conf/init.zumapro.soc.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/hw/init.zumapro.soc.rc \ device/google/zumapro/conf/init.zuma.soc.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/hw/init.zuma.soc.rc \ device/google/zumapro/conf/init.zumapro.board.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/hw/init.zumapro.board.rc \ - device/google/zumapro/conf/init.efs.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/hw/init.efs.rc \ device/google/zumapro/conf/init.persist.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/hw/init.persist.rc +ifeq (true,$(filter $(TARGET_BOOTS_16K) $(PRODUCT_16K_DEVELOPER_OPTION),true)) +PRODUCT_COPY_FILES += \ + device/google/zumapro/conf/init.efs.16k.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/hw/init.efs.rc \ + device/google/zumapro/conf/fstab.efs.from_data:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.efs.from_data + +PRODUCT_PACKAGES += copy_efs_files_to_data +PRODUCT_PACKAGES += fsck.f2fs.vendor +else +PRODUCT_COPY_FILES += \ + device/google/zumapro/conf/init.efs.4k.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/hw/init.efs.rc +endif + ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT))) PRODUCT_COPY_FILES += \ device/google/zumapro/conf/init.debug.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.debug.rc