xref: /rk3399_rockchip-uboot/make.sh (revision 2c6a058b7ea25398013cb25b4e3bb96fe40da1a5)
1#!/bin/bash
2set -e
3BOARD=$1
4SUBCMD=$1
5FUNCADDR=$1
6JOB=`sed -n "N;/processor/p" /proc/cpuinfo|wc -l`
7SUPPORT_LIST=`ls configs/*[r,p][x,v,k][0-9][0-9]*_defconfig`
8
9# @target board: defined in arch/arm/mach-rockchip/<soc>/Kconfig
10# @label: show build message
11# @loader: search for ini file to pack loader
12# @trust: search for ini file to pack trust
13#
14# "NA" means use default name reading from .config
15#
16# Format:           target board               label         loader      trust
17RKCHIP_INI_DESC=("CONFIG_TARGET_GVA_RK3229       NA          RK322XAT     NA"
18                 "CONFIG_COPROCESSOR_RK1808  RK3399PRO-NPU  RK3399PRONPU  RK3399PRONPU"
19# to be add...
20                )
21
22########################################### User can modify #############################################
23# User's rkbin tool relative path
24RKBIN_TOOLS=../rkbin/tools
25
26# User's GCC toolchain and relative path
27ADDR2LINE_ARM32=arm-linux-gnueabihf-addr2line
28ADDR2LINE_ARM64=aarch64-linux-gnu-addr2line
29OBJ_ARM32=arm-linux-gnueabihf-objdump
30OBJ_ARM64=aarch64-linux-gnu-objdump
31GCC_ARM32=arm-linux-gnueabihf-
32GCC_ARM64=aarch64-linux-gnu-
33TOOLCHAIN_ARM32=../prebuilts/gcc/linux-x86/arm/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin
34TOOLCHAIN_ARM64=../prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin
35
36########################################### User not touch #############################################
37BIN_PATH_FIXUP="--replace tools/rk_tools/ ./"
38RKTOOLS=./tools
39
40# Declare global INI file searching index name for every chip, update in select_chip_info()
41RKCHIP=
42RKCHIP_LABEL=
43RKCHIP_LOADER=
44RKCHIP_TRUST=
45
46# Declare rkbin repository path, updated in prepare()
47RKBIN=
48
49# Declare global toolchain path for CROSS_COMPILE, updated in select_toolchain()
50TOOLCHAIN_GCC=
51TOOLCHAIN_OBJDUMP=
52TOOLCHAIN_ADDR2LINE=
53
54# Declare global default output dir and cmd, update in prepare()
55OUTDIR=$2
56OUTOPT=
57
58# Declare global plaform configure, updated in fixup_platform_configure()
59PLATFORM_RSA=
60PLATFORM_SHA=
61PLATFORM_UBOOT_IMG_SIZE=
62PLATFORM_TRUST_IMG_SIZE=
63PLATFORM_AARCH32=
64#########################################################################################################
65help()
66{
67	echo
68	echo "Usage:"
69	echo "	./make.sh [board|subcmd] [O=<dir>]"
70	echo
71	echo "	 - board: board name of defconfig"
72	echo "	 - subcmd: loader|loader-all|trust|uboot|elf|map|sym|<addr>|"
73	echo "	 - O=<dir>: assigned output directory"
74	echo
75	echo "Example:"
76	echo
77	echo "1. Build board:"
78	echo "	./make.sh evb-rk3399               --- build for evb-rk3399_defconfig"
79	echo "	./make.sh evb-rk3399 O=rockdev     --- build for evb-rk3399_defconfig with output dir "./rockdev""
80	echo "	./make.sh firefly-rk3288           --- build for firefly-rk3288_defconfig"
81	echo "	./make.sh                          --- build with exist .config"
82	echo
83	echo "	After build, Images of uboot, loader and trust are all generated."
84	echo
85	echo "2. Pack helper:"
86	echo "	./make.sh trust                    --- pack trust.img"
87	echo "	./make.sh uboot                    --- pack uboot.img"
88	echo "	./make.sh loader                   --- pack loader bin"
89	echo "	./make.sh loader-all	           --- pack loader bin (all supported loaders)"
90	echo
91	echo "3. Debug helper:"
92	echo "	./make.sh elf                      --- dump elf file with -D(default)"
93	echo "	./make.sh elf-S                    --- dump elf file with -S"
94	echo "	./make.sh elf-d                    --- dump elf file with -d"
95	echo "	./make.sh <no reloc_addr>          --- dump function symbol and code position of address(no relocated)"
96	echo "	./make.sh <reloc_addr-reloc_off>   --- dump function symbol and code position of address(relocated)"
97	echo "	./make.sh map                      --- cat u-boot.map"
98	echo "	./make.sh sym                      --- cat u-boot.sym"
99}
100
101prepare()
102{
103	local absolute_path cmd dir count
104
105	# Parse output directory 'O=<dir>'
106	cmd=${OUTDIR%=*}
107	if [ "${cmd}" = 'O' ]; then
108		OUTDIR=${OUTDIR#*=}
109		OUTOPT=O=${OUTDIR}
110	else
111		case $BOARD in
112			# Parse from exit .config
113			''|elf*|loader*|debug*|trust|uboot|map|sym)
114			count=`find -name .config | wc -l`
115			dir=`find -name .config`
116			# Good, find only one .config
117			if [ $count -eq 1 ]; then
118				dir=${dir%/*}
119				OUTDIR=${dir#*/}
120				# Set OUTOPT if not current directory
121				if [ $OUTDIR != '.' ]; then
122					OUTOPT=O=${OUTDIR}
123				fi
124			elif [ $count -eq 0 ]; then
125				echo
126				echo "Build failed, Can't find .config"
127				help
128				exit 1
129			else
130				echo
131				echo "Build failed, find $count '.config': "
132				echo "$dir"
133				echo "Please leave only one of them"
134				exit 1
135			fi
136			;;
137
138			*)
139			OUTDIR=.
140			;;
141		esac
142	fi
143
144	# Parse help and make defconfig
145	case $BOARD in
146		#Help
147		--help|-help|help|--h|-h)
148		help
149		exit 0
150		;;
151
152		#Subcmd
153		''|elf*|loader*|debug*|trust|uboot|map|sym)
154		;;
155
156		*)
157		#Func address is valid ?
158		if [ -z $(echo ${FUNCADDR} | sed 's/[0-9,a-f,A-F,x,X,-]//g') ]; then
159			return
160		elif [ ! -f configs/${BOARD}_defconfig ]; then
161			echo
162			echo "Can't find: configs/${BOARD}_defconfig"
163			echo
164			echo "******** Rockchip Support List *************"
165			echo "${SUPPORT_LIST}"
166			echo "********************************************"
167			echo
168			exit 1
169		else
170			echo "make for ${BOARD}_defconfig by -j${JOB}"
171			make ${BOARD}_defconfig ${OUTOPT}
172		fi
173		;;
174	esac
175
176	# Initialize RKBIN
177	if [ -d ${RKBIN_TOOLS} ]; then
178		absolute_path=$(cd `dirname ${RKBIN_TOOLS}`; pwd)
179		RKBIN=${absolute_path}
180	else
181		echo
182		echo "Can't find '../rkbin/' repository, please download it before pack image!"
183		echo "How to obtain? 3 ways:"
184		echo "	1. Login your Rockchip gerrit account: \"Projects\" -> \"List\" -> search \"rk/rkbin\" repository"
185		echo "	2. Github repository: https://github.com/rockchip-linux/rkbin"
186		echo "	3. Download full release SDK repository"
187		exit 1
188	fi
189}
190
191select_toolchain()
192{
193	local absolute_path
194
195	if grep  -q '^CONFIG_ARM64=y' ${OUTDIR}/.config ; then
196		if [ -d ${TOOLCHAIN_ARM64} ]; then
197			absolute_path=$(cd `dirname ${TOOLCHAIN_ARM64}`; pwd)
198			TOOLCHAIN_GCC=${absolute_path}/bin/${GCC_ARM64}
199			TOOLCHAIN_OBJDUMP=${absolute_path}/bin/${OBJ_ARM64}
200			TOOLCHAIN_ADDR2LINE=${absolute_path}/bin/${ADDR2LINE_ARM64}
201		else
202			echo "Can't find toolchain: ${TOOLCHAIN_ARM64}"
203			exit 1
204		fi
205	else
206		if [ -d ${TOOLCHAIN_ARM32} ]; then
207			absolute_path=$(cd `dirname ${TOOLCHAIN_ARM32}`; pwd)
208			TOOLCHAIN_GCC=${absolute_path}/bin/${GCC_ARM32}
209			TOOLCHAIN_OBJDUMP=${absolute_path}/bin/${OBJ_ARM32}
210			TOOLCHAIN_ADDR2LINE=${absolute_path}/bin/${ADDR2LINE_ARM32}
211		else
212			echo "Can't find toolchain: ${TOOLCHAIN_ARM32}"
213			exit 1
214		fi
215	fi
216
217	# echo "toolchain: ${TOOLCHAIN_GCC}"
218}
219
220sub_commands()
221{
222	local cmd=${SUBCMD%-*} opt=${SUBCMD#*-}
223
224	case $cmd in
225		elf)
226		if [ ! -f ${OUTDIR}/u-boot ]; then
227			echo "Can't find elf file: ${OUTDIR}/u-boot"
228			exit 1
229		else
230			# default 'cmd' without option, use '-D'
231			if [ "${cmd}" = 'elf' -a "${opt}" = 'elf' ]; then
232				opt=D
233			fi
234			${TOOLCHAIN_OBJDUMP} -${opt} ${OUTDIR}/u-boot | less
235			exit 0
236		fi
237		;;
238
239		debug)
240		if [ "${cmd}" = 'debug' -a "${opt}" = 'debug' ]; then
241			echo
242			echo "The commands will modify .config and files, and can't auto restore changes!"
243			echo "debug-N, the N:"
244			echo "    1. lib/initcall.c debug() -> printf()"
245			echo "    2. common/board_r.c and common/board_f.c debug() -> printf()"
246			echo "    3. global #define DEBUG"
247			echo "    4. enable CONFIG_ROCKCHIP_DEBUGGER"
248			echo "    5. enable CONFIG_ROCKCHIP_CRC"
249			echo "    6. enable CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP"
250			echo "    7. enable CONFIG_ROCKCHIP_CRASH_DUMP"
251			echo "    8. set CONFIG_BOOTDELAY=5"
252			echo "    9. armv7 start.S: print entry warning"
253			echo "   10. armv8 start.S: print entry warning"
254			echo
255			echo "Enabled: "
256			grep '^CONFIG_ROCKCHIP_DEBUGGER=y' ${OUTDIR}/.config > /dev/null \
257			&& echo "    CONFIG_ROCKCHIP_DEBUGGER"
258			grep '^CONFIG_ROCKCHIP_CRC=y' ${OUTDIR}/.config > /dev/null \
259			&& echo "    CONFIG_ROCKCHIP_CRC"
260			grep '^CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y' ${OUTDIR}/.config > /dev/null \
261			&& echo "    CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP"
262			grep '^CONFIG_ROCKCHIP_CRASH_DUMP=y' ${OUTDIR}/.config > /dev/null \
263			&& echo "    CONFIG_ROCKCHIP_CRASH_DUMP"
264
265		elif [ "${opt}" = '1' ]; then
266			sed -i 's/\<debug\>/printf/g' lib/initcall.c
267			echo "DEBUG [1]: lib/initcall.c debug() -> printf()"
268		elif [ "${opt}" = '2' ]; then
269			sed -i 's/\<debug\>/printf/g' ./common/board_f.c
270			sed -i 's/\<debug\>/printf/g' ./common/board_r.c
271			echo "DEBUG [2]: common/board_r.c and common/board_f.c debug() -> printf()"
272		elif [ "${opt}" = '3' ]; then
273			sed -i '$i \#define DEBUG\' include/configs/rockchip-common.h
274			echo "DEBUG [3]: global #define DEBUG"
275		elif [ "${opt}" = '4' ]; then
276			sed -i 's/\# CONFIG_ROCKCHIP_DEBUGGER is not set/CONFIG_ROCKCHIP_DEBUGGER=y/g' ${OUTDIR}/.config
277			echo "DEBUG [4]: CONFIG_ROCKCHIP_DEBUGGER is enabled"
278		elif [ "${opt}" = '5' ]; then
279			sed -i 's/\# CONFIG_ROCKCHIP_CRC is not set/CONFIG_ROCKCHIP_CRC=y/g' ${OUTDIR}/.config
280			echo "DEBUG [5]: CONFIG_ROCKCHIP_CRC is enabled"
281		elif [ "${opt}" = '6' ]; then
282			sed -i 's/\# CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP is not set/CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y/g' ${OUTDIR}/.config
283			echo "DEBUG [6]: CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP is enabled"
284		elif [ "${opt}" = '7' ]; then
285			sed -i 's/\# CONFIG_ROCKCHIP_CRASH_DUMP is not set/CONFIG_ROCKCHIP_CRASH_DUMP=y/g' ${OUTDIR}/.config
286			echo "DEBUG [7]: CONFIG_ROCKCHIP_CRASH_DUMP is enabled"
287		elif [ "${opt}" = '8' ]; then
288			sed -i 's/^CONFIG_BOOTDELAY=0/CONFIG_BOOTDELAY=5/g' ${OUTDIR}/.config
289			echo "DEBUG [8]: CONFIG_BOOTDELAY is 5s"
290		elif [ "${opt}" = '9' ]; then
291			sed -i '/save_boot_params_ret:/a\ldr r0, =CONFIG_DEBUG_UART_BASE\nmov r1, #100\nloop:\nmov r2, #0x55\nstr r2, [r0]\nsub r1, r1, #1\ncmp r1, #0\nbne loop\ndsb' \
292			./arch/arm/cpu/armv7/start.S
293			echo "DEBUG [9]: armv7 start.S entry warning 'UUUU...'"
294		elif [ "${opt}" = '10' ]; then
295			sed -i '/save_boot_params_ret:/a\ldr x0, =CONFIG_DEBUG_UART_BASE\nmov x1, #100\nloop:\nmov x2, #0x55\nstr x2, [x0]\nsub x1, x1, #1\ncmp x1, #0\nb.ne loop\ndsb sy' \
296			./arch/arm/cpu/armv8/start.S
297			echo "DEBUG [10]: armv8 start.S entry warning 'UUUU...'"
298		fi
299		echo
300		exit 0
301		;;
302
303		map)
304		cat ${OUTDIR}/u-boot.map | less
305		exit 0
306		;;
307
308		sym)
309		cat ${OUTDIR}/u-boot.sym | less
310		exit 0
311		;;
312
313		trust)
314		pack_trust_image
315		exit 0
316		;;
317
318		loader)
319		pack_loader_image ${opt}
320		exit 0
321		;;
322
323		uboot)
324		pack_uboot_image
325		exit 0
326		;;
327
328		*)
329		# Search function and code position of address
330		RELOC_OFF=${FUNCADDR#*-}
331		FUNCADDR=${FUNCADDR%-*}
332		if [ -z $(echo ${FUNCADDR} | sed 's/[0-9,a-f,A-F,x,X,-]//g') ] && [ ${FUNCADDR} ]; then
333			# With prefix: '0x' or '0X'
334			if [ `echo ${FUNCADDR} | sed -n "/0[x,X]/p" | wc -l` -ne 0 ]; then
335				FUNCADDR=`echo $FUNCADDR | awk '{ print strtonum($0) }'`
336				FUNCADDR=`echo "obase=16;${FUNCADDR}"|bc |tr '[A-Z]' '[a-z]'`
337			fi
338			if [ `echo ${RELOC_OFF} | sed -n "/0[x,X]/p" | wc -l` -ne 0 ] && [ ${RELOC_OFF} ]; then
339				RELOC_OFF=`echo $RELOC_OFF | awk '{ print strtonum($0) }'`
340				RELOC_OFF=`echo "obase=16;${RELOC_OFF}"|bc |tr '[A-Z]' '[a-z]'`
341			fi
342
343			# If reloc address is assigned, do sub
344			if [ "${FUNCADDR}" != "${RELOC_OFF}" ]; then
345				# Hex -> Dec -> SUB -> Hex
346				FUNCADDR=`echo $((16#${FUNCADDR}))`
347				RELOC_OFF=`echo $((16#${RELOC_OFF}))`
348				FUNCADDR=$((FUNCADDR-RELOC_OFF))
349				FUNCADDR=$(echo "obase=16;${FUNCADDR}"|bc |tr '[A-Z]' '[a-z]')
350			fi
351
352			echo
353			sed -n "/${FUNCADDR}/p" ${OUTDIR}/u-boot.sym
354			${TOOLCHAIN_ADDR2LINE} -e ${OUTDIR}/u-boot ${FUNCADDR}
355			exit 0
356		fi
357		;;
358	esac
359}
360
361# We select chip info to do:
362#	1. RKCHIP: fixup platform configure
363#	2. RKCHIP_LOADER: search ini file to pack loader
364#	3. RKCHIP_TRUST: search ini file to pack trust
365#	4. RKCHIP_LABEL: show build message
366#
367# We read chip info from .config and 'RKCHIP_INI_DESC'
368select_chip_info()
369{
370	local target_board item value
371
372	# Read RKCHIP firstly from .config
373	# The regular expression that matching:
374	#  - PX30, PX3SE
375	#  - RK????, RK????X
376	#  - RV????
377	local chip_reg='^CONFIG_ROCKCHIP_[R,P][X,V,K][0-9ESX]{2,5}'
378	count=`egrep -c ${chip_reg} ${OUTDIR}/.config`
379	# Obtain the matching only
380	RKCHIP=`egrep -o ${chip_reg} ${OUTDIR}/.config`
381
382	if [ $count -eq 1 ]; then
383		RKCHIP=${RKCHIP##*_}
384		grep '^CONFIG_ROCKCHIP_RK3368=y' ${OUTDIR}/.config >/dev/null \
385			&& RKCHIP=RK3368H
386	elif [ $count -gt 1 ]; then
387		# Grep the RK CHIP variant
388		grep '^CONFIG_ROCKCHIP_PX3SE=y' ${OUTDIR}/.config > /dev/null \
389			&& RKCHIP=PX3SE
390		grep '^CONFIG_ROCKCHIP_RK3126=y' ${OUTDIR}/.config >/dev/null \
391			&& RKCHIP=RK3126
392		grep '^CONFIG_ROCKCHIP_RK3326=y' ${OUTDIR}/.config >/dev/null \
393			&& RKCHIP=RK3326
394		grep '^CONFIG_ROCKCHIP_RK3128X=y' ${OUTDIR}/.config >/dev/null \
395			&& RKCHIP=RK3128X
396	else
397		echo "Can't get Rockchip SoC definition in .config"
398		exit 1
399	fi
400
401	# Default use RKCHIP
402	RKCHIP_LABEL=${RKCHIP}
403	RKCHIP_LOADER=${RKCHIP}
404	RKCHIP_TRUST=${RKCHIP}
405
406	# Read from RKCHIP_INI_DESC
407	for item in "${RKCHIP_INI_DESC[@]}"
408	do
409		target_board=`echo $item | awk '{ print $1 }'`
410		if grep  -q "^${target_board}=y" ${OUTDIR}/.config ; then
411			value=`echo $item | awk '{ print $2 }'`
412			if [ "$value" != "NA" ]; then
413				RKCHIP_LABEL=${value};
414			fi
415			value=`echo $item | awk '{ print $3 }'`
416			if [ "$value" != "NA" ]; then
417				RKCHIP_LOADER=${value};
418			fi
419			value=`echo $item | awk '{ print $4 }'`
420			if [ "$value" != "NA" ]; then
421				RKCHIP_TRUST=${value};
422			fi
423		fi
424	done
425}
426
427# Fixup platform special configure
428#	1. fixup pack mode;
429#	2. fixup image size
430#	3. fixup ARM64 cpu boot with AArch32
431fixup_platform_configure()
432{
433	local count plat
434
435# <*> Fixup rsa/sha pack mode for platforms
436	# RK3308/PX30/RK3326/RK1808 use RSA-PKCS1 V2.1, it's pack magic is "3"
437	if [ $RKCHIP = "PX30" -o $RKCHIP = "RK3326" -o $RKCHIP = "RK3308" -o $RKCHIP = "RK1808" ]; then
438		PLATFORM_RSA="--rsa 3"
439	# RK3368 use rk big endian SHA256, it's pack magic is "2"
440	elif [ $RKCHIP = "RK3368" ]; then
441		PLATFORM_SHA="--sha 2"
442	# other platforms use default configure
443	fi
444
445# <*> Fixup images size pack for platforms
446	if [ $RKCHIP = "RK3308" ]; then
447		if grep -q '^CONFIG_ARM64_BOOT_AARCH32=y' ${OUTDIR}/.config ; then
448			PLATFORM_UBOOT_IMG_SIZE="--size 512 2"
449			PLATFORM_TRUST_IMG_SIZE="--size 512 2"
450		else
451			PLATFORM_UBOOT_IMG_SIZE="--size 1024 2"
452			PLATFORM_TRUST_IMG_SIZE="--size 1024 2"
453		fi
454	fi
455
456# <*> Fixup PLATFORM_AARCH32 for ARM64 cpu platforms
457	if [ $RKCHIP = "RK3308" ]; then
458		if grep -q '^CONFIG_ARM64_BOOT_AARCH32=y' ${OUTDIR}/.config ; then
459			PLATFORM_AARCH32="AARCH32"
460		fi
461	fi
462}
463
464pack_uboot_image()
465{
466	local UBOOT_LOAD_ADDR
467
468	UBOOT_LOAD_ADDR=`sed -n "/CONFIG_SYS_TEXT_BASE=/s/CONFIG_SYS_TEXT_BASE=//p" ${OUTDIR}/include/autoconf.mk|tr -d '\r'`
469	${RKTOOLS}/loaderimage --pack --uboot ${OUTDIR}/u-boot.bin uboot.img ${UBOOT_LOAD_ADDR} ${PLATFORM_UBOOT_IMG_SIZE}
470
471	# Delete u-boot.img and u-boot-dtb.img, which makes users not be confused with final uboot.img
472	if [ -f ${OUTDIR}/u-boot.img ]; then
473		rm ${OUTDIR}/u-boot.img
474	fi
475
476	if [ -f ${OUTDIR}/u-boot-dtb.img ]; then
477		rm ${OUTDIR}/u-boot-dtb.img
478	fi
479
480	echo "pack uboot okay! Input: ${OUTDIR}/u-boot.bin"
481}
482
483pack_loader_image()
484{
485	local mode=$1 files ini
486
487	if [ ! -f ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini ]; then
488		echo "pack loader failed! Can't find: ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini"
489		return
490	fi
491
492	cd ${RKBIN}
493
494	if [ "${mode}" = 'all' ]; then
495		files=`ls ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL*.ini`
496		for ini in $files
497		do
498			if [ -f "$ini" ]; then
499				${RKTOOLS}/boot_merger ${BIN_PATH_FIXUP} $ini
500				echo "pack loader okay! Input: $ini"
501			fi
502		done
503	else
504		${RKTOOLS}/boot_merger ${BIN_PATH_FIXUP} ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini
505		echo "pack loader okay! Input: ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini"
506	fi
507
508	cd - && mv ${RKBIN}/*_loader_*.bin ./
509}
510
511pack_trust_image()
512{
513	local TOS TOS_TA DARM_BASE TEE_LOAD_ADDR TEE_OFFSET=0x8400000
514
515	# ARM64 uses trust_merger
516	if grep -Eq ''^CONFIG_ARM64=y'|'^CONFIG_ARM64_BOOT_AARCH32=y'' ${OUTDIR}/.config ; then
517		if [ ! -f ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini ]; then
518			echo "pack trust failed! Can't find: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini"
519			return
520		fi
521
522		cd ${RKBIN}
523		${RKTOOLS}/trust_merger ${PLATFORM_SHA} ${PLATFORM_RSA} ${PLATFORM_TRUST_IMG_SIZE} ${BIN_PATH_FIXUP} ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini
524
525		cd - && mv ${RKBIN}/trust.img ./trust.img
526		echo "pack trust okay! Input: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini"
527	# ARM uses loaderimage
528	else
529		if [ ! -f ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini ]; then
530			echo "pack trust failed! Can't find: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini"
531			return
532		fi
533
534		# OP-TEE is 132M(0x8400000) offset from DRAM base.
535		DARM_BASE=`sed -n "/CONFIG_SYS_SDRAM_BASE=/s/CONFIG_SYS_SDRAM_BASE=//p" ${OUTDIR}/include/autoconf.mk|tr -d '\r'`
536		TEE_LOAD_ADDR=$((DARM_BASE+TEE_OFFSET))
537
538		# Convert Dec to Hex
539		TEE_LOAD_ADDR=$(echo "obase=16;${TEE_LOAD_ADDR}"|bc)
540
541		# Parse orignal path
542		TOS=`sed -n "/TOS=/s/TOS=//p" ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini|tr -d '\r'`
543		TOS_TA=`sed -n "/TOSTA=/s/TOSTA=//p" ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini|tr -d '\r'`
544
545		# replace "./tools/rk_tools/" with "./" to compatible legacy ini content of rkdevelop branch
546		TOS=$(echo ${TOS} | sed "s/tools\/rk_tools\//\.\//g")
547		TOS_TA=$(echo ${TOS_TA} | sed "s/tools\/rk_tools\//\.\//g")
548
549		if [ x$TOS_TA != x -a x$TOS != x ]; then
550			${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS} ./trust.img ${TEE_LOAD_ADDR} ${PLATFORM_TRUST_IMG_SIZE}
551			${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS_TA} ./trust_with_ta.img ${TEE_LOAD_ADDR} ${PLATFORM_TRUST_IMG_SIZE}
552			echo "Both trust.img and trust_with_ta.img are ready"
553		elif [ $TOS ]; then
554			${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS} ./trust.img ${TEE_LOAD_ADDR} ${PLATFORM_TRUST_IMG_SIZE}
555			echo "trust.img is ready"
556		elif [ $TOS_TA ]; then
557			${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS_TA} ./trust.img ${TEE_LOAD_ADDR} ${PLATFORM_TRUST_IMG_SIZE}
558			echo "trust.img with ta is ready"
559		else
560			echo "Can't find any tee bin"
561			exit 1
562		fi
563
564		echo "pack trust okay! Input: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini"
565	fi
566}
567
568finish()
569{
570	echo
571	if [ "$BOARD" = '' ]; then
572		echo "Platform ${RKCHIP_LABEL}${PLATFORM_AARCH32} is build OK, with exist .config"
573	else
574		echo "Platform ${RKCHIP_LABEL}${PLATFORM_AARCH32} is build OK, with new .config(make ${BOARD}_defconfig)"
575	fi
576}
577
578prepare
579select_toolchain
580select_chip_info
581fixup_platform_configure
582sub_commands
583make CROSS_COMPILE=${TOOLCHAIN_GCC}  all --jobs=${JOB} ${OUTOPT}
584pack_uboot_image
585pack_loader_image
586pack_trust_image
587finish
588