Android kernel build from source code and from prebuilt
2017-06-16 20:10
1146 查看
When building android project, we can use prebuilt linux kernel or kernel source code.
About how to add new product in AOSP and android build steps,please refer to Android build
tips andAndroid Makefile 具体是 如何识别 TARGET_PRODUCT 变量
I want to use an example to elaborate the build step of a product and how to build kernel.
Example: Add a new flounder device on Nougat. Htc/flounder is already on Nougat, but I want to use different configuration to build it. So I define a new flounder product and add different configurations.
1. Define
2. Define PRODUCT_MAKEFILES
3. When executing "lunch
this file, you can define KERNEL_SRC_DIR to provide kernel source code path if you want to build kernel from source code.
You can also define TARGET_PREBUILT_KERNEL to provider prebuilt kernel path if you want to build kernel from prebuilt binary.
In
this file, there is another important definition
PRODUCT_DEVICE. It determine where to find
BoardConfig.mk and AndroidBoard.mk
4.
5.
6. AndroidKernel.mk (device/htc/flounder/AndroidKernel.mk) ----------
7.
About how to add new product in AOSP and android build steps,please refer to Android build
tips andAndroid Makefile 具体是 如何识别 TARGET_PRODUCT 变量
I want to use an example to elaborate the build step of a product and how to build kernel.
Example: Add a new flounder device on Nougat. Htc/flounder is already on Nougat, but I want to use different configuration to build it. So I define a new flounder product and add different configurations.
1. Define
vendorsetup.sh (device/company/tablet/products/vendorsetup.sh)-------------use
print_lunch_menu command to check
add_lunch_combo firetab_flounder-userdebug
2. Define PRODUCT_MAKEFILES
in device/company/tablet/products/flounder/AndroidProducts.mk
9PRODUCT_MAKEFILES := \ 10 $(LOCAL_DIR)/firetab_flounder.mk
3. When executing "lunch
firetab_flounder-userdebug" command, build system will searching
firetab_flounder.mk and execute it. ----use "make dump-products"
to check
In
this file, you can define KERNEL_SRC_DIR to provide kernel source code path if you want to build kernel from source code.
You can also define TARGET_PREBUILT_KERNEL to provider prebuilt kernel path if you want to build kernel from prebuilt binary.
9# Setup to build custom kernel 10KERNEL_CFG_NAME ?= flounder 11KERNEL_SRC_DIR ?= kernel/htc/flounder 12TARGET_KERNEL_ARCH ?= arm64 13KERNEL_OUT_DIR ?= $(PRODUCT_OUT)/linux/kernel ----------------- $(PRODUCT_OUT)=out/target/product/flounder32 14 15# Check for availability of kernel source 16ifneq ($(wildcard $(KERNEL_SRC_DIR)/Makefile),) 17 # Give precedence to TARGET_PREBUILT_KERNEL 18 ifeq ($(TARGET_PREBUILT_KERNEL),) 19 TARGET_KERNEL_BUILT_FROM_SOURCE := true 20 endif 21endif 25 26PRODUCT_NAME := firetab_flounder 27PRODUCT_DEVICE := flounder32
23# fosmod_nexus_support begin 24ifneq ($(TARGET_KERNEL_BUILT_FROM_SOURCE), true) 25ifeq ($(TARGET_PREBUILT_KERNEL),) 26ifeq ($(USE_SVELTE_KERNEL), true) 27LOCAL_KERNEL := device/htc/flounder_svelte-kernel/Image.gz-dtb 28else 29LOCAL_KERNEL := device/htc/flounder-kernel/Image.gz-dtb 30endif # USE_SVELTE_KERNEL 31else 32LOCAL_KERNEL := $(TARGET_PREBUILT_KERNEL) 33endif 34endif # $(TARGET_KERNEL_BUILT_FROM_SOURCE), true) 35# fosmod_nexus_support end
In
this file, there is another important definition
PRODUCT_DEVICE. It determine where to find
BoardConfig.mk and AndroidBoard.mk
4.
BoardConfig.mk (device/htc/flounder/flounder32/BoardConfig.mk) -----
use "printconfig" to check
3TARGET_CPU_ABI := armeabi-v7a 4TARGET_CPU_ABI2 := armeabi 5TARGET_ARCH := arm 6TARGET_ARCH_VARIANT := armv7-a-neon 7TARGET_CPU_VARIANT := cortex-a15 8 9TARGET_2ND_ARCH := 10TARGET_2ND_ARCH_VARIANT := 11TARGET_2ND_CPU_ABI := 12TARGET_2ND_CPU_ABI2 := 13TARGET_2ND_CPU_VARIANT :=
5.
AndroidBoard.mk (device/htc/flounder/flounder32/AndroidBoard.mk)
28include $(LOCAL_PATH)/../AndroidKernel.mk
6. AndroidKernel.mk (device/htc/flounder/AndroidKernel.mk) ----------
build from source code
10ifeq ($(TARGET_KERNEL_BUILT_FROM_SOURCE),true) 11 12# Force using bash as a shell, otherwise, on Ubuntu, dash will break some 13# dependency due to its bad handling of echo \1 14MAKE += SHELL=/bin/bash 15 16ifeq ($(KERNEL_CFG_NAME),) 17$(error cannot build kernel, config not specified) 18endif 19 20ifeq ($(KERNEL_OUT_DIR),) 21$(error cannot build kernel, no out dir specficied) 22endif 23 24KERNEL_TOOLCHAIN_ARCH := arm64 25 26KERNEL_EXTRA_FLAGS := ANDROID_TOOLCHAIN_FLAGS="-mno-android -Werror" 27KERNEL_CROSS_COMP := aarch64-linux-android- 28 29KERNEL_CCACHE :=$(firstword $(TARGET_CC)) 30KERNEL_PATH := $(ANDROID_BUILD_TOP)/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin 31ifeq ($(notdir $(KERNEL_CCACHE)),ccache) 32KERNEL_CROSS_COMP := "ccache $(KERNEL_CROSS_COMP)" 33KERNEL_PATH := $(KERNEL_PATH):$(ANDROID_BUILD_TOP)/$(dir $(KERNEL_CCACHE)) 34endif 35 36#remove time_macros from ccache options, it breaks signing process 37KERNEL_CCSLOP := $(filter-out time_macros,$(subst $(comma), ,$(CCACHE_SLOPPINESS))) 38KERNEL_CCSLOP := $(subst $(space),$(comma),$(KERNEL_CCSLOP)) 39 40KERNEL_CONFIG := $(KERNEL_OUT_DIR)/.config 41KERNEL_SAVE_DEFCONFIG := $(KERNEL_OUT_DIR)/defconfig 42KERNEL_BLD_FLAGS := \ 43 ARCH=$(TARGET_KERNEL_ARCH) \ 44 $(KERNEL_EXTRA_FLAGS) 45 46KERNEL_BLD_FLAGS :=$(KERNEL_BLD_FLAGS) \ 47 O=../../../$(KERNEL_OUT_DIR) \ 48 49KERNEL_BLD_ENV := CROSS_COMPILE=$(KERNEL_CROSS_COMP) \ 50 PATH=$(KERNEL_PATH):$(PATH) \ 51 CCACHE_SLOPPINESS=$(KERNEL_CCSLOP) 52 53KERNEL_DEFCONFIG ?= $(KERNEL_SRC_DIR)/arch/arm64/configs/$(KERNEL_CFG_NAME)_defconfig 54KERNEL_VERSION_FILE := $(KERNEL_OUT_DIR)/include/config/kernel.release 55KERNEL_BZIMAGE := $(PRODUCT_OUT)/kernel 56 57$(KERNEL_CONFIG): $(KERNEL_DEFCONFIG) 58 $(hide) echo Regenerating kernel config $(KERNEL_OUT_DIR) 59 $(hide) mkdir -p $(KERNEL_OUT_DIR) 60 $(hide) $(KERNEL_BLD_ENV) $(MAKE) -C $(KERNEL_SRC_DIR) $(KERNEL_BLD_FLAGS) $(notdir $(KERNEL_DEFCONFIG)) 61 62ifeq (,$(filter build_kernel-nodeps,$(MAKECMDGOALS))) 63$(KERNEL_BZIMAGE): $(MINIGZIP) 64endif 65 66$(KERNEL_BZIMAGE): $(KERNEL_CONFIG) 67 $(hide) $(KERNEL_BLD_ENV) $(MAKE) -C $(KERNEL_SRC_DIR) $(KERNEL_BLD_FLAGS) 68 $(hide) cp -f $(KERNEL_OUT_DIR)/arch/arm64/boot/Image.gz-dtb $@ 69 70clean_kernel: 71 $(hide) $(KERNEL_BLD_ENV) $(MAKE) -C $(KERNEL_SRC_DIR) $(KERNEL_BLD_FLAGS) clean 72 73menuconfig xconfig gconfig: $(KERNEL_CONFIG) 74 $(hide) $(KERNEL_BLD_ENV) $(MAKE) -C $(KERNEL_SRC_DIR) $(KERNEL_BLD_FLAGS) $@ 75 $(hide) $(KERNEL_BLD_ENV) $(MAKE) -C $(KERNEL_SRC_DIR) $(KERNEL_BLD_FLAGS) savedefconfig 76 $(hide) cp -f $(KERNEL_SAVE_DEFCONFIG) $(KERNEL_DEFCONFIG) 77 $(hide) echo =========== 78 $(hide) echo $(KERNEL_DEFCONFIG) has been modified ! 79 $(hide) echo =========== 80 81TAGS_files := TAGS 82tags_files := tags 83gtags_files := GTAGS GPATH GRTAGS GSYMS 84cscope_files := $(addprefix cscope.,files out out.in out.po) 85 86TAGS tags gtags cscope: $(KERNEL_CONFIG) 87 $(hide) $(KERNEL_BLD_ENV) $(MAKE) -C $(KERNEL_SRC_DIR) $(KERNEL_BLD_FLAGS) $@ 88 $(hide) rm -f $(KERNEL_SRC_DIR)/$($@_files) 89 $(hide) cp -fs $(addprefix `pwd`/$(KERNEL_OUT_DIR)/,$($@_files)) $(KERNEL_SRC_DIR)/ 90 91 92define build_kernel_module 93$(error Use of external Kernel modules is not allowed) 94endef 95 96.PHONY: menuconfig xconfig gconfig 97.PHONY: $(KERNEL_BZIMAGE)------------------ target passed from build/core/Makefile INSTALLED_KERNEL_TARGET 98.PHONY: build_kernel build_kernel-nodeps 99 100$(PRODUCT_OUT)/boot.img: build_kernel -------------------- pack KERNEL_BZIMAGE into boot.img in build/core/Makefile 102endif #TARGET_KERNEL_BUILT_FROM_SOURCE
7.
build from prebuilt binary
58ifneq ($(LOCAL_KERNEL),) 59PRODUCT_COPY_FILES += $(LOCAL_KERNEL):kernel 60endif
相关文章推荐
- How to build NCL and NCAR Graphics from source code
- Build update.zip from your own android source code
- How to build and debug android source code
- how to build and install vim from source code
- Build Android-x86 ICS 4 Virtualbox from Google Virtualbox Target and Intel Kernel 编译体验
- How to build NCL and NCAR Graphics from source code
- Dowload and compile android source code implemented by qualcomm
- CODE 28: Construct Binary Tree from Preorder and Inorder Traversal
- Android: How to download the latest zip Android Source Code easily and using it in Intellij
- Android: Simplified source code for parsing and working with XML data and web services in Android
- [leet code] Construct Binary Tree from Preorder and Inorder Traversal
- About android source code and resource
- Compile android source and kernel for emulator in Debian
- ubuntu 12.04 x64 build android source code
- 【Android-Source】Install Git and repo to get android source code
- Advanced daily build - Auto update build number and lable the source code and bin output
- How to build the Robotics Library from source code on Windows
- Build OpenSolaris from source code
- Atlas Control Toolkit and Source Code for the Build-in Asp.Net 2.0 Providers
- Repo and Git, to get Android source code.