这篇文章上次修改于 839 天前,可能其部分内容已经发生变化,如有疑问可询问作者。
本文属于错误示范,请参考eBPF on Android之打补丁和编译内核修正版进行内核修改与编译
虽然不知道当时怎么编译通过的...但现在看这样编译肯定不对
?
较新版本的安卓内核编译不需要预先编译完整系统,可以单独编译
具体怎么才是较新呢?请参考下面的链接内容
说明
- 编译环境 kali-linux-2021.1-vmware-amd64
- 编译目标 android-msm-crosshatch-4.9-pie-qpr2
环境准备
sudo apt-get install bc
sudo apt-get install libssl-dev
sudo apt-get install gcc-arm-linux-gnueabi
过程
安装repo
调整python优先级
update-alternatives --install /usr/bin/python python /usr/bin/python2 100
update-alternatives --install /usr/bin/python python /usr/bin/python3 150
repo init
repo init -u git://mirrors.ustc.edu.cn/aosp/kernel/manifest -b android-msm-crosshatch-4.9-pie-qpr2 --depth=1
同步代码
repo sync -c -j8
重点
- 设置swap,我内存给的16G,这里swap也给16G,如果内存不够大可能在编译至
vmlinux.o
时失败 - 有关信息可参考 https://blog.seeflower.dev/archives/13/
sudo dd if=/dev/zero of=/swapfile bs=1k count=16384000
sudo mkswap /swapfile
sudo swapon /swapfile
编译内核
build/build.sh
TIPS 如果出现assembler command failed with exit code 1
,请参考后面的问题部分
问题
遇到下列问题,记录解决办法
没有安装libssl-dev
/home/kali/Desktop/0508/private/msm-google/scripts/sign-file.c:25:10: fatal error: 'openssl/opensslv.h' file not found
安装之
sudo apt-get install libssl-dev
没有安装bc
/bin/sh: 1: bc: not found
安装之
sudo apt install bc
unrecognized option '-mfloat-abi=soft'
clang-5.0: error: assembler command failed with exit code 1 (use -v to see invocation)
参考 https://github.com/mapsme/omim/issues/3607
编辑private/msm-google/arch/arm64/kernel/vdso32/Makefile
去除第八行的-no-integrated-as
unrecognised emulation mode: armelf_linux_eabi
/..//bin/ld: unrecognised emulation mode: armelf_linux_eabi
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu elf_l1om elf_k1om i386pep i386pe
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
安装gcc-arm-linux-gnueabi
sudo apt-get install gcc-arm-linux-gnueabi
结果
最终编译成功输出如下
make: Leaving directory '/home/kali/Desktop/0508/out/android-msm-bluecross-4.9/private/msm-google'
Copying kernel UAPI headers to /home/kali/Desktop/0508/out/android-msm-bluecross-4.9/dist/kernel-uapi-headers.tar.gz
========================================================
Copying kernel headers to /home/kali/Desktop/0508/out/android-msm-bluecross-4.9/dist/kernel-headers.tar.gz
~/Desktop/0508/private/msm-google ~/Desktop/0508
~/Desktop/0508
========================================================
Copying modules files
lib/modules/4.9.124-g86541eee-dirty_audio-g4360e08/extra/wlan.ko
lib/modules/4.9.124-g86541eee-dirty_audio-g4360e08/kernel/drivers/input/touchscreen/stm/ftm5.ko
lib/modules/4.9.124-g86541eee-dirty_audio-g4360e08/kernel/drivers/input/touchscreen/sec_ts/sec_touch.ko
lib/modules/4.9.124-g86541eee-dirty_audio-g4360e08/kernel/techpack/audio/soc/pinctrl-wcd.ko
lib/modules/4.9.124-g86541eee-dirty_audio-g4360e08/kernel/techpack/audio/ipc/wcd-dsp-glink.ko
lib/modules/4.9.124-g86541eee-dirty_audio-g4360e08/kernel/techpack/audio/asoc/snd-soc-sdm845-max98927.ko
lib/modules/4.9.124-g86541eee-dirty_audio-g4360e08/kernel/techpack/audio/asoc/snd-soc-sdm845.ko
lib/modules/4.9.124-g86541eee-dirty_audio-g4360e08/kernel/techpack/audio/asoc/codecs/wcd934x/snd-soc-wcd934x.ko
lib/modules/4.9.124-g86541eee-dirty_audio-g4360e08/kernel/techpack/audio/asoc/codecs/snd-soc-wcd-spi.ko
lib/modules/4.9.124-g86541eee-dirty_audio-g4360e08/kernel/techpack/audio/asoc/codecs/wcd-core.ko
lib/modules/4.9.124-g86541eee-dirty_audio-g4360e08/kernel/techpack/audio/asoc/codecs/snd-soc-wcd9xxx.ko
lib/modules/4.9.124-g86541eee-dirty_audio-g4360e08/kernel/techpack/audio/asoc/codecs/snd-soc-cs35l36.ko
========================================================
Copying unstripped module files for debugging purposes (not loaded on device)
========================================================
Files copied to /home/kali/Desktop/0508/out/android-msm-bluecross-4.9/dist
没有评论