將linux和uboot集成到Android編譯框架中

環境

Android-7.1
Linux-4.14
u-boot-2018-09
 

概述

        用太高通平臺的都知道,人家把Linux內核代碼放到了Android代碼根目錄下的kernel路徑下,在編譯Android的時候,會連同Linux內核一塊編譯,最後會將編譯出來的Linux內核鏡像連同ramdisk.img一塊打包到boot.img鏡像中。下面咱們仿照高通的作法,也將Linux內核代碼和uboot代碼集成到Android代碼中。
        Android代碼在編譯時沒有采用遞歸的方式,而是經過include,在Android代碼根目錄下生成一個巨大的Makefile。能夠參考以下博客:
 
 

正文

1、創建一個新的產品

下面咱們首先添加一個新產品,這個新產品是基於ARMv8架構的。

一、建立以下路徑node

mkdir -p device/mycompany/myproduct

二、在myproduct下添加以下幾個文件linux


  • Android.mk
ifneq ($(filter myproduct, $(TARGET_DEVICE)),)

LOCAL_PATH := $(call my-dir)

# if some modules are built directly from this directory (not subdirectories),
# their rules should be written here.

include $(call all-makefiles-under,$(LOCAL_PATH))
endif
  • AndroidProducts.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
  • myproduct.mk
#
# Inherit the full_base and device configurations
$(call inherit-product, $(SRC_TARGET_DIR)/product/full_base.mk)

#
# Overrides
PRODUCT_NAME := myproduct
PRODUCT_DEVICE := myproduct
  • BoardConfig.mk
TARGET_NO_BOOTLOADER := true
TARGET_NO_KERNEL := true
TARGET_NO_RECOVERY := true

# Primary Arch
TARGET_ARCH := arm64
TARGET_ARCH_VARIANT := armv8-a
TARGET_CPU_VARIANT := generic
TARGET_CPU_ABI := arm64-v8a

# Secondary Arch
TARGET_2ND_ARCH := arm
TARGET_2ND_ARCH_VARIANT := armv7-a-neon
TARGET_2ND_CPU_VARIANT := cortex-a15
TARGET_2ND_CPU_ABI := armeabi-v7a
TARGET_2ND_CPU_ABI2 := armeabi

TARGET_USES_64_BIT_BINDER := true
TARGET_SUPPORTS_32_BIT_APPS := true
TARGET_SUPPORTS_64_BIT_APPS := true

TARGET_BOARD_PLATFORM := myproduct
WITH_DEXPREOPT ?= true
BUILD_EMULATOR_OPENGL := true
USE_OPENGL_RENDERER := true
ANDROID_ENABLE_RENDERSCRIPT := true

# Some framework code requires this to enable BT
BOARD_HAVE_BLUETOOTH := true
BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := device/generic/common/bluetooth

BOARD_USES_GENERIC_AUDIO := true
USE_CAMERA_STUB := true

TARGET_USERIMAGES_USE_EXT4 := true
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1610612736
BOARD_USERDATAIMAGE_PARTITION_SIZE := 1595915776
BOARD_CACHEIMAGE_PARTITION_SIZE := 268435456
BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
BOARD_FLASH_BLOCK_SIZE := 512
  • vendorsetup.sh
#
# Copyright (C) 2013 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This file is executed by build/envsetup.sh, and can use anything
# defined in envsetup.sh.
#
# In particular, you can add lunch options with the add_lunch_combo
# function: add_lunch_combo generic-eng

add_lunch_combo myproduct-userdebug

三、編譯android

  • build/envsetup.sh
  • lunch
pengdonglin@pengdonglin-dell:~/Android7_1$ lunch

You're building on Linux

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_mips-eng
     4. aosp_mips64-eng
     5. aosp_x86-eng
     6. aosp_x86_64-eng
     7. full_fugu-userdebug
     8. aosp_fugu-userdebug
     9. mini_emulator_arm64-userdebug
     10. m_e_arm-userdebug
     11. m_e_mips64-eng
     12. m_e_mips-userdebug
     13. mini_emulator_x86_64-userdebug
     14. mini_emulator_x86-userdebug
     15. aosp_dragon-userdebug
     16. aosp_dragon-eng
     17. aosp_marlin-userdebug
     18. aosp_sailfish-userdebug
     19. aosp_flounder-userdebug
     20. aosp_angler-userdebug
     21. aosp_bullhead-userdebug
     22. hikey-userdebug
     23. aosp_shamu-userdebug
     24. myproduct-userdebug

Which would you like? [aosp_arm-eng] 24

============================================
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
============================================
  • make
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 ...
... ...

 

2、集成Linux內核源碼到Android代碼中

一、將Linux內核代碼拷貝到Android代碼根目錄下並重命名爲kernelgit

 

二、添加AndroidKernel.mk到kernelgithub

AndroidKernel.mk能夠參考: AndroidKernel.mk
內容以下:
#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
else
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)
else
$(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-
else
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)
else

ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true)
$(info Using uncompressed kernel)
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/Image
else
ifeq ($(KERNEL_ARCH),arm64)
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/Image.gz
else
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;\
fi
endef

define clean-module-folder
mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
if [ "$$mdpath" != "" ];then\
mpath=`dirname $$mdpath`; rm -rf $$mpath;\
fi
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

 

三、在device/mycompany/myproduct/中添加配置文件AndroidBoard.mkshell

這個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)

四、修改device/mycompany/myproduct/BoardConfig.mkexpress

將TARGET_NO_KERNEL的值修改成false。

五、編譯apache

. build/envsetup.sh
lunch 24
make bootimagewindows

六、添加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) ####

 

3、將U-Boot代碼集成到Android編譯系統中

一、將u-boot-2018.09拷貝到bootable下,並重命名爲u-boot

二、在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)

三、修改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)

四、修改device/mycompany/myproduct/BoardConfig.mk

添加以下內容:
TARGET_NO_U-BOOT := false

五、修改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)
 else
   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

六、修改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  ####

 

完。
相關文章
相關標籤/搜索