一、Android內核源碼的下載:
1.Google GIT地址:
$ git clone https://android.googlesource.com/kernel/common.git
$ git clone https://android.googlesource.com/kernel/exynos.git
$ git clone https://android.googlesource.com/kernel/goldfish.git
$ git clone https://android.googlesource.com/kernel/msm.git
$ git clone https://android.googlesource.com/kernel/omap.git
$ git clone https://android.googlesource.com/kernel/samsung.git
$ git clone https://android.googlesource.com/kernel/tegra.git
2.清華服務器地址:
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/common.git
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/exynos.git
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/goldfish.git
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/hikey-linaro.git
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/lk.git
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/msm.git
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/omap.git
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/samsung.git
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/tegra.git
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/x86_64.git
goldfish
項目包含適用於所模擬的平台的內核源代碼。msm
項目包含適用於 ADP1、ADP2、Nexus One、Nexus 4、Nexus 5、Nexus 6、Nexus 5X、Nexus 6P、Nexus 7 (2013)、Pixel 和 Pixel XL 的源代碼,可用作使用 Qualcomm MSM 芯片組的起點。omap
項目用於 PandaBoard 和 Galaxy Nexus,可用作使用 TI OMAP 芯片組的起點。samsung
項目用於 Nexus S,可用作使用 Samsung Hummingbird 芯片組的起點。tegra
項目用於 Xoom、Nexus 7 (2012)、Nexus 9,可用作使用 NVIDIA Tegra 芯片組的起點。exynos
項目包含適用於 Nexus 10 的內核源代碼,可用作使用 Samsung Exynos 芯片組的起點。x86_64
項目包含適用於 Nexus Player 的內核源代碼,可用作使用 Intel x86_64 芯片組的起點。hikey-linaro
項目用於 HiKey 參考板,可用作使用 HiSilicon 620 芯片組的起點。
二、編譯:
1.代碼庫(msm) download之后會在對應的目錄下可以通過 ls -al 查看到 .git , git branch -a 查看所有分支,我手上nexus平板刷的Android5.0的系統,所有選擇以下內核版本:
git checkout remotes/origin/android-msm-flo-3.4-lollipop-release
2.分支代碼下載好之后:
(1)修改Makefile:
#ARCH ?= $(SUBARCH)
#CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
修改為:
ARCH ?= arm
CROSS_COMPILE ?= arm-eabi-
或者 手動設置環境變量:
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=arm-eabi-
export TARGET_PREBUILT_KERNEL=$你的內核目錄/arch/arm/boot/zImage
(特殊 Google Nexus5 這樣設置 export TARGET_PREBUILT_KERNEL=$你的內核目錄/arch/arm/boot/zImage-dtb ,其他平台遇到問題可以兩個都試試)
(2)配置:
kernel/msm/arch/arm/configs/ ,目錄下有很多配置文件
make flo_defconfig ,選擇默認配置,之后會生成 .config
make menuconfig ,可以通過此命令進一步配置內核更新 .config
(3)編譯:
配置好內核后就可以輸入 : make ,等待 zImage 和 zImage-dtb 的生成。
三、打包 zImage 到 boot.img,並刷機:
第一種方法:將編譯產生的新的Android內核文件 android-xxx/kernel/msm/arch/arm/boot/zImage-dtb 替換掉 Android xxx源碼編譯生成的內核文件。重啟Nexus 5手機進入刷機模式 fastboot flashall -w 刷入手機。
第二種方法:解包Android 源碼編譯生成的boot.img文件替換內核文件,具體的就是對Android 源碼編譯后產成的 android-xxx/out/target/product/flo/boot.img 鏡像文件進行解包替換原來的Android內核文件然后進行打包。解包打包boot.img文件的工具比較多,
1.windows下使用bootimg.exe:
-解包命令:bootimg.exe --unpack-bootimg
-打包命令:bootimg.exe --repack-bootimg
2.linux下使用bootimg-tools工具解包打包boot.img文件替換內核(bootimg-tools工具比較好用--推薦)
(1)下載bootimg-tools解包打包工具: git clone https://github.com/pbatard/bootimg-tools.git
(2) make 編譯生成可執行文件
(3) ./unmkbootimg -i boot.img : 解壓原來android系統源碼生成的boot.img,信息如下:
./unmkbootimg -i boot.img kernel written to 'kernel' (6730288 bytes) ramdisk written to 'ramdisk.cpio.gz' (619357 bytes)
To rebuild this boot image, you can use the command: mkbootimg --base 0 --pagesize 2048 --kernel_offset 0x80208000 --ramdisk_offset 0x82200000 --second_offset 0x81100000 --tags_offset 0x80200100 --cmdline 'console=ttyHSL0,115200,n8 androidboot.hardware=flo user_debug=31 msm_rtb.filter=0x3F ehci-hcd.park=3 vmalloc=340M' --kernel kernel --ramdisk ramdisk.cpio.gz -o boot.img
(4)將內核源碼編譯生成的 zImage 或者 zImage-dtb 復制到 上面解壓boot.img的目錄下命名為kernel,使用以上紅色指令進行打包生成新的boot.img,然后刷機:
adb reboot bootloader
fastboot erase boot
fastboot flash boot boot.img
fastboot reboot
如果能正常開機,那就congratulation!!!^v^
PS: 編譯遇到的問題:
(1) warning: argument to 'sizeof' in 'strncmp' call is the same expression as the second source; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]
解決方法:在相應位置的Makefile里加上:EXTRA_CFLAGS += -Wno-sizeof-pointer-memaccess
(2) Can't use 'defined(@array)' (Maybe you should just omit the defined()?) at kernel/timeconst.pl line 373.
解決方法:把 kernel/timeconst.pl 腳本里該行的 defined( ) 去掉即可。
(3)編譯的zImage打包后刷入無法正常開機,試了n久最后把編譯工具 arm-eabi-4.7 換成 arm-eabi-4.6 編出來的正常 - -!
下面提供msm的kernel源碼和編譯工具以及打包工具的下載鏈接:
msm內核源碼:鏈接:http://pan.baidu.com/s/1eStNPVs 密碼:7xj2
編譯工具: 鏈接:http://pan.baidu.com/s/1sloHLAt 密碼:erjn
打包工具:鏈接:http://pan.baidu.com/s/1mimkiG4 密碼:qs0i
-end-