[Huawei Ideos X6] preyesh1:
This guide will help you in porting ROM's to different devices. Although it my not work 100% of the time, it should you show the steps involved in porting a ROM but also which files are important to a device's functionality.

Some handy tools to have before starting:

- The Android SDK, this contains ADB logcat which is a hugely important tool in ROM development. It lets us know what is perhaps causing an app to F/C or a ROM to bootloop. See our guide on how to set this up HERE

- Notepad++ , very useful for altering scripts.

- Patience, getting ports to boot can sometimes take a lot of effort and time but hopefully this guide will show you the quickest and easiest way to get your ported ROM booting.

Okay first decide which ROM you would like to port, don't port HDPI ROM's to MDPI devices or vice versa it just won't work.And it's best to start with the easy and simple ports to get some experience behind you before you go off porting Sense 3.0 to your X10.

Let's get started...

Porting is fairly easy and requires only some folders, files and a boot.img to be replaced.

Now because this is a universal guide I can only tell you how to get the basic hardware working on your port. AOSP ROMs are fairly easy to figure out so you won't have much trouble figuring out what needs replacing. Manufacturer specific ROMs such as Sense 3.0 ROMs are bit more difficult to figure out but the basic skills you will be taught here can be applied in principle to those ROMs.

1. First off lets start with the biggie, the kernel. Those of you familiar with linux will know how important the kernel is a to system, I won't go into detail here but if your kernel isn't specific to your device then your ROM won't boot. The kernel is contained within the boot.img of your ROM's zip (or zImage if it's a Samsung). During flashing it is unpacked and wrote to the system.

To replace the kernel we need to decompile it and no this isn't as easy as opening it winzip. The best way to do this is using Linux; we can use a combination of both perl scripts and terminal commands.

In order for us too see the kernel files contained within the boot.img, we need to first unpack it and this will extract the kernel binary and the ramdisk. What you need at this point is the split_bootimg.zip. This contains a perl script which will extract both files and display the boot.img header, the kernel command line and the board name (if specified).

An example of the output would be:

Page size: 2048 (0x00000800)

Kernel size: 1388548 (0x00153004)

Ramdisk size: 141518 (0x000228ce)

Second size: 0 (0x00000000)

Board name:

Command line: no_console_suspend=1

So how to use this perl script you ask? Well...

First open a terminal and cd to the directory which contains the perl scripts you just downloaded. Next, type this command: "perl split_bootimg.pl boot.img" and that will extract the kernel to your current directory.

Now, we need to extract the ramdisk, the ramdisk has been unpacked from the boot.img and is sitting your current directory with the file name "boot.img-ramdisk.gz", at the moment this still isn't useful to us so we need to un-gzip and then un-cpio it.

So for that we need the Linux terminal. So again from the terminal or using the same terminal enter these commands:

mkdir ramdisk < Creates a directory where we can store the ramdisk

cd ramdisk < Changes our current directory to that of the ramdisk

gzip -dc ../boot.img-ramdisk.gz | cpio -i < Will un-gzip and un-cpio ramdisk

Okay so now we can see all the ramdisk files:

./init.devicename.rc

./default.prop

./proc

./dev

./init.rc

./init

./sys

./init.goldfish.rc

./sbin

./sbin/adbd

./system

./data

So what's important here is the "init.devicename.rc" and "unvented.device.rc". This is the target devices .rc files contained within the ramdisk, now all we have to do here is rename this .rc file to that of the device you are porting to, e.g: "init.trout.rc" > "init.hero.rc"

Some devices ramdisk differ and may not contain "unvented.device.rc" so if this is case for you,then begin by renaming the init.device.rc to your model id and leave it at that. If you get problems well.. that's what the live support is for.

The other file which may be of use to us here is "init.rc", this contains all the system wide kernel properties which we can change to our liking but we'll leave as it is for now.

So now we've edited the ramdisk, we need to change the kernel so that the one the ROM uses is actually specific to our device, when we used the split_bootimg perl script it also unpacked the kernel and that is also in our current directory with the filename "boot.img-kernel".

Easiest way to replace the kernel is to take a kernel update zip for your device, un-zip it and rename the zImage file to "boot.img-kernel" and copy and replace the file of the same name in your directory.

Okay, now that's all done, we need to pack this back up into something that android can understand when it's being flashed. So we need to make a new boot.img from the files we have in our current directory.

First, we need to pack the ramdisk back up into it's original state, so again we need to use the Linux terminal. The command that will do this is this:

find . | cpio -o -H newc | gzip > ../newramdisk.cpio.gz

Remember the ../ is the path to the directory of your ramdisk, remember to remove anything that won't be used by the kernel as cpio will include EVERYTHING in the working directory.

Okay now that the ramdisk is back in it's original format we need to repack the kernel and ramdisk into the boot.img.

So back into the terminal we go and this time we're going to use the "repack-bootimg" perl script (as if that wasn't obvious enough). The command you will ise here is esentially the same to the one we used to split it, so:

"perl repack-bootimg.pl ../path to kernel ../path to ramdisk directory ../path to outfile"

And the boot.img is complete!

So if we look back to the ROM we are porting we can see that we need to put the boot.img into the root of the zip, this will hold true for almost every Android ROM. Next we need to replace some of the files which allow the hardware and keys to work. This is the easy part.

Go into the root of the zip and follow this path to the kernel modules; "/system/lib/modules" Delete all the files you find here.

Now take the kernel modules which came along with the kernel you added to the boot.img and copy them there. Next follow this path to the propietary hardware files;

"/system/lib/hw" Delete all the files you find here.

Again this as simple as taking the files from a ROM meant for your device and copying them into this directory. So what we've done there is added the kernel modules that we can set symlinks to in the updater-script and contain the modules needed for things like WiFi, bluetooth etc. The "/hw" directory as you can see contains the files which control the sensors and lights such as GPS and the accelerometer.

Next, we can look at making sure the hard and soft keys work, the files which contain the layout of your device keys can be found in;

"/system/usr/keylayout" and "/system/usr/keychars"

Touch only those 2 directories.

Delete all the files in here and copy the ones from your device (following the same directory) here.

Okay now to finish off we need to copy over the mount point information for your device and the WiFi drivers.

Follow this path; "/system/etc" and delete only these files and directories.

- vold.fstab

- /wifi

- /ppp

Now follow the same path in a ROM for your device and copy over these files.

Okay we're done!

Before flashing take a look and some guides which show you how to write updater-scripts, incase you need to create important symbolic links.

Happy Porting!

**mod edit** credits to JieeHD from the VillainROM team for this guide! original thread here: http://www.freeyourandroid.com/guide/porting-android