From f20979faa37d4f272fcce51af18b829027778614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 14 Sep 2018 16:07:25 +0200 Subject: Adding instatiation of the mkmif in the keywrap top level wrapper. Updated testbench anf Makefile to build with instantiated mkmif. The mkmif is not yet used by the keywrap. --- src/tb/tb_keywrap.v | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap.v b/src/tb/tb_keywrap.v index 4d1c25c..1f1dabf 100644 --- a/src/tb/tb_keywrap.v +++ b/src/tb/tb_keywrap.v @@ -97,6 +97,10 @@ module tb_keywrap(); reg tb_clk; reg tb_reset_n; + wire tb_mkm_spi_sclk; + wire tb_mkm_spi_cs_n; + reg tb_mkm_spi_do; + wire tb_mkm_spi_di; reg tb_cs; reg tb_we; reg [(ADDR_BITS -1 ) : 0] tb_address; @@ -111,6 +115,10 @@ module tb_keywrap(); keywrap dut( .clk(tb_clk), .reset_n(tb_reset_n), + .mkm_spi_sclk(tb_mkm_spi_sclk), + .mkm_spi_cs_n(tb_mkm_spi_cs_n), + .mkm_spi_do(tb_mkm_spi_do), + .mkm_spi_di(tb_mkm_spi_di), .cs(tb_cs), .we(tb_we), .address(tb_address), @@ -330,15 +338,17 @@ module tb_keywrap(); //---------------------------------------------------------------- task init_sim; begin - cycle_ctr = 0; - error_ctr = 0; - tc_ctr = 0; + cycle_ctr = 1'h0; + error_ctr = 1'h0; + tc_ctr = 1'h0; - tb_clk = 0; - tb_reset_n = 1; + tb_clk = 1'h0; + tb_reset_n = 1'h1; - tb_cs = 0; - tb_we = 0; + tb_mkm_spi_do = 1'h1; + + tb_cs = 1'h0; + tb_we = 1'h0; tb_address = 8'h0; tb_write_data = 32'h0; end -- cgit v1.2.3 From 00fd27b23e578f5c92d856951645805be5dbab1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 18 Sep 2018 09:54:20 +0200 Subject: Moved the mkmif instance into the core itself. Added API to read the key if DEBUG is set. --- src/tb/tb_keywrap_core.v | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_core.v b/src/tb/tb_keywrap_core.v index 17c8f30..358b512 100644 --- a/src/tb/tb_keywrap_core.v +++ b/src/tb/tb_keywrap_core.v @@ -77,6 +77,11 @@ module tb_keywrap_core(); reg [31 : 0] tb_api_wr_data; wire [31 : 0] tb_api_rd_data; + wire tb_mkm_spi_sclk; + wire tb_mkm_spi_cs_n; + reg tb_mkm_spi_do; + wire tb_mkm_spi_di; + //---------------------------------------------------------------- // Device Under Test. @@ -86,6 +91,11 @@ module tb_keywrap_core(); .clk(tb_clk), .reset_n(tb_reset_n), + .mkm_spi_sclk(tb_mkm_spi_sclk), + .mkm_spi_cs_n(tb_mkm_spi_cs_n), + .mkm_spi_do(tb_mkm_spi_do), + .mkm_spi_di(tb_mkm_spi_di), + .init(tb_init), .next(tb_next), .encdec(tb_encdec), -- cgit v1.2.3 From 12db6151bf7a1c896a6f4bb37d46992a3621caaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 18 Sep 2018 12:35:29 +0200 Subject: Adding API control bits to read and write key. --- src/tb/tb_keywrap_core.v | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_core.v b/src/tb/tb_keywrap_core.v index 358b512..4b94b26 100644 --- a/src/tb/tb_keywrap_core.v +++ b/src/tb/tb_keywrap_core.v @@ -64,6 +64,8 @@ module tb_keywrap_core(); reg tb_reset_n; reg tb_init; reg tb_next; + reg tb_read; + reg tb_write; reg tb_encdec; wire tb_ready; wire tb_valid; @@ -98,7 +100,9 @@ module tb_keywrap_core(); .init(tb_init), .next(tb_next), - .encdec(tb_encdec), + .read(tb_read), + .write(tb_write), + .encdec(tb_encdec), .ready(tb_ready), .valid(tb_valid), @@ -159,6 +163,8 @@ module tb_keywrap_core(); tb_init = 0; tb_next = 0; + tb_read = 0; + tb_write = 0; tb_encdec = 0; tb_rlen = 13'h0; tb_key = 256'h0; -- cgit v1.2.3 From aa31953d8789a7349970809955ee3a2f0ab78177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 25 Sep 2018 15:08:30 +0200 Subject: Added logic to perform status word read operation from the mkm. Adding interfaces and registers to be able to pass mkm status to host. Updated dut instantiation in core testbench to. --- src/tb/tb_keywrap_core.v | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_core.v b/src/tb/tb_keywrap_core.v index 4b94b26..27a2e91 100644 --- a/src/tb/tb_keywrap_core.v +++ b/src/tb/tb_keywrap_core.v @@ -67,11 +67,15 @@ module tb_keywrap_core(); reg tb_read; reg tb_write; reg tb_encdec; + reg tb_mkey_mstatus; wire tb_ready; wire tb_valid; reg [(RLEN_BITS - 1) : 0] tb_rlen; reg [255 : 0] tb_key; + reg [31 : 0] tb_status; reg tb_keylen; + wire [255 : 0] tb_mkey; + wire [31 : 0] tb_mstatus; reg [63 : 0] tb_a_init; wire [63 : 0] tb_a_result; reg tb_api_we; @@ -102,7 +106,8 @@ module tb_keywrap_core(); .next(tb_next), .read(tb_read), .write(tb_write), - .encdec(tb_encdec), + .mkey_mstatus(tb_mkey_mstatus), + .encdec(tb_encdec), .ready(tb_ready), .valid(tb_valid), @@ -110,6 +115,9 @@ module tb_keywrap_core(); .rlen(tb_rlen), .key(tb_key), .keylen(tb_keylen), + .status(tb_status), + .mkey(tb_mkey), + .mstatus(tb_mstatus), .a_init(tb_a_init), .a_result(tb_a_result), @@ -161,18 +169,20 @@ module tb_keywrap_core(); tb_clk = 0; tb_reset_n = 0; - tb_init = 0; - tb_next = 0; - tb_read = 0; - tb_write = 0; - tb_encdec = 0; - tb_rlen = 13'h0; - tb_key = 256'h0; - tb_keylen = 0; - tb_a_init = 64'h0; - tb_api_we = 0; - tb_api_addr = 14'h0; - tb_api_wr_data = 32'h0; + tb_init = 0; + tb_next = 0; + tb_read = 0; + tb_write = 0; + tb_encdec = 0; + tb_mkey_mstatus = 0; + tb_rlen = 13'h0; + tb_key = 256'h0; + tb_status = 32'h0; + tb_keylen = 0; + tb_a_init = 64'h0; + tb_api_we = 0; + tb_api_addr = 14'h0; + tb_api_wr_data = 32'h0; #(CLK_PERIOD * 10); -- cgit v1.2.3 From d4bd0c2e50acafb94dc6e37581ed83d7c30bf46a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 28 Sep 2018 13:37:06 +0200 Subject: Completed syntax debug after integration of new mkmif_core wrapper. --- src/tb/tb_keywrap_core.v | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_core.v b/src/tb/tb_keywrap_core.v index 27a2e91..07777aa 100644 --- a/src/tb/tb_keywrap_core.v +++ b/src/tb/tb_keywrap_core.v @@ -68,6 +68,7 @@ module tb_keywrap_core(); reg tb_write; reg tb_encdec; reg tb_mkey_mstatus; + reg tb_mkey_key; wire tb_ready; wire tb_valid; reg [(RLEN_BITS - 1) : 0] tb_rlen; @@ -107,6 +108,7 @@ module tb_keywrap_core(); .read(tb_read), .write(tb_write), .mkey_mstatus(tb_mkey_mstatus), + .mkey_key(tb_mkey_key), .encdec(tb_encdec), .ready(tb_ready), @@ -175,6 +177,7 @@ module tb_keywrap_core(); tb_write = 0; tb_encdec = 0; tb_mkey_mstatus = 0; + tb_mkey_key = 0; tb_rlen = 13'h0; tb_key = 256'h0; tb_status = 32'h0; -- cgit v1.2.3 From 4e1cb1dbf22b93bde1cf3d5214e47f22d3d21cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 28 Sep 2018 15:47:15 +0200 Subject: Adding initial version of testbench for the mkmif wrapper. --- src/tb/tb_keywrap_mkmif.v | 153 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 src/tb/tb_keywrap_mkmif.v (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v new file mode 100644 index 0000000..09fe652 --- /dev/null +++ b/src/tb/tb_keywrap_mkmif.v @@ -0,0 +1,153 @@ +//====================================================================== +// +// tb_keywrap_mkm.v +// ---------------- +// Testbench for the mkmif wrapper in keywrap. +// +// +// Author: Joachim Strombergson +// Copyright (c) 2018, 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 tb_keywrap_mkm(); + + //---------------------------------------------------------------- + // Parameters. + //---------------------------------------------------------------- + parameter DEBUG = 1; + + parameter CLK_HALF_PERIOD = 1; + parameter CLK_PERIOD = 2 * CLK_HALF_PERIOD; + + + //---------------------------------------------------------------- + // Variables, regs and wires. + //---------------------------------------------------------------- + integer cycle_ctr; + integer error_ctr; + integer tc_ctr; + + reg tb_clk; + reg tb_reset_n; + + + //---------------------------------------------------------------- + // Device Under Test. + //---------------------------------------------------------------- + keywrap_mkmif dut( + .clk(tb_clk), + .reset_n(tb_reset_n), + + .mkm_spi_sclk(), + .mkm_spi_cs_n(), + .mkm_spi_do(), + .mkm_spi_di(), + + .init(), + .read(), + .write(), + .key_status(), + .ready(), + + .wr_status(), + .rd_status(), + .wr_key(), + .rd_key + ); + + + //---------------------------------------------------------------- + // clk_gen + // + // Always running clock generator process. + //---------------------------------------------------------------- + always + begin : clk_gen + #CLK_HALF_PERIOD; + tb_clk = !tb_clk; + end // clk_gen + + + //---------------------------------------------------------------- + // sys_monitor() + // + // An always running process that creates a cycle counter and + // conditionally displays information about the DUT. + //---------------------------------------------------------------- + always + begin : sys_monitor + cycle_ctr = cycle_ctr + 1; + + #(CLK_PERIOD); + end + + + //---------------------------------------------------------------- + // init_sim() + // + // Initialize all counters and testbed functionality as well + // as setting the DUT inputs to defined values. + //---------------------------------------------------------------- + task init_sim; + begin + cycle_ctr = 0; + error_ctr = 0; + tc_ctr = 0; + + tb_clk = 1'h0; + tb_reset_n = 1'h1 + + #(CLK_PERIOD); + end + endtask // init_sim + + + //---------------------------------------------------------------- + // main + //---------------------------------------------------------------- + initial + begin : main + $display(" -= Testbench for Keywrap mkmif wrapper started =-"); + $display(" ================================================"); + $display(""); + + init_sim(); + + $display(""); + $display("*** Keywrap mkmif wrapper testbench done. ***"); + $finish; + end // main + +endmodule // tb_keywrap_mkm + +//====================================================================== +// EOF tb_keywrap_mkm.v +//====================================================================== -- cgit v1.2.3 From 9c66245ee6304146b107e1dd13b9b125e7609142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 30 Oct 2018 15:13:35 +0100 Subject: Integrated the DUT into the testbench and update Makefile to build the sim target- --- src/tb/tb_keywrap_mkmif.v | 58 +++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 19 deletions(-) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index 09fe652..8d42c6d 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -55,8 +55,21 @@ module tb_keywrap_mkm(); integer error_ctr; integer tc_ctr; - reg tb_clk; - reg tb_reset_n; + reg tb_clk; + reg tb_reset_n; + wire tb_mkm_spi_sclk; + wire tb_mkm_spi_cs_n; + reg tb_mkm_spi_do; + wire tb_mkm_spi_di; + reg tb_init; + reg tb_read; + reg tb_write; + reg tb_key_status; + wire tb_ready; + reg [31 : 0] tb_wr_status; + wire [31 : 0] tb_rd_status; + reg [255 : 0] tb_wr_key; + wire [255 : 0] tb_rd_key; //---------------------------------------------------------------- @@ -66,21 +79,21 @@ module tb_keywrap_mkm(); .clk(tb_clk), .reset_n(tb_reset_n), - .mkm_spi_sclk(), - .mkm_spi_cs_n(), - .mkm_spi_do(), - .mkm_spi_di(), - - .init(), - .read(), - .write(), - .key_status(), - .ready(), - - .wr_status(), - .rd_status(), - .wr_key(), - .rd_key + .mkm_spi_sclk(tb_mkm_spi_sclk), + .mkm_spi_cs_n(tb_mkm_spi_cs_n), + .mkm_spi_do(tb_mkm_spi_do), + .mkm_spi_di(tb_mkm_spi_di), + + .init(tb_init), + .read(tb_read), + .write(tb_write), + .key_status(tb_key_status), + .ready(tb_ready), + + .wr_status(tb_wr_status), + .rd_status(tb_rd_status), + .wr_key(tb_wr_key), + .rd_key(tb_rd_key) ); @@ -122,8 +135,15 @@ module tb_keywrap_mkm(); error_ctr = 0; tc_ctr = 0; - tb_clk = 1'h0; - tb_reset_n = 1'h1 + tb_clk = 1'h0; + tb_reset_n = 1'h1; + tb_mkm_spi_do = 1'h0; + tb_init = 1'h0; + tb_read = 1'h0; + tb_write = 1'h0; + tb_key_status = 1'h0; + tb_wr_status = 32'h0; + tb_wr_key = 256'h0; #(CLK_PERIOD); end -- cgit v1.2.3 From 74efb3cd734209511d50b43cf22b8dd77364bc24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 6 Nov 2018 14:16:01 +0100 Subject: Adding test case to observe auto-load of key and status after reset. --- src/tb/tb_keywrap_mkmif.v | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index 8d42c6d..8bd3a05 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -55,6 +55,8 @@ module tb_keywrap_mkm(); integer error_ctr; integer tc_ctr; + integer show_spi; + reg tb_clk; reg tb_reset_n; wire tb_mkm_spi_sclk; @@ -119,6 +121,11 @@ module tb_keywrap_mkm(); begin : sys_monitor cycle_ctr = cycle_ctr + 1; + if (show_spi) + begin + $display("spi_clk: 0x%01x, spi_cs_n: 0x%01x, spi_do: 0x%01x, spi_di: 0x%01x", + tb_mkm_spi_sclk, tb_mkm_spi_cs_n, tb_mkm_spi_do, tb_mkm_spi_di); + end #(CLK_PERIOD); end @@ -135,6 +142,8 @@ module tb_keywrap_mkm(); error_ctr = 0; tc_ctr = 0; + show_spi = 0; + tb_clk = 1'h0; tb_reset_n = 1'h1; tb_mkm_spi_do = 1'h0; @@ -150,6 +159,45 @@ module tb_keywrap_mkm(); endtask // init_sim + //---------------------------------------------------------------- + // reset_dut() + // + // Toggle reset to put the DUT into a well known state. + //---------------------------------------------------------------- + task reset_dut; + begin + $display("TB: Resetting dut."); + tb_reset_n = 0; + #(2 * CLK_PERIOD); + tb_reset_n = 1; + end + endtask // reset_dut + + + //---------------------------------------------------------------- + // test_auto_load + //---------------------------------------------------------------- + task test_auto_load; + begin + tc_ctr = tc_ctr + 1; + + $display("TEST AUTO-LOAD START"); + $display("Check that correct ICV is generated for a single block message."); + + // Observe SPI for a number of cycles. Reset the DUT during monitoring. + show_spi = 1; + #(10 * CLK_PERIOD); + reset_dut(); + #(100 * CLK_PERIOD); + show_spi = 0; + + $display("TEST AUTO-LOAD END"); + $display(""); + end + endtask // auto_load + + + //---------------------------------------------------------------- // main //---------------------------------------------------------------- @@ -160,6 +208,7 @@ module tb_keywrap_mkm(); $display(""); init_sim(); + test_auto_load(); $display(""); $display("*** Keywrap mkmif wrapper testbench done. ***"); -- cgit v1.2.3 From 42d63504f02f895a7b89dc164571c4b0d21cf8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 6 Nov 2018 16:40:14 +0100 Subject: Fixed incorrect address used for the key. Added testcase to verify reading of status word. --- src/tb/tb_keywrap_mkmif.v | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index 8bd3a05..e917c2c 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -182,9 +182,9 @@ module tb_keywrap_mkm(); tc_ctr = tc_ctr + 1; $display("TEST AUTO-LOAD START"); - $display("Check that correct ICV is generated for a single block message."); + $display("Check that key and key status is read automatically after reset."); - // Observe SPI for a number of cycles. Reset the DUT during monitoring. + // Observe SPI for a number of cycles. Reset the DUT during observation. show_spi = 1; #(10 * CLK_PERIOD); reset_dut(); @@ -197,21 +197,51 @@ module tb_keywrap_mkm(); endtask // auto_load + //---------------------------------------------------------------- + // test_write_status + //---------------------------------------------------------------- + task test_write_status; + begin + tc_ctr = tc_ctr + 1; + + $display("TEST WRITE STATUS START"); + $display("Check that we can write the key status word."); + + // Observe SPI for a number of cycles. Reset the DUT during observation. + show_spi = 1; + #(10 * CLK_PERIOD); + + tb_key_status = 1'h0; + tb_write = 1'h1; + tb_wr_status = 32'hdeadbeef; + + #(CLK_PERIOD); + tb_write = 1'h0; + + #(100 * CLK_PERIOD); + show_spi = 0; + + $display("TEST WRITE STATUS END"); + $display(""); + end + endtask // test_write_status + //---------------------------------------------------------------- // main //---------------------------------------------------------------- initial begin : main - $display(" -= Testbench for Keywrap mkmif wrapper started =-"); - $display(" ================================================"); + $display(" -= Testbench for Keywrap mkmif integration started =-"); + $display(" ===================================================="); $display(""); init_sim(); test_auto_load(); + test_write_status(); $display(""); - $display("*** Keywrap mkmif wrapper testbench done. ***"); + $display("*** Keywrap mkmif integration testbench done. ***"); $finish; end // main -- cgit v1.2.3 From 33a7ad0aa4f30582d0858ca31a442316fe075396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Thu, 22 Nov 2018 15:37:26 +0100 Subject: Adding outputs to observe dut API. Adding support in Makefile for using the vendor supplied memory model. --- src/tb/tb_keywrap_mkmif.v | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index e917c2c..faef1df 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -37,7 +37,10 @@ // //====================================================================== -module tb_keywrap_mkm(); +// We need this since the specific memory module sets timescale. +`timescale 1ns/10ps + +module tb_keywrap_mkmif(); //---------------------------------------------------------------- // Parameters. @@ -56,12 +59,13 @@ module tb_keywrap_mkm(); integer tc_ctr; integer show_spi; + integer show_dut_state; reg tb_clk; reg tb_reset_n; wire tb_mkm_spi_sclk; wire tb_mkm_spi_cs_n; - reg tb_mkm_spi_do; + wire tb_mkm_spi_do; wire tb_mkm_spi_di; reg tb_init; reg tb_read; @@ -73,6 +77,8 @@ module tb_keywrap_mkm(); reg [255 : 0] tb_wr_key; wire [255 : 0] tb_rd_key; + wire mem_hold_n = 1'b1; + //---------------------------------------------------------------- // Device Under Test. @@ -99,6 +105,18 @@ module tb_keywrap_mkm(); ); + //---------------------------------------------------------------- + // Memory model. See README.md in src/tech for info on how + // to get the vendor specific model needed here. + //---------------------------------------------------------------- + M23K640 memory(.SI(tb_mkm_spi_di), + .SO(tb_mkm_spi_do), + .SCK(tb_mkm_spi_sclk), + .CS_N(tb_mkm_spi_cs_n), + .HOLD_N(mem_hold_n), + .RESET(tb_reset_n)); + + //---------------------------------------------------------------- // clk_gen // @@ -120,11 +138,21 @@ module tb_keywrap_mkm(); always begin : sys_monitor cycle_ctr = cycle_ctr + 1; + $display("cycle: %08d", cycle_ctr); + + if (show_dut_state) + begin + $display("init: 0x%01x read: 0x%01x write: 0x%01x key_status: 0x%01x", + dut.init, dut.read, dut.write, dut.key_status); + $display("ready: 0x%01x ctrl_state: 0x%02x", dut.ready, dut.keywrap_mkmif_ctrl_reg); + end if (show_spi) begin $display("spi_clk: 0x%01x, spi_cs_n: 0x%01x, spi_do: 0x%01x, spi_di: 0x%01x", tb_mkm_spi_sclk, tb_mkm_spi_cs_n, tb_mkm_spi_do, tb_mkm_spi_di); + $display(); + $display(); end #(CLK_PERIOD); end @@ -142,11 +170,11 @@ module tb_keywrap_mkm(); error_ctr = 0; tc_ctr = 0; - show_spi = 0; + show_spi = 0; + show_dut_state = 1; tb_clk = 1'h0; tb_reset_n = 1'h1; - tb_mkm_spi_do = 1'h0; tb_init = 1'h0; tb_read = 1'h0; tb_write = 1'h0; @@ -166,10 +194,11 @@ module tb_keywrap_mkm(); //---------------------------------------------------------------- task reset_dut; begin - $display("TB: Resetting dut."); + $display("Asserting reset."); tb_reset_n = 0; #(2 * CLK_PERIOD); tb_reset_n = 1; + $display("Deasserting reset."); end endtask // reset_dut @@ -183,6 +212,7 @@ module tb_keywrap_mkm(); $display("TEST AUTO-LOAD START"); $display("Check that key and key status is read automatically after reset."); + $display(); // Observe SPI for a number of cycles. Reset the DUT during observation. show_spi = 1; @@ -245,8 +275,8 @@ module tb_keywrap_mkm(); $finish; end // main -endmodule // tb_keywrap_mkm +endmodule // tb_keywrap_mkmif //====================================================================== -// EOF tb_keywrap_mkm.v +// EOF tb_keywrap_mkmif.v //====================================================================== -- cgit v1.2.3 From 42e3fcaaec5fe0ae0788d3e1c02da1751cbc9c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 23 Nov 2018 07:38:00 +0100 Subject: Adding test case for mem init. Removing auto-load test case since the dut does not support auto load. Updating the write status test case to use wait_ready() for dut status. --- src/tb/tb_keywrap_mkmif.v | 48 ++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index faef1df..1acce3d 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -204,27 +204,40 @@ module tb_keywrap_mkmif(); //---------------------------------------------------------------- - // test_auto_load + // wait_ready() + // + // Wait for ready to be asserted. + //---------------------------------------------------------------- + task wait_ready; + begin + while (!tb_ready) + #(CLK_PERIOD); + + $display("Ready has been set."); + end + endtask // wait_ready + + + //---------------------------------------------------------------- + // test_init_mem //---------------------------------------------------------------- - task test_auto_load; + task test_init_mem; begin tc_ctr = tc_ctr + 1; - $display("TEST AUTO-LOAD START"); - $display("Check that key and key status is read automatically after reset."); + $display("TEST INIT-MEM START"); + $display("Check that the memory is configured when pulling init."); $display(); - // Observe SPI for a number of cycles. Reset the DUT during observation. - show_spi = 1; - #(10 * CLK_PERIOD); - reset_dut(); - #(100 * CLK_PERIOD); - show_spi = 0; + tb_init = 1'h1; + #(CLK_PERIOD); + tb_init = 1'h0; + wait_ready(); - $display("TEST AUTO-LOAD END"); + $display("TEST INIT-MEM END"); $display(""); end - endtask // auto_load + endtask // test_init_mem //---------------------------------------------------------------- @@ -234,24 +247,25 @@ module tb_keywrap_mkmif(); begin tc_ctr = tc_ctr + 1; - $display("TEST WRITE STATUS START"); + $display("TEST WRITE-STATUS START"); $display("Check that we can write the key status word."); // Observe SPI for a number of cycles. Reset the DUT during observation. show_spi = 1; #(10 * CLK_PERIOD); + $display("Trying to write 0xdeadbeef to status address."); + tb_wr_status = 32'hdeadbeef; tb_key_status = 1'h0; tb_write = 1'h1; - tb_wr_status = 32'hdeadbeef; #(CLK_PERIOD); tb_write = 1'h0; - #(100 * CLK_PERIOD); + wait_ready(); show_spi = 0; - $display("TEST WRITE STATUS END"); + $display("TEST WRITE-STATUS END"); $display(""); end endtask // test_write_status @@ -267,7 +281,7 @@ module tb_keywrap_mkmif(); $display(""); init_sim(); - test_auto_load(); + test_init_mem(); test_write_status(); $display(""); -- cgit v1.2.3 From 4e4a87a035e98cc8fbcc6d33b9c6009919213a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 23 Nov 2018 08:17:37 +0100 Subject: Enabled spi observation and can see that SPI interface is alive when pulling init. --- src/tb/tb_keywrap_mkmif.v | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index 1acce3d..ccb8ff3 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -195,10 +195,14 @@ module tb_keywrap_mkmif(); task reset_dut; begin $display("Asserting reset."); + $display(); + tb_reset_n = 0; #(2 * CLK_PERIOD); tb_reset_n = 1; + $display("Deasserting reset."); + $display(); end endtask // reset_dut @@ -210,10 +214,13 @@ module tb_keywrap_mkmif(); //---------------------------------------------------------------- task wait_ready; begin + #(2 * CLK_PERIOD); + while (!tb_ready) #(CLK_PERIOD); $display("Ready has been set."); + $display(); end endtask // wait_ready @@ -229,10 +236,12 @@ module tb_keywrap_mkmif(); $display("Check that the memory is configured when pulling init."); $display(); + show_spi = 1; tb_init = 1'h1; #(CLK_PERIOD); tb_init = 1'h0; wait_ready(); + show_spi = 0; $display("TEST INIT-MEM END"); $display(""); @@ -281,6 +290,7 @@ module tb_keywrap_mkmif(); $display(""); init_sim(); + reset_dut(); test_init_mem(); test_write_status(); -- cgit v1.2.3 From e3ce9cd91fe4da7917dd72920f0a9d0540831c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 23 Nov 2018 10:06:30 +0100 Subject: Added observation of mem internal control states. --- src/tb/tb_keywrap_mkmif.v | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index ccb8ff3..06e3356 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -60,6 +60,7 @@ module tb_keywrap_mkmif(); integer show_spi; integer show_dut_state; + integer show_mem_state; reg tb_clk; reg tb_reset_n; @@ -109,12 +110,12 @@ module tb_keywrap_mkmif(); // Memory model. See README.md in src/tech for info on how // to get the vendor specific model needed here. //---------------------------------------------------------------- - M23K640 memory(.SI(tb_mkm_spi_di), - .SO(tb_mkm_spi_do), - .SCK(tb_mkm_spi_sclk), - .CS_N(tb_mkm_spi_cs_n), - .HOLD_N(mem_hold_n), - .RESET(tb_reset_n)); + M23K640 mem(.SI(tb_mkm_spi_di), + .SO(tb_mkm_spi_do), + .SCK(tb_mkm_spi_sclk), + .CS_N(tb_mkm_spi_cs_n), + .HOLD_N(mem_hold_n), + .RESET(tb_reset_n)); //---------------------------------------------------------------- @@ -147,13 +148,21 @@ module tb_keywrap_mkmif(); $display("ready: 0x%01x ctrl_state: 0x%02x", dut.ready, dut.keywrap_mkmif_ctrl_reg); end + if (show_mem_state) + begin + $display("BitCounter: %08d InstRegister: 0x%01x AddrRegister: 0x%02x", + mem.BitCounter, mem.InstRegister, mem.AddrRegister); + $display("DataShifterI: 0x%02x DataShifterO: 0x%01x", + mem.DataShifterI, mem.DataShifterO); + end + if (show_spi) begin $display("spi_clk: 0x%01x, spi_cs_n: 0x%01x, spi_do: 0x%01x, spi_di: 0x%01x", tb_mkm_spi_sclk, tb_mkm_spi_cs_n, tb_mkm_spi_do, tb_mkm_spi_di); - $display(); - $display(); end + + $display("\n"); #(CLK_PERIOD); end @@ -172,6 +181,7 @@ module tb_keywrap_mkmif(); show_spi = 0; show_dut_state = 1; + show_mem_state = 1; tb_clk = 1'h0; tb_reset_n = 1'h1; -- cgit v1.2.3 From 88d1cb6b6cc58050b406bb0d5134d727d4eca684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 23 Nov 2018 10:34:14 +0100 Subject: Adding task to dump parts of the contents of the serial memory. --- src/tb/tb_keywrap_mkmif.v | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index 06e3356..55305ff 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -167,6 +167,26 @@ module tb_keywrap_mkmif(); end + //---------------------------------------------------------------- + // dump_mem + // + // Dump the contents of the memory model. + //---------------------------------------------------------------- + task dump_mem; + begin : dump_mem + integer i; + + $display("Contents of the first 256 bytes in the serial memory:"); + for (i = 0 ; i < 256 ; i = i + 8) + $display("0x%01x 0x%01x 0x%01x 0x%01x 0x%01x 0x%01x 0x%01x 0x%01x", + mem.MemoryBlock[i], mem.MemoryBlock[i + 1], + mem.MemoryBlock[i + 2], mem.MemoryBlock[i + 3], + mem.MemoryBlock[i + 4], mem.MemoryBlock[i + 5], + mem.MemoryBlock[i + 6], mem.MemoryBlock[i + 7]); + end + endtask // dump_mem + + //---------------------------------------------------------------- // init_sim() // @@ -301,8 +321,10 @@ module tb_keywrap_mkmif(); init_sim(); reset_dut(); + dump_mem(); test_init_mem(); test_write_status(); + dump_mem(); $display(""); $display("*** Keywrap mkmif integration testbench done. ***"); -- cgit v1.2.3 From f67001b76c6b6a7764bbea7fdec5d5d0e3ce9792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 23 Nov 2018 11:08:24 +0100 Subject: Updated display of states. We can now observe correct init of the memory. --- src/tb/tb_keywrap_mkmif.v | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index 55305ff..b22be82 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -143,21 +143,27 @@ module tb_keywrap_mkmif(); if (show_dut_state) begin + $display("DUT control state:"); $display("init: 0x%01x read: 0x%01x write: 0x%01x key_status: 0x%01x", dut.init, dut.read, dut.write, dut.key_status); $display("ready: 0x%01x ctrl_state: 0x%02x", dut.ready, dut.keywrap_mkmif_ctrl_reg); + $display(); end - if (show_mem_state) begin - $display("BitCounter: %08d InstRegister: 0x%01x AddrRegister: 0x%02x", - mem.BitCounter, mem.InstRegister, mem.AddrRegister); - $display("DataShifterI: 0x%02x DataShifterO: 0x%01x", - mem.DataShifterI, mem.DataShifterO); + $display("Memory control state:"); + $display("Hold: 0x%1x BitCounter: 0x%04x", mem.Hold, mem.BitCounter); + $display("DataShifterI: 0x%02x DataShifterO: 0x%1x", mem.DataShifterI, mem.DataShifterO); + $display("InstRegister: 0x%1x AddrRegister: 0x%02x", mem.InstRegister, mem.AddrRegister); + $display("OpMode0: 0x%1x OpMode1: 0x%1x", mem.OpMode0, mem.OpMode1); + $display("InstructionREAD: 0x%1x InstructionRDSR: 0x%1x", mem.InstructionREAD, mem.InstructionRDSR); + $display("InstructionWRSR: 0x%1x InstructionWRITE: 0x%1x", mem.InstructionWRSR, mem.InstructionWRITE); + $display(); end if (show_spi) begin + $display("SPI interface state:"); $display("spi_clk: 0x%01x, spi_cs_n: 0x%01x, spi_do: 0x%01x, spi_di: 0x%01x", tb_mkm_spi_sclk, tb_mkm_spi_cs_n, tb_mkm_spi_do, tb_mkm_spi_di); end -- cgit v1.2.3 From e8fb3bbedca650c3b5fdf0e620bdc231bc85fd55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 23 Nov 2018 12:55:36 +0100 Subject: Added ability observe mkmif state. Realized that the write operation handler was under read operation handling. Fixed this and now status write works. We can observe 0xdeadbeef in the memory after status write operation. --- src/tb/tb_keywrap_mkmif.v | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index b22be82..89e93c7 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -61,6 +61,7 @@ module tb_keywrap_mkmif(); integer show_spi; integer show_dut_state; integer show_mem_state; + integer show_mkm_state; reg tb_clk; reg tb_reset_n; @@ -149,6 +150,14 @@ module tb_keywrap_mkmif(); $display("ready: 0x%01x ctrl_state: 0x%02x", dut.ready, dut.keywrap_mkmif_ctrl_reg); $display(); end + + if (show_mkm_state) + begin + $display("MKM control state:"); + $display("ready: 0x%1x ctrl: 0x%1x", dut.mkm_ready, dut.mkm.mkmif_ctrl_reg); + $display(); + end + if (show_mem_state) begin $display("Memory control state:"); @@ -208,6 +217,7 @@ module tb_keywrap_mkmif(); show_spi = 0; show_dut_state = 1; show_mem_state = 1; + show_mkm_state = 1; tb_clk = 1'h0; tb_reset_n = 1'h1; -- cgit v1.2.3 From 0fb1cd7cddf85af93a29959b66b0295ae0021e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 27 Nov 2018 13:47:35 +0100 Subject: Adding check that correct status word was written into the serial memory. --- src/tb/tb_keywrap_mkmif.v | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index 89e93c7..79083e4 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -216,8 +216,8 @@ module tb_keywrap_mkmif(); show_spi = 0; show_dut_state = 1; - show_mem_state = 1; - show_mkm_state = 1; + show_mem_state = 0; + show_mkm_state = 0; tb_clk = 1'h0; tb_reset_n = 1'h1; @@ -282,7 +282,7 @@ module tb_keywrap_mkmif(); $display("Check that the memory is configured when pulling init."); $display(); - show_spi = 1; + show_spi = 0; tb_init = 1'h1; #(CLK_PERIOD); tb_init = 1'h0; @@ -306,7 +306,7 @@ module tb_keywrap_mkmif(); $display("Check that we can write the key status word."); // Observe SPI for a number of cycles. Reset the DUT during observation. - show_spi = 1; + show_spi = 0; #(10 * CLK_PERIOD); $display("Trying to write 0xdeadbeef to status address."); @@ -320,6 +320,16 @@ module tb_keywrap_mkmif(); wait_ready(); show_spi = 0; + // Check content in memory. + if ((mem.MemoryBlock[0] == 8'hde) && (mem.MemoryBlock[1] == 8'had) && + (mem.MemoryBlock[2] == 8'hbe) && (mem.MemoryBlock[3] == 8'hef)) + $display("Correct status word was written into the memory."); + else + begin + $display("Correct status word was NOT written into the memory."); + error_ctr = error_ctr + 1; + end + $display("TEST WRITE-STATUS END"); $display(""); end -- cgit v1.2.3 From 88c15a5ff837dc6871f7ca8caf4610a4e2d056fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 27 Nov 2018 13:48:22 +0100 Subject: Adding test that tries to write a key into the serial memory. --- src/tb/tb_keywrap_mkmif.v | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index 79083e4..3289a77 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -336,6 +336,39 @@ module tb_keywrap_mkmif(); endtask // test_write_status + //---------------------------------------------------------------- + // test_write_key + //---------------------------------------------------------------- + task test_write_key; + begin + tc_ctr = tc_ctr + 1; + + $display("TEST WRITE-KEY START"); + $display("Check that we can write the key words."); + + // Observe SPI for a number of cycles. Reset the DUT during observation. + show_spi = 0; + #(10 * CLK_PERIOD); + + $display("Trying to write test key to key address."); + $display("test key: 0x01020304 0xaa55aa55 0x00ff00ff 0x0f0e0d0c"); + $display(" 0x11121314 0x55aa55aa 0x11ee11ee 0x1f1e1d1c"); + + tb_wr_key = 256'h01020304_aa55aa55_00ff00ff_0f0e0d0c_11121314_55aa55aa_11ee11ee_1f1e1d1c; + tb_key_status = 1'h1; + tb_write = 1'h1; + + #(CLK_PERIOD); + tb_write = 1'h0; + + wait_ready(); + show_spi = 0; + + $display("TEST WRITE-KEY END"); + $display(""); + end + endtask // test_write_key + //---------------------------------------------------------------- // main //---------------------------------------------------------------- @@ -350,6 +383,7 @@ module tb_keywrap_mkmif(); dump_mem(); test_init_mem(); test_write_status(); + test_write_key(); dump_mem(); $display(""); -- cgit v1.2.3 From 0d2aa16a71c1f0ca183a71c3d5460c6ff1a2f245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 7 Dec 2018 10:03:23 +0100 Subject: Solved event loop. --- src/tb/tb_keywrap_mkmif.v | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'src/tb') diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index 3289a77..b275499 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -215,7 +215,7 @@ module tb_keywrap_mkmif(); tc_ctr = 0; show_spi = 0; - show_dut_state = 1; + show_dut_state = 0; show_mem_state = 0; show_mkm_state = 0; @@ -303,7 +303,7 @@ module tb_keywrap_mkmif(); tc_ctr = tc_ctr + 1; $display("TEST WRITE-STATUS START"); - $display("Check that we can write the key status word."); + $display("Check that we can write the status word."); // Observe SPI for a number of cycles. Reset the DUT during observation. show_spi = 0; @@ -336,6 +336,41 @@ module tb_keywrap_mkmif(); endtask // test_write_status + //---------------------------------------------------------------- + // test_read_status + // Note: This test should be called after test_write_status. + // If not the contents of the memort will be undefined. + //---------------------------------------------------------------- + task test_read_status; + begin + tc_ctr = tc_ctr + 1; + + $display("TEST READ-STATUS START"); + $display("Check that we can read the status word."); + + // Observe SPI for a number of cycles. Reset the DUT during observation. + show_spi = 0; + show_dut_state = 1; + #(10 * CLK_PERIOD); + + $display("Trying to read 0xdeadbeef from the status address."); + tb_key_status = 1'h0; + tb_read = 1'h1; + + #(CLK_PERIOD); + tb_read = 1'h0; + + wait_ready(); + show_spi = 0; + + $display("The word read: 0x%04x", tb_rd_status); + + $display("TEST READ-STATUS END"); + $display(""); + end + endtask // test_read_status + + //---------------------------------------------------------------- // test_write_key //---------------------------------------------------------------- @@ -383,7 +418,8 @@ module tb_keywrap_mkmif(); dump_mem(); test_init_mem(); test_write_status(); - test_write_key(); +// test_read_status(); +// test_write_key(); dump_mem(); $display(""); -- cgit v1.2.3