blob: 38763c04167057bf956f7347f947829a84a947d4
1 | #!/bin/bash |
2 | # |
3 | # By Victor Wan <victor.wan@amlogic.com> |
4 | # (c) 2014.12 @ Shanghai |
5 | # |
6 | |
7 | VERSION="1.0 (2014.12.4)" |
8 | |
9 | SCRIPT_PATH=$PWD/$(dirname "$0") |
10 | |
11 | #assume default script located in device/amlogic/common |
12 | ANDROID_PATH=${SCRIPT_PATH}/../../.. |
13 | KERNEL_PATH=${ANDROID_PATH}/common |
14 | OUTPUT_PATH=/var/tmp/${USER}/build_tmp/ |
15 | REPORT_NAME=.report |
16 | REPORT_FILE= |
17 | MESON_CHIPS="6 6tv 8 8_tee 8b 8b_tee g9tv" |
18 | NR_JOBS_CFG=1 |
19 | NR_JOBS= |
20 | USER_JOBS=1 |
21 | VERBOSE=no |
22 | HELP=yes |
23 | NULL_DEV="> /dev/null" |
24 | COLOR_Y_S="\033[33;40;1m" |
25 | COLOR_Y_E="\033[0m" |
26 | COLOR_R_S="\033[31;40;1m" |
27 | COLOR_R_E="\033[0m" |
28 | |
29 | function usage() |
30 | { |
31 | echo "Usage: $0 -c [-j jobs] [-k kernel_path] [-o output_path] [-v] [-h]" |
32 | echo " -c enable check" |
33 | echo " -j number of build jobs" |
34 | echo " -k kernel path: default kernel path: ${KERNEL_PATH}" |
35 | echo " -o output path: default output path: ${OUTPUT_PATH}" |
36 | echo " -v show verbose build info" |
37 | echo " -h : show help info" |
38 | echo " script version: ${VERSION}" |
39 | echo " chip list: ${MESON_CHIPS}" |
40 | exit 1 |
41 | } |
42 | |
43 | function args_check() |
44 | { |
45 | |
46 | if [ "${HELP}" = "yes" ]; then |
47 | usage |
48 | fi |
49 | |
50 | if [ -n "${USER_JOBS}" ]; then |
51 | NR_JOBS=${USER_JOBS} |
52 | # echo "override NR_JOBS=${USER_JOBS}!" |
53 | else |
54 | NR_CPU=`cat /proc/cpuinfo | grep "processor"|wc -l` |
55 | let "NR_JOBS=${NR_CPU}*${NR_JOBS_CFG}" |
56 | NR_JOBS=${NR_CPU} |
57 | fi |
58 | if [ ! -d ${KERNEL_PATH} ];then |
59 | echo "Can't open ${KERNEL_PATH} !" |
60 | exit 1 |
61 | fi |
62 | |
63 | if [ ! -d ${OUTPUT_PATH} ];then |
64 | echo "Output dir ${OUTPUT_PATH} not exist, will create it!" |
65 | mkdir -p ${OUTPUT_PATH} |
66 | fi |
67 | |
68 | #echo "concurrent build jobs = ${NR_JOBS}" |
69 | if [ "${VERBOSE}" = "yes" ]; then |
70 | NULL_DEV= |
71 | fi |
72 | |
73 | REPORT_FILE=${OUTPUT_PATH}/${REPORT_NAME} |
74 | |
75 | return 0 |
76 | } |
77 | |
78 | function build_busybox() |
79 | { |
80 | #current dir in Kernel root |
81 | local MESON_GEN=$1 |
82 | local ROOTFS=rootfs.cpio |
83 | local BOARD_NAME=meson${MESON_GEN}_skt |
84 | local IMG_FILE=${OUTPUT_PATH}m${MESON_GEN}boot.img |
85 | local DTD_FILE=arch/arm/boot/dts/amlogic/${BOARD_NAME}.dtb |
86 | |
87 | if test ! -e ${OUTPUT_PATH}/.config; then |
88 | echo "The file .config is absent" |
89 | echo "You must make mesonXX_defconfig firstly, exiting..." |
90 | return 1 |
91 | fi |
92 | |
93 | |
94 | rm -f ${IMG_FILE} |
95 | #make modules |
96 | make O=${OUTPUT_PATH} uImage -j ${NR_JOBS} ${NULL_DEV} |
97 | if [ $? -eq 0 ]; then |
98 | echo -e "${COLOR_Y_S}Kernel uImage Build OK${COLOR_Y_E}" |
99 | else |
100 | echo -e "${COLOR_R_S}Kernel uImage Build failed!${COLOR_R_E}" |
101 | return 1 |
102 | fi |
103 | |
104 | find ${ANDROID_PATH}/hardware/amlogic/ -name "*.ko" |xargs rm -f |
105 | find ${ANDROID_PATH}/hardware/amlogic/ -name "*.o" |xargs rm -f |
106 | find ${ANDROID_PATH}/hardware/amlogic/ -name "*.o.cmd" |xargs rm -f |
107 | |
108 | # make O=${OUTPUT_PATH} modules -j ${NR_JOBS} ${NULL_DEV} |
109 | # if [ $? -eq 0 ]; then |
110 | # echo -e "${COLOR_Y_S}Kernel modules Build OK${COLOR_Y_E}" |
111 | # else |
112 | # echo -e "${COLOR_R_S}Kernel modules Build failed!${COLOR_R_E}" |
113 | # return 1 |
114 | # fi |
115 | |
116 | if test ! -e ./arch/arm/boot/dts/amlogic/${BOARD_NAME}.dtd;then |
117 | echo "dtd file ${BOARD_NAME}.dtd not found, using default" |
118 | BOARD_NAME=meson8_skt |
119 | DTD_FILE=./arch/arm/boot/dts/amlogic/${BOARD_NAME}.dtb |
120 | fi |
121 | make O=${OUTPUT_PATH} ${BOARD_NAME}.dtd ${NULL_DEV} |
122 | make O=${OUTPUT_PATH} ${BOARD_NAME}.dtb ${NULL_DEV} |
123 | |
124 | ./mkbootimg --kernel ${OUTPUT_PATH}/arch/arm/boot/uImage --ramdisk ./${ROOTFS} --second ${DTD_FILE} --output ${IMG_FILE} |
125 | #ls -l ${IMG_FILE} |
126 | rm -f ${IMG_FILE} |
127 | |
128 | echo -e "${COLOR_Y_S}${IMG_FILE} for m${MESON_GEN} done${COLOR_Y_E}" |
129 | return 0 |
130 | } |
131 | |
132 | function build_meson() |
133 | { |
134 | |
135 | INT_CNT=0 |
136 | |
137 | if [ -e ${REPORT_FILE} ];then |
138 | rm -rf ${REPORT_FILE} |
139 | fi |
140 | |
141 | cd ${KERNEL_PATH} |
142 | for MESON_GEN in ${MESON_CHIPS} |
143 | do |
144 | |
145 | echo -e "\n${COLOR_Y_S}Build meson${MESON_GEN}${COLOR_Y_E}" |
146 | |
147 | make V=0 distclean |
148 | |
149 | echo -e "${COLOR_Y_S} DISTCLEAN${COLOR_Y_E}" |
150 | make V=0 O=${OUTPUT_PATH} distclean ${NULL_DEV} |
151 | |
152 | |
153 | echo -e "${COLOR_Y_S} DEFCONFIG${COLOR_Y_E}" |
154 | make V=0 O=${OUTPUT_PATH} meson${MESON_GEN}_defconfig ${NULL_DEV} |
155 | |
156 | echo -e "${COLOR_Y_S} BUILDING...${COLOR_Y_E}" |
157 | BUILD_RET=OK |
158 | IMG_SIZE=0M |
159 | |
160 | build_busybox $MESON_GEN |
161 | if [ $? -ne 0 ]; then |
162 | BUILD_RET=FAILED |
163 | else |
164 | IMG_SIZE=`ls ${OUTPUT_PATH}/arch/arm/boot/uImage -hs | awk '{print $1}'` |
165 | fi |
166 | |
167 | if [ "$INT_CNT" -eq 0 ]; then |
168 | echo -n > ${REPORT_FILE} |
169 | echo -e "Machine\t\tSize\t\tStatus" >> ${REPORT_FILE} |
170 | fi |
171 | let "INT_CNT+=1" |
172 | echo -e "m${MESON_GEN}\t\t${IMG_SIZE}\t\t${BUILD_RET}" \ |
173 | >> ${REPORT_FILE} |
174 | |
175 | done |
176 | |
177 | cd ${SCRIPT_PATH} |
178 | return 0 |
179 | } |
180 | |
181 | function build_report() |
182 | { |
183 | if [ ! -e ${REPORT_FILE} ];then |
184 | echo "report file : ${REPORT_FILE} absent!" |
185 | return 1 |
186 | fi |
187 | |
188 | echo -e "\n${COLOR_Y_S}---------- Build report ----------" |
189 | cat ${REPORT_FILE} |
190 | echo -e "\n${COLOR_Y_E}" |
191 | return 0 |
192 | } |
193 | |
194 | function time_distance() |
195 | { |
196 | T_START=$1 |
197 | T_STOP=$2 |
198 | |
199 | DELTA=$(expr ${T_STOP} - ${T_START}) |
200 | HOUR=$(expr ${DELTA} / 3600) |
201 | HOUR_REM=$(expr ${DELTA} % 3600) |
202 | MIN=$(expr ${HOUR_REM} / 60) |
203 | MIN_REM=$(expr ${HOUR_REM} % 60) |
204 | |
205 | #echo "T_START: ${T_START}, T_STOP: ${T_STOP}" |
206 | #echo "DELTA: ${DELTA}, HOUR: ${HOUR}, HOUR_REM: ${HOUR_REM}, MIN: ${MIN}, MIN_REM: ${MIN_REM}" |
207 | echo -e "Time elapse: ${HOUR} hour, ${MIN} min, ${MIN_REM} sec\n" |
208 | } |
209 | ################################################################# |
210 | # |
211 | # main() |
212 | # |
213 | ################################################################# |
214 | while getopts :j:k:o:chvj var |
215 | do |
216 | case ${var} in |
217 | a) ANDROID_PATH=${OPTARG} ;; |
218 | j) USER_JOBS=${OPTARG} ;; |
219 | k) KERNEL_PATH=${OPTARG} ;; |
220 | o) OUTPUT_PATH=${OPTARG} ;; |
221 | c) HELP=no ;; |
222 | h) HELP=yes ;; |
223 | v) VERBOSE=yes;; |
224 | \?) usage ;; |
225 | esac |
226 | done |
227 | |
228 | args_check |
229 | |
230 | TIME_START=`date +"%s"` |
231 | echo -e "\n[$$]check start at `date` with ${NR_JOBS} jobs, version: ${VERSION}" |
232 | echo -e "chip list: ${MESON_CHIPS}" |
233 | |
234 | build_meson |
235 | build_report |
236 | |
237 | TIME_END=`date +"%s"` |
238 | echo -e "[$$]check finished at `date`" |
239 | time_distance ${TIME_START} ${TIME_END} |
240 | |
241 |