Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
[] AL []
Old
(Last edited by [] AL []; 19th October 2012 at 12:36 AM.) Reason: Explained on top of the OP
#1  
[] AL []'s Avatar
Recognized Contributor - OP
Thanks Meter 483
Posts: 983
Join Date: Feb 2011
Default [GUIDE] How To make a CWM recovery flashable zip (patch) - the easy way

* * * * * * * * * * * * * * * * * * * * * * *
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
Attached Files
File Type: zip empty_Patch.zip - [Click for QR Code] (159.7 KB, 1519 views)
File Type: zip UPDATED-empty_Patch.zip - [Click for QR Code] (159.7 KB, 249 views)
File Type: zip UPDATED-CM7-empty_Patch.zip - [Click for QR Code] (125.7 KB, 133 views)
The Following 42 Users Say Thank You to [] AL [] For This Useful Post: [ Click to Expand ]
 
Kayant
Old
#2  
Kayant's Avatar
Recognized Contributor
Thanks Meter 2046
Posts: 1,292
Join Date: Jul 2011
Location: London
Thanks for this i usually use autoapktool the easy way but the manual way is more fun
 
ktmbikerman
Old
(Last edited by ktmbikerman; 13th March 2012 at 07:53 PM.)
#3  
ktmbikerman's Avatar
Senior Member
Thanks Meter 421
Posts: 1,383
Join Date: May 2011
Location: 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
 
nepotu
Old
#4  
Senior Member
Thanks Meter 86
Posts: 313
Join Date: Mar 2011
Location: Bucharest
I'm still building the update.zip files using the classical/manual method described by [] AL [], however this is not for everyone. For rookies there is an easier way to do it (check this out).
The Following User Says Thank You to nepotu For This Useful Post: [ Click to Expand ]
 
[] AL []
Old
#5  
[] AL []'s Avatar
Recognized Contributor - OP
Thanks Meter 483
Posts: 983
Join Date: Feb 2011
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
The Following User Says Thank You to [] AL [] For This Useful Post: [ Click to Expand ]
 
ktmbikerman
Old
#6  
ktmbikerman's Avatar
Senior Member
Thanks Meter 421
Posts: 1,383
Join Date: May 2011
Location: Cape Town
Quote:
Originally Posted by [] AL [] View Post

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.
The Following User Says Thank You to ktmbikerman For This Useful Post: [ Click to Expand ]
 
pavelcheto
Old
#7  
Junior Member
Thanks Meter 1
Posts: 24
Join Date: Apr 2011
Default Signign zip

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

[spoiler]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.
[/spoiler]

I do not understand what's wrong? Is there another way to sign the zip?
 
neo.ank
Old
#8  
neo.ank's Avatar
Senior Member
Thanks Meter 148
Posts: 514
Join Date: Apr 2011
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
 
[] AL []
Old
#9  
[] AL []'s Avatar
Recognized Contributor - OP
Thanks Meter 483
Posts: 983
Join Date: Feb 2011
Quote:
Originally Posted by pavelcheto View Post
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...)

Quote:
Originally Posted by neo.ank View Post
Thanks [] AL []…
I really like the detailed manual guides, they really help you understand things clearly..
Thanks.
I'm glad you like them.
 
mycorrado
Old
(Last edited by mycorrado; 8th June 2012 at 05:56 AM.)
#10  
Junior Member
Thanks Meter 1
Posts: 4
Join Date: Jun 2012
Default 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

The Following User Says Thank You to mycorrado For This Useful Post: [ Click to Expand ]
 
Post Reply+
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...