[Huawei Ideos X5 U8800] qwerty12:
Thank you :)

Certainly, sir.

Unfortunately I won't be working on this anymore unless Huawei get back to my request for the source to the the dhd.ko module (which they may not have to comply with because the license for the module states "Unless you and Broadcom execute a separate written software license agreement governing use of this software" so the U8800pro version may not be under GPL). I made (well, found on the Internet) more optimizations but the Wi-Fi refuses to turn on because the dhd.ko module refuses to load. Only way I can get something working is to build the source that Huawei give or attempt to force other versions of the bcm source to load, but it's unlikely that would work.

--

Anyway, a small guide.

I used an x86_64 laptop running (X)ubuntu 12.04.1 to follow these steps. This page was a great resource.

Prerequisites:

A computer running GNU/Linux :) (a Mac should work in theory - the same toolchain we use is built for it, too, but I have no idea how OS X works)

git installed (apt-get install --no-install-recommends git-core is enough under Ubuntu)

sudo apt-get install flex bison gperf build-essential libncurses5-dev zlib1g-dev ia32-libs lib32z1-dev lib32ncurses5-dev gcc-multilib g++-multilib abootimg

Getting ADB working

One of the best things to do is getting ADB set up, as you then have easy communication with the device. It's not essential but you'll just end up wasting time transferring files through other, longer means.

Grab the Linux platform tools ZIP from here: http://www.hariadi.org/android/manually-download-of-android-sdk-tools-and-sdk-platform-tools/. Extract the adb binary from the zip file, preferably to somewhere in your $PATH. chmod 755 it. chown, if necessary.

Next, open http://aur.archlinux.org/packages/an/android-udev/android-udev.tar.gz and, doing all this as root (sudo in Terminal etc.), place 51-android.rules in /lib/udev/rules.d/ (not the best place - but it works), chmod 644 it and chown root:root it.

Next, execute /usr/sbin/groupadd adbusers, followed by gpasswd -a USERNAME adbusers, USERNAME being the user you normally log on with.

Restart (while you can force Linux to see the new group through the, well, newgrp command udev will not "see" the new rule, despite how much you try with udevadm).

That should be ADB set up (give it a test, remembering to enable USB debugging mode on the phone first!).

On to preparing your workarea.

--

Create a new folder in your home folder and cd to it. This folder will house the prebuilt folder of toolchains and other stuff, and the kernel source in a folder of its own.

In this folder, execute git clone --depth 1 https://android.googlesource.com/platform/prebuilt.git and move onto the next step, since the download takes a while. That command grabs the prebuilt toolchain from Google using Git, but doesn't obtain a deep history for each file to make the download quicker.

Open http://www.huaweidevice.com/worldwi...=toDownloadFile&flay=software&softid=NDY3NTU= and save the source to your Downloads directory. After git has finished running, still in the folder with the "prebuilt" folder, execute tar jxf ~/Downloads/HUAWEI_U8800pro<tab - as in actually press tab> and you should have a kernel folder alongside the prebuilt one.

Building the kernel

cd to this new kernel folder.

First things first: make sure that Bluetooth is properly enabled by editing the Makefile. Find the line #ifeq ($(ENABLE_BTLA_VER30),true) and comment out every line in that section except for KBUILD_CFLAGS += -DHUAWEI_BT_BTLA_VER30 so you end up with this:

#/* < DTS2012020604357 zhangyun 20120206 begin */
# Add Huawei Marco for different BT chip
#ifeq ($(ENABLE_BTLA_VER30),true)
KBUILD_CFLAGS += -DHUAWEI_BT_BTLA_VER30
#endif
#ifeq ($(ENABLE_BLUEZ_VER30),true)
#KBUILD_CFLAGS += -DHUAWEI_BT_BLUEZ_VER30
#endif
#/* DTS2012020604357 zhangyun 20120206 end > */

Commenting out the offending code leaves you with a kernel that builds but a Bluetooth module that won't start up - the same also applies if you try to build with the other define.

You can also make things easier for yourself by replacing the following

ARCH	?= $(SUBARCH)
CROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)

with

ARCH	?= arm
CROSS_COMPILE	?= ../prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-

else you will have to put "ARCH=arm CROSS_COMPILE=../prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-" after "make" each time. Remember this as I'll be assuming that you went for the option to edit the Makefile. I also assume that the prebuilt folder is above the kernel one. Adjust CROSS_COMPILE if necessary.

The ARCH variable is self-explanatory, but the CROSS_COMPILE variable (and the toolchain that it's pointing to) need to be set because the standard GNU development tools that apt installs don't produce output that an ARM processor can understand. So you cross-compile: the tools are for the X86 architecture but produce ARM output. 4.4.3 is chosen because the stock kernel is compiled with GCC 4.4.3 (if you run "adb shell cat /proc/version" you'll see). The arm-eabi-4.4.3 folder is chosen over arm-linux-androideabi-4.4.x because it specifies that magic "3" (I know, bad way to decide but it works), and over i686-android-linux-4.4.3 because we don't want to produce code for the PC.

Get the current configuration in use by the stock kernel (as that's a good point to start from - a known working configuration): http://wiki.cyanogenmod.com/wiki/Building_Kernel_from_source#Configure_the_Build

I'd also recommend placing a copy of .config as arch/arm/configs/<your funky name here> so that if .config gets deleted (make clean etc.) you can run make <the name you gave to the file in arch/arm/configs> and have .config come back again.

(cp arch/arm/configs/<the name you gave to the file> .config if you didn't modify the Makefile to specify the ARM arch.)

Run make oldconfig (not always necessary - generally it's invoked if you've applied a patch that introduces a new config option and the option then needs to go into your .config. Run make menuconfig afterwards and customize away.

When you're done, run make -jX - X as in the number of cores you have + 1. So, in my case, with a quad-core processor and HyperThreading enabled on all of them, "make -j9" works for me. If the compile went OK, you'll be left with a message saying that arch/arm/boot/zImage is ready. If not, run "make" without the -jX argument and make should stop where the error occurs. Have fun fixing the error!

Assuming that you have a new, shiny zImage, it's now time to put it into your boot.img.

Updating your boot.img:

Google have tools for this purpose but I've never used them so I don't know how they work. abootimg works fine for this, however.

Pull the current boot.img off your phone: adb pull /.cust_backup/image/boot.img.. I'd recommend creating a backup somewhere.

Create a new directory to store the boot.img in on your computer and run abootimg -x boot.img (if you had fun enabling every option in the kernel, you'll see why I'm telling you to use the -x option first rather than directly use the -u option). Now run abootimg -u boot.img -k <path to your newly built zImage>.

If this succeeds, yay! If not and you're told it's too big for the boot image, then don't worry. Take the size it's saying that the zImage is and convert that number into hex. Edit bootimg.cfg and change the value of the bootsize setting into the number you just converted into hex. We'll now repack again, but this time running abootimg -u boot.img -f bootimg.cfg -k <path to your newly built zImage>. This should work.

Sending the boot.img to the phone

If your ADB is already running as root, you can do the following to upload the new bootimg:

adb shell mount -o remount,rw /.cust_backup
adb push boot.img /.cust_backup/image/
adb reboot

If not, just reboot into pink screen mode and copy and paste.

Check System Settings and the version number should've changed. Congratulations!

Extras

Installing the modules:

OK, so you decided to build parts of the kernel as a module and you want to actually, y'know, have the modules present on the device. After building the kernel, execute:

make INSTALL_MOD_STRIP=1 modules_install INSTALL_MOD_PATH=<any folder name here>

If you look in that folder, you'll find the modules neatly wrapped up in folders, along with other text files. These text files are useless on a stock ROM because there's no modprobe - you need BusyBox for that. And since we don't want to have them seperated in folders (this is how the stock kernel does it), the files would be wrong, anyway. If you want to use modprobe and have BusyBox installed, you can run depmod on the phone after transferring the modules.

To get the modules into one folder make the directory "modules" in a folder higher-up to where the modules are stored, and then run for i in `find . | grep ko`; do mv "$i" ../modules/; done to move them into that folder.

At this point, I'd just recommend using my OC_Kernel.zip and replacing the modules in that. Or you can adb push them over to the /system/lib/modules folder (after issuing an "adb remount" - assuming that ADB is running as root in the first place).

Making ADB run as root:

As root on your computer, (we want to preserve permissions) use abootimg to split the boot image and extract the contents of the initrd:

abootimg -x boot.img && mkdir newramdisk && cd newramdisk && zcat ../initrd.img | cpio -i --no-absolute-filenames (--no-absolute-filenames is important! I trashed a Ubuntu install by leaving it out - the initrd contains ARM binaries of core Linux programs and if the initrd.img contains an absolute path of "/" then these files will get placed in /)

Make any changes you desire to the initrd. To have adb run as root, just edit /default.prop and set ro.secure to 0. Make sure that the editor you used didn't leave any backup files.

When you're done, run find . -print | cpio -o -H newc | gzip -n -9 > ../initrd.img and this will put the modified initrd folder back into initrd.img.

After that run cd .. ; abootimg -u boot.img -r initrd.img to actually put the initrd.img back into the boot.img.

If you run into a space error, you can do one of three things:

if you only made a single change (like enabling ADB), check to see that there is no backup file (default.prop~) littered about

you can remove the lengthy comments and copyright notices from the files to make space

you can use the trick we used earlier with abootimg to increase the size number in bootimg.cfg for the initrd

Overclocking:

Just look at the acpuclock C file (and possibly relevant cpufreq changes - but I can't remember) in my "OC kernel" diff. Make sure that the option in the kernel config is selected to limit the speeds to the U8800pro's native 1GHz, otherwise the phone will boot at 2GHz!

Rebuilding the Wi-Fi module:

I hope to be able to write this one since it's apparently needed in some cases, but it depends on if Huawei come through :(