From 407842a575b2d7ac3a032f87c2380586d71d6fc6 Mon Sep 17 00:00:00 2001 From: "Eugene San (eugenesan)" Date: Fri, 4 Sep 2015 09:17:59 -0400 Subject: [PATCH] Switch to Nexus style data layout and allow exporting data components to external sdcard Use internal data as in Nexus devices (sdcard0 is emulated). External sdcard now called sdcard1. Optional second partition of external sdcard (data1) can be used to store selected data components such as: app, data, media and dalvik-cache. To do so, one must create a folder with a name of the component/s on data1. We register sdcard1 as secondary storage allowing built-in asec mechanism to be used to move apps to it. We also add misc recovery related settings and coresponding changes to TWRP in order to support above and backup of emulated internal sdcard and apps in asac container. To summarize, this patch allows user to encrypt device including sdcard0 and place selected data components on external sdcard. Change-Id: Ib52086347eb1f8fc9fd11031428f2c49bdda9afb --- BoardConfig.mk | 15 +++--- device_pyramid.mk | 1 + .../base/core/res/res/xml/storage_list.xml | 43 +++++++-------- recovery.fstab | 15 +++--- recovery/root/etc/twrp.fstab | 21 ++++---- rootdir/Android.mk | 8 +++ rootdir/etc/fstab.pyramid | 37 ++++++------- rootdir/etc/init.pyramid.rc | 54 ++++++++++++------- rootdir/etc/init.pyramid.sh | 28 ++++++++++ rootdir/etc/remount.pyramid | 4 +- 10 files changed, 138 insertions(+), 88 deletions(-) mode change 100755 => 100644 rootdir/etc/fstab.pyramid create mode 100755 rootdir/etc/init.pyramid.sh mode change 100755 => 100644 rootdir/etc/remount.pyramid diff --git a/BoardConfig.mk b/BoardConfig.mk index 36d9b930..df724901 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -29,7 +29,6 @@ TARGET_SPECIFIC_HEADER_PATH := $(LOCAL_PATH)/include BOARD_VENDOR := htc - # Bootloader TARGET_NO_BOOTLOADER := true @@ -79,7 +78,6 @@ AUDIO_FEATURE_ENABLED_FM := true TARGET_GPS_HAL_PATH := $(LOCAL_PATH)/gps BOARD_VENDOR_QCOM_GPS_LOC_API_AMSS_VERSION := 50000 - # Graphics USE_OPENGL_RENDERER := true TARGET_DISPLAY_USE_RETIRE_FENCE := true @@ -87,6 +85,7 @@ TARGET_USES_C2D_COMPOSITION := true TARGET_USES_ION := true NUM_FRAMEBUFFER_SURFACE_BUFFERS := 3 TARGET_DISPLAY_INSECURE_MM_HEAP := true +DEVICE_RESOLUTION := 540x960 # Media TARGET_NO_ADAPTIVE_PLAYBACK := true @@ -112,11 +111,14 @@ BOARD_MKBOOTIMG_ARGS := --ramdisk_offset 0x01400000 TARGET_KERNEL_CONFIG := pyramid_defconfig TARGET_KERNEL_SOURCE := kernel/htc/pyramid +# Recovery +TARGET_RECOVERY_DEVICE_MODULES += chargeled TARGET_RECOVERY_FSTAB := device/htc/pyramid/rootdir/etc/fstab.pyramid RECOVERY_FSTAB_VERSION := 2 TARGET_RECOVERY_PIXEL_FORMAT := "RGBX_8888" RECOVERY_GRAPHICS_USE_LINELENGTH := true TARGET_RECOVERY_DEVICE_DIRS += device/htc/pyramid +RECOVERY_SDCARD_ON_DATA := true # Required for Sensors COMMON_GLOBAL_CFLAGS += -DNEEDS_VECTORIMPL_SYMBOLS @@ -148,9 +150,6 @@ BOARD_SUPPRESS_EMMC_WIPE := true # Use dlmalloc MALLOC_IMPL := dlmalloc -# Recovery -TARGET_RECOVERY_DEVICE_MODULES += chargeled - # SELinux -include device/qcom/sepolicy/sepolicy.mk @@ -173,7 +172,7 @@ BOARD_SYSTEMIMAGE_PARTITION_SIZE := 838859776 BOARD_USERDATAIMAGE_PARTITION_SIZE := 1252770816 BOARD_FLASH_BLOCK_SIZE := 262144 -# Twrp +# TWRP TW_THEME := portrait_mdpi TW_INCLUDE_CRYPTO := true TW_NO_SCREEN_BLANK := true @@ -183,3 +182,7 @@ TW_NEW_ION_HEAP := true TW_INCLUDE_NTFS_3G := true TW_BRIGHTNESS_PATH := "/sys/class/leds/lcd-backlight/brightness" TARGET_USE_CUSTOM_LUN_FILE_PATH := "/sys/devices/platform/msm_hsusb/gadget/lun0/file" +TW_BACKUP_DATA_MEDIA := true +TW_INTERNAL_STORAGE_PATH := /sdcard +TW_EXTERNAL_STORAGE_PATH := /sdcard1 +TW_INCLUDE_L_CRYPTO := true diff --git a/device_pyramid.mk b/device_pyramid.mk index d759d421..de6cbaf9 100644 --- a/device_pyramid.mk +++ b/device_pyramid.mk @@ -149,6 +149,7 @@ DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/overlay # Ramdisk PRODUCT_PACKAGES += \ fstab.pyramid \ + init.pyramid.sh \ init.pyramid.rc \ init.pyramid.usb.rc \ ueventd.pyramid.rc \ diff --git a/overlay/frameworks/base/core/res/res/xml/storage_list.xml b/overlay/frameworks/base/core/res/res/xml/storage_list.xml index 208b2c3f..5d92fdae 100644 --- a/overlay/frameworks/base/core/res/res/xml/storage_list.xml +++ b/overlay/frameworks/base/core/res/res/xml/storage_list.xml @@ -1,7 +1,7 @@ - + - - + + + + + + android:storageDescription="@string/storage_usb" + android:removable="true" /> diff --git a/recovery.fstab b/recovery.fstab index 780f9a78..bf1959e1 100644 --- a/recovery.fstab +++ b/recovery.fstab @@ -1,10 +1,11 @@ -# mount point fstype device [device2] [length=] +# mount point fstype device [device2] [length=] -/recovery emmc /dev/block/mmcblk0p21 -/boot emmc /dev/block/mmcblk0p20 -/cache ext4 /dev/block/mmcblk0p24 -/data ext4 /dev/block/mmcblk0p23 length=-16384 -/sd-ext ext4 /dev/block/mmcblk1p2 -/sdcard vfat /dev/block/mmcblk1p1 +/boot emmc /dev/block/mmcblk0p20 +/recovery emmc /dev/block/mmcblk0p21 /system ext4 /dev/block/mmcblk0p22 +/data f2fs /dev/block/mmcblk0p23 length=-16384 +/cache f2fs /dev/block/mmcblk0p24 /misc emmc /dev/block/mmcblk0p31 +/sdcard1 vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1 flags=display="sdcard1";storage;wipeingui;removable +/data1 f2fs /dev/block/mmcblk1p2 /dev/block/mmcblk1 flags=display="data1";wipeingui;removable +/usbdisk vfat /dev/block/sda1 /dev/block/sda flags=display="usbdisk";storage;wipeingui;removable diff --git a/recovery/root/etc/twrp.fstab b/recovery/root/etc/twrp.fstab index 82a48d70..d24c4484 100644 --- a/recovery/root/etc/twrp.fstab +++ b/recovery/root/etc/twrp.fstab @@ -1,12 +1,11 @@ -# mount point fstype device [device2] [length=] - -/boot emmc /dev/block/mmcblk0p20 -/recovery emmc /dev/block/mmcblk0p21 -/system ext4 /dev/block/mmcblk0p22 -/data ext4 /dev/block/mmcblk0p23 length=-16384 -/cache ext4 /dev/block/mmcblk0p24 -/misc emmc /dev/block/mmcblk0p31 -/sdcard vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1 flags=display="MicroSD card";storage;wipeingui;removable -/sd-ext ext4 /dev/block/mmcblk1p2 flags=display="SD-Ext";wipeingui;removable -#/usb-otg vfat /dev/block/sda1 /dev/block/sda flags=display="USB OTG";storage;wipeingui;removable +# mount point fstype device [device2] [length=] +/boot emmc /dev/block/mmcblk0p20 +/recovery emmc /dev/block/mmcblk0p21 +/system ext4 /dev/block/mmcblk0p22 +/data f2fs /dev/block/mmcblk0p23 length=-16384 +/cache f2fs /dev/block/mmcblk0p24 +/misc emmc /dev/block/mmcblk0p31 +/sdcard1 vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1 flags=display="sdcard1";andsec;storage;wipeingui;removable +/data1 f2fs /dev/block/mmcblk1p2 /dev/block/mmcblk1 flags=display="data1";wipeingui;removable +/usbdisk vfat /dev/block/sda1 /dev/block/sda flags=display="usbdisk";storage;wipeingui;removable diff --git a/rootdir/Android.mk b/rootdir/Android.mk index 346808f8..6b6a7c06 100644 --- a/rootdir/Android.mk +++ b/rootdir/Android.mk @@ -8,6 +8,14 @@ LOCAL_SRC_FILES := etc/fstab.pyramid LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT) include $(BUILD_PREBUILT) +include $(CLEAR_VARS) +LOCAL_MODULE := init.pyramid.sh +LOCAL_MODULE_TAGS := optional eng +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := etc/init.pyramid.sh +LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT) +include $(BUILD_PREBUILT) + include $(CLEAR_VARS) LOCAL_MODULE := init.pyramid.rc LOCAL_MODULE_TAGS := optional eng diff --git a/rootdir/etc/fstab.pyramid b/rootdir/etc/fstab.pyramid old mode 100755 new mode 100644 index dd914230..59c9dffe --- a/rootdir/etc/fstab.pyramid +++ b/rootdir/etc/fstab.pyramid @@ -1,25 +1,26 @@ # Android fstab file. -# -#/dev/block/platform/msm_sdcc.1/by-name/dsps /firmware_dsps vfat ro,shortname=lower wait -/dev/block/platform/msm_sdcc.1/by-name/radio /firmware_radio vfat ro,shortname=lower,context=u:object_r:firmware_file:s0 wait -/dev/block/platform/msm_sdcc.1/by-name/adsp /firmware_q6 vfat ro,shortname=lower,context=u:object_r:firmware_file:s0 wait -#/dev/block/platform/msm_sdcc.1/by-name/wcnss /firmware_wcnss vfat ro,shortname=lower wait - -/dev/block/platform/msm_sdcc.1/by-name/boot /boot emmc defaults defaults -/dev/block/platform/msm_sdcc.1/by-name/recovery /recovery emmc defaults defaults -/dev/block/platform/msm_sdcc.1/by-name/misc /misc emmc defaults defaults -/dev/block/platform/msm_sdcc.1/by-name/devlog /devlog ext4 noatime,nosuid,nodev,barrier=0 wait -/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 rw,noatime,barrier=0 wait -/dev/block/platform/msm_sdcc.1/by-name/cache /cache ext4 noatime,nosuid,nodev,barrier=0 wait -/dev/block/platform/msm_sdcc.1/by-name/cache /cache f2fs rw,discard,nosuid,nodev,noatime,nodiratime,inline_xattr wait,check -/dev/block/platform/msm_sdcc.1/by-name/userdata /data ext4 noatime,nosuid,nodev,noauto_da_alloc,barrier=0 wait,encryptable=footer,length=-16384 -/dev/block/platform/msm_sdcc.1/by-name/userdata /data f2fs rw,discard,nosuid,nodev,noatime,nodiratime,inline_xattr wait,check,encryptable=footer,length=-16384 +# +#/dev/block/platform/msm_sdcc.1/by-name/dsps /firmware_dsps vfat ro,shortname=lower wait +/dev/block/platform/msm_sdcc.1/by-name/radio /firmware_radio vfat ro,shortname=lower,context=u:object_r:firmware_file:s0 wait +/dev/block/platform/msm_sdcc.1/by-name/adsp /firmware_q6 vfat ro,shortname=lower,context=u:object_r:firmware_file:s0 wait +#/dev/block/platform/msm_sdcc.1/by-name/wcnss /firmware_wcnss vfat ro,shortname=lower wait +/dev/block/platform/msm_sdcc.1/by-name/boot /boot emmc defaults defaults +/dev/block/platform/msm_sdcc.1/by-name/recovery /recovery emmc defaults defaults +/dev/block/platform/msm_sdcc.1/by-name/misc /misc emmc defaults defaults +/dev/block/platform/msm_sdcc.1/by-name/devlog /devlog ext4 noatime,nosuid,nodev,barrier=0 wait +/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,noatime,barrier=1 wait +/dev/block/platform/msm_sdcc.1/by-name/cache /cache ext4 noatime,nosuid,nodev,barrier=1,data=ordered,nomblk_io_submit,noauto_da_alloc,errors=panic wait,check +/dev/block/platform/msm_sdcc.1/by-name/cache /cache f2fs rw,discard,nosuid,nodev,noatime,nodiratime,inline_xattr wait,check +/dev/block/platform/msm_sdcc.1/by-name/userdata /data ext4 noatime,nosuid,nodev,barrier=1,data=ordered,nomblk_io_submit,noauto_da_alloc,errors=panic wait,check,encryptable=footer,length=-16384 +/dev/block/platform/msm_sdcc.1/by-name/userdata /data f2fs noatime,nodiratime,nosuid,nodev,inline_xattr,discard,rw wait,check,encryptable=footer,length=-16384 +/dev/block/platform/msm_sdcc.3/by-num/p2 /data1 ext4 noatime,nosuid,nodev,barrier=1,data=ordered,nomblk_io_submit,noauto_da_alloc,errors=panic wait,check +/dev/block/platform/msm_sdcc.3/by-num/p2 /data1 f2fs noatime,nodiratime,nosuid,nodev,inline_xattr,discard,rw wait,check # SD card -/devices/platform/msm_sdcc.3/mmc_host/mmc1* auto vfat defaults voldmanaged=sdcard0:auto,noemulatedsd +/devices/platform/msm_sdcc.3/mmc_host/mmc1* auto vfat defaults voldmanaged=sdcard1:auto,noemulatedsd # USB storage -/devices/platform/msm_hsusb_host.0/usb1* auto auto defaults voldmanaged=usbdisk:auto +d* auto auto defaults voldmanaged=usbdisk:auto,noemulatedsd # ZRAM -/dev/block/zram0 none swap defaults zramsize=268435456 +/dev/block/zram0 none swap defaults zramsize=268435456 \ No newline at end of file diff --git a/rootdir/etc/init.pyramid.rc b/rootdir/etc/init.pyramid.rc index 95935e52..26308de3 100755 --- a/rootdir/etc/init.pyramid.rc +++ b/rootdir/etc/init.pyramid.rc @@ -11,17 +11,28 @@ on early-init on init mkdir /devlog 0700 root root - mkdir /mnt/media_rw/sdcard0 0700 media_rw media_rw - mkdir /mnt/media_rw/usbdisk 0700 media_rw media_rw - mkdir /storage/sdcard0 0700 root root - mkdir /storage/usbdisk 0700 root root + # See storage config details at http://source.android.com/tech/storage/ + mkdir /mnt/shell/emulated 0700 shell shell + mkdir /storage/emulated 0555 root root - # for backwards compatibility - symlink /storage/sdcard0 /sdcard - symlink /storage/sdcard0 /mnt/sdcard - symlink /storage/usbdisk /usbdisk - symlink /storage/usbdisk /mnt/usbdisk + export EXTERNAL_STORAGE /storage/emulated/legacy + export EMULATED_STORAGE_SOURCE /mnt/shell/emulated + export EMULATED_STORAGE_TARGET /storage/emulated + + # Secondary storage + mkdir /mnt/media_rw/sdcard1 0700 media_rw media_rw + mkdir /storage/sdcard1 0700 root root + export SECONDARY_STORAGE /storage/sdcard1 + + # Secondary data (optional) + mkdir /data1 0771 root root + + # Support legacy paths + symlink /storage/emulated/legacy /sdcard + symlink /storage/emulated/legacy /mnt/sdcard + symlink /storage/emulated/legacy /storage/sdcard0 + symlink /mnt/shell/emulated/0 /storage/emulated/legacy setprop ro.usb.idproduct.ums 0c86 setprop ro.usb.idproduct.rndis 0c86 @@ -29,11 +40,7 @@ on init setprop ro.usb.idproduct.mtp_adb 0f87 setprop ro.usb.idproduct.ptp 0f87 - export EXTERNAL_STORAGE /storage/sdcard0 - export SECONDARY_STORAGE /storage/usbdisk - on fs - # create firmware mount points mkdir /firmware_radio 0771 system system mkdir /firmware_q6 0771 system system @@ -51,13 +58,17 @@ on fs chmod 0644 /proc/cmdline setprop ro.crypto.tmpfs_options size=128m,mode=0771,uid=1000,gid=1000 + setprop ro.crypto.fuse_sdcard true # Force loading of modem and Q6 images write /dev/smd_pkt_loopback 1 - # link widevine drm library path + # link widevine drm library path symlink /system/vendor/lib /vendor/lib + # run device's script + exec /init.pyramid.sh + mount_all /remount.pyramid on post-fs-data @@ -65,6 +76,8 @@ on post-fs-data chown root root /devlog chmod 0700 /devlog + mkdir /data/media 0770 media_rw media_rw + # Set indication (checked by vold) that we have finished this action setprop vold.post_fs_data_done 1 @@ -262,13 +275,14 @@ service iprenew_wlan0 /system/bin/dhcpcd -n oneshot # wifi-- -service fuse_sdcard0 /system/bin/sdcard -u 1023 -g 1023 -d /mnt/media_rw/sdcard0 /storage/sdcard0 - class late_start - disabled +# external sdcard daemon running as media_rw (1023) +service fuse_sdcard1 /system/bin/sdcard -u 1023 -g 1023 -d /mnt/media_rw/sdcard1 /storage/sdcard1 + class late_start + disabled -service fuse_usbdisk /system/bin/sdcard -u 1023 -g 1023 -d /mnt/media_rw/usbdisk /storage/usbdisk - class late_start - disabled +# virtual sdcard daemon running as media_rw (1023) +service sdcard /system/bin/sdcard -u 1023 -g 1023 -l /data/media /mnt/shell/emulated + class late_start on property:init.svc.bootanim=stopped start qcom-post-boot diff --git a/rootdir/etc/init.pyramid.sh b/rootdir/etc/init.pyramid.sh new file mode 100755 index 00000000..4429f84b --- /dev/null +++ b/rootdir/etc/init.pyramid.sh @@ -0,0 +1,28 @@ +#!/system/bin/sh + +export PATH=${PATH}:/system/bin/:/system/xbin/ + +# Log related mounts and mount points before +log -p i -t userinit "[${0}] Before" +echo "[${0}] Before" >> /cache/${0}.log +mount >> /cache/${0}.log +ls -la /data/ >> /cache/${0}.log +ls -la /data1/ >> /cache/${0}.log + +# Attempt to link data content to secondary data (optional) +# If we fail those locations will be used as usual +# Ensure permissions are set correctly +test -d /data1/app && chmod 0771 /data1/app && chown system:system /data1/app && rm -Rf /data/app && ln -s /data1/app /data/app && log -p i -t userinit "[${0}] Linked /data1/app" && echo "[${0}] Linked /data1/app" >> /cache/${0}.log +#test -d /data1/app-asec && chmod 0700 /data1/app-asec && chown root:root /data1/app-asec && rm -Rf /data/app-asec && ln -s /data1/app-asec /data/app-asec && log -p i -t userinit "[${0}] Linked /data1/app-asec" && echo "[${0}] Linked /data1/app-asec" >> /cache/${0}.log +#test -d /data1/app-lib && chmod 0771 /data1/app-lib && chown system:system /data1/app-lib && rm -Rf /data/app-lib && ln -s /data1/app-lib /data/app-lib && log -p i -t userinit "[${0}] Linked /data1/app-lib" && echo "[${0}] Linked /data1/app-lib" >> /cache/${0}.log +#test -d /data1/app-private && chmod 0771 /data1/app-private && chown system:system /data1/app-private && rm -Rf /data/app-private && ln -s /data1/app-private /data/app-private && log -p i -t userinit "[${0}] Linked /data1/app-private" && echo "[${0}] Linked /data1/app-private" >> /cache/${0}.log +test -d /data1/dalvik-cache && chmod 0771 /data1/dalvik-cache && chown root:root /data1/dalvik-cache && rm -Rf /data/dalvik-cache && ln -s /data1/dalvik-cache /data/dalvik-cache && log -p i -t userinit "[${0}] Linked /data1/dalvik-cache" && echo "[${0}] Linked /data1/dalvik-cache" >> /cache/${0}.log +test -d /data1/data && chmod 0771 /data1/data && chown system:system /data1/data && rm -Rf /data/data && ln -s /data1/data /data/data && log -p i -t userinit "[${0}] Linked /data1/data" && echo "[${0}] Linked /data1/data" >> /cache/${0}.log +test -d /data1/media && chmod 0770 /data1/media && chown media_rw:media_rw /data1/media && rm -Rf /data/media && ln -s /data1/media /data/media && log -p i -t userinit "[${0}] Linked /data1/media" && echo "[${0}] Linked /data1/media" >> /cache/${0}.log + +# Log related mounts and mount points after +log -p i -t userinit "[${0}] After" +echo "[${0}] After" >> /cache/${0}.log +mount >> /cache/${0}.log +ls -la /data/ >> /cache/${0}.log +ls -la /data1/ >> /cache/${0}.log diff --git a/rootdir/etc/remount.pyramid b/rootdir/etc/remount.pyramid old mode 100755 new mode 100644 index 6dfc0ed8..b65a7edd --- a/rootdir/etc/remount.pyramid +++ b/rootdir/etc/remount.pyramid @@ -1,3 +1,3 @@ # Android fstab file. -# -/dev/block/mmcblk0p22 /system ext4 remount,ro,noatime,barrier=0 wait +# +/dev/block/mmcblk0p22 /system ext4 remount,ro,noatime,barrier=0 wait