1#!/bin/bash 2set -ex 3 4HDF_FILE=$1 5UBOOT_FILE=$2 6BUILD_DIR=build_boot_bin 7OUTPUT_DIR=output_boot_bin 8 9usage () { 10 echo "usage: $0 system_top.<hdf/xsa> u-boot.elf [output-archive]" 11 exit 1 12} 13 14depends () { 15 echo Xilinx $1 must be installed and in your PATH 16 echo try: source /opt/Xilinx/Vivado/201x.x/settings64.sh 17 exit 1 18} 19 20### Check command line parameters 21echo $HDF_FILE | grep -q ".hdf\|.xsa" || usage 22echo $UBOOT_FILE | grep -q -e ".elf" -e "uboot" -e "u-boot"|| usage 23 24if [ ! -f $HDF_FILE ]; then 25 echo $HDF_FILE: File not found! 26 usage 27fi 28 29if [ ! -f $UBOOT_FILE ]; then 30 echo $UBOOT_FILE: File not found! 31 usage 32fi 33 34### Check for required Xilinx tools (xcst is equivalent with 'xsdk -batch') 35command -v xsct >/dev/null 2>&1 || depends xsct 36command -v bootgen >/dev/null 2>&1 || depends bootgen 37 38rm -Rf $BUILD_DIR $OUTPUT_DIR 39mkdir -p $OUTPUT_DIR 40mkdir -p $BUILD_DIR 41 42cp $HDF_FILE $BUILD_DIR/ 43cp $UBOOT_FILE $OUTPUT_DIR/u-boot.elf 44cp $HDF_FILE $OUTPUT_DIR/ 45 46### Create create_fsbl_project.tcl file used by xsct to create the fsbl. 47echo "hsi open_hw_design `basename $HDF_FILE`" > $BUILD_DIR/create_fsbl_project.tcl 48echo 'set cpu_name [lindex [hsi get_cells -filter {IP_TYPE==PROCESSOR}] 0]' >> $BUILD_DIR/create_fsbl_project.tcl 49### The fsbl creating flow is different starting with 2019.2 Xilinx version 50if [[ "$HDF_FILE" =~ ".hdf" ]];then 51 echo 'sdk setws ./build/sdk' >> $BUILD_DIR/create_fsbl_project.tcl 52 echo "sdk createhw -name hw_0 -hwspec `basename $HDF_FILE`" >> $BUILD_DIR/create_fsbl_project.tcl 53 echo 'sdk createapp -name fsbl -hwproject hw_0 -proc $cpu_name -os standalone -lang C -app {Zynq FSBL}' >> $BUILD_DIR/create_fsbl_project.tcl 54 echo 'configapp -app fsbl build-config release' >> $BUILD_DIR/create_fsbl_project.tcl 55 echo 'sdk projects -build -type all' >> $BUILD_DIR/create_fsbl_project.tcl 56 57 FSBL_PATH="$BUILD_DIR/build/sdk/fsbl/Release/fsbl.elf" 58 SYSTEM_TOP_BIT_PATH="$BUILD_DIR/build/sdk/hw_0/system_top.bit" 59else 60 echo 'platform create -name hw0 -hw system_top.xsa -os standalone -out ./build/sdk -proc $cpu_name' >> $BUILD_DIR/create_fsbl_project.tcl 61 echo 'platform generate' >> $BUILD_DIR/create_fsbl_project.tcl 62 63 FSBL_PATH="$BUILD_DIR/build/sdk/hw0/export/hw0/sw/hw0/boot/fsbl.elf" 64 SYSTEM_TOP_BIT_PATH="$BUILD_DIR/build/sdk/hw0/hw/system_top.bit" 65fi 66 67### Create zynq.bif file used by bootgen 68echo 'the_ROM_image:' > $OUTPUT_DIR/zynq.bif 69echo '{' >> $OUTPUT_DIR/zynq.bif 70echo '[bootloader] fsbl.elf' >> $OUTPUT_DIR/zynq.bif 71echo 'system_top.bit' >> $OUTPUT_DIR/zynq.bif 72echo 'u-boot.elf' >> $OUTPUT_DIR/zynq.bif 73echo '}' >> $OUTPUT_DIR/zynq.bif 74 75### Build fsbl.elf 76( 77 cd $BUILD_DIR 78 xsct create_fsbl_project.tcl 79) 80 81### Copy fsbl and system_top.bit into the output folder 82cp $FSBL_PATH $OUTPUT_DIR/fsbl.elf 83cp $SYSTEM_TOP_BIT_PATH $OUTPUT_DIR/system_top.bit 84 85### Build BOOT.BIN 86( 87 cd $OUTPUT_DIR 88 bootgen -arch zynq -image zynq.bif -o BOOT.BIN -w 89) 90 91### Optionally tar.gz the entire output folder with the name given in argument 3 92if [ ${#3} -ne 0 ]; then 93 tar czvf $3.tar.gz $OUTPUT_DIR 94fi 95