2023-07-06 12:08:22 +00:00
|
|
|
###############################################################################
|
|
|
|
## Copyright (C) 2014-2023 Analog Devices, Inc. All rights reserved.
|
|
|
|
### SPDX short identifier: ADIBSD
|
|
|
|
###############################################################################
|
2018-11-26 14:09:48 +00:00
|
|
|
|
|
|
|
# script name adi_make_boot_bin.tcl
|
|
|
|
|
|
|
|
# -- HELP SECTION --
|
|
|
|
#
|
|
|
|
# This script was designed to work within the Xilinx tool command line interface
|
|
|
|
# Script arguments:
|
2021-07-14 07:34:38 +00:00
|
|
|
# 1 - xsa file location (default: ./system_top.xsa)
|
2018-11-26 14:09:48 +00:00
|
|
|
# 2 - u-boot.elf file location/name (default: ./u-boot.elf)
|
|
|
|
# 3 - build location (default: pwd: $PWD)"
|
|
|
|
# 4 - bl31.elf(mp soc projects only) file location
|
|
|
|
#
|
|
|
|
# The order of script arguments is mandatory.
|
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
# - adi_make_boot_bin.tcl
|
2021-07-14 07:34:38 +00:00
|
|
|
# - adi_make_boot_bin.tcl $xsa_path/system_top.xsa $uboot_path/u-boot.elf
|
|
|
|
# - adi_make_boot_bin.tcl $xsa_path/system_top.xsa $uboot_path/u-boot.elf $workspace
|
|
|
|
# - adi_make_boot_bin.tcl $xsa_path/system_top.xsa $uboot_path/u-boot.elf $workspace $arm_trf_repo/bl31.elf
|
2018-11-26 14:09:48 +00:00
|
|
|
|
|
|
|
set PWD [pwd]
|
|
|
|
|
2021-07-14 07:34:38 +00:00
|
|
|
# init variables
|
2018-11-26 14:09:48 +00:00
|
|
|
set app_type ""
|
2021-07-14 07:34:38 +00:00
|
|
|
set xsa_file ""
|
2018-11-26 14:09:48 +00:00
|
|
|
set uboot_file ""
|
|
|
|
|
2021-07-14 07:34:38 +00:00
|
|
|
# getting parsed arguments
|
|
|
|
set xsa_file [lindex $argv 0 ] ; # or .xsa(xilinx shell archive)
|
2018-11-26 14:09:48 +00:00
|
|
|
set uboot_file [lindex $argv 1]
|
|
|
|
set build_dir [lindex $argv 2]
|
|
|
|
set arm_tr_frm_file [lindex $argv 3]
|
|
|
|
|
2021-07-14 07:34:38 +00:00
|
|
|
# xsa file exists
|
|
|
|
if { $xsa_file == "" } {
|
|
|
|
set xsa_file system_top.xsa
|
|
|
|
if { ![file exists $xsa_file] } {
|
|
|
|
set xsa_file system_top.xsa
|
|
|
|
}
|
2018-11-26 14:09:48 +00:00
|
|
|
}
|
2021-07-14 07:34:38 +00:00
|
|
|
if { ![file exists $xsa_file] } {
|
|
|
|
puts "ERROR: xsa file location is not set nor located in $PWD"
|
2018-11-26 14:09:48 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
# uboot file exists
|
|
|
|
if { $uboot_file == "" } {
|
2021-07-14 07:34:38 +00:00
|
|
|
if {[catch {set uboot_file "[glob "./u-boot*.elf"]" } fid]} {
|
|
|
|
puts stderr "ERROR: $fid\n\rNOTE: you must have a the u-boot.elf in [pwd]\n\
|
|
|
|
\rSee: https://wiki.analog.com/resources/fpga/docs/build\n"
|
|
|
|
}
|
2018-11-26 14:09:48 +00:00
|
|
|
}
|
|
|
|
if { ![file exists $uboot_file] } {
|
2021-07-14 07:34:38 +00:00
|
|
|
puts "ERROR: uboot file location is not set, nor located in $PWD"
|
2018-11-26 14:09:48 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
# build dir defined
|
|
|
|
if { $build_dir == "" } {
|
|
|
|
set build_dir "boot_bin"
|
|
|
|
}
|
|
|
|
|
2021-07-14 07:34:38 +00:00
|
|
|
if { [file exists $build_dir] } {
|
|
|
|
file delete -force $build_dir
|
|
|
|
}
|
2018-11-26 14:09:48 +00:00
|
|
|
catch { file mkdir $build_dir } err
|
|
|
|
if { ![file exists $build_dir] } {
|
|
|
|
puts "ERROR: Failed to create \"$build_dir\" dir"
|
|
|
|
return
|
|
|
|
}
|
2021-07-14 07:34:38 +00:00
|
|
|
file copy -force $xsa_file $build_dir/system_top.xsa
|
2018-11-26 14:09:48 +00:00
|
|
|
file copy -force $uboot_file $build_dir
|
|
|
|
|
|
|
|
# Zynq MP arm trusted firwmware
|
|
|
|
if { $app_type == "Zynq MP FSBL" } {
|
|
|
|
if { $arm_tr_frm_file == "" } {
|
|
|
|
set arm_tr_frm_file bl31.elf
|
|
|
|
}
|
|
|
|
if { ![file exists $arm_tr_frm_file] } {
|
|
|
|
puts "ERROR: arm trusted firmware (bl31.el) file is not defined or located in $PWD"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# get cpu(app_type)
|
|
|
|
set cpu_name ""
|
|
|
|
set app_type ""
|
2021-07-14 07:34:38 +00:00
|
|
|
hsi open_hw_design $build_dir/system_top.xsa
|
2018-11-26 14:09:48 +00:00
|
|
|
set cpu_name [lindex [hsi get_cells -filter {IP_TYPE==PROCESSOR}] 0]
|
|
|
|
|
|
|
|
if { $cpu_name == ""} {
|
2021-07-14 07:34:38 +00:00
|
|
|
puts "ERROR: cpu name could not be determine from .xsa file"
|
2018-11-26 14:09:48 +00:00
|
|
|
return
|
|
|
|
} else {
|
|
|
|
if { [regexp psu_cortexa53.. $cpu_name] } {
|
|
|
|
set app_type "Zynq MP FSBL"
|
|
|
|
} elseif { [regexp ps7_cortexa9.. $cpu_name] } {
|
|
|
|
set app_type "Zynq FSBL"
|
|
|
|
} elseif { $cpu_name == "sys_mb" } {
|
|
|
|
puts "ERROR: boot_bin (first stage boot loader + ...) is design for arm processors"
|
|
|
|
return
|
|
|
|
} else {
|
2021-07-14 07:34:38 +00:00
|
|
|
puts "ERROR: unknown processor \"$cpu_name\" detected in $build_dir/system_top.xsa"
|
2018-11-26 14:09:48 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-07-14 07:34:38 +00:00
|
|
|
|
|
|
|
# Zynq MP arm trusted firwmware
|
|
|
|
if { $app_type == "Zynq MP FSBL" } {
|
|
|
|
if { $arm_tr_frm_file == "" } {
|
|
|
|
set arm_tr_frm_file bl31.elf
|
|
|
|
}
|
|
|
|
if { ![file exists $arm_tr_frm_file] } {
|
|
|
|
puts "ERROR: arm trusted firmware (bl31.el) file is not defined or located in $PWD"
|
|
|
|
} else {
|
|
|
|
file copy -force $arm_tr_frm_file $build_dir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-26 14:09:48 +00:00
|
|
|
puts "Using CPU $cpu_name"
|
|
|
|
|
|
|
|
# create zynq.bif for target app
|
|
|
|
|
|
|
|
set l_sq_bracket "\["
|
|
|
|
set r_sq_bracket "\]"
|
|
|
|
if { $app_type == "Zynq FSBL" } {
|
|
|
|
|
|
|
|
set zynq_bif [open "$build_dir/zynq.bif" a+]
|
|
|
|
puts $zynq_bif "the_ROM_image:"
|
|
|
|
puts $zynq_bif "{"
|
2021-07-14 07:34:38 +00:00
|
|
|
puts $zynq_bif "${l_sq_bracket}bootloader${r_sq_bracket} ./fsbl.elf"
|
2018-11-26 14:09:48 +00:00
|
|
|
puts $zynq_bif "./system_top.bit"
|
|
|
|
puts $zynq_bif "$uboot_file"
|
|
|
|
puts $zynq_bif "}"
|
|
|
|
close $zynq_bif
|
|
|
|
|
|
|
|
} elseif { $app_type == "Zynq MP FSBL" } {
|
|
|
|
|
|
|
|
set zynqmp_bif [open "$build_dir/zynqmp.bif" a+]
|
|
|
|
puts $zynqmp_bif "the_ROM_image:"
|
|
|
|
puts $zynqmp_bif "{"
|
2021-07-14 07:34:38 +00:00
|
|
|
puts $zynqmp_bif "${l_sq_bracket}pmufw_image${r_sq_bracket} ./pmufw.elf"
|
|
|
|
puts $zynqmp_bif "${l_sq_bracket}bootloader,destination_cpu=a53-0${r_sq_bracket} ./fsbl.elf"
|
2018-11-26 14:09:48 +00:00
|
|
|
puts $zynqmp_bif "${l_sq_bracket}destination_device=pl${r_sq_bracket} ./system_top.bit"
|
|
|
|
puts $zynqmp_bif "${l_sq_bracket}destination_cpu=a53-0,exception_level=el-3,trustzone${r_sq_bracket} $arm_tr_frm_file"
|
|
|
|
puts $zynqmp_bif "${l_sq_bracket}destination_cpu=a53-0,exception_level=el-2${r_sq_bracket} $uboot_file"
|
|
|
|
puts $zynqmp_bif "}"
|
|
|
|
close $zynqmp_bif
|
|
|
|
|
|
|
|
} else {
|
|
|
|
puts "ERROR: unknown \"$app_type\" when creating zynqx.bif "
|
|
|
|
return -level 0 -code error
|
|
|
|
}
|
|
|
|
|
|
|
|
# create fsbl_build.tcl script
|
|
|
|
set fsbl_build [open "$build_dir/fsbl_build.tcl" a+]
|
2021-07-14 07:34:38 +00:00
|
|
|
puts $fsbl_build "hsi open_hw_design system_top.xsa"
|
|
|
|
puts $fsbl_build "platform create -name hw0 -hw system_top.xsa -os standalone -out ./output -proc $cpu_name"
|
|
|
|
puts $fsbl_build "platform generate"
|
2018-11-26 14:09:48 +00:00
|
|
|
close $fsbl_build
|
|
|
|
|
|
|
|
cd $build_dir
|
|
|
|
|
2021-07-14 07:34:38 +00:00
|
|
|
if {[catch { [exec xsct fsbl_build.tcl] } msg]} {
|
|
|
|
puts "$msg"
|
|
|
|
}
|
|
|
|
puts "end of FSBL build"
|
|
|
|
|
|
|
|
file copy -force output/hw0/export/hw0/sw/hw0/boot/fsbl.elf .
|
2018-11-26 14:09:48 +00:00
|
|
|
|
|
|
|
if { $app_type == "Zynq FSBL" } {
|
|
|
|
exec bootgen -image zynq.bif -w -o i BOOT.BIN
|
|
|
|
} elseif { $app_type == "Zynq MP FSBL" } {
|
2021-07-14 07:34:38 +00:00
|
|
|
file copy -force output/hw0/export/hw0/sw/hw0/boot/pmufw.elf .
|
2018-11-26 14:09:48 +00:00
|
|
|
exec bootgen -image zynqmp.bif -arch zynqmp -o BOOT.BIN -w
|
|
|
|
}
|
|
|
|
|
|
|
|
puts "adi_make_boot_bin.tcl done: $build_dir/BOOT.BIN"
|
|
|
|
|
|
|
|
## ***************************************************************************
|
|
|
|
## ***************************************************************************
|