Build Android Kernel && Kernel Module
I Build Android Kernel (with Module enabled)
1. Kernel source is under android_src/kernel folder
2. Config file is under kernel_src/arch/arm/configs folder xxx_deconfig
3. setup config:
$make ARCH=arm CROSS_COMPILE=arm-eabi- xxx_defconfig
(.config file can also be created from device:
adb pull proc/config.gz
zcat config.gz > .config
)
4. enable module:
$make ARCH=arm CROSS_COMPILE=arm-eabi- modules_prepare
5. config and add new things if needed:
$make ARCH=arm CROSS_COMPILE=arm-eabi- menuconfig
6. build kernel:
$make ARCH=arm CROSS_COMPILE=arm-eabi- -jX
[Error in compiling kernel:]
[error1 : ]
drivers/scsi/ufs/ufs_test.c:25:19: fatal error: ../sd.h: No such file or directory
#include <../sd.h>
SOLUTION:
--- Kernel2/drivers/scsi/ufs/ufs_test.c 2014-09-18 14:37:07.000000000 +0800
+++ Kernel/drivers/scsi/ufs/ufs_test.c 2014-11-02 10:18:05.282973816 +0800
@@ -22,7 +22,7 @@
#include <scsi/scsi_device.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_host.h>
-#include <../sd.h>
+#include "../sd.h"
#include "ufshcd.h"
#include "ufs.h"
[error2 : ]
In file included from drivers/video/msm/mdss/mdss_mdp_trace.h:260:0,
from drivers/video/msm/mdss/mdss_mdp.c:61:
include/trace/define_trace.h:79:43: fatal error: ./mdss_mdp_trace.h: No such file or directory
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
SOLUTION:
--- Kernel2/drivers/video/msm/mdss/mdss_mdp_trace.h 2014-09-18 14:37:12.000000000 +0800
+++Kernel/drivers/video/msm/mdss/mdss_mdp_trace.h 2014-11-02 10:31:53.000000000 +0800
@@ -17,7 +17,7 @@
#undef TRACE_SYSTEM
#define TRACE_SYSTEM mdss
#undef TRACE_INCLUDE_PATH
-#define TRACE_INCLUDE_PATH .
+#define TRACE_INCLUDE_PATH ../../../../drivers/video/msm/mdss
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE mdss_mdp_trace
II Build Module
1. Makefile:
VERSION = 3
PATCHLEVEL = 10
SUBLEVEL = 40
EXTRAVERSION = -xxxxxx
EXTRA_CFLAGS=-fno-pic
obj-m += xxxx.o
KDIR=src_to_android_src/source/kernel
PWD := $(shell pwd)
CCPATH := src_to_ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
default:
make -C $(KDIR) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- SUBDIRS=$(PWD) modules
clean:
make -C $(KDIR) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- SUBDIRS=$(PWD) clean
2. VERSION in Makefile:
Kernel version can be found using the following command
$ adb shell
$ cat /proc/version
3. after build, adb push ...ko /sdcard/; adb shell; insmode ...ko
dmesg see log
adb shell; cat /proc/kmsg
Reference:
[1] https://github.com/marco-pratesi/android/blob/master/HOWTOs/Android-Build-Kernel-Modules-HOWTO.txt
[2] http://forum.xda-developers.com/showthread.php?t=1585289
[3] http://forum.xda-developers.com/note-4/snapdragon-dev/sm-n910f-twrp-2-8-1-0-t2923509/page3
[4] https://www.movzio.com/howto/compile-android-kernel-source-beginners-guide-2/
[5] http://forum.xda-developers.com/showthread.php?t=1236576