/myproduct.mk
# This file should set PRODUCT_MAKEFILES to a list of product makefiles
# to expose to the build system. LOCAL_DIR will already be set to
# the directory containing this file.
# This file may not rely on the value of any variable other than
# LOCAL_DIR; do not use any conditionals, and do not look up the
# value of any variable that isn't set in this file or in a file that
# it includes.
PRODUCT_MAKEFILES := \
$(LOCAL_DIR)/myproduct.mk
# Inherit the full_base and device configurations
$(call inherit-product, $(SRC_TARGET_DIR)/product/
= myproduct
# Inherit the full_base and device configurations
$(call inherit-product, $(SRC_TARGET_DIR)/product/full_base.mk)
# Overrides
PRODUCT_NAME := myproduct
PRODUCT_DEVICE := myproduct
. m_e_mips-
. mini_emulator_x86_64-
. mini_emulator_x86-
. aosp_dragon-
. aosp_dragon-
. aosp_marlin-
. aosp_sailfish-
. aosp_flounder-
. aosp_angler-
. aosp_bullhead-
. hikey-
. aosp_shamu-
. myproduct-
pengdonglin@pengdonglin-dell:~/Android7_1$ make
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=7.1.2
TARGET_PRODUCT=myproduct
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=cortex-a15
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.15.0-48-generic-x86_64-with-Ubuntu-18.04-bionic
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=N2G48H
OUT_DIR=out
============================================
Running kati to generate build-myproduct.ninja...
out/build-myproduct.ninja is missing, regenerating...
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=7.1.2
TARGET_PRODUCT=myproduct
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=cortex-a15
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.15.0-48-generic-x86_64-with-Ubuntu-18.04-bionic
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=N2G48H
OUT_DIR=out
============================================
FindEmulator: find: File system loop detected; `./linux-4.14/out64/source' is part of the same file system loop as `./linux-4.14'.
FindEmulator: find: File system loop detected; `./linux-4.14/out64/source' is part of the same file system loop as `./linux-4.14'.
including ./abi/cpp/Android.mk ...
including ./art/Android.mk ...
including ./bionic/Android.mk ...
including ./bootable/recovery/Android.mk ...
including ./build/libs/host/Android.mk ...
... ...
二、集成Linux内核源码到Android代码中
1、将Linux内核代码拷贝到Android代码根目录下并重命名为kernel
2、添加AndroidKernel.mk到kernel
中
内容如下:
#Android makefile to build kernel as a part of Android Build
PERL = perl
KERNEL_TARGET := $(strip $(INSTALLED_KERNEL_TARGET))
ifeq ($(KERNEL_TARGET),)
INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
endif
TARGET_KERNEL_ARCH := $(strip $(TARGET_KERNEL_ARCH))
ifeq ($(TARGET_KERNEL_ARCH),)
KERNEL_ARCH := arm
KERNEL_ARCH := $(TARGET_KERNEL_ARCH)
endif
TARGET_KERNEL_HEADER_ARCH := $(strip $(TARGET_KERNEL_HEADER_ARCH))
ifeq ($(TARGET_KERNEL_HEADER_ARCH),)
KERNEL_HEADER_ARCH := $(KERNEL_ARCH)
$(warning Forcing kernel header generation only for '$(TARGET_KERNEL_HEADER_ARCH)')
KERNEL_HEADER_ARCH := $(TARGET_KERNEL_HEADER_ARCH)
endif
KERNEL_HEADER_DEFCONFIG := $(strip $(KERNEL_HEADER_DEFCONFIG))
ifeq ($(KERNEL_HEADER_DEFCONFIG),)
KERNEL_HEADER_DEFCONFIG := $(KERNEL_DEFCONFIG)
endif
# Force 32-bit binder IPC for 64bit kernel with 32bit userspace
ifeq ($(KERNEL_ARCH),arm64)
ifeq ($(TARGET_ARCH),arm)
KERNEL_CONFIG_OVERRIDE := CONFIG_ANDROID_BINDER_IPC_32BIT=y
endif
endif
TARGET_KERNEL_CROSS_COMPILE_PREFIX := $(strip $(TARGET_KERNEL_CROSS_COMPILE_PREFIX))
ifeq ($(TARGET_KERNEL_CROSS_COMPILE_PREFIX),)
KERNEL_CROSS_COMPILE := arm-eabi-
KERNEL_CROSS_COMPILE := $(TARGET_KERNEL_CROSS_COMPILE_PREFIX)
endif
ifeq ($(TARGET_PREBUILT_KERNEL),)
KERNEL_GCC_NOANDROID_CHK := $(shell (echo "int main() {return 0;}" | $(KERNEL_CROSS_COMPILE)gcc -E -mno-android - > /dev/null 2>&1 ; echo $$?))
ifeq ($(strip $(KERNEL_GCC_NOANDROID_CHK)),0)
KERNEL_CFLAGS := KCFLAGS=-mno-android
endif
KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ
KERNEL_CONFIG := $(KERNEL_OUT)/.config
ifeq ($(KERNEL_DEFCONFIG)$(wildcard $(KERNEL_CONFIG)),)
$(error Kernel configuration not defined, cannot build kernel)
ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true)
$(info Using uncompressed kernel)
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/Image
ifeq ($(KERNEL_ARCH),arm64)
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/Image.gz
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/zImage
endif
endif
ifeq ($(TARGET_KERNEL_APPEND_DTB), true)
$(info Using appended DTB)
TARGET_PREBUILT_INT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL)-dtb
endif
KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
KERNEL_MODULES_INSTALL := system
KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules
TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL)
define mv-modules
mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
if [ "$$mdpath" != "" ];then\
mpath=`dirname $$mdpath`;\
ko=`find $$mpath/kernel -type f -name *.ko`;\
for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\
endef
define clean-module-folder
mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
if [ "$$mdpath" != "" ];then\
mpath=`dirname $$mdpath`; rm -rf $$mpath;\
endef
$(KERNEL_OUT):
mkdir -p $(KERNEL_OUT)
$(KERNEL_CONFIG): $(KERNEL_OUT)
$(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_DEFCONFIG)
$(hide) if [ ! -z "$(KERNEL_CONFIG_OVERRIDE)" ]; then \
echo "Overriding kernel config with '$(KERNEL_CONFIG_OVERRIDE)'"; \
echo $(KERNEL_CONFIG_OVERRIDE) >> $(KERNEL_OUT)/.config; \
$(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) oldconfig; fi
$(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_OUT) $(KERNEL_HEADERS_INSTALL)
$(hide) echo "Building kernel..."
$(hide) rm -rf $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/dts
$(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_CFLAGS)
$(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_CFLAGS) modules
$(MAKE) -C kernel O=../$(KERNEL_OUT) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) INSTALL_MOD_STRIP=1 ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) modules_install
$(mv-modules)
$(clean-module-folder)
$(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT)
$(hide) if [ ! -z "$(KERNEL_HEADER_DEFCONFIG)" ]; then \
$(hide) rm -f ../$(KERNEL_CONFIG); \
$(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=$(KERNEL_HEADER_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_HEADER_DEFCONFIG); \
$(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=$(KERNEL_HEADER_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) headers_install; fi
$(hide) if [ "$(KERNEL_HEADER_DEFCONFIG)" != "$(KERNEL_DEFCONFIG)" ]; then \
echo "Used a different defconfig for header generation"; \
$(hide) rm -f ../$(KERNEL_CONFIG); \
$(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_DEFCONFIG); fi
$(hide) if [ ! -z "$(KERNEL_CONFIG_OVERRIDE)" ]; then \
echo "Overriding kernel config with '$(KERNEL_CONFIG_OVERRIDE)'"; \
echo $(KERNEL_CONFIG_OVERRIDE) >> $(KERNEL_OUT)/.config; \
$(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) oldconfig; fi
kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG)
$(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) tags
kernelconfig: $(KERNEL_OUT) $(KERNEL_CONFIG)
env KCONFIG_NOTIMESTAMP=true \
$(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) menuconfig
env KCONFIG_NOTIMESTAMP=true \
$(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) savedefconfig
cp $(KERNEL_OUT)/defconfig kernel/arch/$(KERNEL_ARCH)/configs/$(KERNEL_DEFCONFIG)
endif
endif
3、在device/mycompany/myproduct/中添加配置文件AndroidBoard.mk
这个AndroidBoard.mk文件会被build/target/board/Android.mk包含。
内容如下:
TARGET_KERNEL_ARCH := arm64
TARGET_KERNEL_CROSS_COMPILE_PREFIX := aarch64-linux-android-
TARGET_USES_UNCOMPRESSED_KERNEL := true
KERNEL_DEFCONFIG := defconfig
include kernel/AndroidKernel.mk
$(INSTALLED_KERNEL_TARGET): $(TARGET_PREBUILT_KERNEL) | $(ACP)
$(transform-prebuilt-to-target)
4、修改device/mycompany/myproduct/BoardConfig.mk
将TARGET_NO_KERNEL的值修改为false。
. build/envsetup.sh
lunch 24
make bootimage
6、添加kernelclean目标
在进行clean的时候,没有必要include那些Android.mk,可以加快执行速度,在build/core/main.mk中提供了一个变量dont_bother_goals,其中的目标在编译时会略过加载Android.mk。
修改build/core/main.mk:
diff --git a/core/main.mk b/core/main.mk
index a612f835d..e333a17d5 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -87,6 +87,8 @@ dont_bother_goals := clean clobber dataclean installclean \
recoveryimage-nodeps \
product-graph dump-products
+dont_bother_goals += kernel-clean
ifneq ($(filter $(dont_bother_goals), $(MAKECMDGOALS)),)
dont_bother := true
endif
@@ -1115,6 +1117,11 @@ clean:
@rm -rf $(OUT_DIR)/*
@echo "Entire build directory removed."
+.PHONY: kernel-clean
+kernel-clean:
+ @echo "Cleaning kernel..."
+ @rm -rf $(PRODUCT_OUT)/obj/KERNEL_OBJ/
.PHONY: clobber
clobber: clean
pengdonglin@pengdonglin-dell:~/Android7_1$ make kernel-clean
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=7.1.2
TARGET_PRODUCT=myproduct
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=cortex-a15
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.15.0-50-generic-x86_64-with-Ubuntu-18.04-bionic
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=N2G48H
OUT_DIR=out
============================================
Running kati to generate build-myproduct-kernel-clean.ninja...
No need to regenerate ninja file
Starting build with ninja
ninja: Entering directory `.'
[100% 1/1] Cleaning kernel...
#### make completed successfully (2 seconds) ####
三、将U-Boot代码集成到Android编译系统中
1、将u-boot-2018.09拷贝到bootable下,并重命名为u-boot
2、在u-boot下添加AndroidU-boot.mk
U-BOOT_TARGET := $(strip $(INSTALLED_U-BOOT_TARGET))
ifeq ($(U-BOOT_TARGET),)
INSTALLED_U-BOOT_TARGET := $(PRODUCT_OUT)/u-boot.bin
endif
TARGET_U-BOOT_ARCH := $(strip $(TARGET_U-BOOT_ARCH))
TARGET_U-BOOT_CROSS_COMPILE_PREFIX := $(strip $(TARGET_U-BOOT_CROSS_COMPILE_PREFIX))
U-BOOT_DEFCONFIG := $(strip $(U-BOOT_DEFCONFIG))
U-BOOT_OUT := $(TARGET_OUT_INTERMEDIATES)/U-BOOT_OBJ
U-BOOT_CONFIG := $(U-BOOT_OUT)/.config
TARGET_PREBUILT_INT_U-BOOT := $(U-BOOT_OUT)/u-boot.bin
TARGET_PREBUILT_U-BOOT := $(TARGET_PREBUILT_INT_U-BOOT)
$(U-BOOT_OUT):
mkdir -p $(U-BOOT_OUT)
$(U-BOOT_CONFIG): $(U-BOOT_OUT)
$(MAKE) -C bootable/u-boot O=../../$(U-BOOT_OUT) ARCH=$(TARGET_U-BOOT_ARCH) CROSS_COMPILE=$(TARGET_U-BOOT_CROSS_COMPILE_PREFIX) $(U-BOOT_DEFCONFIG)
$(TARGET_PREBUILT_INT_U-BOOT): $(U-BOOT_OUT) $(U-BOOT_CONFIG)
$(hide) echo "Building u-boot..."
$(MAKE) -C bootable/u-boot O=../../$(U-BOOT_OUT) ARCH=$(TARGET_U-BOOT_ARCH) CROSS_COMPILE=$(TARGET_U-BOOT_CROSS_COMPILE_PREFIX)
3、修改device/mycompany/myproduct/AndroidBoard.mk
追加如下内容:
TARGET_U-BOOT_ARCH := arm
TARGET_U-BOOT_CROSS_COMPILE_PREFIX := aarch64-linux-android-
U-BOOT_DEFCONFIG := qemu_arm64_defconfig
include bootable/u-boot/AndroidU-boot.mk
$(INSTALLED_U-BOOT_TARGET): $(TARGET_PREBUILT_U-BOOT) | $(ACP)
$(transform-prebuilt-to-target)
4、修改device/mycompany/myproduct/BoardConfig.mk
添加如下内容:
TARGET_NO_U-BOOT := false
5、修改build/core/Makefile
diff --git a/core/Makefile b/core/Makefile
index d8b4ef89b..4b8f8f559 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -464,6 +464,11 @@ ifneq ($(strip $(TARGET_NO_KERNEL)),true)
INSTALLED_KERNEL_TARGET :=
endif
+ifneq ($(strip $(TARGET_NO_U-BOOT)),true)
+ INSTALLED_U-BOOT_TARGET := $(PRODUCT_OUT)/u-boot.bin
+else
+ INSTALLED_U-BOOT_TARGET :=
+endif
# -----------------------------------------------------------------
# the ramdisk
6、修改build/core/main.mk
diff --git a/core/main.mk b/core/main.mk
index a612f835d..bac8ef18d 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -87,6 +87,9 @@ dont_bother_goals := clean clobber dataclean installclean \
recoveryimage-nodeps \
product-graph dump-products
+dont_bother_goals += u-boot-clean
+dont_bother_goals += kernel-clean
ifneq ($(filter $(dont_bother_goals), $(MAKECMDGOALS)),)
dont_bother := true
endif
@@ -907,6 +910,9 @@ endif
.PHONY: ramdisk
ramdisk: $(INSTALLED_RAMDISK_TARGET)
+.PHONY: u-boot
+u-boot: $(INSTALLED_U-BOOT_TARGET)
.PHONY: systemtarball
systemtarball: $(INSTALLED_SYSTEMTARBALL_TARGET)
@@ -1115,6 +1121,16 @@ clean:
@rm -rf $(OUT_DIR)/*
@echo "Entire build directory removed."
+.PHONY: u-boot-clean
+u-boot-clean:
+ @echo "Cleaning u-boot..."
+ @rm -rf $(PRODUCT_OUT)/obj/U-BOOT_OBJ/
+.PHONY: kernel-clean
+kernel-clean:
+ @echo "Cleaning kernel..."
+ @rm -rf $(PRODUCT_OUT)/obj/KERNEL_OBJ/
.PHONY: clobber
clobber: clean
. build/envsetup.sh
lunch 24
make u-boot
OBJCOPY examples/standalone/hello_world.srec
OBJCOPY examples/standalone/hello_world.bin
LD u-boot
OBJCOPY u-boot.srec
OBJCOPY u-boot-nodtb.bin
SYM u-boot.sym
start=$(aarch64-linux-android-nm u-boot | grep __rel_dyn_start | cut -f 1 -d ' '); end=$(aarch64-linux-android-nm u-boot | grep __rel_dyn_end | cut -f 1 -d ' '); tools/relocate-rela u-boot-nodtb.bin 0x00000000 $start $end
COPY u-boot.bin
CFGCHK u-boot.cfg
make[1]: Leaving directory '/home/pengdonglin/Android7_1/out/target/product/myproduct/obj/U-BOOT_OBJ'
make: Leaving directory '/home/pengdonglin/Android7_1/bootable/u-boot'
[100% 4/4] target Prebuilt: (out/target/product/myproduct/u-boot.bin)
make u-boot-clean
pengdonglin@pengdonglin-dell:~/Android7_1$ make u-boot-clean
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=7.1.2
TARGET_PRODUCT=myproduct
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=cortex-a15
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.15.0-50-generic-x86_64-with-Ubuntu-18.04-bionic
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=N2G48H
OUT_DIR=out
============================================
Running kati to generate build-myproduct-u-boot-clean.ninja...
No need to regenerate ninja file
Starting build with ninja
ninja: Entering directory `.'
[100% 1/1] Cleaning u-boot...
#### make completed successfully ####
本文来自博客园,作者:
摩斯电码
,未经同意,禁止转载