Mctrain's Blog

What I learned in IT, as well as thought about life

Enable CONFIG_MODULE in Cyanogenmod Kernel

| Comments

I met a problem when trying to insert kernel module in the moto-g Android phone. My moto-g phone is built with Cyanogenmod falcon ROM, but by default, this ROM does not support installing modules.

proc modules fail

Thus I’ve to enable it in the kernel config, re-compile and install the kernel. In this post I will give a short note about how to do it.

In this blog, I will take falcon as the example, since my device is moto-g.

Some materials:

How To Build CyanogenMod Android for Motorola Moto G (“falcon”)

integrated kernel building


First, follow this post, you can download the source code for falcon device. Support our source code is in ~/android/system,You need to do as follows to prepare before compiling the kernel:

  $ cd ~/android/system
  $ source build/envsetup.sh
  $ breakfast falcon
  $ cd device/motorola/falcon
  $ ./extract-files.sh
  $ croot

NOTE: before executing ./extract-files.sh,you need to plug the device to your computer.

After above operations, you need to refer to this post to prepare and compile the kernel.

Add CONFIG_MODULE option in the kernel config

First go to the kernel code directory:

  $ cd kernel/motorola/msm8226

If you execute make ARCH=arm help, you can see many candidate defconfig options. In our example, we just need to use the falcon_defconfig, so we do as follows:

  $ make ARCH=arm falcon_defconfig

This command will copy the arch/arm/configs/falcon_defconfig file to .config. If we open the .config file, we can see the CONFIG_MODULE option is disabled. In order to enable it, we execute:

  $ make ARCH=arm menuconfig

This will open the menuconfig screen based on the .config default configuration. Then we only need to check the Enable loadable module support and some of the following options in the screen:

menuconfig 1

menuconfig 2

Then we exit and save the config, copy it to the arch/arm/configs/falcon_defconfig, and clear the config settings (that’s important, otherwise, it may fail in the next phase), finally go back to the root directory:

  $ cp .config arch/arm/configs/falcon_defconfig
  $ make mrproper
  $ croot

Compile and install kernel

In this time, we can compile the kernel:

  $ mka bootimage

After several minutes, the kernel compiling is done, the out/target/product/falcon/boot.img is generated.

If you want to flash the kernel to your device, you can type:

  $ adb root
  $ adb remount
  $ installboot
  $ adb reboot

Or if you just want to test the kernel instead of flashing it:

  $ adb reboot bootloader
  $ fastboot boot out/target/product/falcon/boot.img

Finally your newly built kernel works, and you can see the /proc/modules in the file system, which means you can insert your own modules!

proc modules work

Comments