[HOW TO] Compile and Deploy a Kernel
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:
- Install the Lenovo tools and IdeaTab drivers.
- Collect the files you'll need to build and deploy your kernel.
- Configure your build environment -- installing the necessary files and packages.
- Extract the source and prepare the build configuration.
- Build your kernel.
- 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" .
2 -- First, lets get the kernel source:
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:
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
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.
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
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
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.
export CROSS_COMPILE=/home/(your username)/Development/arm-eabi-4.4.3/bin/arm-eabi-
6 -- Now, find the boot.img file from your ROM. Make sure it's not in the same directory as your zImage and type
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
abootimg -x boot.img
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.
fastboot flash:raw boot zImage initrd.img
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
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 by FloRider; 12-18-2012 at 04:38 PM.
12-17-2012 09:53 PM
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:
The prebuilt toolchain is enormous! I can't download that much data.
sudo apt-get install libncurses5 kernel-wedge kernel-package linux-source fakeroot gcc-4.3-multilib
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:
Next, at the part where you entered
sudo apt-get install libncurses5-dev
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 by FloRider; 12-21-2012 at 12:53 PM.
Excellent guide, FloRider. Thanks.
Do we have JellyBean Kernel source?
If you like my work buy me a coffee!!!
Due to the overwhelming PM's that I receive, I am unable to answer all the questions and many questions are duplicates so PLEASE post all questions on this forum so I may better help you and any others who are having the same issues.
No PM's regarding windows questions will be answered, I am a Linux Guy.
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.
Originally Posted by vampirefo.
Re: [HOW TO] Compile and Deploy a Kernel
I don't know if you saw my post, but it's coming...
Originally Posted by vampirefo.
Sent from my HTC6435LVW using Tapatalk 2
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.
Originally Posted by doomboss
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 by FloRider; 01-17-2013 at 10:26 PM.
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.
Originally Posted by doomboss