xref: /rk3399_rockchip-uboot/make.sh (revision 6aa65bb1ee0951865e27da81dde1de76c6d4687e)
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		debug_command
241		exit 0
242		;;
243
244		map)
245		cat ${OUTDIR}/u-boot.map | less
246		exit 0
247		;;
248
249		sym)
250		cat ${OUTDIR}/u-boot.sym | less
251		exit 0
252		;;
253
254		trust)
255		pack_trust_image
256		exit 0
257		;;
258
259		loader)
260		pack_loader_image ${opt}
261		exit 0
262		;;
263
264		uboot)
265		pack_uboot_image
266		exit 0
267		;;
268
269		*)
270		# Search function and code position of address
271		RELOC_OFF=${FUNCADDR#*-}
272		FUNCADDR=${FUNCADDR%-*}
273		if [ -z $(echo ${FUNCADDR} | sed 's/[0-9,a-f,A-F,x,X,-]//g') ] && [ ${FUNCADDR} ]; then
274			# With prefix: '0x' or '0X'
275			if [ `echo ${FUNCADDR} | sed -n "/0[x,X]/p" | wc -l` -ne 0 ]; then
276				FUNCADDR=`echo $FUNCADDR | awk '{ print strtonum($0) }'`
277				FUNCADDR=`echo "obase=16;${FUNCADDR}"|bc |tr '[A-Z]' '[a-z]'`
278			fi
279			if [ `echo ${RELOC_OFF} | sed -n "/0[x,X]/p" | wc -l` -ne 0 ] && [ ${RELOC_OFF} ]; then
280				RELOC_OFF=`echo $RELOC_OFF | awk '{ print strtonum($0) }'`
281				RELOC_OFF=`echo "obase=16;${RELOC_OFF}"|bc |tr '[A-Z]' '[a-z]'`
282			fi
283
284			# If reloc address is assigned, do sub
285			if [ "${FUNCADDR}" != "${RELOC_OFF}" ]; then
286				# Hex -> Dec -> SUB -> Hex
287				FUNCADDR=`echo $((16#${FUNCADDR}))`
288				RELOC_OFF=`echo $((16#${RELOC_OFF}))`
289				FUNCADDR=$((FUNCADDR-RELOC_OFF))
290				FUNCADDR=$(echo "obase=16;${FUNCADDR}"|bc |tr '[A-Z]' '[a-z]')
291			fi
292
293			echo
294			sed -n "/${FUNCADDR}/p" ${OUTDIR}/u-boot.sym
295			${TOOLCHAIN_ADDR2LINE} -e ${OUTDIR}/u-boot ${FUNCADDR}
296			exit 0
297		fi
298		;;
299	esac
300}
301
302# We select chip info to do:
303#	1. RKCHIP: fixup platform configure
304#	2. RKCHIP_LOADER: search ini file to pack loader
305#	3. RKCHIP_TRUST: search ini file to pack trust
306#	4. RKCHIP_LABEL: show build message
307#
308# We read chip info from .config and 'RKCHIP_INI_DESC'
309select_chip_info()
310{
311	local target_board item value
312
313	# Read RKCHIP firstly from .config
314	# The regular expression that matching:
315	#  - PX30, PX3SE
316	#  - RK????, RK????X
317	#  - RV????
318	local chip_reg='^CONFIG_ROCKCHIP_[R,P][X,V,K][0-9ESX]{2,5}'
319	count=`egrep -c ${chip_reg} ${OUTDIR}/.config`
320	# Obtain the matching only
321	RKCHIP=`egrep -o ${chip_reg} ${OUTDIR}/.config`
322
323	if [ $count -eq 1 ]; then
324		RKCHIP=${RKCHIP##*_}
325		grep '^CONFIG_ROCKCHIP_RK3368=y' ${OUTDIR}/.config >/dev/null \
326			&& RKCHIP=RK3368H
327	elif [ $count -gt 1 ]; then
328		# Grep the RK CHIP variant
329		grep '^CONFIG_ROCKCHIP_PX3SE=y' ${OUTDIR}/.config > /dev/null \
330			&& RKCHIP=PX3SE
331		grep '^CONFIG_ROCKCHIP_RK3126=y' ${OUTDIR}/.config >/dev/null \
332			&& RKCHIP=RK3126
333		grep '^CONFIG_ROCKCHIP_RK3326=y' ${OUTDIR}/.config >/dev/null \
334			&& RKCHIP=RK3326
335		grep '^CONFIG_ROCKCHIP_RK3128X=y' ${OUTDIR}/.config >/dev/null \
336			&& RKCHIP=RK3128X
337		grep '^CONFIG_ROCKCHIP_RK3399PRO=y' ${OUTDIR}/.config >/dev/null \
338			&& RKCHIP=RK3399PRO
339	else
340		echo "Can't get Rockchip SoC definition in .config"
341		exit 1
342	fi
343
344	# Default use RKCHIP
345	RKCHIP_LABEL=${RKCHIP}
346	RKCHIP_LOADER=${RKCHIP}
347	RKCHIP_TRUST=${RKCHIP}
348
349	# Read from RKCHIP_INI_DESC
350	for item in "${RKCHIP_INI_DESC[@]}"
351	do
352		target_board=`echo $item | awk '{ print $1 }'`
353		if grep  -q "^${target_board}=y" ${OUTDIR}/.config ; then
354			value=`echo $item | awk '{ print $2 }'`
355			if [ "$value" != "NA" ]; then
356				RKCHIP_LABEL=${value};
357			fi
358			value=`echo $item | awk '{ print $3 }'`
359			if [ "$value" != "NA" ]; then
360				RKCHIP_LOADER=${value};
361			fi
362			value=`echo $item | awk '{ print $4 }'`
363			if [ "$value" != "NA" ]; then
364				RKCHIP_TRUST=${value};
365			fi
366		fi
367	done
368}
369
370# Fixup platform special configure
371#	1. fixup pack mode;
372#	2. fixup image size
373#	3. fixup ARM64 cpu boot with AArch32
374fixup_platform_configure()
375{
376	local count plat
377
378# <*> Fixup rsa/sha pack mode for platforms
379	# RK3308/PX30/RK3326/RK1808 use RSA-PKCS1 V2.1, it's pack magic is "3"
380	if [ $RKCHIP = "PX30" -o $RKCHIP = "RK3326" -o $RKCHIP = "RK3308" -o $RKCHIP = "RK1808" ]; then
381		PLATFORM_RSA="--rsa 3"
382	# RK3368 use rk big endian SHA256, it's pack magic is "2"
383	elif [ $RKCHIP = "RK3368" ]; then
384		PLATFORM_SHA="--sha 2"
385	# other platforms use default configure
386	fi
387
388# <*> Fixup images size pack for platforms
389	if [ $RKCHIP = "RK3308" ]; then
390		if grep -q '^CONFIG_ARM64_BOOT_AARCH32=y' ${OUTDIR}/.config ; then
391			PLATFORM_UBOOT_IMG_SIZE="--size 512 2"
392			PLATFORM_TRUST_IMG_SIZE="--size 512 2"
393		else
394			PLATFORM_UBOOT_IMG_SIZE="--size 1024 2"
395			PLATFORM_TRUST_IMG_SIZE="--size 1024 2"
396		fi
397	elif [ $RKCHIP = "RK1808" ]; then
398		PLATFORM_UBOOT_IMG_SIZE="--size 1024 2"
399		PLATFORM_TRUST_IMG_SIZE="--size 1024 2"
400	fi
401
402# <*> Fixup PLATFORM_AARCH32 for ARM64 cpu platforms
403	if [ $RKCHIP = "RK3308" ]; then
404		if grep -q '^CONFIG_ARM64_BOOT_AARCH32=y' ${OUTDIR}/.config ; then
405			PLATFORM_AARCH32="AARCH32"
406		fi
407	fi
408}
409
410debug_command()
411{
412		if [ "${cmd}" = 'debug' -a "${opt}" = 'debug' ]; then
413			echo
414			echo "The commands will modify .config and files, and can't auto restore changes!"
415			echo "debug-N, the N:"
416			echo "    1. lib/initcall.c debug() -> printf()"
417			echo "    2. common/board_r.c and common/board_f.c debug() -> printf()"
418			echo "    3. global #define DEBUG"
419			echo "    4. enable CONFIG_ROCKCHIP_DEBUGGER"
420			echo "    5. enable CONFIG_ROCKCHIP_CRC"
421			echo "    6. enable CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP"
422			echo "    7. enable CONFIG_ROCKCHIP_CRASH_DUMP"
423			echo "    8. set CONFIG_BOOTDELAY=5"
424			echo "    9. armv7 start.S: print entry warning"
425			echo "   10. armv8 start.S: print entry warning"
426			echo "   11. firmware bootflow debug() -> printf()"
427			echo "   12. bootstage timing report"
428			echo
429			echo "Enabled: "
430			grep '^CONFIG_ROCKCHIP_DEBUGGER=y' ${OUTDIR}/.config > /dev/null \
431			&& echo "    CONFIG_ROCKCHIP_DEBUGGER"
432			grep '^CONFIG_ROCKCHIP_CRC=y' ${OUTDIR}/.config > /dev/null \
433			&& echo "    CONFIG_ROCKCHIP_CRC"
434			grep '^CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y' ${OUTDIR}/.config > /dev/null \
435			&& echo "    CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP"
436			grep '^CONFIG_ROCKCHIP_CRASH_DUMP=y' ${OUTDIR}/.config > /dev/null \
437			&& echo "    CONFIG_ROCKCHIP_CRASH_DUMP"
438
439		elif [ "${opt}" = '1' ]; then
440			sed -i 's/\<debug\>/printf/g' lib/initcall.c
441			sed -i 's/ifdef DEBUG/if 1/g' lib/initcall.c
442			echo "DEBUG [1]: lib/initcall.c debug() -> printf()"
443		elif [ "${opt}" = '2' ]; then
444			sed -i 's/\<debug\>/printf/g' ./common/board_f.c
445			sed -i 's/\<debug\>/printf/g' ./common/board_r.c
446			echo "DEBUG [2]: common/board_r.c and common/board_f.c debug() -> printf()"
447		elif [ "${opt}" = '3' ]; then
448			sed -i '$i \#define DEBUG\' include/configs/rockchip-common.h
449			echo "DEBUG [3]: global #define DEBUG"
450		elif [ "${opt}" = '4' ]; then
451			sed -i 's/\# CONFIG_ROCKCHIP_DEBUGGER is not set/CONFIG_ROCKCHIP_DEBUGGER=y/g' ${OUTDIR}/.config
452			echo "DEBUG [4]: CONFIG_ROCKCHIP_DEBUGGER is enabled"
453		elif [ "${opt}" = '5' ]; then
454			sed -i 's/\# CONFIG_ROCKCHIP_CRC is not set/CONFIG_ROCKCHIP_CRC=y/g' ${OUTDIR}/.config
455			echo "DEBUG [5]: CONFIG_ROCKCHIP_CRC is enabled"
456		elif [ "${opt}" = '6' ]; then
457			sed -i 's/\# CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP is not set/CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y/g' ${OUTDIR}/.config
458			echo "DEBUG [6]: CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP is enabled"
459		elif [ "${opt}" = '7' ]; then
460			sed -i 's/\# CONFIG_ROCKCHIP_CRASH_DUMP is not set/CONFIG_ROCKCHIP_CRASH_DUMP=y/g' ${OUTDIR}/.config
461			echo "DEBUG [7]: CONFIG_ROCKCHIP_CRASH_DUMP is enabled"
462		elif [ "${opt}" = '8' ]; then
463			sed -i 's/^CONFIG_BOOTDELAY=0/CONFIG_BOOTDELAY=5/g' ${OUTDIR}/.config
464			echo "DEBUG [8]: CONFIG_BOOTDELAY is 5s"
465		elif [ "${opt}" = '9' ]; then
466			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' \
467			./arch/arm/cpu/armv7/start.S
468			echo "DEBUG [9]: armv7 start.S entry warning 'UUUU...'"
469		elif [ "${opt}" = '10' ]; then
470			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' \
471			./arch/arm/cpu/armv8/start.S
472			echo "DEBUG [10]: armv8 start.S entry warning 'UUUU...'"
473		elif [ "${opt}" = '11' ]; then
474			sed -i 's/\<debug\>/printf/g' common/fdt_support.c
475			sed -i 's/\<debug\>/printf/g' common/image-fdt.c
476			sed -i 's/\<debug\>/printf/g' common/image.c
477			sed -i 's/\<debug\>/printf/g' arch/arm/lib/bootm.c
478			sed -i 's/\<debug\>/printf/g' common/bootm.c
479			sed -i 's/\<debug\>/printf/g' common/image.c
480			sed -i 's/\<debug\>/printf/g' common/image-android.c
481			sed -i 's/\<debug\>/printf/g' common/android_bootloader.c
482			echo "DEBUG [11]: firmware bootflow debug() -> printf()"
483		elif [ "${opt}" = '12' ]; then
484			sed -i '$a\CONFIG_BOOTSTAGE=y\' ${OUTDIR}/.config
485			sed -i '$a\CONFIG_BOOTSTAGE_REPORT=y\' ${OUTDIR}/.config
486			sed -i '$a\CONFIG_CMD_BOOTSTAGE=y\' ${OUTDIR}/.config
487			echo "DEBUG [12]: bootstage timing report"
488		fi
489		echo
490}
491
492pack_uboot_image()
493{
494	local UBOOT_LOAD_ADDR
495
496	UBOOT_LOAD_ADDR=`sed -n "/CONFIG_SYS_TEXT_BASE=/s/CONFIG_SYS_TEXT_BASE=//p" ${OUTDIR}/include/autoconf.mk|tr -d '\r'`
497	${RKTOOLS}/loaderimage --pack --uboot ${OUTDIR}/u-boot.bin uboot.img ${UBOOT_LOAD_ADDR} ${PLATFORM_UBOOT_IMG_SIZE}
498
499	# Delete u-boot.img and u-boot-dtb.img, which makes users not be confused with final uboot.img
500	if [ -f ${OUTDIR}/u-boot.img ]; then
501		rm ${OUTDIR}/u-boot.img
502	fi
503
504	if [ -f ${OUTDIR}/u-boot-dtb.img ]; then
505		rm ${OUTDIR}/u-boot-dtb.img
506	fi
507
508	echo "pack uboot okay! Input: ${OUTDIR}/u-boot.bin"
509}
510
511pack_loader_image()
512{
513	local mode=$1 files ini
514
515	if [ ! -f ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini ]; then
516		echo "pack loader failed! Can't find: ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini"
517		return
518	fi
519
520	cd ${RKBIN}
521
522	if [ "${mode}" = 'all' ]; then
523		files=`ls ${RKBIN}/RKBOOT/${RKCHIP_LOADER}*MINIALL*.ini`
524		for ini in $files
525		do
526			if [ -f "$ini" ]; then
527				${RKTOOLS}/boot_merger ${BIN_PATH_FIXUP} $ini
528				echo "pack loader okay! Input: $ini"
529			fi
530		done
531	else
532		${RKTOOLS}/boot_merger ${BIN_PATH_FIXUP} ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini
533		echo "pack loader okay! Input: ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini"
534	fi
535
536	cd - && mv ${RKBIN}/*_loader_*.bin ./
537}
538
539pack_trust_image()
540{
541	local TOS TOS_TA DARM_BASE TEE_LOAD_ADDR TEE_OFFSET=0x8400000
542
543	# ARM64 uses trust_merger
544	if grep -Eq ''^CONFIG_ARM64=y'|'^CONFIG_ARM64_BOOT_AARCH32=y'' ${OUTDIR}/.config ; then
545		if [ ! -f ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini ]; then
546			echo "pack trust failed! Can't find: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini"
547			return
548		fi
549
550		cd ${RKBIN}
551		${RKTOOLS}/trust_merger ${PLATFORM_SHA} ${PLATFORM_RSA} ${PLATFORM_TRUST_IMG_SIZE} ${BIN_PATH_FIXUP} ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini
552
553		cd - && mv ${RKBIN}/trust.img ./trust.img
554		echo "pack trust okay! Input: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini"
555	# ARM uses loaderimage
556	else
557		if [ ! -f ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini ]; then
558			echo "pack trust failed! Can't find: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini"
559			return
560		fi
561
562		# OP-TEE is 132M(0x8400000) offset from DRAM base.
563		DARM_BASE=`sed -n "/CONFIG_SYS_SDRAM_BASE=/s/CONFIG_SYS_SDRAM_BASE=//p" ${OUTDIR}/include/autoconf.mk|tr -d '\r'`
564		TEE_LOAD_ADDR=$((DARM_BASE+TEE_OFFSET))
565
566		# Convert Dec to Hex
567		TEE_LOAD_ADDR=$(echo "obase=16;${TEE_LOAD_ADDR}"|bc)
568
569		# Parse orignal path
570		TOS=`sed -n "/TOS=/s/TOS=//p" ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini|tr -d '\r'`
571		TOS_TA=`sed -n "/TOSTA=/s/TOSTA=//p" ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini|tr -d '\r'`
572
573		# replace "./tools/rk_tools/" with "./" to compatible legacy ini content of rkdevelop branch
574		TOS=$(echo ${TOS} | sed "s/tools\/rk_tools\//\.\//g")
575		TOS_TA=$(echo ${TOS_TA} | sed "s/tools\/rk_tools\//\.\//g")
576
577		if [ x$TOS_TA != x -a x$TOS != x ]; then
578			${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS} ./trust.img ${TEE_LOAD_ADDR} ${PLATFORM_TRUST_IMG_SIZE}
579			${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS_TA} ./trust_with_ta.img ${TEE_LOAD_ADDR} ${PLATFORM_TRUST_IMG_SIZE}
580			echo "Both trust.img and trust_with_ta.img are ready"
581		elif [ $TOS ]; then
582			${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS} ./trust.img ${TEE_LOAD_ADDR} ${PLATFORM_TRUST_IMG_SIZE}
583			echo "trust.img is ready"
584		elif [ $TOS_TA ]; then
585			${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS_TA} ./trust.img ${TEE_LOAD_ADDR} ${PLATFORM_TRUST_IMG_SIZE}
586			echo "trust.img with ta is ready"
587		else
588			echo "Can't find any tee bin"
589			exit 1
590		fi
591
592		echo "pack trust okay! Input: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini"
593	fi
594}
595
596finish()
597{
598	echo
599	if [ "$BOARD" = '' ]; then
600		echo "Platform ${RKCHIP_LABEL}${PLATFORM_AARCH32} is build OK, with exist .config"
601	else
602		echo "Platform ${RKCHIP_LABEL}${PLATFORM_AARCH32} is build OK, with new .config(make ${BOARD}_defconfig)"
603	fi
604}
605
606prepare
607select_toolchain
608select_chip_info
609fixup_platform_configure
610sub_commands
611make CROSS_COMPILE=${TOOLCHAIN_GCC}  all --jobs=${JOB} ${OUTOPT}
612pack_uboot_image
613pack_loader_image
614pack_trust_image
615finish
616