Commit 1fe14c02 authored by Peter Jansweijer's avatar Peter Jansweijer

Added updatemem smi file and simulation fucntionality

moved directory precompiled
parent a41a1baf
......@@ -5,4 +5,6 @@
/*.wlf
/*.vstf
/*.lnk
/*.jou
/*.log
/transcript
\ No newline at end of file
......@@ -8,21 +8,19 @@ if {$Simulation} {
set g_simulation 0
}
source VSim_Current_Revision.tcl
source ../../../sw/scripts/VSim_Current_Revision.tcl
puts "elf file used for lm32 in WRPC: [set elf_file_lm32_wrpc "..\\..\\..\\sw\\embedded\\precompiled\\wrps-sw_v4_2_KPx5\\wrc.elf"]"
puts "elf file used for lm32 in WRPC: [set elf_file_lm32_wrpc "..\\..\\..\\sw\\precompiled\\wrps-sw_v4_2_KPx5\\wrc.elf"]"
set lm32_wrpc_instpath "lm32_wrpc_memory"
# !!! Note !!!: Don't forget to compile the software (elf file) for simulation (avoid printf etc. to speed up simulation time)
# !!! Note !!!: The double \\ are there since the DOS command below needs backslashes and a single backslash is seen as a switch in tcl
# Generate a "lm32_memory.mem" file from the "elf" file content
# Note that ISE 12.4 data2mem produces wrong results; use an older version:
#exec cmd.exe /c ..\\Software\\data2mem_ise10_1\\data2mem.exe -bd $elf_file_lm32_wrpc -d -o m xil_coregen_ahbrom.mem
#exec cmd.exe /c data2mem.exe -bd $elf_file_lm32_wrpc -d -o m lm32_wrpc_memory.mem
#exec cmd.exe /c updatemem -data $elf_file_lm32_wrpc -meminfo top1.smi -proc $lm32_wrpc_instpath -out lm32_wrpc_memory.mem -force
exec cmd.exe /c updatemem -meminfo spec7_wr_ref_top.smi -data $elf_file_lm32_wrpc -proc $lm32_wrpc_instpath -force
# Convert the "mem" to a "bram" (a format used by the White Rabbit "memory_loader_pkg.vhd")
do mem2bram.tcl lm32_wrpc_memory
do ../../../sw/scripts/mem2bram.tcl lm32_wrpc_memory 131072
# Now a fresh "lm32_wrpc_memory.bram" is in place for simulation and is loaded into xwb_dpram
# Note that -novopt causes No Optimization (some internal signals might get non-vivible by optimization)
......
###############################################################################
# mem2bram.tcl 15-Dec-2017
# $1 The first paramter is the filename to be used for input and output
# The names of the input MEM file and the output bram file:
puts "MEM input file name = [set mem_file "$1.mem"]"
puts "BRAM output file name = [set bram_file "$1.bram"]"
# The format used by the White Rabbit community (memory_loader_pkg.vhd)
# 32 bit binary data, one address per line
puts "BRAM file word length = [set wordlength 32] bits"
puts "DPRAM_Size = [set dpram_size [expr {131072/4}]], 32 bit words"
###############################################################################
set addr_ptr 0
if {[file exists $mem_file]} {
set mem_fileptr [open $mem_file]
set bram_fileptr [open $bram_file w]
set lineCount 0
while {[gets $mem_fileptr line] >= 0} {
set lineElements [llength $line]
# Skip empty and comment lines (preceeded by "//")
if { $lineElements != 0 && [lindex $line 0] != "//"} {
for {set x 0} {$x < $lineElements} {incr x} {
set lineElem [lindex $line $x]
# Addresses are preceeded with a "@" character
if { [string index $lineElem 0] == "@"} {
set addr [scan $lineElem "@%x"]
# If the BRAM file address pointer did not yet reach the addresses value
# in the MEM file yhen fill the BRAM file with "0" until the BRAM file
# address pointer is lined up.
while {$addr_ptr < $addr} {
set bramline [format "%032b" 0]
puts $bram_fileptr $bramline
incr addr_ptr
}
} else {
# Scan a byte from the MEM file
# every modulo wordlength/8 bytes a new address is written
if { $x % int($wordlength/8) == 0} {
set bramline ""
}
append bramline [format "%08b" [scan $lineElem "%x"]]
# If this is the last line element then...
if { $x == $lineElements - 1} {
# check whether all bytes were read from the BRAM line
# i.e. the byte pointer points to the last byte of the word
if { $x % int($wordlength/8) != int($wordlength/8)- 1} {
puts $bram_fileptr "Warning: word length and bytes per line ($lineElements) are inconsistent!"
puts "Warning: word length and bytes per line ($lineElements) are inconsistent!"
}
}
# when all bytes are scanned then write them to file
if { $x % int($wordlength/8) == int($wordlength/8)- 1} {
puts $bram_fileptr $bramline
incr addr_ptr
}
}
}
}
}
# Append the loader file with zeros until the full dpram_size is filled
while {$addr_ptr < $dpram_size} {
set bramline [format "%032b" 0]
puts $bram_fileptr $bramline
incr addr_ptr
}
close $mem_fileptr
close $bram_fileptr
} else {
puts "WARNING $mem_file not found..."
}
###############################################################################
<?xml version="1.0" encoding="UTF-8"?>
<MemInfoSimulation Version="1" Minor="1">
<Processor Endianness="Big" InstPath="lm32_wrpc_memory">
<AddressSpace Name="lm32_wrpc_memory_dpram" ECC="NONE" Begin="0" End="131071">
<BusBlock>
<BitLane MemType="lm32_wrpc_memory_dpram" MemType_DataWidth="32" MemType_AddressDepth="131071">
<DataWidth MSB="31" LSB="0"/>
<AddressRange Begin="0" End="32767"/>
<Parity ON="false" NumBits="0"/>
<MemFile Name="lm32_wrpc_memory.mem"/>
</BitLane>
</BusBlock>
</AddressSpace>
</Processor>
<Config>
<Option Name="Part" Val="xc7k160tfbg676-2"/>
</Config>
<DRC>
<Rule Name="RDADDRCHANGE" Val="false"/>
</DRC>
</MemInfoSimulation>
......@@ -5,7 +5,7 @@ rem ### Cleanup old log files and stuff
del vivado_mmi_elf.log
set proj_name="spec7_wr_ref_top"
set lm32_wrpc_elf="../../../sw/embedded/precompiled/wrps-sw_spec7/wrc.elf"
set lm32_wrpc_elf="../../../sw/precompiled/wrps-sw_spec7/wrc.elf"
set lm32_wrpc_instpath="lm32_wrpc_memory"
rem ### note that environment variable "VIVADO" must be set to something like "E:\Xilinx\Vivado\2017.1\bin\"
......
......@@ -7,7 +7,7 @@
set proj_name spec7_wr_ref_top
set proj_dir work
set script_dir [pwd]/../../../sw/scripts
set lm32_wrpc_initf [pwd]/../../../sw/embedded/precompiled/wrps-sw_spec7/wrc.bram
set lm32_wrpc_initf [pwd]/../../../sw/precompiled/wrps-sw_spec7/wrc.bram
# update revision except when argument "no_update_revison" is passed (as for example by viv_do_programm.tcl)
if {$argc == 0 || $argv != "no_update_revision"} {
......
###############################################################################
# revisiondate.tcl 08-Dec-2006
# Calculate Current Date
set current_year [clock format [clock seconds] -format %y]
scan $current_year %d current_year
set current_year_h [expr ($current_year / 10)]
set current_year_l [expr ($current_year - 10 * $current_year_h)]
set current_month [clock format [clock seconds] -format %m]
scan $current_month %d current_month
set current_month_h [expr ($current_month / 10)]
set current_month_l [expr ($current_month - 10 * $current_month_h)]
set current_day [clock format [clock seconds] -format %d]
scan $current_day %d current_day
set current_day_h [expr ($current_day / 10)]
set current_day_l [expr ($current_day - 10 * $current_day_h)]
set current_date [expr (1048576*$current_year_h + 65536*$current_year_l + 4096*$current_month_h + 256*$current_month_l + 16*$current_day_h + $current_day_l)]
# Calculate Current Revision
set revision_log_file "revisiondate_log.txt"
set current_rev_date [clock format [clock seconds] -format %y%m%d]
if [file exists $revision_log_file] {
set revision_log_fileptr [open $revision_log_file]
gets $revision_log_fileptr revision_log_date
gets $revision_log_fileptr revision_log_revnumber
close $revision_log_fileptr
if { [string compare $current_rev_date $revision_log_date] == 0 } {
# Dates are equal
set current_revision [expr ($revision_log_revnumber + 1)]
} else {
# Dates are unequal
set current_revision 0
}
set revision_log_fileptr [open $revision_log_file w]
puts $revision_log_fileptr $current_rev_date
puts $revision_log_fileptr $current_revision
close $revision_log_fileptr
} else {
puts "WARNING $revision_log_file not found. Creating new one..."
set current_revision 0
set revision_log_fileptr [open $revision_log_file w]
puts $revision_log_fileptr $current_rev_date
puts $revision_log_fileptr $current_revision
close $revision_log_fileptr
}
puts "###### Synthesis is done with the following settings:"
puts [format "###### DATE: %x" $current_date]
puts [format "###### REVISION: %d" $current_revision]
###############################################################################
......@@ -5,4 +5,6 @@
/*.wlf
/*.vstf
/*.lnk
/*.jou
/*.log
/transcript
\ No newline at end of file
# VSim_Current_Revision.tcl
puts "current year = [set current_year [scan [clock format [clock seconds] -format %y] %d]]"
set current_year_h [expr ($current_year / 10)]
set current_year_l [expr ($current_year - 10 * $current_year_h)]
puts "current month = [set current_month [scan [clock format [clock seconds] -format %m] %d]]"
set current_month_h [expr ($current_month / 10)]
set current_month_l [expr ($current_month - 10 * $current_month_h)]
puts "current day = [set current_day [scan [clock format [clock seconds] -format %d] %d]]"
set current_day_h [expr ($current_day / 10)]
set current_day_l [expr ($current_day - 10 * $current_day_h)]
set current_date [expr (1048576*$current_year_h + 65536*$current_year_l + 4096*$current_month_h + 256*$current_month_l + 16*$current_day_h + $current_day_l)]
puts "current revision = [set current_revision 1]"
......@@ -8,21 +8,19 @@ if {$Simulation} {
set g_simulation 0
}
source VSim_Current_Revision.tcl
source ../../../sw/scripts/VSim_Current_Revision.tcl
puts "elf file used for lm32 in WRPC: [set elf_file_lm32_wrpc "..\\..\\..\\sw\\embedded\\precompiled\\wrps-sw_v4_2_KPx5\\wrc.elf"]"
puts "elf file used for lm32 in WRPC: [set elf_file_lm32_wrpc "..\\..\\..\\sw\\precompiled\\wrps-sw_v4_2_KPx5\\wrc.elf"]"
set lm32_wrpc_instpath "lm32_wrpc_memory"
# !!! Note !!!: Don't forget to compile the software (elf file) for simulation (avoid printf etc. to speed up simulation time)
# !!! Note !!!: The double \\ are there since the DOS command below needs backslashes and a single backslash is seen as a switch in tcl
# Generate a "lm32_memory.mem" file from the "elf" file content
# Note that ISE 12.4 data2mem produces wrong results; use an older version:
#exec cmd.exe /c ..\\Software\\data2mem_ise10_1\\data2mem.exe -bd $elf_file_lm32_wrpc -d -o m xil_coregen_ahbrom.mem
#exec cmd.exe /c data2mem.exe -bd $elf_file_lm32_wrpc -d -o m lm32_wrpc_memory.mem
#exec cmd.exe /c updatemem -data $elf_file_lm32_wrpc -meminfo top1.smi -proc $lm32_wrpc_instpath -out lm32_wrpc_memory.mem -force
exec cmd.exe /c updatemem -meminfo spec7_write_top.smi -data $elf_file_lm32_wrpc -proc $lm32_wrpc_instpath -force
# Convert the "mem" to a "bram" (a format used by the White Rabbit "memory_loader_pkg.vhd")
do mem2bram.tcl lm32_wrpc_memory
do ../../../sw/scripts/mem2bram.tcl lm32_wrpc_memory 131072
# Now a fresh "lm32_wrpc_memory.bram" is in place for simulation and is loaded into xwb_dpram
# Note that -novopt causes No Optimization (some internal signals might get non-vivible by optimization)
......
<?xml version="1.0" encoding="UTF-8"?>
<MemInfoSimulation Version="1" Minor="1">
<Processor Endianness="Big" InstPath="lm32_wrpc_memory">
<AddressSpace Name="lm32_wrpc_memory_dpram" ECC="NONE" Begin="0" End="131071">
<BusBlock>
<BitLane MemType="lm32_wrpc_memory_dpram" MemType_DataWidth="32" MemType_AddressDepth="131071">
<DataWidth MSB="31" LSB="0"/>
<AddressRange Begin="0" End="32767"/>
<Parity ON="false" NumBits="0"/>
<MemFile Name="lm32_wrpc_memory.mem"/>
</BitLane>
</BusBlock>
</AddressSpace>
</Processor>
<Config>
<Option Name="Part" Val="xc7k160tfbg676-2"/>
</Config>
<DRC>
<Rule Name="RDADDRCHANGE" Val="false"/>
</DRC>
</MemInfoSimulation>
......@@ -5,7 +5,7 @@ rem ### Cleanup old log files and stuff
del vivado_mmi_elf.log
set proj_name="spec7_write_top"
set lm32_wrpc_elf="../../../sw/embedded/precompiled/wrps-sw_spec7/wrc.elf"
set lm32_wrpc_elf="../../../sw/precompiled/wrps-sw_spec7/wrc.elf"
set lm32_wrpc_instpath="lm32_wrpc_memory"
rem ### note that environment variable "VIVADO" must be set to something like "E:\Xilinx\Vivado\2017.1\bin\"
......
......@@ -7,8 +7,8 @@
set proj_name spec7_write_top
set proj_dir work
set script_dir [pwd]/../../../sw/scripts
set lm32_wrpc_initf [pwd]/../../../sw/embedded/precompiled/wrps-sw_spec7/wrc.bram
#set lm32_wrpc_initf [pwd]/../../../sw/embedded/precompiled/wrps-sw_spec7/wrc_ext10mhz.bram
set lm32_wrpc_initf [pwd]/../../../sw/precompiled/wrps-sw_spec7/wrc.bram
#set lm32_wrpc_initf [pwd]/../../../sw/precompiled/wrps-sw_spec7/wrc_ext10mhz.bram
# update revision except when argument "no_update_revison" is passed (as for example by viv_do_programm.tcl)
if {$argc == 0 || $argv != "no_update_revision"} {
......
###############################################################################
# mem2bram.tcl 15-Dec-2017
# mem2bram.tcl 25-Mar-2020
# $1 The first paramter is the filename to be used for input and output
# $2 Second parameter is the ramsize in bytes
# The names of the input MEM file and the output bram file:
puts "MEM input file name = [set mem_file "$1.mem"]"
puts "BRAM output file name = [set bram_file "$1.bram"]"
if {$argc == 2} {
puts "ramsize in bytes = [set ram_size [expr (int($2))]]"
} else {
# use default 13072
puts "ramsize in bytes = [set ram_size 131072]"
}
# The format used by the White Rabbit community (memory_loader_pkg.vhd)
# 32 bit binary data, one address per line
puts "BRAM file word length = [set wordlength 32] bits"
puts "DPRAM_Size = [set dpram_size [expr {131072/4}]], 32 bit words"
puts "DPRAM_Size = [set dpram_size [expr {$ram_size/4}]], 32 bit words"
###############################################################################
proc endian_swap32 {bin32} {
if { [string length $bin32] == 32 } {
set swap [string range $bin32 24 31]
append swap [string range $bin32 16 23]
append swap [string range $bin32 8 15]
append swap [string range $bin32 0 7]
} else {
set swap 0
puts "Warning: try to endian swap 32 bits with less than 32 bits input"
}
return $swap
}
###############################################################################
set addr_ptr 0
set bramline ""
if {[file exists $mem_file]} {
set mem_fileptr [open $mem_file]
set bram_fileptr [open $bram_file w]
set lineCount 0
while {[gets $mem_fileptr line] >= 0} {
set lineElements [llength $line]
# Skip empty and comment lines (preceeded by "//")
set first true
# Note from UG898:
# "IMPORTANT: Although Processor Endianness is defined in the MMI file, it is not supported by
# UpdateMEM at this time."
# updatemem acts by default "Little" endian! Swap necessairy for Big endian LM32!
set swap true
while {[gets $mem_fileptr line] >= 0} {
set lineElements [llength $line]
# Skip empty and comment lines (preceeded by "//")
if { $lineElements != 0 && [lindex $line 0] != "//"} {
for {set x 0} {$x < $lineElements} {incr x} {
set lineElem [lindex $line $x]
......@@ -31,7 +62,7 @@ if {[file exists $mem_file]} {
if { [string index $lineElem 0] == "@"} {
set addr [scan $lineElem "@%x"]
# If the BRAM file address pointer did not yet reach the addresses value
# in the MEM file yhen fill the BRAM file with "0" until the BRAM file
# in the MEM file then fill the BRAM file with "0" until the BRAM file
# address pointer is lined up.
while {$addr_ptr < $addr} {
set bramline [format "%032b" 0]
......@@ -39,25 +70,51 @@ if {[file exists $mem_file]} {
incr addr_ptr
}
} else {
# Scan a byte from the MEM file
# every modulo wordlength/8 bytes a new address is written
if { $x % int($wordlength/8) == 0} {
set bramline ""
# Each memfile line contains either 32x 1-byte or 8x 32-bit-words
if {$first} {
set first false
if { $lineElements == 8 } {
#puts "read 32 bit words"
set element_size 32
} else {
#puts "read bytes"
set element_size 8
}
append bramline [format "%08b" [scan $lineElem "%x"]]
# If this is the last line element then...
if { $x == $lineElements - 1} {
}
# if $element_size == 8 then we are reading bytes => read 4 bytes at a time
# if $element_size == 32 then we are reading 32-bit words => read one word at a time
# either read 4 bytes or 1 word
# Scan an element from the MEM file
if {($element_size == 8)} {
# read bytes
append bramline [format "%08b" [scan $lineElem "%x"]]
} else {
# read 32-bit-words
set bin32 [format "%032b" [scan $lineElem "%x"]]
# 32 bit endian swap necesairy?
if {$swap} {
append bramline [endian_swap $bin32]
} else {
append bramline $bin32
}
}
# If we are reading bytes and this is the last line element then...
if { ($element_size == 8) && ($x == $lineElements - 1)} {
# check whether all bytes were read from the BRAM line
# i.e. the byte pointer points to the last byte of the word
if { $x % int($wordlength/8) != int($wordlength/8)- 1} {
# i.e. the byte pointer points to the last (i.e. 3-rd) byte of the word
if { $x % 4 != 3} {
puts $bram_fileptr "Warning: word length and bytes per line ($lineElements) are inconsistent!"
puts "Warning: word length and bytes per line ($lineElements) are inconsistent!"
}
}
# when all bytes are scanned then write them to file
if { $x % int($wordlength/8) == int($wordlength/8)- 1} {
if {(($element_size == 8) && ($x % 4 == 3)) ||
($element_size == 32)} {
puts $bram_fileptr $bramline
set bramline ""
incr addr_ptr
}
}
......@@ -70,7 +127,6 @@ if {[file exists $mem_file]} {
puts $bram_fileptr $bramline
incr addr_ptr
}
close $mem_fileptr
close $bram_fileptr
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment