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 else 338 echo "Can't get Rockchip SoC definition in .config" 339 exit 1 340 fi 341 342 # Default use RKCHIP 343 RKCHIP_LABEL=${RKCHIP} 344 RKCHIP_LOADER=${RKCHIP} 345 RKCHIP_TRUST=${RKCHIP} 346 347 # Read from RKCHIP_INI_DESC 348 for item in "${RKCHIP_INI_DESC[@]}" 349 do 350 target_board=`echo $item | awk '{ print $1 }'` 351 if grep -q "^${target_board}=y" ${OUTDIR}/.config ; then 352 value=`echo $item | awk '{ print $2 }'` 353 if [ "$value" != "NA" ]; then 354 RKCHIP_LABEL=${value}; 355 fi 356 value=`echo $item | awk '{ print $3 }'` 357 if [ "$value" != "NA" ]; then 358 RKCHIP_LOADER=${value}; 359 fi 360 value=`echo $item | awk '{ print $4 }'` 361 if [ "$value" != "NA" ]; then 362 RKCHIP_TRUST=${value}; 363 fi 364 fi 365 done 366} 367 368# Fixup platform special configure 369# 1. fixup pack mode; 370# 2. fixup image size 371# 3. fixup ARM64 cpu boot with AArch32 372fixup_platform_configure() 373{ 374 local count plat 375 376# <*> Fixup rsa/sha pack mode for platforms 377 # RK3308/PX30/RK3326/RK1808 use RSA-PKCS1 V2.1, it's pack magic is "3" 378 if [ $RKCHIP = "PX30" -o $RKCHIP = "RK3326" -o $RKCHIP = "RK3308" -o $RKCHIP = "RK1808" ]; then 379 PLATFORM_RSA="--rsa 3" 380 # RK3368 use rk big endian SHA256, it's pack magic is "2" 381 elif [ $RKCHIP = "RK3368" ]; then 382 PLATFORM_SHA="--sha 2" 383 # other platforms use default configure 384 fi 385 386# <*> Fixup images size pack for platforms 387 if [ $RKCHIP = "RK3308" ]; then 388 if grep -q '^CONFIG_ARM64_BOOT_AARCH32=y' ${OUTDIR}/.config ; then 389 PLATFORM_UBOOT_IMG_SIZE="--size 512 2" 390 PLATFORM_TRUST_IMG_SIZE="--size 512 2" 391 else 392 PLATFORM_UBOOT_IMG_SIZE="--size 1024 2" 393 PLATFORM_TRUST_IMG_SIZE="--size 1024 2" 394 fi 395 fi 396 397# <*> Fixup PLATFORM_AARCH32 for ARM64 cpu platforms 398 if [ $RKCHIP = "RK3308" ]; then 399 if grep -q '^CONFIG_ARM64_BOOT_AARCH32=y' ${OUTDIR}/.config ; then 400 PLATFORM_AARCH32="AARCH32" 401 fi 402 fi 403} 404 405debug_command() 406{ 407 if [ "${cmd}" = 'debug' -a "${opt}" = 'debug' ]; then 408 echo 409 echo "The commands will modify .config and files, and can't auto restore changes!" 410 echo "debug-N, the N:" 411 echo " 1. lib/initcall.c debug() -> printf()" 412 echo " 2. common/board_r.c and common/board_f.c debug() -> printf()" 413 echo " 3. global #define DEBUG" 414 echo " 4. enable CONFIG_ROCKCHIP_DEBUGGER" 415 echo " 5. enable CONFIG_ROCKCHIP_CRC" 416 echo " 6. enable CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP" 417 echo " 7. enable CONFIG_ROCKCHIP_CRASH_DUMP" 418 echo " 8. set CONFIG_BOOTDELAY=5" 419 echo " 9. armv7 start.S: print entry warning" 420 echo " 10. armv8 start.S: print entry warning" 421 echo " 11. firmware bootflow debug() -> printf()" 422 echo 423 echo "Enabled: " 424 grep '^CONFIG_ROCKCHIP_DEBUGGER=y' ${OUTDIR}/.config > /dev/null \ 425 && echo " CONFIG_ROCKCHIP_DEBUGGER" 426 grep '^CONFIG_ROCKCHIP_CRC=y' ${OUTDIR}/.config > /dev/null \ 427 && echo " CONFIG_ROCKCHIP_CRC" 428 grep '^CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y' ${OUTDIR}/.config > /dev/null \ 429 && echo " CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP" 430 grep '^CONFIG_ROCKCHIP_CRASH_DUMP=y' ${OUTDIR}/.config > /dev/null \ 431 && echo " CONFIG_ROCKCHIP_CRASH_DUMP" 432 433 elif [ "${opt}" = '1' ]; then 434 sed -i 's/\<debug\>/printf/g' lib/initcall.c 435 sed -i 's/ifdef DEBUG/if 1/g' lib/initcall.c 436 echo "DEBUG [1]: lib/initcall.c debug() -> printf()" 437 elif [ "${opt}" = '2' ]; then 438 sed -i 's/\<debug\>/printf/g' ./common/board_f.c 439 sed -i 's/\<debug\>/printf/g' ./common/board_r.c 440 echo "DEBUG [2]: common/board_r.c and common/board_f.c debug() -> printf()" 441 elif [ "${opt}" = '3' ]; then 442 sed -i '$i \#define DEBUG\' include/configs/rockchip-common.h 443 echo "DEBUG [3]: global #define DEBUG" 444 elif [ "${opt}" = '4' ]; then 445 sed -i 's/\# CONFIG_ROCKCHIP_DEBUGGER is not set/CONFIG_ROCKCHIP_DEBUGGER=y/g' ${OUTDIR}/.config 446 echo "DEBUG [4]: CONFIG_ROCKCHIP_DEBUGGER is enabled" 447 elif [ "${opt}" = '5' ]; then 448 sed -i 's/\# CONFIG_ROCKCHIP_CRC is not set/CONFIG_ROCKCHIP_CRC=y/g' ${OUTDIR}/.config 449 echo "DEBUG [5]: CONFIG_ROCKCHIP_CRC is enabled" 450 elif [ "${opt}" = '6' ]; then 451 sed -i 's/\# CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP is not set/CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y/g' ${OUTDIR}/.config 452 echo "DEBUG [6]: CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP is enabled" 453 elif [ "${opt}" = '7' ]; then 454 sed -i 's/\# CONFIG_ROCKCHIP_CRASH_DUMP is not set/CONFIG_ROCKCHIP_CRASH_DUMP=y/g' ${OUTDIR}/.config 455 echo "DEBUG [7]: CONFIG_ROCKCHIP_CRASH_DUMP is enabled" 456 elif [ "${opt}" = '8' ]; then 457 sed -i 's/^CONFIG_BOOTDELAY=0/CONFIG_BOOTDELAY=5/g' ${OUTDIR}/.config 458 echo "DEBUG [8]: CONFIG_BOOTDELAY is 5s" 459 elif [ "${opt}" = '9' ]; then 460 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' \ 461 ./arch/arm/cpu/armv7/start.S 462 echo "DEBUG [9]: armv7 start.S entry warning 'UUUU...'" 463 elif [ "${opt}" = '10' ]; then 464 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' \ 465 ./arch/arm/cpu/armv8/start.S 466 echo "DEBUG [10]: armv8 start.S entry warning 'UUUU...'" 467 elif [ "${opt}" = '11' ]; then 468 sed -i 's/\<debug\>/printf/g' common/fdt_support.c 469 sed -i 's/\<debug\>/printf/g' common/image-fdt.c 470 sed -i 's/\<debug\>/printf/g' common/image.c 471 sed -i 's/\<debug\>/printf/g' arch/arm/lib/bootm.c 472 sed -i 's/\<debug\>/printf/g' common/bootm.c 473 sed -i 's/\<debug\>/printf/g' common/image.c 474 sed -i 's/\<debug\>/printf/g' common/image-android.c 475 sed -i 's/\<debug\>/printf/g' common/android_bootloader.c 476 echo "DEBUG [11]: firmware bootflow debug() -> printf()" 477 fi 478 echo 479} 480 481pack_uboot_image() 482{ 483 local UBOOT_LOAD_ADDR 484 485 UBOOT_LOAD_ADDR=`sed -n "/CONFIG_SYS_TEXT_BASE=/s/CONFIG_SYS_TEXT_BASE=//p" ${OUTDIR}/include/autoconf.mk|tr -d '\r'` 486 ${RKTOOLS}/loaderimage --pack --uboot ${OUTDIR}/u-boot.bin uboot.img ${UBOOT_LOAD_ADDR} ${PLATFORM_UBOOT_IMG_SIZE} 487 488 # Delete u-boot.img and u-boot-dtb.img, which makes users not be confused with final uboot.img 489 if [ -f ${OUTDIR}/u-boot.img ]; then 490 rm ${OUTDIR}/u-boot.img 491 fi 492 493 if [ -f ${OUTDIR}/u-boot-dtb.img ]; then 494 rm ${OUTDIR}/u-boot-dtb.img 495 fi 496 497 echo "pack uboot okay! Input: ${OUTDIR}/u-boot.bin" 498} 499 500pack_loader_image() 501{ 502 local mode=$1 files ini 503 504 if [ ! -f ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini ]; then 505 echo "pack loader failed! Can't find: ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini" 506 return 507 fi 508 509 cd ${RKBIN} 510 511 if [ "${mode}" = 'all' ]; then 512 files=`ls ${RKBIN}/RKBOOT/${RKCHIP_LOADER}*MINIALL*.ini` 513 for ini in $files 514 do 515 if [ -f "$ini" ]; then 516 ${RKTOOLS}/boot_merger ${BIN_PATH_FIXUP} $ini 517 echo "pack loader okay! Input: $ini" 518 fi 519 done 520 else 521 ${RKTOOLS}/boot_merger ${BIN_PATH_FIXUP} ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini 522 echo "pack loader okay! Input: ${RKBIN}/RKBOOT/${RKCHIP_LOADER}MINIALL.ini" 523 fi 524 525 cd - && mv ${RKBIN}/*_loader_*.bin ./ 526} 527 528pack_trust_image() 529{ 530 local TOS TOS_TA DARM_BASE TEE_LOAD_ADDR TEE_OFFSET=0x8400000 531 532 # ARM64 uses trust_merger 533 if grep -Eq ''^CONFIG_ARM64=y'|'^CONFIG_ARM64_BOOT_AARCH32=y'' ${OUTDIR}/.config ; then 534 if [ ! -f ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini ]; then 535 echo "pack trust failed! Can't find: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini" 536 return 537 fi 538 539 cd ${RKBIN} 540 ${RKTOOLS}/trust_merger ${PLATFORM_SHA} ${PLATFORM_RSA} ${PLATFORM_TRUST_IMG_SIZE} ${BIN_PATH_FIXUP} ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini 541 542 cd - && mv ${RKBIN}/trust.img ./trust.img 543 echo "pack trust okay! Input: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}${PLATFORM_AARCH32}TRUST.ini" 544 # ARM uses loaderimage 545 else 546 if [ ! -f ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini ]; then 547 echo "pack trust failed! Can't find: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini" 548 return 549 fi 550 551 # OP-TEE is 132M(0x8400000) offset from DRAM base. 552 DARM_BASE=`sed -n "/CONFIG_SYS_SDRAM_BASE=/s/CONFIG_SYS_SDRAM_BASE=//p" ${OUTDIR}/include/autoconf.mk|tr -d '\r'` 553 TEE_LOAD_ADDR=$((DARM_BASE+TEE_OFFSET)) 554 555 # Convert Dec to Hex 556 TEE_LOAD_ADDR=$(echo "obase=16;${TEE_LOAD_ADDR}"|bc) 557 558 # Parse orignal path 559 TOS=`sed -n "/TOS=/s/TOS=//p" ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini|tr -d '\r'` 560 TOS_TA=`sed -n "/TOSTA=/s/TOSTA=//p" ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini|tr -d '\r'` 561 562 # replace "./tools/rk_tools/" with "./" to compatible legacy ini content of rkdevelop branch 563 TOS=$(echo ${TOS} | sed "s/tools\/rk_tools\//\.\//g") 564 TOS_TA=$(echo ${TOS_TA} | sed "s/tools\/rk_tools\//\.\//g") 565 566 if [ x$TOS_TA != x -a x$TOS != x ]; then 567 ${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS} ./trust.img ${TEE_LOAD_ADDR} ${PLATFORM_TRUST_IMG_SIZE} 568 ${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS_TA} ./trust_with_ta.img ${TEE_LOAD_ADDR} ${PLATFORM_TRUST_IMG_SIZE} 569 echo "Both trust.img and trust_with_ta.img are ready" 570 elif [ $TOS ]; then 571 ${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS} ./trust.img ${TEE_LOAD_ADDR} ${PLATFORM_TRUST_IMG_SIZE} 572 echo "trust.img is ready" 573 elif [ $TOS_TA ]; then 574 ${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS_TA} ./trust.img ${TEE_LOAD_ADDR} ${PLATFORM_TRUST_IMG_SIZE} 575 echo "trust.img with ta is ready" 576 else 577 echo "Can't find any tee bin" 578 exit 1 579 fi 580 581 echo "pack trust okay! Input: ${RKBIN}/RKTRUST/${RKCHIP_TRUST}TOS.ini" 582 fi 583} 584 585finish() 586{ 587 echo 588 if [ "$BOARD" = '' ]; then 589 echo "Platform ${RKCHIP_LABEL}${PLATFORM_AARCH32} is build OK, with exist .config" 590 else 591 echo "Platform ${RKCHIP_LABEL}${PLATFORM_AARCH32} is build OK, with new .config(make ${BOARD}_defconfig)" 592 fi 593} 594 595prepare 596select_toolchain 597select_chip_info 598fixup_platform_configure 599sub_commands 600make CROSS_COMPILE=${TOOLCHAIN_GCC} all --jobs=${JOB} ${OUTOPT} 601pack_uboot_image 602pack_loader_image 603pack_trust_image 604finish 605