编译安卓系统6.0.1_for_Nexus5x_编译内核源码以及系统源码
前言
源码已经在香港的服务器下载完毕,并且已经下载到本地了,接下来要做的事儿就是修改文件源代码并复制到Ubuntu16.04的虚拟机里面进行编译.并且刷机.
我的设备是:Nexus 5x
编译的安卓源码版本为:6.0.1_r67
内核版本:3.10.73 remotes/origin/android-msm-bullhead-3.10-marshmallow-dr1.6
编译的系统版本为: userdebug
一、复制文件修改源码
1.复制源码文件丢到虚拟机中
2.补充一下服务器上打包源码目录
#在存放源码和内核源码根目录执行压缩,过滤了隐藏文件 类似.git .repo这种,因为我们后续不需要升级代码
#所以我们不需要版本控制器的文件,也是最大的,占了100G。源码才十几个G
zip -r AndroidSource6.0r67.zip android-6.0.1_r67/ kernel/ -x "*/\.*" -x "\.*"
3.修改内核调试标志绕过反调试(TracerPid设置为0的死值)
//要修改的文件:
//kernel/msm/fs/proc/base.c
//kernel/msm/fs/proc/array.c
//修改点:
//base.c proc_pid_wchan 函数 第285行改成如下:
static int proc_pid_wchan(struct task_struct *task, char *buffer)
{
unsigned long wchan;
char symname[KSYM_NAME_LEN];
wchan = get_wchan(task);
if (lookup_symbol_name(wchan, symname) < 0)
if (!ptrace_may_access(task, PTRACE_MODE_READ))
return 0;
else
return sprintf(buffer, "%lu", wchan);
/* else
return sprintf(buffer, "%s", symname); 这里改为*/
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 原数据:"T (stopped)" */
"S (sleeping)", /* 8 原数据:"t (tracing stop)" */
"Z (zombie)", /* 16 */
"X (dead)", /* 32 */
"x (dead)", /* 64 */
"K (wakekill)", /* 128 */
"W (waking)", /* 256 */
"P (parked)", /* 512 */
};
//array.c第187行改成如下:
static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *p)
{
struct user_namespace *user_ns = seq_user_ns(m);
struct group_info *group_info;
int g;
struct fdtable *fdt = NULL;
const struct cred *cred;
pid_t ppid, tpid;
rcu_read_lock();
ppid = pid_alive(p) ?
task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
tpid = 0;
if (pid_alive(p)) {
struct task_struct *tracer = ptrace_parent(p);
if (tracer)
tpid = task_pid_nr_ns(tracer, ns);
}
cred = get_task_cred(p);
seq_printf(m,
"State:\t%s\n"
"Tgid:\t%d\n"
"Pid:\t%d\n"
"PPid:\t%d\n"
"TracerPid:\t%d\n"
"Uid:\t%d\t%d\t%d\t%d\n"
"Gid:\t%d\t%d\t%d\t%d\n",
get_task_state(p),
task_tgid_nr_ns(p, ns),
pid_nr_ns(pid, ns),
ppid, /*tpid*/0, //修改这里
from_kuid_munged(user_ns, cred->uid),
from_kuid_munged(user_ns, cred->euid),
from_kuid_munged(user_ns, cred->suid),
from_kuid_munged(user_ns, cred->fsuid),
from_kgid_munged(user_ns, cred->gid),
from_kgid_munged(user_ns, cred->egid),
from_kgid_munged(user_ns, cred->sgid),
from_kgid_munged(user_ns, cred->fsgid));
task_lock(p);
if (p->files)
fdt = files_fdtable(p->files);
seq_printf(m,
"FDSize:\t%d\n"
"Groups:\t",
fdt ? fdt->max_fds : 0);
rcu_read_unlock();
group_info = cred->group_info;
task_unlock(p);
for (g = 0; g < group_info->ngroups; g++)
seq_printf(m, "%d ",
from_kgid_munged(user_ns, GROUP_AT(group_info, g)));
put_cred(cred);
seq_putc(m, '\n');
}
// 修改完成后,按下面步骤编译内核,刷入系统
4.内核代码修改完毕开始编译内核文件二、编译内核文件以及安卓源码
1.编译内核源码
#需要下载gcc编译链
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.8
#并且配置环境变量
#文件解压 保证跟内核源码目录同级,终端回车,或者 vim ~/.bashrc 加入尾部
export ARCH=arm64
export SUBARCH=arm64
export CROSS_COMPILE=aarch64-linux-android-
export PATH=$PATH:~/asop/WORKING_DIRECTORY/aarch64-linux-android-4.8/bin:$PATH
make bullhead_defconfig
make -j 8
#这里如果报错如下信息,请更换python版本到2.7在执行
File "/root/asop/WORKING_DIRECTORY/kernel/msm/scripts/gcc-wrapper.py", line 65
print "error, forbidden warning:", m.group(2)
^
SyntaxError: invalid syntax
warning: (PCI_MSM && AMD_IOMMU) selects PCI_MSI which has unmet direct dependencies (PCI && ARCH_SUPPORTS_MSI)
warning: (SND_SOC_APQ8074 && SND_SOC_MSM8994) selects SND_SOC_MSM_HDMI_CODEC_RX which has unmet direct dependencies (SOUND && !M68K && !UML && SND && SND_SOC && FB_MSM_MDSS_HDMI_PANEL && (SND_SOC_MSM8974 || SND_SOC_APQ8084 || SND_SOC_MSM8994))
warning: (ARCH_MSM) selects DEVFREQ_GOV_MSM_BW_HWMON which has unmet direct dependencies (PM_DEVFREQ && (ARCH_MSM_KRAIT || ARCH_MSM_BIMC_BWMON))
warning: (PCI_MSM && AMD_IOMMU) selects PCI_MSI which has unmet direct dependencies (PCI && ARCH_SUPPORTS_MSI)
warning: (SND_SOC_APQ8074 && SND_SOC_MSM8994) selects SND_SOC_MSM_HDMI_CODEC_RX which has unmet direct dependencies (SOUND && !M68K && !UML && SND && SND_SOC && FB_MSM_MDSS_HDMI_PANEL && (SND_SOC_MSM8974 || SND_SOC_APQ8084 || SND_SOC_MSM8994))
warning: (ARCH_MSM) selects DEVFREQ_GOV_MSM_BW_HWMON which has unmet direct dependencies (PM_DEVFREQ && (ARCH_MSM_KRAIT || ARCH_MSM_BIMC_BWMON))
#
# configuration written to .config
#
root@ubuntu:~/asop/WORKING_DIRECTORY/kernel/msm# make -j 8
2.内核编译成功.
2.系统源码编译.
a).编译完内核后,内核生成的路径为:kernel/msm/arch/arm/boot目录下的zImage-dtb文件(nexus 5x 是这个文件,nexus 4是zImage文件,请注意别弄错了),把该文件复制到源码下的device/lge/bullhead-kernel夹下
b).我的编译环境依赖还有jdk都是配置好的,直接执行编译命令就可以了,我在上篇文章就配置好了.#在art/build/Android.common_build.mk中 75行左右
ifneq ($(WITHOUT_HOST_CLANG),true)
#改为
ifeq ($(WITHOUT_HOST_CLANG),false)
#准备编译环境
source build/envsetup.sh
#清空上次编译缓存:
make clobber
# 选择编译目标,如果列表中没有与你手机对应的编译目标,可以用choosecombo命令定制;
lunch
#Nexus 5x的编译为 aosp_bullhead-userdebug 选择18
c).开始编译源码.
#make版本切到3.8,自行百度下载
#编译后默认在/usr/local/bin/make 使用ln -s /usr/local/bin/make /usr/bin/make3.8
#开始多进程编译 12的取值取决于你的电脑配置,可以通过nproc命令查看
root@ubuntu:~/asop/WORKING_DIRECTORY/android-6.0.1_r67# nproc
12
root@ubuntu:~/asop/WORKING_DIRECTORY/android-6.0.1_r67# make3.8 -j12
d).系统编译完成.
e).系统编译完成,镜像目录,五个文件复制出来.#//开机状态下,adb可用时,执行顺序如下,进入手机bootloader
adb reboot bootloader
#//开始刷机
fastboot flash boot boot.img
fastboot flash system system.img
fastboot flash cache cache.img
fastboot flash userdata userdata.img
fastboot flash recovery recovery.img
#//手机重启
fastboot reboot
f).我是复制到windows下刷入的.
g).开机状态.型号AOSP on BullHead最下方的版本号也是userdebug