[HTC Pico (Explorer)] #define:
Hey guys..

With all the awesome development thats been going on for our device, many people have been inspired to start their own versions of android development.. But, most of them do not know where to begin, or how to begin.. Or they may have some questions that remained unanswered..

Hence, I present to you(on a few requests), a simple and newbie friendly guide to compiling your own kernel for the HTC Explorer(Pico)..

Now I understand there is a custom kernel/custom ROM compiling tutorial by sakindia123 right here.. But, it has proven a little too complicated for some of the people starting out in the Android world..

I'll be making it as simple as possible..

-------------------------------------

Alright..

In order to start compiling kernels and/or ROMS, we need a certain prerequisites to be obtained...

1) A Unix based OS..

a) Ubuntu - Preferably latest, which is 12.10 as of right now.. Both 32-bit and 64-bit versions are OK for compiling kernels.. For ROMs you need 32-bit for Froyo and below, and 64-bit for Gingerbread and higher.. Beware that installing a 32-bit version twice will NOT make it a 64-bit version..

b) MacOS - Apple's very own OS.. Not much info about this with me..

2) Some knowledge to move around a Unix based system using the terminal..

3) A few packages, to let the system know we are trying to compile a kernel on it..

4) The source code of the kernel you want to compile.. There are various kernel sources you can compile from.. There's the stock HTC source, for Sense and Sense-based ROMs, there's the 2.6.38 custom kernel source by lirokoa, there's Garuda kernel source by flowish, and the more recent, 3.0.16 kernel source..

5) Some time on our hands, and patience..

-----------------------------------------------------------

Ok.. Now we begin our work..

First, we install the required packages in our Ubuntu setup.. To do that, fire up a terminal window, and type :

sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 git

Now, I myself do not know what these packages exactly do.. All I know is that they help us get our work done, ie, kerneling.. :cowboy:

Now, if you're using Ubuntu 12.04, you many need to create links of certain files, in order for them to work properly.. Run :

sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

Now, it's a good idea to start fresh.. So go ahead and reboot the system.. :good:

---------------------------------------------------------------------

Alright.. So now we have our packages..

Next, we need Java...

Now, in the world of Android, for us Pico users, Java 7 is of no use.. And Java 6 cannot be installed using the "conventional" methods..

So, we'll install Java 6 using the PPA feature..

Fire up a terminal on your newly rebooted system, and type :

sudo add-apt-repository ppa:ferramroberto/java

Next, run :

sudo apt-get update

Now that the repository is added and updated in our system, we'll install Java by running :

sudo apt-get-install sun-java6-jdk

This will install the correct version of Java in our system..

-----------------------------------------------------------------------------

Next up, obtaining the source, boot image tools and toolchain to compile.. You can obtain all the sources I mentioned above using Github.. Except the HTC source, which you'll find at htcdev.com ...

Boot image tools - https://github.com/sakindia123/boot-image-tools

The toolchain, you can get from here - http://www.github.com/sakindia123/android_toolchains

Once you download everything, extract it someplace.. Now, in terminal, do :

gedit .bashrc

And add(at the end) :

export PATH=${PATH}:path/to/toolchain/folder/arm-eabi-4.4.3/bin
export PATH=${PATH}:path/to/bootimagetools/folder/tools

Now close and re-open the terminal, and you're all set to compile..

-----------------------------------------------------------------------------

Now comes the fun part... Compiling the kernel...

This part I'm gonna describe in numbered steps... The path(assumed) I'm gonna take, is '~/android/kernel_source'.. And I'm assuming you are in the top of the kernel source directory...

1) You need to pull the kernel config from your phone.. To do that, connect your phone using ADB, and run :

adb pull proc/config.gz ~/android/kernel_source

2) Next, you need to extract the kernel config from the compressed file..

zcat config.gz > .config

3) Now, we have the .config file directly, so we can omit the "defconfig" command..

3a) If you wanna run the defconfig, then omit steps 1 and 2, and instead run :

make ARCH=arm CROSS_COMPILE=arm-eabi- msm7627a_defconfig ---> For Sense kernel

make ARCH=arm CROSS_COMPILE=arm-eabi- htc_pico_defconfig ----> For lirokoa's and flowish's kernel source

make ARCH=arm CROSS_COMPILE=arm-eabi- pico_defconfig -----> For 3.0.16 kernel..

4) Now, we run the main compiling command :

make ARCH=arm CROSS_COMPILE=arm-eabi- -jX

The X can be replaced by the maximum number of jobs your computer can handle simultaneously.. The higher this number, the faster the compiling will get.. But do not enter a number too high, your computer may explode due to overheating.. Wouldnt want that, would we??

5) If all goes well, at the end of 15-mins to 1 hour(depending on your PC hardware), you'll have a zImage...

6) Now, we create a working directory :

mkdir workspace

7) Next, we copy our zImage to the working directory :

cp arch/arm/boot/zImage workspace

8) Next up, modules..

find . -name '*ko' -exec cp '{}' workspace \;

9) Now, we take a working boot.img from a ROM zip.. We do this for the ramdisk.. But keep in mind that different ROMs have different ramdisks.. For eg, a kernel made with CM9 ramdisk will not work on CM10.. So take the boot.img from the ROM you wanna use the kernel on..

10) We unpack the boot.img :

unpackbootimg -i boot.img

When we do this, we'll get a lot of files.. We only need the file named 'boot.img-ramdisk.gz'..

11) Finally, we make a new boot.img file, which will incorporate our compiled zImage, and the ramdisk we just extracted..

mkbootimg --kernel zImage --ramdisk boot.img-ramdisk.gz --cmdline no_console_suspend=1-console=null --base 12c00000 --output boot-new.img

And Voila!! We have a freshly compiled kernel, 'boot-new.img'..

12) To use it, put your phone in fastboot mode, and run :

fastboot flash boot boot-new.img

13) Now do not reboot the phone... Boot the phone in recovery mode, mount system from the recovery, connect the phone to PC, and then run :

$ adb remount

$ adb push '*ko' system/lib/modules ----> run this from the directory where you copied all the modules

$ adb reboot

And there you have it, your very own kernel..

----------------------------------------------------------------

Ok.. Sometimes you may get weird errors when trying to connect your phone to your computer via ADB... Its mostly a permission problem.. Fortunately, instead of running ADB as root, we have another solution..

Fire up a terminal, and type :

$ sudo gedit /etc/udev/rules.d/51-android.rules

A file will open up.. Add the following content into that file and save it :

######################################################
# Project: http://code.google.com/p/51-android/ #
# File: /etc/udev/rules.d/51-android.rules #
# Author: snowdream #
# Date: 2010.06.07 #
######################################################

#Acer
SUBSYSTEM=="usb", ATTRS{idVendor}=="0502", MODE="0660", OWNER="snowdream"

#ASUS
SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", MODE="0660", OWNER="snowdream"

#Dell
SUBSYSTEM=="usb", ATTRS{idVendor}=="413", MODE="0660", OWNER="snowdream"

#Foxconn
SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", MODE="0660", OWNER="snowdream"

#Fujitsu/Fujitsu Toshiba
SUBSYSTEM=="usb", ATTRS{idVendor}=="04c5", MODE="0660", OWNER="snowdream"

#Garmin-Asus
SUBSYSTEM=="usb", ATTRS{idVendor}=="091e", MODE="0660", OWNER="snowdream"

#Google
SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", MODE="0660", OWNER="snowdream"

#Hisense
SUBSYSTEM=="usb", ATTRS{idVendor}=="109b", MODE="0660", OWNER="snowdream"

#HTC
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0660", OWNER="snowdream"

#HTC HERO

#Huawei
SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0660", OWNER="snowdream"

#K-Touch
SUBSYSTEM=="usb", ATTRS{idVendor}=="24e3", MODE="0660", OWNER="snowdream"

#KT Tech
SUBSYSTEM=="usb", ATTRS{idVendor}=="2116", MODE="0660", OWNER="snowdream"

#Kyocera
SUBSYSTEM=="usb", ATTRS{idVendor}=="0482", MODE="0660", OWNER="snowdream"

#Lenovo
SUBSYSTEM=="usb", ATTRS{idVendor}=="2006", MODE="0660", OWNER="snowdream"

#LG
SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", MODE="0660", OWNER="snowdream"

#Motorola
SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", MODE="0660", OWNER="snowdream"

#NEC
SUBSYSTEM=="usb", ATTRS{idVendor}=="0409", MODE="0660", OWNER="snowdream"

#Nook
SUBSYSTEM=="usb", ATTRS{idVendor}=="2080", MODE="0660", OWNER="snowdream"

#Nvidia
SUBSYSTEM=="usb", ATTRS{idVendor}=="0955", MODE="0660", OWNER="snowdream"

#OTGV
SUBSYSTEM=="usb", ATTRS{idVendor}=="2257", MODE="0660", OWNER="snowdream"

#Pantech
SUBSYSTEM=="usb", ATTRS{idVendor}=="10a9", MODE="0660", OWNER="snowdream"

#Pegatron
SUBSYSTEM=="usb", ATTRS{idVendor}=="1d4d", MODE="0660", OWNER="snowdream"

#Philips
SUBSYSTEM=="usb", ATTRS{idVendor}=="0471", MODE="0660", OWNER="snowdream"

#PMC-Sierra
SUBSYSTEM=="usb", ATTRS{idVendor}=="04da", MODE="0660", OWNER="snowdream"

#Qualcomm
SUBSYSTEM=="usb", ATTRS{idVendor}=="05c6", MODE="0660", OWNER="snowdream"

#SK Telesys
SUBSYSTEM=="usb", ATTRS{idVendor}=="1f53", MODE="0660", OWNER="snowdream"

#Samsung
SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0660", OWNER="snowdream"

#Sharp
SUBSYSTEM=="usb", ATTRS{idVendor}=="04dd", MODE="0660", OWNER="snowdream"

#Sony
SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", MODE="0660", OWNER="snowdream"

#Sony Ericsson
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fce", MODE="0660", OWNER="snowdream"

#Teleepoch
SUBSYSTEM=="usb", ATTRS{idVendor}=="2340", MODE="0660", OWNER="snowdream"

#Toshiba
SUBSYSTEM=="usb", ATTRS{idVendor}=="0930", MODE="0660", OWNER="snowdream"

#ZTE
SUBSYSTEM=="usb", ATTRS{idVendor}=="19d2", MODE="0660", OWNER="snowdream"

Note : Replace "snowdream" with your username.. Keep the double quotes..

Now, we need to give executing permissions to this file.. So :

$ sudo chmod a+r /etc/udev/rules.d/51-android.rules

$ sudo service udev restart

And this will solve the permission problem when connecting through ADB or FASTBOOT...