1# Copyright (C) 2021–2022 Beijing OSWare Technology Co., Ltd 2# This file contains confidential and proprietary information of 3# OSWare Technology Co., Ltd 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17PRODUCT_NAME=$(TARGET_PRODUCT) 18OHOS_BUILD_HOME := $(realpath $(shell pwd)/../../../../../) 19KERNEL_SRC_TMP_PATH := $(OUT_DIR)/kernel/${KERNEL_VERSION} 20KERNEL_OBJ_TMP_PATH := $(OUT_DIR)/kernel/OBJ/${KERNEL_VERSION} 21ifeq ($(BUILD_TYPE), standard) 22 BOOT_IMAGE_PATH = $(OHOS_BUILD_HOME)/device/board/hisilicon/hispark_taurus/uboot/prebuilts 23 KERNEL_SRC_TMP_PATH := $(OUT_DIR)/kernel/src_tmp/${KERNEL_VERSION} 24endif 25 26KERNEL_SRC_PATH := $(OHOS_BUILD_HOME)/kernel/linux/${KERNEL_VERSION} 27KERNEL_PATCH_PATH := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION} 28KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION} 29PREBUILTS_GCC_DIR := $(OHOS_BUILD_HOME)/prebuilts/gcc 30CLANG_HOST_TOOLCHAIN := $(OHOS_BUILD_HOME)/prebuilts/clang/ohos/linux-x86_64/llvm/bin 31KERNEL_HOSTCC := $(CLANG_HOST_TOOLCHAIN)/clang 32KERNEL_PREBUILT_MAKE := make 33CLANG_CC := $(CLANG_HOST_TOOLCHAIN)/clang 34 35HARMONY_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/$(KERNEL_VERSION) 36DEVICE_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/$(KERNEL_VERSION)/$(DEVICE_NAME) 37DEFCONFIG_BASE_FILE := $(HARMONY_CONFIG_PATH)/base_defconfig 38DEFCONFIG_TYPE_FILE := $(HARMONY_CONFIG_PATH)/type/$(BUILD_TYPE)_defconfig 39DEFCONFIG_FORM_FILE := $(HARMONY_CONFIG_PATH)/form/$(KERNEL_FORM)_defconfig 40DEFCONFIG_ARCH_FILE := $(DEVICE_CONFIG_PATH)/arch/$(KERNEL_ARCH)_defconfig 41DEFCONFIG_PROC_FILE := $(DEVICE_CONFIG_PATH)/product/$(KERNEL_PROD)_defconfig 42 43ifneq ($(shell test -e $DEFCONFIG_FORM_FILE), 0) 44 DEFCONFIG_FORM_FILE := 45 $(warning no form config file $(DEFCONFIG_FORM_FILE)) 46endif 47 48ifneq ($(shell test -e $DEFCONFIG_PROC_FILE), 0) 49 DEFCONFIG_PROC_FILE := 50 $(warning no product config file $(DEFCONFIG_PROC_FILE)) 51endif 52 53ifeq ($(KERNEL_ARCH), arm) 54 KERNEL_TARGET_TOOLCHAIN := $(PREBUILTS_GCC_DIR)/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/bin 55 KERNEL_TARGET_TOOLCHAIN_PREFIX := $(KERNEL_TARGET_TOOLCHAIN)/arm-linux-gnueabi- 56else ifeq ($(KERNEL_ARCH), arm64) 57 KERNEL_TARGET_TOOLCHAIN := $(PREBUILTS_GCC_DIR)/linux-x86/aarch64/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin 58 KERNEL_TARGET_TOOLCHAIN_PREFIX := $(KERNEL_TARGET_TOOLCHAIN)/aarch64-linux-gnu- 59endif 60 61KERNEL_CROSS_COMPILE := 62KERNEL_CROSS_COMPILE += CC="$(CLANG_CC)" 63KERNEL_CROSS_COMPILE += CROSS_COMPILE="$(KERNEL_TARGET_TOOLCHAIN_PREFIX)" 64 65KERNEL_MAKE := \ 66 PATH="$(BOOT_IMAGE_PATH):$$PATH" \ 67 $(KERNEL_PREBUILT_MAKE) 68 69DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch 70DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch 71HDF_PATCH_FILE := $(DEVICE_PATCH_DIR)/hdf.patch 72SMALL_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME)_$(BUILD_TYPE).patch 73KERNEL_IMAGE_FILE := $(KERNEL_SRC_TMP_PATH)/arch/$(KERNEL_ARCH)/boot/$(KERNEL_IMAGE) 74DEFCONFIG_FILE := myd_imx8mm_defconfig 75 76$(KERNEL_IMAGE_FILE): 77 $(hide) echo "build kernel..." 78 $(hide) rm -rf $(KERNEL_SRC_TMP_PATH);mkdir -p $(KERNEL_SRC_TMP_PATH);cp -arfL $(KERNEL_SRC_PATH)/* $(KERNEL_SRC_TMP_PATH)/ 79 $(hide) $(OHOS_BUILD_HOME)/device/board/osware/imx8mm/kernel/patch_imx.sh $(KERNEL_PATCH_PATH) $(KERNEL_SRC_TMP_PATH) 80 $(hide) $(OHOS_BUILD_HOME)/drivers/hdf_core/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(KERNEL_PATCH_PATH) ${DEVICE_NAME} 81 sh $(OHOS_BUILD_HOME)/kernel/linux/$(KERNEL_VERSION)/scripts/kconfig/merge_config.sh -O $(KERNEL_SRC_TMP_PATH)/arch/$(KERNEL_ARCH)/configs/ -m $(DEFCONFIG_TYPE_FILE) $(DEFCONFIG_FORM_FILE) $(DEFCONFIG_ARCH_FILE) $(DEFCONFIG_PROC_FILE) $(DEFCONFIG_BASE_FILE) 82 mv $(KERNEL_SRC_TMP_PATH)/arch/$(KERNEL_ARCH)/configs/.config $(KERNEL_SRC_TMP_PATH)/arch/$(KERNEL_ARCH)/configs/$(DEFCONFIG_FILE) 83 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) distclean 84 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(DEFCONFIG_FILE) 85 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) dtbs Image modules -j24 86 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) modules_install INSTALL_MOD_PATH=./TEST 87.PHONY: build-kernel 88build-kernel: $(KERNEL_IMAGE_FILE) 89