1# Copyright (c) 2022 Unionman Technology 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 17KERNEL_VERSION = linux-5.10 18KERNEL_ARCH = arm64 19BUILD_TYPE = standard 20OHOS_ROOT_PATH = $(realpath $(shell pwd)/../..) 21 22KERNEL_SRC_TMP_PATH := $(KERNEL_OBJ_PATH)/kernel/src_tmp/linux-5.10 23KERNEL_OBJ_TMP_PATH := $(KERNEL_OBJ_PATH)/kernel/OBJ/linux-5.10 24 25KERNEL_SRC_PATH := $(OHOS_ROOT_PATH)/kernel/linux/${KERNEL_VERSION} 26 27PREBUILTS_GCC_DIR := $(OHOS_ROOT_PATH)/prebuilts/gcc 28CLANG_HOST_TOOLCHAIN := $(OHOS_ROOT_PATH)/prebuilts/clang/ohos/linux-x86_64/llvm/bin 29KERNEL_HOSTCC := $(CLANG_HOST_TOOLCHAIN)/clang 30KERNEL_PREBUILT_MAKE := make 31 32ifeq ($(BUILD_TYPE), standard) 33ifeq ($(KERNEL_ARCH), arm) 34 KERNEL_ARCH := arm 35 KERNEL_TARGET_TOOLCHAIN := $(PREBUILTS_GCC_DIR)/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/bin 36 KERNEL_TARGET_TOOLCHAIN_PREFIX := $(KERNEL_TARGET_TOOLCHAIN)/arm-linux-gnueabi- 37endif 38ifeq ($(KERNEL_ARCH), arm64) 39 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 := aarch64-linux-gnu- 42endif 43 CLANG_CC := $(CLANG_HOST_TOOLCHAIN)/clang 44else ifeq ($(BUILD_TYPE), small) 45 KERNEL_ARCH := arm64 46 ifeq ($(CLANG_CC), "") 47 CLANG_CC := $(CLANG_HOST_TOOLCHAIN)/clang 48 endif 49endif 50 51KERNEL_PERL := /usr/bin/perl 52 53KERNEL_CROSS_COMPILE := 54KERNEL_CROSS_COMPILE += CC="$(CLANG_CC)" 55ifeq ($(BUILD_TYPE), standard) 56 KERNEL_CROSS_COMPILE += HOSTCC="$(KERNEL_HOSTCC)" 57 KERNEL_CROSS_COMPILE += PERL=$(KERNEL_PERL) 58 KERNEL_CROSS_COMPILE += CROSS_COMPILE="$(KERNEL_TARGET_TOOLCHAIN_PREFIX)" 59else ifeq ($(BUILD_TYPE), small) 60 KERNEL_CROSS_COMPILE += CROSS_COMPILE="arm-linux-gnueabi-" 61endif 62 63KERNEL_MAKE := \ 64 PATH="$$PATH" \ 65 $(KERNEL_PREBUILT_MAKE) 66 67KERNEL_PATCH_FILE := $(DEVICE_PATH)/kernel/build/linux-5.10.patch 68HDF_PATCH_FILE := $(DEVICE_PATH)/../../../../kernel/linux/patches/linux-5.10/common_patch/hdf.patch 69KERNEL_CONFIG_FILE := $(DEVICE_PATH)/kernel/build/unionpi_tiger_standard_defconfig 70KERNEL_LOGO_FILE := $(DEVICE_PATH)/resource/logo/logo.ppm 71 72HARMONY_CONFIG_PATH := $(OHOS_ROOT_PATH)/kernel/linux/config/$(KERNEL_VERSION) 73DEVICE_CONFIG_PATH := $(OHOS_ROOT_PATH)/kernel/linux/config/$(KERNEL_VERSION)/$(DEVICE_NAME) 74DEFCONFIG_BASE_FILE := $(HARMONY_CONFIG_PATH)/base_defconfig 75DEFCONFIG_TYPE_FILE := $(HARMONY_CONFIG_PATH)/type/$(BUILD_TYPE)_defconfig 76DEFCONFIG_FORM_FILE := $(HARMONY_CONFIG_PATH)/form/$(KERNEL_FORM)_defconfig 77DEFCONFIG_ARCH_FILE := $(DEVICE_CONFIG_PATH)/arch/$(KERNEL_ARCH)_defconfig 78DEFCONFIG_PROC_FILE := $(DEVICE_CONFIG_PATH)/product/$(KERNEL_PROD)_defconfig 79 80ifneq ($(shell test -e $DEFCONFIG_FORM_FILE), 0) 81 DEFCONFIG_FORM_FILE := 82 $(warning no form config file $(DEFCONFIG_FORM_FILE)) 83endif 84 85ifneq ($(shell test -e $DEFCONFIG_PROC_FILE), 0) 86 DEFCONFIG_PROC_FILE := 87 $(warning no product config file $(DEFCONFIG_PROC_FILE)) 88endif 89 90ifeq ($(KERNEL_ARCH), arm) 91KERNEL_IMAGE_FILE := $(KERNEL_SRC_TMP_PATH)/arch/arm/boot/uImage 92else ifeq ($(KERNEL_ARCH), arm64) 93KERNEL_IMAGE_FILE := $(KERNEL_SRC_TMP_PATH)/arch/arm64/boot/uImage 94endif 95DEFCONFIG_FILE := defconfig 96 97$(KERNEL_IMAGE_FILE): 98 @rm -rf $(KERNEL_SRC_TMP_PATH);mkdir -p $(KERNEL_SRC_TMP_PATH);cp -arf $(KERNEL_SRC_PATH)/* $(KERNEL_SRC_TMP_PATH)/ 99 @cd $(KERNEL_SRC_TMP_PATH) && patch -p1 < $(KERNEL_PATCH_FILE) 100 @rm -rf $(DEVICE_PATH)/../../../../device/soc/amlogic/a311d/soc/drivers 101 @$(DEVICE_PATH)/kernel/build/patch_hdf.sh $(OHOS_ROOT_PATH) $(KERNEL_SRC_TMP_PATH) $(HDF_PATCH_FILE) 102 @cp -rf $(KERNEL_LOGO_FILE) $(KERNEL_SRC_TMP_PATH)/drivers/video/logo/logo_linux_clut224.ppm 103 sh $(OHOS_ROOT_PATH)/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) 104 mv $(KERNEL_SRC_TMP_PATH)/arch/$(KERNEL_ARCH)/configs/.config $(KERNEL_SRC_TMP_PATH)/arch/$(KERNEL_ARCH)/configs/$(DEFCONFIG_FILE) 105 @$(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) LLVM=1 LLVM_IAS=1 ARCH=$(KERNEL_ARCH) TEXT_OFFSET=0x01080000 $(KERNEL_CROSS_COMPILE) $(DEFCONFIG_FILE) 106 @$(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) LLVM=1 LLVM_IAS=1 ARCH=$(KERNEL_ARCH) TEXT_OFFSET=0x01080000 $(KERNEL_CROSS_COMPILE) modules_prepare 107 @mkdir -p $(KERNEL_OBJ_TMP_PATH)/vendor/include 108 @cp -rf $(KERNEL_SRC_TMP_PATH)/vendor/include/* $(KERNEL_OBJ_TMP_PATH)/vendor/include 109 $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) LLVM=1 LLVM_IAS=1 ARCH=$(KERNEL_ARCH) TEXT_OFFSET=0x01080000 $(KERNEL_CROSS_COMPILE) -j128 modules Image Image.gz dtbs 110 if [ -f $(KERNEL_OBJ_TMP_PATH)/vendor/arch/arm64/boot/dts/amlogic/meson-g12b-unionpi-tiger.dtb ]; then \ 111 $(DEVICE_PATH)/common/tools/linux/dtbTool -o $(IMAGES_PATH)/dtb.img $(KERNEL_OBJ_TMP_PATH)/vendor/arch/arm64/boot/dts/amlogic/ > /dev/null; \ 112 fi 113 @gzip $(IMAGES_PATH)/dtb.img 114 @mv $(IMAGES_PATH)/dtb.img.gz $(IMAGES_PATH)/dtb.img 115ifeq ($(RAMDISK_ENABLE), false) 116 @$(DEVICE_PATH)/tools/linux/mkbootimg --kernel $(KERNEL_OBJ_TMP_PATH)/arch/arm64/boot/Image.gz --base 0x0 --kernel_offset 0x1080000 --cmdline "" --ramdisk $(DEVICE_PATH)/tools/linux/rootfs.cpio.gz --second $(IMAGES_PATH)/dtb.img --output $(IMAGES_PATH)/boot.img > /dev/null 117endif 118 119.PHONY: build-kernel 120build-kernel: $(KERNEL_IMAGE_FILE) 121