Porting Clockwork Recovery to New Devices

Update/Preface:

It is difficult for me to port recovery for a device I don’t have. So, people can attempt to port it using this guide. However, if you want it done properly, and probably quicker, you can loan the device to me personally at:

Koushik Dutta 2721 1st Ave 507 Seattle, WA 98121

The package must include:

  • The rooted phone.
  • A return packing slip to your address.
  • A signed statement saying: “I, <your name here>, am lending this device, <name of device>, to Koushik Dutta so that he can try to port Clockwork Recovery to the device. I understand that rooting a phone voids the warranty and tampering with the software may render the device nonfunctional. I realize and accept that the phone may not be functional when it is returned. Koushik Dutta is not liable for any damages to the device.”
  • BEFORE SENDING ME THE PACKAGE, CONFIRM WITH ME THAT I AM AVAILABLE TO PORT THE RECOVERY.

It will take around a week, and there are no gaurantees whether I will actually be able to do it (due to proprietary software, locked bootloaders, my schedule, etc). After a week (generally quicker), I will send it back. I’m a trustworthy guy and am well known in the Android community. And I’ve already done this for several loaner devices. Smile So you don’t need to worry about the safety of your precious hardware.

Otherwise, continue on the to the guide!

  • This guide will assume you have some familiarity with doing an Android Build.
  • This guide will work for phones that use a standard Android boot image format. This guide will not work for Samsung phones which use an initramfs.

First, let's check out the CyanogenMod tree. The CyanogenMod repository contains Clockwork Recovery, which is part of a full Android build.

repo init -u git://github.com/CyanogenMod/android.git -b gingerbread

repo sync

make -j4 otatools

Now, use dump_image or dd to dump your recovery or boot image from a running phone and copy it to your computer somewhere.

dump_image boot boot.img

To build Android from source for a new device, you need to set up a board config and its makefiles. This is generally a long and tedious process. Luckily, if you are only building recovery, it is a lot easier. From the root of your Android source directory (assuming you've run envsetup.sh), run the following (substituting names appropriately):

build/tools/device/mkvendor.sh device_manufacturer_name device_name /your/path/to/the/boot.img

You will receive the confirmation "Done!" if everything worked. The mkvendor.sh script will also have created the following directory in your Android source tree:

manufacturer_name/device_name

Now, type the following:

lunch full_device_name-eng

This will set the build system up to build for your new device. Open up the directory in a file explorer or IDE. You should have the following files: AndroidBoard.mk, AndroidProducts.mk, BoardConfig.mk, device_.mk, kernel, system.prop, recovery.fstab, and vendorsetup.sh.

The two files you are interested in are recovery.fstab and kernel. The kernel in that directory is the stock one that was extracted from the boot.img that was provided earlier. For the most part, recovery.fstab will work on most devices that have mtd, emmc, or otherwise named partitions. But if not, recovery.fstab will need to be tweaked to support mounts and their mount points. For example, if your /sdcard mount is /dev/block/mmcblk1p1, you would need the following lines in your BoardConfig.mk:

/sdcard vfat /dev/block/mmcblk1p1

Once the recovery.fstab has been properly setup, you can build the recovery using:

make -j4 recoveryimage

Your recovery can then be found at $OUT/recovery.img. If you are in need of building a fakeflash recovery, you will need to run the following to create the update.zip that hot replaces the recovery:

make -j4 recoveryzip

Once this is done, build, and tested, notify me, "koush", on Github and I can build official releases and add ROM Manager support!

Tip: Run "make clobber" between builds if you change the BoardConfig.mk, or the change will not get picked up.

61 comments:

Anonymous said...

Awesome!

Can we get a guide on the rest of the steps for building a rom from source for new devices too?

Anonymous said...

cool, im using a recovery set up for jailbreaking my ps3, can i expect to see that in rom manager soon?

Anonymous said...

Sir.....please help me....i can't seem to contact you by any other means....!!!
I have an spice Mi300 android 2.1 phone....i flashed a wrong recovery through ROM manager....now my phone is not booting up in recovery mode.....it gets stuck on the spice logo....please help....!!!

Normally it is booting up....i can use my phone....but i cant boot it up in recovery mode...please make a support of your clockworkmod recovery for spice Mi300 so that i can reflash it....!!!

Please do this for us....actually after the company's 2.1 update....the processor speed got capped down from 600Mhz to 480Mhz ONLY....plz help...i have rooted my phone...!!!
My email--- frankfill2007@gmail.com

phazei said...

I tried googling, but couldn't find out how to determine if the phone has MTD support. I could only find wiki's for what they are. How can you tell?

phazei said...

Ahh, figured it out looking at the partition names.

I agree with Anon comment 1. I've looked all over and asked on a couple forums, but I can't find any guide on actually porting over a new device to CyanogenMOD or anything of the sort.

Anonymous said...

what mean MTD and DD?
is ron manger work with samsung i5800?

Shawe said...

This don't work:

build/tools/device/mkvendor.sh htc bravo boot.img

Say:

unpackbootimg not found. Is your android build environment set up and have the host tools been built?

"make -j4 otatools" don't compile all dependencies needed.

Anonymous said...

apparently the otatools target doesn't make unpackbootimg.
i managed to get it to work by doing `make -j4 out/host/linux-x86/bin/unpackbootimg`.

phazei said...

If you type:
cat /proc/mtd
And it lists a bunch of items that begin with mtd, then it's MTD and dump_image will work. Otherwise you need to use a utility called DD. There are general tutorials on using DD if you google it, fairly common

Anonymous said...

is the mtd is need??
$
cat /proc/mtd
/proc/mtd: No such file or directory

$
cat /proc/partitions
major minor #blocks name

139 0 513024 tfsr0/c
139 1 256 tfsr1
139 2 1280 tfsr2
139 3 512 tfsr3
139 4 8192 tfsr4
139 5 7680 tfsr5
139 6 225280 tfsr6
139 7 207360 tfsr7
139 8 38912 tfsr8
139 9 7168 tfsr9
139 10 16384 tfsr10
179 0 964608 mmcblk0
179 1 964543 mmcblk0p1
137 0 513024 bml0/c
137 1 256 bml1
137 2 1280 bml2
137 3 512 bml3
137 4 8192 bml4
137 5 7680 bml5
137 6 225280 bml6
137 7 207360 bml7
137 8 38912 bml8
137 9 7168 bml9
137 10 16384 bml10
138 4 4352 stl4
138 6 217600 stl6
138 7 200192 stl7
138 8 34816 stl8

Unknown said...
This comment has been removed by the author.
Unknown said...

I was able to successfully dump partitions on my GT-I5800 (Galaxy 3) with dd:
dd if=/dev/block/bml1 of=/sdcard/dump/bml1.img

As far as I know:
bml1 - Primitive Boot Loader
bml2 - Secondary Boot Loader

I don't know which to use for compile (boot.img)

runt said...
This comment has been removed by the author.
runt said...

Anyone else having issues with "lunch generic_device_name-eng"

hucqim80 said...

Thanks Koush..I've finally port it to Viewpad 7 @ Commtiva Link N700 @ Spice Mi700..Time to port CyanogenMod..

runt said...

How do we commit our new recovery into github?

Anonymous said...

Anyone interested in helping create recovery for the Samsung Galaxy Tablet please join us at irc.freenode.net #ModADroid-Galaxy-Tablet.

Currently having issues with some steps in this guide.

Anonymous said...

Please port Motorola FLIPOUT!!

Anonymous said...

Hi,
does this work in motorola defy?
Does someone try it?Or could?
Thanks

Unknown said...

I get the following error after running the command 'make -j4 recoveryimage'

build/core/base_rules.mk:455: warning: overriding commands for target `out/target/product/generic/recovery/root/sbin/tune2fs'
bootable/recovery/Android.mk:97: warning: ignoring old commands for target `out/target/product/generic/recovery/root/sbin/tune2fs'
make: Nothing to be done for `recoveryimage'.

All previous steps completed succesfully

Any Ideas?

Unknown said...

I followed your steps for the Huawei Ascend from Cricket. I get a recovery.img but it won't load in recovery mode. I have looked at all the setting that I can and they seems to be correct. Are there any other Board config I con ferret out to figure why it isn't loading. Can I send you the config file and any output from the ascend you need to see to help me figure it out.

Anonymous said...

N00b here. Please do roll out support for the Micromax A60. Much appreciated.

TIA :)

Unknown said...

Does ROM Manager support Galaxy 3 I5800?

dreamss said...

Done!
Use the following command to set up your build environment:
lunch full_Flipside-eng
[dreamss@devserver2 droid]$ lunch full_Flipside-eng
[01:28] build/core/product_config.mk:203: *** No matches for product "full_Flipside". Stop.


also my recovery.fstab is empty

dreamss said...

build/tools/device/mkvendor.sh
export SEDCMD=s#__CMDLINE__#$CMDLINE#g

tknv said...

Hi,Is it correct in build/tools/device/mkrecoveryzip.sh ?
java -jar $ANDROID_ROOT/out/host/linux-x86/framework/signapk.jar -w $ANDROID_ROOT/build/target/product/security/testkey.x509.pem $ANDROID_ROOT/build/target/product/security/testkey.pk8 $UTILITIES_DIR/unsigned.zip $UTILITIES_DIR/update.zip

echo Recovery FakeFlash is now available at $OUT/recovery/update.zip
----
I think FakeFlash in $UTILITIES_DIR/update.zip.
Anyway thank you very much.

tknv said...

Hi Koushik,
I testing recovery.img for IS06-PANTECH sirius:detail:http://ow.ly/3TR8X.
Now recovery show like that views, Please advice me if you have time for it.
1st view show double menu.
img:https://picasaweb.google.com/lh/photo/6Cw-kDcfiFzQIq7eEbZiq9lq6EyGd1IafnVEJL8HskY?feat=directlink
2nd view:when push volume down key,show more clockworks menu.
img:https://picasaweb.google.com/lh/photo/Ac74LYD2qKA3mx6GEQsmCdlq6EyGd1IafnVEJL8HskY?feat=directlink
3rd view:push volume down key again.
img:https://picasaweb.google.com/lh/photo/P5P6wJpRxf9u3eEbLqDJW9lq6EyGd1IafnVEJL8HskY?feat=directlink
So when push volume down key,upper double menus line goes down. and push again it,lower double menus line goes down. and push again it,upper...
Sorry my bad english and explains. I hope you read it.
Thanks.

Unknown said...

I got to where it said to lunch full_etc...

But when I do lunch full_Streak7-eng it says "No such file: full_Streak7-eng."

It made all the files and kernel in /device/Dell/Streak7/

Not sure what I am doing wrong.

tknv said...

to @Unknown
did you try . build/envsetup.sh before lunch ?

nicandris said...

stuck on $ lunch full_passion-eng No such file: full_passion-eng. Clues?

nledevil said...

I guess I am the unknown person a few posts back with the Dell Streak 7. I did do envsetup.sh without error, it still didn't build the lunch file. I am syncing the repo and trying again from the beginning to see if I will have any luck.

Oliver K said...

Please give and idea of the problems that could happen. Some difficulties of porting to a new device and what can be done to test it in a secure way.

I'm trying to port it to the Moto XT300/Spice.

Oliver K said...

I managed to overcome the lunch problem by running:

$. build/envsetup.sh && lunch full_device-name-eng

Hope it works for you...

Oliver K said...

Hmmm, I managed to compile the recovery.img based on a moto xt300/spice boot.img.

How safe is it to dump it /system/ and hope for it to flash automatically or flash it with flash_image ?

And, IF(big if) I manage to put it in recovery, and it boots fine in recovery mode... how do I test it safely? I mean, If I flash a rom and it doesnt work, my main OS may be gone and I have a problematic recovery partition... great, aint it?

Thanks for any help

Oliver K said...

Another question:
I've noted that the checkout of the repo repository is gingerbread.

If my android is eclair, does the recovery.img still work?(build/tools/device/mkvendor.sh on the said eclair boot.img)

Oliver K said...

I managed to compile and test the recovery image.

Got to fastboot v0.5 and listed all partitions but said "CANNOT READ BOOT HEADER".

Any suggestions? Thanks

Oliver K said...

Well, after trying some things and NOTHING changing I came to a conclusion.

The blue error message from fastboot says:
USB FastBoot: V0.5
Machine ID: 1007002 v0
Build Date: Oct 26 2010, 17:31:11

MSM Id: 21
MSM Version: 2.0
Modem Build Id:76XXM-22220MSNCJOLYM
Serial Number: UNKNOWN

ptn 0 name='boot' start=297 len=56
ptn 1 name='system' start=353 len=1440
ptn 2 name='userdata' start=1793 len=1781
ptn 3 name='cdrom' start=3574 len=81
ptn 4 name='misc' start=3655 len=3
ptn 5 name='recovery' start=3658 len=44
ptn 6 name='cache' start=3702 len=320
ptn 7 name='fota_bbuf' start=4402 len=3
ptn 8 name='fota_usd' start=4025 len=3
ptn 9 name='fota_bua' start=4028 len=5
ptn 10 name='fota_ua' start=4033 len=5
ptn 11 name='fota_up' start=4038 len=48
ptn 12 name='kpanic' start=4086 len=3
CANNOT READ BOOT IMAGE HEADER

The build date is VERY similar to the one in the /system/build.prop:
Tue Oct 26 17:59:42 BRST 2010

It appears that the bootloader in my xt300/spice is locked... OR the recovery.img is not compiling right and the bootloader can't read it(very unlikely)

Can anyone confirm this is a locked bootloader symptom and/or provide me with info to overcome this problem?

Thanks.

Matt said...

i would love a port to the archos gen 8 tablets... but i dont think that i can use this guide, as i am pretty sure that it uses initramfs.

Unknown said...

Will there be a custom recovery deployed soon for the lg optimus s? my phone is rooted and I have rom manager installed(Premium Version):)as well as fastboot and android sdk on my computer and my phone model is not on the list. Will I be able to look forward to compatibility with my phone soon? If not, would I be able to substitute one of the custom recoveries already on the list and use it with my optimus s?

Thanks

-Nick (njspak@gmail.com)

Pablo Esvertit said...

Thank you for the guide.

I'm in the final step and I have an error when I try to make the recovery .img for a Haipad M701 (android tablet)

after:

make -j4 recoveryimage

I have this error:
out/target/product/M701/boot.img total size is 5271552
error: out/target/product/M701/boot.img too large (5271552 > [3784704 - 270336])
make: *** [out/target/product/M701/boot.img] Error 1
make: *** Se borra el archivo «out/target/product/M701/boot.img»
make: *** Se espera a que terminen otras tareas....
build error!

Any help will be apreciated.

goodoane said...

I can build the recovery but I do have some problems.
I cant make the adb working and mount usb sdcard on android 2.2.2 any suggestion?..
Tablet Huawei Ideos S7.

Anonymous said...

I was wondering if you've worked on a Kyocera Echo yet or if you have that in the works. I have one and I don't feel like building my own ROM, so I might be able to work with you on loaning you my phone for a bit. Contact me if you're interested.

Anonymous said...

dump_image link not working anymore, anyone have the file for me?

Erez A. Korn said...

Trying to port the recovery for an LG Optimus phone. However, it seems to be a non-MTD phone, and I can't locate the boot.img
Any idea?

Tim said...

Hello Koush. Props for everything you have done for the android community. I have used your recoveries on several devices and they all work flawlessly. My question: There is already a CW recovery for the Samsung galaxy s. Do you know if this will be compatible with the galaxy s 4g? Thanks in advance.

Tim, aka 1madfitter

Anonymous said...

Hi
What can i do, if framebuffer on my device don't support pageflipping?
Now i'm getting 4 screens in recovery (Samusng Galaxy Ace - 5830)

Unknown said...

My device, the Synrgic Dreambook W7.

After the process I don't have the kernel in the device dir.

How do I get the kernel?

Jamin13 said...

Is there anyway you could update your dump_image link. The current link is dead and seems to be halting lots of progress for many people.

Feel free to reply if you are still watching over this page and actually taking notice of others in need of your help.

Oliver K said...

@Jamin13

dd is also mentioned, use that.
Or there is nandroid.

Euclid's Brother said...

when running "make -j4 otatools" i get the following error.

build/core/base_rules.mk:162: *** device/samsung/cl-common/libstagefrighthw: MODULE.TARGET.SHARED_LIBRARIES.libstagefrighthw already devined by device/samsung/aries-common/libstagefrighthw. Stop.

Any ideas on how to fix?

Jamin13 said...

When running mkvendor.sh, I get "unpackbootimg not found. Is your android build environment set up and have the host tools been built?"
I ran make -j4 out/host/linux-x86/bin/unpackbootimg bu I'm still getting that message.
Anyone know how to fix this?

Unknown said...

Jamin13,

in CM source root run 'source build/envsetup.sh' and then it will work. Also type 'help' after that.

Anonymous said...

dude you only live 15 minutes away! I am up in Northgate...

contact me @ shhdhs@gmail.com
write subject "clockwork mod"

madmalkav said...

I will love a version for initramfs based systems.

Jamin13 said...

I still cannot get it past "unpackbootimg not found." When I do "make -j4 otatools" is says that unpackbootimg installs and it is in the out/host/linux-x86/bin folder but after running it continues to say

"build/tools/device/mkvendor.sh kyocera echo /jamin/boot.img
unpackbootimg not found. Is your android build environment set up and have the host tools been built?"

Any help with this?

Jamin13 said...

Alrighty, now that I've finally gotten the recovery.img compiled I tried to test it. Blank screen showed up when booting into recovery.

Is there is any way to fix this?

Unknown said...

Jamin13,

What I did is instead of flashing the .img file I copied over all the files from something like out/target//recovery/root/ to the device's current recovery partition. That gave me a working recovery using the stock kernel.

Jamin13 said...

Shahar Or,

Did you do that by just pushing them by adb?

Anonymous said...

hello koush

would you mind porting a version of your excellent recovery to the Samsung Gravity Smart SGH-T589?

its running froyo 2.2.2 from tmobile

Unknown said...

Anonymous,

You'd have better luck catching koush on twitter.

himraj13 said...

Hi Koushik,
I saw at github.com that playfulgod has given you recovery port for MicroMax A70.

can you please let me have it, as i need to upgrade my phone to cyanogenmode 7.

my email is himraj13@gmail.com

I would really appreciate your help.