Samsung Galaxy S/SGH-T959V/Create CWM Package
This tutorial will give you the knowledge necessary for you to be able to create your own CWM-flashable packages for use on your Samsung Galaxy S 4G. This knowledge is useful if you want to have the ability to modify your phone at your own will. For example, I've created a package called sysapps.zip that I flash every time I change my ROM. It contains my preferred Boot Animation, as well as installs various apps as system apps to prevent Android from shutting them down in certain situations, this prevents those annoying launcher redraws. Recently I added the Camera mod and scrolling tweak created by dsexton702 in this thread.
Things You'll Need
First you'll need to know what software you'll need in order to be able to use CWM packages.
- ClockworkMod Recovery
- This seems obvious, but in order to use CWM packages, your phone will need to be rooted and have CWM installed. The easiest way to go about this is to simply install a custom kernel that has CWM built in. There are kernels available for both Gingerbread (2.3.x) and Froyo (2.2.x). If you are unfamiliar with flashing a custom kernel then check out this page.
- 7-Zip or WinRAR
- Text Editor Capable of Using Unix-style Line Endings
- Note: This generally only implies if you're using Windows, this should not be an issue on Linux regardless of which text editor you choose.
- CWM is extremely picky about what line endings are used when creating the updater-script. You must ensure that your text editor supports Unix-style line endings, otherwise CWM will throw an error when attempting to flash that package. You can read more about line endings here. Both options listed below are 100% free!
- Notepad++ (Recommended)
- This is the text editor that I both use and prefer, its really simple to have it use Unix-style line endings, as well as convert Windows-style files as well.
- Gedit for Windows
- Notepad++ (Recommended)
- OPTIONAL Skeleton Package
- This is simply a "skeleton" zip file I created to give you a basic idea of how a CWM package should look in terms of its layout. This particular example can be used to change your boot animation. While not required, I do recommend it if you're just getting started with creating CWM packages.
CWM Package Layout
Lets have a look at the basic layout of a CWM flashable package so you can get an idea of how it should look for it to flash correctly. We will be using the skeleton package linked above for our example.
Directories are in green, files are in blue.
Now let's break down what each part is.
- The only required part of a CWM package is the META-INF folder. This folder contains the update-binary and updater-script files, which tell CWM what to do with this package.
- META-INF/com/google/android/update-binary is a compiled file that carries out the operations in updater-script. Do not try to edit this file, it is compiled.
- META-INF/com/google/android/updater-script is an Edify script which tells CWM what to do with the stuff in the zip file. Below you can see an example updater-script from this skeleton package.
- The zip file can then contain any other files/folders to be flashed/moved onto the phone. In this example there's a file named /system/media/bootanimation.zip, which is the custom boot animation we would like to flash. Later in this tutorial I will list some common locations where various files go.
ui_print("######################################"); ui_print("# INITIATING UPDATE "); ui_print("# System Apps + Tweaks"); ui_print("# Created by crackpot "); ui_print("######################################"); ui_print("Mounting System..."); run_program("/sbin/mount", "/dev/block/stl9", "/system"); ui_print("Removing old boot animation..."); delete("/system/media/bootanimation.zip"); show_progress(0.100000, 60); package_extract_dir("system", "/system"); ui_print("Changing permissions on new boot animation..."); set_perm(0, 0, 0777, "/system/media/bootanimation.zip"); show_progress(1.000000, 0); ui_print("Done!");
Let's take it line by line.
- ui_print(string); simply prints out text to the screen to let the user know what's going on, or any errors.
- run_program(program, [arg1], [arg2], ...); does what it says, it runs a program.
- In this case the program /sbin/mount is ran with the arguments /dev/block/stl9 and /system.
- This line mounts the system partition of our SGS4g, which is located at /dev/block/stl9.
- In order to "use" a partition, it must first be mounted. More information here.
- delete(file1, [file2], ...); does what it says, it deletes a file(s).
- From what I've been told there's a limitation in the current Gingerbread kernel we have where files cannot be overwritten, they must first be deleted. Hence why we delete the old boot animation first.
- show_progress(fraction, duration); displays a progress bar to give the user an idea on how long it will take.
- package_extract_dir(localdir, phonedir); extracts a directory from localdir and puts it in phonedir on the phone.
- In our example package_extract_dir("system", "/system"); copies the system directory in our zip file to the /system directory we mounted earlier.
- set_perm(user, usergroup, permission, file); sets the permissions on a file.
- Linux is insanely picky about permissions being set properly, for security sake.
- I'm not 100% sure if I have the syntax laid out properly for this function, so I made need to make corrections.
MORE COMING SOON!