[HOW TO] Compile and Deploy a Kernel

FloRider

Senior Member
Dec 2, 2012
358
111
In this post I'll walk you through the complex task of compiling and deploying a kernel to your tablet. At this time, we only have kernel source for 4.0.4, so our efforts will only be successful on a tablet running 4.0.4 ROM. The process will be the same for Jelly Bean once we get that source, though. At this time you'll have to be running 4.0.4, stock or MCL. You'll need root access as well.

The packages we'll install should cover Ubuntu 10.04-12.04, both 32- and 64-bit. Therefore, you'll end up installing more than you need, but that won't hurt. On the other hand, if you're running a different distro, you may have to search the web to find the necessary packages to compile a kernel. Finally, almost everything we're doing has to be done in Linux, but I run Linux in a virtual machine on Windows. So, for steps 1 and 6, I won't have Linux-specific instructions. Let's divide and conquer the task before us though. There can be many hurdles to reaching our goal, so I'll try to split it into bite-sized pieces:


  1. Install the Lenovo tools and IdeaTab drivers.
  2. Collect the files you'll need to build and deploy your kernel.
  3. Configure your build environment -- installing the necessary files and packages.
  4. Extract the source and prepare the build configuration.
  5. Build your kernel.
  6. Deploy and test your product.

1 -- I won't elaborate on this one. If you're considering building and flashing a kernel, hopefully you've done this. If not, there are other posts that detail this process. I did say "walk you through", not "push the baby stroller" :rolleyes:.

2 -- First, lets get the kernel source:
http://download.lenovo.com/consumer/open_source_code/a2109n_gpl_kernel_570.tar.bz2
Drop this somewhere on your system (e.g. /Downloads). Now, if you don't have a 4.0.4 ROM zip file, download one. MCL0103 is good choice. Extract boot.img from this file with your favorite zip tool. Next, we'll download the toolchain. We can't compile the kernel without it. It's just an 80MB download. You can get it here:
http://uniteddev.com/wordpress/files/tools/arm-eabi-4.4.3.zip
Finally, let's get the config file. We've got to connect to the tablet for this file. Copy config.gz from the /proc directory on the root of your tablet to somewhere safe on your system. Make sure you can see system files. Extract config from the gzip. Rename it to .config. Dot-something files are hidden unless you can see system files.

3 -- Open a terminal window and type
Code:
sudo apt-get install git-core libncurses5-dev lib32stdc++6 ia32-libs lib32ncurses5-dev lib32z1-dev zlib1g-dev build-essential automake binutils libc6-dev flex bison curl abootimg
This should be more than enough for your particular installation (assuming you are on Ubuntu). If you get compiler errors, I know a few more you can install that I didn't think were necessary.

4 -- Now you need to decide the paths for the toolchain and the source code. That's up to you, but I'll use mine in the directions, so unless you already have a source tree, it'll be easier to use the same structure as mine. Also, the permissions from your /home directory will make things easier. From /home, create a directory named Development. From /Development, create a directory named kernels. Copy the kernel source bzip to /kernels and extract it in that directory. Next, find your .config file and copy it to your source root directory (/A2109N_GPL_kernel_570). Finally, let's take care of the toolchain. Copy arm-eabi-4.4.3.zip to /Development and extract it there.

5 -- Everything should be set to go. I'll talk about build options later, but let's do this the easy way. Open a terminal in /A2109N_GPL_kernel_570 and type
Code:
export ARCH=arm
export CROSS_COMPILE=/home/(your username)/Development/arm-eabi-4.4.3/bin/arm-eabi-
make oldconfig
make -j5
The number after j should be the number of cores on your machine + 1. If everything worked, your kernel will appear in /arch/arm/boot as zImage.

6 -- Now, find the boot.img file from your ROM. Make sure it's not in the same directory as your zImage and type
Code:
abootimg -x boot.img
Delete bootimg.cfg and put zImage in a safe place. Rename it MCL_zImage so we know where it came from. Here comes the moment of truth. Boot your tablet into bootloader and type
Code:
fastboot flash:raw boot zImage initrd.img
fastboot reboot
Cross your fingers and wait for your system to boot. We've flashed over your kernel, so... don't worry :). That's why we kept MCL_zImage. If it doesn't boot, repeat the above steps (flashboot steps), using MCL_zImage. That'll rescue your system.

If you're going to compile again, even if it wasnt successful, you'll have to clean up your source directory. That's easy. Go to your source root and type
Code:
make distclean
Then copy .config to the root again and go ahead with step 5.

That's the process. I'll add more info later. If everything worked, give yourself a pat on the back. If not, double-check your steps... then let me know.

Thanks to anika200 and gmarkall for their valuable input.
 
Last edited:

FloRider

Senior Member
Dec 2, 2012
358
111
What if I'm getting compiler errors?
Assuming you haven't altered the source, I think it's most likely that you're missing a necessary package. It's very difficult to know exactly which are necessary -- if you Google for kernel build guides, they often have extensive lists of packages to install, most of them unnecessary. That said, there are a few more that may be needed for your installation. Try these:
Code:
sudo apt-get install libncurses5 kernel-wedge kernel-package linux-source fakeroot gcc-4.3-multilib

The prebuilt toolchain is enormous! I can't download that much data.
I found an 80MB download. Check the directions again if you didn't see it.

So I just flashed the same kernel on my tablet? Big deal.
It is a big deal. It's not easy to make it through this process the first time. You deserve that pat on the back I mentioned.

Well, what good is this going to do me?
Let's start with the easy part. This won't do much for you, but there are a couple interesting options. First, though, we need to update a library:
Code:
sudo apt-get install libncurses5-dev
Next, at the part where you entered
Code:
make oldconfig
Type
Code:
make menuconfig

This will bring up a text-based menu. If you want a graphic display, search for "make xconfig -- you need to add a couple Qt packages -- but I actually prefer the text version. This menu will load hundreds of options, most of them useless to us. If you do a bit of looking, though, you can find a couple that may enhance your experience. For instance, have you noticed that the only scheduler available on the A2109 is noop? I prefer deadline, and it's in the kernel code. To enable it, go to: Enable the block layer->IO Schedulers->select Deadline (and CFQ if you like), and make sure they're starred instead of reading "M" (which will place them in a module), and finally you can choose the default scheduler if you like. There's some debate about schedulers. I think noop may be the quickest for all tasks, but deadline reduces user wait time for foreground apps. It's a little more advanced than noop, which is a basic FIFO scheduler.

That was sort of cool. Is that it?
Well, there might be a way to enable NTFS write support for your micro sdcard. I can't test it because I can't find my PC card reader, but it's worth a shot if you have an NTFS card. Go to Filesystems->Dos/FAT/NT filesystems and select NTFS write support. Give it a shot and let me know if it works. It won't take long to find out.

I'd like to print from my tablet, but I don't have a wifi printer.
Here's something you can try if you have an OTG cable. I don't know how to print from my tablet, but I've heard that there are apps for it. If you can print to a wifi printer, why not usb? I'll tell you how to find out. Go to Device drivers->USB support and select USB printer support. There may be a specific printer driver somewhere in the settings, but if you don't need to set up a wifi printer, why would it be any different for a USB printer? Download a print app, plug the printer into your tablet, and find out.

I don't have the right character set for my language on my tablet.
Well, you can enable non-US codepages in the settings. I don't know how to enable a different codepage, but maybe a keyboard app will let you. Go to Filesystems->Native language support. Select what you need and see if you can get it to work.

These are starting to sound like shots in the dark.
There are obviously a lot of settings. I didn't delve into every single one. Feel free to search for anything specific you need. I don't know if any of the last three will work, but if even one does, I think that would be helpful to a lot of people.

I'm getting tired of fooling with kernel settings.
At least you're getting better at building and installing kernels, and maybe you found a setting that is useful. It's a good thing that you're building this expertise, because the next activity will take you out of your comfort zone ;).
 
Last edited:

FloRider

Senior Member
Dec 2, 2012
358
111
Do we have JellyBean Kernel source?

No one's expressed any interest in kernel development -- until now :) -- so I haven't been aggressive in pursuing the issue. I requested the source a couple weeks ago, and I'll send a follow-up right now.
 

doomboss

Senior Member
Jan 17, 2013
252
47
Just wondering, is the Nexus7's kernel really different from A2109's kernel?? Please forgive me if this is a dumb question...
 

FloRider

Senior Member
Dec 2, 2012
358
111
Just wondering, is the Nexus7's kernel really different from A2109's kernel?? Please forgive me if this is a dumb question...

Not a dumb question at all. The significant differences are going to be where the hardware differs. The N7 platform, or board, is called Grouper, while ours is Kai. I haven't looked much at the board code, but I have to assume this relates to the specifics of the core hardware, such as memory and storage. Then you'll have differences in the drivers, due to different displays, touchscreens, cameras, etc. What makes the N7 kernel useful is that it is the same version, so a lot of code can be lifted from one to the other and plugged right in. Want a new governor from an N7 kernel? It's mostly a cut & paste operation -- the A2109 config will have to be notified that the new governor exists, but that's simple.

The great thing is that the brains are the same -- the Tegra 3 SoC. Really, the code we're generally interested in (cpu freq, scheduling, governors, suspend functions) can be shared pretty freely. Give it a shot :). The best thing about N7 code, though, is the incredible number of custom kernels out there. Look at the features advertised for a kernel, download the source, and see if you can figure it out.
 
Last edited:

doomboss

Senior Member
Jan 17, 2013
252
47
Not a dumb question at all. The significant differences are going to be where the hardware differs. The N7 platform, or board, is called Grouper, while ours is Kai. I haven't looked much at the board code, but I have to assume this relates to the specifics of the core hardware, such as memory and storage. Then you'll have differences in the drivers, due to different displays, touchscreens, cameras, etc. What makes the N7 kernel useful is that it is the same version, so a lot of code can be lifted from one to the other and plugged right in. Want a new governor from an N7 kernel? It's mostly a cut & paste operation -- the A2109 config will have to be notified that the new governor exists, but that's simple.

The great thing is that the brains are the same -- the Tegra 3 SoC. Really, the code we're generally interested in (cpu freq, scheduling, governors, suspend functions) can be shared pretty freely. Give it a shot :). The best thing about N7 code, though, is the incredible number of custom kernels out there. Look at the features advertised for a kernel, download the source, and see if you can figure it out.

Thank you for the reply!!! :D

I was just had an idea that maybe it is possible to port some custom kernels from Nexus 7 to A2109 since there are plenty of them available on XDA. I am gonna take some time to read your instruction first just to have some idea about how a kernel looks like first :D

Thanks again for the explanation!
 

FloRider

Senior Member
Dec 2, 2012
358
111
Thank you for the reply!!! :D

I was just had an idea that maybe it is possible to port some custom kernels from Nexus 7 to A2109 since there are plenty of them available on XDA. I am gonna take some time to read your instruction first just to have some idea about how a kernel looks like first :D

Thanks again for the explanation!

My pleasure. Let me know if you have any questions. I think I said this in my post, but one of the easiest things to do is to add the deadline scheduler when you compile the kernel (using make menuconfig). The code is already there, so it's a good place to start after you get the hang of compiling the kernel.
 

doomboss

Senior Member
Jan 17, 2013
252
47
Oh i have more question :D Is there a way to open the kernel code on my computer? I want to compare the code with other devices.

Also, all the code needs to type in the tablet by using the terminal emulator on my tablet right?

I am a total noob about building kernel, so i might have more questions later on ;):p
 

FloRider

Senior Member
Dec 2, 2012
358
111
Oh i have more question :D Is there a way to open the kernel code on my computer? I want to compare the code with other devices.

Also, all the code needs to type in the tablet by using the terminal emulator on my tablet right?

I am a total noob about building kernel, so i might have more questions later on ;):p

You're going to need Linux. The guide focuses on Ubuntu (and its derivatives), but of course you can compile the code with any Linux box. It's very simple -- just a few 'make' (build) commands. The source is text, so that can be opened with any editor or IDE. The source is packaged in a tar file, I believe, which can be extracted with commands that should be standard with the Linux distros. It sounds like you don't have a Linux machine though. That's no problem -- I run Linux Mint (based on Ubuntu) in a virtual machine on my Windows box with software called VMware Player. It's all very easy to setup and use.

Take a look at this page: Linux Mint on VirtualBox?Linux Mint on VMWare?Best Run Linux on Windows Tutorial. The important part starts at Running Linux on Windows and ends with Linux Mint on VirtualBox. It's a piece of cake -- trust me. Write back and let me know where you stand and any and all questions you have. PS This is how I got started, maybe just two months or so ago.
 

vampirefo.

Senior Member
Developer
Nov 8, 2011
3,836
1,394
Last I heard (I think on the 14th), it should be about ready. I'll send another message.

Sent from my IdeaTabA2109A using Tapatalk HD

Sounds good, perhaps when the source is released more people might show an interest in kernel building.
 
Top