Jump to content

  1. 0
  2. 0
  3. 0/5

Rate this Topic

* * * * *
4 votes

How to Compile TWRP from Source

  • Please log in to reply

OP Dees_Troy

Dees_Troy

TeamWin

Posted 24 April 2012 - 06:14 AM #1

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 then you probably won't be able to do this.

You can currently use either CM7 or CM9 source code. Follow the correct part of the guide because the code base for CM9 is slightly different than for CM7. First you'll need to sync whichever code base you're going to work with and get it all set up to compile. I suggest that you follow one of the guides on the CM website like this one:

http://wiki.cyanogen...ogenMod_(Linux)

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". You must lunch and compile -eng builds. -userdebug will not work with recovery.

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.

Once you are certain that you can compile a working CWM build, it's time to start pulling in the source code that you'll need to build TWRP.

*FOR CM9*
You'll need to replace CM9/bootable/recovery with this:
https://github.com/T...covery-Project/

Now skip down to the "BEFORE YOU COMPILE" section and continue from there.

Note that if you've used this guide before, as of 5/28/2012 you no longer need a custom busybox setup. The busybox in the CM repo now supports everything that TWRP needs to function properly. If you haven't sync'ed CM recently you may need to resync to get the latest busybox changes.

*FOR CM7*
Bear in mind that pulling in some of this code may break your ability to compile CM7. You'll either need 2 copies of the CM7 source or set up some kind of script to swap the source code in and out automatically. And no I don't have such a script so don't ask :P

First remove and replace CM7/bootable/recovery with this:
https://github.com/T...covery-Project/

And finally replace the entire CM7/build folder with this:
https://github.com/D...TWRP2-CM7_build

Note that if you've used this guide before, as of 5/28/2012 you no longer need a custom busybox setup. The busybox in the CM repo now supports everything that TWRP needs to function properly. If you haven't sync'ed CM recently you may need to resync to get the latest busybox changes.

*BEFORE YOU COMPILE*
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 CM/devices/manufacturer/codename folder (e.g. CM/devices/hp/tenderloin/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:
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 will often seg fault during startup and you'll just see the teamwin curtain flash on the screen over and over.

You will also need at least one build flag for TWRP. 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 that expects a 800x1280 type of theme (which doesn't exist yet).

In addition to the resolution, we have the following build flags:
RECOVERY_GRAPHICS_USE_LINELENGTH := true -- fixes slanty looking graphics on some devices

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
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)
BOARD_HAS_NO_REAL_SDCARD := true -- disables things like sdcard partitioning
TW_INCLUDE_DUMLOCK := true -- includes HTC Dumlock for devices that need it

This is how you would define dual storage for devices that have dual storage devices. For devices that have internal storage we usually define that as /emmc. Note that the mount point must match something in the recovery.fstab
TW_INTERNAL_STORAGE_PATH := "/data/media"
TW_INTERNAL_STORAGE_MOUNT_POINT := "data"
TW_EXTERNAL_STORAGE_PATH := "/sdcard"
TW_EXTERNAL_STORAGE_MOUNT_POINT := "sdcard"

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_INCLUDE_BLOBPACK := true -- uses blobpack to restore boot images on Asus Transformer devices
TW_DEFAULT_EXTERNAL_STORAGE := true -- defaults to external storage instead of internal on dual storage devices
TW_FLASH_FROM_STORAGE := true -- flashes zips from their current location instead of copying them to /tmp for ROMs that are too large to fit in RAM. (We're considering making this the default behavior).
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

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 our Gerrit server. Guide is here.

Edited by Dees_Troy, 31 July 2012 - 06:15 AM.

  • 7 Likes

OP Dees_Troy

Dees_Troy

TeamWin

Posted 24 April 2012 - 06:27 AM #2

There is also this great guide and some device configs done by Smasher816 for Samsung Galaxy S 1 devices:
https://github.com/s...Project-Samsung
  • 0 Likes

OP Dees_Troy

Dees_Troy

TeamWin

Posted 24 April 2012 - 06:27 AM #3

Reserved...
  • 0 Likes

SlashDW

SlashDW

Android Enthusiast

Posted 24 April 2012 - 06:56 AM #4

Can't wait for my computer to get up and running so i can try to get this running on the G2x. Thanks for the info.

Sent from my LG-P999 using Tapatalk 2
  • 0 Likes
GSM Galaxy Nexus
ROM-AOKP's Latest Build
RECOVERY-TWRP's Latest
If you want to say thanks then get me some more space at Dropbox.com!

PonsAsinorem

PonsAsinorem

The Incredible Kangaroo

Posted 30 April 2012 - 11:12 PM #5

Going to try this for the Inc when I get a new computer.
  • 0 Likes

trter10

trter10

that dude

Posted 14 May 2012 - 06:51 PM #6

Don't know what's going wrong...

luke@ubuntu:~/android/system$ repo sync -j3
Fetching projects: 100% (313/313), done.  
fatal: Unable to create '/home/luke/android/.git/index.lock': Permission denied
Checking out files: 100% (413/413), done.ng out files:   2% (9/413)   
Checking out files: 100% (5192/5192), done. out files:   0% (35/5192)   
Checking out files: 100% (618/618), done.ng out files:   2% (18/618)   
Checking out files: 100% (136/136), done.ng out files:  29% (40/136)   
Syncing work tree:  87% (273/313)  fatal: cannot create directory at 'src/com/android/settings/deviceinfo': No space left on device
Traceback (most recent call last):
  File "/home/luke/.repo/repo/main.py", line 385, in <module>
    _Main(sys.argv[1:])
  File "/home/luke/.repo/repo/main.py", line 365, in _Main
    result = repo._Run(argv) or 0
  File "/home/luke/.repo/repo/main.py", line 137, in _Run
    result = cmd.Execute(copts, cargs)
  File "/home/luke/.repo/repo/subcmds/sync.py", line 467, in Execute
    project.Sync_LocalHalf(syncbuf)
  File "/home/luke/.repo/repo/project.py", line 1027, in Sync_LocalHalf
    self._InitWorkTree()
  File "/home/luke/.repo/repo/project.py", line 1814, in _InitWorkTree
    raise GitError("cannot initialize work tree")
error.GitError: cannot initialize work tree
luke@ubuntu:~/android/system$ 

  • 0 Likes

doug piston

doug piston

n00blet

Posted 14 May 2012 - 07:22 PM #7

What did you do before this error?
  • 0 Likes

trter10

trter10

that dude

Posted 15 May 2012 - 03:32 AM #8

I did repo sync -j3.
I had already synced one (took forever) got those errors at the end, so decided to try again.


Sent from my ADR6400L using RootzWiki
  • 0 Likes

cj360

cj360

Android Beginner

  • 24 posts

Posted 25 May 2012 - 03:28 PM #9

The github link for the cm9 sources (the 1st one) is down. I looked thru the other folders not really sure which one to use.
  • 1 Likes

OP Dees_Troy

Dees_Troy

TeamWin

Posted 29 May 2012 - 06:49 AM #10

The github link for the cm9 sources (the 1st one) is down. I looked thru the other folders not really sure which one to use.


Sorry, I merged branches and forgot to update the link. Guide should be all up to date now.
  • 2 Likes