1#!/bin/bash
2# Copyright (c) 2023 Huawei Device Co., Ltd.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15set -e
16SOURCE_FILE_DIR=${1}
17TARGET_KO_NAME=${2}
18OUT_DIR=${3}
19PROJECT_DIR=${4}
20DEVICE_NAME=${5}
21DEVICE_ARCH=${6}
22
23args=("$@")
24after_args=("${args[@]:6}")
25
26obj_list=""
27for item in "${after_args[@]}"
28do
29  obj_list+="$item.o"
30  obj_list+="&"
31done
32
33pushd ${SOURCE_FILE_DIR}
34cp ${PROJECT_DIR}/build/templates/kernel/linux-5.10/Makefile .
35cp ${PROJECT_DIR}/out/kernel/OBJ/linux-5.10/certs/signing_key.pem .
36export PATH=${PROJECT_DIR}/out/kernel/OBJ/linux-5.10/scripts/:$PATH
37
38make PROJECTDIR=${PROJECT_DIR} DEVICENAME=${DEVICE_NAME} DEVICEARCH=${DEVICE_ARCH} TARGETKONAME=${TARGET_KO_NAME} OBJLIST=${obj_list}
39sign-file sha512 signing_key.pem signing_key.pem *.ko
40if [ -d "${OUT_DIR}" ]; then
41    echo "The ko build out dir exist"
42else
43    mkdir ${OUT_DIR}
44fi
45
46cp -f *.ko ${OUT_DIR}
47make clean
48rm -f Makefile
49rm -rf signing_key.pem
50exit 0
51