xref: /openwifi/kernel_boot/build_boot_bin.sh (revision efa47b29f6d5d373a45064351dbcfb7ff5720ddb)
1#!/bin/bash
2
3# Author: Xianjun Jiao
4# SPDX-FileCopyrightText: 2019 UGent
5# SPDX-License-Identifier: AGPL-3.0-or-later
6# https://wiki.analog.com/resources/eval/user-guides/ad-fmcomms2-ebz/software/linux/zynq_2014r2
7
8if [ "$#" -ne 2 ]; then
9    echo "You must enter the \$OPENWIFI_HW_DIR \$BOARD_NAME as argument"
10    echo "BOARD_NAME Like: sdrpi antsdr_e200 antsdr adrv9364z7020 adrv9361z7035 zc706_fmcs2 zed_fmcs2 zc702_fmcs2 zcu102_fmcs2 zcu102_9371"
11    exit 1
12fi
13
14OPENWIFI_HW_DIR=$1
15BOARD_NAME=$2
16
17if [ "$BOARD_NAME" != "antsdr" ] && [ "$BOARD_NAME" != "antsdr_e200" ] && [ "$BOARD_NAME" != "sdrpi" ] && [ "$BOARD_NAME" != "zc706_fmcs2" ] && [ "$BOARD_NAME" != "zc702_fmcs2" ] && [ "$BOARD_NAME" != "zed_fmcs2" ] && [ "$BOARD_NAME" != "adrv9361z7035" ] && [ "$BOARD_NAME" != "adrv9364z7020" ] && [ "$BOARD_NAME" != "zcu102_fmcs2" ] && [ "$BOARD_NAME" != "zcu102_9371" ]; then
18    echo "\$BOARD_NAME is not correct. Please check!"
19    exit 1
20else
21    echo "\$BOARD_NAME is found!"
22fi
23
24set -ex
25
26HDF_FILE=$OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/system_top_hw_platform_0/system.hdf
27UBOOT_FILE=./boards/$BOARD_NAME/u-boot.elf
28BUILD_DIR=./boards/$BOARD_NAME/build_boot_bin
29OUTPUT_DIR=./boards/$BOARD_NAME/output_boot_bin
30
31# usage () {
32# 	echo usage: $0 system_top.hdf u-boot.elf [output-archive]
33# 	exit 1
34# }
35
36# depends () {
37# 	echo Xilinx $1 must be installed and in your PATH
38# 	echo try: source /opt/Xilinx/Vivado/201x.x/settings64.sh
39# 	exit 1
40# }
41
42### Check command line parameters
43echo $HDF_FILE | grep -q ".hdf" || usage
44echo $UBOOT_FILE | grep -q -e ".elf" -e "uboot" || usage
45
46if [ ! -f $HDF_FILE ]; then
47    echo $HDF_FILE: File not found!
48    usage
49fi
50
51if [ ! -f $UBOOT_FILE ]; then
52    echo $UBOOT_FILE: File not found!
53    usage
54fi
55
56### Check for required Xilinx tools
57command -v xsdk >/dev/null 2>&1 || depends xsdk
58command -v bootgen >/dev/null 2>&1 || depends bootgen
59
60rm -Rf $BUILD_DIR $OUTPUT_DIR
61mkdir -p $OUTPUT_DIR
62mkdir -p $BUILD_DIR
63
64cp $HDF_FILE $BUILD_DIR/
65cp $UBOOT_FILE $OUTPUT_DIR/u-boot.elf
66cp $HDF_FILE $OUTPUT_DIR/
67
68### Create create_fsbl_project.tcl file used by xsdk to create the fsbl
69echo "hsi open_hw_design `basename $HDF_FILE`" > $BUILD_DIR/create_fsbl_project.tcl
70echo 'set cpu_name [lindex [hsi get_cells -filter {IP_TYPE==PROCESSOR}] 0]' >> $BUILD_DIR/create_fsbl_project.tcl
71echo 'sdk setws ./build/sdk' >> $BUILD_DIR/create_fsbl_project.tcl
72echo "sdk createhw -name hw_0 -hwspec `basename $HDF_FILE`" >> $BUILD_DIR/create_fsbl_project.tcl
73echo 'sdk createapp -name fsbl -hwproject hw_0 -proc $cpu_name -os standalone -lang C -app {Zynq FSBL}' >> $BUILD_DIR/create_fsbl_project.tcl
74echo 'configapp -app fsbl build-config release' >> $BUILD_DIR/create_fsbl_project.tcl
75echo 'sdk projects -build -type all' >> $BUILD_DIR/create_fsbl_project.tcl
76
77### Create zynq.bif file used by bootgen
78echo 'the_ROM_image:' > $OUTPUT_DIR/zynq.bif
79echo '{' >> $OUTPUT_DIR/zynq.bif
80echo '[bootloader] fsbl.elf' >> $OUTPUT_DIR/zynq.bif
81echo 'system_top.bit' >> $OUTPUT_DIR/zynq.bif
82echo 'u-boot.elf' >> $OUTPUT_DIR/zynq.bif
83echo '}' >> $OUTPUT_DIR/zynq.bif
84
85### Build fsbl.elf
86(
87	cd $BUILD_DIR
88	xsdk -batch -source create_fsbl_project.tcl
89)
90
91### Copy fsbl and system_top.bit into the output folder
92cp $BUILD_DIR/build/sdk/fsbl/Release/fsbl.elf $OUTPUT_DIR/fsbl.elf
93cp $BUILD_DIR/build/sdk/hw_0/system_top.bit $OUTPUT_DIR/system_top.bit
94
95### Build BOOT.BIN
96(
97	cd $OUTPUT_DIR
98	bootgen -arch zynq -image zynq.bif -o BOOT.BIN -w
99)
100
101### clean up BUILD_DIR and copy ILA definition together with .bit into OUTPUT_DIR
102(
103	rm $BUILD_DIR -rf
104)
105
106# ### Optionally tar.gz the entire output folder with the name given in argument 3
107# if [ ${#3} -ne 0 ]; then
108# 	tar czvf $3.tar.gz $OUTPUT_DIR
109# fi
110