1#!/bin/sh 2set -e 3BOARD=$1 4DIR=${BOARD#*-} 5DSTDIR=rockdev/${DIR} 6RKCHIP=$(echo $DIR | tr '[a-z]' '[A-Z]') 7TOOLCHAIN=arm-linux-gnueabi- 8JOB=`sed -n "N;/processor/p" /proc/cpuinfo|wc -l` 9 10prepare() 11{ 12 local dst 13 14 # Check invaid args and help 15 if [ "$BOARD" = '--help' -o "$BOARD" = '-h' -o "$BOARD" = '--h' ]; then 16 echo 17 echo "Usage: ./make.sh board" 18 echo "Example:" 19 echo "./make.sh evb-rk3399 ---- build for evb-rk3399_defconfig" 20 echo "./make.sh firefly-rk3288 ---- build for firefly-rk3288_defconfig" 21 exit 1 22 elif [ ! -f configs/${BOARD}_defconfig ]; then 23 echo "Can't find: configs/${BOARD}_defconfig" 24 exit 1 25 fi 26 27 # Initialize RKBIN and RKTOOLS 28 dst=../rkbin/tools 29 if [ -d ${dst} ]; then 30 RKBIN=$(cd `dirname ${dst}`; pwd) 31 RKTOOLS=${RKBIN}/tools 32 else 33 echo 34 echo "Can't find '../rkbin/' Responsity, please download it before pack image!" 35 echo "How to obtain? 3 ways:" 36 echo " 1. Login your Rockchip gerrit account: \"Projects\" -> \"List\" -> search \"rk/rkbin\" Responsity" 37 echo " 2. Github Responsity: https://github.com/rockchip-linux/rkbin" 38 echo " 3. Download full release SDK Responsity" 39 exit 1 40 fi 41} 42 43select_toolchain() 44{ 45 local dst path 46 if grep -q '^CONFIG_ARM64=y' ${DSTDIR}/out/.config ; then 47 TOOLCHAIN=aarch64-linux-gnu- 48 dst=../prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin 49 if [ -d ${dst} ]; then 50 path=$(cd `dirname ${dst}`; pwd) 51 TOOLCHAIN=${path}/bin/aarch64-linux-android- 52 fi 53 else 54 dst=../prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin 55 if [ -d ${dst} ]; then 56 path=$(cd `dirname ${dst}`; pwd) 57 TOOLCHAIN=${path}/bin/arm-linux-androideabi- 58 fi 59 fi 60 echo toolchain: ${TOOLCHAIN} 61} 62 63pack_uboot_image() 64{ 65 local UBOOT_LOAD_ADDR 66 67 UBOOT_LOAD_ADDR=`sed -n "/CONFIG_SYS_TEXT_BASE=/s/CONFIG_SYS_TEXT_BASE=//p" ${DSTDIR}/out/include/autoconf.mk|tr -d '\r'` 68 ${RKTOOLS}/loaderimage --pack --uboot ${DSTDIR}/out/u-boot.bin uboot.img ${UBOOT_LOAD_ADDR} 69} 70 71pack_loader_image() 72{ 73 cd ${RKBIN} 74 ${RKTOOLS}/boot_merger ${RKBIN}/RKBOOT/${RKCHIP}MINIALL.ini 75 cd - 76 mv ${RKBIN}/*_loader_*.bin ./ 77} 78 79pack_trust_image() 80{ 81 local TOS TOS_TA DARM_BASE TEE_LOAD_ADDR TEE_OFFSET=0x8400000 82 83 # ARM64 uses trust_merger 84 if grep -q '^CONFIG_ARM64=y' ${DSTDIR}/out/.config ; then 85 cd ${RKBIN} 86 ${RKTOOLS}/trust_merger ${RKBIN}/RKTRUST/${RKCHIP}TRUST.ini 87 cd - 88 mv ${RKBIN}/trust.img ./trust.img 89 # ARM uses loaderimage 90 else 91 # OP-TEE is 132M(0x8400000) offset from DRAM base. 92 DARM_BASE=`sed -n "/CONFIG_SYS_SDRAM_BASE=/s/CONFIG_SYS_SDRAM_BASE=//p" ${DSTDIR}/out/include/autoconf.mk|tr -d '\r'` 93 TEE_LOAD_ADDR=$((DARM_BASE+TEE_OFFSET)) 94 95 # Convert Dec to Hex 96 TEE_LOAD_ADDR=$(echo "obase=16;${TEE_LOAD_ADDR}"|bc) 97 98 TOS=`sed -n "/TOS=/s/TOS=//p" ${RKBIN}/RKTRUST/${RKCHIP}TOS.ini|tr -d '\r'` 99 TOS_TA=`sed -n "/TOSTA=/s/TOSTA=//p" ${RKBIN}/RKTRUST/${RKCHIP}TOS.ini|tr -d '\r'` 100 101 if [ $TOS_TA -a $TOS ]; then 102 ${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS} ./trust.img ${TEE_LOAD_ADDR} 103 ${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS_TA} ./trust_with_ta.img ${TEE_LOAD_ADDR} 104 echo "Both trust.img and trust_with_ta.img are ready" 105 elif [ $TOS ]; then 106 ${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS} ./trust.img ${TEE_LOAD_ADDR} 107 echo "trust.img is ready" 108 elif [ $TOS_TA ]; then 109 ${RKTOOLS}/loaderimage --pack --trustos ${RKBIN}/${TOS_TA} ./trust.img ${TEE_LOAD_ADDR} 110 echo "trust.img with ta is ready" 111 else 112 echo "Can't find any tee bin" 113 exit 1 114 fi 115 fi 116} 117 118prepare 119echo "make for ${BOARD}_defconfig by -j${JOB}" 120make ${BOARD}_defconfig O=${DSTDIR}/out 121select_toolchain 122make CROSS_COMPILE=${TOOLCHAIN} all --jobs=${JOB} O=${DSTDIR}/out 123pack_loader_image 124pack_uboot_image 125pack_trust_image 126 127