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