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