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. :-)
- 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.
- 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.
- Download the small kernel patch for the build issue mentioned above (attached to this post) and apply it:
zcat ../linux-gcc.patch.gz | patch -p1
- Grab the /proc/config.gz file from your PRS-T1, uncompress it, and put it in your kernel source tree as .config.
adb shell cat /proc/config.gz | zcat > .config
- 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.
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-
- Now you're ready to build a module. Assuming it's part of the kernel sources, configure it (with make xconfig or menuconfig):
Then run make, not forgetting the -fno-pic option:
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
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