View Single Post
Old 08-17-2012, 08:16 AM   #1
altruizine
Senior Altruist
altruizine ought to be getting tired of karma fortunes by now.altruizine ought to be getting tired of karma fortunes by now.altruizine ought to be getting tired of karma fortunes by now.altruizine ought to be getting tired of karma fortunes by now.altruizine ought to be getting tired of karma fortunes by now.altruizine ought to be getting tired of karma fortunes by now.altruizine ought to be getting tired of karma fortunes by now.altruizine ought to be getting tired of karma fortunes by now.altruizine ought to be getting tired of karma fortunes by now.altruizine ought to be getting tired of karma fortunes by now.altruizine ought to be getting tired of karma fortunes by now.
 
Posts: 82
Karma: 600554
Join Date: Jun 2012
Device: Onyx Boox C67ML, Onyx Boox Note Pro
Lightbulb How-to: Compiling the kernel and kernel modules

In another thread, the question came up of how I went about compiling a kernel module for the kernel shipping on the PRS-T1. In this How-to, I'm assuming you know how to compile a Linux kernel, and will focus the PRS-T1 specifics. I'm using the 1.0.04.12210 firmware.

To compile a kernel module, you first need to build Sony's kernel to generate a Module.symvers file with the correct ABI-version signature. In a second step, you can build your module.

I've been using the GCC 4.4.3 toolchain coming with the Android NDK on Linux, which is trivial to set up (just unpack the NDK tarball). The shipped kernel has been compiled with GCC 4.4.0. This minor version difference triggers a compilation issue, which I (with a little net-wisdom help) have fixed with a small patch (attached to this post).

Another issue is that the kernel does not export the _GLOBAL_OFFSET_TABLE_ symbol, so modules need to be compiled with the -fno-pic compiler option. I'm not sure why that actually works, but it does. :-)
  1. Download and unpack the Android NDK. I happen to use a slightly outdated version of the NDK (Revision 6), but the GCC 4.4.3 toolchain is included in newer NDK revisions as well. YMMV.
  2. Download and unpack Sony's kernel release by following the link on the distribution page (direct download). This is for the 1.0.04.12210 firmware; if you're using another revision, try finding it on Sony's open-source distribution page.
  3. Download the small kernel patch for the build issue mentioned above (attached to this post) and apply it:
    Code:
    cd linux-2.6.35.3
    zcat ../linux-gcc.patch.gz | patch -p1
  4. Grab the /proc/config.gz file from your PRS-T1, uncompress it, and put it in your kernel source tree as .config.
    Code:
    adb shell cat /proc/config.gz | zcat > .config
  5. You're ready to build the kernel. Here's a slightly complicated command line to do it in one step. I'm sure you can figure out how to do this in a fashion that's more convenient to you.
    Code:
    env PATH=$PWD/../android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin:$PATH make -j4 ARCH=arm CROSS_COMPILE=arm-linux-androideabi-
  6. Now you're ready to build a module. Assuming it's part of the kernel sources, configure it (with make xconfig or menuconfig):
    Code:
    env PATH=$PWD/../android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin:$PATH make -j4 ARCH=arm CROSS_COMPILE=arm-linux-androideabi- xconfig
    Then run make, not forgetting the -fno-pic option:
    Code:
    env PATH=$PWD/../android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin:$PATH make -j4 ARCH=arm CROSS_COMPILE=arm-linux-androideabi- EXTRA_CFLAGS=-fno-pic modules
Attached Files
File Type: gz linux-gcc.patch.gz (244 Bytes, 516 views)

Last edited by altruizine; 08-22-2012 at 03:17 AM. Reason: Fix: Made explicit that make xconfig needs the cross-compile options, too
altruizine is offline   Reply With Quote