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- 42endif 43 44KERNEL_CROSS_COMPILE := 45ifeq ($(DEVICE_NAME), hi3751v350) 46KERNEL_CROSS_COMPILE += CONFIG_MSP="y" 47else 48KERNEL_CROSS_COMPILE += CC="$(CLANG_CC)" 49endif 50KERNEL_CROSS_COMPILE += CROSS_COMPILE="$(KERNEL_TARGET_TOOLCHAIN_PREFIX)" 51 52ifeq ($(DEVICE_NAME), hi3751v350) 53KERNEL_MAKE := \ 54 PATH="$(BOOT_IMAGE_PATH):$(KERNEL_TARGET_TOOLCHAIN):$$PATH" \ 55 $(KERNEL_PREBUILT_MAKE) 56else 57KERNEL_MAKE := \ 58 PATH="$(BOOT_IMAGE_PATH):$$PATH" \ 59 $(KERNEL_PREBUILT_MAKE) 60endif 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/patchs/$(DEVICE_NAME).patch 67HDF_PATCH_FILE := $(DEVICE_PATCH_DIR)/hdf.patch 68SMALL_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME)_$(BUILD_TYPE).patch 69KERNEL_IMAGE_FILE := $(KERNEL_SRC_TMP_PATH)/arch/$(KERNEL_ARCH)/boot/$(KERNEL_IMAGE) 70DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig 71 72export KBUILD_OUTPUT=$(KERNEL_OBJ_TMP_PATH) 73 74$(KERNEL_IMAGE_FILE): 75 $(hide) echo "build kernel..." 76ifeq ($(DEVICE_NAME), hi3751v350) 77 $(hide) rm -rf $(KERNEL_SRC_TMP_PATH);mkdir -p $(KERNEL_SRC_TMP_PATH);cp -arfP $(KERNEL_SRC_PATH)/* $(KERNEL_SRC_TMP_PATH)/ 78 $(hide) cd $(KERNEL_SRC_TMP_PATH)/drivers && rm -rf common && ln -s $(SDK_SOURCE_DIR)/common/drv ./common && cd - 79 $(hide) cd $(KERNEL_SRC_TMP_PATH)/drivers && rm -rf msp && ln -s $(SDK_SOURCE_DIR)/msp/drv ./msp && cd - 80else 81 $(hide) rm -rf $(KERNEL_SRC_TMP_PATH);mkdir -p $(KERNEL_SRC_TMP_PATH);cp -arfL $(KERNEL_SRC_PATH)/* $(KERNEL_SRC_TMP_PATH)/ 82endif 83 $(hide) $(OHOS_BUILD_HOME)/drivers/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(HDF_PATCH_FILE) 84 85ifeq ($(PRODUCT_PATH), vendor/hisilicon/watchos) 86 $(hide) cd $(KERNEL_SRC_TMP_PATH) && patch -p1 < $(PRODUCT_PATCH_FILE) 87else 88 $(hide) cd $(KERNEL_SRC_TMP_PATH) && patch -p1 < $(DEVICE_PATCH_FILE) 89endif 90 91ifneq ($(findstring $(BUILD_TYPE), small),) 92 $(hide) cd $(KERNEL_SRC_TMP_PATH) && patch -p1 < $(SMALL_PATCH_FILE) 93endif 94 $(hide) cp -rf $(KERNEL_CONFIG_PATH)/. $(KERNEL_SRC_TMP_PATH)/ 95 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) distclean 96 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(DEFCONFIG_FILE) 97ifeq ($(KERNEL_VERSION), linux-5.10) 98 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) modules_prepare 99endif 100 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) -j64 $(KERNEL_IMAGE) 101endif 102ifeq ($(DEVICE_NAME), hi3751v350) 103 $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) dtbs 104endif 105.PHONY: build-kernel 106build-kernel: $(KERNEL_IMAGE_FILE) 107