18d6344f9Sopenharmony_ci#!/bin/bash 28d6344f9Sopenharmony_ci 38d6344f9Sopenharmony_ci# Copyright (c) 2021-2023 HiHope Open Source Organization . 48d6344f9Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 58d6344f9Sopenharmony_ci# you may not use this file except in compliance with the License. 68d6344f9Sopenharmony_ci# You may obtain a copy of the License at 78d6344f9Sopenharmony_ci# 88d6344f9Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 98d6344f9Sopenharmony_ci# 108d6344f9Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 118d6344f9Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 128d6344f9Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138d6344f9Sopenharmony_ci# See the License for the specific language governing permissions and 148d6344f9Sopenharmony_ci# limitations under the License. 158d6344f9Sopenharmony_ci 168d6344f9Sopenharmony_ciset -e 178d6344f9Sopenharmony_ci 188d6344f9Sopenharmony_cipushd ${1} 198d6344f9Sopenharmony_ciROOT_DIR=${5} 208d6344f9Sopenharmony_ciexport PRODUCT_PATH=${4} 218d6344f9Sopenharmony_ciexport DEVICE_COMPANY=${6} 228d6344f9Sopenharmony_ciexport DEVICE_NAME=${7} 238d6344f9Sopenharmony_ciexport PRODUCT_COMPANY=${8} 248d6344f9Sopenharmony_ciKERNEL_VERSION=${9} 258d6344f9Sopenharmony_ciKERNEL_FORM=${10} 268d6344f9Sopenharmony_ciKERNEL_PROD=${11} 278d6344f9Sopenharmony_ciENABLE_LTO_O0=${12} 288d6344f9Sopenharmony_ci 298d6344f9Sopenharmony_ciKERNEL_SRC_TMP_PATH=${ROOT_DIR}/out/kernel/src_tmp/${KERNEL_VERSION} 308d6344f9Sopenharmony_ciKERNEL_OBJ_TMP_PATH=${ROOT_DIR}/out/kernel/OBJ/${KERNEL_VERSION} 318d6344f9Sopenharmony_ciKERNEL_SOURCE=${ROOT_DIR}/kernel/linux/${KERNEL_VERSION} 328d6344f9Sopenharmony_ciKERNEL_PATCH_PATH=${ROOT_DIR}/kernel/linux/patches/${KERNEL_VERSION} 338d6344f9Sopenharmony_ciKERNEL_PATCH=${ROOT_DIR}/kernel/linux/patches/${KERNEL_VERSION}/rk3568_patch/kernel.patch 348d6344f9Sopenharmony_ciBUILD_SCRIPT_PATH=${3} 358d6344f9Sopenharmony_ciNEWIP_PATCH_FILE=${ROOT_DIR}/kernel/linux/common_modules/newip/apply_newip.sh 368d6344f9Sopenharmony_ciTZDRIVER_PATCH_FILE=${ROOT_DIR}/kernel/linux/common_modules/tzdriver/apply_tzdriver.sh 378d6344f9Sopenharmony_ciXPM_PATCH_FILE=${ROOT_DIR}/kernel/linux/common_modules/xpm/apply_xpm.sh 388d6344f9Sopenharmony_ciCED_PATCH_FILE=${ROOT_DIR}/kernel/linux/common_modules/container_escape_detection/apply_ced.sh 398d6344f9Sopenharmony_ciHIDEADDR_PATCH_FILE=${ROOT_DIR}/kernel/linux/common_modules/memory_security/apply_hideaddr.sh 408d6344f9Sopenharmony_ciQOS_AUTH_PATCH_FILE=${ROOT_DIR}/kernel/linux/common_modules/qos_auth/apply_qos_auth.sh 418d6344f9Sopenharmony_ciUNIFIED_COLLECTION_PATCH_FILE=${ROOT_DIR}/kernel/linux/common_modules/ucollection/apply_ucollection.sh 428d6344f9Sopenharmony_ciCODE_SIGN_PATCH_FILE=${ROOT_DIR}/kernel/linux/common_modules/code_sign/apply_code_sign.sh 438d6344f9Sopenharmony_ciDEC_PATCH_FILE=${ROOT_DIR}/kernel/linux/common_modules/dec/apply_dec.sh 448d6344f9Sopenharmony_ci 458d6344f9Sopenharmony_ciHARMONY_CONFIG_PATH=${ROOT_DIR}/kernel/linux/config/${KERNEL_VERSION} 468d6344f9Sopenharmony_ciDEVICE_CONFIG_PATH=${ROOT_DIR}/kernel/linux/config/${KERNEL_VERSION}/${DEVICE_NAME} 478d6344f9Sopenharmony_ciDEFCONFIG_BASE_FILE=${HARMONY_CONFIG_PATH}/base_defconfig 488d6344f9Sopenharmony_ciDEFCONFIG_TYPE_FILE=${HARMONY_CONFIG_PATH}/type/standard_defconfig 498d6344f9Sopenharmony_ciDEFCONFIG_FORM_FILE=${HARMONY_CONFIG_PATH}/form/${KERNEL_FORM}_defconfig 508d6344f9Sopenharmony_ciDEFCONFIG_ARCH_FILE=${DEVICE_CONFIG_PATH}/arch/arm64_defconfig 518d6344f9Sopenharmony_ciDEFCONFIG_PROC_FILE=${DEVICE_CONFIG_PATH}/product/${KERNEL_PROD}_defconfig 528d6344f9Sopenharmony_ci 538d6344f9Sopenharmony_ciRAMDISK_ARG="disable_ramdisk" 548d6344f9Sopenharmony_ciMAKE_OHOS_ENV="GPUDRIVER=mali" 558d6344f9Sopenharmony_ciexport KBUILD_OUTPUT=${KERNEL_OBJ_TMP_PATH} 568d6344f9Sopenharmony_ci 578d6344f9Sopenharmony_cisource ${BUILD_SCRIPT_PATH}/kernel/kernel_source_checker.sh 588d6344f9Sopenharmony_ci 598d6344f9Sopenharmony_cifor i in "$@" 608d6344f9Sopenharmony_cido 618d6344f9Sopenharmony_ci case $i in 628d6344f9Sopenharmony_ci enable_ramdisk) 638d6344f9Sopenharmony_ci RAMDISK_ARG=enable_ramdisk 648d6344f9Sopenharmony_ci ;; 658d6344f9Sopenharmony_ci enable_mesa3d) 668d6344f9Sopenharmony_ci MAKE_OHOS_ENV="GPUDRIVER=mesa3d" 678d6344f9Sopenharmony_ci ;; 688d6344f9Sopenharmony_ci esac 698d6344f9Sopenharmony_cidone 708d6344f9Sopenharmony_ci 718d6344f9Sopenharmony_cifunction copy_and_patch_kernel_source() 728d6344f9Sopenharmony_ci{ 738d6344f9Sopenharmony_ci rm -rf ${KERNEL_SRC_TMP_PATH} 748d6344f9Sopenharmony_ci mkdir -p ${KERNEL_SRC_TMP_PATH} 758d6344f9Sopenharmony_ci 768d6344f9Sopenharmony_ci rm -rf ${KERNEL_OBJ_TMP_PATH} 778d6344f9Sopenharmony_ci mkdir -p ${KERNEL_OBJ_TMP_PATH} 788d6344f9Sopenharmony_ci 798d6344f9Sopenharmony_ci cp -arf ${KERNEL_SOURCE}/* ${KERNEL_SRC_TMP_PATH}/ 808d6344f9Sopenharmony_ci 818d6344f9Sopenharmony_ci cd ${KERNEL_SRC_TMP_PATH} 828d6344f9Sopenharmony_ci 838d6344f9Sopenharmony_ci #HDF patch 848d6344f9Sopenharmony_ci bash ${ROOT_DIR}/drivers/hdf_core/adapter/khdf/linux/patch_hdf.sh ${ROOT_DIR} ${KERNEL_SRC_TMP_PATH} ${KERNEL_PATCH_PATH} ${DEVICE_NAME} 858d6344f9Sopenharmony_ci 868d6344f9Sopenharmony_ci #update linux-6.6 kernel stdarg.h path to linux/stdarg.h 878d6344f9Sopenharmony_ci if [ ${KERNEL_VERSION} == "linux-6.6" ] 888d6344f9Sopenharmony_ci then 898d6344f9Sopenharmony_ci sed -i 's/<stdarg.h>/<linux\/stdarg.h>/' ${KERNEL_SRC_TMP_PATH}/bounds_checking_function/include/securec.h 908d6344f9Sopenharmony_ci fi 918d6344f9Sopenharmony_ci 928d6344f9Sopenharmony_ci #kernel patch 938d6344f9Sopenharmony_ci patch -p1 < ${KERNEL_PATCH} 948d6344f9Sopenharmony_ci 958d6344f9Sopenharmony_ci #newip 968d6344f9Sopenharmony_ci if [ -f $NEWIP_PATCH_FILE ]; then 978d6344f9Sopenharmony_ci bash $NEWIP_PATCH_FILE ${ROOT_DIR} ${KERNEL_SRC_TMP_PATH} ${DEVICE_NAME} ${KERNEL_VERSION} 988d6344f9Sopenharmony_ci fi 998d6344f9Sopenharmony_ci 1008d6344f9Sopenharmony_ci #tzdriver 1018d6344f9Sopenharmony_ci if [ -f $TZDRIVER_PATCH_FILE ]; then 1028d6344f9Sopenharmony_ci bash $TZDRIVER_PATCH_FILE ${ROOT_DIR} ${KERNEL_SRC_TMP_PATH} ${DEVICE_NAME} ${KERNEL_VERSION} 1038d6344f9Sopenharmony_ci fi 1048d6344f9Sopenharmony_ci 1058d6344f9Sopenharmony_ci #xpm 1068d6344f9Sopenharmony_ci if [ -f $XPM_PATCH_FILE ]; then 1078d6344f9Sopenharmony_ci bash $XPM_PATCH_FILE ${ROOT_DIR} ${KERNEL_SRC_TMP_PATH} ${DEVICE_NAME} ${KERNEL_VERSION} 1088d6344f9Sopenharmony_ci fi 1098d6344f9Sopenharmony_ci 1108d6344f9Sopenharmony_ci #ced 1118d6344f9Sopenharmony_ci if [ -f $CED_PATCH_FILE ]; then 1128d6344f9Sopenharmony_ci bash $CED_PATCH_FILE ${ROOT_DIR} ${KERNEL_SRC_TMP_PATH} ${DEVICE_NAME} ${KERNEL_VERSION} 1138d6344f9Sopenharmony_ci fi 1148d6344f9Sopenharmony_ci 1158d6344f9Sopenharmony_ci #qos_auth 1168d6344f9Sopenharmony_ci if [ -f $QOS_AUTH_PATCH_FILE ]; then 1178d6344f9Sopenharmony_ci bash $QOS_AUTH_PATCH_FILE ${ROOT_DIR} ${KERNEL_SRC_TMP_PATH} ${DEVICE_NAME} ${KERNEL_VERSION} 1188d6344f9Sopenharmony_ci fi 1198d6344f9Sopenharmony_ci 1208d6344f9Sopenharmony_ci #hideaddr 1218d6344f9Sopenharmony_ci if [ -f $HIDEADDR_PATCH_FILE ]; then 1228d6344f9Sopenharmony_ci bash $HIDEADDR_PATCH_FILE ${ROOT_DIR} ${KERNEL_SRC_TMP_PATH} ${DEVICE_NAME} ${KERNEL_VERSION} 1238d6344f9Sopenharmony_ci fi 1248d6344f9Sopenharmony_ci 1258d6344f9Sopenharmony_ci #ucollection 1268d6344f9Sopenharmony_ci if [ -f $UNIFIED_COLLECTION_PATCH_FILE ]; then 1278d6344f9Sopenharmony_ci bash $UNIFIED_COLLECTION_PATCH_FILE ${ROOT_DIR} ${KERNEL_SRC_TMP_PATH} ${DEVICE_NAME} ${KERNEL_VERSION} 1288d6344f9Sopenharmony_ci fi 1298d6344f9Sopenharmony_ci 1308d6344f9Sopenharmony_ci #code_sign 1318d6344f9Sopenharmony_ci if [ -f $CODE_SIGN_PATCH_FILE ]; then 1328d6344f9Sopenharmony_ci bash $CODE_SIGN_PATCH_FILE ${ROOT_DIR} ${KERNEL_SRC_TMP_PATH} ${DEVICE_NAME} ${KERNEL_VERSION} 1338d6344f9Sopenharmony_ci fi 1348d6344f9Sopenharmony_ci 1358d6344f9Sopenharmony_ci #dec 1368d6344f9Sopenharmony_ci if [ -f $DEC_PATCH_FILE ]; then 1378d6344f9Sopenharmony_ci bash $DEC_PATCH_FILE ${ROOT_DIR} ${KERNEL_SRC_TMP_PATH} ${DEVICE_NAME} ${KERNEL_VERSION} 1388d6344f9Sopenharmony_ci fi 1398d6344f9Sopenharmony_ci 1408d6344f9Sopenharmony_ci cp -rf ${BUILD_SCRIPT_PATH}/kernel/logo* ${KERNEL_SRC_TMP_PATH}/ 1418d6344f9Sopenharmony_ci 1428d6344f9Sopenharmony_ci #config 1438d6344f9Sopenharmony_ci if [ ! -f "$DEFCONFIG_FORM_FILE" ]; then 1448d6344f9Sopenharmony_ci DEFCONFIG_FORM_FILE= 1458d6344f9Sopenharmony_ci echo "warning no form config file $(DEFCONFIG_FORM_FILE)" 1468d6344f9Sopenharmony_ci fi 1478d6344f9Sopenharmony_ci if [ ! -f "$DEFCONFIG_PROC_FILE" ]; then 1488d6344f9Sopenharmony_ci DEFCONFIG_PROC_FILE= 1498d6344f9Sopenharmony_ci echo "warning no prod config file $(DEFCONFIG_PROC_FILE)" 1508d6344f9Sopenharmony_ci fi 1518d6344f9Sopenharmony_ci bash ${ROOT_DIR}/kernel/linux/${KERNEL_VERSION}/scripts/kconfig/merge_config.sh -O ${KERNEL_SRC_TMP_PATH}/arch/arm64/configs/ -m ${DEFCONFIG_TYPE_FILE} ${DEFCONFIG_FORM_FILE} ${DEFCONFIG_ARCH_FILE} ${DEFCONFIG_PROC_FILE} ${DEFCONFIG_BASE_FILE} 1528d6344f9Sopenharmony_ci mv ${KERNEL_SRC_TMP_PATH}/arch/arm64/configs/.config ${KERNEL_SRC_TMP_PATH}/arch/arm64/configs/rockchip_linux_defconfig 1538d6344f9Sopenharmony_ci 1548d6344f9Sopenharmony_ci #selinux config patch 1558d6344f9Sopenharmony_ci for arg in "$@"; do 1568d6344f9Sopenharmony_ci if [ "$arg" = "is_release" ]; then 1578d6344f9Sopenharmony_ci echo "close selinux kernel config CONFIG_SECURITY_SELINUX_DEVELOP in release version" 1588d6344f9Sopenharmony_ci ${KERNEL_SOURCE}/scripts/config --file ${KERNEL_SRC_TMP_PATH}/arch/arm64/configs/rockchip_linux_defconfig -d SECURITY_SELINUX_DEVELOP 1598d6344f9Sopenharmony_ci fi 1608d6344f9Sopenharmony_ci done 1618d6344f9Sopenharmony_ci 1628d6344f9Sopenharmony_ci if [ $MAKE_OHOS_ENV == "GPUDRIVER=mesa3d" ]; then 1638d6344f9Sopenharmony_ci python ${ROOT_DIR}/third_party/mesa3d/ohos/modifyDtsi.py ${KERNEL_SRC_TMP_PATH}/arch/arm64/boot/dts/rockchip/rk3568.dtsi 1648d6344f9Sopenharmony_ci fi 1658d6344f9Sopenharmony_ci} 1668d6344f9Sopenharmony_ci 1678d6344f9Sopenharmony_ciset +e 1688d6344f9Sopenharmony_ciis_kernel_change ${ROOT_DIR} 1698d6344f9Sopenharmony_ciKERNEL_SOURCE_CHANGED=$? 1708d6344f9Sopenharmony_ciset -e 1718d6344f9Sopenharmony_ciif [ ${KERNEL_SOURCE_CHANGED} -ne 0 ]; then 1728d6344f9Sopenharmony_ci echo "kernel or it's deps changed, start source update." 1738d6344f9Sopenharmony_ci copy_and_patch_kernel_source 1748d6344f9Sopenharmony_cielse 1758d6344f9Sopenharmony_ci echo "no changes to kernel, skip source copy." 1768d6344f9Sopenharmony_cifi 1778d6344f9Sopenharmony_ci 1788d6344f9Sopenharmony_cicd ${KERNEL_SRC_TMP_PATH} 1798d6344f9Sopenharmony_ci 1808d6344f9Sopenharmony_cieval $MAKE_OHOS_ENV ./make-ohos.sh TB-RK3568X0 $RAMDISK_ARG ${ENABLE_LTO_O0} 1818d6344f9Sopenharmony_ci 1828d6344f9Sopenharmony_cimkdir -p ${2} 1838d6344f9Sopenharmony_ci 1848d6344f9Sopenharmony_ciif [ "enable_ramdisk" != "${13}" ]; then 1858d6344f9Sopenharmony_ci cp ${KERNEL_OBJ_TMP_PATH}/boot_linux.img ${2}/boot_linux.img 1868d6344f9Sopenharmony_cifi 1878d6344f9Sopenharmony_cicp ${KERNEL_OBJ_TMP_PATH}/resource.img ${2}/resource.img 1888d6344f9Sopenharmony_cicp ${3}/loader/MiniLoaderAll.bin ${2}/MiniLoaderAll.bin 1898d6344f9Sopenharmony_cicp ${3}/loader/uboot.img ${2}/uboot.img 1908d6344f9Sopenharmony_ci 1918d6344f9Sopenharmony_ciif [ "enable_absystem" == "${15}" ]; then 1928d6344f9Sopenharmony_ci cp ${3}/loader/parameter_ab.txt ${2}/parameter_ab.txt 1938d6344f9Sopenharmony_ci cp ${3}/loader/config_ab.cfg ${2}/config_ab.cfg 1948d6344f9Sopenharmony_cielse 1958d6344f9Sopenharmony_ci cp ${3}/loader/parameter.txt ${2}/parameter.txt 1968d6344f9Sopenharmony_ci cp ${3}/loader/config.cfg ${2}/config.cfg 1978d6344f9Sopenharmony_cifi 1988d6344f9Sopenharmony_ci 1998d6344f9Sopenharmony_cipopd 2008d6344f9Sopenharmony_ci 2018d6344f9Sopenharmony_ci../kernel/src_tmp/${KERNEL_VERSION}/make-boot.sh .. 2028d6344f9Sopenharmony_ci 2038d6344f9Sopenharmony_ciif [ ${KERNEL_SOURCE_CHANGED} -ne 0 ]; then 2048d6344f9Sopenharmony_ci cp ${ROOT_DIR}/out/kernel/checkpoint/last_build.info ${ROOT_DIR}/out/kernel/checkpoint/last_build.backup 2058d6344f9Sopenharmony_ci cp ${ROOT_DIR}/out/kernel/checkpoint/current_build.info ${ROOT_DIR}/out/kernel/checkpoint/last_build.info 2068d6344f9Sopenharmony_ci echo "kernel compile finish, save build info." 2078d6344f9Sopenharmony_cielse 2088d6344f9Sopenharmony_ci echo "kernel compile finish." 2098d6344f9Sopenharmony_cifi 210