1# Copyright (c) 2021 Huawei Device Co., Ltd. 2# This program is free software; you can redistribute it and/or modify 3# it under the terms of the GNU General Public License as published by 4# the Free Software Foundation; either version 2 of the License, or 5# (at your option) any later version. 6# 7# This program is distributed in the hope that it will be useful, 8# but WITHOUT ANY WARRANTY; without even the implied warranty of 9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10# GNU General Public License for more details. 11# 12# You should have received a copy of the GNU General Public License 13# along with this program. If not, see <http://www.gnu.org/licenses/>. 14# 15# ohos makefile to build kernel 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} 24 export KERNEL_SRC_DIR=out/KERNEL_OBJ/kernel/src_tmp/${KERNEL_VERSION} 25endif 26 27KERNEL_SRC_PATH := $(OHOS_BUILD_HOME)/kernel/linux/${KERNEL_VERSION} 28KERNEL_PATCH_PATH := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION} 29KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION} 30PREBUILTS_GCC_DIR := $(OHOS_BUILD_HOME)/prebuilts/gcc 31CLANG_HOST_TOOLCHAIN := $(OHOS_BUILD_HOME)/prebuilts/clang/ohos/linux-x86_64/llvm/bin 32KERNEL_HOSTCC := $(CLANG_HOST_TOOLCHAIN)/clang 33KERNEL_PREBUILT_MAKE := make 34CLANG_CC := $(CLANG_HOST_TOOLCHAIN)/clang 35 36ifeq ($(KERNEL_ARCH), arm) 37 KERNEL_TARGET_TOOLCHAIN := $(PREBUILTS_GCC_DIR)/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/bin 38 KERNEL_TARGET_TOOLCHAIN_PREFIX := $(KERNEL_TARGET_TOOLCHAIN)/arm-linux-gnueabi- 39else ifeq ($(KERNEL_ARCH), arm64) 40 KERNEL_TARGET_TOOLCHAIN := $(PREBUILTS_GCC_DIR)/linux-x86/aarch64/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin 41 KERNEL_TARGET_TOOLCHAIN_PREFIX := $(KERNEL_TARGET_TOOLCHAIN)/aarch64-linux-gnu- 42else ifeq ($(KERNEL_ARCH), x86_64) 43 KERNEL_TARGET_TOOLCHAIN := gcc 44 KERNEL_TARGET_TOOLCHAIN_PREFIX := 45endif 46 47KERNEL_CROSS_COMPILE := 48ifeq ($(DEVICE_NAME), hispark_phoenix) 49KERNEL_CROSS_COMPILE += CONFIG_MSP="y" 50endif 51 52KERNEL_CROSS_COMPILE += CC="$(CLANG_CC)" 53 54ifneq ($(KERNEL_ARCH), x86_64) 55KERNEL_CROSS_COMPILE += CROSS_COMPILE="$(KERNEL_TARGET_TOOLCHAIN_PREFIX)" 56endif 57 58KERNEL_MAKE := \ 59 PATH="$(BOOT_IMAGE_PATH):$$PATH" \ 60 $(KERNEL_PREBUILT_MAKE) 61 62 63ifneq ($(findstring $(BUILD_TYPE), small standard),) 64DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch 65DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch 66PRODUCT_PATCH_FILE := $(OHOS_BUILD_HOME)/vendor/hisilicon/watchos/patches/$(DEVICE_NAME).patch 67SMALL_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME)_$(BUILD_TYPE).patch 68KERNEL_IMAGE_FILE := $(KERNEL_SRC_TMP_PATH)/arch/$(KERNEL_ARCH)/boot/$(KERNEL_IMAGE) 69DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig 70 71export KBUILD_OUTPUT=$(KERNEL_OBJ_TMP_PATH) 72 73$(KERNEL_IMAGE_FILE): 74 $(hide) echo "build kernel..." 75ifeq ($(DEVICE_NAME), hispark_phoenix) 76 $(hide) rm -rf $(KERNEL_SRC_TMP_PATH);mkdir -p $(KERNEL_SRC_TMP_PATH);cp -arfP $(KERNEL_SRC_PATH)/* $(KERNEL_SRC_TMP_PATH)/ 77 $(hide) cd $(KERNEL_SRC_TMP_PATH)/drivers && rm -rf common && ln -s $(SDK_SOURCE_DIR)/common/drv ./common && cd - 78 $(hide) cd $(KERNEL_SRC_TMP_PATH)/drivers && rm -rf msp && ln -s $(SDK_SOURCE_DIR)/msp/drv ./msp && cd - 79else 80 $(hide) rm -rf $(KERNEL_SRC_TMP_PATH);mkdir -p $(KERNEL_SRC_TMP_PATH);cp -arfL $(KERNEL_SRC_PATH)/* $(KERNEL_SRC_TMP_PATH)/ 81endif 82 $(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) 83 84ifeq ($(PRODUCT_PATH), vendor/hisilicon/watchos) 85 $(hide) cd $(KERNEL_SRC_TMP_PATH) && patch -p1 < $(PRODUCT_PATCH_FILE) 86else 87 $(hide) cd $(KERNEL_SRC_TMP_PATH) && patch -p1 < $(DEVICE_PATCH_FILE) 88endif 89 90ifneq ($(findstring $(BUILD_TYPE), small),) 91 $(hide) cd $(KERNEL_SRC_TMP_PATH) && patch -p1 < $(SMALL_PATCH_FILE) 92endif 93 $(hide) cp -rf $(KERNEL_CONFIG_PATH)/. $(KERNEL_SRC_TMP_PATH)/ 94 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) distclean 95 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(DEFCONFIG_FILE) 96ifeq ($(KERNEL_VERSION), linux-5.10) 97 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) modules_prepare 98endif 99 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) -j64 $(KERNEL_IMAGE) 100endif 101ifeq ($(DEVICE_NAME), hispark_phoenix) 102 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) dtbs 103endif 104.PHONY: build-kernel 105build-kernel: $(KERNEL_IMAGE_FILE) 106