1、下载编译
新建kernel目录
~/srcAndroid/src4.4.4_r1/kernel目录下,输入命令:
seven@ThinkPad:~/srcAndroid/src4.4.4_r1/kernel$ git clone https://aosp.tuna.tsinghua.edu.cn/kernel/msm.git
下载msm版本的内核,下载完毕后,有文件夹msm
cd msm git branch -a git checkout remotes/origin/android-msm-hammerhead-3.4-kitkat-mr2 export PATH=$PATH:/home/seven/srcAndroid/src4.4.4_r1/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7/bin:$PATH
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=arm-eabi-
make hammerhead_defconfig
//make menuconfig
make -j4
我是用的ubuntu16.04 64位系统
//编译内核linux-3.0.1?
出现如下错误:
Can't use 'defined(@array)' (Maybe you should just omit the defined()?) at kernel/timeconst.pl line 373.
/opt/ARM/mini6410/linux/linux-2.6.38/kernel/Makefile:140: recipe for target 'kernel/timeconst.h' failed
make[1]: *** [kernel/timeconst.h] Error 255
Makefile:916: recipe for target 'kernel' failed
make: *** [kernel] Error 2
解决方法:
这样处理
删除
@val = @{$canned_values{$hz}};
if (!defined(@val)) {
@val = compute_values($hz);
}
output前面加入
$cv = $canned_values{$hz};
@val = defined($cv) ? @$cv : compute_values($hz);
make -j4 成功!
生成的内核文件为zImage-dtb
seven@ThinkPad:~/srcAndroid/src4.4.4_r1/kernel/msm/arch/arm/boot$ ls -lt
total 31120
-rw-rw-r-- 1 seven seven 8405832 6月 19 15:00 zImage-dtb
-rwxrwxr-x 1 seven seven 7011504 6月 19 15:00 zImage
drwxrwxr-x 2 seven seven 4096 6月 19 15:00 compressed
-rwxrwxr-x 1 seven seven 17780964 6月 19 15:00 Image
-rw-rw-r-- 1 seven seven 174112 6月 19 12:50 msm8974-hammerhead-rev-f.dtb
-rw-rw-r-- 1 seven seven 174160 6月 19 12:50 msm8974-hammerhead-rev-a.dtb
-rw-rw-r-- 1 seven seven 174164 6月 19 12:50 msm8974-hammerhead-rev-bn.dtb
-rw-rw-r-- 1 seven seven 174196 6月 19 12:50 msm8974-hammerhead-rev-b.dtb
-rw-rw-r-- 1 seven seven 174332 6月 19 12:50 msm8974-hammerhead-rev-c.dtb
-rw-rw-r-- 1 seven seven 174516 6月 19 12:50 msm8974-hammerhead-rev-11j.dtb
-rw-rw-r-- 1 seven seven 174332 6月 19 12:50 msm8974-hammerhead-rev-10.dtb
-rw-rw-r-- 1 seven seven 174516 6月 19 12:50 msm8974-hammerhead-rev-11.dtb
drwxrwxr-x 5 seven seven 12288 6月 19 12:44 dts
-rw-rw-r-- 1 seven seven 1274 6月 19 12:44 install.sh
drwxrwxr-x 2 seven seven 4096 6月 19 12:44 bootp
-rw-rw-r-- 1 seven seven 3641 6月 19 12:44 Makefile
可以替换android源码的对应文件(目录如下),重新编译android源码,刷入手机,或者利用下文中的方法单独替换内核文件,刷入手机
seven@ThinkPad:~/srcAndroid/src4.4.4_r1/device/lge/hammerhead-kernel$ ls vmlinux.bz2 zImage-dtb
2、下载工具并替换内核
/home/seven/srcAndroid/src4.4.4_r1/kernel/msm/目录下:
git clone https://github.com/pbatard/bootimg-tools.git cd bootimg-tools make
在mkbootimg目录下有两个可执行文件:
unmkbootimg和mkbootimg
将mkbootimg加入path,方便使用
export PATH=$PATH:/home/seven/srcAndroid/src4.4.4_r1/kernel/msm/bootimg-tools/mkbootimg:$PATH
将原来编译好的boot.img解压
seven@ThinkPad:~/srcAndroid/src4.4.4_r1/kernel/msm/bootimg-tools/mkbootimg$ unmkbootimg -i ~/srcAndroid/src4.4.4_r1/out/target/product/hammerhead/boot.img kernel written to 'kernel' (8405280 bytes) ramdisk written to 'ramdisk.cpio.gz' (498998 bytes) To rebuild this boot image, you can use the command: mkbootimg --base 0 --pagesize 2048 --kernel_offset 0x00008000 --ramdisk_offset 0x02900000 --second_offset 0x00f00000 --tags_offset 0x02700000 --cmdline 'console=ttyHSL0,115200,n8 androidboot.hardware=hammerhead user_debug=31 maxcpus=2 msm_watchdog_v2.enable=1' --kernel kernel --ramdisk ramdisk.cpio.gz -o
~/srcAndroid/src4.4.4_r1/out/target/product/hammerhead/boot.img
用编译好的内核文件替换掉,上面解压出来的kernel文件
seven@ThinkPad:~/srcAndroid/src4.4.4_r1/kernel/msm/bootimg-tools/mkbootimg$ cp ~/srcAndroid/src4.4.4_r1/kernel/msm/arch/arm/boot/zImage-dtb kernel
打包生成新的boot.img
seven@ThinkPad:~/srcAndroid/src4.4.4_r1/kernel/msm/bootimg-tools/mkbootimg$ mkbootimg --base 0 --pagesize 2048 --kernel_offset 0x00008000 --ramdisk_offset 0x02900000 --second_offset 0x00f00000 --tags_offset 0x02700000 --cmdline 'console=ttyHSL0,115200,n8 androidboot.hardware=hammerhead user_debug=31 maxcpus=2 msm_watchdog_v2.enable=1' --kernel kernel --ramdisk ramdisk.cpio.gz -o
~/srcAndroid/src4.4.4_r1/out/target/product/hammerhead/myboot.img
3、刷入手机
seven@ThinkPad:~/srcAndroid/src4.4.4_r1/out/host/linux-x86/bin$ ./adb reboot bootloader seven@ThinkPad:~/srcAndroid/src4.4.4_r1/out/host/linux-x86/bin$ sudo ./fastboot devices 072ba3800ae5fd9c fastboot seven@ThinkPad:~/srcAndroid/src4.4.4_r1/out/host/linux-x86/bin$ sudo ./fastboot flash boot /home/seven/srcAndroid/src4.4.4_r1/out/target/product/hammerhead/myboot.img seven@ThinkPad:~/srcAndroid/src4.4.4_r1/out/host/linux-x86/bin$ sudo ./fastboot reboot
4、修改源码,过反调试
修改源码文件:
kernel/msm/fs/proc/base.c
kernel/msm/fs/proc/array.c
要修改对以下文件的写入
Status,stat,
修改点:
base.c 第285行改成如下:
else {
if (strstr(symname, "trace")) {
return sprintf(buffer, "%s", "sys_epoll_wait");
}
return sprintf(buffer, "%s", symname);
}
array.c第134行改成如下:
static const char * const task_state_array[] = {
"R (running)", /* 0 */
"S (sleeping)", /* 1 */
"D (disk sleep)", /* 2 */
"S (sleeping)", /* 4 */
"S (sleeping)", /* 8 */
"Z (zombie)", /* 16 */
"X (dead)", /* 32 */
"x (dead)", /* 64 */
"K (wakekill)", /* 128 */
"W (waking)", /* 256 */
};
array.c第187行改成如下:
"Gid: %d %d %d %d
",
get_task_state(p),
task_tgid_nr_ns(p, ns),
pid_nr_ns(pid, ns),
ppid, /*tpid*/0,
cred->uid, cred->euid, cred->suid, cred->fsuid,
cred->gid, cred->egid, cred->sgid, cred->fsgid);
修改完成后,按上面步骤编译内核,刷入系统