[GUIDE] How To make a CWM recovery flashable zip (patch) - the easy way

[] AL []

Recognized Contributor
Feb 22, 2011
2,865
4,625
0
* * * * * * * * * * * * * * * * * * * * * * *
Important update (Oct 19, 2012):

Two important things to add here:

1-) it seems that my updater-script mounting script was wrong and it is surprising that it worked for me all that time.
--> mount() expects 4 args, had 3.

So this should be changed --> from: mount("MTD", "system", "/system") to:
mount("ext3", "EMMC", "/dev/block/mmcblk1p21", "/system");

So I attached an UPDATED empty patch for that.

If your phone uses another ext or dev/block #, you can also try this mounting script:
run_program("/sbin/busybox", "mount", "/system");

2-) Somewhere in September 2012, CM7 team added support for TLS (will add commit details later if I find it), without explaining what it is, this brought changes in the update-binary file and if it is the rom you're using, you might need to use a recent update-binary within your patch. So I also attached an updated empty patch for CM7 recent builds.

That's it! have fun with cwm recovery patches.
Cheers,
/AL

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*


I've been asked about this a few times, so finally here it is: a simple guide on how to make a flashable zip - usable on CWM recovery version 3 and higher (Edify script).


Disclaimer:

Before you go on and follow my directives, I remind you that from here on, you step into the "make this at your own risks and perils" land. I don't pretend to be a guru on this and I might even be wrong on something here; so make a nandroid backup of your current system and apps and copy of any important system file or data you do not want to lose.

Please also understand that there are many different files of various functions on your phone and that the method I've chosen to share below might not apply to all files or situations; this is a basic quick guide for a basic system file replacement.


Ok, now that the things are set straight, let's do this!
Here's what you'll need:

[] a file (or more) that you want to replace or add on your phone;
[] an existing patch.zip file to use as a base - I've attached one below;
[] a good archive manager - I recommend 7-Zip;
[] a good text editor software for your computer - I recommend Notepad++ ;
[] a signing tool - I use apkmanager from here on xda
-> Download it and extract the files into a folder [c:\apkmanager for example]
--> perequisite: java libs installed on your computer.
[] a couple fingers with a normally developped brain attached to them.


All set up?, now let's do this!

- Place the patch.zip on your desktop and rename it to something more indicative of what it will be used for;

- Right-click on it and choose: "7-Zip / Open archive" [*DO NOT extract; just *Open archive*];

Now you should see two folders: one called "system" and one called "META-INF".


I - FILES AND FOLDERS:


Let's start with the "system" one, so double-click on it:

In there, will go all files that what you want to add or replace to the system. So let's say for example that you want to replace the camera and one of its related library. To do so, we first have to create the directory arborescence and create sub-directories in the /system/ folder by following this easy method:

- On your desktop, right-click on an empty spot and select "New / Folder" then edit the name to "app" (no " ") using no CAPS or space at the end;
- repeat the process to make another folder called "lib";
- drag those two new empty folders into the /system/ folder of the 7-zip opened archive [just click yes on the popup dialogs];
- now simply drop the two files in their respective place: the Camera.apk file should go in '/system/app' folder and the library file into '/system/lib' folder.

.. If you have more files to add, just follow the logic above; I'm sure you get the idea by now..


II - UDATER-SCRIPT


The other folder included in the opened archive is named "META-INF" and all the file in it should be left unchanged except for one file: "updater-script" located in the "\META-INF\com\google\android\" folder.

- So navigate to it and drag the file to your desktop and open it with Notepad++ (you can use another text editor but I would not recommend the Windows' default Notepad for that).

That file is just a text file in which all the update instructions/commands are set.

The demo patch.zip that I've attached includes a very standard and basic script which does the bear minimum: it only mounts the system, then adds / overwrites the system files and then unmount the system. That is probably what most endusers need for the vast majority of cases. No need to worry about setting files permissions; your rom/bootmenu should set that for the whole system on boot. But there are tons of other uses and commands we can use in there; things like deleting files or entire folders, setting ownership and permissions, etc., etc. If you're interested in reading more or want to go a little more 'hard-core' on this, you can go read here and here.

So, what to change in the updater-script anyway?

Well, for this example, not much! You can edit the text on the lines starting with "ui_print": those will be displayed on the CWM screen during the update process. A good coding ethic would be to include a patch description and to add in any useful comments like if the patch is for a specific build only, say hello to your mom... or whatever!

2 important notes here though in order to avoid problems:

* Each line of the updater-script MUST end with a ";" (no " ") ;

* There HAS TO BE at least one blank line after the last ( ; ) line of code.

Done with updater-script? -> Save the file and drop it over the old one in the opened archive and close it.

Almost done here... one last step:


III- SIGNING THE PATCH


This is simply done by:

- placing the patch in the apkmanger folder called "place-apk-here-for-signing"
[which should be in C:\~your location~\apkmanager\];

- executing the script (double-click on Script.bat file inside the apkmanager folder) and then selecting option 16* (*this option # might have change in latest version tbd)

Edit: as ktmbikerman has kindly confirmed, the latest version of apkmanager is now called APK multitool and that (signing) option is now # 19;

- Then (type 24?) exit, grab the now signed patch from the same folder and move it to safe place and on the phone's sdcard.

Congratulations you've done your first CWM patch !!!


One last warning:

Sometimes you don't know what a new system file or apk will do to your system. Applying a new patch can be risky and might even prevent your phone from booting up altogether; it happened to me before.. But luckily, I was kind of expecting it and I had been clever enough to first make myself a second patch with the original files and place it along with the other patch on the sdcard before testing the patch. So the no-boot was no big deal afterall because I've then just re-accessed CWM recovery and installed my undo/revert patch.

So all this to say, that it's better be safe than sorry and you can do this by
preparing a fallback patch sometimes..

That's it on this for today; hope it is of any help to some of you guys.
This is a first draft version and I will add more to it soon.

Comment/suggestions are always welcomed, but PLEASE do not full-quote this (or any) long post.

Cheers.

/A
 

Attachments

Last edited:

ktmbikerman

Senior Member
May 7, 2011
1,990
656
0
51
Cape Town
Thanks so much for this tutorial Al, I really appreciate the effort. I'll give some feedback once I've flashed my first patch.

Edit: worked perfectly... I can now flash my country's baseband on any rom :)
 
Last edited:
  • Like
Reactions: [] AL []

[] AL []

Recognized Contributor
Feb 22, 2011
2,865
4,625
0
Thanks for the feedback guys. I'm glad that you like the guide.

I will check out autoapktool and the "D4 Update Zip Maker" eventually...
[Although I had a quick peak at the zip maker and found it more confusing than anything...but that might be just me; need more coffee at this time...]

My guide is very long and maybe too detailed for the job needed really; but I find the manual way is really quick to do once you have everything set up.

OK, one thing I'd like to ask:

Any of you have used the latest version of apk manager that I've linked to?

If so, could you confirm/tell me what option number is the signing apk option?

The version I've beeen using is very old and that (option 16) might be different now... and I'd like to correct the OP if needed. I'm just too lazy to download and try the new soft at this time.. 1 Thank for 1st the answer on this ;)
 
  • Like
Reactions: hackergnome

ktmbikerman

Senior Member
May 7, 2011
1,990
656
0
51
Cape Town
OK, one thing I'd like to ask:

Any of you have used the latest version of apk manager that I've linked to?

If so, could you confirm/tell me what option number is the signing apk option?

The version I've beeen using is very old and that (option 16) might be different now... and I'd like to correct the OP if needed. I'm just too lazy to download and try the new soft at this time.. 1 Thank for 1st the answer on this ;)
Hey AL, I used the same apk manager as you, but the in new APK multitool it is option 19 - Sign an apk.
 
  • Like
Reactions: [] AL []

pavelcheto

Senior Member
Apr 15, 2011
138
8
0
Signign zip

I'm having trouble signing the zip. This is the log from APK multi tool:

A subdirectory or file projects already exists.
A subdirectory or file place-apk-here-for-modding already exists.
A subdirectory or file place-ogg-here already exists.
A subdirectory or file place-apk-here-to-batch-optimize already exists.
A subdirectory or file place-apk-here-for-signing already exists.
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)
'""platform-tools"\adb.exe"' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the path specified.
Error: Unable to access jarfile signapk.jar
Could Not Find C:\Program Files\place-apk-here-for-signing\../place-apk-here-for-signing/empty_Patch.zip
The system cannot find the file specified.

I do not understand what's wrong? Is there another way to sign the zip?
 

neo.ank

Senior Member
Apr 28, 2011
1,329
636
0
Thanks [] AL []…
I really like the detailed manual guides, they really help you understand things clearly..:)

Doesn't matter from where I send it, what matters is written above
 
  • Like
Reactions: [] AL []

[] AL []

Recognized Contributor
Feb 22, 2011
2,865
4,625
0
I'm having trouble signing the zip. This is the log from APK multi tool: ...

I do not understand what's wrong? Is there another way to sign the zip?
Well, I'm no expert of the APK multitool and as mentioned before, I'm even using an old outdated one w different options... But look around on xda and on the Play store, there are numerous apk signing tools around and it should be a fairly simple process (I might look further into it for you later once I get access to my desktop...)

Thanks [] AL []…
I really like the detailed manual guides, they really help you understand things clearly..:)
Thanks.
I'm glad you like them.
 

mycorrado

Member
Jun 5, 2012
12
1
23
recovery.zip

Hi,

I used the steps you outlined to build myself a CWM 5.0.2.7 'recovery.zip' to switch back from touch on my T989..

what I did was to use recovery instead of system so there is a recovery folder and inside it, recovery.img:


ui_print("CWM recovery 5.0.2.7 Flasher");
ui_print("----------------------------");
mount("MTD", "recovery", "/recovery");
show_progress(0.100000, 40);
ui_print(" Unpacking ");
show_progress(0.100000, 40);
package_extract_dir("recovery", "/recovery");
ui_print(" Replacing Files ");
unmount("/recovery");
show_progress(1.000000, 10);
ui_print(" Done !! ");


my updater-script seemed to work fine but my phone is still at 5.8.1.3 touch..


Any suggestions as to what I did wrong?

Oh, and many many thanks for the well written tutorial :)
 
Last edited:
  • Like
Reactions: [] AL []

[] AL []

Recognized Contributor
Feb 22, 2011
2,865
4,625
0
Hi,

I used the steps you outlined to build myself a CWM 5.0.2.7 'recovery.zip' to switch back from touch on my T989..

what I did was to use recovery instead of system so there is a recovery folder and inside it, recovery.img:
Code:
[I]ui_print("CWM recovery 5.0.2.7 Flasher");
ui_print("----------------------------");
mount("MTD", "recovery", "/recovery");
show_progress(0.100000, 40);
ui_print(" Unpacking ");
show_progress(0.100000, 40);
package_extract_dir("recovery", "/recovery");
ui_print(" Replacing Files ");
unmount("/recovery");
show_progress(1.000000, 10);
ui_print(" Done !! ");
[/I]​
my updater-script seemed to work fine but my phone is still at 5.8.1.3 touch..

Any suggestions as to what I did wrong?

Oh, and many many thanks for the well written tutorial :)
You're welcomed and thanks to you.

As for your question, well, I'm no real 'zip patch guru' here and I'd have to dig and learn quite a lot more on this before writing up or suggesting a script to you.

But, I think that recovery is a 'big piece' to replace on the system and really, this would fall outside the scope of this tuttorial. Remember that I mentioned 'for simple apk/file replacement'...

Furthermore, your script might need to delete the files you want to replace first, then replace them and then set their permission/owner ...and what not!?! [again I'm just speculating here and don't take my words for granted - I might be completly off...] All that might actually be done more easilly with the help of a (or some) [sub-] script...

Finally, I'd suggest you to download [if you haven't already] the touch recovery ( v2.2.1) from Team Win and to have a look at its updater-script and the scripts it uses. It's a good occasion to learn anyway... I also imagine that it is very close to what you want to achieve and you might just need to replace your recovery file(s) and re-sign the zip before flashing....

Like always; do a nand backup before flashing anything serious like this...;)
Good luck and tell us how this turns out for you.

Cheers,

/A
 

[] AL []

Recognized Contributor
Feb 22, 2011
2,865
4,625
0
Hey.. Can you convert my updater-script to Edify's updater-script ? :)
I tried but something is wrong.. Please can you make it for me ?
Here is the zip file of that script..
http://dl.dropbox.com/u/51440399/update-script.zip

Thanks for this guide anyway.. :)
Your Amend script was very simple:
Code:
show_progress 0.1 0
copy_dir PACKAGE:system SYSTEM:
set_perm_recursive 0 0 0755 0644 SYSTEM:framework
set_perm_recursive 0 0 0755 0644 SYSTEM:app
show_progress 0.1 10
From the OP, 2 links: "If you're interested in reading more or want to go a little more 'hard-core' on this, you can go read here and here."
--> First of them @ § Section "Copy To System & Data:-" (exactly like yours):
Code:
copy_dir PACKAGE:system SYSTEM:
becomes these two lines:
mount("MTD", "system", "/system");
package_extract_dir("system", "/system");
--> @ § Section "Folder Permission:-":
Code:
set_perm_recursive 1000 1000 0771 0644 DATA:app 
becomes:
set_perm_recursive(1000, 1000, 0771, 0644, "/data/app");
So your next 2 lines become:
Code:
set_perm_recursive(0, 0, 0755, 0644, "/system/framework");
set_perm_recursive(0, 0, 0755, 0644, "/system/app");
--> "Progress bar":
Code:
Edify:     
show_progress(fraction, duration);
Amend:
show_progress fraction, duration
So your old script is mainly doing the same thing as I've explained in the OP: it replaced files from a package onto the system folder. It was also setting permissions/ownership for 2 system folders [but those are the default values for those folders anyway and this might not be needed afterall...]

So basically, you can use the example zip from the OP and its' script untouched; I believe that it should work "as is". Just make sure that you follow the rest of the OP and organize your "package" [files inside] properly and then sign the zip. If it still doesn't work, please refer to these comments below.

Cheers and good luck.

General comments 'to all' re this:

Different phones and roms use different mounting partitions, block sizes, SD-EXT1/2/3/4,...; that means that there will be cases where certain specific scripts will be required. No one can give that to you if you do not give the basic details/info about what you run on.. Again, also please read the two links given above and do your part of the work in order to find out your system's specifics and learn the very basic 1 or 2 scripts.

Check different zip patches that worked for you before and study their scripts and then go experiment... But as always, backup first.

/A
 
Last edited:

chinmay_7d

Senior Member
Oct 20, 2011
444
701
0
DC
i followed your tutorial. well written:good:

but i have a problem here.. everytime i put the patch zip in the "place-apk-here-for-signing" folder and do the signing using apk multi tools using option *17( new version), the script window closes suddenly and the zip file disappears from that folder.

Whats wrong???

Error Log found:
Code:
|07-Jul-12 --  2:40:18.72| 
-------------------------------------------------------------------------- 
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)
'platform-tools\adb' is not recognized as an internal or external command,
operable program or batch file.
Could Not Find E:\Program Files (x86)\apkmultitool\place-apk-here-for-signing\../place-apk-here-for-signing/signed.apk
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at java.util.Arrays.copyOf(Unknown Source)
	at java.io.ByteArrayOutputStream.grow(Unknown Source)
	at java.io.ByteArrayOutputStream.ensureCapacity(Unknown Source)
	at java.io.ByteArrayOutputStream.write(Unknown Source)
	at java.util.zip.DeflaterOutputStream.deflate(Unknown Source)
	at java.util.zip.ZipOutputStream.closeEntry(Unknown Source)
	at java.util.zip.ZipOutputStream.putNextEntry(Unknown Source)
	at java.util.jar.JarOutputStream.putNextEntry(Unknown Source)
	at com.android.signapk.SignApk.copyFiles(SignApk.java:401)
	at com.android.signapk.SignApk.main(SignApk.java:473)
The system cannot find the file specified.
Any help??
 

[] AL []

Recognized Contributor
Feb 22, 2011
2,865
4,625
0
i followed your tutorial. well written:good:

but i have a problem here.. everytime i put the patch zip in the "place-apk-here-for-signing" folder and do the signing using apk multi tools using option *17( new version), the script window closes suddenly and the zip file disappears from that folder.

Whats wrong???

Error Log....

Any help??
Hi and thanks,
as per your issue, strange apk that disappear..
Well I've said it before: I'm no expert at debugging apk multi-tool issues.. but what came to my mind is did you set your windows variables path for java?
Other than that, I see out of memory message...don't know if it's part of the issue or just part of the crash spitout... I suggest that you seek further help on the apkmultitool thread directly maybe.

Otherwise, try getting something like "zip signer 2" from the Market and try signing that way.

/A
 

[] AL []

Recognized Contributor
Feb 22, 2011
2,865
4,625
0
* * * * IMPORTANT UPDATE * * * *

Your old zips created following this guide might no longer work on recent (post-Sept 2012) cm7 builds.

PLEASE READ THE OP CAREFULLY AGAIN (and redo/update your patches).

Cheers
/AL