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