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