Skip to content

Commit 850fa81

Browse files
committed
Use Nexus style data layout, allow data components on external sdcard and some optimizations and cleanups
Use internal data as in Nexus devices (sdcard0 is emulated) and 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. Also: * Add misc recovery related settings and coresponding changes to TWRP in order to support above. * Modify recovery to backup of emulated internal sdcard and apps in asac container. * Remove duplicated default init.rc code * Optimize storage, use cache as secondary swap and reuse devlog as cache To summarize, this patch allows user to encrypt device including sdcard0, place selected data components on external sdcard and hopefuly provides better performance. Change-Id: Ib52086347eb1f8fc9fd11031428f2c49bdda9afb
1 parent d13ed5c commit 850fa81

12 files changed

Lines changed: 175 additions & 124 deletions

File tree

BoardConfig.mk

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ TARGET_SPECIFIC_HEADER_PATH := $(LOCAL_PATH)/include
2929

3030
BOARD_VENDOR := htc
3131

32-
3332
# Bootloader
3433
TARGET_NO_BOOTLOADER := true
3534

@@ -84,14 +83,14 @@ AUDIO_FEATURE_ENABLED_FM := true
8483
TARGET_GPS_HAL_PATH := $(LOCAL_PATH)/gps
8584
BOARD_VENDOR_QCOM_GPS_LOC_API_AMSS_VERSION := 50000
8685

87-
8886
# Graphics
8987
USE_OPENGL_RENDERER := true
9088
TARGET_DISPLAY_USE_RETIRE_FENCE := true
9189
TARGET_USES_C2D_COMPOSITION := true
9290
TARGET_USES_ION := true
9391
NUM_FRAMEBUFFER_SURFACE_BUFFERS := 3
9492
TARGET_DISPLAY_INSECURE_MM_HEAP := true
93+
DEVICE_RESOLUTION := 540x960
9594

9695
# Media
9796
TARGET_NO_ADAPTIVE_PLAYBACK := true
@@ -117,11 +116,14 @@ BOARD_MKBOOTIMG_ARGS := --ramdisk_offset 0x01400000
117116
TARGET_KERNEL_CONFIG := pyramid_defconfig
118117
TARGET_KERNEL_SOURCE := kernel/htc/pyramid
119118

119+
# Recovery
120+
TARGET_RECOVERY_DEVICE_MODULES += chargeled
120121
TARGET_RECOVERY_FSTAB := device/htc/pyramid/rootdir/etc/fstab.pyramid
121122
RECOVERY_FSTAB_VERSION := 2
122123
TARGET_RECOVERY_PIXEL_FORMAT := "RGBX_8888"
123124
RECOVERY_GRAPHICS_USE_LINELENGTH := true
124125
TARGET_RECOVERY_DEVICE_DIRS += device/htc/pyramid
126+
RECOVERY_SDCARD_ON_DATA := true
125127

126128
# Required for Sensors
127129
COMMON_GLOBAL_CFLAGS += -DNEEDS_VECTORIMPL_SYMBOLS
@@ -153,9 +155,6 @@ BOARD_SUPPRESS_EMMC_WIPE := true
153155
# Use dlmalloc
154156
MALLOC_IMPL := dlmalloc
155157

156-
# Recovery
157-
TARGET_RECOVERY_DEVICE_MODULES += chargeled
158-
159158
# SELinux
160159
-include device/qcom/sepolicy/sepolicy.mk
161160

@@ -178,7 +177,7 @@ BOARD_SYSTEMIMAGE_PARTITION_SIZE := 838859776
178177
BOARD_USERDATAIMAGE_PARTITION_SIZE := 1252770816
179178
BOARD_FLASH_BLOCK_SIZE := 262144
180179

181-
# Twrp
180+
# TWRP
182181
TW_THEME := portrait_mdpi
183182
TW_INCLUDE_CRYPTO := true
184183
TW_NO_SCREEN_BLANK := true
@@ -188,3 +187,7 @@ TW_NEW_ION_HEAP := true
188187
TW_INCLUDE_NTFS_3G := true
189188
TW_BRIGHTNESS_PATH := "/sys/class/leds/lcd-backlight/brightness"
190189
TARGET_USE_CUSTOM_LUN_FILE_PATH := "/sys/devices/platform/msm_hsusb/gadget/lun0/file"
190+
TW_BACKUP_DATA_MEDIA := true
191+
TW_INTERNAL_STORAGE_PATH := /sdcard
192+
TW_EXTERNAL_STORAGE_PATH := /sdcard1
193+
TW_INCLUDE_L_CRYPTO := true

device_pyramid.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/overlay
152152
# Ramdisk
153153
PRODUCT_PACKAGES += \
154154
fstab.pyramid \
155+
init.pyramid.sh \
155156
init.pyramid.rc \
156157
init.qcom.power.rc \
157158
init.pyramid.usb.rc \
Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!--
33
**
4-
** Copyright 2011, The Android Open Source Project
4+
** Copyright 2013, The Android Open Source Project
55
**
66
** Licensed under the Apache License, Version 2.0 (the "License")
77
** you may not use this file except in compliance with the License.
@@ -17,30 +17,25 @@
1717
*/
1818
-->
1919

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

3522
<StorageList xmlns:android="http://schemas.android.com/apk/res/android">
36-
<!-- removable is not set in nosdcard product -->
37-
<storage android:mountPoint="/storage/sdcard0"
38-
android:storageDescription="@string/storage_sd_card"
39-
android:primary="true"
40-
android:removable="true"
41-
android:allowMassStorage="true"
42-
android:maxFileSize="4096" />
43-
<storage android:mountPoint="/storage/usbdisk"
44-
android:storageDescription="@string/storage_usb"
45-
android:removable="true" />
23+
<!-- internal emulated storage -->
24+
<storage
25+
android:storageDescription="@string/storage_internal"
26+
android:emulated="true"
27+
android:primary="true"
28+
android:mtpReserve="100" />
29+
<!-- external sdcard (non-removable due to optional usage of second partition for data) -->
30+
<storage android:mountPoint="/storage/sdcard1"
31+
android:storageDescription="@string/storage_sd_card"
32+
android:primary="false"
33+
android:emulated="false"
34+
android:removable="false"
35+
android:allowMassStorage="false"
36+
android:maxFileSize="4096" />
37+
<!-- external USB OTG storage -->
38+
<storage android:mountPoint="/storage/usb-otg"
39+
android:storageDescription="@string/storage_usb"
40+
android:removable="true" />
4641
</StorageList>

recovery.fstab

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# mount point fstype device [device2] [length=]
1+
# mount point fstype device [device2] [length=]
22

3-
/recovery emmc /dev/block/mmcblk0p21
4-
/boot emmc /dev/block/mmcblk0p20
5-
/cache ext4 /dev/block/mmcblk0p24
6-
/data ext4 /dev/block/mmcblk0p23 length=-16384
7-
/sd-ext ext4 /dev/block/mmcblk1p2
8-
/sdcard vfat /dev/block/mmcblk1p1
3+
/boot emmc /dev/block/mmcblk0p20
4+
/recovery emmc /dev/block/mmcblk0p21
95
/system ext4 /dev/block/mmcblk0p22
6+
/data f2fs /dev/block/mmcblk0p23 length=-16384
7+
/cache f2fs /dev/block/mmcblk0p24
108
/misc emmc /dev/block/mmcblk0p31
9+
/sdcard1 vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1 flags=display="sdcard1";storage;wipeingui;removable
10+
/data1 f2fs /dev/block/mmcblk1p2 /dev/block/mmcblk1 flags=display="data1";wipeingui;removable
11+
/usbdisk vfat /dev/block/sda1 /dev/block/sda flags=display="usbdisk";storage;wipeingui;removable

recovery/root/etc/twrp.fstab

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
# mount point fstype device [device2] [length=]
2-
3-
/boot emmc /dev/block/mmcblk0p20
4-
/recovery emmc /dev/block/mmcblk0p21
5-
/system ext4 /dev/block/mmcblk0p22
6-
/data ext4 /dev/block/mmcblk0p23 length=-16384
7-
/cache ext4 /dev/block/mmcblk0p24
8-
/misc emmc /dev/block/mmcblk0p31
9-
/sdcard vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1 flags=display="MicroSD card";storage;wipeingui;removable
10-
/sd-ext ext4 /dev/block/mmcblk1p2 flags=display="SD-Ext";wipeingui;removable
11-
#/usb-otg vfat /dev/block/sda1 /dev/block/sda flags=display="USB OTG";storage;wipeingui;removable
1+
# mount point fstype device [device2] [length=]
122

3+
/boot emmc /dev/block/mmcblk0p20
4+
/recovery emmc /dev/block/mmcblk0p21
5+
/system ext4 /dev/block/mmcblk0p22
6+
/data f2fs /dev/block/mmcblk0p23 length=-16384
7+
/cache f2fs /dev/block/mmcblk0p28
8+
/misc emmc /dev/block/mmcblk0p31
9+
/sdcard1 vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1 flags=display="sdcard1";andsec;storage;wipeingui;removable
10+
/data1 f2fs /dev/block/mmcblk1p2 /dev/block/mmcblk1 flags=display="data1";wipeingui;removable
11+
/usb-otg vfat /dev/block/sda1 /dev/block/sda flags=display="usb-otg";storage;wipeingui;removable

recovery/root/init.recovery.pyramid.rc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,3 @@ service power_test /sbin/power_test
5656
disabled
5757
oneshot
5858
seclabel u:r:recovery:s0
59-
60-
# Always start adbd on userdebug and eng builds
61-
on property:ro.debuggable=1
62-
#write /sys/class/android_usb/android0/enable 1
63-
#start adbd
64-
setprop service.adb.root 1
65-
66-
# Restart adbd so it can run as root
67-
on property:service.adb.root=1
68-
write /sys/class/android_usb/android0/enable 0
69-
restart adbd
70-
write /sys/class/android_usb/android0/enable 1

rootdir/Android.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ LOCAL_SRC_FILES := etc/fstab.pyramid
1616
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
1717
include $(BUILD_PREBUILT)
1818

19+
include $(CLEAR_VARS)
20+
LOCAL_MODULE := init.pyramid.sh
21+
LOCAL_MODULE_TAGS := optional eng
22+
LOCAL_MODULE_CLASS := ETC
23+
LOCAL_SRC_FILES := etc/init.pyramid.sh
24+
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
25+
include $(BUILD_PREBUILT)
26+
1927
include $(CLEAR_VARS)
2028
LOCAL_MODULE := init.pyramid.rc
2129
LOCAL_MODULE_TAGS := optional eng

rootdir/etc/fstab.pyramid

100755100644
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
# Android fstab file.
2-
#<src> <mnt_point> <type> <mnt_flags> <fs_mgr_flags>
3-
#/dev/block/platform/msm_sdcc.1/by-name/dsps /firmware_dsps vfat ro,shortname=lower wait
4-
/dev/block/platform/msm_sdcc.1/by-name/radio /firmware_radio vfat ro,shortname=lower,context=u:object_r:firmware_file:s0 wait
5-
/dev/block/platform/msm_sdcc.1/by-name/adsp /firmware_q6 vfat ro,shortname=lower,context=u:object_r:firmware_file:s0 wait
6-
#/dev/block/platform/msm_sdcc.1/by-name/wcnss /firmware_wcnss vfat ro,shortname=lower wait
7-
8-
/dev/block/platform/msm_sdcc.1/by-name/boot /boot emmc defaults defaults
9-
/dev/block/platform/msm_sdcc.1/by-name/recovery /recovery emmc defaults defaults
10-
/dev/block/platform/msm_sdcc.1/by-name/misc /misc emmc defaults defaults
11-
/dev/block/platform/msm_sdcc.1/by-name/devlog /devlog ext4 noatime,nosuid,nodev,barrier=0 wait
12-
/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 rw,noatime,barrier=0 wait
13-
/dev/block/platform/msm_sdcc.1/by-name/cache /cache ext4 noatime,nosuid,nodev,barrier=0 wait
14-
/dev/block/platform/msm_sdcc.1/by-name/cache /cache f2fs rw,discard,nosuid,nodev,noatime,nodiratime,inline_xattr wait,check
15-
/dev/block/platform/msm_sdcc.1/by-name/userdata /data ext4 noatime,nosuid,nodev,noauto_da_alloc,barrier=0 wait,encryptable=footer,length=-16384
16-
/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
2+
#<src> <mnt_point> <type> <mnt_flags> <fs_mgr_flags>
3+
#/dev/block/platform/msm_sdcc.1/by-name/dsps /firmware_dsps vfat ro,shortname=lower wait
4+
/dev/block/platform/msm_sdcc.1/by-name/radio /firmware_radio vfat ro,shortname=lower,context=u:object_r:firmware_file:s0 wait
5+
/dev/block/platform/msm_sdcc.1/by-name/adsp /firmware_q6 vfat ro,shortname=lower,context=u:object_r:firmware_file:s0 wait
6+
#/dev/block/platform/msm_sdcc.1/by-name/wcnss /firmware_wcnss vfat ro,shortname=lower wait
7+
/dev/block/platform/msm_sdcc.1/by-name/boot /boot emmc defaults defaults
8+
/dev/block/platform/msm_sdcc.1/by-name/recovery /recovery emmc defaults defaults
9+
/dev/block/platform/msm_sdcc.1/by-name/misc /misc emmc defaults defaults
10+
/dev/block/platform/msm_sdcc.1/by-name/devlog /cache ext4 noatime,nosuid,nodev,barrier=1,data=ordered,nomblk_io_submit,noauto_da_alloc,errors=panic wait,check
11+
/dev/block/platform/msm_sdcc.1/by-name/devlog /cache f2fs rw,discard,nosuid,nodev,noatime,nodiratime,inline_xattr wait,check
12+
/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,noatime,barrier=1 wait
13+
/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
14+
/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
15+
/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
16+
/dev/block/platform/msm_sdcc.3/by-num/p2 /data1 f2fs noatime,nodiratime,nosuid,nodev,inline_xattr,discard,rw wait,check
1717

1818
# SD card
19-
/devices/platform/msm_sdcc.3/mmc_host/mmc1* auto vfat defaults voldmanaged=sdcard0:auto,noemulatedsd
19+
/devices/platform/msm_sdcc.3/mmc_host/mmc1* auto vfat defaults voldmanaged=sdcard1:auto,noemulatedsd
2020

2121
# USB storage
22-
/devices/platform/msm_hsusb_host.0/usb1* auto auto defaults voldmanaged=usbdisk:auto
22+
d* auto auto defaults voldmanaged=usbdisk:auto,noemulatedsd
2323

2424
# ZRAM
25-
/dev/block/zram0 none swap defaults zramsize=268435456
25+
/dev/block/zram0 none swap defaults zramsize=134217728
26+
27+
# Cache as secondary swap
28+
/dev/block/platform/msm_sdcc.1/by-name/cache none swap defaults defaults

rootdir/etc/init.pyramid.rc

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,51 @@ import init.qcom.power.rc
33

44
on early-init
55

6-
# ZRAM
7-
write /sys/block/zram0/comp_algorithm lz4
8-
write /sys/block/zram0/max_comp_streams 2
6+
# ZRAM
7+
write /sys/block/zram0/comp_algorithm lz4
8+
write /sys/block/zram0/max_comp_streams 2
99

1010
on init
1111
mkdir /devlog 0700 root root
12-
mkdir /mnt/media_rw/sdcard0 0700 media_rw media_rw
13-
mkdir /mnt/media_rw/usbdisk 0700 media_rw media_rw
1412

15-
mkdir /storage/sdcard0 0700 root root
16-
mkdir /storage/usbdisk 0700 root root
13+
# See storage config details at http://source.android.com/tech/storage/
14+
mkdir /mnt/shell/emulated 0700 shell shell
15+
mkdir /storage/emulated 0555 root root
1716

18-
# for backwards compatibility
19-
symlink /storage/sdcard0 /sdcard
20-
symlink /storage/sdcard0 /mnt/sdcard
21-
symlink /storage/usbdisk /usbdisk
22-
symlink /storage/usbdisk /mnt/usbdisk
17+
export EXTERNAL_STORAGE /storage/emulated/legacy
18+
export EMULATED_STORAGE_SOURCE /mnt/shell/emulated
19+
export EMULATED_STORAGE_TARGET /storage/emulated
20+
21+
# Secondary storage
22+
mkdir /mnt/media_rw/sdcard1 0700 media_rw media_rw
23+
mkdir /storage/sdcard1 0700 root root
24+
export SECONDARY_STORAGE /storage/sdcard1
25+
26+
# Secondary data (optional)
27+
mkdir /data1 0771 root root
28+
29+
# Support legacy paths
30+
symlink /storage/emulated/legacy /sdcard
31+
symlink /storage/emulated/legacy /mnt/sdcard
32+
symlink /storage/emulated/legacy /storage/sdcard0
33+
symlink /mnt/shell/emulated/0 /storage/emulated/legacy
2334

2435
setprop ro.usb.idproduct.ums 0c86
2536
setprop ro.usb.idproduct.rndis 0c86
2637
setprop ro.usb.idproduct.mtp 0f87
2738
setprop ro.usb.idproduct.mtp_adb 0f87
2839
setprop ro.usb.idproduct.ptp 0f87
2940

30-
export EXTERNAL_STORAGE /storage/sdcard0
31-
export SECONDARY_STORAGE /storage/usbdisk
32-
3341
on fs
34-
3542
# create firmware mount points
3643
mkdir /firmware_radio 0771 system system
3744
mkdir /firmware_q6 0771 system system
3845
# mount all mmc partitions
3946
mount_all /fstab.pyramid
47+
# init and enable swap partitions (zram and cache)
48+
mkswap /dev/block/platform/msm_sdcc.1/by-name/cache
4049
swapon_all /fstab.pyramid
50+
write /proc/sys/vm/swappiness 60
4151

4252
mkdir /data/tombstones 0771 system system
4353
symlink /data/tombstones /tombstones
@@ -49,20 +59,26 @@ on fs
4959
chmod 0644 /proc/cmdline
5060

5161
setprop ro.crypto.tmpfs_options size=128m,mode=0771,uid=1000,gid=1000
62+
setprop ro.crypto.fuse_sdcard true
5263

5364
# Force loading of modem and Q6 images
5465
write /dev/smd_pkt_loopback 1
5566

56-
# link widevine drm library path
67+
# link widevine drm library path
5768
symlink /system/vendor/lib /vendor/lib
5869

70+
# run device's script
71+
exec /init.pyramid.sh
72+
5973
mount_all /remount.pyramid
6074

6175
on post-fs-data
6276
# double check the perms and set owner
6377
chown root root /devlog
6478
chmod 0700 /devlog
6579

80+
mkdir /data/media 0770 media_rw media_rw
81+
6682
# Set indication (checked by vold) that we have finished this action
6783
setprop vold.post_fs_data_done 1
6884

@@ -241,29 +257,29 @@ service dhcpcd_wlan0 /system/bin/dhcpcd -ABKL
241257
oneshot
242258

243259
service dhcpcd_p2p /system/bin/dhcpcd -aABKL
244-
disabled
245-
oneshot
260+
disabled
261+
oneshot
246262

247263
service dhcpcd_bt-pan /system/bin/dhcpcd -ABKL
248-
disabled
249-
oneshot
264+
disabled
265+
oneshot
250266

251267
service iprenew_bt-pan /system/bin/dhcpcd -n
252-
disabled
253-
oneshot
268+
disabled
269+
oneshot
254270

255271
service iprenew_wlan0 /system/bin/dhcpcd -n
256-
disabled
257-
oneshot
258-
# wifi--
272+
disabled
273+
oneshot
259274

260-
service fuse_sdcard0 /system/bin/sdcard -u 1023 -g 1023 -d /mnt/media_rw/sdcard0 /storage/sdcard0
261-
class late_start
262-
disabled
275+
# external sdcard daemon running as media_rw (1023)
276+
service fuse_sdcard1 /system/bin/sdcard -u 1023 -g 1023 -d /mnt/media_rw/sdcard1 /storage/sdcard1
277+
class late_start
278+
disabled
263279

264-
service fuse_usbdisk /system/bin/sdcard -u 1023 -g 1023 -d /mnt/media_rw/usbdisk /storage/usbdisk
265-
class late_start
266-
disabled
280+
# virtual sdcard daemon running as media_rw (1023)
281+
service sdcard /system/bin/sdcard -u 1023 -g 1023 -l /data/media /mnt/shell/emulated
282+
class late_start
267283

268284
on property:init.svc.bootanim=stopped
269285
start qcom-post-boot
@@ -278,4 +294,3 @@ on property:service.adb.root=1
278294

279295
on property:sys.radio.shutdown=true
280296
exec /system/bin/sh /system/etc/init.qcom.efs.sync.sh
281-

0 commit comments

Comments
 (0)