1#!/usr/bin/env bash 2 3set -o errexit 4set -o pipefail 5set -o nounset 6 7set -o xtrace 8 9# The goal of this script is gather all binaries provides by AML in order to generate 10# our final u-boot image from the u-boot.bin (bl33) 11# 12# Some binaries come from the u-boot vendor kernel (bl21, acs, bl301) 13# Others from the buildroot package (aml_encrypt tool, bl2.bin, bl30) 14 15function usage() { 16 echo "Usage: $0 [openlinux branch] [soc] [refboard]" 17} 18 19if [[ $# -lt 3 ]] 20then 21 usage 22 exit 22 23fi 24 25GITBRANCH=${1} 26SOCFAMILY=${2} 27REFBOARD=${3} 28 29if [[ "$SOCFAMILY" == "sm1" ]] 30then 31 SOCFAMILY="g12a" 32fi 33 34if ! [[ "$SOCFAMILY" == "g12a" || "$SOCFAMILY" == "g12b" || "$SOCFAMILY" == "sm1" ]] 35then 36 echo "${SOCFAMILY} is not supported - should be [g12a, g12b, sm1]" 37 usage 38 exit 22 39fi 40 41BIN_LIST="$SOCFAMILY/bl2.bin \ 42 $SOCFAMILY/bl30.bin \ 43 $SOCFAMILY/bl31.bin \ 44 $SOCFAMILY/bl31.img \ 45 $SOCFAMILY/aml_encrypt_$SOCFAMILY " 46 47FW_LIST="$SOCFAMILY/*.fw" 48 49# path to clone the openlinux repos 50TMP_GIT=$(mktemp -d) 51 52TMP="fip-collect-${SOCFAMILY}-${REFBOARD}-${GITBRANCH}-$(date +%Y%m%d-%H%M%S)" 53mkdir $TMP 54 55# U-Boot 56git clone --depth=2 https://github.com/khadas/u-boot -b $GITBRANCH $TMP_GIT/u-boot 57 58mkdir $TMP_GIT/gcc-linaro-aarch64-none-elf 59wget -qO- https://releases.linaro.org/archive/13.11/components/toolchain/binaries/gcc-linaro-aarch64-none-elf-4.8-2013.11_linux.tar.xz | tar -xJ --strip-components=1 -C $TMP_GIT/gcc-linaro-aarch64-none-elf 60mkdir $TMP_GIT/gcc-linaro-arm-none-eabi 61wget -qO- https://releases.linaro.org/archive/13.11/components/toolchain/binaries/gcc-linaro-arm-none-eabi-4.8-2013.11_linux.tar.xz | tar -xJ --strip-components=1 -C $TMP_GIT/gcc-linaro-arm-none-eabi 62sed -i "s,/opt/gcc-.*/bin/,," $TMP_GIT/u-boot/Makefile 63( 64 cd $TMP_GIT/u-boot 65 make ${REFBOARD}_defconfig 66 PATH=$TMP_GIT/gcc-linaro-aarch64-none-elf/bin:$TMP_GIT/gcc-linaro-arm-none-eabi/bin:$PATH CROSS_COMPILE=aarch64-none-elf- make -j8 > /dev/null 67 cd fip/tools/ddr_parse && make clean && make 68) 69 70cp $TMP_GIT/u-boot/build/board/khadas/*/firmware/acs.bin $TMP/ 71cp $TMP_GIT/u-boot/build/scp_task/bl301.bin $TMP/ 72# cp $TMP_GIT/u-boot/fip/tools/ddr_parse/parse $TMP/ 73$TMP_GIT/u-boot/fip/tools/ddr_parse/parse ${TMP}/acs.bin 74# FIP/BLX 75echo $BIN_LIST 76for item in $BIN_LIST 77do 78 BIN=$(echo $item) 79 DIR1=$TMP_GIT/u-boot/$(basename --suffix=.bin $item)/bin/ 80 DIR2=$TMP_GIT/u-boot/$(basename --suffix=.img $item)_1.3/bin/ 81 DIR21=$TMP_GIT/u-boot/$(basename --suffix=.bin $item)_1.3/bin/ 82 DIR22=$TMP_GIT/u-boot/$(basename --suffix=.img $item)_1.3/bin/ 83 BRANCH=$GITBRANCH 84 85 if [[ -d $DIR1/$SOCFAMILY/ ]] 86 then 87 cp $DIR1/$BIN ${TMP} 88 elif [[ -d $DIR2/$SOCFAMILY/ ]] 89 then 90 cp $DIR2/$BIN ${TMP} 91 elif [[ -d $DIR21/$SOCFAMILY/ ]] 92 then 93 cp $DIR21/$BIN ${TMP} 94 elif [[ -d $DIR22/$SOCFAMILY/ ]] 95 then 96 cp $DIR22/$BIN ${TMP} 97 fi 98 99done 100 101echo $FW_LIST 102cp $TMP_GIT/u-boot/fip/$FW_LIST ${TMP} 103 104 105# Normalize 106mv $TMP_GIT/u-boot/fip/$SOCFAMILY/aml_encrypt_$SOCFAMILY $TMP/aml_encrypt 107 108date > $TMP/info.txt 109echo "SOC: $SOCFAMILY" >> $TMP/info.txt 110echo "BRANCH: $GITBRANCH ($(date +%Y%m%d))" >> $TMP/info.txt 111for component in $TMP_GIT/* 112do 113 if [[ -d $component/.git ]] 114 then 115 echo "$(basename $component): $(git --git-dir=$component/.git log --pretty=format:%H HEAD~1..HEAD)" >> $TMP/info.txt 116 fi 117done 118echo "BOARD: $REFBOARD" >> $TMP/info.txt 119echo "export SOCFAMILY=$SOCFAMILY" > $TMP/soc-var.sh 120 121rm -rf ${TMP_GIT} 122