scripts: add an option for building profiling kernel and PGO kernel
[platform/kernel/linux-rpi.git] / build-rpi4.sh
1 #!/bin/bash
2
3 COLOR_RED_BG=$(tput setab 1)
4 COLOR_RED_BOLD=$(tput bold)$(tput setaf 1)
5 COLOR_RESET=$(tput sgr0)
6
7 NCPUS=`cat /proc/cpuinfo | grep processor | wc -l`
8 NCPUS=$(($NCPUS * 2))
9
10 if [ $# == 0 ]; then
11         echo "Usage : $0 <architecture> [rt]"
12         echo "  architecture : arm or arm64"
13         echo "  e.g) $0 arm"
14         echo "  e.g) $0 arm64 rt"
15         exit
16 fi
17
18 # Check this system has ccache
19 check_ccache()
20 {
21         type ccache
22         if [ "$?" -eq "0" ]; then
23                 CCACHE=ccache
24         fi
25 }
26
27 check_ccache
28
29 cleanup_localversion()
30 {
31         rm -f localversion-rt
32 }
33
34 DEFCONFIG=tizen_bcm2711_defconfig
35 KCFLAGS=""
36 touch .kernel_buildenv
37 if [ "$2" = "rt" ]; then
38         echo "Build RT-Kernel"
39         BUILD_VERSION=`cat .kernel_buildenv`
40         if [ "$BUILD_VERSION" != "RT" ]; then
41                 echo "Previous .config is for Normal Kernel, so remove"
42                 rm -f .config
43         fi
44         DEFCONFIG=tizen_bcm2711_rt_defconfig
45         cp _localversion-rt localversion-rt
46         trap cleanup_localversion EXIT
47         echo "RT" > ./.kernel_buildenv
48 elif [ "$2" = "pgo" ]; then
49         echo "Build PGO-kernel"
50         BUILD_VERSION=`cat .kernel_buildenv`
51         if [ "$BUILD_VERSION" == "RT" ]; then
52                 echo "Previous .config is for RT Kernel, so remove"
53                 rm -f .config
54         elif [ "$BUILD_VERSION" == "GCOV" ]; then
55                 echo "Previous .config is for GCOV Kernel, so remove and clean"
56                 rm -f .config
57                 make distclean
58         elif [ "$BUILD_VERSION" == "NORMAL" ]; then
59                 echo "Previous .config is for Normal Kernel, so remove"
60                 rm -f .config
61         fi
62         echo "PGO" > ./.kernel_buildenv
63         KCFLAGS="-fprofile-use=$3 -Wno-coverage-mismatch -Wno-error=coverage-mismatch"
64         echo "set KCFLAGS=$KCFLAGS"
65         DEFCONFIG=tizen_bcm2711_defconfig
66 elif [ "$2" = "gcov" ]; then
67         echo "Build GCOV-kernel"
68         BUILD_VERSION=`cat .kernel_buildenv`
69         if [ "$BUILD_VERSION" == "RT" ]; then
70                 echo "Previous .config is for RT Kernel, so remove"
71                 rm -f .config
72         elif [ "$BUILD_VERSION" == "PGO" ]; then
73                 echo "Previous, .config is for PGO kernel, so remove"
74                 rm -f .config
75         elif [ "$BUILD_VERSION" == "NORMAL" ]; then
76                 echo "Previous .config is for Normal Kernel, so remove"
77                 rm -f .config
78         fi
79         echo "GCOV" > ./.kernel_buildenv
80         DEFCONFIG=tizen_bcm2711_gcov_defconfig
81 else
82         echo "Build Normal-Kernel"
83         BUILD_VERSION=`cat .kernel_buildenv`
84         if [ "$BUILD_VERSION" == "RT" ]; then
85                 echo "Previous .config is for RT Kernel, so remove"
86                 rm -f .config
87         fi
88         echo "NORMAL" > ./.kernel_buildenv
89 fi
90
91
92 if [ $1 = "arm" ]; then
93         arch="arm"
94         cross_compile="${CCACHE} arm-linux-gnueabi-"
95         echo "ARM"
96 elif [ $1 = "arm64" ]; then
97         arch="arm64"
98         cross_compile="${CCACHE} aarch64-linux-gnu-"
99         echo "ARM64"
100 fi
101
102 if ! [ -e .config ] ; then
103         make ARCH="${arch}" CROSS_COMPILE="${cross_compile}" ${DEFCONFIG}
104 fi
105
106 make ARCH="${arch}" CROSS_COMPILE="${cross_compile}" KCFLAGS="${KCFLAGS}" -j ${NCPUS} 2>&1 | \
107 sed -e "/error:.*/{s/^.*error:/$(echo -e "${COLOR_RED_BG}&${COLOR_RESET}")/g;q1}" \
108         -e "/Error.*/{s/^.*Error:/$(echo -e "${COLOR_RED_BG}&${COLOR_RESET}")/g;q1}" \
109         -e "/ERROR.*/{s/^.*ERROR/$(echo -e "${COLOR_RED_BG}&${COLOR_RESET}")/g;q1}"
110 if [ $? -ne 0 ]; then
111         echo -e "${COLOR_RED_BOLD}Failed to build${COLOR_RESET}"
112         exit 1
113 fi
114
115 scripts/mkbootimg_rpi4.sh