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 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" || usage 22echo $UBOOT_FILE | grep -q -e ".elf" -e "uboot" || 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 35command -v xsdk >/dev/null 2>&1 || depends xsdk 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 xsdk 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 49echo 'sdk setws ./build/sdk' >> $BUILD_DIR/create_fsbl_project.tcl 50echo "sdk createhw -name hw_0 -hwspec `basename $HDF_FILE`" >> $BUILD_DIR/create_fsbl_project.tcl 51echo 'sdk createapp -name fsbl -hwproject hw_0 -proc $cpu_name -os standalone -lang C -app {Zynq FSBL}' >> $BUILD_DIR/create_fsbl_project.tcl 52echo 'configapp -app fsbl build-config release' >> $BUILD_DIR/create_fsbl_project.tcl 53echo 'sdk projects -build -type all' >> $BUILD_DIR/create_fsbl_project.tcl 54 55### Create zynq.bif file used by bootgen 56echo 'the_ROM_image:' > $OUTPUT_DIR/zynq.bif 57echo '{' >> $OUTPUT_DIR/zynq.bif 58echo '[bootloader] fsbl.elf' >> $OUTPUT_DIR/zynq.bif 59echo 'system_top.bit' >> $OUTPUT_DIR/zynq.bif 60echo 'u-boot.elf' >> $OUTPUT_DIR/zynq.bif 61echo '}' >> $OUTPUT_DIR/zynq.bif 62 63### Build fsbl.elf 64( 65 cd $BUILD_DIR 66 xsdk -batch -source create_fsbl_project.tcl 67) 68 69### Copy fsbl and system_top.bit into the output folder 70cp $BUILD_DIR/build/sdk/fsbl/Release/fsbl.elf $OUTPUT_DIR/fsbl.elf 71cp $BUILD_DIR/build/sdk/hw_0/system_top.bit $OUTPUT_DIR/system_top.bit 72 73### Build BOOT.BIN 74( 75 cd $OUTPUT_DIR 76 bootgen -arch zynq -image zynq.bif -o BOOT.BIN -w 77) 78 79### clean up BUILD_DIR and copy ILA definition together with .bit into OUTPUT_DIR 80( 81 rm $BUILD_DIR -rf 82) 83 84### Optionally tar.gz the entire output folder with the name given in argument 3 85if [ ${#3} -ne 0 ]; then 86 tar czvf $3.tar.gz $OUTPUT_DIR 87fi 88