Skip to content

Commit

Permalink
Switch to Nexus style data layout and allow exporting data components…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
eugenesan committed Sep 14, 2015
1 parent 968a880 commit 407842a
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 88 deletions.
15 changes: 9 additions & 6 deletions BoardConfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ TARGET_SPECIFIC_HEADER_PATH := $(LOCAL_PATH)/include

BOARD_VENDOR := htc


# Bootloader
TARGET_NO_BOOTLOADER := true

Expand Down Expand Up @@ -79,14 +78,14 @@ 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
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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions device_pyramid.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
43 changes: 19 additions & 24 deletions overlay/frameworks/base/core/res/res/xml/storage_list.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
**
** Copyright 2011, The Android Open Source Project
** Copyright 2013, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License")
** you may not use this file except in compliance with the License.
Expand All @@ -17,30 +17,25 @@
*/
-->

<!-- The <device> element should contain one or more <storage> elements.
Exactly one of these should have the attribute primary="true".
This storage will be the primary external storage and should have path="/mnt/sdcard".
Each storage should have both a path and description attribute set.
The following boolean attributes are optional:
primary: this storage is the primary external storage
removable: this is removable storage (for example, a real SD card)
emulated: the storage is emulated via the FUSE sdcard daemon
mtp-reserve: number of megabytes of storage MTP should reserve for free storage
(used for emulated storage that is shared with system's data partition)
A storage should not have both emulated and removable set to true
-->
<!-- See storage config details at http://source.android.com/tech/storage/ -->

<StorageList xmlns:android="http://schemas.android.com/apk/res/android">
<!-- removable is not set in nosdcard product -->
<storage android:mountPoint="/storage/sdcard0"
android:storageDescription="@string/storage_sd_card"
android:primary="true"
android:removable="true"
android:allowMassStorage="true"
android:maxFileSize="4096" />
<!-- internal emulated storage -->
<storage
android:storageDescription="@string/storage_internal"
android:emulated="true"
android:primary="true"
android:mtpReserve="100" />
<!-- external sdcard (non-removable due to optional usage of second partition for data) -->
<storage android:mountPoint="/storage/sdcard1"
android:storageDescription="@string/storage_sd_card"
android:primary="false"
android:emulated="false"
android:removable="false"
android:allowMassStorage="false"
android:maxFileSize="4096" />
<!-- external USB OTG storage -->
<storage android:mountPoint="/storage/usbdisk"
android:storageDescription="@string/storage_usb"
android:removable="true" />
android:storageDescription="@string/storage_usb"
android:removable="true" />
</StorageList>
15 changes: 8 additions & 7 deletions recovery.fstab
Original file line number Diff line number Diff line change
@@ -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
21 changes: 10 additions & 11 deletions recovery/root/etc/twrp.fstab
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions rootdir/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 19 additions & 18 deletions rootdir/etc/fstab.pyramid
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
# Android fstab file.
#<src> <mnt_point> <type> <mnt_flags> <fs_mgr_flags>
#/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
#<src> <mnt_point> <type> <mnt_flags> <fs_mgr_flags>
#/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
54 changes: 34 additions & 20 deletions rootdir/etc/init.pyramid.rc
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,36 @@ 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
setprop ro.usb.idproduct.mtp 0f87
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
Expand All @@ -51,20 +58,26 @@ 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
# double check the perms and set owner
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

Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions rootdir/etc/init.pyramid.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions rootdir/etc/remount.pyramid
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Android fstab file.
#<src> <mnt_point> <type> <mnt_flags> <fs_mgr_flags>
/dev/block/mmcblk0p22 /system ext4 remount,ro,noatime,barrier=0 wait
#<src> <mnt_point> <type> <mnt_flags> <fs_mgr_flags>
/dev/block/mmcblk0p22 /system ext4 remount,ro,noatime,barrier=0 wait

0 comments on commit 407842a

Please sign in to comment.