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