Compile and flash Android 10 source code (QP1A.190711.020) under Mac 10.14.x (Pixel 2 XL)
1. Objectives
Older generations of Windows reverse engineers have been analyzing the Windows kernel one after another, dreaming of taking a look at the Windows source code, but so far they can only see leaked source code from several generations ago. The mobile era is a blessing, the latest version of Android source code is open to you, and you can’t just look at it, you have to touch it.
Now will tell you in detail the process of downloading source code, compiling and flashing the machine over the past week.
- Mac 10.14.6
- jdk 1.8.0_101
- xcode 11.3.1 (11C504)
- Android 10.0 r2 (QP1A.190711.020)
- Pixel 2 XL
2. Analysis
It is said that in Aolai Country in Dongsheng Shenzhou, there is a thing called a shell, which wraps the App tightly, so you can’t even take a look at it, let alone touch it.
But the Android Heart Sutra came, and every move of the shell is running on Android. So if we study the Android Heart Sutra carefully, we may be able to take a look at it, or even touch it.
Download source code
The Android Heart Sutra I studied this time is not the latest one
Prepare hard disk space, about 200G
-
Recommended solution: Buy a 2T mobile hard drive and format it as Mac OS Extended (case-sensitive, journaled)
-
Not recommended: Free up 200G of space for your beloved Xiaobai
1. Create a case-sensitive disk image
$ sudo hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 200g ~/android.dmg
2. Load it
$ sudo hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android
- By default, only 1024 files can be opened at the same time on Mac systems. This limit may be exceeded when compiling Android source code, so this limit needs to be lifted. Add the following content to ~/.bash_profile, and the command will take effect immediately: source ~/.bash_profile
ulimit -S -n 1024
Then put aosp1000r2.7z Unzip to the aosp directory on the hard disk
Download the corresponding Mac SDK. My version is 10.14.
https://github.com/phracker/MacOSX-SDKs/releases
Unzip to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
xz -d MacOSX10.14.sdk.tar.xz
tar xvf MacOSX10.14.sdk.tar
Download the two drivers of Pixel 2XL to the root directory of aosp source code and unzip them
https://developers.google.com/android/drivers
Download two files
google_devices-taimen-qp1a.190711.020-baa894dd.tgz
qcom-taimen-qp1a.190711.020-1d440636.tgz
tar zxvf FileName.tgz
Unzip toaospDirectory, and then execute the decompressed file xx.sh. The generated files are under the vendor directory.
Start Compiling
cd aosp
source build/envsetup.sh
lunch aosp_taimen-userdebug
make -j16
After several hours, the image file will eventually be generated in the aosp/out/target/product/taimen directory:
- system.img: system image
- ramdisk.img: root file system image
- userdata.img: User data image
- recovery.img: recovery image
- boot.img: boot image
- vendor.img: driver image
Great, start flashing
adb reboot bootloader
fastboot flashall -w
Perfectly done, done…
A sad story
I can’t connect to wifi and can’t access the internet. I asked Google and they said the problem was that the persist partition was damaged and I just needed to format it.
I don’t believe him. I downloaded the QP1A.190711.020 factory package of Pixel 2 XL from https://developers.google.com/android/images and found that there was a radio-taimen-g8998-00012-1905270706.img in it , which was not in the code we compiled.
Radio is the communication baseband file. I flashed the factory package first, and then flashed the version we compiled. This time I was able to access the Internet successfully.
I think the problem can be solved by simply flashing the baseband file. Friends who are interested can try it.
fastboot flash radio radio-taimen-g8998-00012-1905270706.img
Pitfalls
-
Compile error
FAIL: TestGlobEscapes //* (0.00s) glob_test.go:562: incorrect matches list: glob_test.go
Comment out the lines of glob_test.go and fs_test.go in the aosp/build/blueprint/Blueprints file
- Install the xcode command line
xcode-select –install
Summarize
The Android source code is already very easy to configure. The compilation on Ubuntu and Mac is very smooth. The only problem is flashing the firmware. Many online tutorials do not explain the flashing steps in detail. The idea provided is to compare it with the official factory package and make up for what is missing.
Scientific Internet access is a prerequisite for studying Android. ( ̄▽ ̄)ゞ