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 4.4, Omni 5.1, Omni 6.0, CM11.0, CM 12.1, or CM 13.0 source code.Omni 5.1 or Omni 6.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 you are using CM, you'll need to place TWRP in the CM/bootable/recovery-twrp folder and set RECOVERY_VARIANT := twrp in your BoardConfig.mk file.TWRP source code can be found here:
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, 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
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
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 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.
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:
/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.
/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:
/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:
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
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/show...postcount=1471
[DEV]如何编译TWRP触摸recovery
所有的 TWRP 3.x 源码是公开的.你可以自己编译它。本指南不会是一个逐步的,逐字的类型的指南。如果您不熟悉基本的Linux命令和/或构建AOSP,那么您可能无法编译成功。 您可以使用Omni 4.4,Omni 5.1,Omni 6.0,CM11.0,CM 12.1或CM 13.0源代码。推荐使用Omni 5.1或Omni 6.0。最近,CM不断做出改变,使建立TWRP更加困难,他们不用努力与TWRP合作。你可以建立CM,但你可能遇到一些小问题。如果您不知道如何解决make文件问题,那么您应该选择使用Omni来代替。 如果你要使用CM, 你需要把TWRP放置在 CM/bootable/recovery-twrp 文件夹并且在你的 BoardConfig.mk 文件中设置 RECOVERY_VARIANT := twrp .TWRP源代码可以在这里找到:
https://github.com/omnirom/android_bootable_recovery
选择最新的可用分支。Omni不需要这一步,因为Omni默认已经包含TWRP源,但是如果您使用的是旧版本的Omni,则可能需要从最新的分支(最新的分支将在较旧的构建树中编译成功)
如果您只想构建TWRP,可以尝试使用较小的树。您可以尝试使用此清单。它应该在大多数情况下工作,但是在某些情况下,您可能需要在树中提供比这个清单更多的repos:
https://github.com/minimal-manifest-twrp
在 你 编 译 之 前
注意:如果添加或更改任何flags,在重新编译需要 make clean 或make clobber ,否则您的flags更改将不会被拾取。 现在你已经有源代码,您需要为你的设备设置或更改几个构建flags。在你的设备上找到 BoardConfig.mk。BoardConfig.mk 位于 devices/manufacturer/codename 文件夹(e.g. devices/lge/hammerhead/BoardConfig.mk). 您的board config将需要包括架构和平台设置。通常如果你使用一些人已经配置的设备配置,这些已经包括在内, 但如果你自己创建的, 你可能需要添加他们.除了那些,recovery会在整个启动中发送失败,你可能会看到teamwin在屏幕上不停的闪烁. 我们经常把我们的所有flags放在BoardConfig.mk 的底部 在 #twrp 头下, 对于所有设备你需要告诉TWRP使用什么主题.TW_THEME flag 代替了老的 DEVICE_RESOLUTION flag.TWRP现在使用缩放来拉伸任何主题以适应屏幕分辨率。目前有5中设置: portrait_hdpi, portrait_mdpi, landscape_hdpi, landscape_mdpi, and watch_mdpi.对于 portrait, 你可以选择 hdpi 主题当分辨率为 720x1280 或更高.对于 landscape 设备, 使用 hdpi 主题当分辨率为 1280x720 或更高. TW_THEME := portrait_hdpi
注意主题不能旋转90度并且目前没有可供旋转的主题.如果你发现触摸屏幕相对于屏幕是旋转的, 那么你可以使用一些flags(在指南的后面会讨论到)来选择触摸输入来匹配屏幕方向. 除了分辨率flags, 我们还有以下的构建flags:
RECOVERY_SDCARD_ON_DATA := true -- 这个开启适当的处理设备上的/data/media 这个文件夹用来储存 (大多数 Honeycomb 和设备出厂搭载ICS 比如Galaxy Nexus) 虽然这个flag对这些类型的设备不需要.如果你没有定义这个 flag 并且在你的fstab中也没有包括对于/sdcard, /internal_sd, /internal_sdcard, 或 /emmc 的任何引用, 那么我们会自动的假设设备使用的是模拟存储 BOARD_HAS_NO_REAL_SDCARD:= true - 如果TWRP不适合您的recovery 分区,禁用诸如sdcard分区之类的东西,则可能会节省一些空间
TW_NO_BATT_PERCENT:= true - 禁用对于电池百分比不正确支持的设备的显示
TW_CUSTOM_POWER_BUTTON:= 107 - 自定义映射锁定屏幕的电源按钮
TW_NO_REBOOT_BOOTLOADER:= true - 从重新启动重启菜单中删除重启到bootloader按钮
TW_NO_REBOOT_RECOVERY:= true - 从重新启动重启菜单中删除重启到recovery按钮
TW_NO_USB_STORAGE:= true - 在不支持USB存储的设备上删除USB存储按钮
RECOVERY_TOUCHSCREEN_SWAP_XY:= true - 交换X和Y轴之间的触摸的映射
RECOVERY_TOUCHSCREEN_FLIP_Y:= true - 翻转y轴触摸屏值
RECOVERY_TOUCHSCREEN_FLIP_X:= true - 翻转x轴触摸屏值
TWRP_EVENT_LOGGING:= t rue - 启用触摸事件记录来帮助调试触摸屏问题(请勿将其放在发行版上 - 它会很快填满您的日志文件)
BOARD_HAS_FLIPPED_SCREEN:= true - 对于屏幕是倒置安装的,将屏幕上下颠倒
还有其他的构建源码你可以在recovery源码中在 Android.mk 文件中找到其他大多数构建flags并不常用因此我没有把他们都写出来 RECOVERY.FSTAB
TWRP 2.5 或更高的版本支持一些新的 recovery.fstab 特性你可以使用拓展的 TWRP 备份/恢复功能.你并不需要添加fstab flags,大多数分区是自动处理的. 请注意,TWRP当前不支持"fstab 2"在4.3或更高版本中看到fstab文件.对于TWRP你仍然需要使用fstab的 "old" 格式 (该格式的示例如下).为了你的构建树的最大TWRP 兼容性, 你可以创建一个 twrp.fstab 并且使用 PRODUCT_COPY_FILES 将文件防止在 /etc/twrp.fstab 中. 当TWRP启动, 如果它发现了 twrp.fstab 在内存盘虚拟盘中,它会重命名 /etc/recovery.fstab 为 /etc/recovery.fstab.bak 并且重命名 /etc/twrp.fstab 为 /etc/recovery.fstab.这将有效地"替换"你的设备文件提供的fstab 2文件与TWRP fstab,允许您保持设备文件和其他recoveries的兼容性。
PRODUCT_COPY_FILES += device/lge/hammerhead/twrp.fstab:recovery/root/etc/twrp.fstab
TWRP中的fstab可以包含fstab中列出的每个分区的一些"flags". 以下是一个我们将使用做来参考的TWRP fstab 在Galaxy S4的示例.
/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已经添加在fstab分区表的末尾,分用白色空格分开(空格和Tab都可以).flags仅影响该分区,但不影响任何其他分区。Flags以分号分隔.如果你的显示名称有空格,则必须用引号括住显示名称.
/external_sd vfat /dev/block/mmcblk1p1 flags=display="Micro SDcard";storage;wipeingui;removable
此分区的flags给予的一个显示名称是“Micro SDcard”,显示给用户。wipeingui使此分区可用于擦除在高级擦除菜单中.可移动flag表示有时此分区可能不存在,防止在启动期间显示挂载错误。下面是一个完整的列表:
removable -- 表示分区可能不存在,防止在启动期间显示挂载错误
storage -- 表示分区可以被用来储存,使分区用来储存备份,恢复,zip安装,等 settingsstorage -- 只有一个分区应该设置为设置存储,该分区用作存储TWRP设置文件的位置
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:
/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
这将3个分区块放在TWRP GUI中的单个“EFS”条目中,允许3个分区块一起备份和恢复在一个条目中 如果您有任何问题,请随时停止并在Freenode上进入#twrp频道.如果你在这里发布,我可能暂时看不到,因为我有很多的论坛,我没有办法一一跟踪它们。如果您成功将TWRP移植到新设备上,请通知我们!我们喜欢听成功故事! 如果你要提交更改的代码,请通过Omni Gerrit服务器提交。Guide is here. 当你获得Omni 或CM 同步并且你的TWRP flags 已经设置, 你应该 source ./build/envsetup.sh .我们通常对设备lunch调试, 所以有时候像"lunch omni_hammerhead-eng". 在你对你的设备lunch成功后,这个命令应用于大多数设备:
make clean && make -j# recoveryimage
用 # 代替核心数+1, 所以说如果你有一个双核处理器那么就是-j3 如果是一个4核处理区那么就是 -j5, 以此类推.如果你正在处理一个"典型的"三星设备,那么你需要
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/show...postcount=1471