The environment
PC: Kali 2021.2 Phone: Nexus 5, Android 6.0.1 GCC: 4.8 Kernel version: 3.4.0
Docker related
See docker to compile Android source code
Download the kernel source code
Cloning of warehouse
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/msm.git
Copy the code
Query branch
The kernel version is 3.4.0-G32AC281, where the short commit ID is 32AC281
git branch -r --contains <short commit id>
Copy the code
The results are as follows:
Origin/android - among MSM - hammerhead - 3.4 - marshmallow origin/android - among MSM - hammerhead - 3.4 - the marshmallow - mr2 Origin/android - among MSM - hammerhead - 3.4 - the marshmallow - mr3Copy the code
Check out the branch
Note: the MR3 version is buggy and cannot query Wifi. The last branch used is Android-mSM-Hammerhead-3.4-marshmallow
Git checkout -b android-msm-hammerhead-3.4-marshmallow origin/android-msm-hammerhead-3.4-marshmallowCopy the code
Enter the bash container as user root
Attach directly using VSCode’s Docker plug-in, or execute the following command
cid=$(docker ps | grep aosp | cut -d" " -f1) && echo $cid
docker exec --privileged -u root -it $cid bash
Copy the code
Configure the GCC
Configure environment variables directly
Find the GCC compiler location in the source code and add PATH to it:
The export PATH = / aosp/android - 6.0.0 _r1 prebuilts/GCC/Linux x86 / arm/arm eabi - 4.8 / bin: $PATHCopy the code
No Android source code: manual download configuration
Download GCC
Git clone https://aosp.tuna.tsinghua.edu.cn/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8Copy the code
Configuring environment Variables
The export PATH = / aosp/arm eabi - 4.8 / bin: $PATHCopy the code
Compile the kernel
Switch to the kernel directory and run the following command:
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=arm-eabi-
make hammerhead_defconfig
cpus=$(grep ^processor /proc/cpuinfo | wc -l)
make -j$[2*$cpus]
Copy the code
Use another compiler
There is no need to compile the kernel with a higher version of the compiler, to be tested…
Using GCC4.9 (not tested)
Similarly, add to PATH and compile
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=arm-linux-androideabi-
make hammerhead_defconfig
cpus=$(grep ^processor /proc/cpuinfo | wc -l)
make -j$[2*$cpus]
Copy the code
Using Clang (not tested)
Android’s GCC 4.9 has been deprecated in favor of Clang, and will be removed from Android in January 2020 as per the below timeline.
Android GCC 4.9 has been deprecated and replaced with Clang
Packaging image
Android source code: directly compiled generation
Open the source directory and do the following:
source ./build/envsetup.sh
lunch aosp_hammerhead-userdebug
Copy the code
Then set the kernel file location (default: /aosp/ Android-6.0.0_R1 /device/ lGE/zimage-dtb)
export TARGET_PREBUILT_KERNEL=/aosp/kernel/msm/arch/arm/boot/zImage-dtb
Copy the code
Then you can pack it
cpus=$(grep ^processor /proc/cpuinfo | wc -l)
make -j$[2*$cpus]
Copy the code
Generated by the image in the out/target/produuct/hammerhead/boot. Img
No Android source code: manual repackaging
Use mkbootimg and unmkbootimg to repackage the image
other
Modify android kernel source through State TracerPid wchan reverse debugging
reference
Android reverse debugging – start with source code
The Nexus5 recompiles the phone’s kernel, and the phone’s WiFi cannot work properly
Android DTB file location _Android kernel source code compiled to the brush