[DEV]How to compile TWRP touch recovery

Search This thread

ankar84

Senior Member
Jan 23, 2013
73
82
Novosibirsk
Hi, Dees_Troy!
TWRP is realy great project!

I have a few questions to you.
Today I compiled TWRP 2.4.4.0 for my Onda V972.
In file BoardConfig.mk I must set partitions size, witch one can get with command cat /proc/mtd in any terminal emulator. But on my Onda V972 there is no /proc/mtd, but I have /proc/partitions
When I input command cat /proc/partitions I get size of all tablets partitions in blocks. But, as I understood, I need to put partitions size in BoardConfig.mk in bytes. So, I just multiply size in blocks at 512. Did I was right? What can happen when the size of the filled partitions wrong?
It is first question.

And second is...
I always get Unable to mount `/recovery` in TWRP shell. In recovery.log I see:
Code:
I:Can`t probe device /dev/block/nandg
E:Unable to mount `/recovery`
I:Actual block dsvice `/dev/block/nandg`, current file system: `ext4`
I:Unmounting main partitions...
 

C3C076

Recognized Contributor
Dec 15, 2012
7,744
24,600
Bratislava
ceco.sk.eu.org
Trying to build TWRP 2.5 but the resulted recovery image exceeds my recovery partition size by about 250kb... Any tips for stripping down the image to fit within 6 MB? (can't do anything with the kernel since no sources are available thus I am forced to use the prebuilt image)
 

C3C076

Recognized Contributor
Dec 15, 2012
7,744
24,600
Bratislava
ceco.sk.eu.org
@yuweng
Somewhat I am not able to reply to your PM (I cannot see my reply in Sent Items)... So I am replying here.

I've made 2 patches that help to save some space on ramdisk. These are:
https://github.com/C3C0/Team-Win-Recovery-Project/commit/e2863a6df0ebf2b6f7620cbc8e2479b773599a3f
https://github.com/C3C0/Team-Win-Recovery-Project/commit/0df94e8eb62a0bfa24651e20519b115bd4e32447

I think I'm going to send a pull request to TWRP upstream.

I haven't tested the new recovery, yet. But I suppose you know that the recovery image for MTK has a special format. You need to unpack the recovery that's built from source and repack it using MTK tools: https://github.com/bgcngm/mtk-tools
 

ankar84

Senior Member
Jan 23, 2013
73
82
Novosibirsk
TWRP 2.5.0.0 cannot open fb0 issue

Now I'm trying to compile TWRP 2.5.0.0 and get error (it is from /cache/recovery/last_log):
Code:
Starting TWRP 2.5.0.0 on Wed Apr 17 04:24:46 2013
I:=> product model: 'Full Android on Emulator'
I:=> using device id: 'Full_Android_on_Emulator'
BOARD_HAS_NO_REAL_SDCARD := true
I:Internal path defined: '/sdcard'
I:External path defined: '/external_sd'
I:Backup folder set to '/external_sd/TWRP/BACKUPS/Full_Android_on_Emulator'
TW_DEFAULT_EXTERNAL_STORAGE := true
TW_NO_REBOOT_BOOTLOADER := true
I:Lun file '/sys/devices/platform/usb_mass_storage/lun0/file' does not exist, USB storage mode disabled
Starting the UI...cannot open fb0: No such file or directory
Unable to get framebuffer.
: No such file or directory
=> Linking mtab
=> Processing recovery.fstab
I:Processing '/bootloader'
I:Created '/bootloader' folder.
I:Processing '/env'
I:Processing '/boot'
I:Processing '/system'
I:Processing '/data'
I:Processing '/misc'
I:Processing '/cache'
I:Processing '/sdcard'
I:Created '/and-sec' folder.
I:Creating Android Secure: /sdcard/.android_secure
I:Backup folder set to '/sdcard/TWRP/BACKUPS/Full_Android_on_Emulator'
I:Settings storage is '/sdcard'
I:Processing '/external_sd'
Updating partition details...
I:Unmounting main partitions...
So, it is not working. Starting the UI...cannot open fb0: No such file or directory What is the problem? When I compiled TWRP 2.4.4.0 everything was just fine.
Enybody knows where to look to resolve that issue?
 

ankar84

Senior Member
Jan 23, 2013
73
82
Novosibirsk
Now I'm trying to compile TWRP 2.5.0.0 and get error (it is from /cache/recovery/last_log):
Code:
Starting TWRP 2.5.0.0 on Wed Apr 17 04:24:46 2013
I:Lun file '/sys/devices/platform/usb_mass_storage/lun0/file' does not exist, USB storage mode disabled
Starting the UI...cannot open fb0: No such file or directory
Unable to get framebuffer.
: No such file or directory
So, it is not working. Starting the UI...cannot open fb0: No such file or directory What is the problem? When I compiled TWRP 2.4.4.0 everything was just fine.
Enybody knows where to look to resolve that issue?

I solved that issue. Thx to Talustus from #twrp at freenode.net
He adviced me to try build new TWRP 2.5.0.0 with kernel from stock 1.35 firmware, witch was working fine on TWRP 2.4.4.0 build.
And it's worked fine! I don't know why, but kernel from latest stock 2.0 didn't work.

Anyway, now I have another problem with my default.prop
I always have ro.product.model=Full Android on Emulator in my default.prop
And it's really critical, because backup will make a folder Full Android on Emulator for backups.
And I need my model v972 in ro.product.model instead of Full Android on Emulator
I know that, if I write in system.prop in my /device/onda/v972 forder ro.product.model=v972 I will get default.prop in compiled TWRP with two ro.product.model
First one will be ro.product.model=Full Android on Emulator
And second will be in system.prop for v972 section ro.product.model=v972
Witch will wins?
And how it is good or bad having two different ro.product.model in one default.prop? I think it is really bad.
Someone can help me?


Edit: Oh, Thx again to #twrp at freenode.net and user interloper.
ro.product.model is parsed from the device.mk files
So, he adviced me to add
Code:
PRODUCT_BRAND := onda
PRODUCT_MODEL := V972
to my device_v972.mk and it worked great!
 
Last edited:

Dees_Troy

Senior Recognized Developer
Mar 31, 2008
1,705
13,537
KC MO
www.teamw.in
Hi, Dees_Troy!
TWRP is realy great project!

I have a few questions to you.
Today I compiled TWRP 2.4.4.0 for my Onda V972.
In file BoardConfig.mk I must set partitions size, witch one can get with command cat /proc/mtd in any terminal emulator. But on my Onda V972 there is no /proc/mtd, but I have /proc/partitions
When I input command cat /proc/partitions I get size of all tablets partitions in blocks. But, as I understood, I need to put partitions size in BoardConfig.mk in bytes. So, I just multiply size in blocks at 512. Did I was right? What can happen when the size of the filled partitions wrong?
It is first question.

And second is...
I always get Unable to mount `/recovery` in TWRP shell. In recovery.log I see:
Code:
I:Can`t probe device /dev/block/nandg
E:Unable to mount `/recovery`
I:Actual block dsvice `/dev/block/nandg`, current file system: `ext4`
I:Unmounting main partitions...

The sizes in BoardConfig.mk are used by the compiler to ensure that the boot.img, recovery.img, etc that it produces are not too large for the partition on your device. We don't use those sizes in TWRP.

The error you're getting about unable to mount /recovery is due to your recovery.fstab. In the recovery.fstab you have told TWRP that the recovery partition is ext4 which is a file system. It's very rare that the recovery partition is actually a mountable file system so something like emmc or mtd is more appropriate, depending on the type of flash memory that you're using.
 
  • Like
Reactions: ankar84

acestars

Senior Member
Mar 31, 2011
294
37
First this is my device
http://wiki.cyanogenmod.org/w/Z71_Info

Code:
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.3.7
TARGET_PRODUCT=cyanogen_z71
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv6-vfp
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=GINGERBREAD
============================================

I succeeded build twrp without error with some lines added into "build/core/prelink-linux-arm.map".
The questions are:
1. Inside my device recovery directory no init_recovery.rc, is it okay if i just create it and add it to BoardConfig.mk?
2. How to change directory structure of update.zip because the directory structure of my device is different from twrp. I want to place library file into /system/lib and binary file into /system/bin or /system/xbin.
3. My device's radio has different partition layout so which files i need to edit and which lines, for recovery.img and boot.img?
4. Maybe you can add complete lis of twrp flag.

Thanks.
 

Ryuinferno

Senior Member
Apr 3, 2012
3,548
7,109
ryuinferno.github.io
Hi, I tired to add a special partition using the SP1_NAME and etc flags in BoardConfig.mk, it works in 2.4 but in 2.5, I see that there seems to be extra flags required for the special partion to be backed up...from /cache/recovery/last_log, I see that under my special partiton, the flags are only "Can_Be_Mounted Can_Be_Wipe" (Backup_Name, Backup_Path etc although configured but does not apply as configured though), but for other partitons like /system, there are "Can_Be_Mounted Can_Be_Wiped Can_Be_Backed_Up Wipe_Available_In_GUI Is_Present"...may I know how to add those flags? Cause in 2.4, even though the "Can_Be_Backed_Up" flag is not there, there is still an option to back up the special partition...Thank you...
 
Last edited:

Dees_Troy

Senior Recognized Developer
Mar 31, 2008
1,705
13,537
KC MO
www.teamw.in
Hi, I tired to add a special partition using the SP1_NAME and etc flags in BoardConfig.mk, it works in 2.4 but in 2.5, I see that there seems to be extra flags required for the special partion to be backed up...from /cache/recovery/last_log, I see that under my special partiton, the flags are only "Can_Be_Mounted Can_Be_Wipe" (Backup_Name, Backup_Path etc although configured but does not apply as configured though), but for other partitons like /system, there are "Can_Be_Mounted Can_Be_Wiped Can_Be_Backed_Up Wipe_Available_In_GUI Is_Present"...may I know how to add those flags? Cause in 2.4, even though the "Can_Be_Backed_Up" flag is not there, there is still an option to back up the special partition...Thank you...

I need to update the guide for the changes we made for 2.5 one of these days, however, to add custom partitions you need to modify the recovery.fstab. Here are some examples:

/efs ext4 /dev/block/mmcblk0p10 flags=display="EFS";backup=1
/external_sd vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1 flags=display="Micro SDcard";storage;wipeingui;removable
/usb-otg vfat /dev/block/sda1 /dev/block/sda flags=display="USB-OTG";storage;wipeingui;removable

@Dees_Troy..
Hey.. Bhargz16 here..
Any way we can change the fonts of the recovery??
At compile time, or via themes??

ғг๏๓ ҭђє ғเรђ™

Right now TWRP uses its own custom font engine. There's really no good way to generate new fonts. Here's a set of prebuilt fonts that you can easily use:
https://github.com/TeamWin/Team-Win-Recovery-Project/tree/twrp2.5/gui/devices/resources/fonts

For anything else, you can either try to reverse engineer the font engine and come up with a way to create new fonts.

I'm hoping to port FreeType fonts to TWRP but I have to see how much space that is going to gobble up in the recovery image.
 

BeeGee_Tokyo

Inactive Recognized Developer
Nov 20, 2008
2,881
1,399
Paranaque
www.giesecke.tk
Ok, first of all sorry for the noob question, but I really went through the 16 pages of this thread and didn't find the answer.

I am building a ROM for the Samsung Galaxy Tab 10.1 (GT-P7500 aka p4 at CM) based on CM10.1.
Unusual, but for this tablet a prebuild kernel is used in the standard CM sources instead of building the kernel together with the ROM. But I changed this and can build the kernel from the sources. But the recovery is never included. Neither the original CM10.1 recovery nor the TWRP recovery (if I change the repositories to TWRP).

Anybody can give me a tip how to include the recovery into boot.img during building the ROM.

Thanks.
 

Dees_Troy

Senior Recognized Developer
Mar 31, 2008
1,705
13,537
KC MO
www.teamw.in
Ok, first of all sorry for the noob question, but I really went through the 16 pages of this thread and didn't find the answer.

I am building a ROM for the Samsung Galaxy Tab 10.1 (GT-P7500 aka p4 at CM) based on CM10.1.
Unusual, but for this tablet a prebuild kernel is used in the standard CM sources instead of building the kernel together with the ROM. But I changed this and can build the kernel from the sources. But the recovery is never included. Neither the original CM10.1 recovery nor the TWRP recovery (if I change the repositories to TWRP).

Anybody can give me a tip how to include the recovery into boot.img during building the ROM.

Thanks.

Most of the Samsung tablets have a separate recovery partition and do not use the recovery in boot setup seen on many Samsung phones older than the SGS3. Use make recoveryimage instead.
 

#define

Senior Member
May 1, 2012
2,025
2,179
I followed the above steps successfully compiled it and then i made a zip file of recovery i flash it and it redirects me to my old recovery am i doing something wrong.

Dont you need fastboot to flash the recovery, which is an img file?? Or is that only on certain devices?? (Excluding samsung, ofcourse)..
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    Anyone got a fully functional TWRP for mediatek device running Android 10 and a "super" partition? How did you do it?
    Have a look on mine:
    I'm currently stuck on decryption.
    /data/system gets decrypted.
    /data/media/0 doesn't decrypt.
    /data/system_de doesn't decrypt (it's where te user keys are stored for /data/media/0)

    EDIT: Honestly, keep away from those "device tree generators". They only do the bare minimum and even fail on that on such (rare breed) devices like mediatek.
  • 399
    All of TWRP 3.x source is public. You can compile it on your own. This guide isn't going to be a step-by-step, word-for-word type of guide. If you're not familiar with basic Linux commands and/or building in AOSP then you probably won't be able to do this.

    You can currently use Omni 6.0, Omni 7.1, Omni 8.1, Omni 9.0, CM 13.0, CM 14.1, CM 15.1, LineageOS 16.0 source code. Omni 9.0 is recommended for now unless your device has a super partition.

    If you are using CM/LineageOS, you'll need to place TWRP in the LineageOS/bootable/recovery-twrp folder and set RECOVERY_VARIANT := twrp in your BoardConfig.mk file. TWRP source code can be found here:
    https://github.com/TeamWin/android_bootable_recovery (NOTE: The location for the latest TWRP source code has changed!)
    Select the newest branch available. This step is not necessary with Omni because Omni already includes TWRP source by default, however, if you are using an older version of Omni, you will probably want to pull from the latest branch (the latest branch will compile successfully in older build trees)

    If you are only interested in building TWRP, you may want to try working with a smaller tree. You can try using this manifest. It should work in most cases but there may be some situations where you will need more repos in your tree than this manifest provides:
    https://github.com/minimal-manifest-twrp

    *BEFORE YOU COMPILE*
    Note: If you add or change any flags, you will need to make clean or make clobber before recompiling or your flag changes will not be picked up.

    Now that you have the source code, you'll need to set or change a few build flags for your device(s). Find the BoardConfig.mk for your device. The BoardConfig.mk is in your devices/manufacturer/codename folder (e.g. devices/lge/hammerhead/BoardConfig.mk).

    Your board config will need to include architecture and platform settings. Usually these are already included if you're using device configs that someone else created, but if you created your own, you may need to add them. Without them, recovery may seg fault during startup and you'll just see the teamwin curtain flash on the screen over and over.

    We usually put all of our flags at the bottom of the BoardConfig.mk under a heading of #twrp For all devices you'll need to tell TWRP what theme to use. This TW_THEME flag replaces the older DEVICE_RESOLUTION flag. TWRP now uses scaling to stretch any theme to fit the screen resolution. There are currently 5 settings which are: portrait_hdpi, portrait_mdpi, landscape_hdpi, landscape_mdpi, and watch_mdpi. For portrait, you should probably select the hdpi theme for resolutions of 720x1280 and higher. For landscape devices, use the hdpi theme for 1280x720 or higher.
    TW_THEME := portrait_hdpi

    Note that themes do not rotate 90 degrees and there currently is no option to rotate a theme. If you find that the touchscreen is rotated relative to the screen, then you can use some flags (discussed later in this guide) to rotate the touch input to match the screen's orientation.

    In addition to the resolution, we have the following build flags:
    RECOVERY_SDCARD_ON_DATA := true -- this enables proper handling of /data/media on devices that have this folder for storage (most Honeycomb and devices that originally shipped with ICS like Galaxy Nexus) This flag is not required for these types of devices though. If you do not define this flag and also do not include any references to /sdcard, /internal_sd, /internal_sdcard, or /emmc in your fstab, then we will automatically assume that the device is using emulated storage.
    BOARD_HAS_NO_REAL_SDCARD := true -- disables things like sdcard partitioning and may save you some space if TWRP isn't fitting in your recovery patition
    TW_NO_BATT_PERCENT := true -- disables the display of the battery percentage for devices that don't support it properly
    TW_CUSTOM_POWER_BUTTON := 107 -- custom maps the power button for the lockscreen
    TW_NO_REBOOT_BOOTLOADER := true -- removes the reboot bootloader button from the reboot menu
    TW_NO_REBOOT_RECOVERY := true -- removes the reboot recovery button from the reboot menu
    RECOVERY_TOUCHSCREEN_SWAP_XY := true -- swaps the mapping of touches between the X and Y axis
    RECOVERY_TOUCHSCREEN_FLIP_Y := true -- flips y axis touchscreen values
    RECOVERY_TOUCHSCREEN_FLIP_X := true -- flips x axis touchscreen values

    TWRP_EVENT_LOGGING := true -- enables touch event logging to help debug touchscreen issues (don't leave this on for a release - it will fill up your logfile very quickly)
    BOARD_HAS_FLIPPED_SCREEN := true -- flips the screen upside down for screens that were mounted upside-down

    There are other build flags which you can locate by scanning the Android.mk files in the recovery source. Most of the other build flags are not often used and thus I won't document them all here.

    *RECOVERY.FSTAB*
    TWRP 2.5 and higher supports some new recovery.fstab features that you can use to extend TWRP's backup/restore capabilities. You do not have to add fstab flags as most partitions are handled automatically.

    Note that TWRP only supports v2 fstabs in version 3.2.0 and higher. You will still need to use the "old" format of fstab for older TWRP (example of that format is below), and even TWRP 3.2.0 still supports the v1 format in addition to the v2 format. To maximize TWRP's compatibility with your build tree, you can create a twrp.fstab and use PRODUCT_COPY_FILES to place the file in /etc/twrp.fstab When TWRP boots, if it finds a twrp.fstab in the ramdisk it will rename /etc/recovery.fstab to /etc/recovery.fstab.bak and then rename /etc/twrp.fstab to /etc/recovery.fstab. Effectively this will "replace" the fstab 2 file that your device files are providing with the TWRP fstab allowing you to maintain compatibility within your device files and with other recoveries.
    Code:
    PRODUCT_COPY_FILES += device/lge/hammerhead/twrp.fstab:recovery/root/etc/twrp.fstab

    The fstab in TWRP can contain some "flags" for each partition listed in the fstab.

    Here's a sample TWRP fstab for the Galaxy S4 that we will use for reference:
    Code:
    /boot       emmc        /dev/block/platform/msm_sdcc.1/by-name/boot
    /system     ext4        /dev/block/platform/msm_sdcc.1/by-name/system
    /data       ext4        /dev/block/platform/msm_sdcc.1/by-name/userdata length=-16384
    /cache      ext4        /dev/block/platform/msm_sdcc.1/by-name/cache
    /recovery   emmc        /dev/block/platform/msm_sdcc.1/by-name/recovery
    /efs        ext4        /dev/block/platform/msm_sdcc.1/by-name/efs                            flags=display="EFS";backup=1
    /external_sd     vfat       /dev/block/mmcblk1p1    /dev/block/mmcblk1   flags=display="Micro SDcard";storage;wipeingui;removable
    /usb-otg         vfat       /dev/block/sda1         /dev/block/sda       flags=display="USB-OTG";storage;wipeingui;removable
    /preload    ext4        /dev/block/platform/msm_sdcc.1/by-name/hidden                            flags=display="Preload";wipeingui;backup=1
    /modem      ext4        /dev/block/platform/msm_sdcc.1/by-name/apnhlos
    /mdm		emmc		/dev/block/platform/msm_sdcc.1/by-name/mdm

    Flags are added to the end of the partition listing in the fstab separated by white space (spaces or tabs are fine). The flags affect only that partition but not any of the others. Flags are separated by semicolons. If your display name is going to have a space, you must surround the display name with quotes.
    Code:
    /external_sd  vfat  /dev/block/mmcblk1p1  flags=display="Micro SDcard";storage;wipeingui;removable
    The flags for this partition give it a display name of "Micro SDcard" which is displayed to the user. wipeingui makes this partition available for wiping in the advanced wipe menu. The removable flag indicates that sometimes this partition may not be present preventing mounting errors from being displayed during startup. Here is a full list of flags:
    removable -- indicates that the partition may not be present preventing mounting errors from being displayed during boot
    storage -- indicates that the partition can be used as storage which makes the partition available as storage for backup, restore, zip installs, etc.
    settingsstorage -- only one partition should be set as settings storage, this partition is used as the location for storing TWRP's settings file
    canbewiped -- indicates that the partition can be wiped by the back-end system, but may not be listed in the GUI for wiping by the user
    userrmrf -- overrides the normal format type of wiping and only allows the partition to be wiped using the rm -rf command
    backup= -- must be succeeded by the equals sign, so backup=1 or backup=0, 1 indicates that the partition can be listed in the backup/restore list while 0 ensures that this partition will not show up in the backup list.
    wipeingui -- makes the partition show up in the GUI to allow the user to select it for wiping in the advanced wipe menu
    wipeduringfactoryreset -- the partition will be wiped during a factory reset
    ignoreblkid -- blkid is used to determine what file system is in use by TWRP, this flag will cause TWRP to skip/ignore the results of blkid and use the file system specified in the fstab only
    retainlayoutversion -- causes TWRP to retain the .layoutversion file in /data on devices like Sony Xperia S which sort of uses /data/media but still has a separate /sdcard partition
    symlink= -- causes TWRP to run an additional mount command when mounting the partition, generally used with /data/media to create /sdcard
    display= -- sets a display name for the partition for listing in the GUI
    storagename= -- sets a storage name for the partition for listing in the GUI storage list
    backupname= -- sets a backup name for the partition for listing in the GUI backup/restore list
    length= -- usually used to reserve empty space at the end of the /data partition for storing the decryption key when Android's full device encryption is present, not setting this may lead to the inability to encrypt the device
    canencryptbackup= -- 1 or 0 to enable/disable, makes TWRP encrypt the backup of this partition if the user chooses encryption (only applies to tar backups, not images)
    userdataencryptbackup= -- 1 or 0 to enable/disable, makes TWRP encrypt only the userdata portion of this partition, certain subfuldes like /data/app would not be encrypted to save time
    subpartitionof= -- must be succeeded by the equals sign and the path of the partition it is a subpartition of. A subpartition is treated as "part" of the main partition so for instance, TWRP automatically makes /datadata a subpartition of /data. This means that /datadata will not show up in the GUI listings, but /datadata would be wiped, backed up, restored, mounted, and unmounted anytime those operations are performed on /data. A good example of the use of subpartitions is the 3x efs partitions on the LG Optimus G:
    Code:
    /efs1         emmc   /dev/block/mmcblk0p12 flags=backup=1;display=EFS
    /efs2         emmc   /dev/block/mmcblk0p13 flags=backup=1;subpartitionof=/efs1
    /efs3         emmc   /dev/block/mmcblk0p14 flags=backup=1;subpartitionof=/efs1
    This lumps all 3 partitions into a single "EFS" entry in the TWRP GUI allowing all three to be backed up and restored together under a single entry.

    As of TWRP 3.2.0, TWRP now supports a version 2 fstab like those that have been found in Android devices for years. Yes, I know we're really slow to adopt this one, but I also saw no major advantage to v2 and the v2 fstab was being used in regular Android as well as recovery and I didn't want full ROM builds crashing or doing other weird things because of TWRP flags being present in the fstab. Version 2 fstab support is automatic. You don’t need to add any build flags. The regular version 1 fstab format is also still valid and it’s possible to use both v1 and v2 types in the same fstab. TWRP 3.2.0 also supports using wildcards via the asterisk in v1 format which can be useful for USB OTG and micro SD cards with multiple partitions. Note also that v2 fstab formats haven’t been extensively tested so developers should test their v2 fstabs before shipping to users (you should always be testing anyway!).

    This is a v1 fstab line with a wildcard intended for a USB OTG drive. All partitions should show up in the list of available storage devices when the user plugs in a drive:

    Code:
    /usb-otg  vfat   /dev/block/sda*  flags=removable;storage;display=USB-OTG

    This line is straight from the v2 fstab for the same device and also should work. In this case the kernel will notify us that new devices have been added or removed via uevents:

    Code:
    /devices/soc.0/f9200000.ssusb/f9200000.dwc3/xhci-hcd.0.auto/usb*    auto      auto    defaults      voldmanaged=usb:auto

    In addition to the v2 fstab, you can include /etc/twrp.flags which uses the v1 fstab format. The twrp.flags file can be used to supplement the v2 fstab with TWRP flags, additional partitions not included in the v2 fstab, and to override settings in the v2 fstab. For example, I have a Huawei device with the following stock v2 fstab present as /etc/recovery.fstab

    Code:
    # Android fstab file.
    #<src>                                                  <mnt_point>         <type>    <mnt_flags and options>                       <fs_mgr_flags>
    # The filesystem that contains the filesystem checker binary (typically /system) cannot
    # specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK
    /dev/block/bootdevice/by-name/system    /system    ext4    ro,barrier=1    wait,verify
    /dev/block/bootdevice/by-name/cust    /cust    ext4    ro,barrier=1    wait,verify
    /devices/hi_mci.1/mmc_host/mmc1/*                       auto                auto      defaults                                      voldmanaged=sdcard:auto,noemulatedsd
    /devices/hisi-usb-otg/usb1/*                            auto                auto      defaults                                      voldmanaged=usbotg:auto
    /dev/block/bootdevice/by-name/userdata         /data                f2fs     nosuid,nodev,noatime,discard,inline_data,inline_xattr wait,forceencrypt=footer,check
    /dev/block/bootdevice/by-name/cache         /cache                ext4      rw,nosuid,nodev,noatime,data=ordered wait,check
    /dev/block/bootdevice/by-name/splash2         /splash2                ext4      rw,nosuid,nodev,noatime,data=ordered,context=u:object_r:splash2_data_file:s0 wait,check
    /dev/block/bootdevice/by-name/secure_storage         /sec_storage                ext4      rw,nosuid,nodev,noatime,discard,auto_da_alloc,mblk_io_submit,data=journal,context=u:object_r:teecd_data_file:s0 wait,check

    In addition I have also included this in /etc/twrp.flags:

    Code:
    /boot         emmc       /dev/block/platform/hi_mci.0/by-name/boot
    /recovery     emmc       /dev/block/platform/hi_mci.0/by-name/recovery   flags=backup=1
    /cust         ext4       /dev/block/platform/hi_mci.0/by-name/cust       flags=display="Cust";backup=1
    /misc         emmc       /dev/block/platform/hi_mci.0/by-name/misc
    /oeminfo      emmc       /dev/block/platform/hi_mci.0/by-name/oeminfo    flags=display="OEMinfo";backup=1
    /data         f2fs       /dev/block/dm-0
    /system_image emmc       /dev/block/platform/hi_mci.0/by-name/system

    The first 2 lines in twrp.flags adds the boot and recovery partitions which were not present at all in the v2 fstab. The /cust line in the twrp.flags file is added to tell TWRP to allow users to back up the cust partition and to give it a slightly better display name. The /misc partition is also only present in the twrp.flags file. Much like the /cust partition, the /oeminfo partition is in the twrp.flags file to tell TWRP to allow users to back it up and give a display name. The /data line is needed because this Huawei device, like many Huawei devices, is encrypted but the encryption uses some special Huawei binaries and is encrypted with some sort of default password that the user cannot change. We use the Huawei binaries to decrypt the device automatically in recovery. The /data line here tells TWRP to use /dev/block/dm-0 instead of /dev/block/bootdevice/by-name/userdata which is required for proper mounting, etc. Lastly we have the /system_image line so that TWRP will add a system image option for backup and restore.

    As we add more new devices, we’ll add more example device trees to https://github.com/TeamWin/ which should help you find more ways to use this new fstab support. Please note that using the v2 fstab format at this point is completely optional, so feel free to continue using v1 if that is what is more comfortable or if you have trouble with the v2 format support.

    If you have questions, feel free to stop by #twrp on Freenode. If you post here I may not see it for a while as I have lots of threads out there and there's no way for me to keep track of them all. If you successfully port TWRP to a new device, please let us know! We love to hear success stories!

    If you have code changes that you'd like to submit, please submit them through the Omni Gerrit server. Guide is here.

    Once you get Omni or CM sync'ed and your TWRP flags set, you should do a source ./build/envsetup.sh We usually lunch for the device in question, so something like "lunch omni_hammerhead-eng".

    After you lunch successfully for your device this is the command used for most devices:
    Code:
    make clean && make -j# recoveryimage

    Replace the # with the core count +1, so if you have a dual core it's -j3 and a quad core becomes -j5, etc. If you're dealing with a "typical" Samsung device, then you'll need to
    Code:
    make -j# bootimage
    Most Samsung devices have the recovery included as an extra ramdisk in the boot image instead of a separate recovery partition as found on most other devices.

    Old guide here: http://forum.xda-developers.com/showpost.php?p=65482905&postcount=1471
    119
    So, now, hopefully you've compiled TWRP for your device and gotten it working. Now, you'd like to know how to get TWRP officially supported for your device so that it can be installed automatically with the TWRP app. In order for us to add "official support" for your device we'll need the following:
    1) Device configuration files to compile TWRP from source for your device. This means that you cannot have repacked a recovery.img by hand to get it working. We need to be able to compile it from source so that we can easily release future updates.
    2) We'll build a copy of TWRP and send it to you for validation. Once you've validated that we can build a working image for your device, we'll add it to the official TWRP app.

    Note that we won't take credit for your port. You'll still get to post it on XDA to collect all the credit that goes with releasing something new for your device along with having your name listed on our website as the maintainer for the device. Also note that it's not always possible to provide automated installs for all devices.

    You can now boot TWRP in an emulator. If you're trying to help develop TWRP, this can be a huge help as you don't have to risk your device and you can do everything directly on your computer.
    jPYg.png


    Download this set of device configuration files.

    Compile a recoveryimage using those device files. In the Android SDK, click on Tools -> Manage AVDs. Click New. Set it up as the following:
    AVD Name: TWRP
    Device: Galaxy Nexus
    Target: ICS or newer though anything will probably work here
    CPU: ARM (armeabi-v7a)
    Check the box for hardware keyboard (your computer's keyboard will work in TWRP)
    Up to you if you want to have the skin with controls present
    Front Camera: None
    Back Camera: None
    RAM: 1024 VM Heap: 64
    Internal Storage: 200
    SD Card: Size: 500 MiB

    Then click OK.

    Once you have your AVD and your recoveryimage, you can boot TWRP in the emulator by browsing to your android-sdk/tools folder and run this command:
    ./emulator -avd TWRP -ramdisk CMFOLDER/out/target/product/twrp/ramdisk-recovery.img

    Note that ADB doesn't work right away. About 10 to 15 seconds after TWRP finishes booting, ADB will come online. We start ADB via init.rc so even if TWRP fails to boot due to some kind of code error that you may have made, ADB should still work. Enjoy!
    117
    TWRP and A/B devices:

    From a TWRP standpoint, A/B devices aren't a whole lot different from regular devices, but developers seem to be shy about working on these devices. I'm going to try to shed some light on this subject and hopefully this will serve as a guide for porting TWRP to A/B devices.

    Firstly, let's understand what is an A/B device and how it's different. A/B devices have duplicates of many partitions on the device. An A/B device has 2x system partitions, 2x boot partitions, 2x vendor partitions, 2x modem / firmware partitions, etc. Only one slot is in use at a time. During early boot, the first stages of the bootloader read some small amount of data called the BCB or Bootloader Control Block and decide whether to boot the A partitions or the B partitions. When an OTA update is available, the data from the active slot is copied from the inactive slot and patched / updated. For example, if you're currently on slot A, your device would download the update and copy the existing system partition from slot A and patch / update it with the new updates into slot B. Once the copying and updating is complete, the BCB is updated and the device reboots using slot B. Next time an update is available, the system partition in slot B is copied to slot A and updated, the BCB gets updated, and we reboot to slot A. When viewing partitions on the device, you'll see something like this:

    Code:
    /dev/block/bootdevice/by-name/boot_a
    /dev/block/bootdevice/by-name/boot_b
    /dev/block/bootdevice/by-name/system_a
    /dev/block/bootdevice/by-name/system_b
    /dev/block/bootdevice/by-name/userdata
    /dev/block/bootdevice/by-name/vendor_a
    /dev/block/bootdevice/by-name/vendor_b

    Note the dual boot, system and vendor partitions in the list above, but only one userdata partition.

    While there is technically no requirement that I am aware of, all A/B devices shipped thus far have no separate recovery partition. Instead, the boot image contains the recovery in its ramdisk. The important thing is knowing that the boot image now also contains the recovery. For completeness, the system partition is a full root file system. During boot, if the kernel is told to boot to recovery, it will extract the ramdisk in the boot partition. If the kernel is not told by the bootloader to boot to recovery, then the kernel will mount the appropriate system partition (A or B) because the system partition is a full root file system. This means that the system partition on these devices is mounted to / instead of to /system and the system partition contains all of the files that would have normally been in the boot image ramdisk and a /system subfolder.

    From a TWRP standpoint, there are 3 things that you have to do for an A/B device. First, you need to set
    Code:
    AB_OTA_UPDATER := true
    in your BoardConfig.mk. Secondly, for any partition that has an A/B option, you need to add
    Code:
    flags=slotselect
    in your fstab so something like this:
    Code:
    /boot		emmc	/dev/block/bootdevice/by-name/boot	flags=slotselect
    /system		ext4	/dev/block/bootdevice/by-name/system	flags=slotselect
    /system_image	emmc	/dev/block/bootdevice/by-name/system	flags=slotselect
    /vendor		ext4	/dev/block/bootdevice/by-name/vendor	flags=slotselect;display="Vendor";backup=1
    /vendor_image	emmc	/dev/block/bootdevice/by-name/vendor	flags=slotselect

    Lastly, once you get into TWRP, you will probably want to make sure that bootctl hal-info responds correctly with no errors. Usually the bootctl binary requires a proprietary library or even a couple of services to work correctly. If bootctl does not work correctly, then you will not be able to switch slots within TWRP correctly either.

    In addition to setting
    Code:
    AB_OTA_UPDATER := true
    you may also want to set:
    Code:
    BOARD_USES_RECOVERY_AS_BOOT := true
    BOARD_BUILD_SYSTEM_ROOT_IMAGE := true

    If you set
    Code:
    BOARD_USES_RECOVERY_AS_BOOT := true
    then make recoveryimage will no longer work and instead you will have to make bootimage. I don't recommend setting either of these flags for TWRP-only build trees. These flags will probably be required for developers building full ROMs for A/B devices.

    Installing / Flashing TWRP on A/B devices:

    Since all known A/B devices do not have a separate recovery partition, you will eventually have to flash TWRP to the boot partition. On the Pixel 1 and 2, we use fastboot boot to temporarily boot TWRP without flashing TWRP. We are then supplying a zip to allow users to flash TWRP to both slots. You can download one of these zips from our website and update the zip as needed to support your devices. Eventually we will add tools to TWRP to allow users to flash recoveries on these devices without needing to use zips.

    Recently, I worked on the Razer Phone. The Razer Phone unfortunately does not support fastboot boot. Instead, users have to determine their currently active boot slot using
    Code:
    adb shell getprop ro.boot.slot_suffix
    then use
    Code:
    fastboot --set-active=_a
    to switch slots to the inactive slot. From here, the user can
    Code:
    fastboot flash boot twrp.img && fastboot reboot
    to get into TWRP. Once in TWRP they can then go to the reboot page and change back to their originally active slot, make a backup, then install TWRP. Using the inactive slot allows users to get a good, unmodified backup of their device before installing TWRP.

    Hopefully this helps!

    Debugging with gdb in TWRP guide can be found here!
    19
    gdb in TWRP

    gdb in TWRP

    To make things quick and easy, the TLDR version is to create a script with the below code. After booting up TWRP, from the same terminal where you have done your source ./build/envsetup.sh and lunch commands, run this script:
    Code:
    if [ ! -f $OUT/system/bin/gdbserver64 ]; then
        echo Building gdbserver64
        make -j8 gdbserver64
    fi
    adb shell stop recovery
    adb push $OUT/system/bin/gdbserver /sbin/
    adb shell chmod 755 /sbin/gdbserver
    adb forward tcp:5039 tcp:5039
    cp $OUT/symbols/recovery/root/sbin/recovery $OUT/symbols/sbin/recovery
    adb push $OUT/symbols/sbin/recovery /sbin/recovery && adb shell chmod 755 /sbin/recovery
    cp $OUT/symbols/system/bin/linker64 $OUT/symbols/sbin/linker64
    cp $OUT/symbols/system/lib64/* $OUT/symbols/sbin
    if [ "$#" = 1 ]; then
    	adb push $OUT/symbols/sbin/$1 /sbin/
    fi
    echo In another terminal run:
    echo gdbclient pid_goes_here
    adb shell gdbserver :5039 /sbin/recovery
    Then in another terminal you will need to source ./build/envsetup.sh and lunch again then run gdbclient pid_goes_here

    THE LONG VERSION:

    This guide was using an Omni 8.1 build tree and the target device was the Razer Phone 2. Since the target device was using aarch64, paths and files may be using “64” in them. If your device is using 32 bit, you can remove 64 from the paths and filenames where needed. You must be able to compile TWRP from source and have some basic knowledge of Linux. Your device must have working adb while in TWRP. The basis for this guide came from the following sites, but reading these sites should not be necessary:
    https://source.android.com/devices/tech/debug/gdb
    https://packmad.github.io/gdb-android/
    https://wladimir-tm4pda.github.io/porting/debugging_gdb.html

    Compile your TWRP image as usual with
    Code:
    make recoveryimage
    and then boot up TWRP. If TWRP is crashing during startup, you may want to
    Code:
    adb shell stop recovery
    so that the recovery service stops and you end the crash loop. This guide assumes that you want to debug TWRP while TWRP starts up.

    The compiled recovery image contains many binaries and libraries that have been stripped of their debugging symbols. The stripped binaries are smaller, but gdb will need access to the unstripped binaries and libraries to assist with debugging. gdb expects to find these binaries and libraries in the same relative path as they are on the device. Unfortunately, in order to get TWRP to work with the linker while in recovery, the build process of TWRP moves binaries and libraries into places that they normally aren’t located (see bootable/recovery/prebuilt/Android.mk if you want a better understanding). You will have to move the unstripped binaries and libraries around a bit to make gdb happy.

    First you will need gdbserver64 which you can compile using
    Code:
    make gdbserver64
    Once gdbserver64 is compiled you must push it to the device with
    Code:
    adb push $OUT/system/bin/gdbserver64 /sbin
    followed by
    Code:
    adb shell chmod 755 /sbin/gdbserver64
    You may also need to issue this command, but I’m not sure if it is required:
    Code:
    adb forward tcp:5039 tcp:5039
    Finally open a new terminal and issue
    Code:
    adb shell gdbserver64 :5039 /sbin/recovery
    You will need to make note of the number at the end of the first line of the output:
    Code:
    Process /sbin/recovery created; pid = [COLOR="Green"]575[/COLOR]

    The first problem that I ran into was that the device uses ro.hardware of qcom and for some reason, the gdbclient expected the symbols files to be in out/target/product/qcom/symbols. If you run into this issue, you’ll have to manually change ro.hardware to match the codename of the device which may require you to change the kernel cmdline. The other option is to simply create the out/target/product/qcom/symbols directory yourself and
    Code:
    cp -R $OUT/symbols $OUT/../qcom/symbols
    I suppose a third option would be to modify the gdbclient code to look in the right place for the symbols, but I didn’t attempt this yet.

    From here you still need to move more things around. Specifically you will need to move symbols/recovery/root/sbin/recovery to symbols/sbin/recovery. Then for the shared libraries, you’ll need to copy everything in symbols/system/lib64 to symbols/sbin. Finally, you’ll need to copy symbols/system/bin/linker64 into symbols/sbin as well.

    In addition, you need to push the unstripped recovery binary to the device so that gdb can match up the symbols with functions and line numbers in the TWRP code:
    Code:
    adb push $OUT/symbols/sbin/recovery /sbin/recovery && adb shell chmod 755 /sbin/recovery

    If you are working on a shared library, you'll also want to push the unstripped library:
    Code:
    adb push $OUT/symbols/sbin/libfoo.so /sbin/libfoo.so

    Now that you have everything where you need it, you can run the gdbclient command from the original terminal where you were issuing your make commands:
    Code:
    gdbclient 575
    where 575 is the pid from your other terminal. You should see some output like this:

    Code:
    It looks like gdbserver is already attached to 575 (process is traced), trying to connect to it using local port=5039
    GNU gdb (GDB) 7.11
    Copyright (C) 2016 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from /home/dees_troy/build/oomni/out/target/product/qcom/symbols/sbin/recovery...done.
    __dl__start () at bionic/linker/arch/arm64/begin.S:32
    32	  mov x0, sp
    (gdb)

    At which point you are at the (gdb) prompt. You can type
    Code:
    continue
    and hit enter to have TWRP continue to load. Once TWRP crashes, you can type
    Code:
    bt
    and hit enter to get the backtrace which should give you a better idea of where things went wrong. Type
    Code:
    quit
    and hit enter to exit the debugging session.

    Hope that helps!
    19
    Old guide which might be useful if someone is building with an older version:

    All of TWRP 2.x source is public. You can compile it on your own. This guide isn't going to be a step-by-step, word-for-word type of guide. If you're not familiar with basic Linux commands and/or building in AOSP then you probably won't be able to do this.

    You can currently use Omni 4.3, Omni 4.4, Omni 5.0, CM10.0, CM10.1, CM10.2, and CM11.0 source code. Omni 4.4 or 5.0 is recommended. Lately CM keeps making changes that make building TWRP more difficult and they make no effort to work with TWRP. You can build in CM but you may run into a few minor issues. If you don't know how to fix make file issues, then you should choose to use Omni instead. (If for some reason you need to compile in an older tree like CM9 or CM7, you will have to use the android-4.4 branch which we will not continue to update.)

    If you are using CM, you'll need to replace CM/bootable/recovery with this:
    https://github.com/omnirom/android_bootable_recovery
    Select the newest branch available. This step is not necessary with Omni because Omni already includes TWRP source by default.
    If you are using CM 12.0 then you will probably want to cherry pick this patch into external/sepolicy: http://review.cyanogenmod.org/#/c/89474/

    If you are in a bind and want to try working with a smaller tree either due to disk space or download size, you can try using this manifest. It should work in most cases but there may be some situations where you will need more repos in your tree than this manifest provides:
    https://github.com/marduk191/recovery_manifest

    *BEFORE YOU COMPILE*
    Note: If you add or change any flags, you will need to make clean or make clobber before recompiling or your flag changes will not be picked up.

    Now that you have the source code, you'll need to set or change a few build flags for your device(s). Find the BoardConfig.mk for your device. The BoardConfig.mk is in your devices/manufacturer/codename folder (e.g. devices/lge/hammerhead/BoardConfig.mk). First, scan the BoardConfig.mk file for
    TARGET_RECOVERY_INITRC :=
    If your device has this line, it will have a path to a custom, prebuilt init.rc that is used in recovery. Most likely you will need to change the custom init.rc slightly. Find the recovery's init.rc file and open it. Near the top you will see something like this:
    Code:
    on init
    	export PATH /sbin
    	export LD_LIBRARY_PATH .:/sbin
    Add the last line needed. This line is needed to get the linker running. Unlike ClockworkMod, TWRP is a dynamically linked recovery. Dynamic linking allows us to save a considerable amount of space to help make sure that TWRP recovery images will fit on more devices. It also lets us use dynamically linked touchscreen binaries as seen on the Motorola Photon and Atrix and the HP TouchPad without having to mount /system.

    Your board config also needs to include architecture and platform settings. Usually these are already included if you're using device configs that someone else created, but if you created your own, you may need to add them. Without them, recovery may seg fault during startup and you'll just see the teamwin curtain flash on the screen over and over.

    We usually put all of our flags at the bottom of the BoardConfig.mk under a heading of #twrp For all devices you'll need to set a resolution. TWRP needs to know the resolution at compile time so that it knows what stock theme to include. You can only use resolutions that have a theme so if you don't see your resolution, you'll have to pick one that's less than or equal to your resolution. You can find the list of stock themes in bootable/recovery/gui/devices. So if your device has a 540x960 display, you would add this:
    DEVICE_RESOLUTION := 540x960

    Note that themes do not rotate, so the 1280x800 theme is intended for tablets and would not work on the Samsung Galaxy Note 1 that expects a 800x1280 type of theme.

    In addition to the resolution, we have the following build flags:
    RECOVERY_SDCARD_ON_DATA := true -- this enables proper handling of /data/media on devices that have this folder for storage (most Honeycomb and devices that originally shipped with ICS like Galaxy Nexus)
    RECOVERY_GRAPHICS_USE_LINELENGTH := true -- fixes slanty looking graphics on some devices
    BOARD_HAS_NO_REAL_SDCARD := true -- disables things like sdcard partitioning and may save you some space if TWRP isn't fitting in your recovery patition
    TW_INCLUDE_DUMLOCK := true -- includes HTC Dumlock for devices that need it
    TW_NO_BATT_PERCENT := true -- disables the display of the battery percentage for devices that don't support it properly
    TW_CUSTOM_POWER_BUTTON := 107 -- custom maps the power button for the lockscreen
    TW_NO_REBOOT_BOOTLOADER := true -- removes the reboot bootloader button from the reboot menu
    TW_NO_REBOOT_RECOVERY := true -- removes the reboot recovery button from the reboot menu
    TW_NO_USB_STORAGE := true -- removes the USB storage button on devices that don't support USB storage
    RECOVERY_TOUCHSCREEN_SWAP_XY := true -- swaps the mapping of touches between the X and Y axis
    RECOVERY_TOUCHSCREEN_FLIP_Y := true -- flips y axis touchscreen values
    RECOVERY_TOUCHSCREEN_FLIP_X := true -- flips x axis touchscreen values
    TW_ALWAYS_RMRF := true -- forces the rm -rf option to always be on (needed for some Motorola devices)
    TW_NEVER_UNMOUNT_SYSTEM := true -- never unmount system (needed for some Motorola devices)
    TW_INCLUDE_INJECTTWRP := true -- adds ability to inject TWRP into some Samsung boot images for Samsung devices that have recovery as a second ramdisk in the boot image
    TW_DEFAULT_EXTERNAL_STORAGE := true -- defaults to external storage instead of internal on dual storage devices (largely deprecated)
    TWRP_EVENT_LOGGING := true -- enables touch event logging to help debug touchscreen issues (don't leave this on for a release - it will fill up your logfile very quickly)

    Here's some flags that may help you, but are not specific to TWRP (works in CWM too):
    This flag has multiple options, but can be used to set different graphics modes that may be need to correct color space issues on some devices:
    TARGET_RECOVERY_PIXEL_FORMAT := "BGRA_8888"
    TARGET_RECOVERY_PIXEL_FORMAT := "RGBX_8888"
    TARGET_RECOVERY_PIXEL_FORMAT := "RGB_565"

    BOARD_HAS_FLIPPED_SCREEN := true -- flips the screen upside down for screens that were mounted upside-down
    TARGET_PREBUILT_RECOVERY_KERNEL := path/to/kernel -- use to specify a kernel specifically for building recovery

    *RECOVERY.FSTAB*
    TWRP 2.5 and higher supports some new recovery.fstab features that you can use to extend TWRP's backup/restore capabilities. You do not have to add fstab flags as most partitions are handled automatically.

    Note that TWRP does not currently support the "fstab 2" version of fstab files seen in 4.3 or higher. You will still need to use the "old" format of fstab for TWRP (example of that format is below). To maximize TWRP's compatibility with your build tree, you can create a twrp.fstab and use PRODUCT_COPY_FILES to place the file in /etc/twrp.fstab When TWRP boots, if it finds a twrp.fstab in the ramdisk it will rename /etc/recovery.fstab to /etc/recovery.fstab.bak and then rename /etc/twrp.fstab to /etc/recovery.fstab. Effectively this will "replace" the fstab 2 file that your device files are providing with the TWRP fstab allowing you to maintain compatibility within your device files and with other recoveries.
    Code:
    PRODUCT_COPY_FILES += device/lge/hammerhead/twrp.fstab:recovery/root/etc/twrp.fstab

    The fstab in TWRP can contain some "flags" for each partition listed in the fstab.

    Here's a sample TWRP fstab for the Galaxy S4 that we will use for reference:
    Code:
    /boot       emmc        /dev/block/platform/msm_sdcc.1/by-name/boot
    /system     ext4        /dev/block/platform/msm_sdcc.1/by-name/system
    /data       ext4        /dev/block/platform/msm_sdcc.1/by-name/userdata length=-16384
    /cache      ext4        /dev/block/platform/msm_sdcc.1/by-name/cache
    /recovery   emmc        /dev/block/platform/msm_sdcc.1/by-name/recovery
    /efs        ext4        /dev/block/platform/msm_sdcc.1/by-name/efs                            flags=display="EFS";backup=1
    /external_sd     vfat       /dev/block/mmcblk1p1    /dev/block/mmcblk1   flags=display="Micro SDcard";storage;wipeingui;removable
    /usb-otg         vfat       /dev/block/sda1         /dev/block/sda       flags=display="USB-OTG";storage;wipeingui;removable
    /preload    ext4        /dev/block/platform/msm_sdcc.1/by-name/hidden                            flags=display="Preload";wipeingui;backup=1
    /modem      ext4        /dev/block/platform/msm_sdcc.1/by-name/apnhlos
    /mdm		emmc		/dev/block/platform/msm_sdcc.1/by-name/mdm

    Flags are added to the end of the partition listing in the fstab separated by white space (spaces or tabs are fine). The flags affect only that partition but not any of the others. Flags are separated by semicolons. If your display name is going to have a space, you must surround the display name with quotes.
    Code:
    /external_sd  vfat  /dev/block/mmcblk1p1  flags=display="Micro SDcard";storage;wipeingui;removable
    The flags for this partition give it a display name of "Micro SDcard" which is displayed to the user. wipeingui makes this partition available for wiping in the advanced wipe menu. The removable flag indicates that sometimes this partition may not be present preventing mounting errors from being displayed during startup. Here is a full list of flags:
    removable -- indicates that the partition may not be present preventing mounting errors from being displayed during boot
    storage -- indicates that the partition can be used as storage which makes the partition available as storage for backup, restore, zip installs, etc.
    settingsstorage -- only one partition should be set as settings storage, this partition is used as the location for storing TWRP's settings file
    canbewiped -- indicates that the partition can be wiped by the back-end system, but may not be listed in the GUI for wiping by the user
    userrmrf -- overrides the normal format type of wiping and only allows the partition to be wiped using the rm -rf command
    backup= -- must be succeeded by the equals sign, so backup=1 or backup=0, 1 indicates that the partition can be listed in the backup/restore list while 0 ensures that this partition will not show up in the backup list.
    wipeingui -- makes the partition show up in the GUI to allow the user to select it for wiping in the advanced wipe menu
    wipeduringfactoryreset -- the partition will be wiped during a factory reset
    ignoreblkid -- blkid is used to determine what file system is in use by TWRP, this flag will cause TWRP to skip/ignore the results of blkid and use the file system specified in the fstab only
    retainlayoutversion -- causes TWRP to retain the .layoutversion file in /data on devices like Sony Xperia S which sort of uses /data/media but still has a separate /sdcard partition
    symlink= -- causes TWRP to run an additional mount command when mounting the partition, generally used with /data/media to create /sdcard
    display= -- sets a display name for the partition for listing in the GUI
    storagename= -- sets a storage name for the partition for listing in the GUI storage list
    backupname= -- sets a backup name for the partition for listing in the GUI backup/restore list
    length= -- usually used to reserve empty space at the end of the /data partition for storing the decryption key when Android's full device encryption is present, not setting this may lead to the inability to encrypt the device
    canencryptbackup= -- 1 or 0 to enable/disable, makes TWRP encrypt the backup of this partition if the user chooses encryption (only applies to tar backups, not images)
    userdataencryptbackup= -- 1 or 0 to enable/disable, makes TWRP encrypt only the userdata portion of this partition, certain subfuldes like /data/app would not be encrypted to save time
    subpartitionof= -- must be succeeded by the equals sign and the path of the partition it is a subpartition of. A subpartition is treated as "part" of the main partition so for instance, TWRP automatically makes /datadata a subpartition of /data. This means that /datadata will not show up in the GUI listings, but /datadata would be wiped, backed up, restored, mounted, and unmounted anytime those operations are performed on /data. A good example of the use of subpartitions is the 3x efs partitions on the LG Optimus G:
    Code:
    /efs1         emmc   /dev/block/mmcblk0p12 flags=backup=1;display=EFS
    /efs2         emmc   /dev/block/mmcblk0p13 flags=backup=1;subpartitionof=/efs1
    /efs3         emmc   /dev/block/mmcblk0p14 flags=backup=1;subpartitionof=/efs1
    This lumps all 3 partitions into a single "EFS" entry in the TWRP GUI allowing all three to be backed up and restored together under a single entry.

    If you have questions, feel free to stop by #twrp on Freenode. If you post here I may not see it for a while as I have lots of threads out there and there's no way for me to keep track of them all. If you successfully port TWRP to a new device, please let us know! We love to hear success stories!

    If you have code changes that you'd like to submit, please submit them through the Omni Gerrit server. Guide is here.

    Once you get Omni or CM sync'ed and your TWRP flags set, you should do a source ./build/envsetup.sh We usually lunch for the device in question, so something like "lunch omni_hammerhead-eng".

    After you lunch successfully for your device this is the command used for most devices:
    Code:
    make clean && make -j# recoveryimage

    Replace the # with the core count +1, so if you have a dual core it's -j3 and a quad core becomes -j5, etc. If you're dealing with a "typical" Samsung device, then you'll need to
    Code:
    make -j# bootimage
    Most Samsung devices have the recovery included as an extra ramdisk in the boot image instead of a separate recovery partition as found on most other devices.

    Notes about 4.4 Kit Kat ROMs and SELinux
    There's absolutely no SELinux support in ICS trees or older. libselinux is not included in these trees and some dependencies for libselinux don't exist elsewhere in these older trees so there's no way to get SELinux support unless you move to a newer tree. I recommend using a 4.3 based tree or higher.

    SELinux support is included in all builds of TWRP so long as you build in a tree that has libselinux present. However, for SELinux support to work, your kernel must support EXT4 security labels as well. If you're using an older kernel, your TWRP won't support SELinux and you will get errors when installing 4.4 Kit Kat ROMs due to set_metadata not being able to set SELinux contexts. You'll see an error in the recovery log stating something along the lines of "Operation not supported on transport endpoint." This means you need to add proper support to the kernel you are using in recovery. (Yes, at least in most cases, recovery has its own kernel.)

    In the kernel source I was testing, the needed flag was CONFIG_EXT4_FS_SECURITY=y and the option was called Ext4 Security Labels under the file systems menu. If you want full SELinux in your kernel you will need to add auditing support (usually found under general setup) then enable SELinux under security options. There's multiple flags and some dependencies involved so your setup may vary slightly.

    The android-4.4 branch of TWRP from Omni now includes a check during boot. You will see text in the log and in the console indicating the SELinux status. This should help you identify what issue(s) you may have with SELinux support.

    Deprecated build flags:
    For TWRP < 2.5:
    The below is how you can add custom / special partitions to the list of partitions available for backup. The SP1_NAME must match the name of a partition defined in recovery.fstab. The SP1_DISPLAY_NAME is the name displayed on the backup page if it needs to be different than SP1_NAME. SP1_BACKUP_METHOD defines how the partition should be backed up (files or image). And SP1_MOUNTABLE determines if the partition can be mounted.
    SP1_NAME := "pds"
    SP1_BACKUP_METHOD := files
    SP1_MOUNTABLE := 1
    SP2_NAME := "osh"
    SP2_DISPLAY_NAME := "Webtop"
    SP2_BACKUP_METHOD := files
    SP2_MOUNTABLE := 1
    SP3_NAME := "preinstall"
    SP3_BACKUP_METHOD := image
    SP3_MOUNTABLE := 0
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone