Monday, October 22, 2012

Creating a basic custom rom

A Dummies Look on Custom Roms
Topics covered are as below :
OK lets get started to learn about the basics

  • Stock Rom
  • Custom Rom
  • Rooting
  • ADB
  • Recovery

Creating a custom rom

  • Custom-rom-creator-studio
  • Android Kitchen
  • Modify/Extract an app
  • smali/baksmali to disassemble the dex files
  • Modifying framework-res.apk
  • UOT Kitchen

When we generally talk about ROM, it means Read Only Memory. However in the Android developer circle it means an actual custom image of the OS installed in the ROM area of your smartphone.

A stock ROM is the version of the phone's operating system that comes with your phone when you buy it.
custom ROM is a fully standalone version of the OS, including the kernel (which makes everything run), apps, services, etc - everything you need to operate the device, except it's customized by someone in some way.
These ROMS are specifically aimed at the consumer who want the advantages of rooting, but without completely changing the basic operating system that comes with the phone. Every phone comes with a stock ROM. It’s not bad, but if you took the time to root your phone then you are probably looking for some extra features.

Android rooting is the process of allowing users of smartphonestablets, and other devices running the Android mobile operating system to attainprivileged control (known as "root access") within Android's subsystem. Rooting is often performed with the goal of overcoming limitations thatcarriers and hardware manufacturers put on some devices, resulting in the ability to alter or replace system applications and settings, run specialized apps that require administrator-level permissions, or perform other operations that are otherwise inaccessible to a normal Android user. Rooting is analogous to jailbreaking devices running the Apple iOS operating system. On Android, rooting can also facilitate the complete removal and replacement of the device's operating system, usually with a more recent release of its current operating system.

ADB stands for Android Debug Bridge. It comes as a part of the standard Android SDK, which you can grab here. Basically, it provides a terminal-based interface for interacting with your phone’s file system. Since Android platform is based on Linux, command-line is the only way to obtain and manipulate root access often required to perform certain advanced operations on your device using root access.
While these things can be done directly on the device itself using some terminal emulator, it will be rather difficult to execute complex commands on such a small screen. ADB provides the bridge between your machine and your computer.
Installing ADB and drivers look here
Turning on ADB
Go to Menu > Settings > Applications > Development > USB Debugging
Learn basic ADB commands

adb push - sends a file to the phone over ADB thru USB - adb push c:\test.apk /sdcard/test.apk

adb pull - receives a file from the phone over ADB thru USB - adb pull /system/app/Test.apk c:\Test.apk

adb shell - starts a shell connection with the phone

adb reboot - restarts the phone

adb reboot recovery - restarts the phone into recovery

adb reboot bootloader - restarts the phone into the bootloader (white screen)

adb remount - remounts the file system

adb install <path to .apk file> - installs an application - adb install c:\swype.apk

adb uninstall <package name> - uninstalls an application - package name is usually in the format,

Learn basic Linux commands to run through ADB shell

cd - changes directories - works through stock android toolbox - cd /system/app

ls - lists all files in the directory - works through stock android toolbox - ls /system/app/

cat - copies files - works through stock android toolbox - cat /system/app/Test.apk > /sdcard/Test.apk

rm - removes files - works through stock android toolbox - rm /system/app/Test.apk

mv - moves files from one location to another - works through stock android toolbox - mv /system/app/Test.apk /sdcard/Test.apk

cp - copies files - functions similar to cat - uses busybox installed by the into recovery mode - cp /system/app/Test.apk /sdcard/Test.apk

mount - loads the file system (usually auto loaded except sometimes in recovery) - mount /dev/block/mtdblock4 /system

unmount - unloads the file system - umount /system

For more commands and description look here

What is recovery?  In Android, recovery refers to the dedicated, bootable partition that has the recovery console installed.  A combination of key presses (or instructions from a command line) will boot your phone to recovery, where you can find tools to help repair (recover) your installation as well as install official OS updates.  Because Android is open and has the recovery source code available, building a customized version with more and different options is relatively easy as well.  Let's look at both options.
The stock recovery is pretty limited, but that's by design.  Its main purpose is to delete all user data and files, or to perform system updates.  Normally, both these operations are started from the running Android system, or you can do things manually and boot right into recovery yourself.  When you tell your phone to do a factory reset, recovery is what boots up and erases the files and data.  Likewise with updates -- when we restart to install an official OS update, it's done in recovery.  Recovery is also where we go to manually install official OS updates we've downloaded from the Internet.  It's very useful, but limited.
Custom Android recoveries offer much more.  They have been coded to allow for backup and restore functions, selective deletion of data so you don't have to wipe everything, and modified to allow update packages that have not been digitally signed by official sources.  You also can mount various partitions so that you can copy files to the SD card without having to remove it or reboot into Android. Anytime you see someone mentioning Clockwork or Amon Ra, they're talking about custom recoveries.  Because of the extra functionality built in, they are a pretty important tool for folks who want to hack their Android phone or tablet.  Recoveries aren't as pretty as a custom ROM and don't get the same love from users and bloggers that custom builds of Android do, but in the end they're even more important. Without them none of this custom ROM stuff would be possible.
The most famous ClockWorkMod (CWM) recovery
ClockworkMod Recovery is a secondary recovery option for Android devices made by Koush. It is based off the eclair recovery image. Features include Nandroid backup, adb shell, advanced options (ignore asserts and signature checks), and file browser for choosing update.zips
It is also known as CWM, clockwork, CW recovery

Porting CWM recovery for MT65xx phones

Basic Clockwork Mod Recovery Menu

Reboot system now (Self explanatory )
Apply update from SDcard. (when you connect your device to your computer it will show up as tablet. The SDcard that cwm refers to is simply your device storage. Always make sure to copy install.zips to the root directory of your tablet storage.) You use this when applying an update for a specific ROM if that is what the ROM developer says.
Wipe Data/ Factory Reset You should always do this before you install a new ROM or if you are having minor issues with your device.
Wipe cache partition Think of this as the lite version of whats above . If you do above though it doesn't hurt to do this too.
Install zip from SDcard Use this to install new ROMs.
Back up and Restore
Mounts and Storage use this to connect your device to your computer when in recovery mode. It is also possible to transfer files to your device while in this mode.
Advanced What you are interested in here is something called dalvik cache, you want to wipe this too before installing any new ROM
Power off

Custom rom creator studio

A project/solution based development environment for creating customized android roms.

For Windows/.NET Framework 4.0 and Linux/Mono 2.10.2
The version for Mono might work on OSX/Mono.

It is using apktool and smali/baksmali to do the hard work.


Open files from command line and associate file types(.rssln, .rsproj and .apk)(windows only)
ApkViewer, shows content of apk files (windows only)
Compare content of apk and jar files with older versions.
Text editor
Automatically discovers boot class paths
Decompiling classes
Recompiling classes
Decoding resources
Encoding resources
Optimizing png files (windows only)
Signing apk files
Excluding/Including files

Android Kitchen is simple yet very powerful tool developed by dsixda, a developer from xda developers forum, made to help making and modifying Android ROMs.
Although dsixda stopped developing this tool some time ago, Android Kitchen is still one of rareAll In One tools with which you can do things you woud probably do with a lot of separate tools

Android Kitchen is a Linux Shell Script but it can be also launched on Windows by using Cygwin.
    • You can extract ROMs from following extentions: .zip, .img (nandroid backup) .app (huawei update format)
    • You can unpack and repack boot.img (for changing kernel…)
    • You can root stock ROM
    • Support for app2sd
    • Deodexing stock ROM
    You can find whole set of features on xda forum

    The android kitchen software to do the basic functions to my ROM like adding root access and such.

    The easiest way to do this is to build a Linux VM but the kitchen can also be run from windows using cygwin.

    Check this post here:

    It has a download for the kitchen software as well as detailed guides on how to use it.

    From clockworkmod perform a nandroid backup of your phone and then copy the system.img and boot.img files into the kitchens original_update folder and then create your working folder from that.

    (If you go through the guide on the kitchen thread you'll understand what I mean)
    After you have your working folder ready you can go through the various kitchen options to add root, superuser & busybox, deodex all your apps, etc, etc.
    You will then want to go through your /system/app folder and remove any apps you don't want and also move and add apps to /data/app for ones that you can run from the user partition (do not move the market out of /system/app).
    There are several guides around of what the system apps do and be carfeul what you remove as some are very important for functionality.

    Check this thread for some basic steps of the things you will want to do to start with.

    To modify/extract an app

    If you want to make some modifications of apps and functionality you will need to get a bit deeper into things.

    You can use tools like apkmanager to decompile the apk files so that you can edit them and recompile.
    To change the interfaces and such you will want to do this to files such as /system/framework/framework-res.apk and /system/app/SystemUI.apk.
    The interfaces are basically made up of a series or xml files that define where everything is and the images that are being displayed.

    There is also a website called UOT Kitchen that can be used to modifiy the interface for you.

    You just need to upload your framework-res.apk and SystemUI.apk and choose the look you like and it will alter them for you.
    I used it to modify the interfaces I used but unfortunately it doesn't work on our phones too well because the dual sim features use different images and relations and the kitchen can't modify them properly. They also don't look so good with the colored sim backgrounds our phones use so I had to modify the images and recreate the interfaces manually for most things but it should work pretty well for any other phone type.

    To go further into coding changes you will need to learn how to use smali/baksmali to disassemble the dex files that are stored in the apps.

    When you use baksmali to disassemble a file it will be a plain text representation of the dalvik code which is kind of a cross between assembly code and java.

    As an example of how to work with that see this guide of how to modify your boot menu options. Like adding recovery option when pressing the power button.

    Depending on what you want to do to your ROM depends on how much you want to delve and learn but luckily there is plenty of information out there since it is an open source platform.

    Porting Touch recovery for MT65xx phones

    Porting Touch recovery for MT65xx phones

    Credits to yuweng

    Extract the Android Kitchen plugins & copy MT65xx folder to dsixda's Android Kitchen tools
    Rename existing plugins folder at scripts to plugins ori. Copy plugins folder into it
    To access MT65xx-Plugin, go to ADVANCED OPTIONS -> Miscellaneous options / Plugin
    If you have a 3 button MT6577 then use menu option 1

    Android Kitchen Plugins for Porting Lewa TWRP to Any MT6575/ 77 (For cygwin)

    Copy your stock recovery.img to recovery.img_MT65xx folder then only press enter

    The plugins will automatically unpack your stock
    recovery.img & repack it with Lewa TWRP
    Also included is the latest Mobileuncle Tools. If
    you haven't install it then copy both to sdcard.
    First, install Mobileuncle Tools

    Thursday, October 18, 2012

    Porting CWM recovery for MT65xx phones

    Credits to yuweng

    bgcngm - unpack/ repack script 
    CLShortFuse - SuperOneClick Root & BusyBox
    DooMLoRD - Root & Busybox
    Koush Dutta - Developer of ClockworkMod recovery
    linerty - MT65xx ROM Backup

    For creating or porting custom rom we need CWM without it is not possible.

    So let us see the steps and process involved in porting ClockWorkMod recovery in MT65XX phones

    1. Rooting and busybox
    2. Backup of your current rom
    3. Installing cygwin and porting CWM recovery
    4. For something wrong goes for MT6573 phones

    Step 1.

    First we need to root the phone and make sure sure busybox is installed..

    There are many rooting steps

    1. Using the modified boot.img as shown in this tutorial (But make sure you the specific boot.img for your phone before flashing)

    2. Using MTKDroidTools to root the phone

    3. Or using Doomla script or similar script to root the phone (Most of the scripts are GENERIC means it will work on any android device of any brand).

    Step 2.

    So make sure you have rooted the mobile and busybox installed...

    Now important step is to backup the rom of the phone.

    There are many ways to do it.

    1. Using SP Flash tool

    and following these simple steps

    Start the flash-tool -> load the scatter-file -> click on 'Read back' -> click on 'Add' -> double click the new entry -> give a name for your backup -> enter start-address and length -> click OK -> click on readback button -> connect your phone.

    2. Using the MTKDroidTools and selecting the backup button

    3. Using the Gsctipt method credits to 

    Download link :

    Extract directly to your SdCard & install GscriptLite.apk

    Press Menu & Add script

    Step 3.

    Now Installing Cygwin for windows

    Cygwin Off-Line Installer

    These recoveries will work on ICS MT6575/MT6577 you may also try for GB for Not working recovery on MT6573 see below after this tutorial.

    Download link
    MT65xx Unpack/ Repack
    Download link
    Mobileuncle Tools
    Download link
    CWMR recovery.img-ramdisk
    Download link
    CWMR recovery.img-ramdisk
    Download link
    CWMR Touch Screen recovery.img-ramdisk
    Download link
    Optional – dsixda Android kitchen v0.199
    Download link

    Browse to wherever you have extracted cygwin & look for cygwin_packages

    Extract bm-mt65xx-unpack-repack.7z to c:\cygwin\bm

    Copy your recovery.img backup from
    Gscript or similar backup to c:\cygwin\bm

    Starting cygwin for the first time

    cd c:/cygwin/bm

    To unpack use command ./ recovery.img

    For linux users you can try this : 

    sudo perl ./ recovery.img

    below are the files  extracted out from recovery.img

    Delete the RED circle files

    Remaining only recovery.img-kernel.img

    Extract whichever CWMR version your prefer to c:\cygwin\bm

    For Linux users :
    sudo perl ./ -recovery ./recovery.img-kernel.img ./recovery.img-ramdisk ./recovery.img

    For Windows :

    Use command
    ./ -recovery ./recovery.img-kernel.img ./recovery.img-ramdisk ./recovery.img

    Turn on your phone USB Storage & copy newly created recovery.img to your SdCard

    Copy mobileuncle tools ( m44tools.apk ) to SdCard

    After phone reboot & you shall have your CWMR
    Special Note : CWMR, enter command is camera not the usual power button !

    Adb shell can be access via CWMR on all three version


    All three recovery.img-ramdisk doesn't work on my mt6573. What now ? No worries, you still
    have a last resort to port a complete working CWMR to your MT6573...
    Koush Dutta, the developer for ClockworkMod is so kind that he created to let people build their own CWMR !

    You will need below script too unpack the recovery.img created by
    Download link

    Create a new folder named bt, copy & paste

    Go to

    Select your backup recovery.img from Gscript or similar backup

    Scroll down to the bottom, either you put a check mark on Touch Recovery to build CWMR
    with Touch Screen support or just leave it to build CWMR standard version

    It is best that you bookmark the page as not to mix up with other people's build

    Remember you build number. The RED icon indicate build fail while the BLUE indicate build
    success. You need to check your build number whether it is a success. Then you can
    download the recovery.img if the build is successful.

    Copy downloaded recovery.img from & start cygwin & go to
    bt folder

    Use the command ./ recovery.img

    You will get a new folder named recovery-img-ramdisk folder

    Go back to bm folder, copy your stock recovery, unpack it & delete recovery.img &
    recovery.img-ramdisk.cpio.gz as not to confuse yourself

    On your stock recovery.img-ramdisk, delete etc, res & sbin & replace it with the one from

    Deleted etc, res, sbin                                                   Three files copy & paste from c:\cygwin\bt

    Go to recovery.img-ramdisk\etc & open recovery.fstab

    Change fstype to ext2 & save it

    Open either one of the three recovery.img-ramdisk & copy the content of system

    Copy & paste it to c:\cygwin\bm\recovery.img-ramdisk\system
    If you intent to use adb shell at CWMR then you have to change your stock recovery
    default.prop → 0
    ro.allow.mock.location=0 → 1
    ro.debuggable=0 → 1
    persist.service.adb.enable=0 → 1
    Use below command to repack
    ./ -recovery ./recovery.img-kernel.img ./recovery.img-ramdisk ./recovery.img
    Keep your finger cross, flash it with mobileuncle tools & it should work on your MT6573 !