1#!/bin/bash
2# Copyright (c) 2021 Huawei Device Co., Ltd.
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16set -e
17
18export OUT_DIR=$1
19export BUILD_TYPE=$2
20export KERNEL_ARCH=$3
21export PRODUCT_PATH=$4
22export DEVICE_NAME=$5
23export KERNEL_VERSION=$6
24
25if [ "$BUILD_TYPE" == "small" ];then
26    LINUX_KERNEL_OUT=${OUT_DIR}/kernel/${KERNEL_VERSION}
27elif [ "$BUILD_TYPE" == "standard" ];then
28    LINUX_KERNEL_OUT=${OUT_DIR}/kernel/src_tmp/${KERNEL_VERSION}
29fi
30LINUX_KERNEL_OBJ_OUT=${OUT_DIR}/kernel/OBJ/${KERNEL_VERSION}
31
32export OHOS_ROOT_PATH=$(pwd)/../../..
33# it needs adaptation for more device target
34kernel_image=""
35if [ "$KERNEL_ARCH" == "arm" ];then
36    kernel_image="uImage"
37elif [ "$KERNEL_ARCH" == "arm64" ];then
38    kernel_image="Image"
39elif [ "$KERNEL_ARCH" == "x86_64" ];then
40    kernel_image="bzImage"
41fi
42export KERNEL_IMAGE=${kernel_image}
43
44if [ "$KERNEL_ARCH" == "riscv64" ];then
45    LINUX_KERNEL_IMAGE_FILE=${LINUX_KERNEL_OBJ_OUT}/arch/riscv/boot/Image
46else
47    LINUX_KERNEL_IMAGE_FILE=${LINUX_KERNEL_OBJ_OUT}/arch/${KERNEL_ARCH}/boot/${kernel_image}
48fi
49
50if [ "$DEVICE_NAME" == "hispark_phoenix"  ];then
51export SDK_SOURCE_DIR=${OHOS_ROOT_PATH}/device/soc/hisilicon/hi3751v350/sdk_linux/source
52fi
53
54make -f kernel.mk
55
56if [ -f "${LINUX_KERNEL_IMAGE_FILE}" ];then
57    echo "Image: ${LINUX_KERNEL_IMAGE_FILE} build success"
58else
59    echo "Image: ${LINUX_KERNEL_IMAGE_FILE} build failed!!!"
60    exit 1
61fi
62
63if [ "$5" == "hispark_taurus" ];then
64    cp -rf ${LINUX_KERNEL_IMAGE_FILE} ${OUT_DIR}/uImage_${DEVICE_NAME}_smp
65fi
66
67exit 0
68