xref: /OK3568_Linux_fs/rkbin/scripts/checkpatch.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/bash
2*4882a593Smuzhiyunset -e
3*4882a593Smuzhiyun
4*4882a593SmuzhiyunARG_COMMIT=$1
5*4882a593SmuzhiyunDIFF_SUBSET="scripts/.diff_*"
6*4882a593SmuzhiyunDIFF_DOC_ALL="scripts/.diff_all.txt"
7*4882a593SmuzhiyunDIFF_DOC_FIXED="scripts/.diff_fixed.txt"
8*4882a593SmuzhiyunLAST_SEVERITY=
9*4882a593SmuzhiyunLAST_DOC=
10*4882a593Smuzhiyun
11*4882a593Smuzhiyunfunction check_doc()
12*4882a593Smuzhiyun{
13*4882a593Smuzhiyun	local TOP_SEVERITY LANGUAGE=$1
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun	if [ "${LANGUAGE}" == "EN" ] ; then
16*4882a593Smuzhiyun		SVT_CRITIAL="critical"
17*4882a593Smuzhiyun		SVT_IMPORTANT="important"
18*4882a593Smuzhiyun		SVT_MODERATE="moderate"
19*4882a593Smuzhiyun		DOC=`git log ${ARG_COMMIT} -1 --name-only | sed -n "/_EN\.md/p"`
20*4882a593Smuzhiyun	else
21*4882a593Smuzhiyun		SVT_CRITIAL="紧急"
22*4882a593Smuzhiyun		SVT_IMPORTANT="重要"
23*4882a593Smuzhiyun		SVT_MODERATE="普通"
24*4882a593Smuzhiyun		DOC=`git log ${ARG_COMMIT} -1 --name-only | sed -n "/_CN\.md/p"`
25*4882a593Smuzhiyun	fi
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun	echo "Checking doc: ${DOC}"
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun	# check DOS encoding
30*4882a593Smuzhiyun	git show ${ARG_COMMIT} -1 ${DOC} | sed -n "/^+/p" > ${DIFF_DOC_ALL}
31*4882a593Smuzhiyun	git show ${ARG_COMMIT} -1 ${DOC} | sed -n "/^+/p" > ${DIFF_DOC_ALL}.dos
32*4882a593Smuzhiyun	dos2unix ${DIFF_DOC_ALL}.dos >/dev/null 2>&1
33*4882a593Smuzhiyun	CSUM1=`md5sum ${DIFF_DOC_ALL} | awk '{ print $1 }'`
34*4882a593Smuzhiyun	CSUM2=`md5sum ${DIFF_DOC_ALL}.dos | awk '{ print $1 }'`
35*4882a593Smuzhiyun	if [ "${CSUM1}" != "${CSUM2}" ]; then
36*4882a593Smuzhiyun		echo "ERROR: ${DOC} is DOS encoding. Fix it by: 'dos2unix ${DOC}'"
37*4882a593Smuzhiyun		exit 1
38*4882a593Smuzhiyun	fi
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun	TITLE=`sed -n "/^+## /p" ${DIFF_DOC_ALL} | tr -d " +#"`
41*4882a593Smuzhiyun	DATE=`sed -n "/^+| 20[0-9][0-9]-/p" ${DIFF_DOC_ALL} | tr -d " " | awk -F "|" '{ print $2 }'`
42*4882a593Smuzhiyun	YEAR=`sed -n "/^+| 20[0-9][0-9]-/p" ${DIFF_DOC_ALL} | tr -d " " | awk -F "|" '{ print $2 }' | awk -F "-" '{ print $1 }'`
43*4882a593Smuzhiyun	MON=`sed -n "/^+| 20[0-9][0-9]-/p" ${DIFF_DOC_ALL} | tr -d " " | awk -F "|" '{ print $2 }' | awk -F "-" '{ print $2 }'`
44*4882a593Smuzhiyun	FILE=`sed -n "/^+| 20[0-9][0-9]-/p" ${DIFF_DOC_ALL} | tr -d " " | awk -F "|" '{ print $3 }'`
45*4882a593Smuzhiyun	COMMIT=`sed -n "/^+| 20[0-9][0-9]-/p" ${DIFF_DOC_ALL} | tr -d " " | awk -F "|" '{ print $4 }'`
46*4882a593Smuzhiyun	SEVERITY=`sed -n "/^+| 20[0-9][0-9]-/p" ${DIFF_DOC_ALL} | tr -d " " | awk -F "|" '{ print $5 }'`
47*4882a593Smuzhiyun	END_LINE_3=`tail -n 3 ${DIFF_DOC_ALL} | sed -n '1p'`
48*4882a593Smuzhiyun	END_LINE_2=`tail -n 3 ${DIFF_DOC_ALL} | sed -n '2p'`
49*4882a593Smuzhiyun	END_LINE_1=`tail -n 3 ${DIFF_DOC_ALL} | sed -n '3p'`
50*4882a593Smuzhiyun	HOST_YEAR=`date +%Y`
51*4882a593Smuzhiyun	HOST_MON=`date +%m`
52*4882a593Smuzhiyun	# echo "### ${COMMIT}, ${SEVERITY}, ${TITLE}, ${FILE}"
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun	# check blank line after Heading 1
55*4882a593Smuzhiyun	HEADING_1=`sed -n '1p' ${DOC}`
56*4882a593Smuzhiyun	if sed -n '2p' ${DOC} | grep -q [a-z,A-Z] ; then
57*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Please add blank line after '${HEADING_1}'"
58*4882a593Smuzhiyun		exit 1
59*4882a593Smuzhiyun	fi
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun	# check space
62*4882a593Smuzhiyun	if sed -n "/##/p" ${DOC} | grep -v '## [a-z,A-Z]' ; then
63*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Please only 1 space between '#' and word"
64*4882a593Smuzhiyun		exit 1
65*4882a593Smuzhiyun	fi
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun	# check new content location
68*4882a593Smuzhiyun	if ! git show ${ARG_COMMIT} -1 ${DOC} | grep -q 'Release Note' ; then
69*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Please add new content at the top but not bottom"
70*4882a593Smuzhiyun		exit 1
71*4882a593Smuzhiyun	fi
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun	# check title
74*4882a593Smuzhiyun	if grep -Eq '### WARN|### WARNING|### Warning|### warn|### warning' ${DIFF_DOC_ALL} ; then
75*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Please use '### Warn'"
76*4882a593Smuzhiyun		exit 1
77*4882a593Smuzhiyun	fi
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun	if grep -Eq '### NEW|### new' ${DIFF_DOC_ALL} ; then
80*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Please use '### New'"
81*4882a593Smuzhiyun		exit 1
82*4882a593Smuzhiyun	fi
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun	if grep -Eq '### FIXED|### fixed' ${DIFF_DOC_ALL} ; then
85*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Please use '### Fixed'"
86*4882a593Smuzhiyun		exit 1
87*4882a593Smuzhiyun	fi
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun	# check year/month
90*4882a593Smuzhiyun	if [ "${HOST_YEAR}" != "${YEAR}" ]; then
91*4882a593Smuzhiyun		echo "ERROR: ${DOC}: '${DATE}' is wrong, the year should be ${HOST_YEAR}"
92*4882a593Smuzhiyun		exit 1
93*4882a593Smuzhiyun	fi
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun	if [ "${HOST_MON}" != "${MON}" ]; then
96*4882a593Smuzhiyun		echo "ERROR: ${DOC}: '${DATE}' is wrong, the month should be ${HOST_MON}"
97*4882a593Smuzhiyun		exit 1
98*4882a593Smuzhiyun	fi
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun	# check TAB before index of 'New' body
101*4882a593Smuzhiyun	if grep -q $'\t[0-9]' ${DOC} ; then
102*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Don't add TAB before index:"
103*4882a593Smuzhiyun		grep $'\t[0-9]' ${DOC}
104*4882a593Smuzhiyun		exit 1
105*4882a593Smuzhiyun	fi
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun	# check upper case and line end
108*4882a593Smuzhiyun	if [ "${LANGUAGE}" == "EN" ] ; then
109*4882a593Smuzhiyun		if grep -q '^[0-9]\. [a-z]' ${DOC} ; then
110*4882a593Smuzhiyun			echo "ERROR: ${DOC}: Please use upper case of first word(i.e. \"1. add ..\" => \"1. Add ...\"):"
111*4882a593Smuzhiyun			grep '^[0-9]\. [a-z]' ${DOC}
112*4882a593Smuzhiyun			exit 1
113*4882a593Smuzhiyun		fi
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun		# check end with '.'
116*4882a593Smuzhiyun		if sed -n '/^[0-9]\. [A-Z]/p' ${DOC} | grep -q '[^.]$' ; then
117*4882a593Smuzhiyun			echo "ERROR: ${DOC}: Please end line with '.'"
118*4882a593Smuzhiyun			grep '^[0-9]\. [A-Z]' ${DOC} | grep '[^.]$'
119*4882a593Smuzhiyun			exit 1
120*4882a593Smuzhiyun		fi
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun		# check Chinese language
123*4882a593Smuzhiyun		if grep -P '[\x{4e00}-\x{9fa5}]' ${DOC} ; then
124*4882a593Smuzhiyun			echo "ERROR: ${DOC}: The Chinese language was found"
125*4882a593Smuzhiyun			exit 1
126*4882a593Smuzhiyun		fi
127*4882a593Smuzhiyun	else
128*4882a593Smuzhiyun		# check end with '。'
129*4882a593Smuzhiyun		if sed -n '/^[0-9]\. /p' ${DOC} | grep -q '[^。]$' ; then
130*4882a593Smuzhiyun			echo "ERROR: ${DOC}: Please end line with '。'"
131*4882a593Smuzhiyun			grep '^[0-9]\. ' ${DOC} | grep '[^。]$'
132*4882a593Smuzhiyun			exit 1
133*4882a593Smuzhiyun		fi
134*4882a593Smuzhiyun	fi
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun	# check space after index of 'New' body
137*4882a593Smuzhiyun	SUM1=`grep '^[0-9]\.' ${DOC} | wc -l`
138*4882a593Smuzhiyun	SUM2=`grep '^[0-9]\.[[:blank:]]' ${DOC} | wc -l`
139*4882a593Smuzhiyun	if [ "$SUM1" != "$SUM2" ]; then
140*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Please add space after index (e.g: '1. ' but not '1.'):"
141*4882a593Smuzhiyun		grep '^+[0-9]\.' ${DIFF_DOC_ALL}
142*4882a593Smuzhiyun		exit 1
143*4882a593Smuzhiyun	fi
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun	# check standalone file
146*4882a593Smuzhiyun	if ! echo ${FILE} | grep -Eq '\.bin|\.elf|\.img' ; then
147*4882a593Smuzhiyun		echo "ERROR: ${DOC}: '${FILE}' missing the file format suffix"
148*4882a593Smuzhiyun		exit 1
149*4882a593Smuzhiyun	fi
150*4882a593Smuzhiyun	if ! echo ${FILE} | grep -q { ; then
151*4882a593Smuzhiyun		if ! git log ${ARG_COMMIT} -1 --name-only | grep -q ${FILE}; then
152*4882a593Smuzhiyun			echo "ERROR: ${DOC}: '${FILE}' is not updated in this patch"
153*4882a593Smuzhiyun			exit 1
154*4882a593Smuzhiyun		fi
155*4882a593Smuzhiyun	fi
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun	# check title
158*4882a593Smuzhiyun	if [ "${TITLE}" != "${FILE}" ]; then
159*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Title '${TITLE}' is not match with '${FILE}'"
160*4882a593Smuzhiyun		exit 1
161*4882a593Smuzhiyun	fi
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun	# check commit
164*4882a593Smuzhiyun	COMMIT=${COMMIT//#/ }
165*4882a593Smuzhiyun	for LIST in ${COMMIT}; do
166*4882a593Smuzhiyun		CMT=`echo ${LIST} | cut -d : -f 2`
167*4882a593Smuzhiyun		if ! git log ${ARG_COMMIT} -1 | grep -q ${CMT} ; then
168*4882a593Smuzhiyun			echo "ERROR: ${DOC}: '${CMT}' is not match in commit message"
169*4882a593Smuzhiyun			exit 1
170*4882a593Smuzhiyun		fi
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun		if ! echo ${FILE} | grep -q { ; then
173*4882a593Smuzhiyun			if echo ${FILE} | grep -Eq 'spl_|tpl_|bl31_|bl32_|tee_' ; then
174*4882a593Smuzhiyun				FILE_PATH=`find -name ${FILE}`
175*4882a593Smuzhiyun				if [ -z "${FILE_PATH}" ]; then
176*4882a593Smuzhiyun					echo "ERROR: ${DOC}: No ${FILE}"
177*4882a593Smuzhiyun					exit 1
178*4882a593Smuzhiyun				fi
179*4882a593Smuzhiyun				if ! strings ${FILE_PATH} | grep -q ${CMT} ; then
180*4882a593Smuzhiyun					echo "ERROR: ${DOC}: ${FILE} is not build from '${CMT}'"
181*4882a593Smuzhiyun					exit 1
182*4882a593Smuzhiyun				fi
183*4882a593Smuzhiyun			fi
184*4882a593Smuzhiyun		fi
185*4882a593Smuzhiyun	done
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun	# check severity
188*4882a593Smuzhiyun	if [ "${SEVERITY}" != "${SVT_CRITIAL}" -a "${SEVERITY}" != "${SVT_IMPORTANT}" -a "${SEVERITY}" != "${SVT_MODERATE}" ]; then
189*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Unknown main severity: ${SEVERITY}"
190*4882a593Smuzhiyun		exit 1
191*4882a593Smuzhiyun	fi
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun	# check horizontal line
194*4882a593Smuzhiyun	if [ "${END_LINE_2}" != "+------" ]; then
195*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Please add horizontal line '------' at the last of new content"
196*4882a593Smuzhiyun		exit 1
197*4882a593Smuzhiyun	fi
198*4882a593Smuzhiyun	if [ "${END_LINE_3}" != "+" ]; then
199*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Please add blank line before horizontal line '------'"
200*4882a593Smuzhiyun		exit 1
201*4882a593Smuzhiyun	fi
202*4882a593Smuzhiyun	if [ "${END_LINE_1}" != "+" ]; then
203*4882a593Smuzhiyun		echo "ERROR: ${DOC}: Please add blank line after horizontal line '------'"
204*4882a593Smuzhiyun		exit 1
205*4882a593Smuzhiyun	fi
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun	# check 'Fixed' content
208*4882a593Smuzhiyun	if grep -q "^+### Fixed" ${DIFF_DOC_ALL} ; then
209*4882a593Smuzhiyun		awk -v RS='### Fixed' 'END{printf "%s", $0}' ${DIFF_DOC_ALL} > ${DIFF_DOC_FIXED}
210*4882a593Smuzhiyun		sed -i "/^$/d"    ${DIFF_DOC_FIXED}
211*4882a593Smuzhiyun		sed -i "/Index/d" ${DIFF_DOC_FIXED}
212*4882a593Smuzhiyun		sed -i "/---/d"   ${DIFF_DOC_FIXED}
213*4882a593Smuzhiyun		sed -i "/^+$/d"   ${DIFF_DOC_FIXED}
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun		while read LINE
216*4882a593Smuzhiyun		do
217*4882a593Smuzhiyun			EACH_SEVERITY=`echo "${LINE}" | awk -F "|" '{ print $3 }' | tr -d " "`
218*4882a593Smuzhiyun			if [ "${EACH_SEVERITY}" != "${SVT_CRITIAL}" -a "${EACH_SEVERITY}" != "${SVT_IMPORTANT}" -a "${EACH_SEVERITY}" != "${SVT_MODERATE}" ]; then
219*4882a593Smuzhiyun				if [ -z "${EACH_SEVERITY}" ]; then
220*4882a593Smuzhiyun					echo "ERROR: ${DOC}: No severity found, please use Table to list what you '### Fixed'"
221*4882a593Smuzhiyun				else
222*4882a593Smuzhiyun					echo "ERROR: ${DOC}: Unknown severity: ${EACH_SEVERITY}"
223*4882a593Smuzhiyun				fi
224*4882a593Smuzhiyun				exit 1
225*4882a593Smuzhiyun			fi
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun			# echo "## EACH: $EACH_SEVERITY"
228*4882a593Smuzhiyun			if [ -z "${TOP_SEVERITY}" ]; then
229*4882a593Smuzhiyun				TOP_SEVERITY="${EACH_SEVERITY}"
230*4882a593Smuzhiyun			elif [ "${TOP_SEVERITY}" == "${SVT_MODERATE}" ]; then
231*4882a593Smuzhiyun				if [ "${EACH_SEVERITY}" == "${SVT_CRITIAL}" -o "${EACH_SEVERITY}" == "${SVT_IMPORTANT}" ]; then
232*4882a593Smuzhiyun					TOP_SEVERITY="${EACH_SEVERITY}"
233*4882a593Smuzhiyun				fi
234*4882a593Smuzhiyun			elif [ "${TOP_SEVERITY}" == "${SVT_IMPORTANT}" ]; then
235*4882a593Smuzhiyun				if [ "${EACH_SEVERITY}" == "${SVT_CRITIAL}" ]; then
236*4882a593Smuzhiyun					TOP_SEVERITY="${EACH_SEVERITY}"
237*4882a593Smuzhiyun				fi
238*4882a593Smuzhiyun			fi
239*4882a593Smuzhiyun		done < ${DIFF_DOC_FIXED}
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun		if [ "${SEVERITY}" != "${TOP_SEVERITY}" ]; then
242*4882a593Smuzhiyun			echo "ERROR: ${DOC}: Top severity should be '${TOP_SEVERITY}' as it's the highest level of all sub severity"
243*4882a593Smuzhiyun			exit 1
244*4882a593Smuzhiyun		fi
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun		# check top severity miss match
247*4882a593Smuzhiyun		if [ ! -z ${LAST_SEVERITY} ]; then
248*4882a593Smuzhiyun			if [ "${LAST_SEVERITY}" == "普通" -a "${TOP_SEVERITY}" != "moderate" ]; then
249*4882a593Smuzhiyun				MISS_MATCH="y"
250*4882a593Smuzhiyun			elif [ "${LAST_SEVERITY}" == "重要" -a "${TOP_SEVERITY}" != "important" ]; then
251*4882a593Smuzhiyun				MISS_MATCH="y"
252*4882a593Smuzhiyun			elif [ "${LAST_SEVERITY}" == "紧急" -a "${TOP_SEVERITY}" != "critical" ]; then
253*4882a593Smuzhiyun				MISS_MATCH="y"
254*4882a593Smuzhiyun			elif [ "${LAST_SEVERITY}" == "moderate" -a "${TOP_SEVERITY}" != "普通" ]; then
255*4882a593Smuzhiyun				MISS_MATCH="y"
256*4882a593Smuzhiyun			elif [ "${LAST_SEVERITY}" == "important" -a "${TOP_SEVERITY}" != "重要" ]; then
257*4882a593Smuzhiyun				MISS_MATCH="y"
258*4882a593Smuzhiyun			elif [ "${LAST_SEVERITY}" == "critical" -a "${TOP_SEVERITY}" != "紧急" ]; then
259*4882a593Smuzhiyun				MISS_MATCH="y"
260*4882a593Smuzhiyun			fi
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun			if [ "${MISS_MATCH}" == "y" ]; then
263*4882a593Smuzhiyun				echo "ERROR: ${DOC}: top Severity is '${SEVERITY}', while ${LAST_DOC}: top Severity is '${LAST_SEVERITY}'"
264*4882a593Smuzhiyun				echo "       Available Severity types are: moderate(普通), important(重要), critical(紧急)"
265*4882a593Smuzhiyun				exit 1
266*4882a593Smuzhiyun			fi
267*4882a593Smuzhiyun		fi
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun		LAST_SEVERITY="${SEVERITY}"
270*4882a593Smuzhiyun		LAST_DOC="${DOC}"
271*4882a593Smuzhiyun	fi
272*4882a593Smuzhiyun}
273*4882a593Smuzhiyun
274*4882a593Smuzhiyunfunction check_docs()
275*4882a593Smuzhiyun{
276*4882a593Smuzhiyun	if git log ${ARG_COMMIT} -1 --name-only | sed -n '5p' | grep -Eq '^    Revert "' ; then
277*4882a593Smuzhiyun		return;
278*4882a593Smuzhiyun	fi
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun	if git log ${ARG_COMMIT} -1 --name-only | grep -Eq '\.bin|\.elf' ; then
281*4882a593Smuzhiyun		DOC_CN=`git log ${ARG_COMMIT} -1 --name-only | sed -n "/_CN\.md/p"`
282*4882a593Smuzhiyun		DOC_EN=`git log ${ARG_COMMIT} -1 --name-only | sed -n "/_EN\.md/p"`
283*4882a593Smuzhiyun		if [ -z "${DOC_CN}" -o -z "${DOC_EN}" ]; then
284*4882a593Smuzhiyun			echo "ERROR: Should update CN and EN Release-Note when .bin/elf changed"
285*4882a593Smuzhiyun			exit 1
286*4882a593Smuzhiyun		fi
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun		NUM=`git log ${ARG_COMMIT} -1 --name-only | sed -n "/\.md/p" | wc -l`
289*4882a593Smuzhiyun		if [ ${NUM} -gt 2 ]; then
290*4882a593Smuzhiyun			echo "ERROR: More than 2 release note are updated"
291*4882a593Smuzhiyun			exit 1
292*4882a593Smuzhiyun		fi
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun		if ! which dos2unix > /dev/null 2>&1 ; then
295*4882a593Smuzhiyun			echo "ERROR: No 'dos2unix'. Fix by: sudo apt-get install dos2unix"
296*4882a593Smuzhiyun			exit 1
297*4882a593Smuzhiyun		fi
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun		check_doc CN
300*4882a593Smuzhiyun		check_doc EN
301*4882a593Smuzhiyun	fi
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun	rm -f ${DIFF_SUBSET}
304*4882a593Smuzhiyun}
305*4882a593Smuzhiyun
306*4882a593Smuzhiyunfunction pack_loader_image()
307*4882a593Smuzhiyun{
308*4882a593Smuzhiyun	for FILE in `ls ./RKBOOT/*MINIALL*.ini`
309*4882a593Smuzhiyun	do
310*4882a593Smuzhiyun		if [ "${FILE}" = "./RKBOOT/RK302AMINIALL.ini" -o \
311*4882a593Smuzhiyun			 "${FILE}" = "./RKBOOT/RK30BMINIALL.ini" -o \
312*4882a593Smuzhiyun			 "${FILE}" = "./RKBOOT/RK30MINIALL.ini" -o \
313*4882a593Smuzhiyun			 "${FILE}" = "./RKBOOT/RK310BMINIALL.ini" ]; then
314*4882a593Smuzhiyun			continue;
315*4882a593Smuzhiyun		fi
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun		if grep -q '^PATH=img/' ${FILE}; then
318*4882a593Smuzhiyun			continue;
319*4882a593Smuzhiyun		fi
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun		echo "Pack loader: ${FILE}"
322*4882a593Smuzhiyun		./tools/boot_merger ${FILE}
323*4882a593Smuzhiyun		rm -f *loader*.bin *download*.bin *idblock*.img
324*4882a593Smuzhiyun		echo
325*4882a593Smuzhiyun	done
326*4882a593Smuzhiyun}
327*4882a593Smuzhiyun
328*4882a593Smuzhiyunfunction pack_trust_image()
329*4882a593Smuzhiyun{
330*4882a593Smuzhiyun	# Pack 32-bit trust
331*4882a593Smuzhiyun	for FILE in `ls ./RKTRUST/*TOS*.ini`
332*4882a593Smuzhiyun	do
333*4882a593Smuzhiyun		if ! test -s ${FILE}; then
334*4882a593Smuzhiyun			continue;
335*4882a593Smuzhiyun		elif ! grep -q 'TOS' ${FILE}; then
336*4882a593Smuzhiyun			continue;
337*4882a593Smuzhiyun		elif grep -q '^PATH=img/' ${FILE}; then
338*4882a593Smuzhiyun			continue;
339*4882a593Smuzhiyun		fi
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun		echo "Pack trust: ${FILE}"
342*4882a593Smuzhiyun		# Parse orignal path
343*4882a593Smuzhiyun		TOS=`sed -n "/TOS=/s/TOS=//p" ${FILE}|tr -d '\r'`
344*4882a593Smuzhiyun		TOS_TA=`sed -n "/TOSTA=/s/TOSTA=//p" ${FILE}|tr -d '\r'`
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun		# replace "./tools/rk_tools/" with "./" to compatible legacy ini content of rkdevelop branch
347*4882a593Smuzhiyun		TOS=$(echo ${TOS} | sed "s/tools\/rk_tools\//\.\//g")
348*4882a593Smuzhiyun		TOS_TA=$(echo ${TOS_TA} | sed "s/tools\/rk_tools\//\.\//g")
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun		if [ x${TOS_TA} != x -a x${TOS} != x ]; then
351*4882a593Smuzhiyun			./tools/loaderimage --pack --trustos ${TOS} ./trust.img 0x68400000
352*4882a593Smuzhiyun			./tools/loaderimage --pack --trustos ${TOS_TA} ./trust_with_ta.img 0x68400000
353*4882a593Smuzhiyun		elif [ ${TOS} ]; then
354*4882a593Smuzhiyun			./tools/loaderimage --pack --trustos ${TOS} ./trust.img 0x68400000
355*4882a593Smuzhiyun		elif [ ${TOS_TA} ]; then
356*4882a593Smuzhiyun			./tools/loaderimage --pack --trustos ${TOS_TA} ./trust.img 0x68400000
357*4882a593Smuzhiyun		else
358*4882a593Smuzhiyun			exit 1
359*4882a593Smuzhiyun		fi
360*4882a593Smuzhiyun		rm -f trust*.img
361*4882a593Smuzhiyun		echo
362*4882a593Smuzhiyun	done
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun	# Pack 64-bit trust
365*4882a593Smuzhiyun	for FILE in `ls ./RKTRUST/*TRUST*.ini`
366*4882a593Smuzhiyun	do
367*4882a593Smuzhiyun		if grep -q '^PATH=img/' ${FILE}; then
368*4882a593Smuzhiyun			continue;
369*4882a593Smuzhiyun		fi
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun		echo "Pack trust: ${FILE}"
372*4882a593Smuzhiyun		./tools/trust_merger ${FILE}
373*4882a593Smuzhiyun		rm -f trust*.img
374*4882a593Smuzhiyun		echo
375*4882a593Smuzhiyun	done
376*4882a593Smuzhiyun}
377*4882a593Smuzhiyun
378*4882a593Smuzhiyunfunction check_dirty()
379*4882a593Smuzhiyun{
380*4882a593Smuzhiyun	for FILE in `find -name '*spl*.bin' -o -name '*tpl*.bin' -o -name '*usbplug*.bin' -o -name '*bl31*.elf' -o -name '*bl32*.bin'`; do
381*4882a593Smuzhiyun		echo "Checking clean: ${FILE}"
382*4882a593Smuzhiyun		if strings ${FILE} | grep '\-dirty ' ; then
383*4882a593Smuzhiyun			echo "ERROR: ${FILE} is dirty"
384*4882a593Smuzhiyun			exit 1
385*4882a593Smuzhiyun		fi
386*4882a593Smuzhiyun	done
387*4882a593Smuzhiyun}
388*4882a593Smuzhiyun
389*4882a593Smuzhiyunfunction check_stripped()
390*4882a593Smuzhiyun{
391*4882a593Smuzhiyun	for FILE in `find -name '*bl31*.elf'`; do
392*4882a593Smuzhiyun		echo "Checking strip: ${FILE}"
393*4882a593Smuzhiyun		INFO=`file ${FILE}`
394*4882a593Smuzhiyun		if echo ${INFO} | grep -q "not stripped" ; then
395*4882a593Smuzhiyun			echo "ERROR: ${FILE} is not stripped"
396*4882a593Smuzhiyun			exit 1
397*4882a593Smuzhiyun		fi
398*4882a593Smuzhiyun	done
399*4882a593Smuzhiyun}
400*4882a593Smuzhiyun
401*4882a593Smuzhiyunfunction check_mode()
402*4882a593Smuzhiyun{
403*4882a593Smuzhiyun	echo "Checking file mode..."
404*4882a593Smuzhiyun	if git whatchanged ${ARG_COMMIT} -1 --oneline | sed -n '/RKBOOT\//p; /RKTRUST\//p; /bin\//p; /doc\//p;' | awk '{ print $2 }' | grep -q 755 ; then
405*4882a593Smuzhiyun		git whatchanged ${ARG_COMMIT} -1 --oneline | sed -n '/RKBOOT\//p; /RKTRUST\//p; /bin\//p; /doc\//p;' | grep 755
406*4882a593Smuzhiyun		echo "ERROR: Set 644 file permission but not 755."
407*4882a593Smuzhiyun		exit 1
408*4882a593Smuzhiyun	fi
409*4882a593Smuzhiyun}
410*4882a593Smuzhiyun
411*4882a593Smuzhiyunfunction finish()
412*4882a593Smuzhiyun{
413*4882a593Smuzhiyun	echo "OK, everything is nice."
414*4882a593Smuzhiyun	echo
415*4882a593Smuzhiyun}
416*4882a593Smuzhiyun
417*4882a593Smuzhiyuncheck_mode
418*4882a593Smuzhiyuncheck_docs
419*4882a593Smuzhiyuncheck_dirty
420*4882a593Smuzhiyuncheck_stripped
421*4882a593Smuzhiyunpack_loader_image
422*4882a593Smuzhiyunpack_trust_image
423*4882a593Smuzhiyunfinish
424