From 283bfbeeb7fb5767815c10ea98bb155638d4bfb3 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Tue, 17 Mar 2015 13:49:30 +0100 Subject: Rearrange cores. --- README.md | 14 +- build/.gitignore | 41 - build/Makefile | 20 - build/coretest-novena.bmm | 0 build/coretest-novena.ucf | 594 ----------- build/xilinx.mk | 176 ---- build/xilinx.opt | 42 - common/rtl/ipcore/_xmsgs/cg.xmsgs | 27 + common/rtl/ipcore/clkmgr_dcm.asy | 25 + common/rtl/ipcore/clkmgr_dcm.gise | 31 + common/rtl/ipcore/clkmgr_dcm.ncf | 60 ++ common/rtl/ipcore/clkmgr_dcm.sym | 24 + common/rtl/ipcore/clkmgr_dcm.ucf | 59 ++ common/rtl/ipcore/clkmgr_dcm.v | 148 +++ common/rtl/ipcore/clkmgr_dcm.veo | 79 ++ common/rtl/ipcore/clkmgr_dcm.xco | 269 +++++ common/rtl/ipcore/clkmgr_dcm.xdc | 67 ++ common/rtl/ipcore/clkmgr_dcm.xise | 74 ++ .../rtl/ipcore/clkmgr_dcm/clk_wiz_v3_6_readme.txt | 184 ++++ .../ipcore/clkmgr_dcm/doc/clk_wiz_v3_6_readme.txt | 184 ++++ .../ipcore/clkmgr_dcm/doc/clk_wiz_v3_6_vinfo.html | 195 ++++ common/rtl/ipcore/clkmgr_dcm/doc/pg065_clk_wiz.pdf | Bin 0 -> 42657 bytes .../clkmgr_dcm/example_design/clkmgr_dcm_exdes.ucf | 60 ++ .../clkmgr_dcm/example_design/clkmgr_dcm_exdes.v | 164 ++++ .../clkmgr_dcm/example_design/clkmgr_dcm_exdes.xdc | 69 ++ .../rtl/ipcore/clkmgr_dcm/implement/implement.bat | 90 ++ .../rtl/ipcore/clkmgr_dcm/implement/implement.sh | 91 ++ .../ipcore/clkmgr_dcm/implement/planAhead_ise.bat | 58 ++ .../ipcore/clkmgr_dcm/implement/planAhead_ise.sh | 59 ++ .../ipcore/clkmgr_dcm/implement/planAhead_ise.tcl | 78 ++ .../ipcore/clkmgr_dcm/implement/planAhead_rdn.bat | 58 ++ .../ipcore/clkmgr_dcm/implement/planAhead_rdn.sh | 57 ++ .../ipcore/clkmgr_dcm/implement/planAhead_rdn.tcl | 69 ++ common/rtl/ipcore/clkmgr_dcm/implement/xst.prj | 2 + common/rtl/ipcore/clkmgr_dcm/implement/xst.scr | 9 + .../ipcore/clkmgr_dcm/simulation/clkmgr_dcm_tb.v | 145 +++ .../clkmgr_dcm/simulation/functional/simcmds.tcl | 8 + .../simulation/functional/simulate_isim.bat | 59 ++ .../simulation/functional/simulate_isim.sh | 61 ++ .../simulation/functional/simulate_mti.bat | 61 ++ .../simulation/functional/simulate_mti.do | 65 ++ .../simulation/functional/simulate_mti.sh | 61 ++ .../simulation/functional/simulate_ncsim.sh | 62 ++ .../simulation/functional/simulate_vcs.sh | 72 ++ .../simulation/functional/ucli_commands.key | 5 + .../simulation/functional/vcs_session.tcl | 18 + .../clkmgr_dcm/simulation/functional/wave.do | 60 ++ .../clkmgr_dcm/simulation/functional/wave.sv | 118 +++ .../clkmgr_dcm/simulation/timing/clkmgr_dcm_tb.v | 149 +++ .../clkmgr_dcm/simulation/timing/sdf_cmd_file | 2 + .../clkmgr_dcm/simulation/timing/simcmds.tcl | 9 + .../clkmgr_dcm/simulation/timing/simulate_isim.sh | 62 ++ .../clkmgr_dcm/simulation/timing/simulate_mti.bat | 59 ++ .../clkmgr_dcm/simulation/timing/simulate_mti.do | 65 ++ .../clkmgr_dcm/simulation/timing/simulate_mti.sh | 61 ++ .../clkmgr_dcm/simulation/timing/simulate_ncsim.sh | 64 ++ .../clkmgr_dcm/simulation/timing/simulate_vcs.sh | 72 ++ .../clkmgr_dcm/simulation/timing/ucli_commands.key | 5 + .../clkmgr_dcm/simulation/timing/vcs_session.tcl | 1 + .../ipcore/clkmgr_dcm/simulation/timing/wave.do | 71 ++ common/rtl/ipcore/clkmgr_dcm_flist.txt | 54 + common/rtl/ipcore/clkmgr_dcm_xmdf.tcl | 140 +++ common/rtl/ipcore/coregen.cgp | 9 + common/rtl/ipcore/create_clkmgr_dcm.tcl | 37 + common/rtl/ipcore/edit_clkmgr_dcm.tcl | 37 + common/rtl/novena_clkmgr.v | 130 +++ eim/build/.gitignore | 52 + eim/build/Makefile | 40 + eim/build/xilinx.mk | 174 ++++ eim/build/xilinx.opt | 42 + eim/iseconfig/.gitignore | 48 + eim/iseconfig/novena_eim.xise | 475 +++++++++ eim/rtl/novena_eim.v | 182 ++++ eim/rtl/novena_regs.v | 129 +++ eim/sw/Makefile | 14 + eim/sw/hash_tester_eim.c | 884 +++++++++++++++++ eim/sw/novena-eim.c | 708 ++++++++++++++ eim/sw/novena-eim.h | 52 + eim/ucf/novena_eim.ucf | 152 +++ i2c/build/.gitignore | 52 + i2c/build/Makefile | 36 + i2c/build/xilinx.mk | 174 ++++ i2c/build/xilinx.opt | 42 + i2c/iseconfig/.gitignore | 48 + i2c/iseconfig/novena_i2c.xise | 455 +++++++++ i2c/rtl/novena_i2c.v | 221 +++++ i2c/rtl/novena_regs.v | 129 +++ i2c/sw/Makefile | 7 + i2c/sw/hash_tester_i2c.c | 1030 ++++++++++++++++++++ i2c/ucf/novena_i2c.ucf | 82 ++ src/rtl/coretest_hashes.v | 321 ------ src/rtl/novena_fpga.v | 147 --- src/sw/00-index.txt | 12 - src/sw/1000_block.bin | Bin 64000 -> 0 bytes src/sw/configure.sh | 15 - src/sw/hash.c | 620 ------------ src/sw/hash_tester.c | 981 ------------------- src/sw/hash_tester.py | 693 ------------- src/sw/nist_1024_double.bin | 1 - src/sw/nist_1024_single.bin | 1 - src/sw/nist_512_double.bin | 1 - src/sw/nist_512_single.bin | 1 - 102 files changed, 9348 insertions(+), 3672 deletions(-) delete mode 100644 build/.gitignore delete mode 100644 build/Makefile delete mode 100644 build/coretest-novena.bmm delete mode 100644 build/coretest-novena.ucf delete mode 100644 build/xilinx.mk delete mode 100644 build/xilinx.opt create mode 100644 common/rtl/ipcore/_xmsgs/cg.xmsgs create mode 100644 common/rtl/ipcore/clkmgr_dcm.asy create mode 100644 common/rtl/ipcore/clkmgr_dcm.gise create mode 100644 common/rtl/ipcore/clkmgr_dcm.ncf create mode 100644 common/rtl/ipcore/clkmgr_dcm.sym create mode 100644 common/rtl/ipcore/clkmgr_dcm.ucf create mode 100644 common/rtl/ipcore/clkmgr_dcm.v create mode 100644 common/rtl/ipcore/clkmgr_dcm.veo create mode 100644 common/rtl/ipcore/clkmgr_dcm.xco create mode 100644 common/rtl/ipcore/clkmgr_dcm.xdc create mode 100644 common/rtl/ipcore/clkmgr_dcm.xise create mode 100644 common/rtl/ipcore/clkmgr_dcm/clk_wiz_v3_6_readme.txt create mode 100644 common/rtl/ipcore/clkmgr_dcm/doc/clk_wiz_v3_6_readme.txt create mode 100644 common/rtl/ipcore/clkmgr_dcm/doc/clk_wiz_v3_6_vinfo.html create mode 100644 common/rtl/ipcore/clkmgr_dcm/doc/pg065_clk_wiz.pdf create mode 100644 common/rtl/ipcore/clkmgr_dcm/example_design/clkmgr_dcm_exdes.ucf create mode 100644 common/rtl/ipcore/clkmgr_dcm/example_design/clkmgr_dcm_exdes.v create mode 100644 common/rtl/ipcore/clkmgr_dcm/example_design/clkmgr_dcm_exdes.xdc create mode 100644 common/rtl/ipcore/clkmgr_dcm/implement/implement.bat create mode 100644 common/rtl/ipcore/clkmgr_dcm/implement/implement.sh create mode 100644 common/rtl/ipcore/clkmgr_dcm/implement/planAhead_ise.bat create mode 100644 common/rtl/ipcore/clkmgr_dcm/implement/planAhead_ise.sh create mode 100644 common/rtl/ipcore/clkmgr_dcm/implement/planAhead_ise.tcl create mode 100644 common/rtl/ipcore/clkmgr_dcm/implement/planAhead_rdn.bat create mode 100644 common/rtl/ipcore/clkmgr_dcm/implement/planAhead_rdn.sh create mode 100644 common/rtl/ipcore/clkmgr_dcm/implement/planAhead_rdn.tcl create mode 100644 common/rtl/ipcore/clkmgr_dcm/implement/xst.prj create mode 100644 common/rtl/ipcore/clkmgr_dcm/implement/xst.scr create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/clkmgr_dcm_tb.v create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/functional/simcmds.tcl create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_isim.bat create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_isim.sh create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_mti.bat create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_mti.do create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_mti.sh create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_ncsim.sh create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_vcs.sh create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/functional/ucli_commands.key create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/functional/vcs_session.tcl create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/functional/wave.do create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/functional/wave.sv create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/timing/clkmgr_dcm_tb.v create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/timing/sdf_cmd_file create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/timing/simcmds.tcl create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_isim.sh create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_mti.bat create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_mti.do create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_mti.sh create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_ncsim.sh create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_vcs.sh create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/timing/ucli_commands.key create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/timing/vcs_session.tcl create mode 100644 common/rtl/ipcore/clkmgr_dcm/simulation/timing/wave.do create mode 100644 common/rtl/ipcore/clkmgr_dcm_flist.txt create mode 100644 common/rtl/ipcore/clkmgr_dcm_xmdf.tcl create mode 100644 common/rtl/ipcore/coregen.cgp create mode 100644 common/rtl/ipcore/create_clkmgr_dcm.tcl create mode 100644 common/rtl/ipcore/edit_clkmgr_dcm.tcl create mode 100644 common/rtl/novena_clkmgr.v create mode 100644 eim/build/.gitignore create mode 100644 eim/build/Makefile create mode 100644 eim/build/xilinx.mk create mode 100644 eim/build/xilinx.opt create mode 100644 eim/iseconfig/.gitignore create mode 100644 eim/iseconfig/novena_eim.xise create mode 100644 eim/rtl/novena_eim.v create mode 100644 eim/rtl/novena_regs.v create mode 100755 eim/sw/Makefile create mode 100644 eim/sw/hash_tester_eim.c create mode 100644 eim/sw/novena-eim.c create mode 100644 eim/sw/novena-eim.h create mode 100644 eim/ucf/novena_eim.ucf create mode 100644 i2c/build/.gitignore create mode 100644 i2c/build/Makefile create mode 100644 i2c/build/xilinx.mk create mode 100644 i2c/build/xilinx.opt create mode 100644 i2c/iseconfig/.gitignore create mode 100644 i2c/iseconfig/novena_i2c.xise create mode 100644 i2c/rtl/novena_i2c.v create mode 100644 i2c/rtl/novena_regs.v create mode 100755 i2c/sw/Makefile create mode 100644 i2c/sw/hash_tester_i2c.c create mode 100644 i2c/ucf/novena_i2c.ucf delete mode 100644 src/rtl/coretest_hashes.v delete mode 100644 src/rtl/novena_fpga.v delete mode 100644 src/sw/00-index.txt delete mode 100644 src/sw/1000_block.bin delete mode 100755 src/sw/configure.sh delete mode 100644 src/sw/hash.c delete mode 100644 src/sw/hash_tester.c delete mode 100755 src/sw/hash_tester.py delete mode 100644 src/sw/nist_1024_double.bin delete mode 100644 src/sw/nist_1024_single.bin delete mode 100644 src/sw/nist_512_double.bin delete mode 100644 src/sw/nist_512_single.bin diff --git a/README.md b/README.md index 302a492..0a364e1 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,15 @@ -coretest_hashes +platform/novena =============== -The coretest system combined with cryptographic hash functions. +Platform-specific files for the Novena PVT1. ## Introduction ## -This is a HW subsystem that includes the coretest module connected to an -I2C bus for external access and to hash function cores. This version -includes the SHA-1, SHA-256, and SHA-512 cores. +This includes the Verilog top-level files and build systems for Novena +with either I2C or EIM interfaces. ## Status ## +***(2015-03-16)*** +Reorganized. Built using Xilinx ISE 14.7. + ***(2014-08-27)*** -Initial version. Build using Xilinx ISE 14.3. +Initial version. Built using Xilinx ISE 14.3. diff --git a/build/.gitignore b/build/.gitignore deleted file mode 100644 index f5352a4..0000000 --- a/build/.gitignore +++ /dev/null @@ -1,41 +0,0 @@ -_xmsgs -coretest-novena.bgn -coretest-novena.bit -coretest-novena.bld -coretest-novena.cfi -coretest-novena.drc -coretest-novena.map -coretest-novena.mcs -coretest-novena.mrp -coretest-novena.ncd -coretest-novena.ngc -coretest-novena.ngc_xst.xrpt -coretest-novena.ngd -coretest-novena.ngm -coretest-novena.pcf -coretest-novena.prj -coretest-novena.prm -coretest-novena.psr -coretest-novena.scr -coretest-novena.srp -coretest-novena_bitgen.xwbt -coretest-novena_ngdbuild.xrpt -coretest-novena_par.ncd -coretest-novena_par.pad -coretest-novena_par.par -coretest-novena_par.ptwx -coretest-novena_par.unroutes -coretest-novena_par.xpi -coretest-novena_par_pad.csv -coretest-novena_par_pad.txt -coretest-novena_summary.xml -coretest-novena_usage.xml -netlist.lst -novena_fpga.lso -novena_fpga_map.xrpt -novena_fpga_par.xrpt -par_usage_statistics.html -usage_statistics_webtalk.html -webtalk.log -xlnx_auto_0_xdb -xst diff --git a/build/Makefile b/build/Makefile deleted file mode 100644 index d05a056..0000000 --- a/build/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -project = coretest-novena -vendor = xilinx -family = spartan6 -part = xc6slx45csg324-3 -top_module = novena_fpga -isedir = /opt/Xilinx/14.3/ISE_DS -xil_env = . $(isedir)/settings64.sh - -vfiles = ../src/rtl/novena_fpga.v ../src/rtl/coretest_hashes.v \ - ../../coretest/src/rtl/coretest.v \ - ../../i2c/src/rtl/i2c_core.v ../../i2c/src/rtl/i2c.v \ - ../../sha1/src/rtl/sha1_core.v ../../sha1/src/rtl/sha1.v \ - ../../sha1/src/rtl/sha1_w_mem.v \ - ../../sha256/src/rtl/sha256_core.v ../../sha256/src/rtl/sha256_k_constants.v \ - ../../sha256/src/rtl/sha256.v ../../sha256/src/rtl/sha256_w_mem.v \ - ../../sha512/src/rtl/sha512_core.v ../../sha512/src/rtl/sha512_h_constants.v \ - ../../sha512/src/rtl/sha512_k_constants.v ../../sha512/src/rtl/sha512.v \ - ../../sha512/src/rtl/sha512_w_mem.v - -include xilinx.mk diff --git a/build/coretest-novena.bmm b/build/coretest-novena.bmm deleted file mode 100644 index e69de29..0000000 diff --git a/build/coretest-novena.ucf b/build/coretest-novena.ucf deleted file mode 100644 index 448c692..0000000 --- a/build/coretest-novena.ucf +++ /dev/null @@ -1,594 +0,0 @@ -### Autogenerated on 2013-May-10 01:38 by edifToUcf.py -### Extracting designator U800 from EDIF netlist novena-dvt.EDF - -### extended performance annotation -CONFIG VCCAUX = 3.3; -# Valid values are 2.5 and 3.3 -CONFIG MCB_PERFORMANCE = EXTENDED; - -NET "APOPTOSIS" LOC = K1; -NET "APOPTOSIS" IOSTANDARD = LVCMOS33; - -# AUD6_TFS -# NET "DEL_CONT" LOC = A4; -# NET "DEL_CONT" IOSTANDARD = LVCMOS33; -# AUD6_TXC -# NET "DEL_RST_L" LOC = B4; -# NET "DEL_RST_L" IOSTANDARD = LVCMOS33; -# NET "AUD6_TXD" LOC = A6; -# NET "AUD6_TXD" IOSTANDARD = LVCMOS33; -# NET "AUD_MCLK" LOC = H6; -# NET "AUD_MCLK" IOSTANDARD = LVCMOS33; -# AUD_MIC_CLK -#NET "ZEROVEN" LOC = G3; -#NET "ZEROVEN" IOSTANDARD = LVCMOS33; -# NET "AUD_MIC_DAT" LOC = C5; -# NET "AUD_MIC_DAT" IOSTANDARD = LVCMOS33; - -# NET "BATT_NRST" LOC = N1; -# NET "BATT_NRST" IOSTANDARD = LVCMOS33; -# NET "BATT_REFLASH_ALRT" LOC = N2; -# NET "BATT_REFLASH_ALRT" IOSTANDARD = LVCMOS33; - -NET "CLK2_N" LOC = H1; -NET "CLK2_N" IOSTANDARD = LVDS_33; -NET "CLK2_N" DIFF_TERM = "TRUE"; -NET "CLK2_P" LOC = H2; -NET "CLK2_P" IOSTANDARD = LVDS_33; -NET "CLK2_P" DIFF_TERM = "TRUE"; - -# NET "DDC_SCL" LOC = J6; -# NET "DDC_SCL" IOSTANDARD = LVCMOS33; -# NET "DDC_SDA" LOC = F2; -# NET "DDC_SDA" IOSTANDARD = LVCMOS33; - -# ECSPI3_MISO -#NET "SPI1_MISO" LOC = A3; -#NET "SPI1_MISO" IOSTANDARD = LVCMOS33; -# # R13 -# ECSPI3_MOSI -#NET "SPI1_MOSI" LOC = A2; -#NET "SPI1_MOSI" IOSTANDARD = LVCMOS33; -# ECSPI3_RDY -#NET "SPI1_DELI_SEL" LOC = A5; -#NET "SPI1_DELI_SEL" IOSTANDARD = LVCMOS33; -# # R15 -# ECSPI3_SCLK -#NET "SPI1_SCLK" LOC = D9; -#NET "SPI1_SCLK" IOSTANDARD = LVCMOS33; -# ECSPI3_SS2 -#NET "SAMPEN" LOC = B3; -#NET "SAMPEN" IOSTANDARD = LVCMOS33; - -# NET "EIM_BCLK" LOC = C9; -# NET "EIM_BCLK" IOSTANDARD = LVCMOS33; -#NET "EIM_CS[0]" LOC = B11; -#NET "EIM_CS[0]" IOSTANDARD = LVCMOS33; -#NET "EIM_CS[1]" LOC = A15; -#NET "EIM_CS[1]" IOSTANDARD = LVCMOS33; - -NET "EIM_DA[0]" LOC = G9; -NET "EIM_DA[0]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[0]" SLEW = SLOW; -NET "EIM_DA[1]" LOC = A10; -NET "EIM_DA[1]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[1]" SLEW = SLOW; -NET "EIM_DA[2]" LOC = F9; -NET "EIM_DA[2]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[2]" SLEW = SLOW; -NET "EIM_DA[3]" LOC = B9; -NET "EIM_DA[3]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[3]" SLEW = SLOW; -NET "EIM_DA[4]" LOC = E13; -NET "EIM_DA[4]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[4]" SLEW = SLOW; -NET "EIM_DA[5]" LOC = F13; -NET "EIM_DA[5]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[5]" SLEW = SLOW; -NET "EIM_DA[6]" LOC = A9; -NET "EIM_DA[6]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[6]" SLEW = SLOW; -NET "EIM_DA[7]" LOC = A8; -NET "EIM_DA[7]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[7]" SLEW = SLOW; -NET "EIM_DA[8]" LOC = B8; -NET "EIM_DA[8]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[8]" SLEW = SLOW; -NET "EIM_DA[9]" LOC = D8; -NET "EIM_DA[9]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[9]" SLEW = SLOW; -NET "EIM_DA[10]" LOC = D11; -NET "EIM_DA[10]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[10]" SLEW = SLOW; -NET "EIM_DA[11]" LOC = C8; -NET "EIM_DA[11]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[11]" SLEW = SLOW; -NET "EIM_DA[12]" LOC = C7; -NET "EIM_DA[12]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[12]" SLEW = SLOW; - -NET "EIM_DA[13]" LOC = C11; -NET "EIM_DA[13]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[13]" SLEW = SLOW; - -NET "EIM_DA[14]" LOC = C4; -NET "EIM_DA[14]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[14]" SLEW = SLOW; -NET "EIM_DA[15]" LOC = B6; -NET "EIM_DA[15]" IOSTANDARD = LVCMOS33; -NET "EIM_DA[15]" SLEW = SLOW; - -# EIM_A16 -NET "EIM_A16" LOC = A11; -NET "EIM_A16" IOSTANDARD = LVCMOS33; -NET "EIM_A16" SLEW = SLOW; - -# EIM_A17 -NET "EIM_A17" LOC = B12; -NET "EIM_A17" IOSTANDARD = LVCMOS33; -NET "EIM_A17" SLEW = SLOW; -# EIM_A18 -#NET "ENC_PBIN" LOC = D14; -#NET "ENC_PBIN" IOSTANDARD = LVCMOS33; - -# EIM_LBA -#NET "EIM_LBA" LOC = B14; -#NET "EIM_LBA" IOSTANDARD = LVCMOS33; -# NET "EIM_OE" LOC = C10; -# NET "EIM_OE" IOSTANDARD = LVCMOS33; -# EIM_RW -#NET "LED3" LOC = C14; -#NET "LED3" IOSTANDARD = LVCMOS33; -# NET "EIM_WAIT" LOC = A7; -# NET "EIM_WAIT" IOSTANDARD = LVCMOS33; - -# #NET "FPGA_DONE" LOC = V17; -# #NET "FPGA_DONE" IOSTANDARD = LVCMOS33; -# #NET "FPGA_HSWAPEN" LOC = D4; -# #NET "FPGA_HSWAPEN" IOSTANDARD = LVCMOS33; -# FPGA_INIT_N -#NET "LED2" LOC = U3; -#NET "LED2" IOSTANDARD = LVCMOS33; - -NET "FPGA_LED2" LOC = A16; -NET "FPGA_LED2" IOSTANDARD = LVCMOS33; -NET "FPGA_LED2" SLEW = SLOW; - -# NET "FPGA_LSPI_CLK" LOC = D3; -# NET "FPGA_LSPI_CLK" IOSTANDARD = LVCMOS33; -# NET "FPGA_LSPI_CS" LOC = D1; -# NET "FPGA_LSPI_CS" IOSTANDARD = LVCMOS33; -# NET "FPGA_LSPI_HOLD" LOC = E3; -# NET "FPGA_LSPI_HOLD" IOSTANDARD = LVCMOS33; -# NET "FPGA_LSPI_MISO" LOC = D2; -# NET "FPGA_LSPI_MISO" IOSTANDARD = LVCMOS33; -# NET "FPGA_LSPI_MOSI" LOC = C2; -# NET "FPGA_LSPI_MOSI" IOSTANDARD = LVCMOS33; -# NET "FPGA_LSPI_WP" LOC = C1; -# NET "FPGA_LSPI_WP" IOSTANDARD = LVCMOS33; - -# #NET "FPGA_M0" LOC = T15; -# #NET "FPGA_M0" IOSTANDARD = LVCMOS33; -# #NET "FPGA_M1" LOC = N12; -# #NET "FPGA_M1" IOSTANDARD = LVCMOS33; - -# #NET "FPGA_RESET_N" LOC = V2; -# #NET "FPGA_RESET_N" IOSTANDARD = TMDS_33; -# #NET "FPGA_SUSPEND" LOC = R16; -# #NET "FPGA_SUSPEND" IOSTANDARD = LVCMOS33; -# #NET "FPGA_TCK" LOC = A17; -# #NET "FPGA_TCK" IOSTANDARD = LVCMOS33; -# #NET "FPGA_TDI" LOC = D15; -# #NET "FPGA_TDI" IOSTANDARD = LVCMOS33; -# #NET "FPGA_TDO" LOC = D16; -# #NET "FPGA_TDO" IOSTANDARD = LVCMOS33; -# #NET "FPGA_TMS" LOC = B18; -# #NET "FPGA_TMS" IOSTANDARD = LVCMOS33; - -# # NET "GND" LOC = A1;# A18 B7 B13 C3 C16 D5 D10 E15 G2 G5 G12 G17 H8 H10 J4 J9 J11 J15 K8 K10 L9 L11 M2 M6 M17 N13 R1 R4 R9 R14 R18 T16 U6 U12 V1 V18 -# # NET "GND" IOSTANDARD = LVCMOS33; - -NET "I2C3_SCL" LOC = P4; -NET "I2C3_SCL" IOSTANDARD = LVCMOS33; -NET "I2C3_SDA" LOC = P3; -NET "I2C3_SDA" IOSTANDARD = LVCMOS33; - -# # NET "P1_2V" LOC = G7;# H9 H11 J8 J10 K9 K11 L8 L10 M7 M12 -# # NET "P1_2V" IOSTANDARD = LVCMOS33; -# # NET "P3_3V_DELAYED" LOC = B1;# B5 B10 B15 B17 D7 D13 E2 E5 E9 E10 E14 E17 G4 G10 G15 J2 J5 J12 J14 J17 K7 M4 M9 M15 P5 P9 P10 P14 R2 R6 R12 R17 U4 U9 U14 -# # NET "P3_3V_DELAYED" IOSTANDARD = LVCMOS33; - -NET "RESETBMCU" LOC = F1; -NET "RESETBMCU" IOSTANDARD = LVCMOS33; - -# NET "SMB_SCL" LOC = N3; -# NET "SMB_SCL" IOSTANDARD = LVCMOS33; -# NET "SMB_SDA" LOC = N4; -# NET "SMB_SDA" IOSTANDARD = LVCMOS33; - -# NET "UART4_CTS" LOC = U1; -# NET "UART4_CTS" IOSTANDARD = LVCMOS33; -# NET "UART4_RTS" LOC = U2; -# NET "UART4_RTS" IOSTANDARD = LVCMOS33; -# NET "UART4_RXD" LOC = T1; -# NET "UART4_RXD" IOSTANDARD = LVCMOS33; -# NET "UART4_TXD" LOC = P1; -# NET "UART4_TXD" IOSTANDARD = LVCMOS33; - -# UIM_CLK -#NET "MODES" LOC = B16; -#NET "MODES" IOSTANDARD = LVCMOS33; -# UIM_DATA -#NET "ENC_SW" LOC = A12; -#NET "ENC_SW" IOSTANDARD = LVCMOS33; -# #NET "UIM_PWR" LOC = C18; -# #NET "UIM_PWR" IOSTANDARD = SSTL15_II; -# #NET "UIM_PWRON" LOC = A14; -# #NET "UIM_PWRON" IOSTANDARD = LVCMOS33; -# UIM_RESET -#NET "SW_BACKUP" LOC = C15; -#NET "SW_BACKUP" IOSTANDARD = LVCMOS33; - -############## -# DDR3 -############## - -# NET "F_BA[2]" IOSTANDARD = SSTL15_II; -# NET "F_BA[1]" IOSTANDARD = SSTL15_II; -# NET "F_BA[0]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[13]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[12]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[11]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[10]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[9]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[8]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[7]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[6]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[5]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[4]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[3]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[2]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[1]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_A[0]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[15]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[14]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[13]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[12]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[11]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[10]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[9]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[8]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[7]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[6]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[5]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[4]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[3]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[2]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[1]" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_D[0]" IOSTANDARD = SSTL15_II; -# NET "F_CAS_N" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_CKE" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_ODT" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_RST_N" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_RZQ" IOSTANDARD = SSTL15_II; -# NET "F_DDR3_ZIO" IOSTANDARD = SSTL15_II; -# NET "F_LDM" IOSTANDARD = SSTL15_II; -# NET "F_RAS_N" IOSTANDARD = SSTL15_II; -# NET "F_UDM" IOSTANDARD = SSTL15_II; -# NET "F_WE_N" IOSTANDARD = SSTL15_II; - - -# NET "F_BA[0]" LOC = H13; -# NET "F_BA[1]" LOC = H14; -# NET "F_BA[2]" LOC = K13; -# NET "F_BA[0]" OUT_TERM = UNTUNED_50; -# NET "F_BA[1]" OUT_TERM = UNTUNED_50; -# NET "F_BA[2]" OUT_TERM = UNTUNED_50; - -# NET "F_CAS_N" LOC = K16; -# NET "F_CAS_N" OUT_TERM = UNTUNED_50; - -# NET "F_DDR3_A[0]" LOC = H15; -# NET "F_DDR3_A[1]" LOC = H16; -# NET "F_DDR3_A[10]" LOC = E16; -# NET "F_DDR3_A[11]" LOC = G14; -# NET "F_DDR3_A[12]" LOC = D18; -# NET "F_DDR3_A[13]" LOC = C17; -# NET "F_DDR3_A[2]" LOC = F18; -# NET "F_DDR3_A[3]" LOC = J13; -# NET "F_DDR3_A[4]" LOC = E18; -# NET "F_DDR3_A[5]" LOC = L12; -# NET "F_DDR3_A[6]" LOC = L13; -# NET "F_DDR3_A[7]" LOC = F17; -# NET "F_DDR3_A[8]" LOC = H12; -# NET "F_DDR3_A[9]" LOC = G13; -# NET "F_DDR3_A[0]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[10]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[11]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[12]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[13]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[1]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[2]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[3]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[4]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[5]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[6]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[7]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[8]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_A[9]" OUT_TERM = UNTUNED_50; - -# NET "F_DDR3_CKE" LOC = D17; -# NET "F_DDR3_CKE" OUT_TERM = UNTUNED_50; - -# NET "F_DDR3_CK_N" LOC = G18; -# NET "F_DDR3_CK_N" IOSTANDARD = DIFF_SSTL15_II; -# NET "F_DDR3_CK_N" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_CK_P" LOC = G16; -# NET "F_DDR3_CK_P" IOSTANDARD = DIFF_SSTL15_II; -# NET "F_DDR3_CK_P" OUT_TERM = UNTUNED_50; - -# NET "F_DDR3_D[0]" LOC = M16; -# NET "F_DDR3_D[1]" LOC = M18; -# NET "F_DDR3_D[10]" LOC = P17; -# NET "F_DDR3_D[11]" LOC = P18; -# NET "F_DDR3_D[12]" LOC = T17; -# NET "F_DDR3_D[13]" LOC = T18; -# NET "F_DDR3_D[14]" LOC = U17; -# NET "F_DDR3_D[15]" LOC = U18; -# NET "F_DDR3_D[2]" LOC = L17; -# NET "F_DDR3_D[3]" LOC = L18; -# NET "F_DDR3_D[4]" LOC = H17; -# NET "F_DDR3_D[5]" LOC = H18; -# NET "F_DDR3_D[6]" LOC = J16; -# NET "F_DDR3_D[7]" LOC = J18; -# NET "F_DDR3_D[8]" LOC = N17; -# NET "F_DDR3_D[9]" LOC = N18; -# NET "F_DDR3_D[0]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[10]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[11]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[12]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[13]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[14]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[15]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[1]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[2]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[3]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[4]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[5]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[6]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[7]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[8]" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_D[9]" OUT_TERM = UNTUNED_50; - -# NET "F_DDR3_RST_N" LOC = F14; -# NET "F_DDR3_RST_N" OUT_TERM = UNTUNED_50; - -# NET "F_DDR3_ODT" LOC = K14; -# NET "F_DDR3_ODT" OUT_TERM = UNTUNED_50; - -# NET "F_RAS_N" LOC = K15; -# NET "F_RAS_N" OUT_TERM = UNTUNED_50; -# NET "F_UDM" LOC = L15; -# NET "F_UDM" OUT_TERM = UNTUNED_50; -# NET "F_UDQS_N" LOC = N16; -# NET "F_UDQS_N" IOSTANDARD = DIFF_SSTL15_II; -# NET "F_UDQS_N" OUT_TERM = UNTUNED_50; -# NET "F_UDQS_P" LOC = N15; -# NET "F_UDQS_P" IOSTANDARD = DIFF_SSTL15_II; -# NET "F_UDQS_P" OUT_TERM = UNTUNED_50; -# NET "F_LDM" LOC = L16; -# NET "F_LDM" OUT_TERM = UNTUNED_50; -# NET "F_LDQS_N" LOC = K18; -# NET "F_LDQS_N" IOSTANDARD = DIFF_SSTL15_II; -# NET "F_LDQS_N" OUT_TERM = UNTUNED_50; -# NET "F_LDQS_P" LOC = K17; -# NET "F_LDQS_P" IOSTANDARD = DIFF_SSTL15_II; -# NET "F_LDQS_P" OUT_TERM = UNTUNED_50; -# NET "F_WE_N" LOC = K12; -# NET "F_WE_N" OUT_TERM = UNTUNED_50; - -# NET "F_DDR3_RZQ" LOC = F15; -# NET "F_DDR3_RZQ" OUT_TERM = UNTUNED_50; -# NET "F_DDR3_ZIO" LOC = M14; -# NET "F_DDR3_ZIO" OUT_TERM = UNTUNED_50; - -#NET "F_BA[*]" IOSTANDARD = SSTL15_II | OUT_TERM = UNTUNED_50; - -#NET "F_CAS_N" IOSTANDARD = SSTL15_II | OUT_TERM = UNTUNED_50; - -#NET "F_DDR3_A[*]" SSTL15_II | OUT_TERM = UNTUNED_50; - -#NET "F_DDR3_CKE" IOSTANDARD = SSTL15_II | OUT_TERM = UNTUNED_50; - - -#NET "F_DDR3_D[*]" IOSTANDARD = SSTL15_II | OUT_TERM = UNTUNED_50; - -#NET "F_DDR3_RST_N" IOSTANDARD = SSTL15_II | OUT_TERM = UNTUNED_50; - -#NET "F_DDR3_ODT" IOSTANDARD = SSTL15_II | OUT_TERM = UNTUNED_50; - -#NET "F_RAS_N" IOSTANDARD = SSTL15_II | OUT_TERM = UNTUNED_50; -#NET "F_UDM" IOSTANDARD = SSTL15_II | OUT_TERM = UNTUNED_50; -#NET "F_LDM" IOSTANDARD = SSTL15_II | OUT_TERM = UNTUNED_50; -#NET "F_WE_N" IOSTANDARD = SSTL15_II | OUT_TERM = UNTUNED_50; - -#NET "F_DDR3_RZQ" IOSTANDARD = SSTL15_II | OUT_TERM = UNTUNED_50; -#NET "F_DDR3_ZIO" IOSTANDARD = SSTL15_II | OUT_TERM = UNTUNED_50; - - -############## -# I/O connector -############## -#NET "F_DX0" LOC = K6; -#NET "F_DX0" IOSTANDARD = LVCMOS33; -#NET "F_DX0" SLEW = SLOW; -# NET "F_DX0" PULLUP; - -NET "F_DX1" LOC = L7; -NET "F_DX1" IOSTANDARD = LVCMOS33; -NET "F_DX1" SLEW = SLOW; - -#NET "F_DX2" LOC = H3; -#NET "F_DX2" IOSTANDARD = LVCMOS33; -#NET "F_DX2" SLEW = SLOW; - -#NET "F_DX3" LOC = H4; -#NET "F_DX3" IOSTANDARD = LVCMOS33; -#NET "F_DX3" SLEW = SLOW; -# NET "F_DX3" PULLUP; - -# NET "F_DX[4]" LOC = J1; -# NET "F_DX[5]" LOC = J3; -# NET "F_DX6" LOC = L3; -# NET "F_DX6" IOSTANDARD = LVCMOS33; -# NET "F_DX6" SLEW = SLOW; - -# NET "F_DX7" LOC = L4; -# NET "F_DX7" IOSTANDARD = LVCMOS33; -# NET "F_DX7" SLEW = SLOW; - -# NET "F_DX8" LOC = K2; -# NET "F_DX8" IOSTANDARD = LVCMOS33; -# NET "F_DX8" SLEW = SLOW; - -#NET "F_DX11" LOC = M1; -#NET "F_DX11" IOSTANDARD = LVCMOS33; -#NET "F_DX11" SLEW = SLOW; -# NET "F_DX12" LOC = M3; -# NET "F_DX12" IOSTANDARD = LVCMOS33; -# NET "F_DX12" SLEW = SLOW; - -# NET "F_DX13" LOC = P2; -# NET "F_DX13" IOSTANDARD = LVCMOS33; -# NET "F_DX13" SLEW = SLOW; - -# NET "F_DX14" LOC = T2; -# NET "F_DX14" IOSTANDARD = LVCMOS33; -# NET "F_DX14" SLEW = SLOW; - -NET "F_DX15" LOC = M5; -NET "F_DX15" IOSTANDARD = LVCMOS33; -NET "F_DX15" SLEW = SLOW; - -# NET "F_DX[16]" LOC = L6; -NET "F_DX17" LOC = G1; -NET "F_DX17" IOSTANDARD = LVCMOS33; -NET "F_DX17" SLEW = SLOW; -#NET "F_DX18" LOC = H7; -#NET "F_DX18" IOSTANDARD = LVCMOS33; -#NET "F_DX18" SLEW = SLOW; - -# NET "F_DX[*]" IOSTANDARD = LVCMOS33; - -NET "F_LVDS_N0" LOC = P6; -NET "F_LVDS_N0" IOSTANDARD = LVCMOS33; -NET "F_LVDS_N0" SLEW = SLOW; -NET "F_LVDS_P0" LOC = N5; -NET "F_LVDS_P0" IOSTANDARD = LVCMOS33; -NET "F_LVDS_P0" SLEW = SLOW; -# NET "F_LVDS_N1" LOC = V4; -# NET "F_LVDS_N1" IOSTANDARD = LVCMOS33; -# NET "F_LVDS_N1" SLEW = SLOW; -# NET "F_LVDS_P1" LOC = T4; -# NET "F_LVDS_P1" IOSTANDARD = LVCMOS33; -# NET "F_LVDS_P1" SLEW = SLOW; -# NET "F_LVDS_N2" LOC = T3; -# NET "F_LVDS_N2" IOSTANDARD = LVCMOS33; -# NET "F_LVDS_N2" SLEW = SLOW; -# NET "F_LVDS_P[2]" LOC = R3; - -# NET "F_LVDS_N3" LOC = V5; -# NET "F_LVDS_N3" IOSTANDARD = LVCMOS33; -# NET "F_LVDS_N3" SLEW = SLOW; - -# NET "F_LVDS_P[3]" LOC = U5; -# NET "F_LVDS_N4" LOC = T5; -# NET "F_LVDS_N4" IOSTANDARD = LVCMOS33; -# NET "F_LVDS_N4" SLEW = SLOW; -NET "F_LVDS_P4" LOC = R5; -NET "F_LVDS_P4" IOSTANDARD = LVCMOS33; -NET "F_LVDS_P4" SLEW = SLOW; - -# NET "F_LVDS_N5" LOC = T7; -# NET "F_LVDS_N5" IOSTANDARD = LVCMOS33; -# NET "F_LVDS_N5" SLEW = SLOW; - -# NET "F_LVDS_P5" LOC = R7; -# NET "F_LVDS_P5" IOSTANDARD = LVCMOS33; -# NET "F_LVDS_P5" SLEW = SLOW; - -# NET "F_LVDS_N[6]" LOC = V6; -# NET "F_LVDS_P[6]" LOC = T6; -NET "F_LVDS_N7" LOC = V7; -NET "F_LVDS_N7" IOSTANDARD = LVCMOS33; -NET "F_LVDS_N7" SLEW = SLOW; - -NET "F_LVDS_P7" LOC = U7; -NET "F_LVDS_P7" IOSTANDARD = LVCMOS33; -NET "F_LVDS_P7" SLEW = SLOW; - -# NET "F_LVDS_N8" LOC = V8; -# NET "F_LVDS_N8" IOSTANDARD = LVCMOS33; -# NET "F_LVDS_N8" SLEW = SLOW; - -# NET "F_LVDS_P[8]" LOC = U8; -# NET "F_LVDS_N[9]" LOC = V9; -#NET "F_LVDS_P9" LOC = T9; -#NET "F_LVDS_P9" IOSTANDARD = LVCMOS33; - -# NET "F_LVDS_N[10]" LOC = V11; -# NET "F_LVDS_P[10]" LOC = U11; -NET "F_LVDS_N11" LOC = T11; -NET "F_LVDS_N11" IOSTANDARD = LVCMOS33; -NET "F_LVDS_N11" SLEW = SLOW; -NET "F_LVDS_P11" LOC = R11; -NET "F_LVDS_P11" IOSTANDARD = LVCMOS33; -NET "F_LVDS_P11" SLEW = SLOW; -# NET "F_LVDS_N[12]" LOC = V13; -# NET "F_LVDS_P[12]" LOC = U13; -# NET "F_LVDS_N[13]" LOC = V14; -# NET "F_LVDS_P[13]" LOC = T14; -# NET "F_LVDS_N[14]" LOC = V16; -# NET "F_LVDS_P[14]" LOC = U16; -NET "F_LVDS_N15" LOC = V10; -NET "F_LVDS_N15" IOSTANDARD = LVCMOS33; -NET "F_LVDS_N15" SLEW = SLOW; -NET "F_LVDS_P15" LOC = U10; -NET "F_LVDS_P15" IOSTANDARD = LVCMOS33; -NET "F_LVDS_P15" SLEW = SLOW; - -# NET "F_LVDS_P[*]" IOSTANDARD = LVDS_33 | DIFF_TERM = TRUE; -# NET "F_LVDS_N[*]" IOSTANDARD = LVDS_33 | DIFF_TERM = TRUE; - -# NET "F_LVDS_NA" LOC = K3; -# NET "F_LVDS_NA" IOSTANDARD = LVDS_33 | DIFF_TERM = TRUE; -# NET "F_LVDS_PA" LOC = K4; -# NET "F_LVDS_PA" IOSTANDARD = LVDS_33 | DIFF_TERM = TRUE; -# NET "F_LVDS_NB" LOC = K5; -# NET "F_LVDS_NB" IOSTANDARD = LVCMOS33; -# NET "F_LVDS_NB" SLEW = SLOW; -# NET "F_LVDS_PB" LOC = L5; -# NET "F_LVDS_PB" IOSTANDARD = LVCMOS33; -# NET "F_LVDS_PB" SLEW = SLOW; -NET "F_LVDS_NC" LOC = L1; -NET "F_LVDS_NC" IOSTANDARD = LVCMOS33; -NET "F_LVDS_NC" SLEW = SLOW; -# NET "F_LVDS_PC" LOC = L2; -# NET "F_LVDS_PC" IOSTANDARD = LVCMOS33; -# NET "F_LVDS_PC" SLEW = SLOW; - -#NET "F_LVDS_CK0_N" LOC = T8; -#NET "F_LVDS_CK0_N" IOSTANDARD = LVCMOS33; -#NET "F_LVDS_CK0_P" LOC = R8; -#NET "F_LVDS_CK0_P" IOSTANDARD = LVCMOS33; - -NET "F_LVDS_CK1_N" LOC = T10; -NET "F_LVDS_CK1_N" IOSTANDARD = LVCMOS33; -NET "F_LVDS_CK1_N" SLEW = SLOW; -NET "F_LVDS_CK1_P" LOC = R10; -NET "F_LVDS_CK1_P" IOSTANDARD = LVCMOS33; -NET "F_LVDS_CK1_P" SLEW = SLOW; - -# NET "F_LVDS_CK_N[*]" IOSTANDARD = LVDS_33 | DIFF_TERM = TRUE; -# NET "F_LVDS_CK_P[*]" IOSTANDARD = LVDS_33 | DIFF_TERM = TRUE; -NET "CLK2_P" PERIOD = 20 ns; diff --git a/build/xilinx.mk b/build/xilinx.mk deleted file mode 100644 index a3a0216..0000000 --- a/build/xilinx.mk +++ /dev/null @@ -1,176 +0,0 @@ -# The top level module should define the variables below then include -# this file. The files listed should be in the same directory as the -# Makefile. -# -# variable description -# ---------- ------------- -# project project name (top level module should match this name) -# top_module top level module of the project -# libdir path to library directory -# libs library modules used -# vfiles all local .v files -# xilinx_cores all local .xco files -# vendor vendor of FPGA (xilinx, altera, etc.) -# family FPGA device family (spartan3e) -# part FPGA part name (xc4vfx12-10-sf363) -# flashsize size of flash for mcs file (16384) -# optfile (optional) xst extra opttions file to put in .scr -# map_opts (optional) options to give to map -# par_opts (optional) options to give to par -# intstyle (optional) intstyle option to all tools -# -# files description -# ---------- ------------ -# $(project).ucf ucf file -# -# Library modules should have a modules.mk in their root directory, -# namely $(libdir)//module.mk, that simply adds to the vfiles -# and xilinx_cores variable. -# -# all the .xco files listed in xilinx_cores will be generated with core, with -# the resulting .v and .ngc files placed back in the same directory as -# the .xco file. -# -# TODO: .xco files are device dependant, should use a template based system - -coregen_work_dir ?= ./coregen-tmp -map_opts ?= -timing -ol high -detail -pr b -register_duplication -w -par_opts ?= -ol high -isedir ?= /opt/Xilinx/13.3/ISE_DS -xil_env ?= . $(isedir)/settings32.sh -flashsize ?= 8192 - -libmks = $(patsubst %,$(libdir)/%/module.mk,$(libs)) -mkfiles = Makefile $(libmks) xilinx.mk -include $(libmks) - -corengcs = $(foreach core,$(xilinx_cores),$(core:.xco=.ngc)) -local_corengcs = $(foreach ngc,$(corengcs),$(notdir $(ngc))) -vfiles += $(foreach core,$(xilinx_cores),$(core:.xco=.v)) -junk += $(local_corengcs) - -.PHONY: default xilinx_cores clean twr etwr -default: $(project).bit $(project).mcs -xilinx_cores: $(corengcs) -twr: $(project).twr -etwr: $(project)_err.twr - -define cp_template -$(2): $(1) - cp $(1) $(2) -endef -$(foreach ngc,$(corengcs),$(eval $(call cp_template,$(ngc),$(notdir $(ngc))))) - -%.ngc %.v: %.xco - @echo "=== rebuilding $@" - if [ -d $(coregen_work_dir) ]; then \ - rm -rf $(coregen_work_dir)/*; \ - else \ - mkdir -p $(coregen_work_dir); \ - fi - cd $(coregen_work_dir); \ - $(xil_env); \ - coregen -b $$OLDPWD/$<; \ - cd - - xcodir=`dirname $<`; \ - basename=`basename $< .xco`; \ - if [ ! -r $(coregen_work_dir/$$basename.ngc) ]; then \ - echo "'$@' wasn't created."; \ - exit 1; \ - else \ - cp $(coregen_work_dir)/$$basename.v $(coregen_work_dir)/$$basename.ngc $$xcodir; \ - fi -junk += $(coregen_work_dir) - -date = $(shell date +%F-%H-%M) - -# some common junk -junk += *.xrpt - -programming_files: $(project).bit $(project).mcs - mkdir -p $@/$(date) - mkdir -p $@/latest - for x in .bit .mcs .cfi _bd.bmm; do cp $(project)$$x $@/$(date)/$(project)$$x; cp $(project)$$x $@/latest/$(project)$$x; done - $(xil_env); xst -help | head -1 | sed 's/^/#/' | cat - $(project).scr > $@/$(date)/$(project).scr - -$(project).mcs: $(project).bit - $(xil_env); \ - promgen -w -s $(flashsize) -p mcs -o $@ -u 0 $^ -junk += $(project).mcs $(project).cfi $(project).prm - -$(project).bit: $(project)_par.ncd - $(xil_env); \ - bitgen $(intstyle) -g UnusedPin:Pullnone -g DriveDone:yes -g StartupClk:Cclk -w $(project)_par.ncd $(project).bit -junk += $(project).bgn $(project).bit $(project).drc $(project)_bd.bmm - - -$(project)_par.ncd: $(project).ncd - $(xil_env); \ - if par $(intstyle) $(par_opts) -w $(project).ncd $(project)_par.ncd; then \ - :; \ - else \ - $(MAKE) etwr; \ - fi -junk += $(project)_par.ncd $(project)_par.par $(project)_par.pad -junk += $(project)_par_pad.csv $(project)_par_pad.txt -junk += $(project)_par.grf $(project)_par.ptwx -junk += $(project)_par.unroutes $(project)_par.xpi - -$(project).ncd: $(project).ngd - if [ -r $(project)_par.ncd ]; then \ - cp $(project)_par.ncd smartguide.ncd; \ - smartguide="-smartguide smartguide.ncd"; \ - else \ - smartguide=""; \ - fi; \ - $(xil_env); \ - map $(intstyle) $(map_opts) $$smartguide $< -junk += $(project).ncd $(project).pcf $(project).ngm $(project).mrp $(project).map -junk += smartguide.ncd $(project).psr -junk += $(project)_summary.xml $(project)_usage.xml - -$(project).ngd: $(project).ngc $(project).ucf $(project).bmm - $(xil_env); ngdbuild $(intstyle) $(project).ngc -bm $(project).bmm -junk += $(project).ngd $(project).bld - -$(project).ngc: $(vfiles) $(local_corengcs) $(project).scr $(project).prj - $(xil_env); xst $(intstyle) -ifn $(project).scr -junk += xlnx_auto* $(top_module).lso $(project).srp -junk += netlist.lst xst $(project).ngc - -$(project).prj: $(vfiles) $(mkfiles) - for src in $(vfiles); do echo "verilog work $$src" >> $(project).tmpprj; done - sort -u $(project).tmpprj > $(project).prj - rm -f $(project).tmpprj -junk += $(project).prj - -optfile += $(wildcard $(project).opt) -top_module ?= $(project) -$(project).scr: $(optfile) $(mkfiles) ./xilinx.opt - echo "run" > $@ - echo "-p $(part)" >> $@ - echo "-top $(top_module)" >> $@ - echo "-ifn $(project).prj" >> $@ - echo "-ofn $(project).ngc" >> $@ - cat ./xilinx.opt $(optfile) >> $@ -junk += $(project).scr - -$(project).post_map.twr: $(project).ncd - $(xil_env); trce -e 10 $< $(project).pcf -o $@ -junk += $(project).post_map.twr $(project).post_map.twx smartpreview.twr - -$(project).twr: $(project)_par.ncd - $(xil_env); trce $< $(project).pcf -o $(project).twr -junk += $(project).twr $(project).twx smartpreview.twr - -$(project)_err.twr: $(project)_par.ncd - $(xil_env); trce -e 10 $< $(project).pcf -o $(project)_err.twr -junk += $(project)_err.twr $(project)_err.twx -junk += $(project).lso $(project)_bitgen.xwb $(project)_bitgen.xwbt -junk += usage_statistics_webtalk.html par_usage_statistics.html webtalk.log _xmsgs default.xreport - -.gitignore: $(mkfiles) - echo programming_files $(junk) | sed 's, ,\n,g' > .gitignore - -clean:: - rm -rf $(junk) diff --git a/build/xilinx.opt b/build/xilinx.opt deleted file mode 100644 index 7fe9d8b..0000000 --- a/build/xilinx.opt +++ /dev/null @@ -1,42 +0,0 @@ --ifmt mixed --ofmt NGC --opt_mode speed --opt_level 1 --iuc NO --keep_hierarchy no --netlist_hierarchy as_optimized --rtlview no --glob_opt AllClockNets --read_cores yes --write_timing_constraints NO --cross_clock_analysis NO --hierarchy_separator / --bus_delimiter <> --case maintain --slice_utilization_ratio 100 --bram_utilization_ratio 100 -#-dsp_utilization_ratio 100 --safe_implementation No --fsm_extract YES --fsm_encoding Auto --fsm_style lut --ram_extract Yes --ram_style Auto --rom_extract Yes --rom_style Auto --shreg_extract YES --auto_bram_packing NO --resource_sharing YES --async_to_sync NO -#-use_dsp48 auto --iobuf YES --max_fanout 500 --register_duplication YES --register_balancing No --optimize_primitives NO --use_clock_enable Auto --use_sync_set Auto --use_sync_reset Auto --iob auto --equivalent_register_removal YES --slice_utilization_ratio_maxmargin 5 diff --git a/common/rtl/ipcore/_xmsgs/cg.xmsgs b/common/rtl/ipcore/_xmsgs/cg.xmsgs new file mode 100644 index 0000000..985e6e3 --- /dev/null +++ b/common/rtl/ipcore/_xmsgs/cg.xmsgs @@ -0,0 +1,27 @@ + + + +Generating IP... + + +A core named 'clkmgr_dcm' already exists in the project. Output products for this core may be overwritten. + + +A core named 'clkmgr_dcm' already exists in the project. Output products for this core may be overwritten. + + +Component clk_wiz_v3_6 does not have a valid model name for Verilog synthesis + + +Finished generation of ASY schematic symbol. + + +Finished FLIST file generation. + + + + diff --git a/common/rtl/ipcore/clkmgr_dcm.asy b/common/rtl/ipcore/clkmgr_dcm.asy new file mode 100644 index 0000000..016d02a --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm.asy @@ -0,0 +1,25 @@ +Version 4 +SymbolType BLOCK +TEXT 32 32 LEFT 4 clkmgr_dcm +RECTANGLE Normal 32 32 576 1088 +LINE Normal 0 80 32 80 +PIN 0 80 LEFT 36 +PINATTR PinName clk_in1 +PINATTR Polarity IN +LINE Normal 0 432 32 432 +PIN 0 432 LEFT 36 +PINATTR PinName reset +PINATTR Polarity IN +LINE Normal 608 80 576 80 +PIN 608 80 RIGHT 36 +PINATTR PinName clk_out1 +PINATTR Polarity OUT +LINE Normal 608 880 576 880 +PIN 608 880 RIGHT 36 +PINATTR PinName input_clk_stopped +PINATTR Polarity OUT +LINE Normal 608 1008 576 1008 +PIN 608 1008 RIGHT 36 +PINATTR PinName clk_valid +PINATTR Polarity OUT + diff --git a/common/rtl/ipcore/clkmgr_dcm.gise b/common/rtl/ipcore/clkmgr_dcm.gise new file mode 100644 index 0000000..ed6d0f7 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm.gise @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + 11.1 + + + + + + + + + + + diff --git a/common/rtl/ipcore/clkmgr_dcm.ncf b/common/rtl/ipcore/clkmgr_dcm.ncf new file mode 100644 index 0000000..ef4e259 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm.ncf @@ -0,0 +1,60 @@ +# file: clkmgr_dcm.ucf +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# Input clock periods. These duplicate the values entered for the +# input clocks. You can use these to time your system +#---------------------------------------------------------------- +NET "CLK_IN1" TNM_NET = "CLK_IN1"; +TIMESPEC "TS_CLK_IN1" = PERIOD "CLK_IN1" 20.0 ns HIGH 50% INPUT_JITTER 200.0ps; + + +# FALSE PATH constraints +PIN "RESET" TIG; + + diff --git a/common/rtl/ipcore/clkmgr_dcm.sym b/common/rtl/ipcore/clkmgr_dcm.sym new file mode 100644 index 0000000..7d178b8 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm.sym @@ -0,0 +1,24 @@ + + + BLOCK + 2015-1-28T21:56:19 + + + + + + + clkmgr_dcm + + + + + + + + + + + + + diff --git a/common/rtl/ipcore/clkmgr_dcm.ucf b/common/rtl/ipcore/clkmgr_dcm.ucf new file mode 100644 index 0000000..658fdb4 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm.ucf @@ -0,0 +1,59 @@ +# file: clkmgr_dcm.ucf +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# Input clock periods. These duplicate the values entered for the +# input clocks. You can use these to time your system +#---------------------------------------------------------------- +NET "CLK_IN1" TNM_NET = "CLK_IN1"; +TIMESPEC "TS_CLK_IN1" = PERIOD "CLK_IN1" 20.0 ns HIGH 50% INPUT_JITTER 200.0ps; + + +# FALSE PATH constraints +PIN "RESET" TIG; + diff --git a/common/rtl/ipcore/clkmgr_dcm.v b/common/rtl/ipcore/clkmgr_dcm.v new file mode 100644 index 0000000..71477a8 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm.v @@ -0,0 +1,148 @@ +// file: clkmgr_dcm.v +// +// (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +// +// This file contains confidential and proprietary information +// of Xilinx, Inc. and is protected under U.S. and +// international copyright and other intellectual property +// laws. +// +// DISCLAIMER +// This disclaimer is not a license and does not grant any +// rights to the materials distributed herewith. Except as +// otherwise provided in a valid license issued to you by +// Xilinx, and to the maximum extent permitted by applicable +// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +// (2) Xilinx shall not be liable (whether in contract or tort, +// including negligence, or under any other theory of +// liability) for any loss or damage of any kind or nature +// related to, arising under or in connection with these +// materials, including for any direct, or any indirect, +// special, incidental, or consequential loss or damage +// (including loss of data, profits, goodwill, or any type of +// loss or damage suffered as a result of any action brought +// by a third party) even if such damage or loss was +// reasonably foreseeable or Xilinx had been advised of the +// possibility of the same. +// +// CRITICAL APPLICATIONS +// Xilinx products are not designed or intended to be fail- +// safe, or for use in any application requiring fail-safe +// performance, such as life-support or safety devices or +// systems, Class III medical devices, nuclear facilities, +// applications related to the deployment of airbags, or any +// other applications that could lead to death, personal +// injury, or severe property or environmental damage +// (individually and collectively, "Critical +// Applications"). Customer assumes the sole risk and +// liability of any use of Xilinx products in Critical +// Applications, subject only to applicable laws and +// regulations governing limitations on product liability. +// +// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +// PART OF THIS FILE AT ALL TIMES. +// +//---------------------------------------------------------------------------- +// User entered comments +//---------------------------------------------------------------------------- +// None +// +//---------------------------------------------------------------------------- +// "Output Output Phase Duty Pk-to-Pk Phase" +// "Clock Freq (MHz) (degrees) Cycle (%) Jitter (ps) Error (ps)" +//---------------------------------------------------------------------------- +// CLK_OUT1____50.000______0.000______50.0______200.000____150.000 +// +//---------------------------------------------------------------------------- +// "Input Clock Freq (MHz) Input Jitter (UI)" +//---------------------------------------------------------------------------- +// __primary______________50____________0.010 + +`timescale 1ps/1ps + +(* CORE_GENERATION_INFO = "clkmgr_dcm,clk_wiz_v3_6,{component_name=clkmgr_dcm,use_phase_alignment=true,use_min_o_jitter=false,use_max_i_jitter=false,use_dyn_phase_shift=false,use_inclk_switchover=false,use_dyn_reconfig=false,feedback_source=FDBK_AUTO,primtype_sel=DCM_SP,num_out_clk=1,clkin1_period=20.0,clkin2_period=20.0,use_power_down=false,use_reset=true,use_locked=false,use_inclk_stopped=true,use_status=false,use_freeze=false,use_clk_valid=true,feedback_type=SINGLE,clock_mgr_type=MANUAL,manual_override=false}" *) +module clkmgr_dcm + (// Clock in ports + input CLK_IN1, + // Clock out ports + output CLK_OUT1, + // Status and control signals + input RESET, + output INPUT_CLK_STOPPED, + output CLK_VALID + ); + + // Input buffering + //------------------------------------ + assign clkin1 = CLK_IN1; + + + // Clocking primitive + //------------------------------------ + + // Instantiation of the DCM primitive + // * Unused inputs are tied off + // * Unused outputs are labeled unused + wire psdone_unused; + wire locked_int; + wire [7:0] status_int; + wire clkfb; + wire clk0; + + DCM_SP + #(.CLKDV_DIVIDE (2.000), + .CLKFX_DIVIDE (1), + .CLKFX_MULTIPLY (4), + .CLKIN_DIVIDE_BY_2 ("FALSE"), + .CLKIN_PERIOD (20.0), + .CLKOUT_PHASE_SHIFT ("NONE"), + .CLK_FEEDBACK ("1X"), + .DESKEW_ADJUST ("SYSTEM_SYNCHRONOUS"), + .PHASE_SHIFT (0), + .STARTUP_WAIT ("FALSE")) + dcm_sp_inst + // Input clock + (.CLKIN (clkin1), + .CLKFB (clkfb), + // Output clocks + .CLK0 (clk0), + .CLK90 (), + .CLK180 (), + .CLK270 (), + .CLK2X (), + .CLK2X180 (), + .CLKFX (), + .CLKFX180 (), + .CLKDV (), + // Ports for dynamic phase shift + .PSCLK (1'b0), + .PSEN (1'b0), + .PSINCDEC (1'b0), + .PSDONE (), + // Other control and status signals + .LOCKED (locked_int), + .STATUS (status_int), + + .RST (RESET), + // Unused pin- tie low + .DSSEN (1'b0)); + + assign INPUT_CLK_STOPPED = status_int[1]; + assign CLK_VALID = ( ( locked_int == 1'b 1 ) && ( status_int[1] == 1'b 0 ) ); + + // Output buffering + //----------------------------------- + assign clkfb = CLK_OUT1; + + BUFG clkout1_buf + (.O (CLK_OUT1), + .I (clk0)); + + + + +endmodule diff --git a/common/rtl/ipcore/clkmgr_dcm.veo b/common/rtl/ipcore/clkmgr_dcm.veo new file mode 100644 index 0000000..c4e1d31 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm.veo @@ -0,0 +1,79 @@ +// +// (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +// +// This file contains confidential and proprietary information +// of Xilinx, Inc. and is protected under U.S. and +// international copyright and other intellectual property +// laws. +// +// DISCLAIMER +// This disclaimer is not a license and does not grant any +// rights to the materials distributed herewith. Except as +// otherwise provided in a valid license issued to you by +// Xilinx, and to the maximum extent permitted by applicable +// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +// (2) Xilinx shall not be liable (whether in contract or tort, +// including negligence, or under any other theory of +// liability) for any loss or damage of any kind or nature +// related to, arising under or in connection with these +// materials, including for any direct, or any indirect, +// special, incidental, or consequential loss or damage +// (including loss of data, profits, goodwill, or any type of +// loss or damage suffered as a result of any action brought +// by a third party) even if such damage or loss was +// reasonably foreseeable or Xilinx had been advised of the +// possibility of the same. +// +// CRITICAL APPLICATIONS +// Xilinx products are not designed or intended to be fail- +// safe, or for use in any application requiring fail-safe +// performance, such as life-support or safety devices or +// systems, Class III medical devices, nuclear facilities, +// applications related to the deployment of airbags, or any +// other applications that could lead to death, personal +// injury, or severe property or environmental damage +// (individually and collectively, "Critical +// Applications"). Customer assumes the sole risk and +// liability of any use of Xilinx products in Critical +// Applications, subject only to applicable laws and +// regulations governing limitations on product liability. +// +// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +// PART OF THIS FILE AT ALL TIMES. +// +//---------------------------------------------------------------------------- +// User entered comments +//---------------------------------------------------------------------------- +// None +// +//---------------------------------------------------------------------------- +// "Output Output Phase Duty Pk-to-Pk Phase" +// "Clock Freq (MHz) (degrees) Cycle (%) Jitter (ps) Error (ps)" +//---------------------------------------------------------------------------- +// CLK_OUT1____50.000______0.000______50.0______200.000____150.000 +// +//---------------------------------------------------------------------------- +// "Input Clock Freq (MHz) Input Jitter (UI)" +//---------------------------------------------------------------------------- +// __primary______________50____________0.010 + +// The following must be inserted into your Verilog file for this +// core to be instantiated. Change the instance name and port connections +// (in parentheses) to your own signal names. + +//----------- Begin Cut here for INSTANTIATION Template ---// INST_TAG + + clkmgr_dcm instance_name + (// Clock in ports + .CLK_IN1(CLK_IN1), // IN + // Clock out ports + .CLK_OUT1(CLK_OUT1), // OUT + // Status and control signals + .RESET(RESET),// IN + .INPUT_CLK_STOPPED(INPUT_CLK_STOPPED), // OUT + .CLK_VALID(CLK_VALID)); // OUT +// INST_TAG_END ------ End INSTANTIATION Template --------- diff --git a/common/rtl/ipcore/clkmgr_dcm.xco b/common/rtl/ipcore/clkmgr_dcm.xco new file mode 100644 index 0000000..37f1a1d --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm.xco @@ -0,0 +1,269 @@ +############################################################## +# +# Xilinx Core Generator version 14.7 +# Date: Sun Feb 01 07:49:40 2015 +# +############################################################## +# +# This file contains the customisation parameters for a +# Xilinx CORE Generator IP GUI. It is strongly recommended +# that you do not manually alter this file as it may cause +# unexpected and unsupported behavior. +# +############################################################## +# +# Generated from component: xilinx.com:ip:clk_wiz:3.6 +# +############################################################## +# +# BEGIN Project Options +SET addpads = false +SET asysymbol = true +SET busformat = BusFormatAngleBracketNotRipped +SET createndf = false +SET designentry = Verilog +SET device = xc6slx45 +SET devicefamily = spartan6 +SET flowvendor = Other +SET formalverification = false +SET foundationsym = false +SET implementationfiletype = Ngc +SET package = csg324 +SET removerpms = false +SET simulationfiles = Behavioral +SET speedgrade = -3 +SET verilogsim = true +SET vhdlsim = false +# END Project Options +# BEGIN Select +SELECT Clocking_Wizard xilinx.com:ip:clk_wiz:3.6 +# END Select +# BEGIN Parameters +CSET calc_done=DONE +CSET clk_in_sel_port=CLK_IN_SEL +CSET clk_out1_port=CLK_OUT1 +CSET clk_out1_use_fine_ps_gui=false +CSET clk_out2_port=CLK_OUT2 +CSET clk_out2_use_fine_ps_gui=false +CSET clk_out3_port=CLK_OUT3 +CSET clk_out3_use_fine_ps_gui=false +CSET clk_out4_port=CLK_OUT4 +CSET clk_out4_use_fine_ps_gui=false +CSET clk_out5_port=CLK_OUT5 +CSET clk_out5_use_fine_ps_gui=false +CSET clk_out6_port=CLK_OUT6 +CSET clk_out6_use_fine_ps_gui=false +CSET clk_out7_port=CLK_OUT7 +CSET clk_out7_use_fine_ps_gui=false +CSET clk_valid_port=CLK_VALID +CSET clkfb_in_n_port=CLKFB_IN_N +CSET clkfb_in_p_port=CLKFB_IN_P +CSET clkfb_in_port=CLKFB_IN +CSET clkfb_in_signaling=SINGLE +CSET clkfb_out_n_port=CLKFB_OUT_N +CSET clkfb_out_p_port=CLKFB_OUT_P +CSET clkfb_out_port=CLKFB_OUT +CSET clkfb_stopped_port=CLKFB_STOPPED +CSET clkin1_jitter_ps=200.0 +CSET clkin1_ui_jitter=0.010 +CSET clkin2_jitter_ps=100.0 +CSET clkin2_ui_jitter=0.010 +CSET clkout1_drives=BUFG +CSET clkout1_requested_duty_cycle=50.0 +CSET clkout1_requested_out_freq=50 +CSET clkout1_requested_phase=0.000 +CSET clkout2_drives=BUFG +CSET clkout2_requested_duty_cycle=50.0 +CSET clkout2_requested_out_freq=50 +CSET clkout2_requested_phase=0 +CSET clkout2_used=false +CSET clkout3_drives=BUFG +CSET clkout3_requested_duty_cycle=50.0 +CSET clkout3_requested_out_freq=100.000 +CSET clkout3_requested_phase=0.000 +CSET clkout3_used=false +CSET clkout4_drives=BUFG +CSET clkout4_requested_duty_cycle=50.0 +CSET clkout4_requested_out_freq=100.000 +CSET clkout4_requested_phase=0.000 +CSET clkout4_used=false +CSET clkout5_drives=BUFG +CSET clkout5_requested_duty_cycle=50.0 +CSET clkout5_requested_out_freq=100.000 +CSET clkout5_requested_phase=0.000 +CSET clkout5_used=false +CSET clkout6_drives=BUFG +CSET clkout6_requested_duty_cycle=50.0 +CSET clkout6_requested_out_freq=100.000 +CSET clkout6_requested_phase=0.000 +CSET clkout6_used=false +CSET clkout7_drives=BUFG +CSET clkout7_requested_duty_cycle=50.0 +CSET clkout7_requested_out_freq=100.000 +CSET clkout7_requested_phase=0.000 +CSET clkout7_used=false +CSET clock_mgr_type=MANUAL +CSET component_name=clkmgr_dcm +CSET daddr_port=DADDR +CSET dclk_port=DCLK +CSET dcm_clk_feedback=1X +CSET dcm_clk_out1_port=CLK0 +CSET dcm_clk_out2_port=CLK0 +CSET dcm_clk_out3_port=CLK0 +CSET dcm_clk_out4_port=CLK0 +CSET dcm_clk_out5_port=CLK0 +CSET dcm_clk_out6_port=CLK0 +CSET dcm_clkdv_divide=2.0 +CSET dcm_clkfx_divide=1 +CSET dcm_clkfx_multiply=4 +CSET dcm_clkgen_clk_out1_port=CLKFX +CSET dcm_clkgen_clk_out2_port=CLKFX +CSET dcm_clkgen_clk_out3_port=CLKFX +CSET dcm_clkgen_clkfx_divide=1 +CSET dcm_clkgen_clkfx_md_max=0.000 +CSET dcm_clkgen_clkfx_multiply=4 +CSET dcm_clkgen_clkfxdv_divide=2 +CSET dcm_clkgen_clkin_period=10.000 +CSET dcm_clkgen_notes=None +CSET dcm_clkgen_spread_spectrum=NONE +CSET dcm_clkgen_startup_wait=false +CSET dcm_clkin_divide_by_2=false +CSET dcm_clkin_period=20.000 +CSET dcm_clkout_phase_shift=NONE +CSET dcm_deskew_adjust=SYSTEM_SYNCHRONOUS +CSET dcm_notes=None +CSET dcm_phase_shift=0 +CSET dcm_pll_cascade=NONE +CSET dcm_startup_wait=false +CSET den_port=DEN +CSET din_port=DIN +CSET dout_port=DOUT +CSET drdy_port=DRDY +CSET dwe_port=DWE +CSET feedback_source=FDBK_AUTO +CSET in_freq_units=Units_MHz +CSET in_jitter_units=Units_UI +CSET input_clk_stopped_port=INPUT_CLK_STOPPED +CSET jitter_options=UI +CSET jitter_sel=No_Jitter +CSET locked_port=LOCKED +CSET mmcm_bandwidth=OPTIMIZED +CSET mmcm_clkfbout_mult_f=4.000 +CSET mmcm_clkfbout_phase=0.000 +CSET mmcm_clkfbout_use_fine_ps=false +CSET mmcm_clkin1_period=10.000 +CSET mmcm_clkin2_period=10.000 +CSET mmcm_clkout0_divide_f=4.000 +CSET mmcm_clkout0_duty_cycle=0.500 +CSET mmcm_clkout0_phase=0.000 +CSET mmcm_clkout0_use_fine_ps=false +CSET mmcm_clkout1_divide=1 +CSET mmcm_clkout1_duty_cycle=0.500 +CSET mmcm_clkout1_phase=0.000 +CSET mmcm_clkout1_use_fine_ps=false +CSET mmcm_clkout2_divide=1 +CSET mmcm_clkout2_duty_cycle=0.500 +CSET mmcm_clkout2_phase=0.000 +CSET mmcm_clkout2_use_fine_ps=false +CSET mmcm_clkout3_divide=1 +CSET mmcm_clkout3_duty_cycle=0.500 +CSET mmcm_clkout3_phase=0.000 +CSET mmcm_clkout3_use_fine_ps=false +CSET mmcm_clkout4_cascade=false +CSET mmcm_clkout4_divide=1 +CSET mmcm_clkout4_duty_cycle=0.500 +CSET mmcm_clkout4_phase=0.000 +CSET mmcm_clkout4_use_fine_ps=false +CSET mmcm_clkout5_divide=1 +CSET mmcm_clkout5_duty_cycle=0.500 +CSET mmcm_clkout5_phase=0.000 +CSET mmcm_clkout5_use_fine_ps=false +CSET mmcm_clkout6_divide=1 +CSET mmcm_clkout6_duty_cycle=0.500 +CSET mmcm_clkout6_phase=0.000 +CSET mmcm_clkout6_use_fine_ps=false +CSET mmcm_clock_hold=false +CSET mmcm_compensation=ZHOLD +CSET mmcm_divclk_divide=1 +CSET mmcm_notes=None +CSET mmcm_ref_jitter1=0.010 +CSET mmcm_ref_jitter2=0.010 +CSET mmcm_startup_wait=false +CSET num_out_clks=1 +CSET override_dcm=false +CSET override_dcm_clkgen=false +CSET override_mmcm=false +CSET override_pll=false +CSET platform=nt +CSET pll_bandwidth=OPTIMIZED +CSET pll_clk_feedback=CLKFBOUT +CSET pll_clkfbout_mult=8 +CSET pll_clkfbout_phase=0.000 +CSET pll_clkin_period=20.0 +CSET pll_clkout0_divide=2 +CSET pll_clkout0_duty_cycle=0.500 +CSET pll_clkout0_phase=0.000 +CSET pll_clkout1_divide=10 +CSET pll_clkout1_duty_cycle=0.500 +CSET pll_clkout1_phase=0.000 +CSET pll_clkout2_divide=1 +CSET pll_clkout2_duty_cycle=0.500 +CSET pll_clkout2_phase=0.000 +CSET pll_clkout3_divide=1 +CSET pll_clkout3_duty_cycle=0.500 +CSET pll_clkout3_phase=0.000 +CSET pll_clkout4_divide=1 +CSET pll_clkout4_duty_cycle=0.500 +CSET pll_clkout4_phase=0.000 +CSET pll_clkout5_divide=1 +CSET pll_clkout5_duty_cycle=0.500 +CSET pll_clkout5_phase=0.000 +CSET pll_compensation=SYSTEM_SYNCHRONOUS +CSET pll_divclk_divide=1 +CSET pll_notes=None +CSET pll_ref_jitter=0.010 +CSET power_down_port=POWER_DOWN +CSET prim_in_freq=50 +CSET prim_in_jitter=0.010 +CSET prim_source=No_buffer +CSET primary_port=CLK_IN1 +CSET primitive=MMCM +CSET primtype_sel=DCM_SP +CSET psclk_port=PSCLK +CSET psdone_port=PSDONE +CSET psen_port=PSEN +CSET psincdec_port=PSINCDEC +CSET relative_inclk=REL_PRIMARY +CSET reset_port=RESET +CSET secondary_in_freq=100.000 +CSET secondary_in_jitter=0.010 +CSET secondary_port=CLK_IN2 +CSET secondary_source=Single_ended_clock_capable_pin +CSET ss_mod_freq=250 +CSET ss_mode=CENTER_HIGH +CSET status_port=STATUS +CSET summary_strings=empty +CSET use_clk_valid=true +CSET use_clkfb_stopped=false +CSET use_dyn_phase_shift=false +CSET use_dyn_reconfig=false +CSET use_freeze=false +CSET use_freq_synth=true +CSET use_inclk_stopped=true +CSET use_inclk_switchover=false +CSET use_locked=false +CSET use_max_i_jitter=false +CSET use_min_o_jitter=false +CSET use_min_power=false +CSET use_phase_alignment=true +CSET use_power_down=false +CSET use_reset=true +CSET use_spread_spectrum=false +CSET use_spread_spectrum_1=false +CSET use_status=false +# END Parameters +# BEGIN Extra information +MISC pkg_timestamp=2012-05-10T12:44:55Z +# END Extra information +GENERATE +# CRC: d6857c2d diff --git a/common/rtl/ipcore/clkmgr_dcm.xdc b/common/rtl/ipcore/clkmgr_dcm.xdc new file mode 100644 index 0000000..9ecc102 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm.xdc @@ -0,0 +1,67 @@ +# file: clkmgr_dcm.xdc +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# Input clock periods. These duplicate the values entered for the +# input clocks. You can use these to time your system +#---------------------------------------------------------------- +create_clock -name CLK_IN1 -period 20.0 [get_ports CLK_IN1] +set_propagated_clock CLK_IN1 +set_input_jitter CLK_IN1 0.2 + +set_false_path -from [get_ports "RESET"] + +# Derived clock periods. These are commented out because they are +# automatically propogated by the tools +# However, if you'd like to use them for module level testing, you +# can copy them into your module level timing checks +#----------------------------------------------------------------- + +#----------------------------------------------------------------- + +#----------------------------------------------------------------- diff --git a/common/rtl/ipcore/clkmgr_dcm.xise b/common/rtl/ipcore/clkmgr_dcm.xise new file mode 100644 index 0000000..7369d3b --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm.xise @@ -0,0 +1,74 @@ + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/common/rtl/ipcore/clkmgr_dcm/clk_wiz_v3_6_readme.txt b/common/rtl/ipcore/clkmgr_dcm/clk_wiz_v3_6_readme.txt new file mode 100644 index 0000000..91dcdd0 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/clk_wiz_v3_6_readme.txt @@ -0,0 +1,184 @@ +CHANGE LOG for LogiCORE Clocking Wizard V3.6 + + Release Date: June 19, 2013 +-------------------------------------------------------------------------------- + +Table of Contents + +1. INTRODUCTION +2. DEVICE SUPPORT +3. NEW FEATURE HISTORY +4. RESOLVED ISSUES +5. KNOWN ISSUES & LIMITATIONS +6. TECHNICAL SUPPORT & FEEDBACK +7. CORE RELEASE HISTORY +8. LEGAL DISCLAIMER + +-------------------------------------------------------------------------------- + + +1. INTRODUCTION + +For installation instructions for this release, please go to: + + http://www.xilinx.com/ipcenter/coregen/ip_update_install_instructions.htm + +For system requirements: + + http://www.xilinx.com/ipcenter/coregen/ip_update_system_requirements.htm + +This file contains release notes for the Xilinx LogiCORE IP Clocking Wizard v3.6 +solution. For the latest core updates, see the product page at: + + http://www.xilinx.com/products/design_resources/conn_central/solution_kits/wizards/ + +................................................................................ + +2. DEVICE SUPPORT + + + 2.1 ISE + + + The following device families are supported by the core for this release. + + All 7 Series devices + + + Zynq-7000 devices + Zynq-7000 + Defense Grade Zynq-7000Q (XQ) + + + All Virtex-6 devices + + + All Spartan-6 devices + + +................................................................................ + +3. NEW FEATURE HISTORY + + + 3.1 ISE + + - Spread Spectrum support for 7 series MMCME2 + + - ISE 14.2 software support + +................................................................................ + +4. RESOLVED ISSUES + + + 4.1 ISE + + Resolved issue with example design becoming core top in planAhead + + Resolved issue with Virtex6 MMCM instantiation for VHDL project + Please refer to AR 50719 - http://www.xilinx.com/support/answers/50719.htm + +................................................................................ + +5. KNOWN ISSUES & LIMITATIONS + + + 5.1 ISE + + + The most recent information, including known issues, workarounds, and + resolutions for this version is provided in the IP Release Notes Guide + located at + + www.xilinx.com/support/documentation/user_guides/xtp025.pdf + + +................................................................................ + +6. TECHNICAL SUPPORT & FEEDBACK + + +To obtain technical support, create a WebCase at www.xilinx.com/support. +Questions are routed to a team with expertise using this product. + +Xilinx provides technical support for use of this product when used +according to the guidelines described in the core documentation, and +cannot guarantee timing, functionality, or support of this product for +designs that do not follow specified guidelines. + + +................................................................................ + +7. CORE RELEASE HISTORY + + +Date By Version Description +================================================================================ +06/19/2013 Xilinx, Inc. 3.6(Rev3) ISE 14.6 support +10/16/2012 Xilinx, Inc. 3.6(Rev2) ISE 14.3 support +07/25/2012 Xilinx, Inc. 3.6 ISE 14.2 support +04/24/2012 Xilinx, Inc. 3.5 ISE 14.1 support +01/18/2012 Xilinx, Inc. 3.3 ISE 13.4 support +06/22/2011 Xilinx, Inc. 3.2 ISE 13.2 support +03/01/2011 Xilinx, Inc. 3.1 ISE 13.1 support +12/14/2010 Xilinx, Inc. 1.8 ISE 12.4 support +09/21/2010 Xilinx, Inc. 1.7 ISE 12.3 support +07/23/2010 Xilinx, Inc. 1.6 ISE 12.2 support +04/19/2010 Xilinx, Inc. 1.5 ISE 12.1 support +12/02/2009 Xilinx, Inc. 1.4 ISE 11.4 support +09/16/2009 Xilinx, Inc. 1.3 ISE 11.3 support +06/24/2009 Xilinx, Inc. 1.2 ISE 11.2 support +04/24/2009 Xilinx, Inc. 1.1 Initial release; 11.1 support +================================================================================ + +................................................................................ + +8. LEGAL DISCLAIMER + +(c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. + +This file contains confidential and proprietary information +of Xilinx, Inc. and is protected under U.S. and +international copyright and other intellectual property +laws. + +DISCLAIMER +This disclaimer is not a license and does not grant any +rights to the materials distributed herewith. Except as +otherwise provided in a valid license issued to you by +Xilinx, and to the maximum extent permitted by applicable +law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +(2) Xilinx shall not be liable (whether in contract or tort, +including negligence, or under any other theory of +liability) for any loss or damage of any kind or nature +related to, arising under or in connection with these +materials, including for any direct, or any indirect, +special, incidental, or consequential loss or damage +(including loss of data, profits, goodwill, or any type of +loss or damage suffered as a result of any action brought +by a third party) even if such damage or loss was +reasonably foreseeable or Xilinx had been advised of the +possibility of the same. + +CRITICAL APPLICATIONS +Xilinx products are not designed or intended to be fail- +safe, or for use in any application requiring fail-safe +performance, such as life-support or safety devices or +systems, Class III medical devices, nuclear facilities, +applications related to the deployment of airbags, or any +other applications that could lead to death, personal +injury, or severe property or environmental damage +(individually and collectively, "Critical +Applications"). Customer assumes the sole risk and +liability of any use of Xilinx products in Critical +Applications, subject only to applicable laws and +regulations governing limitations on product liability. + +THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +PART OF THIS FILE AT ALL TIMES. + diff --git a/common/rtl/ipcore/clkmgr_dcm/doc/clk_wiz_v3_6_readme.txt b/common/rtl/ipcore/clkmgr_dcm/doc/clk_wiz_v3_6_readme.txt new file mode 100644 index 0000000..91dcdd0 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/doc/clk_wiz_v3_6_readme.txt @@ -0,0 +1,184 @@ +CHANGE LOG for LogiCORE Clocking Wizard V3.6 + + Release Date: June 19, 2013 +-------------------------------------------------------------------------------- + +Table of Contents + +1. INTRODUCTION +2. DEVICE SUPPORT +3. NEW FEATURE HISTORY +4. RESOLVED ISSUES +5. KNOWN ISSUES & LIMITATIONS +6. TECHNICAL SUPPORT & FEEDBACK +7. CORE RELEASE HISTORY +8. LEGAL DISCLAIMER + +-------------------------------------------------------------------------------- + + +1. INTRODUCTION + +For installation instructions for this release, please go to: + + http://www.xilinx.com/ipcenter/coregen/ip_update_install_instructions.htm + +For system requirements: + + http://www.xilinx.com/ipcenter/coregen/ip_update_system_requirements.htm + +This file contains release notes for the Xilinx LogiCORE IP Clocking Wizard v3.6 +solution. For the latest core updates, see the product page at: + + http://www.xilinx.com/products/design_resources/conn_central/solution_kits/wizards/ + +................................................................................ + +2. DEVICE SUPPORT + + + 2.1 ISE + + + The following device families are supported by the core for this release. + + All 7 Series devices + + + Zynq-7000 devices + Zynq-7000 + Defense Grade Zynq-7000Q (XQ) + + + All Virtex-6 devices + + + All Spartan-6 devices + + +................................................................................ + +3. NEW FEATURE HISTORY + + + 3.1 ISE + + - Spread Spectrum support for 7 series MMCME2 + + - ISE 14.2 software support + +................................................................................ + +4. RESOLVED ISSUES + + + 4.1 ISE + + Resolved issue with example design becoming core top in planAhead + + Resolved issue with Virtex6 MMCM instantiation for VHDL project + Please refer to AR 50719 - http://www.xilinx.com/support/answers/50719.htm + +................................................................................ + +5. KNOWN ISSUES & LIMITATIONS + + + 5.1 ISE + + + The most recent information, including known issues, workarounds, and + resolutions for this version is provided in the IP Release Notes Guide + located at + + www.xilinx.com/support/documentation/user_guides/xtp025.pdf + + +................................................................................ + +6. TECHNICAL SUPPORT & FEEDBACK + + +To obtain technical support, create a WebCase at www.xilinx.com/support. +Questions are routed to a team with expertise using this product. + +Xilinx provides technical support for use of this product when used +according to the guidelines described in the core documentation, and +cannot guarantee timing, functionality, or support of this product for +designs that do not follow specified guidelines. + + +................................................................................ + +7. CORE RELEASE HISTORY + + +Date By Version Description +================================================================================ +06/19/2013 Xilinx, Inc. 3.6(Rev3) ISE 14.6 support +10/16/2012 Xilinx, Inc. 3.6(Rev2) ISE 14.3 support +07/25/2012 Xilinx, Inc. 3.6 ISE 14.2 support +04/24/2012 Xilinx, Inc. 3.5 ISE 14.1 support +01/18/2012 Xilinx, Inc. 3.3 ISE 13.4 support +06/22/2011 Xilinx, Inc. 3.2 ISE 13.2 support +03/01/2011 Xilinx, Inc. 3.1 ISE 13.1 support +12/14/2010 Xilinx, Inc. 1.8 ISE 12.4 support +09/21/2010 Xilinx, Inc. 1.7 ISE 12.3 support +07/23/2010 Xilinx, Inc. 1.6 ISE 12.2 support +04/19/2010 Xilinx, Inc. 1.5 ISE 12.1 support +12/02/2009 Xilinx, Inc. 1.4 ISE 11.4 support +09/16/2009 Xilinx, Inc. 1.3 ISE 11.3 support +06/24/2009 Xilinx, Inc. 1.2 ISE 11.2 support +04/24/2009 Xilinx, Inc. 1.1 Initial release; 11.1 support +================================================================================ + +................................................................................ + +8. LEGAL DISCLAIMER + +(c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. + +This file contains confidential and proprietary information +of Xilinx, Inc. and is protected under U.S. and +international copyright and other intellectual property +laws. + +DISCLAIMER +This disclaimer is not a license and does not grant any +rights to the materials distributed herewith. Except as +otherwise provided in a valid license issued to you by +Xilinx, and to the maximum extent permitted by applicable +law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +(2) Xilinx shall not be liable (whether in contract or tort, +including negligence, or under any other theory of +liability) for any loss or damage of any kind or nature +related to, arising under or in connection with these +materials, including for any direct, or any indirect, +special, incidental, or consequential loss or damage +(including loss of data, profits, goodwill, or any type of +loss or damage suffered as a result of any action brought +by a third party) even if such damage or loss was +reasonably foreseeable or Xilinx had been advised of the +possibility of the same. + +CRITICAL APPLICATIONS +Xilinx products are not designed or intended to be fail- +safe, or for use in any application requiring fail-safe +performance, such as life-support or safety devices or +systems, Class III medical devices, nuclear facilities, +applications related to the deployment of airbags, or any +other applications that could lead to death, personal +injury, or severe property or environmental damage +(individually and collectively, "Critical +Applications"). Customer assumes the sole risk and +liability of any use of Xilinx products in Critical +Applications, subject only to applicable laws and +regulations governing limitations on product liability. + +THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +PART OF THIS FILE AT ALL TIMES. + diff --git a/common/rtl/ipcore/clkmgr_dcm/doc/clk_wiz_v3_6_vinfo.html b/common/rtl/ipcore/clkmgr_dcm/doc/clk_wiz_v3_6_vinfo.html new file mode 100644 index 0000000..d6deba0 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/doc/clk_wiz_v3_6_vinfo.html @@ -0,0 +1,195 @@ + + +clk_wiz_v3_6_vinfo + + + +

+CHANGE LOG for LogiCORE Clocking Wizard V3.6 
+
+                    Release Date: June 19, 2013
+--------------------------------------------------------------------------------
+
+Table of Contents
+
+1. INTRODUCTION 
+2. DEVICE SUPPORT    
+3. NEW FEATURE HISTORY   
+4. RESOLVED ISSUES 
+5. KNOWN ISSUES & LIMITATIONS 
+6. TECHNICAL SUPPORT & FEEDBACK
+7. CORE RELEASE HISTORY 
+8. LEGAL DISCLAIMER 
+
+--------------------------------------------------------------------------------
+
+
+1. INTRODUCTION
+
+For installation instructions for this release, please go to:
+
+  www.xilinx.com/ipcenter/coregen/ip_update_install_instructions.htm
+
+For system requirements:
+
+   www.xilinx.com/ipcenter/coregen/ip_update_system_requirements.htm
+
+This file contains release notes for the Xilinx LogiCORE IP Clocking Wizard v3.6
+solution. For the latest core updates, see the product page at:
+
+   www.xilinx.com/products/design_resources/conn_central/solution_kits/wizards/
+
+................................................................................
+
+2. DEVICE SUPPORT
+
+
+  2.1 ISE 
+   
+  
+  The following device families are supported by the core for this release.
+  
+  All 7 Series devices
+
+
+  Zynq-7000 devices
+    Zynq-7000
+    Defense Grade Zynq-7000Q (XQ)
+
+
+  All Virtex-6 devices
+  
+  
+  All Spartan-6 devices
+  
+  
+................................................................................
+
+3. NEW FEATURE HISTORY 
+
+
+  3.1 ISE 
+  
+    - Spread Spectrum support for 7 series MMCME2
+
+    - ISE 14.2 software support
+
+................................................................................
+
+4. RESOLVED ISSUES
+
+
+  4.1 ISE 
+  
+      Resolved issue with example design becoming core top in planAhead
+
+      Resolved issue with Virtex6 MMCM instantiation for VHDL project
+      Please refer to AR 50719 - www.xilinx.com/support/answers/50719.htm
+
+................................................................................
+
+5. KNOWN ISSUES & LIMITATIONS
+
+
+  5.1 ISE 
+  
+  
+  The most recent information, including known issues, workarounds, and
+  resolutions for this version is provided in the IP Release Notes Guide
+  located at
+
+   www.xilinx.com/support/documentation/user_guides/xtp025.pdf
+  
+  
+................................................................................
+
+6. TECHNICAL SUPPORT & FEEDBACK
+
+
+To obtain technical support, create a WebCase at www.xilinx.com/support.
+Questions are routed to a team with expertise using this product.
+
+Xilinx provides technical support for use of this product when used
+according to the guidelines described in the core documentation, and
+cannot guarantee timing, functionality, or support of this product for
+designs that do not follow specified guidelines.
+
+
+................................................................................
+
+7. CORE RELEASE HISTORY
+
+
+Date        By            Version      Description
+================================================================================
+06/19/2013  Xilinx, Inc.  3.6(Rev3)    ISE 14.6 support
+10/16/2012  Xilinx, Inc.  3.6(Rev2)    ISE 14.3 support
+07/25/2012  Xilinx, Inc.  3.6          ISE 14.2 support
+04/24/2012  Xilinx, Inc.  3.5          ISE 14.1 support
+01/18/2012  Xilinx, Inc.  3.3          ISE 13.4 support
+06/22/2011  Xilinx, Inc.  3.2          ISE 13.2 support
+03/01/2011  Xilinx, Inc.  3.1          ISE 13.1 support
+12/14/2010  Xilinx, Inc.  1.8          ISE 12.4 support
+09/21/2010  Xilinx, Inc.  1.7          ISE 12.3 support
+07/23/2010  Xilinx, Inc.  1.6          ISE 12.2 support
+04/19/2010  Xilinx, Inc.  1.5          ISE 12.1 support
+12/02/2009  Xilinx, Inc.  1.4          ISE 11.4 support
+09/16/2009  Xilinx, Inc.  1.3          ISE 11.3 support
+06/24/2009  Xilinx, Inc.  1.2          ISE 11.2 support
+04/24/2009  Xilinx, Inc.  1.1          Initial release; 11.1 support
+================================================================================
+                          
+................................................................................
+
+8. LEGAL DISCLAIMER
+
+(c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved.
+
+This file contains confidential and proprietary information
+of Xilinx, Inc. and is protected under U.S. and
+international copyright and other intellectual property
+laws.
+
+DISCLAIMER
+This disclaimer is not a license and does not grant any
+rights to the materials distributed herewith. Except as
+otherwise provided in a valid license issued to you by
+Xilinx, and to the maximum extent permitted by applicable
+law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
+WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
+AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
+BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
+INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
+(2) Xilinx shall not be liable (whether in contract or tort,
+including negligence, or under any other theory of
+liability) for any loss or damage of any kind or nature
+related to, arising under or in connection with these
+materials, including for any direct, or any indirect,
+special, incidental, or consequential loss or damage
+(including loss of data, profits, goodwill, or any type of
+loss or damage suffered as a result of any action brought
+by a third party) even if such damage or loss was
+reasonably foreseeable or Xilinx had been advised of the
+possibility of the same.
+
+CRITICAL APPLICATIONS
+Xilinx products are not designed or intended to be fail-
+safe, or for use in any application requiring fail-safe
+performance, such as life-support or safety devices or
+systems, Class III medical devices, nuclear facilities,
+applications related to the deployment of airbags, or any
+other applications that could lead to death, personal
+injury, or severe property or environmental damage
+(individually and collectively, "Critical
+Applications"). Customer assumes the sole risk and
+liability of any use of Xilinx products in Critical
+Applications, subject only to applicable laws and
+regulations governing limitations on product liability.
+
+THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
+PART OF THIS FILE AT ALL TIMES.
+
+
+
+ + diff --git a/common/rtl/ipcore/clkmgr_dcm/doc/pg065_clk_wiz.pdf b/common/rtl/ipcore/clkmgr_dcm/doc/pg065_clk_wiz.pdf new file mode 100644 index 0000000..a7daa60 Binary files /dev/null and b/common/rtl/ipcore/clkmgr_dcm/doc/pg065_clk_wiz.pdf differ diff --git a/common/rtl/ipcore/clkmgr_dcm/example_design/clkmgr_dcm_exdes.ucf b/common/rtl/ipcore/clkmgr_dcm/example_design/clkmgr_dcm_exdes.ucf new file mode 100644 index 0000000..dffb528 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/example_design/clkmgr_dcm_exdes.ucf @@ -0,0 +1,60 @@ +# file: clkmgr_dcm_exdes.ucf +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# Input clock periods. These duplicate the values entered for the +# input clocks. You can use these to time your system +#---------------------------------------------------------------- +NET "CLK_IN1" TNM_NET = "CLK_IN1"; +TIMESPEC "TS_CLK_IN1" = PERIOD "CLK_IN1" 20.0 ns HIGH 50% INPUT_JITTER 200.0ps; + + +# FALSE PATH constraints +PIN "COUNTER_RESET" TIG; +PIN "RESET" TIG; + diff --git a/common/rtl/ipcore/clkmgr_dcm/example_design/clkmgr_dcm_exdes.v b/common/rtl/ipcore/clkmgr_dcm/example_design/clkmgr_dcm_exdes.v new file mode 100644 index 0000000..10627b3 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/example_design/clkmgr_dcm_exdes.v @@ -0,0 +1,164 @@ +// file: clkmgr_dcm_exdes.v +// +// (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +// +// This file contains confidential and proprietary information +// of Xilinx, Inc. and is protected under U.S. and +// international copyright and other intellectual property +// laws. +// +// DISCLAIMER +// This disclaimer is not a license and does not grant any +// rights to the materials distributed herewith. Except as +// otherwise provided in a valid license issued to you by +// Xilinx, and to the maximum extent permitted by applicable +// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +// (2) Xilinx shall not be liable (whether in contract or tort, +// including negligence, or under any other theory of +// liability) for any loss or damage of any kind or nature +// related to, arising under or in connection with these +// materials, including for any direct, or any indirect, +// special, incidental, or consequential loss or damage +// (including loss of data, profits, goodwill, or any type of +// loss or damage suffered as a result of any action brought +// by a third party) even if such damage or loss was +// reasonably foreseeable or Xilinx had been advised of the +// possibility of the same. +// +// CRITICAL APPLICATIONS +// Xilinx products are not designed or intended to be fail- +// safe, or for use in any application requiring fail-safe +// performance, such as life-support or safety devices or +// systems, Class III medical devices, nuclear facilities, +// applications related to the deployment of airbags, or any +// other applications that could lead to death, personal +// injury, or severe property or environmental damage +// (individually and collectively, "Critical +// Applications"). Customer assumes the sole risk and +// liability of any use of Xilinx products in Critical +// Applications, subject only to applicable laws and +// regulations governing limitations on product liability. +// +// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +// PART OF THIS FILE AT ALL TIMES. +// + +//---------------------------------------------------------------------------- +// Clocking wizard example design +//---------------------------------------------------------------------------- +// This example design instantiates the created clocking network, where each +// output clock drives a counter. The high bit of each counter is ported. +//---------------------------------------------------------------------------- + +`timescale 1ps/1ps + +module clkmgr_dcm_exdes + #( + parameter TCQ = 100 + ) + (// Clock in ports + input CLK_IN1, + // Reset that only drives logic in example design + input COUNTER_RESET, + output [1:1] CLK_OUT, + // High bits of counters driven by clocks + output COUNT, + // Status and control signals + input RESET, + output INPUT_CLK_STOPPED, + output CLK_VALID + ); + + // Parameters for the counters + //------------------------------- + // Counter width + localparam C_W = 16; + // Create reset for the counters + wire reset_int = RESET || COUNTER_RESET; + + reg rst_sync; + reg rst_sync_int; + reg rst_sync_int1; + reg rst_sync_int2; + + + + // Declare the clocks and counter + wire clk_int; + wire clk_n; + wire clk; + reg [C_W-1:0] counter; + + // Insert BUFGs on all input clocks that don't already have them + //-------------------------------------------------------------- + BUFG clkin1_buf + (.O (clk_in1_buf), + .I (CLK_IN1)); + + // Instantiation of the clocking network + //-------------------------------------- + clkmgr_dcm clknetwork + (// Clock in ports + .CLK_IN1 (clk_in1_buf), + // Clock out ports + .CLK_OUT1 (clk_int), + // Status and control signals + .RESET (RESET), + .INPUT_CLK_STOPPED (INPUT_CLK_STOPPED), + .CLK_VALID (CLK_VALID)); + + assign clk_n = ~clk; + + ODDR2 clkout_oddr + (.Q (CLK_OUT[1]), + .C0 (clk), + .C1 (clk_n), + .CE (1'b1), + .D0 (1'b1), + .D1 (1'b0), + .R (1'b0), + .S (1'b0)); + + // Connect the output clocks to the design + //----------------------------------------- + assign clk = clk_int; + + + // Reset synchronizer + //----------------------------------- + always @(posedge reset_int or posedge clk) begin + if (reset_int) begin + rst_sync <= 1'b1; + rst_sync_int <= 1'b1; + rst_sync_int1 <= 1'b1; + rst_sync_int2 <= 1'b1; + end + else begin + rst_sync <= 1'b0; + rst_sync_int <= rst_sync; + rst_sync_int1 <= rst_sync_int; + rst_sync_int2 <= rst_sync_int1; + end + end + + + // Output clock sampling + //----------------------------------- + always @(posedge clk or posedge rst_sync_int2) begin + if (rst_sync_int2) begin + counter <= #TCQ { C_W { 1'b 0 } }; + end else begin + counter <= #TCQ counter + 1'b 1; + end + end + + // alias the high bit to the output + assign COUNT = counter[C_W-1]; + + + +endmodule diff --git a/common/rtl/ipcore/clkmgr_dcm/example_design/clkmgr_dcm_exdes.xdc b/common/rtl/ipcore/clkmgr_dcm/example_design/clkmgr_dcm_exdes.xdc new file mode 100644 index 0000000..787023d --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/example_design/clkmgr_dcm_exdes.xdc @@ -0,0 +1,69 @@ +# file: clkmgr_dcm_exdes.xdc +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# Input clock periods. These duplicate the values entered for the +# input clocks. You can use these to time your system +#---------------------------------------------------------------- +create_clock -name CLK_IN1 -period 20.0 [get_ports CLK_IN1] +set_propagated_clock CLK_IN1 +set_input_jitter CLK_IN1 0.2 + +# FALSE PATH constraint added on COUNTER_RESET +set_false_path -from [get_ports "COUNTER_RESET"] +set_false_path -from [get_ports "RESET"] + +# Derived clock periods. These are commented out because they are +# automatically propogated by the tools +# However, if you'd like to use them for module level testing, you +# can copy them into your module level timing checks +#----------------------------------------------------------------- + +#----------------------------------------------------------------- + +#----------------------------------------------------------------- diff --git a/common/rtl/ipcore/clkmgr_dcm/implement/implement.bat b/common/rtl/ipcore/clkmgr_dcm/implement/implement.bat new file mode 100644 index 0000000..3d313d5 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/implement/implement.bat @@ -0,0 +1,90 @@ +REM file: implement.bat +REM +REM (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +REM +REM This file contains confidential and proprietary information +REM of Xilinx, Inc. and is protected under U.S. and +REM international copyright and other intellectual property +REM laws. +REM +REM DISCLAIMER +REM This disclaimer is not a license and does not grant any +REM rights to the materials distributed herewith. Except as +REM otherwise provided in a valid license issued to you by +REM Xilinx, and to the maximum extent permitted by applicable +REM law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +REM WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +REM AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +REM BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +REM INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +REM (2) Xilinx shall not be liable (whether in contract or tort, +REM including negligence, or under any other theory of +REM liability) for any loss or damage of any kind or nature +REM related to, arising under or in connection with these +REM materials, including for any direct, or any indirect, +REM special, incidental, or consequential loss or damage +REM (including loss of data, profits, goodwill, or any type of +REM loss or damage suffered as a result of any action brought +REM by a third party) even if such damage or loss was +REM reasonably foreseeable or Xilinx had been advised of the +REM possibility of the same. +REM +REM CRITICAL APPLICATIONS +REM Xilinx products are not designed or intended to be fail- +REM safe, or for use in any application requiring fail-safe +REM performance, such as life-support or safety devices or +REM systems, Class III medical devices, nuclear facilities, +REM applications related to the deployment of airbags, or any +REM other applications that could lead to death, personal +REM injury, or severe property or environmental damage +REM (individually and collectively, "Critical +REM Applications"). Customer assumes the sole risk and +REM liability of any use of Xilinx products in Critical +REM Applications, subject only to applicable laws and +REM regulations governing limitations on product liability. +REM +REM THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +REM PART OF THIS FILE AT ALL TIMES. +REM + +REM ----------------------------------------------------------------------------- +REM Script to synthesize and implement the RTL provided for the clocking wizard +REM ----------------------------------------------------------------------------- + +REM Clean up the results directory +rmdir /S /Q results +mkdir results + +REM Copy unisim_comp.v file to results directory +copy %XILINX%\verilog\src\iSE\unisim_comp.v .\results\ + +REM Synthesize the Verilog Wrapper Files +echo 'Synthesizing Clocking Wizard design with XST' +xst -ifn xst.scr +move clkmgr_dcm_exdes.ngc results\ + +REM Copy the constraints files generated by Coregen +echo 'Copying files from constraints directory to results directory' +copy ..\example_design\clkmgr_dcm_exdes.ucf results\ + +cd results + +echo 'Running ngdbuild' +ngdbuild -uc clkmgr_dcm_exdes.ucf clkmgr_dcm_exdes + +echo 'Running map' +map -timing -pr b clkmgr_dcm_exdes -o mapped.ncd + +echo 'Running par' +par -w mapped.ncd routed mapped.pcf + +echo 'Running trce' +trce -e 10 routed -o routed mapped.pcf + +echo 'Running design through bitgen' +bitgen -w routed + +echo 'Running netgen to create gate level model for the clocking wizard example design' +netgen -ofmt verilog -sim -sdf_anno false -tm clkmgr_dcm_exdes -w routed.ncd routed.v +cd .. + diff --git a/common/rtl/ipcore/clkmgr_dcm/implement/implement.sh b/common/rtl/ipcore/clkmgr_dcm/implement/implement.sh new file mode 100644 index 0000000..2c64bee --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/implement/implement.sh @@ -0,0 +1,91 @@ +#!/bin/sh +# file: implement.sh +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +#----------------------------------------------------------------------------- +# Script to synthesize and implement the RTL provided for the clocking wizard +#----------------------------------------------------------------------------- + +# Clean up the results directory +rm -rf results +mkdir results + +# Copy unisim_comp.v file to results directory +cp $XILINX/verilog/src/iSE/unisim_comp.v ./results/ + +# Synthesize the Verilog Wrapper Files +echo 'Synthesizing Clocking Wizard design with XST' +xst -ifn xst.scr +mv clkmgr_dcm_exdes.ngc results/ + +# Copy the constraints files generated by Coregen +echo 'Copying files from constraints directory to results directory' +cp ../example_design/clkmgr_dcm_exdes.ucf results/ + +cd results + +echo 'Running ngdbuild' +ngdbuild -uc clkmgr_dcm_exdes.ucf clkmgr_dcm_exdes + +echo 'Running map' +map -timing clkmgr_dcm_exdes -o mapped.ncd + +echo 'Running par' +par -w mapped.ncd routed mapped.pcf + +echo 'Running trce' +trce -e 10 routed -o routed mapped.pcf + +echo 'Running design through bitgen' +bitgen -w routed + +echo 'Running netgen to create gate level model for the clocking wizard example design' +netgen -ofmt verilog -sim -sdf_anno false -tm clkmgr_dcm_exdes -w routed.ncd routed.v + +cd .. diff --git a/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_ise.bat b/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_ise.bat new file mode 100644 index 0000000..9782028 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_ise.bat @@ -0,0 +1,58 @@ +REM file: planAhead_ise.bat +REM +REM (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +REM +REM This file contains confidential and proprietary information +REM of Xilinx, Inc. and is protected under U.S. and +REM international copyright and other intellectual property +REM laws. +REM +REM DISCLAIMER +REM This disclaimer is not a license and does not grant any +REM rights to the materials distributed herewith. Except as +REM otherwise provided in a valid license issued to you by +REM Xilinx, and to the maximum extent permitted by applicable +REM law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +REM WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +REM AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +REM BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +REM INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +REM (2) Xilinx shall not be liable (whether in contract or tort, +REM including negligence, or under any other theory of +REM liability) for any loss or damage of any kind or nature +REM related to, arising under or in connection with these +REM materials, including for any direct, or any indirect, +REM special, incidental, or consequential loss or damage +REM (including loss of data, profits, goodwill, or any type of +REM loss or damage suffered as a result of any action brought +REM by a third party) even if such damage or loss was +REM reasonably foreseeable or Xilinx had been advised of the +REM possibility of the same. +REM +REM CRITICAL APPLICATIONS +REM Xilinx products are not designed or intended to be fail- +REM safe, or for use in any application requiring fail-safe +REM performance, such as life-support or safety devices or +REM systems, Class III medical devices, nuclear facilities, +REM applications related to the deployment of airbags, or any +REM other applications that could lead to death, personal +REM injury, or severe property or environmental damage +REM (individually and collectively, "Critical +REM Applications"). Customer assumes the sole risk and +REM liability of any use of Xilinx products in Critical +REM Applications, subject only to applicable laws and +REM regulations governing limitations on product liability. +REM +REM THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +REM PART OF THIS FILE AT ALL TIMES. +REM + +REM----------------------------------------------------------------------------- +REM Script to synthesize and implement the RTL provided for the clocking wizard +REM----------------------------------------------------------------------------- + +del \f results +mkdir results +cd results + +planAhead -mode batch -source ..\planAhead_ise.tcl diff --git a/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_ise.sh b/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_ise.sh new file mode 100644 index 0000000..7f436b6 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_ise.sh @@ -0,0 +1,59 @@ +#!/bin/sh +# file: planAhead_ise.sh +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +#----------------------------------------------------------------------------- +# Script to synthesize and implement the RTL provided for the clocking wizard +#----------------------------------------------------------------------------- + +rm -rf results +mkdir results +cd results + +planAhead -mode batch -source ../planAhead_ise.tcl diff --git a/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_ise.tcl b/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_ise.tcl new file mode 100644 index 0000000..ab77638 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_ise.tcl @@ -0,0 +1,78 @@ +# file: planAhead_ise.tcl +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +set projDir [file dirname [info script]] +set projName clkmgr_dcm +set topName clkmgr_dcm_exdes +set device xc6slx45csg324-3 + +create_project $projName $projDir/results/$projName -part $device + +set_property design_mode RTL [get_filesets sources_1] + +## Source files +#set verilogSources [glob $srcDir/*.v] +import_files -fileset [get_filesets sources_1] -force -norecurse ../../example_design/clkmgr_dcm_exdes.v +import_files -fileset [get_filesets sources_1] -force -norecurse ../../../clkmgr_dcm.v + + +#UCF file +import_files -fileset [get_filesets constrs_1] -force -norecurse ../../example_design/clkmgr_dcm_exdes.ucf + +set_property top $topName [get_property srcset [current_run]] + +launch_runs -runs synth_1 +wait_on_run synth_1 + +set_property add_step Bitgen [get_runs impl_1] +launch_runs -runs impl_1 +wait_on_run impl_1 + + + diff --git a/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_rdn.bat b/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_rdn.bat new file mode 100644 index 0000000..3e1e03b --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_rdn.bat @@ -0,0 +1,58 @@ +REM file: planAhead_rdn.sh +REM +REM (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +REM +REM This file contains confidential and proprietary information +REM of Xilinx, Inc. and is protected under U.S. and +REM international copyright and other intellectual property +REM laws. +REM +REM DISCLAIMER +REM This disclaimer is not a license and does not grant any +REM rights to the materials distributed herewith. Except as +REM otherwise provided in a valid license issued to you by +REM Xilinx, and to the maximum extent permitted by applicable +REM law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +REM WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +REM AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +REM BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +REM INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +REM (2) Xilinx shall not be liable (whether in contract or tort, +REM including negligence, or under any other theory of +REM liability) for any loss or damage of any kind or nature +REM related to, arising under or in connection with these +REM materials, including for any direct, or any indirect, +REM special, incidental, or consequential loss or damage +REM (including loss of data, profits, goodwill, or any type of +REM loss or damage suffered as a result of any action brought +REM by a third party) even if such damage or loss was +REM reasonably foreseeable or Xilinx had been advised of the +REM possibility of the same. +REM +REM CRITICAL APPLICATIONS +REM Xilinx products are not designed or intended to be fail- +REM safe, or for use in any application requiring fail-safe +REM performance, such as life-support or safety devices or +REM systems, Class III medical devices, nuclear facilities, +REM applications related to the deployment of airbags, or any +REM other applications that could lead to death, personal +REM injury, or severe property or environmental damage +REM (individually and collectively, "Critical +REM Applications"). Customer assumes the sole risk and +REM liability of any use of Xilinx products in Critical +REM Applications, subject only to applicable laws and +REM regulations governing limitations on product liability. +REM +REM THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +REM PART OF THIS FILE AT ALL TIMES. +REM + +REM----------------------------------------------------------------------------- +REM Script to synthesize and implement the RTL provided for the XADC wizard +REM----------------------------------------------------------------------------- + +del \f results +mkdir results +cd results + +planAhead -mode batch -source ..\planAhead_rdn.tcl diff --git a/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_rdn.sh b/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_rdn.sh new file mode 100644 index 0000000..a5adee8 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_rdn.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# file: planAhead_rdn.sh +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +#----------------------------------------------------------------------------- +# Script to synthesize and implement the RTL provided for the XADC wizard +#----------------------------------------------------------------------------- +rm -rf results +mkdir results +cd results +planAhead -mode batch -source ../planAhead_rdn.tcl diff --git a/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_rdn.tcl b/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_rdn.tcl new file mode 100644 index 0000000..e8c0fdf --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/implement/planAhead_rdn.tcl @@ -0,0 +1,69 @@ +# file : planAhead_rdn.tcl +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +set device xc6slx45csg324-3 +set projName clkmgr_dcm +set design clkmgr_dcm +set projDir [file dirname [info script]] +create_project $projName $projDir/results/$projName -part $device -force +set_property design_mode RTL [current_fileset -srcset] +set top_module clkmgr_dcm_exdes +set_property top clkmgr_dcm_exdes [get_property srcset [current_run]] +add_files -norecurse {../../../clkmgr_dcm.v} +add_files -norecurse {../../example_design/clkmgr_dcm_exdes.v} +import_files -fileset [get_filesets constrs_1 ] -force -norecurse {../../example_design/clkmgr_dcm_exdes.xdc} +synth_design +opt_design +place_design +route_design +write_sdf -rename_top_module clkmgr_dcm_exdes -file routed.sdf +write_verilog -nolib -mode timesim -sdf_anno false -rename_top_module clkmgr_dcm_exdes -file routed.v +report_timing -nworst 30 -path_type full -file routed.twr +report_drc -file report.drc +write_bitstream -bitgen_options {-g UnconstrainedPins:Allow} -file routed.bit diff --git a/common/rtl/ipcore/clkmgr_dcm/implement/xst.prj b/common/rtl/ipcore/clkmgr_dcm/implement/xst.prj new file mode 100644 index 0000000..cd0e0e6 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/implement/xst.prj @@ -0,0 +1,2 @@ +verilog work ../../clkmgr_dcm.v +verilog work ../example_design/clkmgr_dcm_exdes.v diff --git a/common/rtl/ipcore/clkmgr_dcm/implement/xst.scr b/common/rtl/ipcore/clkmgr_dcm/implement/xst.scr new file mode 100644 index 0000000..20d09f4 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/implement/xst.scr @@ -0,0 +1,9 @@ +run +-ifmt MIXED +-top clkmgr_dcm_exdes +-p xc6slx45-csg324-3 +-ifn xst.prj +-ofn clkmgr_dcm_exdes +-keep_hierarchy soft +-equivalent_register_removal no +-max_fanout 65535 diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/clkmgr_dcm_tb.v b/common/rtl/ipcore/clkmgr_dcm/simulation/clkmgr_dcm_tb.v new file mode 100644 index 0000000..ee24750 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/clkmgr_dcm_tb.v @@ -0,0 +1,145 @@ +// file: clkmgr_dcm_tb.v +// +// (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +// +// This file contains confidential and proprietary information +// of Xilinx, Inc. and is protected under U.S. and +// international copyright and other intellectual property +// laws. +// +// DISCLAIMER +// This disclaimer is not a license and does not grant any +// rights to the materials distributed herewith. Except as +// otherwise provided in a valid license issued to you by +// Xilinx, and to the maximum extent permitted by applicable +// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +// (2) Xilinx shall not be liable (whether in contract or tort, +// including negligence, or under any other theory of +// liability) for any loss or damage of any kind or nature +// related to, arising under or in connection with these +// materials, including for any direct, or any indirect, +// special, incidental, or consequential loss or damage +// (including loss of data, profits, goodwill, or any type of +// loss or damage suffered as a result of any action brought +// by a third party) even if such damage or loss was +// reasonably foreseeable or Xilinx had been advised of the +// possibility of the same. +// +// CRITICAL APPLICATIONS +// Xilinx products are not designed or intended to be fail- +// safe, or for use in any application requiring fail-safe +// performance, such as life-support or safety devices or +// systems, Class III medical devices, nuclear facilities, +// applications related to the deployment of airbags, or any +// other applications that could lead to death, personal +// injury, or severe property or environmental damage +// (individually and collectively, "Critical +// Applications"). Customer assumes the sole risk and +// liability of any use of Xilinx products in Critical +// Applications, subject only to applicable laws and +// regulations governing limitations on product liability. +// +// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +// PART OF THIS FILE AT ALL TIMES. +// + +//---------------------------------------------------------------------------- +// Clocking wizard demonstration testbench +//---------------------------------------------------------------------------- +// This demonstration testbench instantiates the example design for the +// clocking wizard. Input clocks are toggled, which cause the clocking +// network to lock and the counters to increment. +//---------------------------------------------------------------------------- + +`timescale 1ps/1ps + +`define wait_lock @(posedge CLK_VALID) + +module clkmgr_dcm_tb (); + + // Clock to Q delay of 100ps + localparam TCQ = 100; + + + // timescale is 1ps/1ps + localparam ONE_NS = 1000; + localparam PHASE_ERR_MARGIN = 100; // 100ps + // how many cycles to run + localparam COUNT_PHASE = 1024; + // we'll be using the period in many locations + localparam time PER1 = 20.0*ONE_NS; + localparam time PER1_1 = PER1/2; + localparam time PER1_2 = PER1 - PER1/2; + + // Declare the input clock signals + reg CLK_IN1 = 1; + + // The high bit of the sampling counter + wire COUNT; + // Status and control signals + reg RESET = 0; + wire INPUT_CLK_STOPPED; + wire CLK_VALID; + reg COUNTER_RESET = 0; +wire [1:1] CLK_OUT; +//Freq Check using the M & D values setting and actual Frequency generated + + + // Input clock generation + //------------------------------------ + always begin + CLK_IN1 = #PER1_1 ~CLK_IN1; + CLK_IN1 = #PER1_2 ~CLK_IN1; + end + + // Test sequence + reg [15*8-1:0] test_phase = ""; + initial begin + // Set up any display statements using time to be readable + $timeformat(-12, 2, "ps", 10); + COUNTER_RESET = 0; + test_phase = "reset"; + RESET = 1; + #(PER1*6); + RESET = 0; + test_phase = "wait lock"; + `wait_lock; + #(PER1*6); + COUNTER_RESET = 1; + #(PER1*20) + COUNTER_RESET = 0; + + test_phase = "counting"; + #(PER1*COUNT_PHASE); + + $display("SIMULATION PASSED"); + $display("SYSTEM_CLOCK_COUNTER : %0d\n",$time/PER1); + $finish; + end + + // Instantiation of the example design containing the clock + // network and sampling counters + //--------------------------------------------------------- + clkmgr_dcm_exdes + #( + .TCQ (TCQ) + ) dut + (// Clock in ports + .CLK_IN1 (CLK_IN1), + // Reset for logic in example design + .COUNTER_RESET (COUNTER_RESET), + .CLK_OUT (CLK_OUT), + // High bits of the counters + .COUNT (COUNT), + // Status and control signals + .RESET (RESET), + .INPUT_CLK_STOPPED (INPUT_CLK_STOPPED), + .CLK_VALID (CLK_VALID)); + +// Freq Check + +endmodule diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simcmds.tcl b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simcmds.tcl new file mode 100644 index 0000000..e19ead8 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simcmds.tcl @@ -0,0 +1,8 @@ +# file: simcmds.tcl + +# create the simulation script +vcd dumpfile isim.vcd +vcd dumpvars -m /clkmgr_dcm_tb -l 0 +wave add / +run 50000ns +quit diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_isim.bat b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_isim.bat new file mode 100644 index 0000000..80904cb --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_isim.bat @@ -0,0 +1,59 @@ +REM file: simulate_isim.bat +REM +REM (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +REM +REM This file contains confidential and proprietary information +REM of Xilinx, Inc. and is protected under U.S. and +REM international copyright and other intellectual property +REM laws. +REM +REM DISCLAIMER +REM This disclaimer is not a license and does not grant any +REM rights to the materials distributed herewith. Except as +REM otherwise provided in a valid license issued to you by +REM Xilinx, and to the maximum extent permitted by applicable +REM law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +REM WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +REM AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +REM BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +REM INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +REM (2) Xilinx shall not be liable (whether in contract or tort, +REM including negligence, or under any other theory of +REM liability) for any loss or damage of any kind or nature +REM related to, arising under or in connection with these +REM materials, including for any direct, or any indirect, +REM special, incidental, or consequential loss or damage +REM (including loss of data, profits, goodwill, or any type of +REM loss or damage suffered as a result of any action brought +REM by a third party) even if such damage or loss was +REM reasonably foreseeable or Xilinx had been advised of the +REM possibility of the same. +REM +REM CRITICAL APPLICATIONS +REM Xilinx products are not designed or intended to be fail- +REM safe, or for use in any application requiring fail-safe +REM performance, such as life-support or safety devices or +REM systems, Class III medical devices, nuclear facilities, +REM applications related to the deployment of airbags, or any +REM other applications that could lead to death, personal +REM injury, or severe property or environmental damage +REM (individually and collectively, "Critical +REM Applications"). Customer assumes the sole risk and +REM liability of any use of Xilinx products in Critical +REM Applications, subject only to applicable laws and +REM regulations governing limitations on product liability. +REM +REM THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +REM PART OF THIS FILE AT ALL TIMES. +REM + +vlogcomp -work work %XILINX%\verilog\src\glbl.v +vlogcomp -work work ..\..\..\clkmgr_dcm.v +vlogcomp -work work ..\..\example_design\clkmgr_dcm_exdes.v +vlogcomp -work work ..\clkmgr_dcm_tb.v + +REM compile the project +fuse work.clkmgr_dcm_tb work.glbl -L unisims_ver -o clkmgr_dcm_isim.exe + +REM run the simulation script +.\clkmgr_dcm_isim.exe -gui -tclbatch simcmds.tcl diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_isim.sh b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_isim.sh new file mode 100644 index 0000000..9fb5029 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_isim.sh @@ -0,0 +1,61 @@ +# file: simulate_isim.sh +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# nt +# create the project +vlogcomp -work work ${XILINX}/verilog/src/glbl.v +vlogcomp -work work ../../../clkmgr_dcm.v +vlogcomp -work work ../../example_design/clkmgr_dcm_exdes.v +vlogcomp -work work ../clkmgr_dcm_tb.v + +# compile the project +fuse work.clkmgr_dcm_tb work.glbl -L unisims_ver -o clkmgr_dcm_isim.exe + +# run the simulation script +./clkmgr_dcm_isim.exe -gui -tclbatch simcmds.tcl diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_mti.bat b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_mti.bat new file mode 100644 index 0000000..7497cd9 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_mti.bat @@ -0,0 +1,61 @@ +REM file: simulate_mti.bat +REM +REM (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +REM +REM This file contains confidential and proprietary information +REM of Xilinx, Inc. and is protected under U.S. and +REM international copyright and other intellectual property +REM laws. +REM +REM DISCLAIMER +REM This disclaimer is not a license and does not grant any +REM rights to the materials distributed herewith. Except as +REM otherwise provided in a valid license issued to you by +REM Xilinx, and to the maximum extent permitted by applicable +REM law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +REM WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +REM AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +REM BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +REM INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +REM (2) Xilinx shall not be liable (whether in contract or tort, +REM including negligence, or under any other theory of +REM liability) for any loss or damage of any kind or nature +REM related to, arising under or in connection with these +REM materials, including for any direct, or any indirect, +REM special, incidental, or consequential loss or damage +REM (including loss of data, profits, goodwill, or any type of +REM loss or damage suffered as a result of any action brought +REM by a third party) even if such damage or loss was +REM reasonably foreseeable or Xilinx had been advised of the +REM possibility of the same. +REM +REM CRITICAL APPLICATIONS +REM Xilinx products are not designed or intended to be fail- +REM safe, or for use in any application requiring fail-safe +REM performance, such as life-support or safety devices or +REM systems, Class III medical devices, nuclear facilities, +REM applications related to the deployment of airbags, or any +REM other applications that could lead to death, personal +REM injury, or severe property or environmental damage +REM (individually and collectively, "Critical +REM Applications"). Customer assumes the sole risk and +REM liability of any use of Xilinx products in Critical +REM Applications, subject only to applicable laws and +REM regulations governing limitations on product liability. +REM +REM THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +REM PART OF THIS FILE AT ALL TIMES. +REM + +REM set up the working directory +vlib work + +REM compile all of the files +vlog -work work %XILINX%\verilog\src\glbl.v +vlog -work work ..\..\..\clkmgr_dcm.v +vlog -work work ..\..\example_design\clkmgr_dcm_exdes.v +vlog -work work ..\clkmgr_dcm_tb.v + +REM run the simulation +vsim -c -t ps -voptargs="+acc" -L secureip -L unisims_ver work.clkmgr_dcm_tb work.glbl + diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_mti.do b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_mti.do new file mode 100644 index 0000000..b0e526f --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_mti.do @@ -0,0 +1,65 @@ +# file: simulate_mti.do +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# set up the working directory +set work work +vlib work + +# compile all of the files +vlog -work work $env(XILINX)/verilog/src/glbl.v +vlog -work work ../../../clkmgr_dcm.v +vlog -work work ../../example_design/clkmgr_dcm_exdes.v +vlog -work work ../clkmgr_dcm_tb.v + +# run the simulation +vsim -t ps -voptargs="+acc" -L unisims_ver work.clkmgr_dcm_tb work.glbl +do wave.do +log clkmgr_dcm_tb/dut/counter +log -r /* +run 50000ns diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_mti.sh b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_mti.sh new file mode 100644 index 0000000..66099e0 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_mti.sh @@ -0,0 +1,61 @@ +#/bin/sh +# file: simulate_mti.sh +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# +# set up the working directory +set work work +vlib work + +# compile all of the files +vlog -work work $XILINX/verilog/src/glbl.v +vlog -work work ../../../clkmgr_dcm.v +vlog -work work ../../example_design/clkmgr_dcm_exdes.v +vlog -work work ../clkmgr_dcm_tb.v + +# run the simulation +vsim -c -t ps -voptargs="+acc" -L secureip -L unisims_ver work.clkmgr_dcm_tb work.glbl diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_ncsim.sh b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_ncsim.sh new file mode 100644 index 0000000..01b0412 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_ncsim.sh @@ -0,0 +1,62 @@ +#/bin/sh +# file: simulate_ncsim.sh +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# set up the working directory +mkdir work + +# compile all of the files +ncvlog -work work ${XILINX}/verilog/src/glbl.v +ncvlog -work work ../../../clkmgr_dcm.v +ncvlog -work work ../../example_design/clkmgr_dcm_exdes.v +ncvlog -work work ../clkmgr_dcm_tb.v + +# elaborate and run the simulation +ncelab -work work -access +wc work.clkmgr_dcm_tb work.glbl +ncsim -input "@database -open -shm nc; probe -create -database nc -all -depth all; probe dut.counter; run 50000ns; exit" work.clkmgr_dcm_tb diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_vcs.sh b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_vcs.sh new file mode 100644 index 0000000..39668df --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/simulate_vcs.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# file: simulate_vcs.sh +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# remove old files +rm -rf simv* csrc DVEfiles AN.DB + +# compile all of the files +# Note that -sverilog is not strictly required- You can +# remove the -sverilog if you change the type of the +# localparam for the periods in the testbench file to +# [63:0] from time +vlogan -sverilog \ + ${XILINX}/verilog/src/glbl.v \ + ../../../clkmgr_dcm.v \ + ../../example_design/clkmgr_dcm_exdes.v \ + ../clkmgr_dcm_tb.v + +# prepare the simulation +vcs +vcs+lic+wait -debug clkmgr_dcm_tb glbl + +# run the simulation +./simv -ucli -i ucli_commands.key + +# launch the viewer +dve -vpd vcdplus.vpd -session vcs_session.tcl diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/functional/ucli_commands.key b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/ucli_commands.key new file mode 100644 index 0000000..2bbdd0f --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/ucli_commands.key @@ -0,0 +1,5 @@ +call {$vcdpluson} +call {$vcdplusmemon(clkmgr_dcm_tb.dut.counter)} +run +call {$vcdplusclose} +quit diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/functional/vcs_session.tcl b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/vcs_session.tcl new file mode 100644 index 0000000..628e55a --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/vcs_session.tcl @@ -0,0 +1,18 @@ +gui_open_window Wave +gui_sg_create clkmgr_dcm_group +gui_list_add_group -id Wave.1 {clkmgr_dcm_group} +gui_sg_addsignal -group clkmgr_dcm_group {clkmgr_dcm_tb.test_phase} +gui_set_radix -radix {ascii} -signals {clkmgr_dcm_tb.test_phase} +gui_sg_addsignal -group clkmgr_dcm_group {{Input_clocks}} -divider +gui_sg_addsignal -group clkmgr_dcm_group {clkmgr_dcm_tb.CLK_IN1} +gui_sg_addsignal -group clkmgr_dcm_group {{Output_clocks}} -divider +gui_sg_addsignal -group clkmgr_dcm_group {clkmgr_dcm_tb.dut.clk} +gui_list_expand -id Wave.1 clkmgr_dcm_tb.dut.clk +gui_sg_addsignal -group clkmgr_dcm_group {{Status_control}} -divider +gui_sg_addsignal -group clkmgr_dcm_group {clkmgr_dcm_tb.RESET} +gui_sg_addsignal -group clkmgr_dcm_group {clkmgr_dcm_tb.USE_INCLK_STOPPED} +gui_sg_addsignal -group clkmgr_dcm_group {{Counters}} -divider +gui_sg_addsignal -group clkmgr_dcm_group {clkmgr_dcm_tb.COUNT} +gui_sg_addsignal -group clkmgr_dcm_group {clkmgr_dcm_tb.dut.counter} +gui_list_expand -id Wave.1 clkmgr_dcm_tb.dut.counter +gui_zoom -window Wave.1 -full diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/functional/wave.do b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/wave.do new file mode 100644 index 0000000..eee7422 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/wave.do @@ -0,0 +1,60 @@ +# file: wave.do +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +add wave -noupdate -format Literal -radix ascii /clkmgr_dcm_tb/test_phase +add wave -noupdate -divider {Input clocks} +add wave -noupdate -format Logic /clkmgr_dcm_tb/CLK_IN1 +add wave -noupdate -divider {Output clocks} +add wave -noupdate -format Logic /clkmgr_dcm_tb/dut/clk +add wave -noupdate -divider Status/control +add wave -noupdate -format Logic /clkmgr_dcm_tb/RESET +add wave -noupdate -format Logic /clkmgr_dcm_tb/INPUT_CLK_STOPPED +add wave -noupdate -divider Counters +add wave -noupdate -format Literal -radix hexadecimal /clkmgr_dcm_tb/COUNT +add wave -noupdate -format Literal -radix hexadecimal /clkmgr_dcm_tb/dut/counter diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/functional/wave.sv b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/wave.sv new file mode 100644 index 0000000..c3c3eef --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/functional/wave.sv @@ -0,0 +1,118 @@ +# file: wave.sv +# +# (c) Copyright 2008 - 2010 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# +# Get the windows set up +# +if {[catch {window new WatchList -name "Design Browser 1" -geometry 1054x819+536+322}] != ""} { + window geometry "Design Browser 1" 1054x819+536+322 +} +window target "Design Browser 1" on +browser using {Design Browser 1} +browser set \ + -scope nc::clkmgr_dcm_tb +browser yview see nc::clkmgr_dcm_tb +browser timecontrol set -lock 0 + +if {[catch {window new WaveWindow -name "Waveform 1" -geometry 1010x600+0+541}] != ""} { + window geometry "Waveform 1" 1010x600+0+541 +} +window target "Waveform 1" on +waveform using {Waveform 1} +waveform sidebar visibility partial +waveform set \ + -primarycursor TimeA \ + -signalnames name \ + -signalwidth 175 \ + -units ns \ + -valuewidth 75 +cursor set -using TimeA -time 0 +waveform baseline set -time 0 +waveform xview limits 0 20000n + +# +# Define signal groups +# +catch {group new -name {Output clocks} -overlay 0} +catch {group new -name {Status/control} -overlay 0} +catch {group new -name {Counters} -overlay 0} + +set id [waveform add -signals [list {nc::clkmgr_dcm_tb.CLK_IN1}]] + +group using {Output clocks} +group set -overlay 0 +group set -comment {} +group clear 0 end + +group insert \ + {clkmgr_dcm_tb.dut.clk} \ + +group using {Counters} +group set -overlay 0 +group set -comment {} +group clear 0 end + +group insert \ + {clkmgr_dcm_tb.dut.counter} \ + +group using {Status/control} +group set -overlay 0 +group set -comment {} +group clear 0 end + +group insert \ + {nc::clkmgr_dcm_tb.RESET} {nc::clkmgr_dcm_tb.INPUT_CLK_STOPPED} + +set id [waveform add -signals [list {nc::clkmgr_dcm_tb.COUNT} ]] + +set id [waveform add -signals [list {nc::clkmgr_dcm_tb.test_phase} ]] +waveform format $id -radix %a + +set groupId [waveform add -groups {{Input clocks}}] +set groupId [waveform add -groups {{Output clocks}}] +set groupId [waveform add -groups {{Status/control}}] +set groupId [waveform add -groups {{Counters}}] diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/timing/clkmgr_dcm_tb.v b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/clkmgr_dcm_tb.v new file mode 100644 index 0000000..9618253 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/clkmgr_dcm_tb.v @@ -0,0 +1,149 @@ +// file: clkmgr_dcm_tb.v +// +// (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +// +// This file contains confidential and proprietary information +// of Xilinx, Inc. and is protected under U.S. and +// international copyright and other intellectual property +// laws. +// +// DISCLAIMER +// This disclaimer is not a license and does not grant any +// rights to the materials distributed herewith. Except as +// otherwise provided in a valid license issued to you by +// Xilinx, and to the maximum extent permitted by applicable +// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +// (2) Xilinx shall not be liable (whether in contract or tort, +// including negligence, or under any other theory of +// liability) for any loss or damage of any kind or nature +// related to, arising under or in connection with these +// materials, including for any direct, or any indirect, +// special, incidental, or consequential loss or damage +// (including loss of data, profits, goodwill, or any type of +// loss or damage suffered as a result of any action brought +// by a third party) even if such damage or loss was +// reasonably foreseeable or Xilinx had been advised of the +// possibility of the same. +// +// CRITICAL APPLICATIONS +// Xilinx products are not designed or intended to be fail- +// safe, or for use in any application requiring fail-safe +// performance, such as life-support or safety devices or +// systems, Class III medical devices, nuclear facilities, +// applications related to the deployment of airbags, or any +// other applications that could lead to death, personal +// injury, or severe property or environmental damage +// (individually and collectively, "Critical +// Applications"). Customer assumes the sole risk and +// liability of any use of Xilinx products in Critical +// Applications, subject only to applicable laws and +// regulations governing limitations on product liability. +// +// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +// PART OF THIS FILE AT ALL TIMES. +// + +//---------------------------------------------------------------------------- +// Clocking wizard demonstration testbench +//---------------------------------------------------------------------------- +// This demonstration testbench instantiates the example design for the +// clocking wizard. Input clocks are toggled, which cause the clocking +// network to lock and the counters to increment. +//---------------------------------------------------------------------------- + +`timescale 1ps/1ps + +`define wait_lock @(posedge CLK_VALID) + +module clkmgr_dcm_tb (); + + // Clock to Q delay of 100ps + localparam TCQ = 100; + + + // timescale is 1ps/1ps + localparam ONE_NS = 1000; + localparam PHASE_ERR_MARGIN = 100; // 100ps + // how many cycles to run + localparam COUNT_PHASE = 1024; + // we'll be using the period in many locations + localparam time PER1 = 20.0*ONE_NS; + localparam time PER1_1 = PER1/2; + localparam time PER1_2 = PER1 - PER1/2; + + // Declare the input clock signals + reg CLK_IN1 = 1; + + // The high bit of the sampling counter + wire COUNT; + // Status and control signals + reg RESET = 0; + wire INPUT_CLK_STOPPED; + wire CLK_VALID; + reg COUNTER_RESET = 0; +wire [1:1] CLK_OUT; +//Freq Check using the M & D values setting and actual Frequency generated + + reg [13:0] timeout_counter = 14'b00000000000000; + + // Input clock generation + //------------------------------------ + always begin + CLK_IN1 = #PER1_1 ~CLK_IN1; + CLK_IN1 = #PER1_2 ~CLK_IN1; + end + + // Test sequence + reg [15*8-1:0] test_phase = ""; + initial begin + // Set up any display statements using time to be readable + $timeformat(-12, 2, "ps", 10); + $display ("Timing checks are not valid"); + COUNTER_RESET = 0; + test_phase = "reset"; + RESET = 1; + #(PER1*6); + RESET = 0; + test_phase = "wait lock"; + `wait_lock; + #(PER1*6); + COUNTER_RESET = 1; + #(PER1*19.5) + COUNTER_RESET = 0; + #(PER1*1) + $display ("Timing checks are valid"); + test_phase = "counting"; + #(PER1*COUNT_PHASE); + + $display("SIMULATION PASSED"); + $display("SYSTEM_CLOCK_COUNTER : %0d\n",$time/PER1); + $finish; + end + + + + // Instantiation of the example design containing the clock + // network and sampling counters + //--------------------------------------------------------- + clkmgr_dcm_exdes + dut + (// Clock in ports + .CLK_IN1 (CLK_IN1), + // Reset for logic in example design + .COUNTER_RESET (COUNTER_RESET), + .CLK_OUT (CLK_OUT), + // High bits of the counters + .COUNT (COUNT), + // Status and control signals + .RESET (RESET), + .INPUT_CLK_STOPPED (INPUT_CLK_STOPPED), + .CLK_VALID (CLK_VALID)); + + +// Freq Check + +endmodule diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/timing/sdf_cmd_file b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/sdf_cmd_file new file mode 100644 index 0000000..d59e315 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/sdf_cmd_file @@ -0,0 +1,2 @@ +COMPILED_SDF_FILE = "../../implement/results/routed.sdf.X", +SCOPE = clkmgr_dcm_tb.dut; diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simcmds.tcl b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simcmds.tcl new file mode 100644 index 0000000..14523af --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simcmds.tcl @@ -0,0 +1,9 @@ +# file: simcmds.tcl + +# create the simulation script +vcd dumpfile isim.vcd +vcd dumpvars -m /clkmgr_dcm_tb -l 0 +wave add / +run 50000ns +quit + diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_isim.sh b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_isim.sh new file mode 100644 index 0000000..0152cb0 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_isim.sh @@ -0,0 +1,62 @@ +# file: simulate_isim.sh +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# create the project +vlogcomp -work work ${XILINX}/verilog/src/glbl.v +vlogcomp -work work ../../implement/results/routed.v +vlogcomp -work work clkmgr_dcm_tb.v + +# compile the project +fuse work.clkmgr_dcm_tb work.glbl -L secureip -L simprims_ver -o clkmgr_dcm_isim.exe + +# run the simulation script +./clkmgr_dcm_isim.exe -tclbatch simcmds.tcl -sdfmax /clkmgr_dcm_tb/dut=../../implement/results/routed.sdf + +# run the simulation script +#./clkmgr_dcm_isim.exe -gui -tclbatch simcmds.tcl diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_mti.bat b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_mti.bat new file mode 100644 index 0000000..8a08dc0 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_mti.bat @@ -0,0 +1,59 @@ +REM file: simulate_mti.bat +REM +REM (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +REM +REM This file contains confidential and proprietary information +REM of Xilinx, Inc. and is protected under U.S. and +REM international copyright and other intellectual property +REM laws. +REM +REM DISCLAIMER +REM This disclaimer is not a license and does not grant any +REM rights to the materials distributed herewith. Except as +REM otherwise provided in a valid license issued to you by +REM Xilinx, and to the maximum extent permitted by applicable +REM law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +REM WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +REM AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +REM BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +REM INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +REM (2) Xilinx shall not be liable (whether in contract or tort, +REM including negligence, or under any other theory of +REM liability) for any loss or damage of any kind or nature +REM related to, arising under or in connection with these +REM materials, including for any direct, or any indirect, +REM special, incidental, or consequential loss or damage +REM (including loss of data, profits, goodwill, or any type of +REM loss or damage suffered as a result of any action brought +REM by a third party) even if such damage or loss was +REM reasonably foreseeable or Xilinx had been advised of the +REM possibility of the same. +REM +REM CRITICAL APPLICATIONS +REM Xilinx products are not designed or intended to be fail- +REM safe, or for use in any application requiring fail-safe +REM performance, such as life-support or safety devices or +REM systems, Class III medical devices, nuclear facilities, +REM applications related to the deployment of airbags, or any +REM other applications that could lead to death, personal +REM injury, or severe property or environmental damage +REM (individually and collectively, "Critical +REM Applications"). Customer assumes the sole risk and +REM liability of any use of Xilinx products in Critical +REM Applications, subject only to applicable laws and +REM regulations governing limitations on product liability. +REM +REM THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +REM PART OF THIS FILE AT ALL TIMES. +REM +# set up the working directory +set work work +vlib work + +REM compile all of the files +vlog -work work %XILINX%\verilog\src\glbl.v +vlog -work work ..\..\implement\results\routed.v +vlog -work work clkmgr_dcm_tb.v + +REM run the simulation +vsim -c -t ps +transport_int_delays -voptargs="+acc" -L secureip -L simprims_ver -sdfmax clkmgr_dcm_tb\dut=..\..\implement\results\routed.sdf +no_notifier work.clkmgr_dcm_tb work.glbl diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_mti.do b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_mti.do new file mode 100644 index 0000000..bfeb9c5 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_mti.do @@ -0,0 +1,65 @@ +# file: simulate_mti.do +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# set up the working directory +set work work +vlib work + +# compile all of the files +vlog -work work $env(XILINX)/verilog/src/glbl.v +vlog -work work ../../implement/results/routed.v +vlog -work work clkmgr_dcm_tb.v + +# run the simulation +vsim -t ps +transport_int_delays -voptargs="+acc" -L secureip -L simprims_ver -sdfmax clkmgr_dcm_tb/dut=../../implement/results/routed.sdf +no_notifier work.clkmgr_dcm_tb work.glbl +#do wave.do +#log -r /* +run 50000ns + + diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_mti.sh b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_mti.sh new file mode 100644 index 0000000..b842adc --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_mti.sh @@ -0,0 +1,61 @@ +#/bin/sh +# file: simulate_mti.sh +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# set up the working directory +set work work +vlib work + +# compile all of the files +vlog -work work $XILINX/verilog/src/glbl.v +vlog -work work ../../implement/results/routed.v +vlog -work work clkmgr_dcm_tb.v + +# run the simulation +vsim -c -t ps +transport_int_delays -voptargs="+acc" -L secureip -L simprims_ver -sdfmax clkmgr_dcm_tb/dut=../../implement/results/routed.sdf +no_notifier work.clkmgr_dcm_tb work.glbl diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_ncsim.sh b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_ncsim.sh new file mode 100644 index 0000000..fd18dde --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_ncsim.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# file: simulate_ncsim.sh +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# set up the working directory +mkdir work + +# compile all of the files +ncvlog -work work ${XILINX}/verilog/src/glbl.v +ncvlog -work work ../../implement/results/routed.v +ncvlog -work work clkmgr_dcm_tb.v + +# elaborate and run the simulation +ncsdfc ../../implement/results/routed.sdf + +ncelab -work work -access +wc -pulse_r 10 -nonotifier work.clkmgr_dcm_tb work.glbl -sdf_cmd_file sdf_cmd_file +ncsim -input "@database -open -shm nc; probe -create -database nc -all -depth all; run 50000ns; exit" work.clkmgr_dcm_tb + diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_vcs.sh b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_vcs.sh new file mode 100644 index 0000000..26a8c27 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/simulate_vcs.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# file: simulate_vcs.sh +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +# remove old files +rm -rf simv* csrc DVEfiles AN.DB + +# compile all of the files +# Note that -sverilog is not strictly required- You can +# remove the -sverilog if you change the type of the +# localparam for the periods in the testbench file to +# [63:0] from time + vlogan -sverilog \ + clkmgr_dcm_tb.v \ + ../../implement/results/routed.v + + +# prepare the simulation +vcs -sdf max:clkmgr_dcm_exdes:../../implement/results/routed.sdf +v2k -y $XILINX/verilog/src/simprims \ + +libext+.v -debug clkmgr_dcm_tb.v ../../implement/results/routed.v + +# run the simulation +./simv -ucli -i ucli_commands.key + +# launch the viewer +#dve -vpd vcdplus.vpd -session vcs_session.tcl diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/timing/ucli_commands.key b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/ucli_commands.key new file mode 100644 index 0000000..b32669e --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/ucli_commands.key @@ -0,0 +1,5 @@ + +call {$vcdpluson} +run 50000ns +call {$vcdplusclose} +quit diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/timing/vcs_session.tcl b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/vcs_session.tcl new file mode 100644 index 0000000..6cc6e24 --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/vcs_session.tcl @@ -0,0 +1 @@ +gui_open_window Wave diff --git a/common/rtl/ipcore/clkmgr_dcm/simulation/timing/wave.do b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/wave.do new file mode 100644 index 0000000..7cc804b --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm/simulation/timing/wave.do @@ -0,0 +1,71 @@ +# file: wave.do +# +# (c) Copyright 2008 - 2011 Xilinx, Inc. All rights reserved. +# +# This file contains confidential and proprietary information +# of Xilinx, Inc. and is protected under U.S. and +# international copyright and other intellectual property +# laws. +# +# DISCLAIMER +# This disclaimer is not a license and does not grant any +# rights to the materials distributed herewith. Except as +# otherwise provided in a valid license issued to you by +# Xilinx, and to the maximum extent permitted by applicable +# law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND +# WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES +# AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING +# BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- +# INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and +# (2) Xilinx shall not be liable (whether in contract or tort, +# including negligence, or under any other theory of +# liability) for any loss or damage of any kind or nature +# related to, arising under or in connection with these +# materials, including for any direct, or any indirect, +# special, incidental, or consequential loss or damage +# (including loss of data, profits, goodwill, or any type of +# loss or damage suffered as a result of any action brought +# by a third party) even if such damage or loss was +# reasonably foreseeable or Xilinx had been advised of the +# possibility of the same. +# +# CRITICAL APPLICATIONS +# Xilinx products are not designed or intended to be fail- +# safe, or for use in any application requiring fail-safe +# performance, such as life-support or safety devices or +# systems, Class III medical devices, nuclear facilities, +# applications related to the deployment of airbags, or any +# other applications that could lead to death, personal +# injury, or severe property or environmental damage +# (individually and collectively, "Critical +# Applications"). Customer assumes the sole risk and +# liability of any use of Xilinx products in Critical +# Applications, subject only to applicable laws and +# regulations governing limitations on product liability. +# +# THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS +# PART OF THIS FILE AT ALL TIMES. +# + +onerror {resume} +quietly WaveActivateNextPane {} 0 +add wave -noupdate /clkmgr_dcm_tb/CLK_IN1 +add wave -noupdate /clkmgr_dcm_tb/COUNT +add wave -noupdate /clkmgr_dcm_tb/RESET +TreeUpdate [SetDefaultTree] +WaveRestoreCursors {{Cursor 1} {3223025 ps} 0} +configure wave -namecolwidth 238 +configure wave -valuecolwidth 107 +configure wave -justifyvalue left +configure wave -signalnamewidth 0 +configure wave -snapdistance 10 +configure wave -datasetprefix 0 +configure wave -rowmargin 4 +configure wave -childrowmargin 2 +configure wave -gridoffset 0 +configure wave -gridperiod 1 +configure wave -griddelta 40 +configure wave -timeline 0 +configure wave -timelineunits ps +update +WaveRestoreZoom {0 ps} {74848022 ps} diff --git a/common/rtl/ipcore/clkmgr_dcm_flist.txt b/common/rtl/ipcore/clkmgr_dcm_flist.txt new file mode 100644 index 0000000..bd1b2cd --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm_flist.txt @@ -0,0 +1,54 @@ +# Output products list for +_xmsgs\pn_parser.xmsgs +clkmgr_dcm.asy +clkmgr_dcm.gise +clkmgr_dcm.ucf +clkmgr_dcm.v +clkmgr_dcm.veo +clkmgr_dcm.xco +clkmgr_dcm.xdc +clkmgr_dcm.xise +clkmgr_dcm\clk_wiz_v3_6_readme.txt +clkmgr_dcm\doc\clk_wiz_v3_6_readme.txt +clkmgr_dcm\doc\clk_wiz_v3_6_vinfo.html +clkmgr_dcm\doc\pg065_clk_wiz.pdf +clkmgr_dcm\example_design\clkmgr_dcm_exdes.ucf +clkmgr_dcm\example_design\clkmgr_dcm_exdes.v +clkmgr_dcm\example_design\clkmgr_dcm_exdes.xdc +clkmgr_dcm\implement\implement.bat +clkmgr_dcm\implement\implement.sh +clkmgr_dcm\implement\planAhead_ise.bat +clkmgr_dcm\implement\planAhead_ise.sh +clkmgr_dcm\implement\planAhead_ise.tcl +clkmgr_dcm\implement\planAhead_rdn.bat +clkmgr_dcm\implement\planAhead_rdn.sh +clkmgr_dcm\implement\planAhead_rdn.tcl +clkmgr_dcm\implement\xst.prj +clkmgr_dcm\implement\xst.scr +clkmgr_dcm\simulation\clkmgr_dcm_tb.v +clkmgr_dcm\simulation\functional\simcmds.tcl +clkmgr_dcm\simulation\functional\simulate_isim.bat +clkmgr_dcm\simulation\functional\simulate_isim.sh +clkmgr_dcm\simulation\functional\simulate_mti.bat +clkmgr_dcm\simulation\functional\simulate_mti.do +clkmgr_dcm\simulation\functional\simulate_mti.sh +clkmgr_dcm\simulation\functional\simulate_ncsim.sh +clkmgr_dcm\simulation\functional\simulate_vcs.sh +clkmgr_dcm\simulation\functional\ucli_commands.key +clkmgr_dcm\simulation\functional\vcs_session.tcl +clkmgr_dcm\simulation\functional\wave.do +clkmgr_dcm\simulation\functional\wave.sv +clkmgr_dcm\simulation\timing\clkmgr_dcm_tb.v +clkmgr_dcm\simulation\timing\sdf_cmd_file +clkmgr_dcm\simulation\timing\simcmds.tcl +clkmgr_dcm\simulation\timing\simulate_isim.sh +clkmgr_dcm\simulation\timing\simulate_mti.bat +clkmgr_dcm\simulation\timing\simulate_mti.do +clkmgr_dcm\simulation\timing\simulate_mti.sh +clkmgr_dcm\simulation\timing\simulate_ncsim.sh +clkmgr_dcm\simulation\timing\simulate_vcs.sh +clkmgr_dcm\simulation\timing\ucli_commands.key +clkmgr_dcm\simulation\timing\vcs_session.tcl +clkmgr_dcm\simulation\timing\wave.do +clkmgr_dcm_flist.txt +clkmgr_dcm_xmdf.tcl diff --git a/common/rtl/ipcore/clkmgr_dcm_xmdf.tcl b/common/rtl/ipcore/clkmgr_dcm_xmdf.tcl new file mode 100644 index 0000000..307029b --- /dev/null +++ b/common/rtl/ipcore/clkmgr_dcm_xmdf.tcl @@ -0,0 +1,140 @@ +# The package naming convention is _xmdf +package provide clkmgr_dcm_xmdf 1.0 + +# This includes some utilities that support common XMDF operations +package require utilities_xmdf + +# Define a namespace for this package. The name of the name space +# is _xmdf +namespace eval ::clkmgr_dcm_xmdf { +# Use this to define any statics +} + +# Function called by client to rebuild the params and port arrays +# Optional when the use context does not require the param or ports +# arrays to be available. +proc ::clkmgr_dcm_xmdf::xmdfInit { instance } { +# Variable containg name of library into which module is compiled +# Recommendation: +# Required +utilities_xmdf::xmdfSetData $instance Module Attributes Name clkmgr_dcm +} +# ::clkmgr_dcm_xmdf::xmdfInit + +# Function called by client to fill in all the xmdf* data variables +# based on the current settings of the parameters +proc ::clkmgr_dcm_xmdf::xmdfApplyParams { instance } { + +set fcount 0 +# Array containing libraries that are assumed to exist +# Examples include unisim and xilinxcorelib +# Optional +# In this example, we assume that the unisim library will +# be magically +# available to the simulation and synthesis tool +utilities_xmdf::xmdfSetData $instance FileSet $fcount type logical_library +utilities_xmdf::xmdfSetData $instance FileSet $fcount logical_library unisim +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/clk_wiz_readme.txt +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/doc/clk_wiz_ds709.pdf +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/doc/clk_wiz_gsg521.pdf +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/implement/implement.bat +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/implement/implement.sh +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/implement/xst.prj +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/implement/xst.scr +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/simulation/clkmgr_dcm_tb.v +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/simulation/functional/simcmds.tcl +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/simulation/functional/simulate_isim.sh +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/simulation/functional/simulate_mti.do +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/simulation/functional/simulate_ncsim.sh +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/simulation/functional/simulate_vcs.sh +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/simulation/functional/ucli_commands.key +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/simulation/functional/vcs_session.tcl +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/simulation/functional/wave.do +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm/simulation/functional/wave.sv +utilities_xmdf::xmdfSetData $instance FileSet $fcount type Ignore +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm.asy +utilities_xmdf::xmdfSetData $instance FileSet $fcount type asy +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm.ejp +utilities_xmdf::xmdfSetData $instance FileSet $fcount type AnyView +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm.ucf +utilities_xmdf::xmdfSetData $instance FileSet $fcount type ucf +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm.v +utilities_xmdf::xmdfSetData $instance FileSet $fcount type verilog +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm.veo +utilities_xmdf::xmdfSetData $instance FileSet $fcount type verilog_template +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm.xco +utilities_xmdf::xmdfSetData $instance FileSet $fcount type coregen_ip +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount relative_path clkmgr_dcm_xmdf.tcl +utilities_xmdf::xmdfSetData $instance FileSet $fcount type AnyView +incr fcount + +utilities_xmdf::xmdfSetData $instance FileSet $fcount associated_module clkmgr_dcm +incr fcount + +} + +# ::gen_comp_name_xmdf::xmdfApplyParams diff --git a/common/rtl/ipcore/coregen.cgp b/common/rtl/ipcore/coregen.cgp new file mode 100644 index 0000000..8bc2e70 --- /dev/null +++ b/common/rtl/ipcore/coregen.cgp @@ -0,0 +1,9 @@ +SET busformat = BusFormatAngleBracketNotRipped +SET designentry = Verilog +SET device = xc6slx45 +SET devicefamily = spartan6 +SET flowvendor = Other +SET package = csg324 +SET speedgrade = -3 +SET verilogsim = true +SET vhdlsim = false diff --git a/common/rtl/ipcore/create_clkmgr_dcm.tcl b/common/rtl/ipcore/create_clkmgr_dcm.tcl new file mode 100644 index 0000000..fec8dec --- /dev/null +++ b/common/rtl/ipcore/create_clkmgr_dcm.tcl @@ -0,0 +1,37 @@ +## +## Core Generator Run Script, generator for Project Navigator create command +## + +proc findRtfPath { relativePath } { + set xilenv "" + if { [info exists ::env(XILINX) ] } { + if { [info exists ::env(MYXILINX)] } { + set xilenv [join [list $::env(MYXILINX) $::env(XILINX)] $::xilinx::path_sep ] + } else { + set xilenv $::env(XILINX) + } + } + foreach path [ split $xilenv $::xilinx::path_sep ] { + set fullPath [ file join $path $relativePath ] + if { [ file exists $fullPath ] } { + return $fullPath + } + } + return "" +} + +source [ findRtfPath "data/projnav/scripts/dpm_cgUtils.tcl" ] + +set result [ run_cg_create "xilinx.com:ip:clk_wiz:3.6" "clkmgr_dcm" "Clocking Wizard" "Clocking Wizard (xilinx.com:ip:clk_wiz:3.6) generated by Project Navigator" xc6slx45-3csg324 Verilog ] + +if { $result == 0 } { + puts "Core Generator create command completed successfully." +} elseif { $result == 1 } { + puts "Core Generator create command failed." +} elseif { $result == 3 || $result == 4 } { + # convert 'version check' result to real return range, bypassing any messages. + set result [ expr $result - 3 ] +} else { + puts "Core Generator create cancelled." +} +exit $result diff --git a/common/rtl/ipcore/edit_clkmgr_dcm.tcl b/common/rtl/ipcore/edit_clkmgr_dcm.tcl new file mode 100644 index 0000000..4992eb1 --- /dev/null +++ b/common/rtl/ipcore/edit_clkmgr_dcm.tcl @@ -0,0 +1,37 @@ +## +## Core Generator Run Script, generator for Project Navigator edit command +## + +proc findRtfPath { relativePath } { + set xilenv "" + if { [info exists ::env(XILINX) ] } { + if { [info exists ::env(MYXILINX)] } { + set xilenv [join [list $::env(MYXILINX) $::env(XILINX)] $::xilinx::path_sep ] + } else { + set xilenv $::env(XILINX) + } + } + foreach path [ split $xilenv $::xilinx::path_sep ] { + set fullPath [ file join $path $relativePath ] + if { [ file exists $fullPath ] } { + return $fullPath + } + } + return "" +} + +source [ findRtfPath "data/projnav/scripts/dpm_cgUtils.tcl" ] + +set result [ run_cg_edit "clkmgr_dcm" xc6slx45-3csg324 Verilog ] + +if { $result == 0 } { + puts "Core Generator edit command completed successfully." +} elseif { $result == 1 } { + puts "Core Generator edit command failed." +} elseif { $result == 3 || $result == 4 } { + # convert 'version check' result to real return range, bypassing any messages. + set result [ expr $result - 3 ] +} else { + puts "Core Generator edit cancelled." +} +exit $result diff --git a/common/rtl/novena_clkmgr.v b/common/rtl/novena_clkmgr.v new file mode 100644 index 0000000..97db451 --- /dev/null +++ b/common/rtl/novena_clkmgr.v @@ -0,0 +1,130 @@ +//====================================================================== +// +// novena_clkmgr.v +// --------------- +// Clock and reset implementation for the Cryptech Novena +// FPGA framework. +// +// +// Author: Pavel Shatov +// Copyright (c) 2015, NORDUnet A/S All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// - Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// - Neither the name of the NORDUnet nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//====================================================================== + +module novena_clkmgr + ( + input wire gclk_p, // signal from clock pins + input wire gclk_n, // + + input wire reset_mcu_b, // cpu reset (async) + + output wire sys_clk, // buffered system clock output + output wire sys_rst // system reset output (sync) + ); + + // + // Ports + // + + + // + // IBUFGDS + // + (* BUFFER_TYPE="NONE" *) + wire gclk; + + IBUFGDS IBUFGDS_gclk + ( + .I(gclk_p), + .IB(gclk_n), + .O(gclk) + ); + + + // + // DCM + // + wire dcm_reset; // dcm reset + wire dcm_locked; // output clock valid + wire gclk_missing; // no input clock + + clkmgr_dcm dcm + ( + .CLK_IN1(gclk), + .RESET(dcm_reset), + .INPUT_CLK_STOPPED(gclk_missing), + + .CLK_OUT1(sys_clk), + .CLK_VALID(dcm_locked) + ); + + + // + // DCM Reset Logic + // + + /* DCM should be reset on power-up, when input clock is stopped or when the + * CPU gets reset. + */ + + reg [15: 0] dcm_rst_shreg = {16{1'b1}}; // 16-bit shift register + + always @(posedge gclk or negedge reset_mcu_b or posedge gclk_missing) + // + if ((reset_mcu_b == 1'b0) || (gclk_missing == 1'b1)) + dcm_rst_shreg <= {16{1'b1}}; + else + dcm_rst_shreg <= {dcm_rst_shreg[14:0], 1'b0}; + + assign dcm_reset = dcm_rst_shreg[15]; + + + // + // System Reset Logic + // + + /* System reset is asserted for 16 cycles whenever DCM aquires lock. */ + + reg [15: 0] sys_rst_shreg = {16{1'b1}}; // 16-bit shift register + + always @(posedge sys_clk or negedge reset_mcu_b or posedge gclk_missing or negedge dcm_locked) + // + if ((reset_mcu_b == 1'b0) || (gclk_missing == 1'b1) || (dcm_locked == 1'b0)) + sys_rst_shreg <= {16{1'b1}}; + else if (dcm_locked == 1'b1) + sys_rst_shreg <= {sys_rst_shreg[14:0], 1'b0}; + + assign sys_rst = sys_rst_shreg[15]; + + +endmodule + +//====================================================================== +// EOF novena_clkmgr.v +//====================================================================== diff --git a/eim/build/.gitignore b/eim/build/.gitignore new file mode 100644 index 0000000..01d7e9c --- /dev/null +++ b/eim/build/.gitignore @@ -0,0 +1,52 @@ +*.xrpt +_xmsgs +default.xreport +netlist.lst +*.bgn +*.bit +*.bld +*.cfi +*.drc +*.lso +*.lso +*.map +*.mcs +*.mrp +*.ncd +*.ngc +*.ngd +*.ngm +*.pcf +*.post_map.twr +*.post_map.twx +*.prj +*.prm +*.psr +*.scr +*.srp +*.twr +*.twx +*_bd.bmm +*_bitgen.xwb +*_bitgen.xwbt +*_err.twr +*_err.twx +*_par.grf +*_par.ncd +*_par.pad +*_par.par +*_par.ptwx +*_par.unroutes +*_par.xpi +*_par_pad.csv +*_par_pad.txt +*_summary.xml +*_usage.xml +par_usage_statistics.html +smartguide.ncd +smartpreview.twr +smartpreview.twr +usage_statistics_webtalk.html +webtalk.log +xlnx_auto* +xst diff --git a/eim/build/Makefile b/eim/build/Makefile new file mode 100644 index 0000000..c89d4ec --- /dev/null +++ b/eim/build/Makefile @@ -0,0 +1,40 @@ +project = novena_eim +vendor = xilinx +family = spartan6 +part = xc6slx45csg324-3 +top_module = novena_top +isedir = /opt/Xilinx/14.7/ISE_DS +xil_env = . $(isedir)/settings64.sh +ucf = ../ucf/novena_eim.ucf + +vfiles = \ + ../rtl/novena_eim.v \ + ../rtl/novena_regs.v \ + ../../common/rtl/novena_clkmgr.v \ + ../../common/rtl/ipcore/clkmgr_dcm.v \ + ../../../common/core_selector/src/rtl/core_selector.v \ + ../../../common/core_selector/src/rtl/global_selector.v \ + ../../../common/core_selector/src/rtl/cipher_selector.v \ + ../../../common/core_selector/src/rtl/hash_selector.v \ + ../../../common/core_selector/src/rtl/rng_selector.v \ + ../../../../comm/eim/src/rtl/cdc_bus_pulse.v \ + ../../../../comm/eim/src/rtl/eim_arbiter_cdc.v \ + ../../../../comm/eim/src/rtl/eim_arbiter.v \ + ../../../../comm/eim/src/rtl/eim_da_phy.v \ + ../../../../comm/eim/src/rtl/eim_indicator.v \ + ../../../../comm/eim/src/rtl/eim_regs.v \ + ../../../../comm/eim/src/rtl/eim.v \ + ../../../../hash/sha1/src/rtl/sha1.v \ + ../../../../hash/sha1/src/rtl/sha1_core.v \ + ../../../../hash/sha1/src/rtl/sha1_w_mem.v \ + ../../../../hash/sha256/src/rtl/sha256.v \ + ../../../../hash/sha256/src/rtl/sha256_core.v \ + ../../../../hash/sha256/src/rtl/sha256_k_constants.v \ + ../../../../hash/sha256/src/rtl/sha256_w_mem.v \ + ../../../../hash/sha512/src/rtl/sha512.v \ + ../../../../hash/sha512/src/rtl/sha512_core.v \ + ../../../../hash/sha512/src/rtl/sha512_h_constants.v \ + ../../../../hash/sha512/src/rtl/sha512_k_constants.v \ + ../../../../hash/sha512/src/rtl/sha512_w_mem.v + +include xilinx.mk diff --git a/eim/build/xilinx.mk b/eim/build/xilinx.mk new file mode 100644 index 0000000..f35cc98 --- /dev/null +++ b/eim/build/xilinx.mk @@ -0,0 +1,174 @@ +# The top level module should define the variables below then include +# this file. The files listed should be in the same directory as the +# Makefile. +# +# variable description +# ---------- ------------- +# project project name (top level module should match this name) +# top_module top level module of the project +# libdir path to library directory +# libs library modules used +# vfiles all local .v files +# xilinx_cores all local .xco files +# vendor vendor of FPGA (xilinx, altera, etc.) +# family FPGA device family (spartan3e) +# part FPGA part name (xc4vfx12-10-sf363) +# flashsize size of flash for mcs file (16384) +# optfile (optional) xst extra opttions file to put in .scr +# map_opts (optional) options to give to map +# par_opts (optional) options to give to par +# intstyle (optional) intstyle option to all tools +# ucf constraint file, defaults to $(project).ucf +# +# Library modules should have a modules.mk in their root directory, +# namely $(libdir)//module.mk, that simply adds to the vfiles +# and xilinx_cores variable. +# +# all the .xco files listed in xilinx_cores will be generated with core, with +# the resulting .v and .ngc files placed back in the same directory as +# the .xco file. +# +# TODO: .xco files are device dependant, should use a template based system + +coregen_work_dir ?= ./coregen-tmp +map_opts ?= -timing -ol high -detail -pr b -register_duplication -w +par_opts ?= -ol high +isedir ?= /opt/Xilinx/13.3/ISE_DS +xil_env ?= . $(isedir)/settings32.sh +flashsize ?= 8192 +ucf ?= $(project).ucf + +libmks = $(patsubst %,$(libdir)/%/module.mk,$(libs)) +mkfiles = $(libmks) xilinx.mk +include $(libmks) + +corengcs = $(foreach core,$(xilinx_cores),$(core:.xco=.ngc)) +local_corengcs = $(foreach ngc,$(corengcs),$(notdir $(ngc))) +vfiles += $(foreach core,$(xilinx_cores),$(core:.xco=.v)) +junk += $(local_corengcs) + +.PHONY: default xilinx_cores clean twr etwr +default: $(project).bit $(project).mcs +xilinx_cores: $(corengcs) +twr: $(project).twr +etwr: $(project)_err.twr + +define cp_template +$(2): $(1) + cp $(1) $(2) +endef +$(foreach ngc,$(corengcs),$(eval $(call cp_template,$(ngc),$(notdir $(ngc))))) + +%.ngc %.v: %.xco + @echo "=== rebuilding $@" + if [ -d $(coregen_work_dir) ]; then \ + rm -rf $(coregen_work_dir)/*; \ + else \ + mkdir -p $(coregen_work_dir); \ + fi + cd $(coregen_work_dir); \ + $(xil_env); \ + coregen -b $$OLDPWD/$<; \ + cd - + xcodir=`dirname $<`; \ + basename=`basename $< .xco`; \ + if [ ! -r $(coregen_work_dir/$$basename.ngc) ]; then \ + echo "'$@' wasn't created."; \ + exit 1; \ + else \ + cp $(coregen_work_dir)/$$basename.v $(coregen_work_dir)/$$basename.ngc $$xcodir; \ + fi +junk += $(coregen_work_dir) + +date = $(shell date +%F-%H-%M) + +# some common junk +junk += *.xrpt + +programming_files: $(project).bit $(project).mcs + mkdir -p $@/$(date) + mkdir -p $@/latest + for x in .bit .mcs .cfi _bd.bmm; do cp $(project)$$x $@/$(date)/$(project)$$x; cp $(project)$$x $@/latest/$(project)$$x; done + $(xil_env); xst -help | head -1 | sed 's/^/#/' | cat - $(project).scr > $@/$(date)/$(project).scr + +$(project).mcs: $(project).bit + $(xil_env); \ + promgen -w -s $(flashsize) -p mcs -o $@ -u 0 $^ +junk += $(project).mcs $(project).cfi $(project).prm + +$(project).bit: $(project)_par.ncd + $(xil_env); \ + bitgen $(intstyle) -g UnusedPin:Pullnone -g DriveDone:yes -g StartupClk:Cclk -w $(project)_par.ncd $(project).bit +junk += $(project).bgn $(project).bit $(project).drc $(project)_bd.bmm + + +$(project)_par.ncd: $(project).ncd + $(xil_env); \ + if par $(intstyle) $(par_opts) -w $(project).ncd $(project)_par.ncd; then \ + :; \ + else \ + $(MAKE) etwr; \ + fi +junk += $(project)_par.ncd $(project)_par.par $(project)_par.pad +junk += $(project)_par_pad.csv $(project)_par_pad.txt +junk += $(project)_par.grf $(project)_par.ptwx +junk += $(project)_par.unroutes $(project)_par.xpi + +$(project).ncd: $(project).ngd + if [ -r $(project)_par.ncd ]; then \ + cp $(project)_par.ncd smartguide.ncd; \ + smartguide="-smartguide smartguide.ncd"; \ + else \ + smartguide=""; \ + fi; \ + $(xil_env); \ + map $(intstyle) $(map_opts) $$smartguide $< +junk += $(project).ncd $(project).pcf $(project).ngm $(project).mrp $(project).map +junk += smartguide.ncd $(project).psr +junk += $(project)_summary.xml $(project)_usage.xml + +$(project).ngd: $(project).ngc $(ucf) + $(xil_env); ngdbuild $(intstyle) $(project).ngc -uc $(ucf) +junk += $(project).ngd $(project).bld + +$(project).ngc: $(vfiles) $(local_corengcs) $(project).scr $(project).prj + $(xil_env); xst $(intstyle) -ifn $(project).scr +junk += xlnx_auto* $(top_module).lso $(project).srp +junk += netlist.lst xst $(project).ngc + +$(project).prj: $(vfiles) $(mkfiles) + for src in $(vfiles); do echo "verilog work $$src" >> $(project).tmpprj; done + sort -u $(project).tmpprj > $(project).prj + rm -f $(project).tmpprj +junk += $(project).prj + +optfile += $(wildcard $(project).opt) +top_module ?= $(project) +$(project).scr: $(optfile) $(mkfiles) ./xilinx.opt + echo "run" > $@ + echo "-p $(part)" >> $@ + echo "-top $(top_module)" >> $@ + echo "-ifn $(project).prj" >> $@ + echo "-ofn $(project).ngc" >> $@ + cat ./xilinx.opt $(optfile) >> $@ +junk += $(project).scr + +$(project).post_map.twr: $(project).ncd + $(xil_env); trce -e 10 $< $(project).pcf -o $@ +junk += $(project).post_map.twr $(project).post_map.twx smartpreview.twr + +$(project).twr: $(project)_par.ncd + $(xil_env); trce $< $(project).pcf -o $(project).twr +junk += $(project).twr $(project).twx smartpreview.twr + +$(project)_err.twr: $(project)_par.ncd + $(xil_env); trce -e 10 $< $(project).pcf -o $(project)_err.twr +junk += $(project)_err.twr $(project)_err.twx +junk += $(project).lso $(project)_bitgen.xwb $(project)_bitgen.xwbt +junk += usage_statistics_webtalk.html par_usage_statistics.html webtalk.log _xmsgs default.xreport + +.gitignore: $(mkfiles) + echo programming_files $(junk) | sed 's, ,\n,g' > .gitignore + +clean:: + rm -rf $(junk) diff --git a/eim/build/xilinx.opt b/eim/build/xilinx.opt new file mode 100644 index 0000000..7fe9d8b --- /dev/null +++ b/eim/build/xilinx.opt @@ -0,0 +1,42 @@ +-ifmt mixed +-ofmt NGC +-opt_mode speed +-opt_level 1 +-iuc NO +-keep_hierarchy no +-netlist_hierarchy as_optimized +-rtlview no +-glob_opt AllClockNets +-read_cores yes +-write_timing_constraints NO +-cross_clock_analysis NO +-hierarchy_separator / +-bus_delimiter <> +-case maintain +-slice_utilization_ratio 100 +-bram_utilization_ratio 100 +#-dsp_utilization_ratio 100 +-safe_implementation No +-fsm_extract YES +-fsm_encoding Auto +-fsm_style lut +-ram_extract Yes +-ram_style Auto +-rom_extract Yes +-rom_style Auto +-shreg_extract YES +-auto_bram_packing NO +-resource_sharing YES +-async_to_sync NO +#-use_dsp48 auto +-iobuf YES +-max_fanout 500 +-register_duplication YES +-register_balancing No +-optimize_primitives NO +-use_clock_enable Auto +-use_sync_set Auto +-use_sync_reset Auto +-iob auto +-equivalent_register_removal YES +-slice_utilization_ratio_maxmargin 5 diff --git a/eim/iseconfig/.gitignore b/eim/iseconfig/.gitignore new file mode 100644 index 0000000..91e8e2b --- /dev/null +++ b/eim/iseconfig/.gitignore @@ -0,0 +1,48 @@ +iseconfig +_ngo +*.bgn +*_bitgen.xwbt +*.bld +*.cmd_log +*.drc +*_envsettings.html +*_guide.ncd +*.lso +*_map.map +*_map.mrp +*_map.ncd +*_map.ngm +*_map.xrpt +*.ncd +*.ngc +*.ngd +*_ngdbuild.xrpt +*.ngr +*.pad +*_pad.csv +*_pad.txt +*.par +*_par.xrpt +*.pcf +*.prj +*.ptwx +*.stx +*_summary.html +*_summary.xml +*.syr +*.twr +*.twx +*.unroutes +*_usage.xml +*.ut +*.xpi +*.xst +*_xst.xrpt +*.gise +par_usage_statistics.html +usage_statistics_webtalk.html +webtalk.log +webtalk_pn.xml +xlnx_auto_0_xdb +_xmsgs +xst diff --git a/eim/iseconfig/novena_eim.xise b/eim/iseconfig/novena_eim.xise new file mode 100644 index 0000000..0633e22 --- /dev/null +++ b/eim/iseconfig/novena_eim.xise @@ -0,0 +1,475 @@ + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/eim/rtl/novena_eim.v b/eim/rtl/novena_eim.v new file mode 100644 index 0000000..fbff86c --- /dev/null +++ b/eim/rtl/novena_eim.v @@ -0,0 +1,182 @@ +//====================================================================== +// +// novena_top.v +// ------------ +// Top module for the Cryptech Novena FPGA framework. This design +// allow us to run the EIM interface at one clock and cores including +// core selector with the always present global clock. +// +// +// Author: Pavel Shatov +// Copyright (c) 2015, NORDUnet A/S All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// - Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// - Neither the name of the NORDUnet nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//====================================================================== + +module novena_top + ( + // Differential input for 50 MHz general clock. + input wire gclk_p_pin, + input wire gclk_n_pin, + + // Reset controlled by the CPU. + // this must be configured as input w/pullup + input wire reset_mcu_b_pin, + + // Cryptech avalanche noise board input and LED outputs + input wire ct_noise, + output wire [7 : 0] ct_led, + + // EIM interface + input wire eim_bclk, // EIM burst clock. Started by the CPU. + input wire eim_cs0_n, // Chip select (active low). + inout wire [15 : 0] eim_da, // Bidirectional address and data port. + input wire [18: 16] eim_a, // MSB part of address port. + input wire eim_lba_n, // Latch address signal (active low). + input wire eim_wr_n, // write enable signal (active low). + input wire eim_oe_n, // output enable signal (active low). + output wire eim_wait_n, // Data wait signal (active low). + + // Novena utility ports + output wire apoptosis_pin, // Hold low to not restart after config. + output wire led_pin // LED on edge close to the FPGA. + ); + + + //---------------------------------------------------------------- + // Clock Manager + // + // Clock manager is used to generate SYS_CLK from GCLK + // and implement the reset logic. + // ---------------------------------------------------------------- + wire sys_clk; + wire sys_rst; + wire eim_bclk_buf; + + novena_clkmgr clkmgr + ( + .gclk_p(gclk_p_pin), + .gclk_n(gclk_n_pin), + + .reset_mcu_b(reset_mcu_b_pin), + + .sys_clk(sys_clk), + .sys_rst(sys_rst) + ); + + + // + // BCLK BUFG + // + BUFG BUFG_BCLK + ( + .I(eim_bclk), + .O(eim_bclk_buf) + ); + + + //---------------------------------------------------------------- + // EIM Interface + // + // EIM subsystem handles all data transfer to/from CPU via EIM bus. + //---------------------------------------------------------------- + wire [16: 0] sys_eim_addr; + wire sys_eim_wr; + wire sys_eim_rd; + wire [31: 0] sys_eim_dout; + wire [31: 0] sys_eim_din; + + eim eim + ( + .eim_bclk(eim_bclk_buf), + .eim_cs0_n(eim_cs0_n), + .eim_da(eim_da), + .eim_a(eim_a), + .eim_lba_n(eim_lba_n), + .eim_wr_n(eim_wr_n), + .eim_oe_n(eim_oe_n), + .eim_wait_n(eim_wait_n), + + .sys_clk(sys_clk), + .sys_rst(sys_rst), + + .sys_eim_addr(sys_eim_addr), + .sys_eim_wr(sys_eim_wr), + .sys_eim_rd(sys_eim_rd), + .sys_eim_dout(sys_eim_dout), + .sys_eim_din(sys_eim_din), + + .led_pin(led_pin) + ); + + + //---------------------------------------------------------------- + // Core Selector + // + // This multiplexer is used to map different types of cores, such as + // hashes, RNGs and ciphers to different regions (segments) of memory. + //---------------------------------------------------------------- + core_selector cores + ( + .sys_clk(sys_clk), + .sys_rst(sys_rst), + + .sys_eim_addr(sys_eim_addr), + .sys_eim_wr(sys_eim_wr), + .sys_eim_rd(sys_eim_rd), + + .sys_write_data(sys_eim_dout), + .sys_read_data(sys_eim_din) + ); + + + //---------------------------------------------------------------- + // Cryptech Logic + // + // Logic specific to the Cryptech use of the Novena. + // Currently we just hard wire the LED outputs. + //---------------------------------------------------------------- + assign ct_led = {8{ct_noise}}; + + + //---------------------------------------------------------------- + // Novena Patch + // + // Patch logic to keep the Novena board happy. + // The apoptosis_pin pin must be kept low or the whole board + // (more exactly the CPU) will be reset after the FPGA has + // been configured. + //---------------------------------------------------------------- + assign apoptosis_pin = 1'b0; + + +endmodule + +//====================================================================== +// EOF novena_top.v +//====================================================================== diff --git a/eim/rtl/novena_regs.v b/eim/rtl/novena_regs.v new file mode 100644 index 0000000..f14e113 --- /dev/null +++ b/eim/rtl/novena_regs.v @@ -0,0 +1,129 @@ +//====================================================================== +// +// novena_regs.v +// ------------- +// Global registers for the Cryptech Novena FPGA framework. +// +// +// Author: Pavel Shatov +// Copyright (c) 2015, NORDUnet A/S All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// - Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// - Neither the name of the NORDUnet nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//====================================================================== + +`timescale 1ns / 1ps + +module board_regs + ( + input wire clk, + input wire rst, + + input wire cs, + input wire we, + + input wire [ 7 : 0] address, + input wire [31 : 0] write_data, + output wire [31 : 0] read_data + ); + + + //---------------------------------------------------------------- + // Internal constant and parameter definitions. + //---------------------------------------------------------------- + // API addresses. + localparam ADDR_CORE_NAME0 = 8'h00; + localparam ADDR_CORE_NAME1 = 8'h01; + localparam ADDR_CORE_VERSION = 8'h02; + localparam ADDR_DUMMY_REG = 8'hFF; // general-purpose register + + // Core ID constants. + localparam CORE_NAME0 = 32'h50565431; // "PVT1" + localparam CORE_NAME1 = 32'h20202020; // " " + localparam CORE_VERSION = 32'h302e3130; // "0.10" + + + //---------------------------------------------------------------- + // Wires. + //---------------------------------------------------------------- + reg [31: 0] tmp_read_data; + + // dummy register to check that you can actually write something + reg [31: 0] reg_dummy; + + + //---------------------------------------------------------------- + // Concurrent connectivity for ports etc. + //---------------------------------------------------------------- + assign read_data = tmp_read_data; + + + //---------------------------------------------------------------- + // Access Handler + //---------------------------------------------------------------- + always @(posedge clk) + // + if (rst) + reg_dummy <= {32{1'b0}}; + else if (cs) begin + // + if (we) begin + // + // WRITE handler + // + case (address) + ADDR_DUMMY_REG: + reg_dummy <= write_data; + endcase + // + end else begin + // + // READ handler + // + case (address) + ADDR_CORE_NAME0: + tmp_read_data <= CORE_NAME0; + ADDR_CORE_NAME1: + tmp_read_data <= CORE_NAME1; + ADDR_CORE_VERSION: + tmp_read_data <= CORE_VERSION; + ADDR_DUMMY_REG: + tmp_read_data <= reg_dummy; + // + default: + tmp_read_data <= {32{1'b0}}; // read non-existent locations as zeroes + endcase + // + end + // + end + +endmodule + +//====================================================================== +// EOF novena_regs.v +//====================================================================== diff --git a/eim/sw/Makefile b/eim/sw/Makefile new file mode 100755 index 0000000..9d28af7 --- /dev/null +++ b/eim/sw/Makefile @@ -0,0 +1,14 @@ +all: hash_tester_eim + +.c.o: + gcc -c -Wall -o $@ $< + +hash_tester_eim: hash_tester_eim.o novena-eim.o + gcc -o $@ $^ + +hash_tester_eim.o: hash_tester_eim.c novena-eim.h + +novena-eim.o: novena-eim.c novena-eim.h + +clean: + rm -f *.o hash_tester_eim diff --git a/eim/sw/hash_tester_eim.c b/eim/sw/hash_tester_eim.c new file mode 100644 index 0000000..74685ee --- /dev/null +++ b/eim/sw/hash_tester_eim.c @@ -0,0 +1,884 @@ +/* + * hash_tester.c + * -------------- + * This program sends several commands to the coretest_hashes subsystem + * in order to verify the SHA-1, SHA-256 and SHA-512/x hash function + * cores. + * + * Note: This version of the program talks to the FPGA over an EIM bus. + * + * The single and dual block test cases are taken from the + * NIST KAT document: + * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA_All.pdf + * + * + * Authors: Joachim Strömbergson, Paul Selkirk + * Copyright (c) 2014-2015, NORDUnet A/S All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of the NORDUnet nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "novena-eim.h" + +int debug = 0; +int quiet = 0; +int repeat = 0; + +#define SEGMENT_OFFSET_GLOBALS EIM_BASE_ADDR + 0x000000 +#define SEGMENT_OFFSET_HASHES EIM_BASE_ADDR + 0x010000 +#define SEGMENT_OFFSET_RNGS EIM_BASE_ADDR + 0x020000 +#define SEGMENT_OFFSET_CIPHERS EIM_BASE_ADDR + 0x030000 + +/* addresses and codes common to all cores */ +#define ADDR_NAME0 (0x0 << 2) +#define ADDR_NAME1 (0x1 << 2) +#define ADDR_VERSION (0x2 << 2) + +/* At segment 0, we have board-level register and communication channel registers */ +#define BOARD_ADDR_BASE SEGMENT_OFFSET_GLOBALS + 0x0000 +#define BOARD_ADDR_NAME0 BOARD_ADDR_BASE + ADDR_NAME0 +#define BOARD_ADDR_NAME1 BOARD_ADDR_BASE + ADDR_NAME1 +#define BOARD_ADDR_VERSION BOARD_ADDR_BASE + ADDR_VERSION +#define BOARD_ADDR_DUMMY BOARD_ADDR_BASE + (0xFF << 2) + +#define COMM_ADDR_BASE SEGMENT_OFFSET_GLOBALS + 0x0400 +#define COMM_ADDR_NAME0 COMM_ADDR_BASE + ADDR_NAME0 +#define COMM_ADDR_NAME1 COMM_ADDR_BASE + ADDR_NAME1 +#define COMM_ADDR_VERSION COMM_ADDR_BASE + ADDR_VERSION + +/* addresses and codes common to all hash cores */ +#define ADDR_CTRL (0x8 << 2) +#define CTRL_INIT_CMD 1 +#define CTRL_NEXT_CMD 2 +#define ADDR_STATUS (9 << 2) +#define STATUS_READY_BIT 1 +#define STATUS_VALID_BIT 2 +#define ADDR_BLOCK (0x10 << 2) +#define ADDR_DIGEST (0x20 << 2) + +#define HASH_CORE_SIZE (0x100 << 2) + +/* addresses and codes for the specific hash cores */ +#define SHA1_ADDR_BASE SEGMENT_OFFSET_HASHES + (0*HASH_CORE_SIZE) +#define SHA1_ADDR_NAME0 SHA1_ADDR_BASE + ADDR_NAME0 +#define SHA1_ADDR_NAME1 SHA1_ADDR_BASE + ADDR_NAME1 +#define SHA1_ADDR_VERSION SHA1_ADDR_BASE + ADDR_VERSION +#define SHA1_ADDR_CTRL SHA1_ADDR_BASE + ADDR_CTRL +#define SHA1_ADDR_STATUS SHA1_ADDR_BASE + ADDR_STATUS +#define SHA1_ADDR_BLOCK SHA1_ADDR_BASE + ADDR_BLOCK +#define SHA1_ADDR_DIGEST SHA1_ADDR_BASE + ADDR_DIGEST +#define SHA1_BLOCK_LEN 512 / 8 +#define SHA1_DIGEST_LEN 160 / 8 + +#define SHA256_ADDR_BASE SEGMENT_OFFSET_HASHES + (1*HASH_CORE_SIZE) +#define SHA256_ADDR_NAME0 SHA256_ADDR_BASE + ADDR_NAME0 +#define SHA256_ADDR_NAME1 SHA256_ADDR_BASE + ADDR_NAME1 +#define SHA256_ADDR_VERSION SHA256_ADDR_BASE + ADDR_VERSION +#define SHA256_ADDR_CTRL SHA256_ADDR_BASE + ADDR_CTRL +#define SHA256_ADDR_STATUS SHA256_ADDR_BASE + ADDR_STATUS +#define SHA256_ADDR_BLOCK SHA256_ADDR_BASE + ADDR_BLOCK +#define SHA256_ADDR_DIGEST SHA256_ADDR_BASE + ADDR_DIGEST +#define SHA256_BLOCK_LEN 512 / 8 +#define SHA256_DIGEST_LEN 256 / 8 + +#define SHA512_ADDR_BASE SEGMENT_OFFSET_HASHES + (2*HASH_CORE_SIZE) +#define SHA512_ADDR_NAME0 SHA512_ADDR_BASE + ADDR_NAME0 +#define SHA512_ADDR_NAME1 SHA512_ADDR_BASE + ADDR_NAME1 +#define SHA512_ADDR_VERSION SHA512_ADDR_BASE + ADDR_VERSION +#define SHA512_ADDR_CTRL SHA512_ADDR_BASE + ADDR_CTRL +#define SHA512_ADDR_STATUS SHA512_ADDR_BASE + ADDR_STATUS +#define SHA512_ADDR_BLOCK SHA512_ADDR_BASE + ADDR_BLOCK +#define SHA512_ADDR_DIGEST SHA512_ADDR_BASE + 0x100 +#define SHA512_BLOCK_LEN 1024 / 8 +#define SHA512_224_DIGEST_LEN 224 / 8 +#define SHA512_256_DIGEST_LEN 256 / 8 +#define SHA384_DIGEST_LEN 384 / 8 +#define SHA512_DIGEST_LEN 512 / 8 +#define MODE_SHA_512_224 0 << 2 +#define MODE_SHA_512_256 1 << 2 +#define MODE_SHA_384 2 << 2 +#define MODE_SHA_512 3 << 2 + +/* SHA-1/SHA-256 One Block Message Sample + Input Message: "abc" */ +const uint8_t NIST_512_SINGLE[] = +{ 0x61, 0x62, 0x63, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18 }; + +const uint8_t SHA1_SINGLE_DIGEST[] = +{ 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, + 0xba, 0x3e, 0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c, + 0x9c, 0xd0, 0xd8, 0x9d }; + +const uint8_t SHA256_SINGLE_DIGEST[] = +{ 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA, + 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23, + 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C, + 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD }; + +/* SHA-1/SHA-256 Two Block Message Sample + Input Message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" */ +const uint8_t NIST_512_DOUBLE0[] = +{ 0x61, 0x62, 0x63, 0x64, 0x62, 0x63, 0x64, 0x65, + 0x63, 0x64, 0x65, 0x66, 0x64, 0x65, 0x66, 0x67, + 0x65, 0x66, 0x67, 0x68, 0x66, 0x67, 0x68, 0x69, + 0x67, 0x68, 0x69, 0x6A, 0x68, 0x69, 0x6A, 0x6B, + 0x69, 0x6A, 0x6B, 0x6C, 0x6A, 0x6B, 0x6C, 0x6D, + 0x6B, 0x6C, 0x6D, 0x6E, 0x6C, 0x6D, 0x6E, 0x6F, + 0x6D, 0x6E, 0x6F, 0x70, 0x6E, 0x6F, 0x70, 0x71, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +const uint8_t NIST_512_DOUBLE1[] = +{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0 }; + +const uint8_t SHA1_DOUBLE_DIGEST[] = +{ 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, + 0xBA, 0xAE, 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, + 0xE5, 0x46, 0x70, 0xF1 }; + +const uint8_t SHA256_DOUBLE_DIGEST[] = +{ 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8, + 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39, + 0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67, + 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 }; + +/* SHA-512 One Block Message Sample + Input Message: "abc" */ +const uint8_t NIST_1024_SINGLE[] = +{ 0x61, 0x62, 0x63, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18 }; + +const uint8_t SHA512_224_SINGLE_DIGEST[] = +{ 0x46, 0x34, 0x27, 0x0f, 0x70, 0x7b, 0x6a, 0x54, + 0xda, 0xae, 0x75, 0x30, 0x46, 0x08, 0x42, 0xe2, + 0x0e, 0x37, 0xed, 0x26, 0x5c, 0xee, 0xe9, 0xa4, + 0x3e, 0x89, 0x24, 0xaa }; +const uint8_t SHA512_256_SINGLE_DIGEST[] = +{ 0x53, 0x04, 0x8e, 0x26, 0x81, 0x94, 0x1e, 0xf9, + 0x9b, 0x2e, 0x29, 0xb7, 0x6b, 0x4c, 0x7d, 0xab, + 0xe4, 0xc2, 0xd0, 0xc6, 0x34, 0xfc, 0x6d, 0x46, + 0xe0, 0xe2, 0xf1, 0x31, 0x07, 0xe7, 0xaf, 0x23 }; +const uint8_t SHA384_SINGLE_DIGEST[] = +{ 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, + 0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07, + 0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63, + 0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed, + 0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23, + 0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7 }; +const uint8_t SHA512_SINGLE_DIGEST[] = +{ 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba, + 0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31, + 0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2, + 0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a, + 0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8, + 0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd, + 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e, + 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f }; + +/* SHA-512 Two Block Message Sample + Input Message: "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" + "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" */ +const uint8_t NIST_1024_DOUBLE0[] = +{ 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, + 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, + 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, + 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, + 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, + 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, + 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, + 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, + 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +const uint8_t NIST_1024_DOUBLE1[] = +{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80 }; + +const uint8_t SHA512_224_DOUBLE_DIGEST[] = +{ 0x23, 0xfe, 0xc5, 0xbb, 0x94, 0xd6, 0x0b, 0x23, + 0x30, 0x81, 0x92, 0x64, 0x0b, 0x0c, 0x45, 0x33, + 0x35, 0xd6, 0x64, 0x73, 0x4f, 0xe4, 0x0e, 0x72, + 0x68, 0x67, 0x4a, 0xf9 }; +const uint8_t SHA512_256_DOUBLE_DIGEST[] = +{ 0x39, 0x28, 0xe1, 0x84, 0xfb, 0x86, 0x90, 0xf8, + 0x40, 0xda, 0x39, 0x88, 0x12, 0x1d, 0x31, 0xbe, + 0x65, 0xcb, 0x9d, 0x3e, 0xf8, 0x3e, 0xe6, 0x14, + 0x6f, 0xea, 0xc8, 0x61, 0xe1, 0x9b, 0x56, 0x3a }; +const uint8_t SHA384_DOUBLE_DIGEST[] = +{ 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, + 0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47, + 0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2, + 0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12, + 0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9, + 0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39 }; +const uint8_t SHA512_DOUBLE_DIGEST[] = +{ 0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda, + 0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f, + 0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1, + 0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18, + 0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4, + 0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a, + 0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54, + 0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09 }; + +/* ---------------- test-case low-level code ---------------- */ + +void dump(char *label, const uint8_t *buf, int len) +{ + if (debug) { + int i; + printf("%s [", label); + for (i = 0; i < len; ++i) + printf(" %02x", buf[i]); + printf(" ]\n"); + } +} + +int tc_write(off_t offset, const uint8_t *buf, int len) +{ + dump("write ", buf, len); + + for (; len > 0; offset += 4, buf += 4, len -= 4) { + uint32_t val; + val = htonl(*(uint32_t *)buf); + eim_write_32(offset, &val); + } + + return 0; +} + +int tc_read(off_t offset, uint8_t *buf, int len) +{ + uint8_t *rbuf = buf; + int rlen = len; + + for (; rlen > 0; offset += 4, rbuf += 4, rlen -= 4) { + uint32_t val; + eim_read_32(offset, &val); + *(uint32_t *)rbuf = ntohl(val); + } + + dump("read ", buf, len); + + return 0; +} + +int tc_expected(off_t offset, const uint8_t *expected, int len) +{ + uint8_t *buf; + int i; + + buf = malloc(len); + if (buf == NULL) { + perror("malloc"); + return 1; + } + dump("expect", expected, len); + + if (tc_read(offset, buf, len) != 0) + goto errout; + + for (i = 0; i < len; ++i) + if (buf[i] != expected[i]) { + fprintf(stderr, "response byte %d: expected 0x%02x, got 0x%02x\n", + i, expected[i], buf[i]); + goto errout; + } + + free(buf); + return 0; +errout: + free(buf); + return 1; +} + +int tc_init(off_t offset) +{ + uint8_t buf[4] = { 0, 0, 0, CTRL_INIT_CMD }; + + return tc_write(offset, buf, 4); +} + +int tc_next(off_t offset) +{ + uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT_CMD }; + + return tc_write(offset, buf, 4); +} + +int tc_wait(off_t offset, uint8_t status) +{ + uint8_t buf[4]; + +#if 0 + do { + if (tc_read(offset, buf, 4) != 0) + return 1; + } while (!(buf[3] & status)); + + return 0; +#else + int i; + for (i = 0; i < 10; ++i) { + if (tc_read(offset, buf, 4) != 0) + return 1; + if (buf[3] & status) + return 0; + } + fprintf(stderr, "tc_wait timed out\n"); + return 1; +#endif +} + +int tc_wait_ready(off_t offset) +{ + return tc_wait(offset, STATUS_READY_BIT); +} + +int tc_wait_valid(off_t offset) +{ + return tc_wait(offset, STATUS_VALID_BIT); +} + +/* ---------------- sanity test case ---------------- */ + +int TC0() +{ + uint8_t board_name0[4] = { 'P', 'V', 'T', '1'}; + uint8_t board_name1[4] = { ' ', ' ', ' ', ' '}; + uint8_t board_version[4] = { '0', '.', '1', '0'}; + + uint8_t comm_name0[4] = { 'e', 'i', 'm', ' '}; + uint8_t comm_name1[4] = { ' ', ' ', ' ', ' '}; + uint8_t comm_version[4] = { '0', '.', '1', '0'}; + + uint8_t t[4]; + + if (!quiet) + printf("TC0-1: Reading board type, version, and dummy reg from global registers.\n"); + + /* write current time into dummy register, then try to read it back + * to make sure that we can actually write something into EIM + */ + (void)time((time_t *)t); + tc_write(BOARD_ADDR_DUMMY, (void *)&t, 4); + + if (tc_expected(BOARD_ADDR_NAME0, board_name0, 4) || + tc_expected(BOARD_ADDR_NAME1, board_name1, 4) || + tc_expected(BOARD_ADDR_VERSION, board_version, 4) || + tc_expected(BOARD_ADDR_DUMMY, (void *)t, 4)) + return 1; + + if (!quiet) + printf("TC0-2: Reading name and version words from communications core.\n"); + + return + tc_expected(COMM_ADDR_NAME0, comm_name0, 4) || + tc_expected(COMM_ADDR_NAME1, comm_name1, 4) || + tc_expected(COMM_ADDR_VERSION, comm_version, 4); +} + +/* ---------------- SHA-1 test cases ---------------- */ + +/* TC1: Read name and version from SHA-1 core. */ +int TC1(void) +{ + uint8_t name0[4] = { 0x73, 0x68, 0x61, 0x31 }; /* "sha1" */ + uint8_t name1[4] = { 0x20, 0x20, 0x20, 0x20 }; /* " " */ + uint8_t version[4] = { 0x30, 0x2e, 0x35, 0x30 }; /* "0.50" */ + + if (!quiet) + printf("TC1: Reading name and version words from SHA-1 core.\n"); + + return + tc_expected(SHA1_ADDR_NAME0, name0, 4) || + tc_expected(SHA1_ADDR_NAME1, name1, 4) || + tc_expected(SHA1_ADDR_VERSION, version, 4); +} + +/* TC2: SHA-1 Single block message test as specified by NIST. */ +int TC2(void) +{ + const uint8_t *block = NIST_512_SINGLE; + const uint8_t *expected = SHA1_SINGLE_DIGEST; + int ret; + + if (!quiet) + printf("TC2: Single block message test for SHA-1.\n"); + + /* Write block to SHA-1. */ + tc_write(SHA1_ADDR_BLOCK, block, SHA1_BLOCK_LEN); + /* Start initial block hashing, wait and check status. */ + tc_init(SHA1_ADDR_CTRL); + tc_wait_valid(SHA1_ADDR_STATUS); + /* Extract the digest. */ + ret = tc_expected(SHA1_ADDR_DIGEST, expected, SHA1_DIGEST_LEN); + return ret; +} + +/* TC3: SHA-1 Double block message test as specified by NIST. */ +int TC3(void) +{ + const uint8_t *block[2] = { NIST_512_DOUBLE0, NIST_512_DOUBLE1 }; + static const uint8_t block0_expected[] = + { 0xF4, 0x28, 0x68, 0x18, 0xC3, 0x7B, 0x27, 0xAE, + 0x04, 0x08, 0xF5, 0x81, 0x84, 0x67, 0x71, 0x48, + 0x4A, 0x56, 0x65, 0x72 }; + const uint8_t *expected = SHA1_DOUBLE_DIGEST; + int ret; + + if (!quiet) + printf("TC3: Double block message test for SHA-1.\n"); + + /* Write first block to SHA-1. */ + tc_write(SHA1_ADDR_BLOCK, block[0], SHA1_BLOCK_LEN); + /* Start initial block hashing, wait and check status. */ + tc_init(SHA1_ADDR_CTRL); + tc_wait_valid(SHA1_ADDR_STATUS); + /* Extract the first digest. */ + tc_expected(SHA1_ADDR_DIGEST, block0_expected, SHA1_DIGEST_LEN); + /* Write second block to SHA-1. */ + tc_write(SHA1_ADDR_BLOCK, block[1], SHA1_BLOCK_LEN); + /* Start next block hashing, wait and check status. */ + tc_next(SHA1_ADDR_CTRL); + tc_wait_valid(SHA1_ADDR_STATUS); + /* Extract the second digest. */ + ret = tc_expected(SHA1_ADDR_DIGEST, expected, SHA1_DIGEST_LEN); + return ret; +} + +/* ---------------- SHA-256 test cases ---------------- */ + +/* TC4: Read name and version from SHA-256 core. */ +int TC4(void) +{ + uint8_t name0[4] = { 0x73, 0x68, 0x61, 0x32 }; /* "sha2" */ + uint8_t name1[4] = { 0x2d, 0x32, 0x35, 0x36 }; /* "-256" */ + uint8_t version[4] = { 0x30, 0x2e, 0x38, 0x30 }; /* "0.80" */ + + if (!quiet) + printf("TC4: Reading name, type and version words from SHA-256 core.\n"); + + return + tc_expected(SHA256_ADDR_NAME0, name0, 4) || + tc_expected(SHA256_ADDR_NAME1, name1, 4) || + tc_expected(SHA256_ADDR_VERSION, version, 4); +} + +/* TC5: SHA-256 Single block message test as specified by NIST. */ +int TC5() +{ + const uint8_t *block = NIST_512_SINGLE; + const uint8_t *expected = SHA256_SINGLE_DIGEST; + + if (!quiet) + printf("TC5: Single block message test for SHA-256.\n"); + + return + /* Write block to SHA-256. */ + tc_write(SHA256_ADDR_BLOCK, block, SHA256_BLOCK_LEN) || + /* Start initial block hashing, wait and check status. */ + tc_init(SHA256_ADDR_CTRL) || + tc_wait_valid(SHA256_ADDR_STATUS) || + /* Extract the digest. */ + tc_expected(SHA256_ADDR_DIGEST, expected, SHA256_DIGEST_LEN); +} + +/* TC6: SHA-256 Double block message test as specified by NIST. */ +int TC6() +{ + const uint8_t *block[2] = { NIST_512_DOUBLE0, NIST_512_DOUBLE1 }; + static const uint8_t block0_expected[] = + { 0x85, 0xE6, 0x55, 0xD6, 0x41, 0x7A, 0x17, 0x95, + 0x33, 0x63, 0x37, 0x6A, 0x62, 0x4C, 0xDE, 0x5C, + 0x76, 0xE0, 0x95, 0x89, 0xCA, 0xC5, 0xF8, 0x11, + 0xCC, 0x4B, 0x32, 0xC1, 0xF2, 0x0E, 0x53, 0x3A }; + const uint8_t *expected = SHA256_DOUBLE_DIGEST; + + if (!quiet) + printf("TC6: Double block message test for SHA-256.\n"); + + return + /* Write first block to SHA-256. */ + tc_write(SHA256_ADDR_BLOCK, block[0], SHA256_BLOCK_LEN) || + /* Start initial block hashing, wait and check status. */ + tc_init(SHA256_ADDR_CTRL) || + tc_wait_valid(SHA256_ADDR_STATUS) || + /* Extract the first digest. */ + tc_expected(SHA256_ADDR_DIGEST, block0_expected, SHA256_DIGEST_LEN) || + /* Write second block to SHA-256. */ + tc_write(SHA256_ADDR_BLOCK, block[1], SHA256_BLOCK_LEN) || + /* Start next block hashing, wait and check status. */ + tc_next(SHA256_ADDR_CTRL) || + tc_wait_valid(SHA256_ADDR_STATUS) || + /* Extract the second digest. */ + tc_expected(SHA256_ADDR_DIGEST, expected, SHA256_DIGEST_LEN); +} + +/* TC7: SHA-256 Huge message test. */ +int TC7() +{ + static const uint8_t block[] = + { 0xaa, 0x55, 0xaa, 0x55, 0xde, 0xad, 0xbe, 0xef, + 0x55, 0xaa, 0x55, 0xaa, 0xf0, 0x0f, 0xf0, 0x0f, + 0xaa, 0x55, 0xaa, 0x55, 0xde, 0xad, 0xbe, 0xef, + 0x55, 0xaa, 0x55, 0xaa, 0xf0, 0x0f, 0xf0, 0x0f, + 0xaa, 0x55, 0xaa, 0x55, 0xde, 0xad, 0xbe, 0xef, + 0x55, 0xaa, 0x55, 0xaa, 0xf0, 0x0f, 0xf0, 0x0f, + 0xaa, 0x55, 0xaa, 0x55, 0xde, 0xad, 0xbe, 0xef, + 0x55, 0xaa, 0x55, 0xaa, 0xf0, 0x0f, 0xf0, 0x0f }; + + /* final digest after 1000 iterations */ + static const uint8_t expected[] = + { 0x76, 0x38, 0xf3, 0xbc, 0x50, 0x0d, 0xd1, 0xa6, + 0x58, 0x6d, 0xd4, 0xd0, 0x1a, 0x15, 0x51, 0xaf, + 0xd8, 0x21, 0xd2, 0x35, 0x2f, 0x91, 0x9e, 0x28, + 0xd5, 0x84, 0x2f, 0xab, 0x03, 0xa4, 0x0f, 0x2a }; + + int i, n = 1000; + + if (!quiet) + printf("TC7: Message with %d blocks test for SHA-256.\n", n); + + /* Write block data to SHA-256. */ + if (tc_write(SHA256_ADDR_BLOCK, block, SHA256_BLOCK_LEN)) + return 1; + + /* Start initial block hashing, wait and check status. */ + if (tc_init(SHA256_ADDR_CTRL) || + tc_wait_ready(SHA256_ADDR_STATUS)) + return 1; + + /* First block done. Do the rest. */ + for (i = 1; i < n; ++i) { + /* Start next block hashing, wait and check status. */ + if (tc_next(SHA256_ADDR_CTRL) || + tc_wait_ready(SHA256_ADDR_STATUS)) + return 1; + } + + /* XXX valid is probably set at the same time as ready */ + if (tc_wait_valid(SHA256_ADDR_STATUS)) + return 1; + /* Extract the final digest. */ + return tc_expected(SHA256_ADDR_DIGEST, expected, SHA256_DIGEST_LEN); +} + +/* ---------------- SHA-512 test cases ---------------- */ + +/* TC8: Read name and version from SHA-512 core. */ +int TC8() +{ + uint8_t name0[4] = { 0x73, 0x68, 0x61, 0x32 }; /* "sha2" */ + uint8_t name1[4] = { 0x2d, 0x35, 0x31, 0x32 }; /* "-512" */ + uint8_t version[4] = { 0x30, 0x2e, 0x38, 0x30 }; /* "0.80" */ + + if (!quiet) + printf("TC8: Reading name, type and version words from SHA-512 core.\n"); + + return + tc_expected(SHA512_ADDR_NAME0, name0, 4) || + tc_expected(SHA512_ADDR_NAME1, name1, 4) || + tc_expected(SHA512_ADDR_VERSION, version, 4); +} + +/* TC9: SHA-512 Single block message test as specified by NIST. + We do this for all modes. */ +int tc9(int mode, const uint8_t *expected, int digest_len) +{ + const uint8_t *block = NIST_1024_SINGLE; + uint8_t init[4] = { 0, 0, 0, CTRL_INIT_CMD + mode }; + + return + /* Write block to SHA-512. */ + tc_write(SHA512_ADDR_BLOCK, block, SHA512_BLOCK_LEN) || + /* Start initial block hashing, wait and check status. */ + tc_write(SHA512_ADDR_CTRL, init, 4) || + tc_wait_valid(SHA512_ADDR_STATUS) || + /* Extract the digest. */ + tc_expected(SHA512_ADDR_DIGEST, expected, digest_len); +} + +int TC9() +{ + if (!quiet) + printf("TC9-1: Single block message test for SHA-512/224.\n"); + if (tc9(MODE_SHA_512_224, SHA512_224_SINGLE_DIGEST, SHA512_224_DIGEST_LEN) != 0) + return 1; + + if (!quiet) + printf("TC9-2: Single block message test for SHA-512/256.\n"); + if (tc9(MODE_SHA_512_256, SHA512_256_SINGLE_DIGEST, SHA512_256_DIGEST_LEN) != 0) + return 1; + + if (!quiet) + printf("TC9-3: Single block message test for SHA-384.\n"); + if (tc9(MODE_SHA_384, SHA384_SINGLE_DIGEST, SHA384_DIGEST_LEN) != 0) + return 1; + + if (!quiet) + printf("TC9-4: Single block message test for SHA-512.\n"); + if (tc9(MODE_SHA_512, SHA512_SINGLE_DIGEST, SHA512_DIGEST_LEN) != 0) + return 1; + + return 0; +} + +/* TC10: SHA-512 Double block message test as specified by NIST. + We do this for all modes. */ +int tc10(int mode, const uint8_t *expected, int digest_len) +{ + const uint8_t *block[2] = { NIST_1024_DOUBLE0, NIST_1024_DOUBLE1 }; + uint8_t init[4] = { 0, 0, 0, CTRL_INIT_CMD + mode }; + uint8_t next[4] = { 0, 0, 0, CTRL_NEXT_CMD + mode }; + + return + /* Write first block to SHA-512. */ + tc_write(SHA512_ADDR_BLOCK, block[0], SHA512_BLOCK_LEN) || + /* Start initial block hashing, wait and check status. */ + tc_write(SHA512_ADDR_CTRL, init, 4) || + tc_wait_ready(SHA512_ADDR_STATUS) || + /* Write second block to SHA-512. */ + tc_write(SHA512_ADDR_BLOCK, block[1], SHA512_BLOCK_LEN) || + /* Start next block hashing, wait and check status. */ + tc_write(SHA512_ADDR_CTRL, next, 4) || + tc_wait_valid(SHA512_ADDR_STATUS) || + /* Extract the digest. */ + tc_expected(SHA512_ADDR_DIGEST, expected, digest_len); +} + +int TC10() +{ + if (!quiet) + printf("TC10-1: Double block message test for SHA-512/224.\n"); + if (tc10(MODE_SHA_512_224, SHA512_224_DOUBLE_DIGEST, SHA512_224_DIGEST_LEN) != 0) + return 1; + + if (!quiet) + printf("TC10-2: Double block message test for SHA-512/256.\n"); + if (tc10(MODE_SHA_512_256, SHA512_256_DOUBLE_DIGEST, SHA512_256_DIGEST_LEN) != 0) + return 1; + + if (!quiet) + printf("TC10-3: Double block message test for SHA-384.\n"); + if (tc10(MODE_SHA_384, SHA384_DOUBLE_DIGEST, SHA384_DIGEST_LEN) != 0) + return 1; + + if (!quiet) + printf("TC10-4: Double block message test for SHA-512.\n"); + if (tc10(MODE_SHA_512, SHA512_DOUBLE_DIGEST, SHA512_DIGEST_LEN) != 0) + return 1; + + return 0; +} + +/* ---------------- main ---------------- */ + +/* signal handler for ctrl-c to end repeat testing */ +unsigned long iter = 0; +struct timeval tv_start, tv_end; +void sighandler(int unused) +{ + double tv_diff; + + gettimeofday(&tv_end, NULL); + tv_diff = (double)(tv_end.tv_sec - tv_start.tv_sec) + + (double)(tv_end.tv_usec - tv_start.tv_usec)/1000000; + printf("\n%lu iterations in %.3f seconds (%.3f iterations/sec)\n", + iter, tv_diff, (double)iter/tv_diff); + exit(EXIT_SUCCESS); +} + +int main(int argc, char *argv[]) +{ + typedef int (*tcfp)(void); + tcfp all_tests[] = { TC0, TC1, TC2, TC3, TC4, TC5, TC6, TC7, TC8, TC9, TC10 }; + tcfp sha1_tests[] = { TC1, TC2, TC3 }; + tcfp sha256_tests[] = { TC4, TC5, TC6, TC7 }; + tcfp sha512_tests[] = { TC8, TC9, TC10 }; + + char *usage = "Usage: %s [-h] [-d] [-q] [-r] tc...\n"; + int i, j, opt; + + while ((opt = getopt(argc, argv, "h?dqr")) != -1) { + switch (opt) { + case 'h': + case '?': + printf(usage, argv[0]); + return EXIT_SUCCESS; + case 'd': + debug = 1; + break; + case 'q': + quiet = 1; + break; + case 'r': + repeat = 1; + break; + default: + fprintf(stderr, usage, argv[0]); + return EXIT_FAILURE; + } + } + + /* set up EIM */ + if (eim_setup() != 0) { + fprintf(stderr, "EIM setup failed\n"); + return EXIT_FAILURE; + } + + /* repeat one test until interrupted */ + if (repeat) { + tcfp tc; + if (optind != argc - 1) { + fprintf(stderr, "only one test case can be repeated\n"); + return EXIT_FAILURE; + } + j = atoi(argv[optind]); + if (j < 0 || j >= sizeof(all_tests)/sizeof(all_tests[0])) { + fprintf(stderr, "invalid test number %s\n", argv[optind]); + return EXIT_FAILURE; + } + tc = (all_tests[j]); + srand(time(NULL)); + signal(SIGINT, sighandler); + gettimeofday(&tv_start, NULL); + while (1) { + ++iter; + if ((iter & 0xffff) == 0) { + printf("."); + fflush(stdout); + } + if (tc() != 0) + sighandler(0); + } + return EXIT_SUCCESS; /*NOTREACHED*/ + } + + /* no args == run all tests */ + if (optind >= argc) { + for (j = 0; j < sizeof(all_tests)/sizeof(all_tests[0]); ++j) + if (all_tests[j]() != 0) + return EXIT_FAILURE; + return EXIT_SUCCESS; + } + + /* run one or more tests (by number) or groups of tests (by name) */ + for (i = optind; i < argc; ++i) { + if (strcmp(argv[i], "all") == 0) { + for (j = 0; j < sizeof(all_tests)/sizeof(all_tests[0]); ++j) + if (all_tests[j]() != 0) + return EXIT_FAILURE; + } + else if (strcmp(argv[i], "sha1") == 0) { + for (j = 0; j < sizeof(sha1_tests)/sizeof(sha1_tests[0]); ++j) + if (sha1_tests[j]() != 0) + return EXIT_FAILURE; + } + else if (strcmp(argv[i], "sha256") == 0) { + for (j = 0; j < sizeof(sha256_tests)/sizeof(sha256_tests[0]); ++j) + if (sha256_tests[j]() != 0) + return EXIT_FAILURE; + } + else if (strcmp(argv[i], "sha512") == 0) { + for (j = 0; j < sizeof(sha512_tests)/sizeof(sha512_tests[0]); ++j) + if (sha512_tests[j]() != 0) + return EXIT_FAILURE; + } + else if (isdigit(argv[i][0]) && + (((j = atoi(argv[i])) >= 0) && + (j < sizeof(all_tests)/sizeof(all_tests[0])))) { + if (all_tests[j]() != 0) + return EXIT_FAILURE; + } + else { + fprintf(stderr, "unknown test case %s\n", argv[i]); + return EXIT_FAILURE; + } + } + + return EXIT_SUCCESS; +} diff --git a/eim/sw/novena-eim.c b/eim/sw/novena-eim.c new file mode 100644 index 0000000..85bfac0 --- /dev/null +++ b/eim/sw/novena-eim.c @@ -0,0 +1,708 @@ +/* + * novena-eim.c + * ------------ + * This module contains the userland magic to set up and use the EIM bus. + * + * + * Author: Pavel Shatov + * Copyright (c) 2014-2015, NORDUnet A/S All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of the NORDUnet nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include +#include +#include +#include +#include +#include +#include + +#include "novena-eim.h" + + +//------------------------------------------------------------------------------ +// Defines +//------------------------------------------------------------------------------ +#define MEMORY_DEVICE "/dev/mem" + +#define IOMUXC_MUX_MODE_ALT0 0 // 000 + +#define IOMUXC_PAD_CTL_SRE_FAST 1 // 1 +#define IOMUXC_PAD_CTL_DSE_33_OHM 7 // 111 +#define IOMUXC_PAD_CTL_SPEED_MEDIUM_10 2 // 10 +#define IOMUXC_PAD_CTL_ODE_DISABLED 0 // 0 +#define IOMUXC_PAD_CTL_PKE_DISABLED 0 // 0 +#define IOMUXC_PAD_CTL_PUE_PULL 1 // 1 +#define IOMUXC_PAD_CTL_PUS_100K_OHM_PU 2 // 10 +#define IOMUXC_PAD_CTL_HYS_DISABLED 0 // 0 + +#define CCM_CGR_OFF 0 // 00 +#define CCM_CGR_ON_EXCEPT_STOP 3 // 11 + + +//------------------------------------------------------------------------------ +// CPU Registers +//------------------------------------------------------------------------------ +enum IMX6DQ_REGISTER_OFFSET +{ + IOMUXC_SW_MUX_CTL_PAD_EIM_CS0_B = 0x020E00F8, + IOMUXC_SW_MUX_CTL_PAD_EIM_OE_B = 0x020E0100, + IOMUXC_SW_MUX_CTL_PAD_EIM_RW = 0x020E0104, + IOMUXC_SW_MUX_CTL_PAD_EIM_LBA_B = 0x020E0108, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD00 = 0x020E0114, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD01 = 0x020E0118, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD02 = 0x020E011C, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD03 = 0x020E0120, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD04 = 0x020E0124, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD05 = 0x020E0128, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD06 = 0x020E012C, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD07 = 0x020E0130, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD08 = 0x020E0134, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD09 = 0x020E0138, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD10 = 0x020E013C, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD11 = 0x020E0140, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD12 = 0x020E0144, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD13 = 0x020E0148, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD14 = 0x020E014C, + IOMUXC_SW_MUX_CTL_PAD_EIM_AD15 = 0x020E0150, + IOMUXC_SW_MUX_CTL_PAD_EIM_WAIT_B = 0x020E0154, + IOMUXC_SW_MUX_CTL_PAD_EIM_BCLK = 0x020E0158, + + IOMUXC_SW_PAD_CTL_PAD_EIM_CS0_B = 0x020E040C, + IOMUXC_SW_PAD_CTL_PAD_EIM_OE_B = 0x020E0414, + IOMUXC_SW_PAD_CTL_PAD_EIM_RW = 0x020E0418, + IOMUXC_SW_PAD_CTL_PAD_EIM_LBA_B = 0x020E041C, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD00 = 0x020E0428, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD01 = 0x020E042C, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD02 = 0x020E0430, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD03 = 0x020E0434, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD04 = 0x020E0438, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD05 = 0x020E043C, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD06 = 0x020E0440, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD07 = 0x020E0444, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD08 = 0x020E0448, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD09 = 0x020E044C, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD10 = 0x020E0450, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD11 = 0x020E0454, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD12 = 0x020E0458, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD13 = 0x020E045C, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD14 = 0x020E0460, + IOMUXC_SW_PAD_CTL_PAD_EIM_AD15 = 0x020E0464, + IOMUXC_SW_PAD_CTL_PAD_EIM_WAIT_B = 0x020E0468, + IOMUXC_SW_PAD_CTL_PAD_EIM_BCLK = 0x020E046C, + + CCM_CCGR6 = 0x020C4080, + + EIM_CS0GCR1 = 0x021B8000, + EIM_CS0GCR2 = 0x021B8004, + EIM_CS0RCR1 = 0x021B8008, + EIM_CS0RCR2 = 0x021B800C, + EIM_CS0WCR1 = 0x021B8010, + EIM_CS0WCR2 = 0x021B8014, + + EIM_WCR = 0x021B8090, + EIM_WIAR = 0x021B8094, + EIM_EAR = 0x021B8098, +}; + + +//------------------------------------------------------------------------------ +// Structures +//------------------------------------------------------------------------------ +struct IOMUXC_SW_MUX_CTL_PAD_EIM +{ + unsigned int mux_mode : 3; + unsigned int reserved_3 : 1; + unsigned int sion : 1; + unsigned int reserved_31_5 : 27; +}; + +struct IOMUXC_SW_PAD_CTL_PAD_EIM +{ + unsigned int sre : 1; + unsigned int reserved_2_1 : 2; + unsigned int dse : 3; + unsigned int speed : 2; + unsigned int reserved_10_8 : 3; + unsigned int ode : 1; + unsigned int pke : 1; + unsigned int pue : 1; + unsigned int pus : 2; + unsigned int hys : 1; + unsigned int reserved_31_17 : 15; +}; + +struct CCM_CCGR6 +{ + unsigned int cg0_usboh3 : 2; + unsigned int cg1_usdhc1 : 2; + unsigned int cg2_usdhc2 : 2; + unsigned int cg3_usdhc3 : 2; + + unsigned int cg3_usdhc4 : 2; + unsigned int cg5_eim_slow : 2; + unsigned int cg6_vdoaxiclk : 2; + unsigned int cg7_vpu : 2; + + unsigned int cg8_reserved : 2; + unsigned int cg9_reserved : 2; + unsigned int cg10_reserved : 2; + unsigned int cg11_reserved : 2; + + unsigned int cg12_reserved : 2; + unsigned int cg13_reserved : 2; + unsigned int cg14_reserved : 2; + unsigned int cg15_reserved : 2; +}; + +struct EIM_CS_GCR1 +{ + unsigned int csen : 1; + unsigned int swr : 1; + unsigned int srd : 1; + unsigned int mum : 1; + unsigned int wfl : 1; + unsigned int rfl : 1; + unsigned int cre : 1; + unsigned int crep : 1; + unsigned int bl : 3; + unsigned int wc : 1; + unsigned int bcd : 2; + unsigned int bcs : 2; + unsigned int dsz : 3; + unsigned int sp : 1; + unsigned int csrec : 3; + unsigned int aus : 1; + unsigned int gbc : 3; + unsigned int wp : 1; + unsigned int psz : 4; +}; + +struct EIM_CS_GCR2 +{ + unsigned int adh : 2; + unsigned int reserved_3_2 : 2; + unsigned int daps : 4; + unsigned int dae : 1; + unsigned int dap : 1; + unsigned int reserved_11_10 : 2; + unsigned int mux16_byp_grant : 1; + unsigned int reserved_31_13 : 19; +}; + +struct EIM_CS_RCR1 +{ + unsigned int rcsn : 3; + unsigned int reserved_3 : 1; + unsigned int rcsa : 3; + unsigned int reserved_7 : 1; + unsigned int oen : 3; + unsigned int reserved_11 : 1; + unsigned int oea : 3; + unsigned int reserved_15 : 1; + unsigned int radvn : 3; + unsigned int ral : 1; + unsigned int radva : 3; + unsigned int reserved_23 : 1; + unsigned int rwsc : 6; + unsigned int reserved_31_30 : 2; +}; + +struct EIM_CS_RCR2 +{ + unsigned int rben : 3; + unsigned int rbe : 1; + unsigned int rbea : 3; + unsigned int reserved_7 : 1; + unsigned int rl : 2; + unsigned int reserved_11_10 : 2; + unsigned int pat : 3; + unsigned int apr : 1; + unsigned int reserved_31_16 : 16; +}; + +struct EIM_CS_WCR1 +{ + unsigned int wcsn : 3; + unsigned int wcsa : 3; + unsigned int wen : 3; + unsigned int wea : 3; + unsigned int wben : 3; + unsigned int wbea : 3; + unsigned int wadvn : 3; + unsigned int wadva : 3; + unsigned int wwsc : 6; + unsigned int wbed : 1; + unsigned int wal : 1; +}; + +struct EIM_CS_WCR2 +{ + unsigned int wbcdd : 1; + unsigned int reserved_31_1 : 31; +}; + +struct EIM_WCR +{ + unsigned int bcm : 1; + unsigned int gbcd : 2; + unsigned int reserved_3 : 1; + unsigned int inten : 1; + unsigned int intpol : 1; + unsigned int reserved_7_6 : 2; + unsigned int wdog_en : 1; + unsigned int wdog_limit : 2; + unsigned int reserved_31_11 : 21; +}; + +struct EIM_WIAR +{ + unsigned int ips_req : 1; + unsigned int ips_ack : 1; + unsigned int irq : 1; + unsigned int errst : 1; + unsigned int aclk_en : 1; + unsigned int reserved_31_5 : 27; +}; + +struct EIM_EAR +{ + unsigned int error_addr : 32; +}; + + +//------------------------------------------------------------------------------ +// Variables +//------------------------------------------------------------------------------ +static long mem_page_size = 0; +static int mem_dev_fd = -1; +static void * mem_map_ptr = MAP_FAILED; +static off_t mem_base_addr = 0; + + +//------------------------------------------------------------------------------ +// Prototypes +//------------------------------------------------------------------------------ +static void _eim_setup_iomuxc (void); +static void _eim_setup_ccm (void); +static void _eim_setup_eim (void); +static void _eim_cleanup (void); +static off_t _eim_calc_offset (off_t); +static void _eim_remap_mem (off_t); + + +//------------------------------------------------------------------------------ +// Set up EIM bus. Returns 0 on success, -1 on failure. +//------------------------------------------------------------------------------ +int eim_setup(void) +{ + // register cleanup function + if (atexit(_eim_cleanup) != 0) { + fprintf(stderr, "ERROR: atexit() failed.\n"); + return -1; + } + + // determine memory page size to use in mmap() + mem_page_size = sysconf(_SC_PAGESIZE); + if (mem_page_size < 1) { + fprintf(stderr, "ERROR: sysconf(_SC_PAGESIZE) == %ld\n", mem_page_size); + return -1; + } + + // try to open memory device + mem_dev_fd = open(MEMORY_DEVICE, O_RDWR | O_SYNC); + if (mem_dev_fd == -1) { + fprintf(stderr, "ERROR: open(%s) failed.\n", MEMORY_DEVICE); + return -1; + } + + // configure IOMUXC + _eim_setup_iomuxc(); + + // configure Clock Controller Module + _eim_setup_ccm(); + + /* We need to properly configure EIM mode and all the corresponding parameters. + * That's a lot of code, let's do it now. + */ + _eim_setup_eim(); + + // done + return 0; +} + + +//------------------------------------------------------------------------------ +// Shut down EIM bus. This is called automatically on exit(). +//------------------------------------------------------------------------------ +static void _eim_cleanup(void) +{ + // unmap memory if needed + if (mem_map_ptr != MAP_FAILED) + if (munmap(mem_map_ptr, mem_page_size) != 0) + fprintf(stderr, "WARNING: munmap() failed.\n"); + + // close memory device if needed + if (mem_dev_fd != -1) + if (close(mem_dev_fd) != 0) + fprintf(stderr, "WARNING: close() failed.\n"); +} + + +//------------------------------------------------------------------------------ +// Several blocks in the CPU have common pins. We use the I/O MUX Controller +// to configure what block will actually use I/O pins. We wait for the EIM +// module to be able to communicate with the on-board FPGA. +//------------------------------------------------------------------------------ +static void _eim_setup_iomuxc(void) +{ + // create structures + struct IOMUXC_SW_MUX_CTL_PAD_EIM reg_mux; // mux control register + struct IOMUXC_SW_PAD_CTL_PAD_EIM reg_pad; // pad control register + + // setup mux control register + reg_mux.mux_mode = IOMUXC_MUX_MODE_ALT0; // ALT0 mode must be used for EIM + reg_mux.sion = 0; // forced input not needed + reg_mux.reserved_3 = 0; // must be 0 + reg_mux.reserved_31_5 = 0; // must be 0 + + // setup pad control register + reg_pad.sre = IOMUXC_PAD_CTL_SRE_FAST; // fast slew rate + reg_pad.dse = IOMUXC_PAD_CTL_DSE_33_OHM; // highest drive strength + reg_pad.speed = IOMUXC_PAD_CTL_SPEED_MEDIUM_10; // medium speed + reg_pad.ode = IOMUXC_PAD_CTL_ODE_DISABLED; // open drain not needed + reg_pad.pke = IOMUXC_PAD_CTL_PKE_DISABLED; // neither pull nor keeper are needed + reg_pad.pue = IOMUXC_PAD_CTL_PUE_PULL; // doesn't matter actually, because PKE is disabled + reg_pad.pus = IOMUXC_PAD_CTL_PUS_100K_OHM_PU; // doesn't matter actually, because PKE is disabled + reg_pad.hys = IOMUXC_PAD_CTL_HYS_DISABLED; // use CMOS, not Schmitt trigger input + reg_pad.reserved_2_1 = 0; // must be 0 + reg_pad.reserved_10_8 = 0; // must be 0 + reg_pad.reserved_31_17 = 0; // must be 0 + + // all the pins must be configured to use the same ALT0 mode + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_CS0_B, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_OE_B, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_RW, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_LBA_B, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD00, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD01, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD02, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD03, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD04, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD05, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD06, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD07, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD08, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD09, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD10, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD11, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD12, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD13, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD14, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_AD15, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_WAIT_B, (uint32_t *)®_mux); + eim_write_32(IOMUXC_SW_MUX_CTL_PAD_EIM_BCLK, (uint32_t *)®_mux); + + // we need to configure all the I/O pads too + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_CS0_B, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_OE_B, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_RW, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_LBA_B, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD00, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD01, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD02, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD03, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD04, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD05, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD06, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD07, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD08, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD09, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD10, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD11, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD12, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD13, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD14, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_AD15, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_WAIT_B, (uint32_t *)®_pad); + eim_write_32(IOMUXC_SW_PAD_CTL_PAD_EIM_BCLK, (uint32_t *)®_pad); +} + + +//------------------------------------------------------------------------------ +// Configure Clock Controller Module to enable clocking of EIM block. +//------------------------------------------------------------------------------ +static void _eim_setup_ccm(void) +{ + // create structure + struct CCM_CCGR6 ccm_ccgr6; + + // read register + eim_read_32(CCM_CCGR6, (uint32_t *)&ccm_ccgr6); + + // modify register + ccm_ccgr6.cg0_usboh3 = CCM_CGR_ON_EXCEPT_STOP; + ccm_ccgr6.cg1_usdhc1 = CCM_CGR_OFF; + ccm_ccgr6.cg2_usdhc2 = CCM_CGR_ON_EXCEPT_STOP; + ccm_ccgr6.cg3_usdhc3 = CCM_CGR_ON_EXCEPT_STOP; + + ccm_ccgr6.cg3_usdhc4 = CCM_CGR_OFF; + ccm_ccgr6.cg5_eim_slow = CCM_CGR_ON_EXCEPT_STOP; + ccm_ccgr6.cg6_vdoaxiclk = CCM_CGR_OFF; + ccm_ccgr6.cg7_vpu = CCM_CGR_OFF; + + ccm_ccgr6.cg8_reserved = 0; + ccm_ccgr6.cg9_reserved = 0; + ccm_ccgr6.cg10_reserved = 0; + ccm_ccgr6.cg11_reserved = 0; + ccm_ccgr6.cg12_reserved = 0; + ccm_ccgr6.cg13_reserved = 0; + ccm_ccgr6.cg14_reserved = 0; + ccm_ccgr6.cg15_reserved = 0; + + // write register + eim_write_32(CCM_CCGR6, (uint32_t *)&ccm_ccgr6); +} + + +//------------------------------------------------------------------------------ +// Configure EIM mode and all the corresponding parameters. That's a lot of code. +//------------------------------------------------------------------------------ +static void _eim_setup_eim(void) +{ + // create structures + struct EIM_CS_GCR1 gcr1; + struct EIM_CS_GCR2 gcr2; + struct EIM_CS_RCR1 rcr1; + struct EIM_CS_RCR2 rcr2; + struct EIM_CS_WCR1 wcr1; + struct EIM_CS_WCR2 wcr2; + + struct EIM_WCR wcr; + struct EIM_WIAR wiar; + struct EIM_EAR ear; + + // read all the registers + eim_read_32(EIM_CS0GCR1, (uint32_t *)&gcr1); + eim_read_32(EIM_CS0GCR2, (uint32_t *)&gcr2); + eim_read_32(EIM_CS0RCR1, (uint32_t *)&rcr1); + eim_read_32(EIM_CS0RCR2, (uint32_t *)&rcr2); + eim_read_32(EIM_CS0WCR1, (uint32_t *)&wcr1); + eim_read_32(EIM_CS0WCR2, (uint32_t *)&wcr2); + + eim_read_32(EIM_WCR, (uint32_t *)&wcr); + eim_read_32(EIM_WIAR, (uint32_t *)&wiar); + eim_read_32(EIM_EAR, (uint32_t *)&ear); + + // manipulate registers as needed + gcr1.csen = 1; // chip select is enabled + gcr1.swr = 1; // write is sync + gcr1.srd = 1; // read is sync + gcr1.mum = 1; // address and data are multiplexed + gcr1.wfl = 0; // write latency is not fixed + gcr1.rfl = 0; // read latency is not fixed + gcr1.cre = 0; // CRE signal not needed + //gcr1.crep = x; // don't care, CRE not used + gcr1.bl = 4; // burst length + gcr1.wc = 0; // write is not continuous + gcr1.bcd = 3; // BCLK divisor is 3+1=4 + gcr1.bcs = 1; // delay from ~CS to BCLK is 1 cycle + gcr1.dsz = 1; // 16 bits per databeat at DATA[15:0] + gcr1.sp = 0; // supervisor protection is disabled + gcr1.csrec = 1; // ~CS recovery is 1 cycle + gcr1.aus = 1; // address is not shifted + gcr1.gbc = 1; // ~CS gap is 1 cycle + gcr1.wp = 0; // write protection is not enabled + //gcr1.psz = x; // don't care, page mode is not used + + gcr2.adh = 0; // address hold duration is 1 cycle + //gcr2.daps = x; // don't care, DTACK is not used + gcr2.dae = 0; // DTACK is not used + //gcr2.dap = x; // don't care, DTACK is not used + gcr2.mux16_byp_grant= 1; // enable grant mechanism + gcr2.reserved_3_2 = 0; // must be 0 + gcr2.reserved_11_10 = 0; // must be 0 + gcr2.reserved_31_13 = 0; // must be 0 + + //rcr1.rcsn = x; // don't care in sync mode + rcr1.rcsa = 0; // no delay for ~CS needed + //rcr1.oen = x; // don't care in sync mode + rcr1.oea = 0; // no delay for ~OE needed + rcr1.radvn = 0; // no delay for ~LBA needed + rcr1.ral = 0; // clear ~LBA when needed + rcr1.radva = 0; // no delay for ~LBA needed + rcr1.rwsc = 1; // one wait state + rcr1.reserved_3 = 0; // must be 0 + rcr1.reserved_7 = 0; // must be 0 + rcr1.reserved_11 = 0; // must be 0 + rcr1.reserved_15 = 0; // must be 0 + rcr1.reserved_23 = 0; // must be 0 + rcr1.reserved_31_30 = 0; // must be 0 + + //rcr2.rben = x; // don't care in sync mode + rcr2.rbe = 0; // BE is disabled + //rcr2.rbea = x; // don't care when BE is not used + rcr2.rl = 0; // read latency is 0 + //rcr2.pat = x; // don't care when page read is not used + rcr2.apr = 0; // page read mode is not used + rcr2.reserved_7 = 0; // must be 0 + rcr2.reserved_11_10 = 0; // must be 0 + rcr2.reserved_31_16 = 0; // must be 0 + + //wcr1.wcsn = x; // don't care in sync mode + wcr1.wcsa = 0; // no delay for ~CS needed + //wcr1.wen = x; // don't care in sync mode + wcr1.wea = 0; // no delay for ~WR_N needed + //wcr1.wben = x; // don't care in sync mode + //wcr1.wbea = x; // don't care in sync mode + wcr1.wadvn = 0; // no delay for ~LBA needed + wcr1.wadva = 0; // no delay for ~LBA needed + wcr1.wwsc = 1; // no wait state in needed + wcr1.wbed = 1; // BE is disabled + wcr1.wal = 0; // clear ~LBA when needed + + wcr2.wbcdd = 0; // write clock division is not needed + wcr2.reserved_31_1 = 0; // must be 0 + + wcr.bcm = 0; // clock is only active during access + //wcr.gbcd = x; // don't care when BCM=0 + wcr.inten = 0; // interrupt is not used + //wcr.intpol = x; // don't care when interrupt is not used + wcr.wdog_en = 1; // watchdog is enabled + wcr.wdog_limit = 00; // timeout is 128 BCLK cycles + wcr.reserved_3 = 0; // must be 0 + wcr.reserved_7_6 = 0; // must be 0 + wcr.reserved_31_11 = 0; // must be 0 + + wiar.ips_req = 0; // IPS not needed + wiar.ips_ack = 0; // IPS not needed + //wiar.irq = x; // don't touch + //wiar.errst = x; // don't touch + wiar.aclk_en = 1; // clock is enabled + wiar.reserved_31_5 = 0; // must be 0 + + //ear.error_addr = x; // read-only + + // write modified registers + eim_write_32(EIM_CS0GCR1, (uint32_t *)&gcr1); + eim_write_32(EIM_CS0GCR2, (uint32_t *)&gcr2); + eim_write_32(EIM_CS0RCR1, (uint32_t *)&rcr1); + eim_write_32(EIM_CS0RCR2, (uint32_t *)&rcr2); + eim_write_32(EIM_CS0WCR1, (uint32_t *)&wcr1); + eim_write_32(EIM_CS0WCR2, (uint32_t *)&wcr2); + eim_write_32(EIM_WCR, (uint32_t *)&wcr); + eim_write_32(EIM_WIAR, (uint32_t *)&wiar); +/* eim_write_32(EIM_EAR, (uint32_t *)&ear);*/ +} + + +//------------------------------------------------------------------------------ +// Write a 32-bit word to EIM. +// If EIM is not set up correctly, this will abort with a bus error. +//------------------------------------------------------------------------------ +void eim_write_32(off_t offset, uint32_t *pvalue) +{ + // calculate memory offset + uint32_t *ptr = (uint32_t *)_eim_calc_offset(offset); + + // write data to memory + memcpy(ptr, pvalue, sizeof(uint32_t)); +} + +//------------------------------------------------------------------------------ +// Read a 32-bit word from EIM. +// If EIM is not set up correctly, this will abort with a bus error. +//------------------------------------------------------------------------------ +void eim_read_32(off_t offset, uint32_t *pvalue) +{ + // calculate memory offset + uint32_t *ptr = (uint32_t *)_eim_calc_offset(offset); + + // read data from memory + memcpy(pvalue, ptr, sizeof(uint32_t)); +} + + +//------------------------------------------------------------------------------ +// Calculate an offset into the currently-mapped EIM page. +//------------------------------------------------------------------------------ +static off_t _eim_calc_offset(off_t offset) +{ + // make sure that memory is mapped + if (mem_map_ptr == MAP_FAILED) + _eim_remap_mem(offset); + + // calculate starting and ending addresses of currently mapped page + off_t offset_low = mem_base_addr; + off_t offset_high = mem_base_addr + (mem_page_size - 1); + + // check that offset is in currently mapped page, remap new page otherwise + if ((offset < offset_low) || (offset > offset_high)) + _eim_remap_mem(offset); + + // calculate pointer + return (off_t)mem_map_ptr + (offset - mem_base_addr); +} + + +//------------------------------------------------------------------------------ +// Map in a new EIM page. +//------------------------------------------------------------------------------ +static void _eim_remap_mem(off_t offset) +{ + // unmap old memory page if needed + if (mem_map_ptr != MAP_FAILED) { + if (munmap(mem_map_ptr, mem_page_size) != 0) { + fprintf(stderr, "ERROR: munmap() failed.\n"); + exit(EXIT_FAILURE); + } + } + + // calculate starting address of new page + while (offset % mem_page_size) + offset--; + + // try to map new memory page + mem_map_ptr = mmap(NULL, mem_page_size, PROT_READ | PROT_WRITE, MAP_SHARED, + mem_dev_fd, offset); + if (mem_map_ptr == MAP_FAILED) { + fprintf(stderr, "ERROR: mmap() failed.\n"); + exit(EXIT_FAILURE); + } + + // save last mapped page address + mem_base_addr = offset; +} + + +//------------------------------------------------------------------------------ +// End-of-File +//------------------------------------------------------------------------------ diff --git a/eim/sw/novena-eim.h b/eim/sw/novena-eim.h new file mode 100644 index 0000000..75613bf --- /dev/null +++ b/eim/sw/novena-eim.h @@ -0,0 +1,52 @@ +/* + * novena-eim.h + * ------------ + * This module contains the userland magic to set up and use the EIM bus. + * + * + * Author: Pavel Shatov + * Copyright (c) 2014-2015, NORDUnet A/S All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of the NORDUnet nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define EIM_BASE_ADDR 0x08000000 + +/* Set up EIM bus. + * Returns 0 on success, -1 on failure. + */ +int eim_setup(void); + +/* Write a 32-bit word to EIM. + * If EIM is not set up correctly, this will abort with a bus error. + */ +void eim_write_32(off_t, uint32_t *); + +/* Read a 32-bit word from EIM. + * If EIM is not set up correctly, this will abort with a bus error. + */ +void eim_read_32(off_t, uint32_t *); diff --git a/eim/ucf/novena_eim.ucf b/eim/ucf/novena_eim.ucf new file mode 100644 index 0000000..b324bab --- /dev/null +++ b/eim/ucf/novena_eim.ucf @@ -0,0 +1,152 @@ +#====================================================================== +# +# novena_eim.ucf +# ------------------- +# Constraint file for implementing the Cryptech Novena base +# for the Xilinx Spartan6 LX45 on the Novena. +# +# +# Author: Pavel Shatov +# Copyright (c) 2014, NORDUnet A/S All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# - Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# - Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# - Neither the name of the NORDUnet nor the names of its contributors may +# be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#====================================================================== + +#------------------------------------------------------------------------------- +CONFIG VCCAUX = 3.3; +#------------------------------------------------------------------------------- + + +#-------------------------------------------------------------------------------- +# GCLK Timing +#-------------------------------------------------------------------------------- +NET "gclk_p_pin" TNM_NET = TNM_gclk; +TIMESPEC TS_gclk = PERIOD TNM_gclk 20 ns HIGH 50%; + + +#------------------------------------------------------------------------------- +# BCLK Timing +#------------------------------------------------------------------------------- +NET "eim_bclk" TNM_NET = TNM_bclk; +TIMESPEC TS_bclk = PERIOD TNM_bclk 30 ns HIGH 50%; + + +#------------------------------------------------------------------------------- +# FPGA Pinout +#------------------------------------------------------------------------------- +NET "led_pin" LOC = "A16" | IOSTANDARD = "LVCMOS33" | SLEW = "SLOW" | DRIVE = 12; +NET "apoptosis_pin" LOC = "K1" | IOSTANDARD = "LVCMOS33" | SLEW = "SLOW" | DRIVE = 12; +NET "reset_mcu_b_pin" LOC = "F1" | IOSTANDARD = "LVCMOS33" | PULLUP; + +NET "gclk_p_pin" LOC = "H2" | IOSTANDARD = "LVDS_33" | DIFF_TERM = "TRUE"; +NET "gclk_n_pin" LOC = "H1" | IOSTANDARD = "LVDS_33" | DIFF_TERM = "TRUE"; + +NET "eim_bclk" LOC = "C9" | IOSTANDARD = "LVCMOS33"; +NET "eim_cs0_n" LOC = "B11" | IOSTANDARD = "LVCMOS33"; + +NET "eim_da<0>" LOC = "G9" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<1>" LOC = "A10" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<2>" LOC = "F9" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<3>" LOC = "B9" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<4>" LOC = "E13" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<5>" LOC = "F13" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<6>" LOC = "A9" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<7>" LOC = "A8" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<8>" LOC = "B8" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<9>" LOC = "D8" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<10>" LOC = "D11" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<11>" LOC = "C8" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<12>" LOC = "C7" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<13>" LOC = "C11" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<14>" LOC = "C4" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; +NET "eim_da<15>" LOC = "B6" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; + +NET "eim_a<16>" LOC = "A11" | IOSTANDARD = "LVCMOS33"; +NET "eim_a<17>" LOC = "B12" | IOSTANDARD = "LVCMOS33"; +NET "eim_a<18>" LOC = "D14" | IOSTANDARD = "LVCMOS33"; + +NET "eim_lba_n" LOC = "B14" | IOSTANDARD = "LVCMOS33"; +NET "eim_wr_n" LOC = "C14" | IOSTANDARD = "LVCMOS33"; +NET "eim_oe_n" LOC = "C10" | IOSTANDARD = "LVCMOS33"; +NET "eim_wait_n" LOC = "A7" | IOSTANDARD = "LVCMOS33" | SLEW = "FAST" | DRIVE = 12; + +# Pins to the header where the LEDs on the Cryptech +# Avalanche Noise Board are connected. +NET "ct_led<0>" LOC = K6 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<1>" LOC = H4 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<2>" LOC = H3 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<3>" LOC = M1 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<4>" LOC = L7 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<5>" LOC = G1 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<6>" LOC = T2 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<7>" LOC = H7 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; + +# Pins to the header where the noise sources on the +# Cryptech Avalanche Noise Board are connected. +NET "ct_noise" LOC = L4 | IOSTANDARD = LVCMOS33; + +#------------------------------------------------------------------------------- +# EIM Input Timing +#------------------------------------------------------------------------------- +NET "eim_cs0_n" TNM = "TNM_EIM_IN"; +NET "eim_da<*>" TNM = "TNM_EIM_IN"; +NET "eim_lba_n" TNM = "TNM_EIM_IN"; +NET "eim_wr_n" TNM = "TNM_EIM_IN"; +NET "eim_oe_n" TNM = "TNM_EIM_IN"; + +TIMEGRP "TNM_EIM_IN" OFFSET = IN 9.75 ns VALID 16.0 ns BEFORE "eim_bclk" RISING; + + +#------------------------------------------------------------------------------- +# EIM Output Timing +#------------------------------------------------------------------------------- +NET "eim_da<*>" TNM = "TNM_EIM_OUT"; +NET "eim_wait_n" TNM = "TNM_EIM_OUT"; + +TIMEGRP "TNM_EIM_OUT" OFFSET = OUT 13.0 ns AFTER "eim_bclk" FALLING; + + +#------------------------------------------------------------------------------- +# CDC Paths +#------------------------------------------------------------------------------- +INST "eim/eim/eim_cdc/cdc_eim_sys/src_ff" TNM = "TNM_from_bclk"; +INST "eim/eim/eim_cdc/cdc_eim_sys/src_latch*" TNM = "TNM_from_bclk"; +INST "eim/eim/eim_cdc/cdc_eim_sys/ff_sync*" TNM = "TNM_to_sys_clk"; +INST "eim/eim/eim_cdc/cdc_eim_sys/dst_latch*" TNM = "TNM_to_sys_clk"; + +INST "eim/eim/eim_cdc/cdc_sys_eim/src_ff" TNM = "TNM_from_sys_clk"; +INST "eim/eim/eim_cdc/cdc_sys_eim/src_latch*" TNM = "TNM_from_sys_clk"; +INST "eim/eim/eim_cdc/cdc_sys_eim/ff_sync*" TNM = "TNM_to_bclk"; +INST "eim/eim/eim_cdc/cdc_sys_eim/dst_latch*" TNM = "TNM_to_bclk"; + +TIMESPEC "TS_bclk_2_sys_clk" = FROM "TNM_from_bclk" TO "TNM_to_sys_clk" TIG; +TIMESPEC "TS_sys_clk_2_bclk" = FROM "TNM_from_sys_clk" TO "TNM_to_bclk" TIG; + +#====================================================================== +# EOF novena_eim.ucf +#====================================================================== diff --git a/i2c/build/.gitignore b/i2c/build/.gitignore new file mode 100644 index 0000000..01d7e9c --- /dev/null +++ b/i2c/build/.gitignore @@ -0,0 +1,52 @@ +*.xrpt +_xmsgs +default.xreport +netlist.lst +*.bgn +*.bit +*.bld +*.cfi +*.drc +*.lso +*.lso +*.map +*.mcs +*.mrp +*.ncd +*.ngc +*.ngd +*.ngm +*.pcf +*.post_map.twr +*.post_map.twx +*.prj +*.prm +*.psr +*.scr +*.srp +*.twr +*.twx +*_bd.bmm +*_bitgen.xwb +*_bitgen.xwbt +*_err.twr +*_err.twx +*_par.grf +*_par.ncd +*_par.pad +*_par.par +*_par.ptwx +*_par.unroutes +*_par.xpi +*_par_pad.csv +*_par_pad.txt +*_summary.xml +*_usage.xml +par_usage_statistics.html +smartguide.ncd +smartpreview.twr +smartpreview.twr +usage_statistics_webtalk.html +webtalk.log +xlnx_auto* +xst diff --git a/i2c/build/Makefile b/i2c/build/Makefile new file mode 100644 index 0000000..3959c4f --- /dev/null +++ b/i2c/build/Makefile @@ -0,0 +1,36 @@ +project = novena_i2c +vendor = xilinx +family = spartan6 +part = xc6slx45csg324-3 +top_module = novena_top +isedir = /opt/Xilinx/14.7/ISE_DS +xil_env = . $(isedir)/settings64.sh +ucf = ../ucf/novena_i2c.ucf + +vfiles = \ + ../rtl/novena_i2c.v \ + ../rtl/novena_regs.v \ + ../../common/rtl/novena_clkmgr.v \ + ../../common/rtl/ipcore/clkmgr_dcm.v \ + ../../../common/core_selector/src/rtl/core_selector.v \ + ../../../common/core_selector/src/rtl/global_selector.v \ + ../../../common/core_selector/src/rtl/cipher_selector.v \ + ../../../common/core_selector/src/rtl/hash_selector.v \ + ../../../common/core_selector/src/rtl/rng_selector.v \ + ../../../../comm/i2c/src/rtl/i2c_regs.v \ + ../../../../comm/i2c/src/rtl/i2c_core.v \ + ../../../../comm/coretest/src/rtl/coretest.v \ + ../../../../hash/sha1/src/rtl/sha1.v \ + ../../../../hash/sha1/src/rtl/sha1_core.v \ + ../../../../hash/sha1/src/rtl/sha1_w_mem.v \ + ../../../../hash/sha256/src/rtl/sha256.v \ + ../../../../hash/sha256/src/rtl/sha256_core.v \ + ../../../../hash/sha256/src/rtl/sha256_k_constants.v \ + ../../../../hash/sha256/src/rtl/sha256_w_mem.v \ + ../../../../hash/sha512/src/rtl/sha512.v \ + ../../../../hash/sha512/src/rtl/sha512_core.v \ + ../../../../hash/sha512/src/rtl/sha512_h_constants.v \ + ../../../../hash/sha512/src/rtl/sha512_k_constants.v \ + ../../../../hash/sha512/src/rtl/sha512_w_mem.v + +include xilinx.mk diff --git a/i2c/build/xilinx.mk b/i2c/build/xilinx.mk new file mode 100644 index 0000000..f35cc98 --- /dev/null +++ b/i2c/build/xilinx.mk @@ -0,0 +1,174 @@ +# The top level module should define the variables below then include +# this file. The files listed should be in the same directory as the +# Makefile. +# +# variable description +# ---------- ------------- +# project project name (top level module should match this name) +# top_module top level module of the project +# libdir path to library directory +# libs library modules used +# vfiles all local .v files +# xilinx_cores all local .xco files +# vendor vendor of FPGA (xilinx, altera, etc.) +# family FPGA device family (spartan3e) +# part FPGA part name (xc4vfx12-10-sf363) +# flashsize size of flash for mcs file (16384) +# optfile (optional) xst extra opttions file to put in .scr +# map_opts (optional) options to give to map +# par_opts (optional) options to give to par +# intstyle (optional) intstyle option to all tools +# ucf constraint file, defaults to $(project).ucf +# +# Library modules should have a modules.mk in their root directory, +# namely $(libdir)//module.mk, that simply adds to the vfiles +# and xilinx_cores variable. +# +# all the .xco files listed in xilinx_cores will be generated with core, with +# the resulting .v and .ngc files placed back in the same directory as +# the .xco file. +# +# TODO: .xco files are device dependant, should use a template based system + +coregen_work_dir ?= ./coregen-tmp +map_opts ?= -timing -ol high -detail -pr b -register_duplication -w +par_opts ?= -ol high +isedir ?= /opt/Xilinx/13.3/ISE_DS +xil_env ?= . $(isedir)/settings32.sh +flashsize ?= 8192 +ucf ?= $(project).ucf + +libmks = $(patsubst %,$(libdir)/%/module.mk,$(libs)) +mkfiles = $(libmks) xilinx.mk +include $(libmks) + +corengcs = $(foreach core,$(xilinx_cores),$(core:.xco=.ngc)) +local_corengcs = $(foreach ngc,$(corengcs),$(notdir $(ngc))) +vfiles += $(foreach core,$(xilinx_cores),$(core:.xco=.v)) +junk += $(local_corengcs) + +.PHONY: default xilinx_cores clean twr etwr +default: $(project).bit $(project).mcs +xilinx_cores: $(corengcs) +twr: $(project).twr +etwr: $(project)_err.twr + +define cp_template +$(2): $(1) + cp $(1) $(2) +endef +$(foreach ngc,$(corengcs),$(eval $(call cp_template,$(ngc),$(notdir $(ngc))))) + +%.ngc %.v: %.xco + @echo "=== rebuilding $@" + if [ -d $(coregen_work_dir) ]; then \ + rm -rf $(coregen_work_dir)/*; \ + else \ + mkdir -p $(coregen_work_dir); \ + fi + cd $(coregen_work_dir); \ + $(xil_env); \ + coregen -b $$OLDPWD/$<; \ + cd - + xcodir=`dirname $<`; \ + basename=`basename $< .xco`; \ + if [ ! -r $(coregen_work_dir/$$basename.ngc) ]; then \ + echo "'$@' wasn't created."; \ + exit 1; \ + else \ + cp $(coregen_work_dir)/$$basename.v $(coregen_work_dir)/$$basename.ngc $$xcodir; \ + fi +junk += $(coregen_work_dir) + +date = $(shell date +%F-%H-%M) + +# some common junk +junk += *.xrpt + +programming_files: $(project).bit $(project).mcs + mkdir -p $@/$(date) + mkdir -p $@/latest + for x in .bit .mcs .cfi _bd.bmm; do cp $(project)$$x $@/$(date)/$(project)$$x; cp $(project)$$x $@/latest/$(project)$$x; done + $(xil_env); xst -help | head -1 | sed 's/^/#/' | cat - $(project).scr > $@/$(date)/$(project).scr + +$(project).mcs: $(project).bit + $(xil_env); \ + promgen -w -s $(flashsize) -p mcs -o $@ -u 0 $^ +junk += $(project).mcs $(project).cfi $(project).prm + +$(project).bit: $(project)_par.ncd + $(xil_env); \ + bitgen $(intstyle) -g UnusedPin:Pullnone -g DriveDone:yes -g StartupClk:Cclk -w $(project)_par.ncd $(project).bit +junk += $(project).bgn $(project).bit $(project).drc $(project)_bd.bmm + + +$(project)_par.ncd: $(project).ncd + $(xil_env); \ + if par $(intstyle) $(par_opts) -w $(project).ncd $(project)_par.ncd; then \ + :; \ + else \ + $(MAKE) etwr; \ + fi +junk += $(project)_par.ncd $(project)_par.par $(project)_par.pad +junk += $(project)_par_pad.csv $(project)_par_pad.txt +junk += $(project)_par.grf $(project)_par.ptwx +junk += $(project)_par.unroutes $(project)_par.xpi + +$(project).ncd: $(project).ngd + if [ -r $(project)_par.ncd ]; then \ + cp $(project)_par.ncd smartguide.ncd; \ + smartguide="-smartguide smartguide.ncd"; \ + else \ + smartguide=""; \ + fi; \ + $(xil_env); \ + map $(intstyle) $(map_opts) $$smartguide $< +junk += $(project).ncd $(project).pcf $(project).ngm $(project).mrp $(project).map +junk += smartguide.ncd $(project).psr +junk += $(project)_summary.xml $(project)_usage.xml + +$(project).ngd: $(project).ngc $(ucf) + $(xil_env); ngdbuild $(intstyle) $(project).ngc -uc $(ucf) +junk += $(project).ngd $(project).bld + +$(project).ngc: $(vfiles) $(local_corengcs) $(project).scr $(project).prj + $(xil_env); xst $(intstyle) -ifn $(project).scr +junk += xlnx_auto* $(top_module).lso $(project).srp +junk += netlist.lst xst $(project).ngc + +$(project).prj: $(vfiles) $(mkfiles) + for src in $(vfiles); do echo "verilog work $$src" >> $(project).tmpprj; done + sort -u $(project).tmpprj > $(project).prj + rm -f $(project).tmpprj +junk += $(project).prj + +optfile += $(wildcard $(project).opt) +top_module ?= $(project) +$(project).scr: $(optfile) $(mkfiles) ./xilinx.opt + echo "run" > $@ + echo "-p $(part)" >> $@ + echo "-top $(top_module)" >> $@ + echo "-ifn $(project).prj" >> $@ + echo "-ofn $(project).ngc" >> $@ + cat ./xilinx.opt $(optfile) >> $@ +junk += $(project).scr + +$(project).post_map.twr: $(project).ncd + $(xil_env); trce -e 10 $< $(project).pcf -o $@ +junk += $(project).post_map.twr $(project).post_map.twx smartpreview.twr + +$(project).twr: $(project)_par.ncd + $(xil_env); trce $< $(project).pcf -o $(project).twr +junk += $(project).twr $(project).twx smartpreview.twr + +$(project)_err.twr: $(project)_par.ncd + $(xil_env); trce -e 10 $< $(project).pcf -o $(project)_err.twr +junk += $(project)_err.twr $(project)_err.twx +junk += $(project).lso $(project)_bitgen.xwb $(project)_bitgen.xwbt +junk += usage_statistics_webtalk.html par_usage_statistics.html webtalk.log _xmsgs default.xreport + +.gitignore: $(mkfiles) + echo programming_files $(junk) | sed 's, ,\n,g' > .gitignore + +clean:: + rm -rf $(junk) diff --git a/i2c/build/xilinx.opt b/i2c/build/xilinx.opt new file mode 100644 index 0000000..7fe9d8b --- /dev/null +++ b/i2c/build/xilinx.opt @@ -0,0 +1,42 @@ +-ifmt mixed +-ofmt NGC +-opt_mode speed +-opt_level 1 +-iuc NO +-keep_hierarchy no +-netlist_hierarchy as_optimized +-rtlview no +-glob_opt AllClockNets +-read_cores yes +-write_timing_constraints NO +-cross_clock_analysis NO +-hierarchy_separator / +-bus_delimiter <> +-case maintain +-slice_utilization_ratio 100 +-bram_utilization_ratio 100 +#-dsp_utilization_ratio 100 +-safe_implementation No +-fsm_extract YES +-fsm_encoding Auto +-fsm_style lut +-ram_extract Yes +-ram_style Auto +-rom_extract Yes +-rom_style Auto +-shreg_extract YES +-auto_bram_packing NO +-resource_sharing YES +-async_to_sync NO +#-use_dsp48 auto +-iobuf YES +-max_fanout 500 +-register_duplication YES +-register_balancing No +-optimize_primitives NO +-use_clock_enable Auto +-use_sync_set Auto +-use_sync_reset Auto +-iob auto +-equivalent_register_removal YES +-slice_utilization_ratio_maxmargin 5 diff --git a/i2c/iseconfig/.gitignore b/i2c/iseconfig/.gitignore new file mode 100644 index 0000000..91e8e2b --- /dev/null +++ b/i2c/iseconfig/.gitignore @@ -0,0 +1,48 @@ +iseconfig +_ngo +*.bgn +*_bitgen.xwbt +*.bld +*.cmd_log +*.drc +*_envsettings.html +*_guide.ncd +*.lso +*_map.map +*_map.mrp +*_map.ncd +*_map.ngm +*_map.xrpt +*.ncd +*.ngc +*.ngd +*_ngdbuild.xrpt +*.ngr +*.pad +*_pad.csv +*_pad.txt +*.par +*_par.xrpt +*.pcf +*.prj +*.ptwx +*.stx +*_summary.html +*_summary.xml +*.syr +*.twr +*.twx +*.unroutes +*_usage.xml +*.ut +*.xpi +*.xst +*_xst.xrpt +*.gise +par_usage_statistics.html +usage_statistics_webtalk.html +webtalk.log +webtalk_pn.xml +xlnx_auto_0_xdb +_xmsgs +xst diff --git a/i2c/iseconfig/novena_i2c.xise b/i2c/iseconfig/novena_i2c.xise new file mode 100644 index 0000000..719e157 --- /dev/null +++ b/i2c/iseconfig/novena_i2c.xise @@ -0,0 +1,455 @@ + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/i2c/rtl/novena_i2c.v b/i2c/rtl/novena_i2c.v new file mode 100644 index 0000000..1cb47a0 --- /dev/null +++ b/i2c/rtl/novena_i2c.v @@ -0,0 +1,221 @@ +//====================================================================== +// +// novena_top.v +// ------------ +// Top module for the Cryptech Novena FPGA framework with the I2C bus. +// +// +// Author: Pavel Shatov +// Copyright (c) 2015, NORDUnet A/S All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// - Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// - Neither the name of the NORDUnet nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//====================================================================== + +module novena_top + ( + // Differential input for 50 MHz general clock. + input wire gclk_p_pin, + input wire gclk_n_pin, + + // Reset controlled by the CPU. + // this must be configured as input w/pullup + input wire reset_mcu_b_pin, + + // Cryptech avalanche noise board input and LED outputs + input wire ct_noise, + output wire [7 : 0] ct_led, + + // I2C interface + input wire i2c_scl, + inout wire i2c_sda, + + // Novena utility ports + output wire apoptosis_pin, // Hold low to not restart after config. + output wire led_pin // LED on edge close to the FPGA. + ); + + + //---------------------------------------------------------------- + // Clock Manager + // + // Clock manager is used to generate SYS_CLK from GCLK + // and implement the reset logic. + // ---------------------------------------------------------------- + wire sys_clk; + wire sys_rst; + + novena_clkmgr clkmgr + ( + .gclk_p(gclk_p_pin), + .gclk_n(gclk_n_pin), + + .reset_mcu_b(reset_mcu_b_pin), + + .sys_clk(sys_clk), + .sys_rst(sys_rst) + ); + + + //---------------------------------------------------------------- + // I2C Interface + // + // I2C subsystem handles all data transfer to/from CPU via I2C bus. + //---------------------------------------------------------------- + parameter I2C_DEVICE_ADDR = 7'h0f; + + wire [16: 0] sys_eim_addr; + wire sys_eim_wr; + wire sys_eim_rd; + + wire sda_pd; + wire sda_int; + + wire clk = sys_clk; + wire reset_n = ~sys_rst; + + // Coretest connections. + wire coretest_reset_n; + wire coretest_cs; + wire coretest_we; + wire [15 : 0] coretest_address; + wire [31 : 0] coretest_write_data; + wire [31 : 0] coretest_read_data; + + // I2C connections + wire [6:0] i2c_device_addr; + wire i2c_rxd_syn; + wire [7 : 0] i2c_rxd_data; + wire i2c_rxd_ack; + wire i2c_txd_syn; + wire [7 : 0] i2c_txd_data; + wire i2c_txd_ack; + + IOBUF #(.DRIVE(8), .SLEW("SLOW")) + IOBUF_sda ( + .IO(i2c_sda), + .I(1'b0), + .T(!sda_pd), + .O(sda_int) + ); + + i2c_core i2c_core + ( + .clk(clk), + .reset(sys_rst), + + // External data interface + .SCL(i2c_scl), + .SDA(sda_int), + .SDA_pd(sda_pd), + .i2c_device_addr(i2c_device_addr), + + // Internal receive interface. + .rxd_syn(i2c_rxd_syn), + .rxd_data(i2c_rxd_data), + .rxd_ack(i2c_rxd_ack), + + // Internal transmit interface. + .txd_syn(i2c_txd_syn), + .txd_data(i2c_txd_data), + .txd_ack(i2c_txd_ack) + ); + + coretest coretest + ( + .clk(clk), + .reset_n(reset_n), + + .rx_syn(i2c_rxd_syn), + .rx_data(i2c_rxd_data), + .rx_ack(i2c_rxd_ack), + + .tx_syn(i2c_txd_syn), + .tx_data(i2c_txd_data), + .tx_ack(i2c_txd_ack), + + // Interface to the core being tested. + .core_reset_n(coretest_reset_n), + .core_cs(coretest_cs), + .core_we(coretest_we), + .core_address(coretest_address), + .core_write_data(coretest_write_data), + .core_read_data(coretest_read_data) + ); + + wire select = (i2c_device_addr == I2C_DEVICE_ADDR); + assign sys_eim_addr = { coretest_address[15:13], 1'b0, coretest_address[12:0] }; + assign sys_eim_wr = select & coretest_cs & coretest_we; + assign sys_eim_rd = select & coretest_cs & ~coretest_we; + + + //---------------------------------------------------------------- + // Core Selector + // + // This multiplexer is used to map different types of cores, such as + // hashes, RNGs and ciphers to different regions (segments) of memory. + //---------------------------------------------------------------- + core_selector cores + ( + .sys_clk(clk), + .sys_rst(sys_rst), + + .sys_eim_addr(sys_eim_addr), + .sys_eim_wr(sys_eim_wr), + .sys_eim_rd(sys_eim_rd), + + .sys_write_data(coretest_write_data), + .sys_read_data(coretest_read_data) + ); + + + //---------------------------------------------------------------- + // Cryptech Logic + // + // Logic specific to the Cryptech use of the Novena. + // Currently we just hard wire the LED outputs. + //---------------------------------------------------------------- + assign ct_led = {8{ct_noise}}; + + + //---------------------------------------------------------------- + // Novena Patch + // + // Patch logic to keep the Novena board happy. + // The apoptosis_pin pin must be kept low or the whole board + // (more exactly the CPU) will be reset after the FPGA has + // been configured. + //---------------------------------------------------------------- + assign apoptosis_pin = 1'b0; + + assign led_pin = 1'b1; + +endmodule + +//====================================================================== +// EOF novena_top.v +//====================================================================== diff --git a/i2c/rtl/novena_regs.v b/i2c/rtl/novena_regs.v new file mode 100644 index 0000000..f14e113 --- /dev/null +++ b/i2c/rtl/novena_regs.v @@ -0,0 +1,129 @@ +//====================================================================== +// +// novena_regs.v +// ------------- +// Global registers for the Cryptech Novena FPGA framework. +// +// +// Author: Pavel Shatov +// Copyright (c) 2015, NORDUnet A/S All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// - Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// - Neither the name of the NORDUnet nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//====================================================================== + +`timescale 1ns / 1ps + +module board_regs + ( + input wire clk, + input wire rst, + + input wire cs, + input wire we, + + input wire [ 7 : 0] address, + input wire [31 : 0] write_data, + output wire [31 : 0] read_data + ); + + + //---------------------------------------------------------------- + // Internal constant and parameter definitions. + //---------------------------------------------------------------- + // API addresses. + localparam ADDR_CORE_NAME0 = 8'h00; + localparam ADDR_CORE_NAME1 = 8'h01; + localparam ADDR_CORE_VERSION = 8'h02; + localparam ADDR_DUMMY_REG = 8'hFF; // general-purpose register + + // Core ID constants. + localparam CORE_NAME0 = 32'h50565431; // "PVT1" + localparam CORE_NAME1 = 32'h20202020; // " " + localparam CORE_VERSION = 32'h302e3130; // "0.10" + + + //---------------------------------------------------------------- + // Wires. + //---------------------------------------------------------------- + reg [31: 0] tmp_read_data; + + // dummy register to check that you can actually write something + reg [31: 0] reg_dummy; + + + //---------------------------------------------------------------- + // Concurrent connectivity for ports etc. + //---------------------------------------------------------------- + assign read_data = tmp_read_data; + + + //---------------------------------------------------------------- + // Access Handler + //---------------------------------------------------------------- + always @(posedge clk) + // + if (rst) + reg_dummy <= {32{1'b0}}; + else if (cs) begin + // + if (we) begin + // + // WRITE handler + // + case (address) + ADDR_DUMMY_REG: + reg_dummy <= write_data; + endcase + // + end else begin + // + // READ handler + // + case (address) + ADDR_CORE_NAME0: + tmp_read_data <= CORE_NAME0; + ADDR_CORE_NAME1: + tmp_read_data <= CORE_NAME1; + ADDR_CORE_VERSION: + tmp_read_data <= CORE_VERSION; + ADDR_DUMMY_REG: + tmp_read_data <= reg_dummy; + // + default: + tmp_read_data <= {32{1'b0}}; // read non-existent locations as zeroes + endcase + // + end + // + end + +endmodule + +//====================================================================== +// EOF novena_regs.v +//====================================================================== diff --git a/i2c/sw/Makefile b/i2c/sw/Makefile new file mode 100755 index 0000000..0142c92 --- /dev/null +++ b/i2c/sw/Makefile @@ -0,0 +1,7 @@ +all: hash_tester_i2c + +hash_tester_i2c: hash_tester_i2c.c + gcc -Wall -o $@ $^ + +clean: + rm -f hash_tester_i2c diff --git a/i2c/sw/hash_tester_i2c.c b/i2c/sw/hash_tester_i2c.c new file mode 100644 index 0000000..f1c6fb4 --- /dev/null +++ b/i2c/sw/hash_tester_i2c.c @@ -0,0 +1,1030 @@ +/* + * hash_tester.c + * -------------- + * This program sends several commands to the coretest_hashes subsystem + * in order to verify the SHA-1, SHA-256 and SHA-512/x hash function + * cores. + * + * Note: This version of the program talks to the FPGA over an I2C bus. + * + * The single and dual block test cases are taken from the + * NIST KAT document: + * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA_All.pdf + * + * + * Authors: Joachim Strömbergson, Paul Selkirk + * Copyright (c) 2014, SUNET + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* I2C configuration */ +#define I2C_dev "/dev/i2c-2" +#define I2C_addr 0x0f + +/* command codes */ +#define SOC 0x55 +#define EOC 0xaa +#define READ_CMD 0x10 +#define WRITE_CMD 0x11 +#define RESET_CMD 0x01 + +/* response codes */ +#define SOR 0xaa +#define EOR 0x55 +#define READ_OK 0x7f +#define WRITE_OK 0x7e +#define RESET_OK 0x7d +#define UNKNOWN 0xfe +#define ERROR 0xfd + +#define SEGMENT_OFFSET_GLOBALS 0x00 +#define SEGMENT_OFFSET_HASHES 0x20 +#define SEGMENT_OFFSET_RNGS 0x40 +#define SEGMENT_OFFSET_CIPHERS 0x60 + +/* addresses and codes common to all cores */ +#define ADDR_NAME0 0x00 +#define ADDR_NAME1 0x01 +#define ADDR_VERSION 0x02 + +/* At segment 0, we have board-level register and communication channel registers */ +#define BOARD_ADDR_PREFIX SEGMENT_OFFSET_GLOBALS + 0x00 +#define BOARD_ADDR_DUMMY 0xFF + +#define COMM_ADDR_PREFIX SEGMENT_OFFSET_GLOBALS + 0x01 + +/* addresses and codes common to all hash cores */ +#define ADDR_CTRL 0x08 +#define CTRL_INIT_CMD 1 +#define CTRL_NEXT_CMD 2 +#define ADDR_STATUS 0x09 +#define STATUS_READY_BIT 1 +#define STATUS_VALID_BIT 2 + +/* addresses and codes for the specific hash cores */ +#define SHA1_ADDR_PREFIX SEGMENT_OFFSET_HASHES + 0x00 +#define SHA1_ADDR_BLOCK 0x10 +#define SHA1_BLOCK_LEN 16 +#define SHA1_ADDR_DIGEST 0x20 +#define SHA1_DIGEST_LEN 5 + +#define SHA256_ADDR_PREFIX SEGMENT_OFFSET_HASHES + 0x01 +#define SHA256_ADDR_BLOCK 0x10 +#define SHA256_BLOCK_LEN 16 +#define SHA256_ADDR_DIGEST 0x20 +#define SHA256_DIGEST_LEN 8 + +#define SHA512_ADDR_PREFIX SEGMENT_OFFSET_HASHES + 0x02 +#define SHA512_CTRL_MODE_LOW 2 +#define SHA512_CTRL_MODE_HIGH 3 +#define SHA512_ADDR_BLOCK 0x10 +#define SHA512_BLOCK_LEN 32 +#define SHA512_ADDR_DIGEST 0x40 +#define SHA512_DIGEST_LEN 16 +#define MODE_SHA_512_224 0 +#define MODE_SHA_512_256 1 +#define MODE_SHA_384 2 +#define MODE_SHA_512 3 + +int i2cfd; +int debug = 0; + +/* SHA-1/SHA-256 One Block Message Sample + Input Message: "abc" */ +const uint32_t NIST_512_SINGLE[] = +{ 0x61626380, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000018 }; + +const uint32_t SHA1_SINGLE_DIGEST[] = +{ 0xa9993e36, 0x4706816a, 0xba3e2571, 0x7850c26c, + 0x9cd0d89d }; + +const uint32_t SHA256_SINGLE_DIGEST[] = +{ 0xBA7816BF, 0x8F01CFEA, 0x414140DE, 0x5DAE2223, + 0xB00361A3, 0x96177A9C, 0xB410FF61, 0xF20015AD }; + +/* SHA-1/SHA-256 Two Block Message Sample + Input Message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" */ +const uint32_t NIST_512_DOUBLE0[] = +{ 0x61626364, 0x62636465, 0x63646566, 0x64656667, + 0x65666768, 0x66676869, 0x6768696A, 0x68696A6B, + 0x696A6B6C, 0x6A6B6C6D, 0x6B6C6D6E, 0x6C6D6E6F, + 0x6D6E6F70, 0x6E6F7071, 0x80000000, 0x00000000 }; +const uint32_t NIST_512_DOUBLE1[] = +{ 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x000001C0 }; + +const uint32_t SHA1_DOUBLE_DIGEST[] = +{ 0x84983E44, 0x1C3BD26E, 0xBAAE4AA1, 0xF95129E5, + 0xE54670F1 }; + +const uint32_t SHA256_DOUBLE_DIGEST[] = +{ 0x248D6A61, 0xD20638B8, 0xE5C02693, 0x0C3E6039, + 0xA33CE459, 0x64FF2167, 0xF6ECEDD4, 0x19DB06C1 }; + +/* SHA-512 One Block Message Sample + Input Message: "abc" */ +const uint32_t NIST_1024_SINGLE[] = +{ 0x61626380, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000018 }; + +const uint32_t SHA512_224_SINGLE_DIGEST[] = +{ 0x4634270f, 0x707b6a54, 0xdaae7530, 0x460842e2, + 0x0e37ed26, 0x5ceee9a4, 0x3e8924aa }; +const uint32_t SHA512_256_SINGLE_DIGEST[] = +{ 0x53048e26, 0x81941ef9, 0x9b2e29b7, 0x6b4c7dab, + 0xe4c2d0c6, 0x34fc6d46, 0xe0e2f131, 0x07e7af23 }; +const uint32_t SHA384_SINGLE_DIGEST[] = +{ 0xcb00753f, 0x45a35e8b, 0xb5a03d69, 0x9ac65007, + 0x272c32ab, 0x0eded163, 0x1a8b605a, 0x43ff5bed, + 0x8086072b, 0xa1e7cc23, 0x58baeca1, 0x34c825a7 }; +const uint32_t SHA512_SINGLE_DIGEST[] = +{ 0xddaf35a1, 0x93617aba, 0xcc417349, 0xae204131, + 0x12e6fa4e, 0x89a97ea2, 0x0a9eeee6, 0x4b55d39a, + 0x2192992a, 0x274fc1a8, 0x36ba3c23, 0xa3feebbd, + 0x454d4423, 0x643ce80e, 0x2a9ac94f, 0xa54ca49f }; + +/* SHA-512 Two Block Message Sample + Input Message: "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" + "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" */ +const uint32_t NIST_1024_DOUBLE0[] = +{ 0x61626364, 0x65666768, 0x62636465, 0x66676869, + 0x63646566, 0x6768696a, 0x64656667, 0x68696a6b, + 0x65666768, 0x696a6b6c, 0x66676869, 0x6a6b6c6d, + 0x6768696a, 0x6b6c6d6e, 0x68696a6b, 0x6c6d6e6f, + 0x696a6b6c, 0x6d6e6f70, 0x6a6b6c6d, 0x6e6f7071, + 0x6b6c6d6e, 0x6f707172, 0x6c6d6e6f, 0x70717273, + 0x6d6e6f70, 0x71727374, 0x6e6f7071, 0x72737475, + 0x80000000, 0x00000000, 0x00000000, 0x00000000 }; +const uint32_t NIST_1024_DOUBLE1[] = +{ 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000380 }; + +const uint32_t SHA512_224_DOUBLE_DIGEST[] = +{ 0x23fec5bb, 0x94d60b23, 0x30819264, 0x0b0c4533, + 0x35d66473, 0x4fe40e72, 0x68674af9 }; +const uint32_t SHA512_256_DOUBLE_DIGEST[] = +{ 0x3928e184, 0xfb8690f8, 0x40da3988, 0x121d31be, + 0x65cb9d3e, 0xf83ee614, 0x6feac861, 0xe19b563a }; +const uint32_t SHA384_DOUBLE_DIGEST[] = +{ 0x09330c33, 0xf71147e8, 0x3d192fc7, 0x82cd1b47, + 0x53111b17, 0x3b3b05d2, 0x2fa08086, 0xe3b0f712, + 0xfcc7c71a, 0x557e2db9, 0x66c3e9fa, 0x91746039 }; +const uint32_t SHA512_DOUBLE_DIGEST[] = +{ 0x8e959b75, 0xdae313da, 0x8cf4f728, 0x14fc143f, + 0x8f7779c6, 0xeb9f7fa1, 0x7299aead, 0xb6889018, + 0x501d289e, 0x4900f7e4, 0x331b99de, 0xc4b5433a, + 0xc7d329ee, 0xb6dd2654, 0x5e96e55b, 0x874be909 }; + +/* ---------------- I2C low-level code ---------------- */ +int i2c_setup(char *dev, int addr) +{ + i2cfd = open(dev, O_RDWR); + if (i2cfd < 0) { + fprintf(stderr, "Unable to open %s: ", dev); + perror(""); + i2cfd = 0; + return 1; + } + + if (ioctl(i2cfd, I2C_SLAVE, addr) < 0) { + fprintf(stderr, "Unable to set I2C slave device 0x%02x: ", addr); + perror(""); + return 1; + } + + return 0; +} + +int i2c_write(uint8_t *buf, int len) +{ + if (debug) { + int i; + printf("write ["); + for (i = 0; i < len; ++i) + printf(" %02x", buf[i]); + printf(" ]\n"); + } + + if (write(i2cfd, buf, len) != len) { + perror("i2c write failed"); + return 1; + } + + return 0; +} + +int i2c_read(uint8_t *b) +{ + /* read() on the i2c device only returns one byte at a time, + * and tc_get_resp() needs to parse the response one byte at a time + */ + if (read(i2cfd, b, 1) != 1) { + perror("i2c read failed"); + return 1; + } + + return 0; +} + +/* ---------------- test-case low-level code ---------------- */ +int tc_send_write_cmd(uint8_t addr0, uint8_t addr1, uint32_t data) +{ + uint8_t buf[9]; + + buf[0] = SOC; + buf[1] = WRITE_CMD; + buf[2] = addr0; + buf[3] = addr1; + buf[4] = (data >> 24) & 0xff; + buf[5] = (data >> 16) & 0xff; + buf[6] = (data >> 8) & 0xff; + buf[7] = data & 0xff; + buf[8] = EOC; + + return i2c_write(buf, sizeof(buf)); +} + +int tc_send_read_cmd(uint8_t addr0, uint8_t addr1) +{ + uint8_t buf[5]; + + buf[0] = SOC; + buf[1] = READ_CMD; + buf[2] = addr0; + buf[3] = addr1; + buf[4] = EOC; + + return i2c_write(buf, sizeof(buf)); +} + +int tc_get_resp(uint8_t *buf, int len) +{ + int i; + + for (i = 0; i < len; ++i) { + if (i2c_read(&buf[i]) != 0) + return 1; + if ((i == 0) && (buf[i] != SOR)) { + /* we've gotten out of sync, and there's probably nothing we can do */ + fprintf(stderr, "response byte 0: expected 0x%02x (SOR), got 0x%02x\n", + SOR, buf[0]); + return 1; + } + else if (i == 1) { /* response code */ + switch (buf[i]) { + case READ_OK: + len = 9; + break; + case WRITE_OK: + len = 5; + break; + case RESET_OK: + len = 3; + break; + case ERROR: + case UNKNOWN: + len = 4; + break; + default: + /* we've gotten out of sync, and there's probably nothing we can do */ + fprintf(stderr, "unknown response code 0x%02x\n", buf[i]); + return 1; + } + } + } + + if (debug) { + printf("read ["); + for (i = 0; i < len; ++i) + printf(" %02x", buf[i]); + printf(" ]\n"); + } + + return 0; +} + +int tc_get_expected(uint8_t *expected, int len) +{ + uint8_t buf[9]; + int i; + + if (tc_get_resp(buf, sizeof(buf)) != 0) + return 1; + + for (i = 0; i < len; ++i) { + if (buf[i] != expected[i]) { + fprintf(stderr, "response byte %d: expected 0x%02x, got 0x%02x\n", + i, expected[i], buf[i]); + return 1; + } + } + + return 0; +} + +int tc_get_write_resp(uint8_t addr0, uint8_t addr1) +{ + uint8_t expected[5]; + + expected[0] = SOR; + expected[1] = WRITE_OK; + expected[2] = addr0; + expected[3] = addr1; + expected[4] = EOR; + + return tc_get_expected(expected, sizeof(expected)); +} + +int tc_get_read_resp(uint8_t addr0, uint8_t addr1, uint32_t data) +{ + uint8_t expected[9]; + + expected[0] = SOR; + expected[1] = READ_OK; + expected[2] = addr0; + expected[3] = addr1; + expected[4] = (data >> 24) & 0xff; + expected[5] = (data >> 16) & 0xff; + expected[6] = (data >> 8) & 0xff; + expected[7] = data & 0xff; + expected[8] = EOR; + + return tc_get_expected(expected, sizeof(expected)); +} + +int tc_write(uint8_t addr0, uint8_t addr1, uint32_t data) +{ + return (tc_send_write_cmd(addr0, addr1, data) || + tc_get_write_resp(addr0, addr1)); +} + +int tc_read(uint8_t addr0, uint8_t addr1, uint32_t data) +{ + return (tc_send_read_cmd(addr0, addr1) || + tc_get_read_resp(addr0, addr1, data)); +} + +int tc_init(uint8_t addr0) +{ + return tc_write(addr0, ADDR_CTRL, CTRL_INIT_CMD); +} + +int tc_next(uint8_t addr0) +{ + return tc_write(addr0, ADDR_CTRL, CTRL_NEXT_CMD); +} + +int tc_wait(uint8_t addr0, uint8_t status) +{ + uint8_t buf[9]; + + do { + if (tc_send_read_cmd(addr0, ADDR_STATUS) != 0) + return 1; + if (tc_get_resp(buf, 9) != 0) + return 1; + if (buf[1] != READ_OK) + return 1; + } while ((buf[7] & status) != status); + + return 0; +} + +int tc_wait_ready(uint8_t addr0) +{ + return tc_wait(addr0, STATUS_READY_BIT); +} + +int tc_wait_valid(uint8_t addr0) +{ + return tc_wait(addr0, STATUS_VALID_BIT); +} + +/* ---------------- sanity test case ---------------- */ + +int TC0() +{ + uint32_t board_name0 = 0x50565431; /* "PVT1" */ + uint32_t board_name1 = 0x20202020; /* " " */ + uint32_t board_version = 0x302e3130; /* "0.10" */ + + uint32_t comm_name0 = 0x69326320; /* "i2c " */ + uint32_t comm_name1 = 0x20202020; /* " " */ + uint32_t comm_version = 0x302e3130; /* "0.10" */ + + uint32_t t; + + printf("TC0-1: Reading board type, version, and dummy reg from global registers.\n"); + + /* write current time into dummy register, then try to read it back + * to make sure that we can actually write something into I2C + */ + t = time(NULL); + tc_write(BOARD_ADDR_PREFIX, BOARD_ADDR_DUMMY, t); + + if (tc_read(BOARD_ADDR_PREFIX, ADDR_NAME0, board_name0) || + tc_read(BOARD_ADDR_PREFIX, ADDR_NAME1, board_name1) || + tc_read(BOARD_ADDR_PREFIX, ADDR_VERSION, board_version) || + tc_read(BOARD_ADDR_PREFIX, BOARD_ADDR_DUMMY, t)) + return 1; + + printf("TC0-2: Reading name and version words from communications core.\n"); + + return + tc_read(COMM_ADDR_PREFIX, ADDR_NAME0, comm_name0) || + tc_read(COMM_ADDR_PREFIX, ADDR_NAME1, comm_name1) || + tc_read(COMM_ADDR_PREFIX, ADDR_VERSION, comm_version); +} + +/* ---------------- SHA-1 test cases ---------------- */ + +int sha1_read(uint8_t addr, uint32_t data) +{ + return tc_read(SHA1_ADDR_PREFIX, addr, data); +} + +int sha1_write(uint8_t addr, uint32_t data) +{ + return tc_write(SHA1_ADDR_PREFIX, addr, data); +} + +int sha1_init(void) +{ + return tc_init(SHA1_ADDR_PREFIX); +} + +int sha1_next(void) +{ + return tc_next(SHA1_ADDR_PREFIX); +} + +int sha1_wait_ready(void) +{ + return tc_wait_ready(SHA1_ADDR_PREFIX); +} + +int sha1_wait_valid(void) +{ + return tc_wait_valid(SHA1_ADDR_PREFIX); +} + +/* TC1: Read name and version from SHA-1 core. */ +int TC1(void) +{ + uint32_t name0 = 0x73686131; /* "sha1" */ + uint32_t name1 = 0x20202020; /* " " */ + uint32_t version = 0x302e3530; /* "0.50" */ + + printf("TC1: Reading name, type and version words from SHA-1 core.\n"); + + return + sha1_read(ADDR_NAME0, name0) || + sha1_read(ADDR_NAME1, name1) || + sha1_read(ADDR_VERSION, version); +} + +/* TC2: SHA-1 Single block message test as specified by NIST. */ +int TC2(void) +{ + const uint32_t *block = NIST_512_SINGLE; + const uint32_t *expected = SHA1_SINGLE_DIGEST; + int i; + + printf("TC2: Single block message test for SHA-1.\n"); + + /* Write block to SHA-1. */ + for (i = 0; i < SHA1_BLOCK_LEN; ++i) { + if (sha1_write(SHA1_ADDR_BLOCK + i, block[i]) != 0) + return 1; + } + + /* Start initial block hashing, wait and check status. */ + if ((sha1_init() != 0) || (sha1_wait_valid() != 0)) + return 1; + + /* Extract the digest. */ + for (i = 0; i < SHA1_DIGEST_LEN; ++i) { + if (sha1_read(SHA1_ADDR_DIGEST + i, expected[i]) != 0) + return 1; + } + + return 0; +} + +/* TC3: SHA-1 Double block message test as specified by NIST. */ +int TC3(void) +{ + const uint32_t *block[2] = { NIST_512_DOUBLE0, NIST_512_DOUBLE1 }; + static const uint32_t block0_expected[] = + { 0xF4286818, 0xC37B27AE, 0x0408F581, 0x84677148, 0x4A566572 }; + const uint32_t *expected = SHA1_DOUBLE_DIGEST; + int i; + + printf("TC3: Double block message test for SHA-1.\n"); + + /* Write first block to SHA-1. */ + for (i = 0; i < SHA1_BLOCK_LEN; ++i) { + if (sha1_write(SHA1_ADDR_BLOCK + i, block[0][i]) != 0) + return 1; + } + + /* Start initial block hashing, wait and check status. */ + if ((sha1_init() != 0) || (sha1_wait_valid() != 0)) + return 1; + + /* Extract the first digest. */ + for (i = 0; i < SHA1_DIGEST_LEN; ++i) { + if (sha1_read(SHA1_ADDR_DIGEST + i, block0_expected[i]) != 0) + return 1; + } + + /* Write second block to SHA-1. */ + for (i = 0; i < SHA1_BLOCK_LEN; ++i) { + if (sha1_write(SHA1_ADDR_BLOCK + i, block[1][i]) != 0) + return 1; + } + + /* Start next block hashing, wait and check status. */ + if ((sha1_next() != 0) || (sha1_wait_valid() != 0)) + return 1; + + /* Extract the second digest. */ + for (i = 0; i < SHA1_DIGEST_LEN; ++i) { + if (sha1_read(SHA1_ADDR_DIGEST + i, expected[i]) != 0) + return 1; + } + + return 0; +} + +/* ---------------- SHA-256 test cases ---------------- */ + +int sha256_read(uint8_t addr, uint32_t data) +{ + return tc_read(SHA256_ADDR_PREFIX, addr, data); +} + +int sha256_write(uint8_t addr, uint32_t data) +{ + return tc_write(SHA256_ADDR_PREFIX, addr, data); +} + +int sha256_init(void) +{ + return tc_init(SHA256_ADDR_PREFIX); +} + +int sha256_next(void) +{ + return tc_next(SHA256_ADDR_PREFIX); +} + +int sha256_wait_ready(void) +{ + return tc_wait_ready(SHA256_ADDR_PREFIX); +} + +int sha256_wait_valid(void) +{ + return tc_wait_valid(SHA256_ADDR_PREFIX); +} + +/* TC4: Read name and version from SHA-256 core. */ +int TC4(void) +{ + uint32_t name0 = 0x73686132; /* "sha2" */ + uint32_t name1 = 0x2d323536; /* "-256" */ + uint32_t version = 0x302e3830; /* "0.80" */ + + printf("TC4: Reading name, type and version words from SHA-256 core.\n"); + + return + sha256_read(ADDR_NAME0, name0) || + sha256_read(ADDR_NAME1, name1) || + sha256_read(ADDR_VERSION, version); +} + +/* TC5: SHA-256 Single block message test as specified by NIST. */ +int TC5(void) +{ + const uint32_t *block = NIST_512_SINGLE; + const uint32_t *expected = SHA256_SINGLE_DIGEST; + int i; + + printf("TC5: Single block message test for SHA-256.\n"); + + /* Write block to SHA-256. */ + for (i = 0; i < SHA256_BLOCK_LEN; ++i) { + if (sha256_write(SHA256_ADDR_BLOCK + i, block[i]) != 0) + return 1; + } + + /* Start initial block hashing, wait and check status. */ + if ((sha256_init() != 0) || (sha256_wait_valid() != 0)) + return 1; + + /* Extract the digest. */ + for (i = 0; i < SHA256_DIGEST_LEN; ++i) { + if (sha256_read(SHA256_ADDR_DIGEST + i, expected[i]) != 0) + return 1; + } + + + return 0; +} + +/* TC6: SHA-1 Double block message test as specified by NIST. */ +int TC6(void) +{ + const uint32_t *block[2] = { NIST_512_DOUBLE0, NIST_512_DOUBLE1 }; + static const uint32_t block0_expected[] = + { 0x85E655D6, 0x417A1795, 0x3363376A, 0x624CDE5C, + 0x76E09589, 0xCAC5F811, 0xCC4B32C1, 0xF20E533A }; + const uint32_t *expected = SHA256_DOUBLE_DIGEST; + int i; + + printf("TC6: Double block message test for SHA-256.\n"); + + /* Write first block to SHA-256. */ + for (i = 0; i < SHA256_BLOCK_LEN; ++i) { + if (sha256_write(SHA256_ADDR_BLOCK + i, block[0][i]) != 0) + return 1; + } + + /* Start initial block hashing, wait and check status. */ + if ((sha256_init() != 0) || (sha256_wait_valid() != 0)) + return 1; + + /* Extract the first digest. */ + for (i = 0; i < SHA256_DIGEST_LEN; ++i) { + if (sha256_read(SHA256_ADDR_DIGEST + i, block0_expected[i]) != 0) + return 1; + } + + /* Write second block to SHA-256. */ + for (i = 0; i < SHA256_BLOCK_LEN; ++i) { + if (sha256_write(SHA256_ADDR_BLOCK + i, block[1][i]) != 0) + return 1; + } + + /* Start next block hashing, wait and check status. */ + if ((sha256_next() != 0) || (sha256_wait_valid() != 0)) + return 1; + + /* Extract the second digest. */ + for (i = 0; i < SHA256_DIGEST_LEN; ++i) { + if (sha256_read(SHA256_ADDR_DIGEST + i, expected[i]) != 0) + return 1; + } + + return 0; +} + +/* TC7: SHA-256 Huge message test. */ +int TC7(void) +{ + static const uint32_t block[] = + { 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f, + 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f, + 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f, + 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f }; + + /* final digest after 1000 iterations */ + static const uint32_t expected[] = + { 0x7638f3bc, 0x500dd1a6, 0x586dd4d0, 0x1a1551af, + 0xd821d235, 0x2f919e28, 0xd5842fab, 0x03a40f2a }; + + int i, n = 1000; + + printf("TC7: Message with %d blocks test for SHA-256.\n", n); + + /* Write first block to SHA-256. */ + for (i = 0; i < SHA256_BLOCK_LEN; ++i) { + if (sha256_write( SHA256_ADDR_BLOCK + i, block[i]) != 0) + return 1; + } + + /* Start initial block hashing, wait and check status. */ + if ((sha256_init() != 0) || (sha256_wait_ready() != 0)) + return 1; + + /* First block done. Do the rest. */ + for (i = 1; i < n; ++i) { + /* Start next block hashing, wait and check status. */ + if ((sha256_next() != 0) || (sha256_wait_ready() != 0)) + return 1; + } + + /* XXX valid is probably set at the same time as ready */ + if (sha256_wait_valid() != 0) + return 1; + /* Extract the final digest. */ + for (i = 0; i < SHA256_DIGEST_LEN; ++i) { + if (sha256_read(SHA256_ADDR_DIGEST + i, expected[i]) != 0) + return 1; + } + + return 0; +} + +/* ---------------- SHA-512 test cases ---------------- */ + +int sha512_read(uint8_t addr, uint32_t data) +{ + return tc_read(SHA512_ADDR_PREFIX, addr, data); +} + +int sha512_write(uint8_t addr, uint32_t data) +{ + return tc_write(SHA512_ADDR_PREFIX, addr, data); +} + +int sha512_init(uint8_t mode) +{ + return tc_write(SHA512_ADDR_PREFIX, ADDR_CTRL, + CTRL_INIT_CMD + (mode << SHA512_CTRL_MODE_LOW)); +} + +int sha512_next(uint8_t mode) +{ + return tc_write(SHA512_ADDR_PREFIX, ADDR_CTRL, + CTRL_NEXT_CMD + (mode << SHA512_CTRL_MODE_LOW)); +} + +int sha512_wait_ready(void) +{ + return tc_wait_ready(SHA512_ADDR_PREFIX); +} + +int sha512_wait_valid(void) +{ + return tc_wait_valid(SHA512_ADDR_PREFIX); +} + +/* TC8: Read name and version from SHA-512 core. */ +int TC8(void) +{ + uint32_t name0 = 0x73686132; /* "sha2" */ + uint32_t name1 = 0x2d353132; /* "-512" */ + uint32_t version = 0x302e3830; /* "0.80" */ + + printf("TC8: Reading name, type and version words from SHA-512 core.\n"); + + return + sha512_read(ADDR_NAME0, name0) || + sha512_read(ADDR_NAME1, name1) || + sha512_read(ADDR_VERSION, version); +} + +/* TC9: SHA-512 Single block message test as specified by NIST. + We do this for all modes. */ +int tc9(uint8_t mode, const uint32_t *expected, int len) +{ + const uint32_t *block = NIST_1024_SINGLE; + int i; + + /* Write block to SHA-512. */ + for (i = 0; i < SHA512_BLOCK_LEN; ++i) { + if (sha512_write(SHA512_ADDR_BLOCK + i, block[i]) != 0) + return 1; + } + + /* Start initial block hashing, wait and check status. */ + if ((sha512_init(mode) != 0) || (sha512_wait_valid() != 0)) + return 1; + + /* Extract the digest. */ + for (i = 0; i < len/4; ++i) { + if (sha512_read(SHA512_ADDR_DIGEST + i, expected[i]) != 0) + return 1; + } + + return 0; +} + +int TC9(void) +{ + printf("TC9-1: Single block message test for SHA-512/224.\n"); + if (tc9(MODE_SHA_512_224, SHA512_224_SINGLE_DIGEST, + sizeof(SHA512_224_SINGLE_DIGEST)) != 0) + return 1; + + printf("TC9-2: Single block message test for SHA-512/256.\n"); + if (tc9(MODE_SHA_512_256, SHA512_256_SINGLE_DIGEST, + sizeof(SHA512_256_SINGLE_DIGEST)) != 0) + return 1; + + printf("TC9-3: Single block message test for SHA-384.\n"); + if (tc9(MODE_SHA_384, SHA384_SINGLE_DIGEST, + sizeof(SHA384_SINGLE_DIGEST)) != 0) + return 1; + + printf("TC9-4: Single block message test for SHA-512.\n"); + if (tc9(MODE_SHA_512, SHA512_SINGLE_DIGEST, + sizeof(SHA512_SINGLE_DIGEST)) != 0) + return 1; + + return 0; +} + +/* TC10: SHA-512 Double block message test as specified by NIST. + We do this for all modes. */ +int tc10(uint8_t mode, const uint32_t *expected, int len) +{ + const uint32_t *block[2] = { NIST_1024_DOUBLE0, NIST_1024_DOUBLE1 }; + int i; + + /* Write first block to SHA-512. */ + for (i = 0; i < SHA512_BLOCK_LEN; ++i) { + if (sha512_write(SHA512_ADDR_BLOCK + i, block[0][i]) != 0) + return 1; + } + + /* Start initial block hashing, wait and check status. */ + if ((sha512_init(mode) != 0) || (sha512_wait_ready() != 0)) + return 1; + + /* Write second block to SHA-512. */ + for (i = 0; i < SHA512_BLOCK_LEN; ++i) { + if (sha512_write(SHA512_ADDR_BLOCK + i, block[1][i]) != 0) + return 1; + } + + /* Start next block hashing, wait and check status. */ + if ((sha512_next(mode) != 0) || (sha512_wait_valid() != 0)) + return 1; + + /* Extract the digest. */ + for (i = 0; i < len/4; ++i) { + if (sha512_read(SHA512_ADDR_DIGEST + i, expected[i]) != 0) + return 1; + } + + return 0; +} + +int TC10(void) +{ + printf("TC10-1: Double block message test for SHA-512/224.\n"); + if (tc10(MODE_SHA_512_224, SHA512_224_DOUBLE_DIGEST, + sizeof(SHA512_224_DOUBLE_DIGEST)) != 0) + return 1; + + printf("TC10-2: Double block message test for SHA-512/256.\n"); + if (tc10(MODE_SHA_512_256, SHA512_256_DOUBLE_DIGEST, + sizeof(SHA512_256_DOUBLE_DIGEST)) != 0) + return 1; + + printf("TC10-3: Double block message test for SHA-384.\n"); + if (tc10(MODE_SHA_384, SHA384_DOUBLE_DIGEST, + sizeof(SHA384_DOUBLE_DIGEST)) != 0) + return 1; + + printf("TC10-4: Double block message test for SHA-512.\n"); + if (tc10(MODE_SHA_512, SHA512_DOUBLE_DIGEST, + sizeof(SHA512_DOUBLE_DIGEST)) != 0) + return 1; + + return 0; +} + +/* ---------------- main ---------------- */ + +int main(int argc, char *argv[]) +{ + typedef int (*tcfp)(void); + tcfp all_tests[] = { TC0, TC1, TC2, TC3, TC4, TC5, TC6, TC7, TC8, TC9, TC10 }; + tcfp sha1_tests[] = { TC1, TC2, TC3 }; + tcfp sha256_tests[] = { TC4, TC5, TC6, TC7 }; + tcfp sha512_tests[] = { TC8, TC9, TC10 }; + + char *usage = "Usage: %s [-d] [-i I2C_device] [-a I2C_addr] tc...\n"; + char *dev = I2C_dev; + int addr = I2C_addr; + int i, j, opt; + + while ((opt = getopt(argc, argv, "h?di:a:")) != -1) { + switch (opt) { + case 'h': + case '?': + printf(usage, argv[0]); + return 0; + case 'd': + debug = 1; + break; + case 'i': + dev = optarg; + break; + case 'a': + addr = (int)strtol(optarg, NULL, 0); + if ((addr < 0x03) || (addr > 0x77)) { + fprintf(stderr, "addr must be between 0x03 and 0x77\n"); + return 1; + } + break; + default: + fprintf(stderr, usage, argv[0]); + return 1; + } + } + + if (i2c_setup(dev, addr) != 0) + return 1; + + /* no args == run all tests */ + if (optind >= argc) { + for (j = 0; j < sizeof(all_tests)/sizeof(all_tests[0]); ++j) + if (all_tests[j]() != 0) + return 1; + return 0; + } + + for (i = optind; i < argc; ++i) { + if (strcmp(argv[i], "all") == 0) { + for (j = 0; j < sizeof(all_tests)/sizeof(all_tests[0]); ++j) + if (all_tests[j]() != 0) + return 1; + } + else if (strcmp(argv[i], "sha1") == 0) { + for (j = 0; j < sizeof(sha1_tests)/sizeof(sha1_tests[0]); ++j) + if (sha1_tests[j]() != 0) + return 1; + } + else if (strcmp(argv[i], "sha256") == 0) { + for (j = 0; j < sizeof(sha256_tests)/sizeof(sha256_tests[0]); ++j) + if (sha256_tests[j]() != 0) + return 1; + } + else if (strcmp(argv[i], "sha512") == 0) { + for (j = 0; j < sizeof(sha512_tests)/sizeof(sha512_tests[0]); ++j) + if (sha512_tests[j]() != 0) + return 1; + } + else if (isdigit(argv[i][0]) && + (((j = atoi(argv[i])) >= 0) && + (j < sizeof(all_tests)/sizeof(all_tests[0])))) { + if (all_tests[j]() != 0) + return 1; + } + else { + fprintf(stderr, "unknown test case %s\n", argv[i]); + return 1; + } + } + + return 0; +} diff --git a/i2c/ucf/novena_i2c.ucf b/i2c/ucf/novena_i2c.ucf new file mode 100644 index 0000000..02fc77e --- /dev/null +++ b/i2c/ucf/novena_i2c.ucf @@ -0,0 +1,82 @@ +#====================================================================== +# +# novena_ise.ucf +# -------------- +# Constraint file for implementing the Cryptech Novena base +# for the Xilinx Spartan6 LX45 on the Novena. +# +# +# Author: Pavel Shatov +# Copyright (c) 2014, NORDUnet A/S All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# - Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# - Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# - Neither the name of the NORDUnet nor the names of its contributors may +# be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#====================================================================== + +#------------------------------------------------------------------------------- +CONFIG VCCAUX = 3.3; +#------------------------------------------------------------------------------- + + +#-------------------------------------------------------------------------------- +# GCLK Timing +#-------------------------------------------------------------------------------- +NET "gclk_p_pin" TNM_NET = TNM_gclk; +TIMESPEC TS_gclk = PERIOD TNM_gclk 20 ns HIGH 50%; + + +#------------------------------------------------------------------------------- +# FPGA Pinout +#------------------------------------------------------------------------------- +NET "led_pin" LOC = "A16" | IOSTANDARD = "LVCMOS33" | SLEW = "SLOW" | DRIVE = 12; +NET "apoptosis_pin" LOC = "K1" | IOSTANDARD = "LVCMOS33" | SLEW = "SLOW" | DRIVE = 12; +NET "reset_mcu_b_pin" LOC = "F1" | IOSTANDARD = "LVCMOS33" | PULLUP; + +NET "gclk_p_pin" LOC = "H2" | IOSTANDARD = "LVDS_33" | DIFF_TERM = "TRUE"; +NET "gclk_n_pin" LOC = "H1" | IOSTANDARD = "LVDS_33" | DIFF_TERM = "TRUE"; + +NET "i2c_scl" LOC = "P4" | IOSTANDARD = LVCMOS33; +NET "i2c_sda" LOC = "P3" | IOSTANDARD = LVCMOS33; + +# Pins to the header where the LEDs on the Cryptech +# Avalanche Noise Board are connected. +NET "ct_led<0>" LOC = K6 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<1>" LOC = H4 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<2>" LOC = H3 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<3>" LOC = M1 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<4>" LOC = L7 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<5>" LOC = G1 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<6>" LOC = T2 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; +NET "ct_led<7>" LOC = H7 | IOSTANDARD = LVCMOS33 | SLEW = SLOW; + +# Pins to the header where the noise sources on the +# Cryptech Avalanche Noise Board are connected. +NET "ct_noise" LOC = L4 | IOSTANDARD = LVCMOS33; + +#====================================================================== +# EOF novena_i2c.ucf +#====================================================================== diff --git a/src/rtl/coretest_hashes.v b/src/rtl/coretest_hashes.v deleted file mode 100644 index fc2ccff..0000000 --- a/src/rtl/coretest_hashes.v +++ /dev/null @@ -1,321 +0,0 @@ -//====================================================================== -// -// coretest_hashes.v -// ----------------- -// Top level wrapper that creates the Cryptech coretest system. -// The wrapper contains instances of external interface, coretest -// and the core to be tested. And if more than one core is -// present the wrapper also includes address and data muxes. -// -// -// Author: Joachim Strombergson -// Copyright (c) 2014, SUNET -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or -// without modification, are permitted provided that the following -// conditions are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -//====================================================================== - -module coretest_hashes( - input wire clk, - input wire reset_n, - - // External interface. - input wire SCL, - input wire SDA, - output wire SDA_pd, - - output wire [7 : 0] debug - ); - - - //---------------------------------------------------------------- - // Internal constant and parameter definitions. - //---------------------------------------------------------------- - parameter I2C_DEVICE_ADDR = 7'h0f; - parameter I2C_ADDR_PREFIX = 8'h00; - parameter SHA1_ADDR_PREFIX = 8'h10; - parameter SHA256_ADDR_PREFIX = 8'h20; - parameter SHA512_ADDR_PREFIX = 8'h30; - - - //---------------------------------------------------------------- - // Wires. - //---------------------------------------------------------------- - // Coretest connections. - wire coretest_reset_n; - wire coretest_cs; - wire coretest_we; - wire [15 : 0] coretest_address; - wire [31 : 0] coretest_write_data; - reg [31 : 0] coretest_read_data; - reg coretest_error; - - // i2c connections - wire [6:0] i2c_device_addr; - wire i2c_rxd_syn; - wire [7 : 0] i2c_rxd_data; - wire i2c_rxd_ack; - wire i2c_txd_syn; - wire [7 : 0] i2c_txd_data; - wire i2c_txd_ack; - reg i2c_cs; - reg i2c_we; - reg [7 : 0] i2c_address; - reg [31 : 0] i2c_write_data; - wire [31 : 0] i2c_read_data; - wire i2c_error; - wire [7 : 0] i2c_debug; - - // sha1 connections. - reg sha1_cs; - reg sha1_we; - reg [7 : 0] sha1_address; - reg [31 : 0] sha1_write_data; - wire [31 : 0] sha1_read_data; - wire sha1_error; - wire [7 : 0] sha1_debug; - - // sha256 connections. - reg sha256_cs; - reg sha256_we; - reg [7 : 0] sha256_address; - reg [31 : 0] sha256_write_data; - wire [31 : 0] sha256_read_data; - wire sha256_error; - wire [7 : 0] sha256_debug; - - // sha512 connections. - reg sha512_cs; - reg sha512_we; - reg [7 : 0] sha512_address; - reg [31 : 0] sha512_write_data; - wire [31 : 0] sha512_read_data; - wire sha512_error; - wire [7 : 0] sha512_debug; - - - //---------------------------------------------------------------- - // Concurrent assignment. - //---------------------------------------------------------------- - assign debug = i2c_debug; - - - //---------------------------------------------------------------- - // Core instantiations. - //---------------------------------------------------------------- - coretest coretest( - .clk(clk), - .reset_n(reset_n), - - .rx_syn(i2c_rxd_syn), - .rx_data(i2c_rxd_data), - .rx_ack(i2c_rxd_ack), - - .tx_syn(i2c_txd_syn), - .tx_data(i2c_txd_data), - .tx_ack(i2c_txd_ack), - - // Interface to the core being tested. - .core_reset_n(coretest_reset_n), - .core_cs(coretest_cs), - .core_we(coretest_we), - .core_address(coretest_address), - .core_write_data(coretest_write_data), - .core_read_data(coretest_read_data), - .core_error(coretest_error) - ); - - - i2c i2c( - .clk(clk), - .reset_n(!reset_n), // active high - - .SCL(SCL), - .SDA(SDA), - .SDA_pd(SDA_pd), - .i2c_device_addr(i2c_device_addr), - - .rxd_syn(i2c_rxd_syn), - .rxd_data(i2c_rxd_data), - .rxd_ack(i2c_rxd_ack), - - .txd_syn(i2c_txd_syn), - .txd_data(i2c_txd_data), - .txd_ack(i2c_txd_ack), - - .cs(i2c_cs), - .we(i2c_we), - .address(i2c_address), - .write_data(i2c_write_data), - .read_data(i2c_read_data), - .error(i2c_error), - - .debug(i2c_debug) - ); - - - sha1 sha1( - // Clock and reset. - .clk(clk), - .reset_n(reset_n), - - // Control. - .cs(sha1_cs), - .we(sha1_we), - - // Data ports. - .address(sha1_address), - .write_data(sha1_write_data), - .read_data(sha1_read_data), - .error(sha1_error) - ); - - - sha256 sha256( - // Clock and reset. - .clk(clk), - .reset_n(reset_n), - - // Control. - .cs(sha256_cs), - .we(sha256_we), - - // Data ports. - .address(sha256_address), - .write_data(sha256_write_data), - .read_data(sha256_read_data), - .error(sha256_error) - ); - - - sha512 sha512( - // Clock and reset. - .clk(clk), - .reset_n(reset_n), - - // Control. - .cs(sha512_cs), - .we(sha512_we), - - // Data ports. - .address(sha512_address), - .write_data(sha512_write_data), - .read_data(sha512_read_data), - .error(sha512_error) - ); - - - //---------------------------------------------------------------- - // address_mux - // - // Combinational data mux that handles addressing between - // cores using the 32-bit memory like interface. - //---------------------------------------------------------------- - always @* - begin : address_mux - // Default assignments. - coretest_read_data = 32'h00000000; - coretest_error = 0; - - i2c_cs = 0; - i2c_we = 0; - i2c_address = 8'h00; - i2c_write_data = 32'h00000000; - - sha1_cs = 0; - sha1_we = 0; - sha1_address = 8'h00; - sha1_write_data = 32'h00000000; - - sha256_cs = 0; - sha256_we = 0; - sha256_address = 8'h00; - sha256_write_data = 32'h00000000; - - sha512_cs = 0; - sha512_we = 0; - sha512_address = 8'h00; - sha512_write_data = 32'h00000000; - - - if (i2c_device_addr == I2C_DEVICE_ADDR) - case (coretest_address[15 : 8]) - I2C_ADDR_PREFIX: - begin - i2c_cs = coretest_cs; - i2c_we = coretest_we; - i2c_address = coretest_address[7 : 0]; - i2c_write_data = coretest_write_data; - coretest_read_data = i2c_read_data; - coretest_error = i2c_error; - end - - - SHA1_ADDR_PREFIX: - begin - sha1_cs = coretest_cs; - sha1_we = coretest_we; - sha1_address = coretest_address[7 : 0]; - sha1_write_data = coretest_write_data; - coretest_read_data = sha1_read_data; - coretest_error = sha1_error; - end - - - SHA256_ADDR_PREFIX: - begin - sha256_cs = coretest_cs; - sha256_we = coretest_we; - sha256_address = coretest_address[7 : 0]; - sha256_write_data = coretest_write_data; - coretest_read_data = sha256_read_data; - coretest_error = sha256_error; - end - - - SHA512_ADDR_PREFIX: - begin - sha512_cs = coretest_cs; - sha512_we = coretest_we; - sha512_address = coretest_address[7 : 0]; - sha512_write_data = coretest_write_data; - coretest_read_data = sha512_read_data; - coretest_error = sha512_error; - end - - - default: - begin - end - endcase // case (coretest_address[15 : 8]) - end // address_mux - -endmodule // coretest_hashes - -//====================================================================== -// EOF coretest_hashes.v -//====================================================================== diff --git a/src/rtl/novena_fpga.v b/src/rtl/novena_fpga.v deleted file mode 100644 index fd0f667..0000000 --- a/src/rtl/novena_fpga.v +++ /dev/null @@ -1,147 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2013, Andrew "bunnie" Huang -// -// See the NOTICE file distributed with this work for additional -// information regarding copyright ownership. The copyright holder -// licenses this file to you under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// code distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -////////////////////////////////////////////////////////////////////////////// - -/// note: must set "-g UnusedPin:Pullnone" to avoid conflicts with unused pins - -`timescale 1ns / 1ps - -module novena_fpga( - // CPU side mapping - input wire [15:0] EIM_DA, - output reg EIM_A16, // relay of the trigger output - output reg EIM_A17, // relay of the trigger data (read path) - - // connector side mapping - //input wire F_LVDS_N3, // output of trigger - //input wire F_DX2, // output of trigger - //output wire F_LVDS_N5, // trigger reset - output wire F_LVDS_P4, // trigger reset - //inout wire F_LVDS_P5, // trigger data (bidir) - //input wire F_DX18, // trigger data in from sticker (DUT->CPU) - output wire F_LVDS_P11, // trigger data out to sticker (CPU->DUT) - //output wire F_LVDS_N8, // trigger clock - //output wire F_DX14, // trigger clock - - output wire F_LVDS_N7, // drive TPI data line - output wire F_LVDS_P7, // drive TPI signal lines - - output wire F_DX15, // 1 = drive 5V, 0 = drive 3V to DUT - - output wire F_LVDS_CK1_N, - output wire F_LVDS_CK1_P, - output wire F_LVDS_N11, - - output wire F_LVDS_N0, - output wire F_LVDS_P0, - output wire F_DX1, - - output wire F_LVDS_N15, - output wire F_LVDS_P15, - output wire F_LVDS_NC, - - //input wire F_DX11, - //input wire F_DX3, - //input wire F_DX0, - - //input wire F_LVDS_CK0_P, - //input wire F_LVDS_CK0_N, - //input wire F_LVDS_P9, - - //input wire [1:0] EIM_CS, - //input wire EIM_LBA, - - input wire CLK2_N, - input wire CLK2_P, - output wire FPGA_LED2, - - input wire I2C3_SCL, - inout wire I2C3_SDA, - - input wire RESETBMCU, - output wire F_DX17, // dummy - output wire APOPTOSIS -); - wire clk; - - IBUFGDS clkibufgds( - .I(CLK2_P), - .IB(CLK2_N), - .O(clk) - ); - - assign FPGA_LED2 = 1'b1; - - assign APOPTOSIS = 1'b0; - assign F_DX15 = 1'b1; //+5V P_DUT - - // OE on bank to drive signals; signal not inverted in software - assign F_LVDS_P7 = !EIM_DA[3]; - // OE on bank to drive the data; signal not inverted in software - assign F_LVDS_N7 = !EIM_DA[4]; - assign F_LVDS_P4 = 1'b0; - assign F_LVDS_P11 = 1'b0; - assign F_LVDS_CK1_N = 1'b0; - assign F_LVDS_CK1_P = 1'b0; - assign F_LVDS_N11 = 1'b0; - assign F_LVDS_N0 = 1'b0; - assign F_LVDS_P0 = 1'b0; - assign F_DX1 = 1'b0; - assign F_LVDS_N15 = 1'b0; - assign F_LVDS_P15 = 1'b0; - assign F_LVDS_NC = 1'b0; - - // reduction and of EIM_DA, dummy-map to keep compiler quiet - assign F_DX17 = &EIM_DA | RESETBMCU; - - //////////////////////////////////// - ///// I2C register set - //////////////////////////////////// - wire SDA_pd; - wire SDA_int; - reg clk25; - - initial begin - clk25 <= 1'b0; - end - always @ (posedge clk) begin - clk25 <= ~clk25; - EIM_A16 <= 1'b0; - EIM_A17 <= 1'b0; - end - - IOBUF #( - .DRIVE(8), - .SLEW("SLOW") - ) IOBUF_sda ( - .IO(I2C3_SDA), - .I(1'b0), - .T(!SDA_pd), - .O(SDA_int) - ); - - coretest_hashes top( - .clk(clk25), - .reset_n(1'b1), - - .SCL(I2C3_SCL), - .SDA(SDA_int), - .SDA_pd(SDA_pd) - ); - -endmodule diff --git a/src/sw/00-index.txt b/src/sw/00-index.txt deleted file mode 100644 index c704834..0000000 --- a/src/sw/00-index.txt +++ /dev/null @@ -1,12 +0,0 @@ -configure.sh - Configure a bitstream file onto the FPGA - -hash_tester.c - Test the hash cores -hash_tester.py - Same thing, only in Python - -hash.c - Hash an arbitrary file - -nist_512_single.bin - One-block test file for SHA-1 and SHA-256 -nist_512_double.bin - Two-block test file for SHA-1 and SHA-256 -nist_1024_single.bin - One-block test file for SHA-512 -nist_1024_double.bin - Two-block test file for SHA-512 -1000_block.bin - A large file for speed testing diff --git a/src/sw/1000_block.bin b/src/sw/1000_block.bin deleted file mode 100644 index 7e2b02b..0000000 Binary files a/src/sw/1000_block.bin and /dev/null differ diff --git a/src/sw/configure.sh b/src/sw/configure.sh deleted file mode 100755 index b3ed7cf..0000000 --- a/src/sw/configure.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -# bitbang a configuration to the FPGA on a Novena PVT1 -bitfile="${1-novena_fpga.bit}" -echo "Setting export of reset pin" -echo 135 > /sys/class/gpio/export -echo "setting reset pin to out" -echo out > /sys/class/gpio/gpio135/direction -echo "flipping reset" -echo 0 > /sys/class/gpio/gpio135/value -echo 1 > /sys/class/gpio/gpio135/value -echo "configuring FPGA" -dd if=${bitfile} of=/dev/spidev2.0 bs=128 -echo "turning on clock to FPGA" -# compile devmem2 from novena-scope-drivers/userspace/devmem2.c -./devmem2 0x020c8160 w 0x00000D2B diff --git a/src/sw/hash.c b/src/sw/hash.c deleted file mode 100644 index 29110eb..0000000 --- a/src/sw/hash.c +++ /dev/null @@ -1,620 +0,0 @@ -/* - * hash.c - * ------ - * This program uses the coretest_hashes subsystem to produce a - * cryptographic hash of a file or input stream. It is a generalization - * of the hash_tester.c test program. - * - * Authors: Joachim Strömbergson, Paul Selkirk - * Copyright (c) 2014, SUNET - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -char *usage = -"Usage: %s [-d] [-v] [-q] [-i I2C_device] [-a I2C_addr] [algorithm [file]]\n" -"algorithms: sha-1, sha-256, sha-512/224, sha-512/256, sha-384, sha-512\n"; - -/* I2C configuration */ -#define I2C_dev "/dev/i2c-2" -#define I2C_addr 0x0f - -/* command codes */ -#define SOC 0x55 -#define EOC 0xaa -#define READ_CMD 0x10 -#define WRITE_CMD 0x11 -#define RESET_CMD 0x01 - -/* response codes */ -#define SOR 0xaa -#define EOR 0x55 -#define READ_OK 0x7f -#define WRITE_OK 0x7e -#define RESET_OK 0x7d -#define UNKNOWN 0xfe -#define ERROR 0xfd - -/* addresses and codes common to all hash cores */ -#define ADDR_NAME0 0x00 -#define ADDR_NAME1 0x01 -#define ADDR_VERSION 0x02 -#define ADDR_CTRL 0x08 -#define CTRL_INIT_CMD 1 -#define CTRL_NEXT_CMD 2 -#define ADDR_STATUS 0x09 -#define STATUS_READY_BIT 0 -#define STATUS_VALID_BIT 1 - -/* addresses and codes for the specific hash cores */ -/* block and digest lengths are number of bytes */ -#define SHA1_ADDR_PREFIX 0x10 -#define SHA1_ADDR_BLOCK 0x10 -#define SHA1_BLOCK_LEN 512/8 -#define SHA1_ADDR_DIGEST 0x20 -#define SHA1_DIGEST_LEN 160/8 - -#define SHA256_ADDR_PREFIX 0x20 -#define SHA256_ADDR_BLOCK 0x10 -#define SHA256_BLOCK_LEN 512/8 -#define SHA256_ADDR_DIGEST 0x20 -#define SHA256_DIGEST_LEN 256/8 - -#define SHA512_ADDR_PREFIX 0x30 -#define SHA512_CTRL_MODE_LOW 2 -#define SHA512_CTRL_MODE_HIGH 3 -#define SHA512_ADDR_BLOCK 0x10 -#define SHA512_BLOCK_LEN 1024/8 -#define SHA512_ADDR_DIGEST 0x40 -#define SHA512_224_DIGEST_LEN 224/8 -#define SHA512_256_DIGEST_LEN 256/8 -#define SHA384_DIGEST_LEN 384/8 -#define SHA512_DIGEST_LEN 512/8 -#define MODE_SHA512_224 0 -#define MODE_SHA512_256 1 -#define MODE_SHA384 2 -#define MODE_SHA512 3 - -int i2cfd; -int debug = 0; -int verbose = 0; - -/* ---------------- algorithm lookup code ---------------- */ - -struct ctrl { - char *name; - uint8_t addr_prefix; - uint8_t addr_block; - uint8_t block_len; - uint8_t addr_digest; - uint8_t digest_len; - uint8_t mode; -} ctrl[] = { - { "sha-1", SHA1_ADDR_PREFIX, SHA1_ADDR_BLOCK, SHA1_BLOCK_LEN, - SHA1_ADDR_DIGEST, SHA1_DIGEST_LEN, 0 }, - { "sha-256", SHA256_ADDR_PREFIX, SHA256_ADDR_BLOCK, SHA256_BLOCK_LEN, - SHA256_ADDR_DIGEST, SHA256_DIGEST_LEN, 0 }, - { "sha-512/224", SHA512_ADDR_PREFIX, SHA512_ADDR_BLOCK, SHA512_BLOCK_LEN, - SHA512_ADDR_DIGEST, SHA512_224_DIGEST_LEN, MODE_SHA512_224 }, - { "sha-512/256", SHA512_ADDR_PREFIX, SHA512_ADDR_BLOCK, SHA512_BLOCK_LEN, - SHA512_ADDR_DIGEST, SHA512_256_DIGEST_LEN, MODE_SHA512_256 }, - { "sha-384", SHA512_ADDR_PREFIX, SHA512_ADDR_BLOCK, SHA512_BLOCK_LEN, - SHA512_ADDR_DIGEST, SHA384_DIGEST_LEN, MODE_SHA384 }, - { "sha-512", SHA512_ADDR_PREFIX, SHA512_ADDR_BLOCK, SHA512_BLOCK_LEN, - SHA512_ADDR_DIGEST, SHA512_DIGEST_LEN, MODE_SHA512 }, - { NULL, 0, 0, 0 } -}; - -/* return the control structure for the given algorithm */ -struct ctrl *find_algo(char *algo) -{ - int i; - - for (i = 0; ctrl[i].name != NULL; ++i) - if (strcmp(ctrl[i].name, algo) == 0) - return &ctrl[i]; - - fprintf(stderr, "algorithm \"%s\" not found\n\n", algo); - fprintf(stderr, usage, "hash"); - return NULL; -} - -/* ---------------- I2C low-level code ---------------- */ - -int i2c_open(char *dev, int addr) -{ - i2cfd = open(dev, O_RDWR); - if (i2cfd < 0) { - fprintf(stderr, "Unable to open %s: ", dev); - perror(""); - i2cfd = 0; - return 1; - } - - if (ioctl(i2cfd, I2C_SLAVE, addr) < 0) { - fprintf(stderr, "Unable to set I2C slave device 0x%02x: ", addr); - perror(""); - return 1; - } - - return 0; -} - -void i2c_close(void) -{ - close(i2cfd); -} - -int i2c_write(uint8_t *buf, int len) -{ - if (debug) { - int i; - printf("write ["); - for (i = 0; i < len; ++i) - printf(" %02x", buf[i]); - printf(" ]\n"); - } - - if (write(i2cfd, buf, len) != len) { - perror("i2c write failed"); - return 1; - } - - return 0; -} - -int i2c_read(uint8_t *b) -{ - /* read() on the i2c device only returns one byte at a time, - * and tc_get_resp() needs to parse the response one byte at a time - */ - if (read(i2cfd, b, 1) != 1) { - perror("i2c read failed"); - return 1; - } - - return 0; -} - -/* ---------------- test-case low-level code ---------------- */ - -int tc_send_write_cmd(uint8_t addr0, uint8_t addr1, uint8_t *data) -{ - uint8_t buf[9] = { SOC, WRITE_CMD, addr0, addr1, - data[0], data[1], data[2], data[3], EOC }; - - return i2c_write(buf, sizeof(buf)); -} - -int tc_send_read_cmd(uint8_t addr0, uint8_t addr1) -{ - uint8_t buf[5] = { SOC, READ_CMD, addr0, addr1, EOC }; - - return i2c_write(buf, sizeof(buf)); -} - -int tc_get_resp(uint8_t *buf, int len) -{ - int i; - - for (i = 0; i < len; ++i) { - if (i2c_read(&buf[i]) != 0) - return 1; - if ((i == 0) && (buf[i] != SOR)) { - /* we've gotten out of sync, and there's probably nothing we can do */ - fprintf(stderr, "response byte 0: expected 0x%02x (SOR), got 0x%02x\n", - SOR, buf[0]); - return 1; - } - else if (i == 1) { /* response code */ - switch (buf[i]) { - case READ_OK: - len = 9; - break; - case WRITE_OK: - len = 5; - break; - case RESET_OK: - len = 3; - break; - case ERROR: - case UNKNOWN: - len = 4; - break; - default: - /* we've gotten out of sync, and there's probably nothing we can do */ - fprintf(stderr, "unknown response code 0x%02x\n", buf[i]); - return 1; - } - } - } - - if (debug) { - printf("read ["); - for (i = 0; i < len; ++i) - printf(" %02x", buf[i]); - printf(" ]\n"); - } - - return 0; -} - -int tc_compare(uint8_t *buf, uint8_t *expected, int len) -{ - int i; - - /* start at byte 1 because SOR has already been tested */ - for (i = 1; i < len; ++i) { - if (buf[i] != expected[i]) { - fprintf(stderr, "response byte %d: expected 0x%02x, got 0x%02x\n", - i, expected[i], buf[i]); - return 1; - } - } - - return 0; -} - -int tc_get_write_resp(uint8_t addr0, uint8_t addr1) -{ - uint8_t buf[5]; - uint8_t expected[5] = { SOR, WRITE_OK, addr0, addr1, EOR }; - - return - tc_get_resp(buf, sizeof(buf)) || - tc_compare(buf, expected, sizeof(expected)); -} - -int tc_get_read_resp(uint8_t addr0, uint8_t addr1, uint8_t *data) -{ - uint8_t buf[9]; - uint8_t expected[4] = { SOR, READ_OK, addr0, addr1 }; - - if ((tc_get_resp(buf, sizeof(buf)) != 0) || - (tc_compare(buf, expected, 4) != 0) || buf[8] != EOR) - return 1; - - data[0] = buf[4]; - data[1] = buf[5]; - data[2] = buf[6]; - data[3] = buf[7]; - - return 0; -} - -int tc_write(uint8_t addr0, uint8_t addr1, uint8_t *data) -{ - return (tc_send_write_cmd(addr0, addr1, data) || - tc_get_write_resp(addr0, addr1)); -} - -int tc_read(uint8_t addr0, uint8_t addr1, uint8_t *data) -{ - return (tc_send_read_cmd(addr0, addr1) || - tc_get_read_resp(addr0, addr1, data)); -} - -int tc_init(uint8_t addr0, uint8_t mode) -{ - uint8_t buf[4] = { 0, 0, 0, CTRL_INIT_CMD }; - - if (addr0 == SHA512_ADDR_PREFIX) - buf[3] += (mode << SHA512_CTRL_MODE_LOW); - - return tc_write(addr0, ADDR_CTRL, buf); -} - -int tc_next(uint8_t addr0, uint8_t mode) -{ - uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT_CMD }; - - if (addr0 == SHA512_ADDR_PREFIX) - buf[3] += (mode << SHA512_CTRL_MODE_LOW); - - return tc_write(addr0, ADDR_CTRL, buf); -} - -int tc_wait(uint8_t addr0, uint8_t status) -{ - uint8_t buf[4]; - - do { - if (tc_read(addr0, ADDR_STATUS, &buf[0]) != 0) - return 1; - } while ((buf[3] & status) != status); - - return 0; -} - -int tc_wait_ready(uint8_t addr0) -{ - return tc_wait(addr0, STATUS_READY_BIT); -} - -int tc_wait_valid(uint8_t addr0) -{ - return tc_wait(addr0, STATUS_VALID_BIT); -} - -int tc_write_block(uint8_t addr0, uint8_t addr1, uint8_t *buf, int len) -{ - int i; - - for (i = 0; i < len/4; ++i) { - if (tc_write(addr0, addr1 + i, &buf[i*4]) != 0) - return 1; - } - - return 0; -} - -int tc_read_digest(uint8_t addr0, uint8_t addr1, uint8_t *buf, int len) -{ - int i; - - for (i = 0; i < len/4; ++i) { - if (tc_read(addr0, addr1 + i, &buf[i*4]) != 0) - return 1; - } - - return 0; -} - -/* ---------------- hash ---------------- */ - -int transmit(uint8_t *block, uint8_t blen, uint8_t addr0, uint8_t baddr, - uint8_t mode, int first) -{ - int i; - - if (debug) { - printf("write ["); - for (i = 0; i < blen; ++i) - printf(" %02x", block[i]); - printf(" ]\n"); - } - - if (tc_write_block(addr0, baddr, block, blen) != 0) { - return 1; - } - if (first) { - if (tc_init(addr0, mode) != 0) - return 1; - } - else { - if (tc_next(addr0, mode) != 0) - return 1; - } - if (tc_wait_ready(addr0) != 0) - return 1; - - return 0; -} - -int pad_transmit(uint8_t *block, uint8_t flen, uint8_t blen, - uint8_t addr0, uint8_t baddr, uint8_t mode, - long long tlen, int first) -{ - assert(flen < blen); - - block[flen++] = 0x80; - memset(block + flen, 0, blen - flen); - - if (blen - flen < ((blen == 64) ? 8 : 16)) { - if (transmit(block, blen, addr0, baddr, mode, first) != 0) - return 1; - first = 0; - memset(block, 0, blen); - } - - /* properly the length is 128 bits for sha-512, but we can't - * actually count above 64 bits - */ - ((uint32_t *)block)[blen/4 - 2] = htonl((tlen >> 32) & 0xffff); - ((uint32_t *)block)[blen/4 - 1] = htonl(tlen & 0xffff); - - return transmit(block, blen, addr0, baddr, mode, first); -} - -/* return number of digest bytes read */ -int hash(char *algo, char *file, uint8_t *digest) -{ - uint8_t block[SHA512_BLOCK_LEN]; - struct ctrl *ctrl; - int in_fd = 0; /* stdin */ - uint8_t addr0, baddr, blen, daddr, dlen, mode; - int nblk, nread, first; - int ret = -1; - struct timeval start, stop, difftime; - - ctrl = find_algo(algo); - if (ctrl == NULL) - return -1; - addr0 = ctrl->addr_prefix; - baddr = ctrl->addr_block; - blen = ctrl->block_len; - daddr = ctrl->addr_digest; - dlen = ctrl->digest_len; - mode = ctrl->mode; - - if (strcmp(file, "-") != 0) { - in_fd = open(file, O_RDONLY); - if (in_fd < 0) { - perror("open"); - return -1; - } - } - - if (verbose) { - if (gettimeofday(&start, NULL) < 0) { - perror("gettimeofday"); - goto out; - } - } - - for (nblk = 0, first = 1; ; ++nblk, first = 0) { - nread = read(in_fd, block, blen); - if (nread < 0) { - /* read error */ - perror("read"); - goto out; - } - else if (nread < blen) { - /* partial read = last block */ - if (pad_transmit(block, nread, blen, addr0, baddr, mode, - (nblk * blen + nread) * 8, first) != 0) - goto out; - break; - } - else { - /* full block read */ - if (transmit(block, blen, addr0, baddr, mode, first) != 0) - goto out; - } - } - - if (tc_wait_valid(addr0) != 0) - goto out; - if (tc_read_digest(addr0, daddr, digest, dlen) != 0) { - perror("i2c read failed"); - goto out; - } - - if (verbose) { - if (gettimeofday(&stop, NULL) < 0) { - perror("gettimeofday"); - goto out; - } - timersub(&stop, &start, &difftime); - printf("%d blocks written in %d.%03d sec (%.3f blocks/sec)\n", - nblk, (int)difftime.tv_sec, (int)difftime.tv_usec/1000, - (float)nblk / ((float)difftime.tv_sec + ((float)difftime.tv_usec)/1000000)); - } - - ret = dlen; -out: - if (in_fd != 0) - close(in_fd); - return ret; -} - -/* ---------------- main ---------------- */ - -int main(int argc, char *argv[]) -{ - char *dev = I2C_dev; - int addr = I2C_addr; - int i, opt, quiet = 0; - char *algo = "sha-1"; - char *file = "-"; - uint8_t digest[512/8]; - int dlen; - - while ((opt = getopt(argc, argv, "h?dvqi:a:")) != -1) { - switch (opt) { - case 'h': - case '?': - printf(usage, argv[0]); - return 0; - case 'd': - debug = 1; - break; - case 'v': - verbose = 1; - break; - case 'q': - quiet = 1; - break; - case 'i': - dev = optarg; - break; - case 'a': - addr = (int)strtol(optarg, NULL, 0); - if ((addr < 0x03) || (addr > 0x77)) { - fprintf(stderr, "addr must be between 0x03 and 0x77\n"); - return 1; - } - break; - default: - fprintf(stderr, usage, argv[0]); - return 1; - } - } - - if (optind < argc) { - algo = argv[optind]; - ++optind; - } - else { - if (!quiet) - printf("defaulting to algorithm \"%s\"\n", algo); - } - - if (optind < argc) { - file = argv[optind]; - ++optind; - } - else { - if (!quiet) - printf("reading from stdin\n"); - } - - if (i2c_open(dev, addr) != 0) - return -1; - - dlen = hash(algo, file, digest); - if (dlen < 0) - return 1; - - for (i = 0; i < dlen; ++i) { - printf("%02x", digest[i]); - if (i % 16 == 15) - printf("\n"); - else if (i % 4 == 3) - printf(" "); - } - if (dlen % 16 != 0) - printf("\n"); - - i2c_close(); - - return 0; -} diff --git a/src/sw/hash_tester.c b/src/sw/hash_tester.c deleted file mode 100644 index 04f6c6d..0000000 --- a/src/sw/hash_tester.c +++ /dev/null @@ -1,981 +0,0 @@ -/* - * hash_tester.c - * -------------- - * This program sends several commands to the coretest_hashes subsystem - * in order to verify the SHA-1, SHA-256 and SHA-512/x hash function - * cores. - * - * Note: This version of the program talks to the FPGA over an I2C bus. - * - * The single and dual block test cases are taken from the - * NIST KAT document: - * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA_All.pdf - * - * - * Authors: Joachim Strömbergson, Paul Selkirk - * Copyright (c) 2014, SUNET - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* I2C configuration */ -#define I2C_dev "/dev/i2c-2" -#define I2C_addr 0x0f - -/* command codes */ -#define SOC 0x55 -#define EOC 0xaa -#define READ_CMD 0x10 -#define WRITE_CMD 0x11 -#define RESET_CMD 0x01 - -/* response codes */ -#define SOR 0xaa -#define EOR 0x55 -#define READ_OK 0x7f -#define WRITE_OK 0x7e -#define RESET_OK 0x7d -#define UNKNOWN 0xfe -#define ERROR 0xfd - -/* addresses and codes common to all hash cores */ -#define ADDR_NAME0 0x00 -#define ADDR_NAME1 0x01 -#define ADDR_VERSION 0x02 -#define ADDR_CTRL 0x08 -#define CTRL_INIT_CMD 1 -#define CTRL_NEXT_CMD 2 -#define ADDR_STATUS 0x09 -#define STATUS_READY_BIT 1 -#define STATUS_VALID_BIT 2 - -/* addresses and codes for the specific hash cores */ -#define SHA1_ADDR_PREFIX 0x10 -#define SHA1_ADDR_BLOCK 0x10 -#define SHA1_BLOCK_LEN 16 -#define SHA1_ADDR_DIGEST 0x20 -#define SHA1_DIGEST_LEN 5 - -#define SHA256_ADDR_PREFIX 0x20 -#define SHA256_ADDR_BLOCK 0x10 -#define SHA256_BLOCK_LEN 16 -#define SHA256_ADDR_DIGEST 0x20 -#define SHA256_DIGEST_LEN 8 - -#define SHA512_ADDR_PREFIX 0x30 -#define SHA512_CTRL_MODE_LOW 2 -#define SHA512_CTRL_MODE_HIGH 3 -#define SHA512_ADDR_BLOCK 0x10 -#define SHA512_BLOCK_LEN 32 -#define SHA512_ADDR_DIGEST 0x40 -#define SHA512_DIGEST_LEN 16 -#define MODE_SHA_512_224 0 -#define MODE_SHA_512_256 1 -#define MODE_SHA_384 2 -#define MODE_SHA_512 3 - -int i2cfd; -int debug = 0; - -/* SHA-1/SHA-256 One Block Message Sample - Input Message: "abc" */ -const uint32_t NIST_512_SINGLE[] = -{ 0x61626380, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000018 }; - -const uint32_t SHA1_SINGLE_DIGEST[] = -{ 0xa9993e36, 0x4706816a, 0xba3e2571, 0x7850c26c, - 0x9cd0d89d }; - -const uint32_t SHA256_SINGLE_DIGEST[] = -{ 0xBA7816BF, 0x8F01CFEA, 0x414140DE, 0x5DAE2223, - 0xB00361A3, 0x96177A9C, 0xB410FF61, 0xF20015AD }; - -/* SHA-1/SHA-256 Two Block Message Sample - Input Message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" */ -const uint32_t NIST_512_DOUBLE0[] = -{ 0x61626364, 0x62636465, 0x63646566, 0x64656667, - 0x65666768, 0x66676869, 0x6768696A, 0x68696A6B, - 0x696A6B6C, 0x6A6B6C6D, 0x6B6C6D6E, 0x6C6D6E6F, - 0x6D6E6F70, 0x6E6F7071, 0x80000000, 0x00000000 }; -const uint32_t NIST_512_DOUBLE1[] = -{ 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x000001C0 }; - -const uint32_t SHA1_DOUBLE_DIGEST[] = -{ 0x84983E44, 0x1C3BD26E, 0xBAAE4AA1, 0xF95129E5, - 0xE54670F1 }; - -const uint32_t SHA256_DOUBLE_DIGEST[] = -{ 0x248D6A61, 0xD20638B8, 0xE5C02693, 0x0C3E6039, - 0xA33CE459, 0x64FF2167, 0xF6ECEDD4, 0x19DB06C1 }; - -/* SHA-512 One Block Message Sample - Input Message: "abc" */ -const uint32_t NIST_1024_SINGLE[] = -{ 0x61626380, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000018 }; - -const uint32_t SHA512_224_SINGLE_DIGEST[] = -{ 0x4634270f, 0x707b6a54, 0xdaae7530, 0x460842e2, - 0x0e37ed26, 0x5ceee9a4, 0x3e8924aa }; -const uint32_t SHA512_256_SINGLE_DIGEST[] = -{ 0x53048e26, 0x81941ef9, 0x9b2e29b7, 0x6b4c7dab, - 0xe4c2d0c6, 0x34fc6d46, 0xe0e2f131, 0x07e7af23 }; -const uint32_t SHA384_SINGLE_DIGEST[] = -{ 0xcb00753f, 0x45a35e8b, 0xb5a03d69, 0x9ac65007, - 0x272c32ab, 0x0eded163, 0x1a8b605a, 0x43ff5bed, - 0x8086072b, 0xa1e7cc23, 0x58baeca1, 0x34c825a7 }; -const uint32_t SHA512_SINGLE_DIGEST[] = -{ 0xddaf35a1, 0x93617aba, 0xcc417349, 0xae204131, - 0x12e6fa4e, 0x89a97ea2, 0x0a9eeee6, 0x4b55d39a, - 0x2192992a, 0x274fc1a8, 0x36ba3c23, 0xa3feebbd, - 0x454d4423, 0x643ce80e, 0x2a9ac94f, 0xa54ca49f }; - -/* SHA-512 Two Block Message Sample - Input Message: "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" - "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" */ -const uint32_t NIST_1024_DOUBLE0[] = -{ 0x61626364, 0x65666768, 0x62636465, 0x66676869, - 0x63646566, 0x6768696a, 0x64656667, 0x68696a6b, - 0x65666768, 0x696a6b6c, 0x66676869, 0x6a6b6c6d, - 0x6768696a, 0x6b6c6d6e, 0x68696a6b, 0x6c6d6e6f, - 0x696a6b6c, 0x6d6e6f70, 0x6a6b6c6d, 0x6e6f7071, - 0x6b6c6d6e, 0x6f707172, 0x6c6d6e6f, 0x70717273, - 0x6d6e6f70, 0x71727374, 0x6e6f7071, 0x72737475, - 0x80000000, 0x00000000, 0x00000000, 0x00000000 }; -const uint32_t NIST_1024_DOUBLE1[] = -{ 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000380 }; - -const uint32_t SHA512_224_DOUBLE_DIGEST[] = -{ 0x23fec5bb, 0x94d60b23, 0x30819264, 0x0b0c4533, - 0x35d66473, 0x4fe40e72, 0x68674af9 }; -const uint32_t SHA512_256_DOUBLE_DIGEST[] = -{ 0x3928e184, 0xfb8690f8, 0x40da3988, 0x121d31be, - 0x65cb9d3e, 0xf83ee614, 0x6feac861, 0xe19b563a }; -const uint32_t SHA384_DOUBLE_DIGEST[] = -{ 0x09330c33, 0xf71147e8, 0x3d192fc7, 0x82cd1b47, - 0x53111b17, 0x3b3b05d2, 0x2fa08086, 0xe3b0f712, - 0xfcc7c71a, 0x557e2db9, 0x66c3e9fa, 0x91746039 }; -const uint32_t SHA512_DOUBLE_DIGEST[] = -{ 0x8e959b75, 0xdae313da, 0x8cf4f728, 0x14fc143f, - 0x8f7779c6, 0xeb9f7fa1, 0x7299aead, 0xb6889018, - 0x501d289e, 0x4900f7e4, 0x331b99de, 0xc4b5433a, - 0xc7d329ee, 0xb6dd2654, 0x5e96e55b, 0x874be909 }; - -/* ---------------- I2C low-level code ---------------- */ -int i2c_setup(char *dev, int addr) -{ - i2cfd = open(dev, O_RDWR); - if (i2cfd < 0) { - fprintf(stderr, "Unable to open %s: ", dev); - perror(""); - i2cfd = 0; - return 1; - } - - if (ioctl(i2cfd, I2C_SLAVE, addr) < 0) { - fprintf(stderr, "Unable to set I2C slave device 0x%02x: ", addr); - perror(""); - return 1; - } - - return 0; -} - -int i2c_write(uint8_t *buf, int len) -{ - if (debug) { - int i; - printf("write ["); - for (i = 0; i < len; ++i) - printf(" %02x", buf[i]); - printf(" ]\n"); - } - - if (write(i2cfd, buf, len) != len) { - perror("i2c write failed"); - return 1; - } - - return 0; -} - -int i2c_read(uint8_t *b) -{ - /* read() on the i2c device only returns one byte at a time, - * and tc_get_resp() needs to parse the response one byte at a time - */ - if (read(i2cfd, b, 1) != 1) { - perror("i2c read failed"); - return 1; - } - - return 0; -} - -/* ---------------- test-case low-level code ---------------- */ -int tc_send_write_cmd(uint8_t addr0, uint8_t addr1, uint32_t data) -{ - uint8_t buf[9]; - - buf[0] = SOC; - buf[1] = WRITE_CMD; - buf[2] = addr0; - buf[3] = addr1; - buf[4] = (data >> 24) & 0xff; - buf[5] = (data >> 16) & 0xff; - buf[6] = (data >> 8) & 0xff; - buf[7] = data & 0xff; - buf[8] = EOC; - - return i2c_write(buf, sizeof(buf)); -} - -int tc_send_read_cmd(uint8_t addr0, uint8_t addr1) -{ - uint8_t buf[5]; - - buf[0] = SOC; - buf[1] = READ_CMD; - buf[2] = addr0; - buf[3] = addr1; - buf[4] = EOC; - - return i2c_write(buf, sizeof(buf)); -} - -int tc_get_resp(uint8_t *buf, int len) -{ - int i; - - for (i = 0; i < len; ++i) { - if (i2c_read(&buf[i]) != 0) - return 1; - if ((i == 0) && (buf[i] != SOR)) { - /* we've gotten out of sync, and there's probably nothing we can do */ - fprintf(stderr, "response byte 0: expected 0x%02x (SOR), got 0x%02x\n", - SOR, buf[0]); - return 1; - } - else if (i == 1) { /* response code */ - switch (buf[i]) { - case READ_OK: - len = 9; - break; - case WRITE_OK: - len = 5; - break; - case RESET_OK: - len = 3; - break; - case ERROR: - case UNKNOWN: - len = 4; - break; - default: - /* we've gotten out of sync, and there's probably nothing we can do */ - fprintf(stderr, "unknown response code 0x%02x\n", buf[i]); - return 1; - } - } - } - - if (debug) { - printf("read ["); - for (i = 0; i < len; ++i) - printf(" %02x", buf[i]); - printf(" ]\n"); - } - - return 0; -} - -int tc_get_expected(uint8_t *expected, int len) -{ - uint8_t buf[9]; - int i; - - if (tc_get_resp(buf, sizeof(buf)) != 0) - return 1; - - for (i = 0; i < len; ++i) { - if (buf[i] != expected[i]) { - fprintf(stderr, "response byte %d: expected 0x%02x, got 0x%02x\n", - i, expected[i], buf[i]); - return 1; - } - } - - return 0; -} - -int tc_get_write_resp(uint8_t addr0, uint8_t addr1) -{ - uint8_t expected[5]; - - expected[0] = SOR; - expected[1] = WRITE_OK; - expected[2] = addr0; - expected[3] = addr1; - expected[4] = EOR; - - return tc_get_expected(expected, sizeof(expected)); -} - -int tc_get_read_resp(uint8_t addr0, uint8_t addr1, uint32_t data) -{ - uint8_t expected[9]; - - expected[0] = SOR; - expected[1] = READ_OK; - expected[2] = addr0; - expected[3] = addr1; - expected[4] = (data >> 24) & 0xff; - expected[5] = (data >> 16) & 0xff; - expected[6] = (data >> 8) & 0xff; - expected[7] = data & 0xff; - expected[8] = EOR; - - return tc_get_expected(expected, sizeof(expected)); -} - -int tc_write(uint8_t addr0, uint8_t addr1, uint32_t data) -{ - return (tc_send_write_cmd(addr0, addr1, data) || - tc_get_write_resp(addr0, addr1)); -} - -int tc_read(uint8_t addr0, uint8_t addr1, uint32_t data) -{ - return (tc_send_read_cmd(addr0, addr1) || - tc_get_read_resp(addr0, addr1, data)); -} - -int tc_init(uint8_t addr0) -{ - return tc_write(addr0, ADDR_CTRL, CTRL_INIT_CMD); -} - -int tc_next(uint8_t addr0) -{ - return tc_write(addr0, ADDR_CTRL, CTRL_NEXT_CMD); -} - -int tc_wait(uint8_t addr0, uint8_t status) -{ - uint8_t buf[9]; - - do { - if (tc_send_read_cmd(addr0, ADDR_STATUS) != 0) - return 1; - if (tc_get_resp(buf, 9) != 0) - return 1; - if (buf[1] != READ_OK) - return 1; - } while ((buf[7] & status) != status); - - return 0; -} - -int tc_wait_ready(uint8_t addr0) -{ - return tc_wait(addr0, STATUS_READY_BIT); -} - -int tc_wait_valid(uint8_t addr0) -{ - return tc_wait(addr0, STATUS_VALID_BIT); -} - -/* ---------------- SHA-1 test cases ---------------- */ - -int sha1_read(uint8_t addr, uint32_t data) -{ - return tc_read(SHA1_ADDR_PREFIX, addr, data); -} - -int sha1_write(uint8_t addr, uint32_t data) -{ - return tc_write(SHA1_ADDR_PREFIX, addr, data); -} - -int sha1_init(void) -{ - return tc_init(SHA1_ADDR_PREFIX); -} - -int sha1_next(void) -{ - return tc_next(SHA1_ADDR_PREFIX); -} - -int sha1_wait_ready(void) -{ - return tc_wait_ready(SHA1_ADDR_PREFIX); -} - -int sha1_wait_valid(void) -{ - return tc_wait_valid(SHA1_ADDR_PREFIX); -} - -/* TC1: Read name and version from SHA-1 core. */ -int TC1(void) -{ - uint32_t name0 = 0x73686131; /* "sha1" */ - uint32_t name1 = 0x20202020; /* " " */ - uint32_t version = 0x302e3530; /* "0.50" */ - - printf("TC1: Reading name, type and version words from SHA-1 core.\n"); - - return - sha1_read(ADDR_NAME0, name0) || - sha1_read(ADDR_NAME1, name1) || - sha1_read(ADDR_VERSION, version); -} - -/* TC2: SHA-1 Single block message test as specified by NIST. */ -int TC2(void) -{ - const uint32_t *block = NIST_512_SINGLE; - const uint32_t *expected = SHA1_SINGLE_DIGEST; - int i; - - printf("TC2: Single block message test for SHA-1.\n"); - - /* Write block to SHA-1. */ - for (i = 0; i < SHA1_BLOCK_LEN; ++i) { - if (sha1_write(SHA1_ADDR_BLOCK + i, block[i]) != 0) - return 1; - } - - /* Start initial block hashing, wait and check status. */ - if ((sha1_init() != 0) || (sha1_wait_valid() != 0)) - return 1; - - /* Extract the digest. */ - for (i = 0; i < SHA1_DIGEST_LEN; ++i) { - if (sha1_read(SHA1_ADDR_DIGEST + i, expected[i]) != 0) - return 1; - } - - return 0; -} - -/* TC3: SHA-1 Double block message test as specified by NIST. */ -int TC3(void) -{ - const uint32_t *block[2] = { NIST_512_DOUBLE0, NIST_512_DOUBLE1 }; - static const uint32_t block0_expected[] = - { 0xF4286818, 0xC37B27AE, 0x0408F581, 0x84677148, 0x4A566572 }; - const uint32_t *expected = SHA1_DOUBLE_DIGEST; - int i; - - printf("TC3: Double block message test for SHA-1.\n"); - - /* Write first block to SHA-1. */ - for (i = 0; i < SHA1_BLOCK_LEN; ++i) { - if (sha1_write(SHA1_ADDR_BLOCK + i, block[0][i]) != 0) - return 1; - } - - /* Start initial block hashing, wait and check status. */ - if ((sha1_init() != 0) || (sha1_wait_valid() != 0)) - return 1; - - /* Extract the first digest. */ - for (i = 0; i < SHA1_DIGEST_LEN; ++i) { - if (sha1_read(SHA1_ADDR_DIGEST + i, block0_expected[i]) != 0) - return 1; - } - - /* Write second block to SHA-1. */ - for (i = 0; i < SHA1_BLOCK_LEN; ++i) { - if (sha1_write(SHA1_ADDR_BLOCK + i, block[1][i]) != 0) - return 1; - } - - /* Start next block hashing, wait and check status. */ - if ((sha1_next() != 0) || (sha1_wait_valid() != 0)) - return 1; - - /* Extract the second digest. */ - for (i = 0; i < SHA1_DIGEST_LEN; ++i) { - if (sha1_read(SHA1_ADDR_DIGEST + i, expected[i]) != 0) - return 1; - } - - return 0; -} - -/* ---------------- SHA-256 test cases ---------------- */ - -int sha256_read(uint8_t addr, uint32_t data) -{ - return tc_read(SHA256_ADDR_PREFIX, addr, data); -} - -int sha256_write(uint8_t addr, uint32_t data) -{ - return tc_write(SHA256_ADDR_PREFIX, addr, data); -} - -int sha256_init(void) -{ - return tc_init(SHA256_ADDR_PREFIX); -} - -int sha256_next(void) -{ - return tc_next(SHA256_ADDR_PREFIX); -} - -int sha256_wait_ready(void) -{ - return tc_wait_ready(SHA256_ADDR_PREFIX); -} - -int sha256_wait_valid(void) -{ - return tc_wait_valid(SHA256_ADDR_PREFIX); -} - -/* TC4: Read name and version from SHA-256 core. */ -int TC4(void) -{ - uint32_t name0 = 0x73686132; /* "sha2" */ - uint32_t name1 = 0x2d323536; /* "-256" */ - uint32_t version = 0x302e3830; /* "0.80" */ - - printf("TC4: Reading name, type and version words from SHA-256 core.\n"); - - return - sha256_read(ADDR_NAME0, name0) || - sha256_read(ADDR_NAME1, name1) || - sha256_read(ADDR_VERSION, version); -} - -/* TC5: SHA-256 Single block message test as specified by NIST. */ -int TC5(void) -{ - const uint32_t *block = NIST_512_SINGLE; - const uint32_t *expected = SHA256_SINGLE_DIGEST; - int i; - - printf("TC5: Single block message test for SHA-256.\n"); - - /* Write block to SHA-256. */ - for (i = 0; i < SHA256_BLOCK_LEN; ++i) { - if (sha256_write(SHA256_ADDR_BLOCK + i, block[i]) != 0) - return 1; - } - - /* Start initial block hashing, wait and check status. */ - if ((sha256_init() != 0) || (sha256_wait_valid() != 0)) - return 1; - - /* Extract the digest. */ - for (i = 0; i < SHA256_DIGEST_LEN; ++i) { - if (sha256_read(SHA256_ADDR_DIGEST + i, expected[i]) != 0) - return 1; - } - - - return 0; -} - -/* TC6: SHA-1 Double block message test as specified by NIST. */ -int TC6(void) -{ - const uint32_t *block[2] = { NIST_512_DOUBLE0, NIST_512_DOUBLE1 }; - static const uint32_t block0_expected[] = - { 0x85E655D6, 0x417A1795, 0x3363376A, 0x624CDE5C, - 0x76E09589, 0xCAC5F811, 0xCC4B32C1, 0xF20E533A }; - const uint32_t *expected = SHA256_DOUBLE_DIGEST; - int i; - - printf("TC6: Double block message test for SHA-256.\n"); - - /* Write first block to SHA-256. */ - for (i = 0; i < SHA256_BLOCK_LEN; ++i) { - if (sha256_write(SHA256_ADDR_BLOCK + i, block[0][i]) != 0) - return 1; - } - - /* Start initial block hashing, wait and check status. */ - if ((sha256_init() != 0) || (sha256_wait_valid() != 0)) - return 1; - - /* Extract the first digest. */ - for (i = 0; i < SHA256_DIGEST_LEN; ++i) { - if (sha256_read(SHA256_ADDR_DIGEST + i, block0_expected[i]) != 0) - return 1; - } - - /* Write second block to SHA-256. */ - for (i = 0; i < SHA256_BLOCK_LEN; ++i) { - if (sha256_write(SHA256_ADDR_BLOCK + i, block[1][i]) != 0) - return 1; - } - - /* Start next block hashing, wait and check status. */ - if ((sha256_next() != 0) || (sha256_wait_valid() != 0)) - return 1; - - /* Extract the second digest. */ - for (i = 0; i < SHA256_DIGEST_LEN; ++i) { - if (sha256_read(SHA256_ADDR_DIGEST + i, expected[i]) != 0) - return 1; - } - - return 0; -} - -/* TC7: SHA-256 Huge message test. */ -int TC7(void) -{ - static const uint32_t block[] = - { 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f, - 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f, - 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f, - 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f }; - - /* final digest after 1000 iterations */ - static const uint32_t expected[] = - { 0x7638f3bc, 0x500dd1a6, 0x586dd4d0, 0x1a1551af, - 0xd821d235, 0x2f919e28, 0xd5842fab, 0x03a40f2a }; - - int i, n = 1000; - - printf("TC7: Message with %d blocks test for SHA-256.\n", n); - - /* Write first block to SHA-256. */ - for (i = 0; i < SHA256_BLOCK_LEN; ++i) { - if (sha256_write( SHA256_ADDR_BLOCK + i, block[i]) != 0) - return 1; - } - - /* Start initial block hashing, wait and check status. */ - if ((sha256_init() != 0) || (sha256_wait_ready() != 0)) - return 1; - - /* First block done. Do the rest. */ - for (i = 1; i < n; ++i) { - /* Start next block hashing, wait and check status. */ - if ((sha256_next() != 0) || (sha256_wait_ready() != 0)) - return 1; - } - - /* XXX valid is probably set at the same time as ready */ - if (sha256_wait_valid() != 0) - return 1; - /* Extract the final digest. */ - for (i = 0; i < SHA256_DIGEST_LEN; ++i) { - if (sha256_read(SHA256_ADDR_DIGEST + i, expected[i]) != 0) - return 1; - } - - return 0; -} - -/* ---------------- SHA-512 test cases ---------------- */ - -int sha512_read(uint8_t addr, uint32_t data) -{ - return tc_read(SHA512_ADDR_PREFIX, addr, data); -} - -int sha512_write(uint8_t addr, uint32_t data) -{ - return tc_write(SHA512_ADDR_PREFIX, addr, data); -} - -int sha512_init(uint8_t mode) -{ - return tc_write(SHA512_ADDR_PREFIX, ADDR_CTRL, - CTRL_INIT_CMD + (mode << SHA512_CTRL_MODE_LOW)); -} - -int sha512_next(uint8_t mode) -{ - return tc_write(SHA512_ADDR_PREFIX, ADDR_CTRL, - CTRL_NEXT_CMD + (mode << SHA512_CTRL_MODE_LOW)); -} - -int sha512_wait_ready(void) -{ - return tc_wait_ready(SHA512_ADDR_PREFIX); -} - -int sha512_wait_valid(void) -{ - return tc_wait_valid(SHA512_ADDR_PREFIX); -} - -/* TC8: Read name and version from SHA-512 core. */ -int TC8(void) -{ - uint32_t name0 = 0x73686132; /* "sha2" */ - uint32_t name1 = 0x2d353132; /* "-512" */ - uint32_t version = 0x302e3830; /* "0.80" */ - - printf("TC8: Reading name, type and version words from SHA-512 core.\n"); - - return - sha512_read(ADDR_NAME0, name0) || - sha512_read(ADDR_NAME1, name1) || - sha512_read(ADDR_VERSION, version); -} - -/* TC9: SHA-512 Single block message test as specified by NIST. - We do this for all modes. */ -int tc9(uint8_t mode, const uint32_t *expected, int len) -{ - const uint32_t *block = NIST_1024_SINGLE; - int i; - - /* Write block to SHA-512. */ - for (i = 0; i < SHA512_BLOCK_LEN; ++i) { - if (sha512_write(SHA512_ADDR_BLOCK + i, block[i]) != 0) - return 1; - } - - /* Start initial block hashing, wait and check status. */ - if ((sha512_init(mode) != 0) || (sha512_wait_valid() != 0)) - return 1; - - /* Extract the digest. */ - for (i = 0; i < len/4; ++i) { - if (sha512_read(SHA512_ADDR_DIGEST + i, expected[i]) != 0) - return 1; - } - - return 0; -} - -int TC9(void) -{ - printf("TC9-1: Single block message test for SHA-512/224.\n"); - if (tc9(MODE_SHA_512_224, SHA512_224_SINGLE_DIGEST, - sizeof(SHA512_224_SINGLE_DIGEST)) != 0) - return 1; - - printf("TC9-2: Single block message test for SHA-512/256.\n"); - if (tc9(MODE_SHA_512_256, SHA512_256_SINGLE_DIGEST, - sizeof(SHA512_256_SINGLE_DIGEST)) != 0) - return 1; - - printf("TC9-3: Single block message test for SHA-384.\n"); - if (tc9(MODE_SHA_384, SHA384_SINGLE_DIGEST, - sizeof(SHA384_SINGLE_DIGEST)) != 0) - return 1; - - printf("TC9-4: Single block message test for SHA-512.\n"); - if (tc9(MODE_SHA_512, SHA512_SINGLE_DIGEST, - sizeof(SHA512_SINGLE_DIGEST)) != 0) - return 1; - - return 0; -} - -/* TC10: SHA-512 Double block message test as specified by NIST. - We do this for all modes. */ -int tc10(uint8_t mode, const uint32_t *expected, int len) -{ - const uint32_t *block[2] = { NIST_1024_DOUBLE0, NIST_1024_DOUBLE1 }; - int i; - - /* Write first block to SHA-512. */ - for (i = 0; i < SHA512_BLOCK_LEN; ++i) { - if (sha512_write(SHA512_ADDR_BLOCK + i, block[0][i]) != 0) - return 1; - } - - /* Start initial block hashing, wait and check status. */ - if ((sha512_init(mode) != 0) || (sha512_wait_ready() != 0)) - return 1; - - /* Write second block to SHA-512. */ - for (i = 0; i < SHA512_BLOCK_LEN; ++i) { - if (sha512_write(SHA512_ADDR_BLOCK + i, block[1][i]) != 0) - return 1; - } - - /* Start next block hashing, wait and check status. */ - if ((sha512_next(mode) != 0) || (sha512_wait_valid() != 0)) - return 1; - - /* Extract the digest. */ - for (i = 0; i < len/4; ++i) { - if (sha512_read(SHA512_ADDR_DIGEST + i, expected[i]) != 0) - return 1; - } - - return 0; -} - -int TC10(void) -{ - printf("TC10-1: Double block message test for SHA-512/224.\n"); - if (tc10(MODE_SHA_512_224, SHA512_224_DOUBLE_DIGEST, - sizeof(SHA512_224_DOUBLE_DIGEST)) != 0) - return 1; - - printf("TC10-2: Double block message test for SHA-512/256.\n"); - if (tc10(MODE_SHA_512_256, SHA512_256_DOUBLE_DIGEST, - sizeof(SHA512_256_DOUBLE_DIGEST)) != 0) - return 1; - - printf("TC10-3: Double block message test for SHA-384.\n"); - if (tc10(MODE_SHA_384, SHA384_DOUBLE_DIGEST, - sizeof(SHA384_DOUBLE_DIGEST)) != 0) - return 1; - - printf("TC10-4: Double block message test for SHA-512.\n"); - if (tc10(MODE_SHA_512, SHA512_DOUBLE_DIGEST, - sizeof(SHA512_DOUBLE_DIGEST)) != 0) - return 1; - - return 0; -} - -/* ---------------- main ---------------- */ - -int main(int argc, char *argv[]) -{ - typedef int (*tcfp)(void); - tcfp all_tests[] = { TC1, TC2, TC3, TC4, TC5, TC6, TC7, TC8, TC9, TC10 }; - tcfp sha1_tests[] = { TC1, TC2, TC3 }; - tcfp sha256_tests[] = { TC4, TC5, TC6, TC7 }; - tcfp sha512_tests[] = { TC8, TC9, TC10 }; - - char *usage = "Usage: %s [-d] [-i I2C_device] [-a I2C_addr] tc...\n"; - char *dev = I2C_dev; - int addr = I2C_addr; - int i, j, opt; - - while ((opt = getopt(argc, argv, "h?di:a:")) != -1) { - switch (opt) { - case 'h': - case '?': - printf(usage, argv[0]); - return 0; - case 'd': - debug = 1; - break; - case 'i': - dev = optarg; - break; - case 'a': - addr = (int)strtol(optarg, NULL, 0); - if ((addr < 0x03) || (addr > 0x77)) { - fprintf(stderr, "addr must be between 0x03 and 0x77\n"); - return 1; - } - break; - default: - fprintf(stderr, usage, argv[0]); - return 1; - } - } - - if (i2c_setup(dev, addr) != 0) - return 1; - - /* no args == run all tests */ - if (optind >= argc) { - for (j = 0; j < sizeof(all_tests)/sizeof(all_tests[0]); ++j) - if (all_tests[j]() != 0) - return 1; - return 0; - } - - for (i = optind; i < argc; ++i) { - if (strcmp(argv[i], "sha1") == 0) { - for (j = 0; j < sizeof(sha1_tests)/sizeof(sha1_tests[0]); ++j) - if (sha1_tests[j]() != 0) - return 1; - } - else if (strcmp(argv[i], "sha256") == 0) { - for (j = 0; j < sizeof(sha256_tests)/sizeof(sha256_tests[0]); ++j) - if (sha256_tests[j]() != 0) - return 1; - } - else if (strcmp(argv[i], "sha512") == 0) { - for (j = 0; j < sizeof(sha512_tests)/sizeof(sha512_tests[0]); ++j) - if (sha512_tests[j]() != 0) - return 1; - } - else if (strcmp(argv[i], "all") == 0) { - for (j = 0; j < sizeof(all_tests)/sizeof(all_tests[0]); ++j) - if (all_tests[j]() != 0) - return 1; - } - else if (isdigit(argv[i][0]) && - (((j = atoi(argv[i])) > 0) && - (j <= sizeof(all_tests)/sizeof(all_tests[0])))) { - if (all_tests[j - 1]() != 0) - return 1; - } - else { - fprintf(stderr, "unknown test case %s\n", argv[i]); - return 1; - } - } - - return 0; -} diff --git a/src/sw/hash_tester.py b/src/sw/hash_tester.py deleted file mode 100755 index a1b838b..0000000 --- a/src/sw/hash_tester.py +++ /dev/null @@ -1,693 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -#======================================================================= -# -# hash_tester.py -# -------------- -# This program sends several commands to the coretest_hashes subsystem -# in order to verify the SHA-1, SHA-256 and SHA-512/x hash function -# cores. The program will use the built in hash implementations in -# Python to do functional comparison and validation. -# -# This version of the program talks to the FPGA over an I2C bus, but -# does not require any additional modules. -# -# The single and dual block test cases are taken from the -# NIST KAT document: -# http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA_All.pdf -# -# -# Authors: Joachim Strömbergson, Paul Selkirk -# Copyright (c) 2014, SUNET -# -# Redistribution and use in source and binary forms, with or -# without modification, are permitted provided that the following -# conditions are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -#======================================================================= - -#------------------------------------------------------------------- -# Python module imports. -#------------------------------------------------------------------- -import sys -import io -import fcntl - -#------------------------------------------------------------------- -# Defines. -#------------------------------------------------------------------- - -# addresses and codes common to all hash cores -ADDR_NAME0 = 0x00 -ADDR_NAME1 = 0x01 -ADDR_VERSION = 0x02 -ADDR_CTRL = 0x08 -CTRL_INIT_CMD = 1 -CTRL_NEXT_CMD = 2 -ADDR_STATUS = 0x09 -STATUS_READY_BIT = 1 -STATUS_VALID_BIT = 2 - -#---------------------------------------------------------------- -# NIST sample message blocks and expected digests -#---------------------------------------------------------------- - -# SHA-1/SHA-256 One Block Message Sample -# Input Message: "abc" -NIST_512_SINGLE = [ 0x61626380, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000018 ] - -SHA1_SINGLE_DIGEST = [ 0xa9993e36, 0x4706816a, 0xba3e2571, 0x7850c26c, - 0x9cd0d89d ] - -SHA256_SINGLE_DIGEST = [ 0xBA7816BF, 0x8F01CFEA, 0x414140DE, 0x5DAE2223, - 0xB00361A3, 0x96177A9C, 0xB410FF61, 0xF20015AD ] - -# SHA-1/SHA-256 Two Block Message Sample -# Input Message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" -NIST_512_DOUBLE0 = [ 0x61626364, 0x62636465, 0x63646566, 0x64656667, - 0x65666768, 0x66676869, 0x6768696A, 0x68696A6B, - 0x696A6B6C, 0x6A6B6C6D, 0x6B6C6D6E, 0x6C6D6E6F, - 0x6D6E6F70, 0x6E6F7071, 0x80000000, 0x00000000 ] -NIST_512_DOUBLE1 = [ 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x000001C0 ] - -SHA1_DOUBLE_DIGEST = [ 0x84983E44, 0x1C3BD26E, 0xBAAE4AA1, 0xF95129E5, - 0xE54670F1 ] - -SHA256_DOUBLE_DIGEST = [ 0x248D6A61, 0xD20638B8, 0xE5C02693, 0x0C3E6039, - 0xA33CE459, 0x64FF2167, 0xF6ECEDD4, 0x19DB06C1 ] - -# SHA-512 One Block Message Sample -# Input Message: "abc" -NIST_1024_SINGLE = [ 0x61626380, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000018 ] - -SHA512_224_SINGLE_DIGEST = [0x4634270f, 0x707b6a54, 0xdaae7530, 0x460842e2, - 0x0e37ed26, 0x5ceee9a4, 0x3e8924aa] -SHA512_256_SINGLE_DIGEST = [0x53048e26, 0x81941ef9, 0x9b2e29b7, 0x6b4c7dab, - 0xe4c2d0c6, 0x34fc6d46, 0xe0e2f131, 0x07e7af23] -SHA384_SINGLE_DIGEST = [0xcb00753f, 0x45a35e8b, 0xb5a03d69, 0x9ac65007, - 0x272c32ab, 0x0eded163, 0x1a8b605a, 0x43ff5bed, - 0x8086072b, 0xa1e7cc23, 0x58baeca1, 0x34c825a7] -SHA512_SINGLE_DIGEST = [0xddaf35a1, 0x93617aba, 0xcc417349, 0xae204131, - 0x12e6fa4e, 0x89a97ea2, 0x0a9eeee6, 0x4b55d39a, - 0x2192992a, 0x274fc1a8, 0x36ba3c23, 0xa3feebbd, - 0x454d4423, 0x643ce80e, 0x2a9ac94f, 0xa54ca49f] - -# SHA-512 Two Block Message Sample -# Input Message: "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" -# "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" -NIST_1024_DOUBLE0 = [ 0x61626364, 0x65666768, 0x62636465, 0x66676869, - 0x63646566, 0x6768696a, 0x64656667, 0x68696a6b, - 0x65666768, 0x696a6b6c, 0x66676869, 0x6a6b6c6d, - 0x6768696a, 0x6b6c6d6e, 0x68696a6b, 0x6c6d6e6f, - 0x696a6b6c, 0x6d6e6f70, 0x6a6b6c6d, 0x6e6f7071, - 0x6b6c6d6e, 0x6f707172, 0x6c6d6e6f, 0x70717273, - 0x6d6e6f70, 0x71727374, 0x6e6f7071, 0x72737475, - 0x80000000, 0x00000000, 0x00000000, 0x00000000 ] -NIST_1024_DOUBLE1 = [ 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000380 ] - -SHA512_224_DOUBLE_DIGEST = [ 0x23fec5bb, 0x94d60b23, 0x30819264, 0x0b0c4533, - 0x35d66473, 0x4fe40e72, 0x68674af9 ] -SHA512_256_DOUBLE_DIGEST = [ 0x3928e184, 0xfb8690f8, 0x40da3988, 0x121d31be, - 0x65cb9d3e, 0xf83ee614, 0x6feac861, 0xe19b563a ] -SHA384_DOUBLE_DIGEST = [ 0x09330c33, 0xf71147e8, 0x3d192fc7, 0x82cd1b47, - 0x53111b17, 0x3b3b05d2, 0x2fa08086, 0xe3b0f712, - 0xfcc7c71a, 0x557e2db9, 0x66c3e9fa, 0x91746039 ] -SHA512_DOUBLE_DIGEST = [ 0x8e959b75, 0xdae313da, 0x8cf4f728, 0x14fc143f, - 0x8f7779c6, 0xeb9f7fa1, 0x7299aead, 0xb6889018, - 0x501d289e, 0x4900f7e4, 0x331b99de, 0xc4b5433a, - 0xc7d329ee, 0xb6dd2654, 0x5e96e55b, 0x874be909 ] - -#---------------------------------------------------------------- -# I2C class -#---------------------------------------------------------------- - -# default configuration -I2C_dev = "/dev/i2c-2" -I2C_addr = 0x0f - -# from /usr/include/linux/i2c-dev.h -I2C_SLAVE = 0x0703 - -def hexlist(list): - return "[ " + ' '.join('%02x' % b for b in list) + " ]" - -class I2C: - # file handle for the i2c device - file = None - - # constructor: initialize the i2c communications channel - def __init__(self, dev=I2C_dev, addr=I2C_addr): - self.dev = dev - self.addr = addr - try: - self.file = io.FileIO(self.dev, 'r+b') - except IOError as e: - print "Unable to open %s: %s" % (self.dev, e.strerror) - sys.exit(1) - try: - fcntl.ioctl(self.file, I2C_SLAVE, self.addr) - except IOError as e: - print "Unable to set I2C slave device 0x%02x: %s" % (self.addr, e.strerror) - sys.exit(1) - - # destructor: close the i2c communications channel - def __del__(self): - if (self.file): - self.file.close() - - # write a command to the i2c device - def write(self, buf): - if DEBUG: - print "write %s" % hexlist(buf) - self.file.write(bytearray(buf)) - - # read one response byte from the i2c device - def read(self): - # read() on the i2c device will only return one byte at a time, - # and tc.get_resp() needs to parse the response one byte at a time - return ord(self.file.read(1)) - -#---------------------------------------------------------------- -# test-case class -#---------------------------------------------------------------- - -# command codes -SOC = 0x55 -EOC = 0xaa -READ_CMD = 0x10 -WRITE_CMD = 0x11 -RESET_CMD = 0x01 - -# response codes -SOR = 0xaa -EOR = 0x55 -READ_OK = 0x7f -WRITE_OK = 0x7e -RESET_OK = 0x7d -UNKNOWN = 0xfe -ERROR = 0xfd - -class TcError(Exception): - pass - -class tc: - def __init__(self, i2c, addr0, addr1): - self.i2c = i2c - self.addr0 = addr0 - self.addr1 = addr1 - - def send_write_cmd(self, data): - buf = [SOC, WRITE_CMD, self.addr0, self.addr1] - for s in (24, 16, 8, 0): - buf.append(data >> s & 0xff) - buf.append(EOC) - self.i2c.write(buf) - - def send_read_cmd(self): - buf = [SOC, READ_CMD, self.addr0, self.addr1, EOC] - self.i2c.write(buf) - - def get_resp(self): - buf = [] - len = 2 - i = 0 - while i < len: - b = self.i2c.read() - if ((i == 0) and (b != SOR)): - # we've gotten out of sync, and there's probably nothing we can do - print "response byte 0: expected 0x%02x (SOR), got 0x%02x" % (SOR, b) - raise TcError() - elif (i == 1): # response code - try: - # anonymous dictionary of message lengths - len = {READ_OK:9, WRITE_OK:5, RESET_OK:3, ERROR:4, UNKNOWN:4}[b] - except KeyError: # unknown response code - # we've gotten out of sync, and there's probably nothing we can do - print "unknown response code 0x%02x" % b - raise TcError() - buf.append(b) - i += 1 - if DEBUG: - print "read %s" % hexlist(buf) - return buf - - def get_expected(self, expected): - buf = self.get_resp() - if (buf != expected): - print "expected %s,\nreceived %s" % (hexlist(expected), hexlist(buf)) - raise TcError() - - def get_write_resp(self): - expected = [SOR, WRITE_OK, self.addr0, self.addr1, EOR] - self.get_expected(expected) - - def get_read_resp(self, data): - expected = [SOR, READ_OK, self.addr0, self.addr1] - for s in (24, 16, 8, 0): - expected.append(data >> s & 0xff) - expected.append(EOR) - self.get_expected(expected) - - def write(self, data): - self.send_write_cmd(data) - self.get_write_resp() - - def read(self, data): - self.send_read_cmd() - self.get_read_resp(data) - -def tc_write(i2c, addr0, addr1, data): - tc(i2c, addr0, addr1).write(data) - -def tc_read(i2c, addr0, addr1, data): - tc(i2c, addr0, addr1).read(data) - -def tc_init(i2c, addr0): - tc(i2c, addr0, ADDR_CTRL).write(CTRL_INIT_CMD) - -def tc_next(i2c, addr0): - tc(i2c, addr0, ADDR_CTRL).write(CTRL_NEXT_CMD) - -def tc_wait(i2c, addr0, status): - t = tc(i2c, addr0, ADDR_STATUS) - while 1: - t.send_read_cmd() - buf = t.get_resp() - if ((buf[7] & status) == status): - break - -def tc_wait_ready(i2c, addr0): - tc_wait(i2c, addr0, STATUS_READY_BIT) - -def tc_wait_valid(i2c, addr0): - tc_wait(i2c, addr0, STATUS_VALID_BIT) - -#---------------------------------------------------------------- -# SHA-1 test cases -#---------------------------------------------------------------- -SHA1_ADDR_PREFIX = 0x10 -SHA1_ADDR_BLOCK = 0x10 -SHA1_ADDR_DIGEST = 0x20 - -def sha1_read(i2c, addr, data): - tc_read(i2c, SHA1_ADDR_PREFIX, addr, data) - -def sha1_write(i2c, addr, data): - tc_write(i2c, SHA1_ADDR_PREFIX, addr, data) - -def sha1_init(i2c): - tc_init(i2c, SHA1_ADDR_PREFIX) - -def sha1_next(i2c): - tc_next(i2c, SHA1_ADDR_PREFIX) - -def sha1_wait_ready(i2c): - tc_wait_ready(i2c, SHA1_ADDR_PREFIX) - -def sha1_wait_valid(i2c): - tc_wait_valid(i2c, SHA1_ADDR_PREFIX) - -# TC1: Read name and version from SHA-1 core. -def TC1(i2c): - print "TC1: Reading name, type and version words from SHA-1 core." - - sha1_read(i2c, ADDR_NAME0, 0x73686131) # "sha1" - sha1_read(i2c, ADDR_NAME1, 0x20202020) # " " - sha1_read(i2c, ADDR_VERSION, 0x302e3530) # "0.50" - -# TC2: SHA-1 Single block message test as specified by NIST. -def TC2(i2c): - block = NIST_512_SINGLE - expected = SHA1_SINGLE_DIGEST - - print "TC2: Single block message test for SHA-1." - - # Write block to SHA-1. - for i in range(len(block)): - sha1_write(i2c, SHA1_ADDR_BLOCK + i, block[i]) - - # Start initial block hashing, wait and check status. - sha1_init(i2c) - sha1_wait_valid(i2c) - - # Extract the digest. - for i in range(len(expected)): - sha1_read(i2c, SHA1_ADDR_DIGEST + i, expected[i]) - -# TC3: SHA-1 Double block message test as specified by NIST. -def TC3(i2c): - block = [ NIST_512_DOUBLE0, NIST_512_DOUBLE1 ] - block0_expected = [ 0xF4286818, 0xC37B27AE, 0x0408F581, 0x84677148, - 0x4A566572 ] - expected = SHA1_DOUBLE_DIGEST - - print "TC3: Double block message test for SHA-1." - - # Write first block to SHA-1. - for i in range(len(block[0])): - sha1_write(i2c, SHA1_ADDR_BLOCK + i, block[0][i]) - - # Start initial block hashing, wait and check status. - sha1_init(i2c) - sha1_wait_valid(i2c) - - # Extract the first digest. - for i in range(len(block0_expected)): - sha1_read(i2c, SHA1_ADDR_DIGEST + i, block0_expected[i]) - - # Write second block to SHA-1. - for i in range(len(block[1])): - sha1_write(i2c, SHA1_ADDR_BLOCK + i, block[1][i]) - - # Start next block hashing, wait and check status. - sha1_next(i2c) - sha1_wait_valid(i2c) - - # Extract the second digest. - for i in range(len(expected)): - sha1_read(i2c, SHA1_ADDR_DIGEST + i, expected[i]) - -#---------------------------------------------------------------- -# SHA-256 test cases -#---------------------------------------------------------------- -SHA256_ADDR_PREFIX = 0x20 -SHA256_ADDR_BLOCK = 0x10 -SHA256_ADDR_DIGEST = 0x20 - -def sha256_read(i2c, addr, data): - tc_read(i2c, SHA256_ADDR_PREFIX, addr, data) - -def sha256_write(i2c, addr, data): - tc_write(i2c, SHA256_ADDR_PREFIX, addr, data) - -def sha256_init(i2c): - tc_init(i2c, SHA256_ADDR_PREFIX) - -def sha256_next(i2c): - tc_next(i2c, SHA256_ADDR_PREFIX) - -def sha256_wait_ready(i2c): - tc_wait_ready(i2c, SHA256_ADDR_PREFIX) - -def sha256_wait_valid(i2c): - tc_wait_valid(i2c, SHA256_ADDR_PREFIX) - -# TC4: Read name and version from SHA-256 core. -def TC4(i2c): - print "TC4: Reading name, type and version words from SHA-256 core." - - sha256_read(i2c, ADDR_NAME0, 0x73686132) # "sha2" - sha256_read(i2c, ADDR_NAME1, 0x2d323536) # "-256" - sha256_read(i2c, ADDR_VERSION, 0x302e3830) # "0.80" - -# TC5: SHA-256 Single block message test as specified by NIST. -def TC5(i2c): - block = NIST_512_SINGLE - expected = SHA256_SINGLE_DIGEST - - print "TC5: Single block message test for SHA-256." - - # Write block to SHA-256. - for i in range(len(block)): - sha256_write(i2c, SHA256_ADDR_BLOCK + i, block[i]) - - # Start initial block hashing, wait and check status. - sha256_init(i2c) - sha256_wait_valid(i2c) - - # Extract the digest. - for i in range(len(expected)): - sha256_read(i2c, SHA256_ADDR_DIGEST + i, expected[i]) - -# TC6: SHA-256 Double block message test as specified by NIST. -def TC6(i2c): - block = [ NIST_512_DOUBLE0, NIST_512_DOUBLE1 ] - block0_expected = [ 0x85E655D6, 0x417A1795, 0x3363376A, 0x624CDE5C, - 0x76E09589, 0xCAC5F811, 0xCC4B32C1, 0xF20E533A ] - expected = SHA256_DOUBLE_DIGEST - - print "TC6: Double block message test for SHA-256." - - # Write first block to SHA-256. - for i in range(len(block[0])): - sha256_write(i2c, SHA256_ADDR_BLOCK + i, block[0][i]) - - # Start initial block hashing, wait and check status. - sha256_init(i2c) - sha256_wait_valid(i2c) - - # Extract the first digest. - for i in range(len(block0_expected)): - sha256_read(i2c, SHA256_ADDR_DIGEST + i, block0_expected[i]) - - # Write second block to SHA-256. - for i in range(len(block[1])): - sha256_write(i2c, SHA256_ADDR_BLOCK + i, block[1][i]) - - # Start next block hashing, wait and check status. - sha256_next(i2c) - sha256_wait_valid(i2c) - - # Extract the second digest. - for i in range(len(expected)): - sha256_read(i2c, SHA256_ADDR_DIGEST + i, expected[i]) - -# TC7: SHA-256 Huge message test. -def TC7(i2c): - block = [ 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f, - 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f, - 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f, - 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f ] - expected = [ 0x7638f3bc, 0x500dd1a6, 0x586dd4d0, 0x1a1551af, - 0xd821d235, 0x2f919e28, 0xd5842fab, 0x03a40f2a ] - n = 1000 - - print "TC7: Message with %d blocks test for SHA-256." % n - - # Write first block to SHA-256. - for i in range(len(block)): - sha256_write(i2c, SHA256_ADDR_BLOCK + i, block[i]) - - # Start initial block hashing, wait and check status. - sha256_init(i2c) - sha256_wait_ready(i2c) - - # First block done. Do the rest. - for i in range(n - 1): - # Start next block hashing, wait and check status. - sha256_next(i2c) - sha256_wait_ready(i2c) - - # XXX valid is probably set at the same time as ready - sha256_wait_valid(i2c) - - # Extract the final digest. - for i in range(len(expected)): - sha256_read(i2c, SHA256_ADDR_DIGEST + i, expected[i]) - -#---------------------------------------------------------------- -# SHA-512 test cases -#---------------------------------------------------------------- -SHA512_ADDR_PREFIX = 0x30 -SHA512_ADDR_BLOCK = 0x10 -SHA512_ADDR_DIGEST = 0x40 -SHA512_CTRL_MODE_LOW = 2 -SHA512_CTRL_MODE_HIGH = 3 -MODE_SHA_512_224 = 0 -MODE_SHA_512_256 = 1 -MODE_SHA_384 = 2 -MODE_SHA_512 = 3 - -def sha512_read(i2c, addr, data): - tc_read(i2c, SHA512_ADDR_PREFIX, addr, data) - -def sha512_write(i2c, addr, data): - tc_write(i2c, SHA512_ADDR_PREFIX, addr, data) - -def sha512_init(i2c, mode): - tc_write(i2c, SHA512_ADDR_PREFIX, ADDR_CTRL, - CTRL_INIT_CMD + (mode << SHA512_CTRL_MODE_LOW)) - -def sha512_next(i2c, mode): - tc_write(i2c, SHA512_ADDR_PREFIX, ADDR_CTRL, - CTRL_NEXT_CMD + (mode << SHA512_CTRL_MODE_LOW)) - -def sha512_wait_ready(i2c): - tc_wait_ready(i2c, SHA512_ADDR_PREFIX) - -def sha512_wait_valid(i2c): - tc_wait_valid(i2c, SHA512_ADDR_PREFIX) - -# TC8: Read name and version from SHA-512 core. -def TC8(i2c): - print "TC8: Reading name, type and version words from SHA-512 core." - - sha512_read(i2c, ADDR_NAME0, 0x73686132) # "sha2" - sha512_read(i2c, ADDR_NAME1, 0x2d353132) # "-512" - sha512_read(i2c, ADDR_VERSION, 0x302e3830) # "0.80" - -# TC9: SHA-512 Single block message test as specified by NIST. -# We do this for all modes. -def TC9(i2c): - def tc9(i2c, mode, expected): - block = NIST_1024_SINGLE - - # Write block to SHA-512. - for i in range(len(block)): - sha512_write(i2c, SHA512_ADDR_BLOCK + i, block[i]) - - # Start initial block hashing, wait and check status. - sha512_init(i2c, mode) - sha512_wait_valid(i2c) - - # Extract the digest. - for i in range(len(expected)): - sha512_read(i2c, SHA512_ADDR_DIGEST + i, expected[i]) - - print "TC9-1: Single block message test for SHA-512/224." - tc9(i2c, MODE_SHA_512_224, SHA512_224_SINGLE_DIGEST) - - print "TC9-2: Single block message test for SHA-512/256." - tc9(i2c, MODE_SHA_512_256, SHA512_256_SINGLE_DIGEST) - - print "TC9-3: Single block message test for SHA-384." - tc9(i2c, MODE_SHA_384, SHA384_SINGLE_DIGEST) - - print "TC9-4: Single block message test for SHA-512." - tc9(i2c, MODE_SHA_512, SHA512_SINGLE_DIGEST) - -# TC10: SHA-512 Single block message test as specified by NIST. -# We do this for all modes. -def TC10(i2c): - def tc10(i2c, mode, expected): - block = [ NIST_1024_DOUBLE0, NIST_1024_DOUBLE1 ] - - # Write first block to SHA-512. - for i in range(len(block[0])): - sha512_write(i2c, SHA512_ADDR_BLOCK + i, block[0][i]) - - # Start initial block hashing, wait and check status. - sha512_init(i2c, mode) - sha512_wait_ready(i2c) - - # Write second block to SHA-512. - for i in range(len(block[1])): - sha512_write(i2c, SHA512_ADDR_BLOCK + i, block[1][i]) - - # Start next block hashing, wait and check status. - sha512_next(i2c, mode) - sha512_wait_valid(i2c) - - # Extract the digest. - for i in range(len(expected)): - sha512_read(i2c, SHA512_ADDR_DIGEST + i, expected[i]) - - print "TC10-1: Double block message test for SHA-512/224." - tc10(i2c, MODE_SHA_512_224, SHA512_224_DOUBLE_DIGEST) - - print "TC10-2: Double block message test for SHA-512/256." - tc10(i2c, MODE_SHA_512_256, SHA512_256_DOUBLE_DIGEST) - - print "TC10-3: Double block message test for SHA-384." - tc10(i2c, MODE_SHA_384, SHA384_DOUBLE_DIGEST) - - print "TC10-4: Double block message test for SHA-512." - tc10(i2c, MODE_SHA_512, SHA512_DOUBLE_DIGEST) - - -#---------------------------------------------------------------- -# main -#---------------------------------------------------------------- -if __name__ == '__main__': - import argparse - - all_tests = [ TC1, TC2, TC3, TC4, TC5, TC6, TC7, TC8, TC9, TC10 ] - sha1_tests = all_tests[0:3] - sha256_tests = all_tests[3:7] - sha512_tests = all_tests[7:] - - parser = argparse.ArgumentParser() - parser.add_argument('-d', '--debug', action='store_true', - help='add debugging/trace information') - parser.add_argument('-i', dest='dev', default=I2C_dev, - help='I2C device name (default ' + I2C_dev + ')') - parser.add_argument('-a', dest='addr', type=lambda x:int(x,0), default=I2C_addr, - help='I2C device address (default ' + hex(I2C_addr) + ')') - parser.add_argument('test_cases', metavar='TC', nargs='*', - help='test case number, "sha1", "sha256", "sha512", or "all"') - args = parser.parse_args() - DEBUG = args.debug - i = I2C(args.dev, args.addr) - - if (not args.test_cases): - for TC in all_tests: - TC(i) - else: - for t in args.test_cases: - if (t == 'sha1'): - for TC in sha1_tests: - TC(i) - elif (t == 'sha256'): - for TC in sha256_tests: - TC(i) - elif (t == 'sha512'): - for TC in sha512_tests: - TC(i) - elif (t == 'all'): - for TC in all_tests: - TC(i) - else: - try: - n = int(t) - except: - print 'invalid test case %s' % t - else: - if ((n < 1) or (n > len(all_tests))): - print 'invalid test case %d' % n - else: - all_tests[n-1](i) - -#======================================================================= -# EOF hash_tester.py -#======================================================================= diff --git a/src/sw/nist_1024_double.bin b/src/sw/nist_1024_double.bin deleted file mode 100644 index 4674ea4..0000000 --- a/src/sw/nist_1024_double.bin +++ /dev/null @@ -1 +0,0 @@ -abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu \ No newline at end of file diff --git a/src/sw/nist_1024_single.bin b/src/sw/nist_1024_single.bin deleted file mode 100644 index f2ba8f8..0000000 --- a/src/sw/nist_1024_single.bin +++ /dev/null @@ -1 +0,0 @@ -abc \ No newline at end of file diff --git a/src/sw/nist_512_double.bin b/src/sw/nist_512_double.bin deleted file mode 100644 index 199f24e..0000000 --- a/src/sw/nist_512_double.bin +++ /dev/null @@ -1 +0,0 @@ -abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq \ No newline at end of file diff --git a/src/sw/nist_512_single.bin b/src/sw/nist_512_single.bin deleted file mode 100644 index f2ba8f8..0000000 --- a/src/sw/nist_512_single.bin +++ /dev/null @@ -1 +0,0 @@ -abc \ No newline at end of file -- cgit v1.2.3