[DEV]How to compile TWRP touch recovery

Search This thread

Dees_Troy

Senior Recognized Developer
Mar 31, 2008
1,705
13,539
KC MO
www.teamw.in
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
 
Last edited:

Dees_Troy

Senior Recognized Developer
Mar 31, 2008
1,705
13,539
KC MO
www.teamw.in
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!
 
Last edited:

Dees_Troy

Senior Recognized Developer
Mar 31, 2008
1,705
13,539
KC MO
www.teamw.in
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!
 
Last edited:

sgt. meow

Senior Member
Dec 21, 2011
4,431
2,980
22
Dhaka
I know I've PM'ed you but I would like to ask you again. What should I do after compiling the TWRP recovery binary? What files have to be copied and where? I'm trying to integrate it with an ICS kernel.
 

mfsr98

Senior Member
Nov 26, 2011
1,231
291
Porto
Once you get CM sync'ed, I suggest that you go ahead and compile a build of ClockworkMod (ClockworkMod source is included in the CM repos). We usually lunch for the device in question, so something like "lunch full_tenderloin-eng".

After you lunch successfully for your device this is the command used for most devices:
Code:
make clean && make -j# recoveryimage
I don't get this part. What is lunch supposed to be? is it supposed to be a individual command for a device or can I do "lunch full_tenderloin-eng" for all devices? Because I am building for a device that doesn't run Android natively (at least out of-the-box) so cyanogenmod doesn't support it on any way...
Also, can I use this for resistive screens? Just to make sure.
Thanks for the guide, I have been looking for this for a long time :D
 

manuel100

Senior Member
Nov 19, 2011
129
30
ROME
thanks for the guide, well structured and not so complicated

i have only a question: i'm trying to build it for galaxy 5, the problem is that the resolution is 320x240, so can you tip me on modify the sources? (i've done this some days ago, but images were too large)
 
  • Like
Reactions: AJPuzon

mg2195

Senior Member
Dec 5, 2011
2,983
2,572
26
RSM
thanks for the guide, well structured and not so complicated

i have only a question: i'm trying to build it for galaxy 5, the problem is that the resolution is 320x240, so can you tip me on modify the sources? (i've done this some days ago, but images were too large)

Set the device resolution to 320x240...I'm pretty sure they have support for that resolution...and if they don't then you can copy one of there's except resize it all to 320x240

Edit-they only have 320x480 https://github.com/TeamWin/Team-Win-Recovery-Project/

My question: I built twrp from source a while ago using smasher's Samsung inject twrp zip...that worked fine for a while...but recently we switched to mtd format so that inject twrp zip doesn't work...neither does the inhect twrp button within twrp anymore...I've seen that the galaxy s has the same problem as well...just wondering if you know of a work around...

Sent from my SGH-I997 using Tapatalk 2
 
Last edited:

manuel100

Senior Member
Nov 19, 2011
129
30
ROME
Set the device resolution to 320x240...I'm pretty sure they have support for that resolution...and if they don't then you can copy one of there's except resize it all to 320x240

Edit-they only have 320x480 https://github.com/TeamWin/Team-Win-Recovery-Project/

My question: I built twrp from source a while ago using smasher's Samsung inject twrp zip...that worked fine for a while...but recently we switched to mtd format so that inject twrp zip doesn't work...neither does the inhect twrp button within twrp anymore...I've seen that the galaxy s has the same problem as well...just wondering if you know of a work around...

Sent from my SGH-I997 using Tapatalk 2

thanks for respond, however i've tried resizing images to 320x240 but i don't know what should be the size of bottoms, because they are alway out-of-screen

what is smasher's Samsung inject twrp zip? but i think that the recovery doesn't work because you have to built it with mtd support (for ex. on madteam they are trying to build a mtd kernel, but for install that testing rom they built a special cwm with mtd support)
 

mg2195

Senior Member
Dec 5, 2011
2,983
2,572
26
RSM
thanks for respond, however i've tried resizing images to 320x240 but i don't know what should be the size of bottoms, because they are alway out-of-screen

what is smasher's Samsung inject twrp zip? but i think that the recovery doesn't work because you have to built it with mtd support (for ex. on madteam they are trying to build a mtd kernel, but for install that testing rom they built a special cwm with mtd support)

Smashers inject twrp zip is a tool for Samsung devices that let's you get the recovery without flashing the whole kernel. You basically put the ramdisk-recovery.img in the zip and then flash. During the flash process it pulls the boot.img, replaces the current ramdisk-recovery.img with the new one that contains twrp. It then deletes the old boot.img and flashes the new one...not affecting the actual kernel...

The recovery itself has mtd support...I can use it if I flash the whole boot.img, but I don't want to release the recovery within a whole kernel...because then I have to keep it up to date with both twrp and kernel sources, not to mention the different kernels available for my device....I can't make a recovery for each kernel...don't have the time for that...that's where the inject came in handy....the user could use any kernel he wanted while still using twrp

Recovery logs say it fails to find the ramdisk inside the boot.img and then in parenthesis something about may not be using gzip compression...which it is....


Sent from my SGH-I997 using Tapatalk 2

---------- Post added at 07:21 AM ---------- Previous post was at 07:19 AM ----------

Deestroy did this same tutorial on rootzwiki...if you look at the second post you'll see info about the smasher inject twrp I was referring to...http://rootzwiki.com/index.php?/topic/23903-How-to-Compile-TWRP-from-Source

Sent from my SGH-I997 using Tapatalk 2
 

mfsr98

Senior Member
Nov 26, 2011
1,231
291
Porto
I don't get this part. What is lunch supposed to be? is it supposed to be a individual command for a device or can I do "lunch full_tenderloin-eng" for all devices? Because I am building for a device that doesn't run Android natively (at least out of-the-box) so cyanogenmod doesn't support it on any way...
Also, can I use this for resistive screens? Just to make sure.
Thanks for the guide, I have been looking for this for a long time :D
can I get help here please? :)
 
  • Like
Reactions: neutronjeff

mg2195

Senior Member
Dec 5, 2011
2,983
2,572
26
RSM
can I get help here please? :)

Its a single command...it opens up the menu for devices...just type lunch into the terminal and hit enter...you'll see what I mean. You will probably have to add your device to the menu by creating a vendorsetup.sh in your device repo if it doesn't already exist....

Sent from my SGH-I997 using Tapatalk 2
 

Dees_Troy

Senior Recognized Developer
Mar 31, 2008
1,705
13,539
KC MO
www.teamw.in
What about for android beginners???

There's only so much that you can dumb it down and simplify it. There's lots of other guides out there for getting started. Compiling a recovery is not a super simple task that anyone and everyone can do and there's plenty of potential pitfalls including the possibility of bricking your device. If none or very little of this guide makes sense, then you might see if a developer for your device is interested in working on it instead.
 

ktempleton

Senior Member
Oct 3, 2012
4,531
5,941
Lebanon
Hey guys I'm trying to compile this for my phone the problem I'm running into is I need the root.ts I've searched and it doesn't come up with anything any help would be appreciated thanks

Sent from my SAMSUNG-SGH-I577 using xda premium
 
Last edited:

gls9

Senior Member
Nov 13, 2011
233
47
I have a mtk6577 device which is not in de device tree of CM9.
I can compile CWM for my device with CM9. Because I was only making recovery, there was no need for setting up boardconfig.

In this guide there is a part starting with TARGET_RECOVERY_INITRC which is not there in my boardconfig.
Also is stated:
"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 will often seg fault during startup and you'll just see the teamwin curtain flash on the screen over and over."

Does this mean that I cannot build TWRP without it, even I can build CWM ?
 

Dees_Troy

Senior Recognized Developer
Mar 31, 2008
1,705
13,539
KC MO
www.teamw.in
I have a mtk6577 device which is not in de device tree of CM9.
I can compile CWM for my device with CM9. Because I was only making recovery, there was no need for setting up boardconfig.

In this guide there is a part starting with TARGET_RECOVERY_INITRC which is not there in my boardconfig.
Also is stated:
"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 will often seg fault during startup and you'll just see the teamwin curtain flash on the screen over and over."

Does this mean that I cannot build TWRP without it, even I can build CWM ?

Look for another mtk6577 device that has CM & copy the arch flags from it.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 2
    You could still build TWRP for 10.0 and use it with a 11.0 ROM as they are two seperate entities and don't interact with each other.
    No, building TWRP with A11 sources is required, considering the binder changes and due to the fact his device is using keymaster4.1. Right now, one must sync the whole AOSP source, specifically 11_r29.
    1
    I am trying to build a TWRP for my device OP8T. As i never did this before no experience and i do not know what does it mean this:
    "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."
    What is this clobber thing??
    Clobber wipes a partial build and starts the whole build process from the begining.
    Code:
    make clobber;
    For TWRP, its not such a big ask, as it only takes 8 minutes (on my box) to build it from go to woah, but doing a clobber on a full ROM can be arduous, as that could take 2hrs to start again and get to where your up to, with some people taking >24hrs. Starting from where it left off could save you a lot of time on a full ROM.

    Perssonally, I run the clobber on any build I expect to flash to my phone. Just to ensure I have a "clean" repeatable build.
    1
    minimal manifest does not support android 11 ? As i saw 10 is the highest branch...
    That's because it's not officially supported yet. They just recently made the jump to 10.0 as it needed a code restructuring. But that's no problem. You could still build TWRP for 10.0 and use it with a 11.0 ROM as they are two seperate entities and don't interact with each other.
    If you are interested in building 11.0 reguardless of it being officially supported you could change the branch values inside the manifests xml from "10" to "11". But as there are quite many different repositories with different naming schemes you'd need to check if the name is indeed the right branch.
    Maybe someone already did that on one of the many forks of platform_manifest_twrp_omni. You'd just need to search.
  • 401
    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