[DEV]How to compile TWRP touch recovery

Search This thread

Young540

Member
Dec 22, 2020
15
6
[ 12% 1933/15605] Generated: (/home/yo.../target/product/mlv5/android-info.txt)
FAILED: /home/youngs/android/twrp9/out/target/product/mlv5/android-info.txt
/bin/bash -c "(build/make/tools/check_radio_versions.py ) && (echo \"board=mt6755\" > /home/youngs/android/twrp9/out/target/product/mlv5/android-info.txt )"
File "/home/youngs/android/twrp9/build/make/tools/check_radio_versions.py", line 56
print "*** Error opening \"%s.sha1\"; can't verify %s" % (fn, key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
[ 12% 1942/15605] target C++: recover...h <= bootable/recovery/rotate_logs.cpp
ninja: build stopped: subcommand failed.
18:51:24 ninja failed with: exit status 1

#### failed to build some targets (01:13 (mm:ss)) ####

what's wrong here ?
 
  • Like
Reactions: rom-g

travelbug

Senior Member
Oct 22, 2014
63
18
[ 12% 1933/15605] Generated: (/home/yo.../target/product/mlv5/android-info.txt)
FAILED: /home/youngs/android/twrp9/out/target/product/mlv5/android-info.txt
/bin/bash -c "(build/make/tools/check_radio_versions.py ) && (echo \"board=mt6755\" > /home/youngs/android/twrp9/out/target/product/mlv5/android-info.txt )"
File "/home/youngs/android/twrp9/build/make/tools/check_radio_versions.py", line 56
print "*** Error opening \"%s.sha1\"; can't verify %s" % (fn, key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
[ 12% 1942/15605] target C++: recover...h <= bootable/recovery/rotate_logs.cpp
ninja: build stopped: subcommand failed.
18:51:24 ninja failed with: exit status 1

#### failed to build some targets (01:13 (mm:ss)) ####

what's wrong here ?
@Young540
I had the same issue today and resolved that by updating the symlink for python to python2 not 3. Otherwise you will run into issues with print statements.

Do you have python2 installed? If not, do that first.

Check your current 'active' python version "python --version"
=> should be '3'

Symlink python2 "sudo ln -sf python2 /usr/bin/python" (at least this worked for me)

Check your current 'active' python version "python --version"
=> should be '2' now
 
  • Like
Reactions: GivFNZ

Young540

Member
Dec 22, 2020
15
6
@Young540
I had the same issue today and resolved that by updating the symlink for python to python2 not 3. Otherwise you will run into issues with print statements.

Do you have python2 installed? If not, do that first.

Check your current 'active' python version "python --version"
=> should be '3'

Symlink python2 "sudo ln -sf python2 /usr/bin/python" (at least this worked for me)

Check your current 'active' python version "python --version"
=> should be '2' now
Ok thanks, I will do so
 

Young540

Member
Dec 22, 2020
15
6
@Young540
I had the same issue today and resolved that by updating the symlink for python to python2 not 3. Otherwise you will run into issues with print statements.

Do you have python2 installed? If not, do that first.

Check your current 'active' python version "python --version"
=> should be '3'

Symlink python2 "sudo ln -sf python2 /usr/bin/python" (at least this worked for me)

Check your current 'active' python version "python --version"
=> should be '2' now
Thanks, It worked.
 
  • Like
Reactions: travelbug

DiamondJohn

Recognized Contributor
Aug 31, 2013
7,375
7,391
Sydney
i am in windows how i do it
I had never heard of people building Android from source using WSL. Vaguely new about WSL. Did a search and found this XDA link

Although, personally I like the separation besewn my windows & linux boxes; room for error and restart/reattempt. And that I can blow away my linux environment & start again or have multiple different Linux env on my one windows box (or even try out deferent versions of windows (or even other os's) without breaking my current windows box). I share drives between my linux boxes and even have virtual partitions (ie drives) on usb devices,
 

Rajnish@17

Member
Oct 21, 2018
10
1
[ 12% 1933/15605] Generated: (/home/yo.../target/product/mlv5/android-info.txt)
FAILED: /home/youngs/android/twrp9/out/target/product/mlv5/android-info.txt
/bin/bash -c "(build/make/tools/check_radio_versions.py ) && (echo \"board=mt6755\" > /home/youngs/android/twrp9/out/target/product/mlv5/android-info.txt )"
File "/home/youngs/android/twrp9/build/make/tools/check_radio_versions.py", line 56
print "*** Error opening \"%s.sha1\"; can't verify %s" % (fn, key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
[ 12% 1942/15605] target C++: recover...h <= bootable/recovery/rotate_logs.cpp
ninja: build stopped: subcommand failed.
18:51:24 ninja failed with: exit status 1

#### failed to build some targets (01:13 (mm:ss)) ####

what's wrong here
Use python2 instead of python3. i was having same problem because omni build only supports python2
 

ARDV

Senior Member
Apr 6, 2012
477
20
i'm using manjaro linux
i/m trying to compile TWRP for Huawei p10 vtr-l09
i'm using this repo:



github.com



GitHub - minimal-manifest-twrp/platform_manifest_twrp_omni: Minimal manifest for building TWRP for devices shipped with Android 5.1 through Android 9.0


Minimal manifest for building TWRP for devices shipped with Android 5.1 through Android 9.0 - minimal-manifest-twrp/platform_manifest_twrp_omni

github.com



and this is the device tree:



github.com



GitHub - josip-k/android_device_huawei_vtr: Device Tree for Huawei Phones


Device Tree for Huawei Phones. Contribute to josip-k/android_device_huawei_vtr development by creating an account on GitHub.

github.com



after:
cd twrp
export ALLOW_MISSING_DEPENDENCIES=true
i get:


Code:

./build/envsetup.sh
zsh: permission denied: ./build/envsetup.sh


when i try with root previllages i get:


Code:

sudo ./build/envsetup.sh
sudo: ./build/envsetup.sh: command not found
 
Last edited:

Fyramiz

Member
Oct 26, 2023
29
9
Can you please help me,ive compiled twrp(struggling as i don't have kernel source so used stock kernel which is big so i used TW_EXCLUDE tags) and the device is A/B unisoc powered device with super partition and i can't use fastboot boot as its a unisoc(tryed it in fastboot and fastbootd) and i tryed to just flash it to inactive slot but stuck at factory bootloader logo i restored device using SPD flash tool but recovery doesn't work, if any know solution plz tell me
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!
 

GivFNZ

Senior Member
Jan 30, 2019
80
28
Campinas
Moto G5 Plus
Moto G5S
@Young540
I had the same issue today and resolved that by updating the symlink for python to python2 not 3. Otherwise you will run into issues with print statements.

Do you have python2 installed? If not, do that first.

Check your current 'active' python version "python --version"
=> should be '3'

Symlink python2 "sudo ln -sf python2 /usr/bin/python" (at least this worked for me)

Check your current 'active' python version "python --version"
=> should be '2' now
Oh nice, I was having this issue too, but that fixed my issue, thank you!
 
  • Like
Reactions: Young540

Anghirrim

Senior Member
Apr 29, 2011
1,172
276
Google Nexus 5
Samsung Galaxy J5
Hello,

With ArchVisions, we recently managed to build TWRP for the Galaxy Tab S9 FE (here).

However, I have a questions regarding the patched vbmeta.img. Is it supposed to be device specific or generic?

I tried to compare some by unpacking them using the following tool: https://github.com/cfig/Android_boot_image_editor

The content of the output vbmeta.avb.json is different from one one vbmeta to another. One is almost completely empty (except from the structure), another one is a copy/paste of the stock vbmeta.img extract, and I couldn't understand how it can be called "patched".

Shall we always generate a patched vbmeta.img (knowing that on Samsung devices we have no fastboot), or can we just use an empty one (except from the structure)?

Thanks for your help.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    @Young540
    I had the same issue today and resolved that by updating the symlink for python to python2 not 3. Otherwise you will run into issues with print statements.

    Do you have python2 installed? If not, do that first.

    Check your current 'active' python version "python --version"
    => should be '3'

    Symlink python2 "sudo ln -sf python2 /usr/bin/python" (at least this worked for me)

    Check your current 'active' python version "python --version"
    => should be '2' now
    Oh nice, I was having this issue too, but that fixed my issue, thank you!
  • 420
    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://xdaforums.com/showpost.php?p=65482905&postcount=1471
    124
    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!
    124
    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!
    20
    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