Launch Emulator
Launch Emulator
if {$::tcl_platform(os) == "Linux"} {
set script_ext "sh"
set xsim_redir ">/dev/null"
} else {
set script_ext "bat"
set xsim_redir ">NUL"
}
if {$wcfg_file ne ""} {
if {[file exists $wcfg_file]} {
set wcfg_cmd_str "open_wave_config $wcfg_file"
if {$::tcl_platform(os) != "Linux"} {
# only for linux, unix sockets, windows uses tcp sockets
set machine_path_socket_path 1
set enable_tcp_sockets 1
}
close $fp
exit 0
}
# ##################### set device family ###########
set cpu_type ""
if {$enable_prep_target == 1} {
set cpu_type [setCpuType $device_family]
} else {
if {![info exists device_family] || $device_family == ""} {
#exit 1
} else {
set cpu_type [setCpuType $device_family]
}
}
if {$ddr_sharing_size != ""} {
puts "WARNING : \[LAUNCH_EMULATOR\] DDR Memory Sharing option -m is deprecated.
Ignoring -m option used."
set ddr_sharing_size ""
}
# for versal, noc ddr sharing more than 2 GB, create noc shared files txt.CR-
1064064
#if {$device_family == "versal"} {
# if {[info exists ddr_sharing_size] && $ddr_sharing_size != ""} {
# set sharing_size_arr [split $ddr_sharing_size "G"]
# set sharing_size [lindex $sharing_size_arr 0]
# if {$sharing_size <= 2} {
# puts "\[LAUNCH_EMULATOR\] INFO:Sharing less than or equal to 2G DDR Memory.
Using default NOCSIM_DRAM_FILE"
# }
# if {$sharing_size > 34} {
# puts "\[LAUNCH_EMULATOR\] INFO:Only 34G DDR Memory can be shared using NOC
SIM CONFIG files. Setting shared value to 34G though $sharing_size G is mentioned."
# set sharing_size 34
# }
# if {$sharing_size > 2 && $target_emu == "hw_emu"} {
# create_ddr_memory_files $pl_sim_dir $sharing_size
# }
# }
#}
######################################################################
# QEMU script and arguments
# create start_qemu.sh
set qemu_cmd [get_qemu_cmd $cpu_type $::tcl_platform(os) $verbose $qemu_v4]
set pmc_cmd [get_pmc_cmd $cpu_type $::tcl_platform(os) $verbose $qemu_v4]
# ####################################################
if {[info exists target] && $target != "" && [info exists host] && $host != ""} {
append qemu_args " -net \"nic,netdev=net0\" -netdev \"user,id=net0,hostfwd=tcp::$
{target}-:${host}\""
#append qemu_args " -redir \"tcp:${target}::${host}\""
}
######################################################################
######################################################################
# PMC script and arguments
# create start_pmu.sh
if {$cpu_type == "cortex-a9"} {
# There is no microblaze in zynq 7000. No need to generate start_pmu.sh
} else {
set pmcargs_microblaze_set 0
if {$cpu_type == "cortex-a53"} {
# zynq mp
set pmc_dtb ""
if {[info exists ::env(QEMU_DTB_PATH)] } {
set pmc_dtb [file join $::env(QEMU_DTB_PATH) zynqmp-pmu.dtb]
} else {
if {$qemu_v4 != 1} {
if {$::tcl_platform(os) == "Linux"} {
set pmc_dtb [file join $::env(XILINX_XD) data emulation dtbs zynqmp
zynqmp-pmu.dtb]
} else {
set pmc_dtb [file join $::env(XILINX_XD) data emulation dtbs zynqmp
dtb_qemu_win zynqmp-pmu.dtb]
}
} else {
set pmc_dtb [file join $::env(XILINX_XD) data emulation dtbs zynqmp
dtb_qemuv4_2 zynqmp-pmu.dtb]
}
}
puts "pmc_dtb $pmc_dtb"
append pmc_args " -hw-dtb $pmc_dtb "
set pmc_rom [file join $::env(XILINX_XD) data emulation dtbs zynqmp
pmu_rom_qemu_sha3.elf]
append pmc_args " -kernel $pmc_rom "
if {$enable_tcp_sockets} {
append pmc_args " -chardev \"socket,id=pmu-apu-
rp,host=127.0.0.1,port=$pmc_port\""
} else {
if {$machine_path_socket_path eq 1} {
append pmc_args " -chardev \"socket,path=./qemu-rport-_pmu@0,id=pmu-apu-
rp\""
} else {
append pmc_args " -chardev \"socket,path=/tmp/$::env(VIMAGE_PID)/qemu-
rport-_pmu@0,id=pmu-apu-rp\""
}
}
} else {
# VERSAL
set pmc_dtb ""
if {[info exists ::env(QEMU_DTB_PATH)] } {
set pmc_dtb [file join $::env(QEMU_DTB_PATH) board-versal-pmc-virt.dtb]
} else {
if {$qemu_v4 != 1} {
if {$pmc_hw_dtb != ""} {
set pmc_dtb $pmc_hw_dtb
} else {
set pmc_dtb [file join $::env(XILINX_XD) data emulation dtbs versal
$target_emu board-versal-pmc-virt.dtb]
}
} else {
set pmc_dtb [file join $::env(XILINX_XD) data emulation dtbs versal
dtb_qemuv4_2 board-versal-pmc-virt.dtb]
}
}
if {$target_emu == "sw_emu"} {
# no need of xsim_script for sw_emu as there is no PL to simulate.It is PS only
deisgn.
} else {
if {![file exists $xsim_script]} {
puts "ERROR: \[LAUNCH_EMULATOR\] Missing expected simulation script:
$xsim_script"
exit 1
}
}
######################################################################
######################################################################
# SD card image ######################################################
set emulation_live 0
if {$enable_tcp_sockets == 1 || $cpu_type == "cortex-a9"} {
while {($emulation_live == 0)} {
after 1000
puts -nonewline "."
flush stdout
if {[port_open $port] || $dont_check } {
set emulation_live 1
puts "."
}
if {![pid_exists $qemu_pid] && !$dont_check } {
puts " Failed to start $qemu_script. Aborting!"
puts "ERROR: \[LAUNCH_EMULATOR\] launch_emulator exited because of an issue
in launching QEMU"
exit 1
}
}
}
return $qemu_pid
}
# #####################################################################
# We donot want to see a seperate shell for pmu even when interactive mode
is enabled.Henec explicitly setting interactive to 0
# Timeout handling
set done 0
if {[info exists timeout] && $timeout != ""} {
after [expr $timeout * 1000] set done 1
}
if {$done} {
puts "\[LAUNCH_EMULATOR\] Emulation timeout reached!"
}
# Cleanup
#Adding 2 second delay, because XSIM is taking some time to quit after qemu quits.
#If this dalay is not added , during cleanup, we are trying to kill xsim process
using the PID present..
#When we are checking for xsim pid, it exists.But, by the time we give kill
command, it gets killed , and kill command cannot find xsim pid. and we are seeing
terminate issues because of this.
after 2000
if {[pid_exists $qemu_pid]} {
if {$done} {
set systemTime [clock seconds]
puts "\[LAUNCH_EMULATOR\] INFO: [clock format $systemTime -format %H:%M:%S] :
Trying to kill PS-QEMU forcefully because timeout is reached"
}
if {!$done} {
set systemTime [clock seconds]
puts "\[LAUNCH_EMULATOR\] INFO: [clock format $systemTime -format %H:%M:%S] :
Trying to kill PS-QEMU forcefully"
}
kill_process $qemu_pid $verbose
if {![pid_exists $qemu_pid]} {
set systemTime [clock seconds]
puts "\[LAUNCH_EMULATOR\] INFO: [clock format $systemTime -format %H:%M:%S] :
PS-QEMU exited by force"
}
} else {
set systemTime [clock seconds]
puts "\[LAUNCH_EMULATOR\] INFO: [clock format $systemTime -format %H:%M:%S] :
PS-QEMU exited"
}
if {[pid_exists $pl_pid]} {
if {$done && $target_emu == "hw_emu"} {
set systemTime [clock seconds]
puts "\[LAUNCH_EMULATOR\] INFO: [clock format $systemTime -format %H:%M:%S] :
Trying to kill simulation forcefully because timeout is reached"
}
if {!$done && $target_emu == "hw_emu"} {
set systemTime [clock seconds]
puts "\[LAUNCH_EMULATOR\] INFO: [clock format $systemTime -format %H:%M:%S] :
Trying to kill simulation forcefully because QEMU exited"
}
if {$done && $target_emu == "sw_emu"} {
set systemTime [clock seconds]
puts "\[LAUNCH_EMULATOR\] INFO: [clock format $systemTime -format %H:%M:%S] :
Trying to kill PLLauncher forcefully because timeout is reached"
}
if {!$done && $target_emu == "sw_emu"} {
set systemTime [clock seconds]
puts "\[LAUNCH_EMULATOR\] INFO: [clock format $systemTime -format %H:%M:%S] :
Trying to kill PLLauncher forcefully because QEMU exited"
}
if {![pid_exists $pl_pid]} {
if {$target_emu == "hw_emu"} {
set systemTime [clock seconds]
puts "\[LAUNCH_EMULATOR\] INFO: [clock format $systemTime -format %H:%M:%S]
: Simulation exited by force"
} else {
set systemTime [clock seconds]
puts "\[LAUNCH_EMULATOR\] INFO: [clock format $systemTime -format %H:%M:%S]
: PLLauncher exited by force"
}
}
} else {
if {$target_emu == "hw_emu" } {
set systemTime [clock seconds]
puts "\[LAUNCH_EMULATOR\] INFO: [clock format $systemTime -format %H:%M:%S] :
Simulation exited"
} else {
set systemTime [clock seconds]
puts "\[LAUNCH_EMULATOR\] INFO: [clock format $systemTime -format %H:%M:
%S] : PLLauncher exited"
}
}
foreach pid_to_kill $pids_to_kill {
if {[pid_exists $pid_to_kill]} {
puts "\[LAUNCH_EMULATOR\] INFO: killing $pid_to_kill"
kill_process $pid_to_kill $verbose
if {![pid_exists $pid_to_kill]} {
puts "\[LAUNCH_EMULATOR\] INFO: killed $pid_to_kill"
}
}
}
puts "DONE!"
puts "INFO: Emulation ran successfully"
exit 0
}