[AT&T Samsung Galaxy S II SGH-I777] dimoochka:
Sure, I included all my code below. On the i777/S959G there are two partitions used for this: mmcblk0p5 and mmcblk0p6

I don't have an i777 myself and my memory sucks, but I THINK that mmcblk0p5 is both the kernel AND recovery on this device - you'll have to verify this yourself because I've heard conflicting reports. It's entirely possible this applies only to the i9100 (and the i777 and S959G are actually identical).

The S959G stores the kernel on mmcblk0p5 and the recovery is stored separately on mmcblk0p6. The twrp.fstab you'll see in the commit below is accordingly designed for the S959G.

The base build of android I used was CM12.1, and the twrp branch I used was android-5.1. At the time, I built it on top of this commit:

https://github.com/TeamWin/Team-Win-Recovery-Project/commit/f20a5701b9783ca6485127c15fda0862c5d16166

This is the corresponding base tree:

https://github.com/TeamWin/Team-Win-Recovery-Project/tree/f20a5701b9783ca6485127c15fda0862c5d16166

This is the commit I used in the device/samsung/galaxys2-common folder:

diff --git a/BoardCommonConfig.mk b/BoardCommonConfig.mk
index 89fcbe3..e9ad1da 100644
--- a/BoardCommonConfig.mk
+++ b/BoardCommonConfig.mk
@@ -175,7 +175,7 @@ BOARD_SEPOLICY_UNION += \

# Recovery
BOARD_CUSTOM_RECOVERY_KEYMAPPING := ../../device/samsung/galaxys2-common/recovery/recovery_keys.c
-BOARD_CUSTOM_GRAPHICS := ../../../device/samsung/galaxys2-common/recovery/graphics.c
+#BOARD_CUSTOM_GRAPHICS := ../../../device/samsung/galaxys2-common/recovery/graphics.c
BOARD_UMS_LUNFILE := "/sys/class/android_usb/android0/f_mass_storage/lun0/file"
BOARD_USES_MMCUTILS := true
BOARD_HAS_NO_MISC_PARTITION := true

These are the commits I used in the device/samsung/i777 folder (see the comments inside, they're useful):

diff --git a/BoardConfig.mk b/BoardConfig.mk
index 8716840..e740a70 100644
--- a/BoardConfig.mk
+++ b/BoardConfig.mk
@@ -36,3 +36,81 @@ TARGET_OTA_ASSERT_DEVICE := i777,SGH-I777,SGH-S959G

# Use the non-open-source parts, if they're present
-include vendor/samsung/i777/BoardConfigVendor.mk
+
+#twrp
+#TW_INCLUDE_INJECTTWRP := true ---- doesn't work :(
+DEVICE_RESOLUTION := 480x800
+TW_INCLUDE_L_CRYPTO := true
+
+RECOVERY_SDCARD_ON_DATA := true
+TW_INTERNAL_STORAGE_PATH := "/data/media/0"
+TW_INTERNAL_STORAGE_MOUNT_POINT := "data"
+TW_EXTERNAL_STORAGE_PATH := "/sdcard"
+TW_EXTERNAL_STORAGE_MOUNT_POINT := "sdcard"
+
+#commented following definition out in BoardCommonConfig.mk so we can define it here
+BOARD_CUSTOM_GRAPHICS := ../../../bootable/recovery/minui/graphics.c
+
+# TWRP - doesn't work
+#PRODUCT_COPY_FILES += device/samsung/i777/twrp.fstab:recovery/root/etc/twrp.fstab
+
+# Also need to enable ADB in TWRP for advanced users:
+# Replaced lines 965-966 in build/core/Makefile with:
+# # Copy twrp.fstab into ramdisk... didn't work with PRODUCT_COPY_FILES method
+#	$(hide) cp -f device/samsung/i777/twrp.fstab $(TARGET_RECOVERY_ROOT_OUT)/etc/twrp.fstab;)
+# # Set ro.adb.secure to 0 on the recovery ramdisk so you can adb into it.
+#	$(hide) cat $(INSTALLED_DEFAULT_PROP_TARGET) $(recovery_build_prop) \
+#	| sed s/ro.adb.secure=1/ro.adb.secure=0/ \
+#	> $(TARGET_RECOVERY_ROOT_OUT)/default.prop
+
+
+########## Alternatively, you can add to build/tools/post_process_props.py at line 45
+########## prop.put("ro.adb.secure", "0");
+########## But this solution adds it to the /system/default.prop file as well :(

diff --git a/twrp.fstab b/twrp.fstab
new file mode 100644
index 0000000..355195e
--- /dev/null
+++ b/twrp.fstab
@@ -0,0 +1,14 @@
+# mount point fstype device
+
+/boot emmc /dev/block/mmcblk0p5 flags=display="Boot [System Kernel]";backup=1
+/modem emmc /dev/block/mmcblk0p8 flags=display="Modem";backup=1
+/recovery emmc /dev/block/mmcblk0p6 flags=display="Recovery [+Kernel]";backup=1
+
+/cache ext4 /dev/block/mmcblk0p7 flags=display="Cache";wipeingui;backup=1;wipeduringfactoryreset;canencryptbackup=1
+/preload ext4 /dev/block/mmcblk0p12 flags=display="Preload";wipeingui;backup=1
+/efs ext4 /dev/block/mmcblk0p1 flags=display="EFS [IMEI]";backup=1;canencryptbackup=1;mounttodecrypt
+/system ext4 /dev/block/mmcblk0p9 flags=display="System";wipeingui;backup=1;canencryptbackup=1
+/data ext4 /dev/block/mmcblk0p10 flags=display="Data";wipeingui;backup=1;wipeduringfactoryreset;canencryptbackup=1;encryptable=/efs/metadata
+/emmc auto /dev/block/mmcblk0p11 flags=display="Internal Storage";storage;settingsstorage;wipeingui
+/sdcard auto /dev/block/mmcblk1p1 /dev/block/mmcblk1 flags=display="MicroSD Card";storage;wipeingui;removable

Some manual bugfixes I made to this branch TWRP stored in the android/bootable/recovery folder (not sure if they still apply):

diff --git a/partition.cpp b/partition.cpp
index 8c5b412..72082ea 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -262,6 +262,8 @@ bool TWPartition::Process_Fstab_Line(string Line, bool Display_Error) {
Wipe_Available_in_GUI = true;
Can_Be_Backed_Up = true;
Mount_Read_Only = true;
+ } else if (Mount_Point == "/efs") {
+ Mount(false);
} else if (Mount_Point == "/data") {
UnMount(false); // added in case /data is mounted as tmpfs for qcom hardware decrypt
Display_Name = "Data";
@@ -465,19 +467,6 @@ bool TWPartition::Process_Flags(string Flags, bool Display_Error) {
ptr_len = strlen(ptr);
if (strcmp(ptr, "removable") == 0) {
Removable = true;
- } else if (strncmp(ptr, "storage", 7) == 0) {
- if (ptr_len == 7) {
- Is_Storage = true;
- } else if (ptr_len == 9) {
- ptr += 9;
- if (*ptr == '1' || *ptr == 'y' || *ptr == 'Y') {
- LOGINFO("storage set to true\n");
- Is_Storage = true;
- } else {
- LOGINFO("storage set to false\n");
- Is_Storage = false;
- }
- }
} else if (strcmp(ptr, "settingsstorage") == 0) {
Is_Storage = true;
Is_Settings_Storage = true;
@@ -519,22 +508,35 @@ bool TWPartition::Process_Flags(string Flags, bool Display_Error) {
if (Display_Name.substr(Display_Name.size() - 1, 1) == "\"") {
Display_Name.resize(Display_Name.size() - 1);
}
- } else if (ptr_len > 11 && strncmp(ptr, "storagename=", 11) == 0) {
+ } else if (ptr_len > 12 && strncmp(ptr, "storagename=", 12) == 0) {
has_storage_name = true;
- ptr += 11;
+ ptr += 12;
if (*ptr == '\"') ptr++;
Storage_Name = ptr;
if (Storage_Name.substr(Storage_Name.size() - 1, 1) == "\"") {
Storage_Name.resize(Storage_Name.size() - 1);
}
- } else if (ptr_len > 11 && strncmp(ptr, "backupname=", 10) == 0) {
+ } else if (ptr_len > 11 && strncmp(ptr, "backupname=", 11) == 0) {
has_backup_name = true;
- ptr += 10;
+ ptr += 11;
if (*ptr == '\"') ptr++;
Backup_Display_Name = ptr;
if (Backup_Display_Name.substr(Backup_Display_Name.size() - 1, 1) == "\"") {
Backup_Display_Name.resize(Backup_Display_Name.size() - 1);
}
+ } else if (strncmp(ptr, "storage", 7) == 0) {
+ if (ptr_len == 7) {
+ Is_Storage = true;
+ } else if (ptr_len == 9) {
+ ptr += 9;
+ if (*ptr == '1' || *ptr == 'y' || *ptr == 'Y') {
+ LOGINFO("storage set to true\n");
+ Is_Storage = true;
+ } else {
+ LOGINFO("storage set to false\n");
+ Is_Storage = false;
+ }
+ }
} else if (ptr_len > 10 && strncmp(ptr, "blocksize=", 10) == 0) {
ptr += 10;
Format_Block_Size = (unsigned long)(atol(ptr));
@@ -652,8 +654,10 @@ void TWPartition::Setup_File_System(bool Display_Error) {

// Make the mount point folder if it doesn't exist
Make_Dir(Mount_Point, Display_Error);
- Display_Name = Mount_Point.substr(1, Mount_Point.size() - 1);
- Backup_Name = Display_Name;
+ if (Display_Name != "Data") {
+ Display_Name = Mount_Point.substr(1, Mount_Point.size() - 1);
+ Backup_Name = Display_Name;
+ }
Backup_Method = FILES;
}