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/rtl/keywrap.v | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap.v b/src/rtl/keywrap.v index f8fcbd7..b394c9c 100644 --- a/src/rtl/keywrap.v +++ b/src/rtl/keywrap.v @@ -53,6 +53,11 @@ module keywrap #(parameter ADDR_BITS = 13) input wire clk, input wire reset_n, + output wire mkm_spi_sclk, + output wire mkm_spi_cs_n, + input wire mkm_spi_do, + output wire mkm_spi_di, + input wire cs, input wire we, @@ -150,6 +155,12 @@ module keywrap #(parameter ADDR_BITS = 13) wire [63 : 0] core_a_result; wire [31 : 0] core_api_rd_data; + reg mem_cs; + reg mem_we; + reg [7 : 0] mem_address; + reg [31 : 0] mem_write_data; + wire [31 : 0] mem_read_data; + //---------------------------------------------------------------- // Concurrent connectivity for ports etc. @@ -166,7 +177,7 @@ module keywrap #(parameter ADDR_BITS = 13) //---------------------------------------------------------------- - // core instantiation. + // keywrap core instantiation. //---------------------------------------------------------------- keywrap_core #(.MEM_BITS(MEM_BITS)) core( @@ -194,6 +205,22 @@ module keywrap #(parameter ADDR_BITS = 13) .api_rd_data(core_api_rd_data) ); + mkmif memory( + .clk(clk), + .reset_n(reset_n), + + .spi_sclk(mkm_spi_sclk), + .spi_cs_n(mkm_spi_cs_n), + .spi_do(mkm_spi_do), + .spi_di(mkm_spi_di), + + .cs(mem_cs), + .we(mem_we), + .address(mem_address), + .write_data(mem_write_data), + .read_data(mem_read_data) + ); + //---------------------------------------------------------------- // reg_update @@ -330,6 +357,20 @@ module keywrap #(parameter ADDR_BITS = 13) end // else: !if(we) end // if (cs) end // block: api + + + //---------------------------------------------------------------- + // mkmif_ctrl + // Logic needed to handle the integratrion of the mkmif + //---------------------------------------------------------------- + always @* + begin : mkmif_ctrl + mem_cs = 1'h0; + mem_we = 1'h0; + mem_address = 8'h0; + mem_write_data = 32'h0; + end + endmodule // keywrap //====================================================================== -- 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/rtl/keywrap.v | 49 +++++++++++++------------------------------------ src/rtl/keywrap_core.v | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 36 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap.v b/src/rtl/keywrap.v index b394c9c..5604ce4 100644 --- a/src/rtl/keywrap.v +++ b/src/rtl/keywrap.v @@ -151,16 +151,11 @@ module keywrap #(parameter ADDR_BITS = 13) wire core_ready; wire core_valid; wire [255 : 0] core_key; + wire [255 : 0] core_read_key; wire [63 : 0] core_a_init; wire [63 : 0] core_a_result; wire [31 : 0] core_api_rd_data; - reg mem_cs; - reg mem_we; - reg [7 : 0] mem_address; - reg [31 : 0] mem_write_data; - wire [31 : 0] mem_read_data; - //---------------------------------------------------------------- // Concurrent connectivity for ports etc. @@ -184,6 +179,11 @@ module keywrap #(parameter ADDR_BITS = 13) .clk(clk), .reset_n(reset_n), + .mkm_spi_sclk(mkm_spi_sclk), + .mkm_spi_cs_n(mkm_spi_cs_n), + .mkm_spi_do(mkm_spi_do), + .mkm_spi_di(mkm_spi_di), + .init(init_reg), .next(next_reg), .encdec(encdec_reg), @@ -195,6 +195,7 @@ module keywrap #(parameter ADDR_BITS = 13) .key(core_key), .keylen(keylen_reg), + .read_key(core_read_key), .a_init(core_a_init), .a_result(core_a_result), @@ -205,22 +206,6 @@ module keywrap #(parameter ADDR_BITS = 13) .api_rd_data(core_api_rd_data) ); - mkmif memory( - .clk(clk), - .reset_n(reset_n), - - .spi_sclk(mkm_spi_sclk), - .spi_cs_n(mkm_spi_cs_n), - .spi_do(mkm_spi_do), - .spi_di(mkm_spi_di), - - .cs(mem_cs), - .we(mem_we), - .address(mem_address), - .write_data(mem_write_data), - .read_data(mem_read_data) - ); - //---------------------------------------------------------------- // reg_update @@ -303,6 +288,7 @@ module keywrap #(parameter ADDR_BITS = 13) begin if (we) begin + // Write access if (address == {{PAD{1'h0}}, ADDR_CTRL}) begin init_new = write_data[CTRL_INIT_BIT]; @@ -354,23 +340,14 @@ module keywrap #(parameter ADDR_BITS = 13) if (address == {{PAD{1'h0}}, ADDR_A1}) api_rd_delay_new = core_a_result[31 : 0]; + + // Not correct read key mux. + if ((address >= {{PAD{1'h0}}, ADDR_KEY0}) && + (address <= {{PAD{1'h0}}, ADDR_KEY7})) + api_rd_delay_new = core_read_key[031 : 000]; end // else: !if(we) end // if (cs) end // block: api - - - //---------------------------------------------------------------- - // mkmif_ctrl - // Logic needed to handle the integratrion of the mkmif - //---------------------------------------------------------------- - always @* - begin : mkmif_ctrl - mem_cs = 1'h0; - mem_we = 1'h0; - mem_address = 8'h0; - mem_write_data = 32'h0; - end - endmodule // keywrap //====================================================================== diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index d1e63b0..e9a7177 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -45,6 +45,11 @@ module keywrap_core #(parameter MEM_BITS = 11) input wire clk, input wire reset_n, + output wire mkm_spi_sclk, + output wire mkm_spi_cs_n, + input wire mkm_spi_do, + output wire mkm_spi_di, + input wire init, input wire next, input wire encdec, @@ -56,6 +61,7 @@ module keywrap_core #(parameter MEM_BITS = 11) input wire [255 : 0] key, input wire keylen, + output wire [255 : 0] read_key, input wire [63 : 0] a_init, output wire [63 : 0] a_result, @@ -84,6 +90,9 @@ module keywrap_core #(parameter MEM_BITS = 11) localparam CTRL_NEXT_UCHECK = 4'h9; localparam CTRL_NEXT_FINALIZE = 4'ha; + // If set to one, will allow read access to key memory. + localparam DEBUG_MKM_READ = 1'h1; + //---------------------------------------------------------------- // Registers and memories including control signals. @@ -139,6 +148,12 @@ module keywrap_core #(parameter MEM_BITS = 11) reg [63 : 0] core_wr_data; wire [63 : 0] core_rd_data; + reg mkm_cs; + reg mkm_we; + reg [7 : 0] mkm_address; + reg [31 : 0] mkm_write_data; + wire [31 : 0] mkm_read_data; + //---------------------------------------------------------------- // Instantiations. @@ -178,6 +193,23 @@ module keywrap_core #(parameter MEM_BITS = 11) ); + mkmif mkm( + .clk(clk), + .reset_n(reset_n), + + .spi_sclk(mkm_spi_sclk), + .spi_cs_n(mkm_spi_cs_n), + .spi_do(mkm_spi_do), + .spi_di(mkm_spi_di), + + .cs(mkm_cs), + .we(mkm_we), + .address(mkm_address), + .write_data(mkm_write_data), + .read_data(mkm_read_data) + ); + + //---------------------------------------------------------------- // Assignments for ports. //---------------------------------------------------------------- @@ -356,6 +388,10 @@ module keywrap_core #(parameter MEM_BITS = 11) iteration_ctr_dec = 1'h0; iteration_ctr_set = 1'h0; iteration_ctr_rst = 1'h0; + mkm_cs = 1'h0; + mkm_we = 1'h0; + mkm_address = 8'h0; + mkm_write_data = 32'h0; keywrap_core_ctrl_new = CTRL_IDLE; keywrap_core_ctrl_we = 1'h0; -- cgit v1.2.3 From 50bc6e775d7a2a4ad75511c43af93759cc6b09c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 18 Sep 2018 11:19:30 +0200 Subject: Moved compile time debug access control of key to the API. Added correct code to mux key. --- src/rtl/keywrap.v | 15 +++++++++++---- src/rtl/keywrap_core.v | 3 --- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap.v b/src/rtl/keywrap.v index 5604ce4..786ab54 100644 --- a/src/rtl/keywrap.v +++ b/src/rtl/keywrap.v @@ -108,6 +108,11 @@ module keywrap #(parameter ADDR_BITS = 13) localparam PAD = ADDR_BITS - 8; + // If set to one, will allow read access to key memory. + // Should be set to zero in all production FPGA bitstreams. + localparam DEBUG_MKM_READ = 1'h1; + + //---------------------------------------------------------------- // Registers including update variables and write enable. //---------------------------------------------------------------- @@ -341,10 +346,12 @@ module keywrap #(parameter ADDR_BITS = 13) if (address == {{PAD{1'h0}}, ADDR_A1}) api_rd_delay_new = core_a_result[31 : 0]; - // Not correct read key mux. - if ((address >= {{PAD{1'h0}}, ADDR_KEY0}) && - (address <= {{PAD{1'h0}}, ADDR_KEY7})) - api_rd_delay_new = core_read_key[031 : 000]; + // Warning: Should be disabled after mkmif + // integration has been completed. + if (DEBUG_MKM_READ) + if ((address >= {{PAD{1'h0}},ADDR_KEY0}) && (address <= {{PAD{1'h0}}, ADDR_KEY7})) + api_rd_delay_new = core_read_key[(7 - (address - {{PAD{1'h0}}, ADDR_KEY7})) * 32 +: 32]; + end // else: !if(we) end // if (cs) end // block: api diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index e9a7177..6810307 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -90,9 +90,6 @@ module keywrap_core #(parameter MEM_BITS = 11) localparam CTRL_NEXT_UCHECK = 4'h9; localparam CTRL_NEXT_FINALIZE = 4'ha; - // If set to one, will allow read access to key memory. - localparam DEBUG_MKM_READ = 1'h1; - //---------------------------------------------------------------- // Registers and memories including control signals. -- 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/rtl/keywrap.v | 24 +++++++++++++++++++++--- src/rtl/keywrap_core.v | 2 ++ 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap.v b/src/rtl/keywrap.v index 786ab54..870a85c 100644 --- a/src/rtl/keywrap.v +++ b/src/rtl/keywrap.v @@ -77,6 +77,8 @@ module keywrap #(parameter ADDR_BITS = 13) localparam ADDR_CTRL = 8'h08; localparam CTRL_INIT_BIT = 0; localparam CTRL_NEXT_BIT = 1; + localparam CTRL_READ_BIT = 2; + localparam CTRL_WRITE_BIT = 3; localparam ADDR_STATUS = 8'h09; localparam STATUS_READY_BIT = 0; @@ -122,6 +124,12 @@ module keywrap #(parameter ADDR_BITS = 13) reg next_reg; reg next_new; + reg read_reg; + reg read_new; + + reg write_reg; + reg write_new; + reg encdec_reg; reg keylen_reg; reg config_we; @@ -191,6 +199,8 @@ module keywrap #(parameter ADDR_BITS = 13) .init(init_reg), .next(next_reg), + .read(read_reg), + .write(write_reg), .encdec(encdec_reg), .ready(core_ready), @@ -226,6 +236,8 @@ module keywrap #(parameter ADDR_BITS = 13) init_reg <= 1'h0; next_reg <= 1'h0; + read_reg <= 1'h0; + write_reg <= 1'h0; encdec_reg <= 1'h0; keylen_reg <= 1'h0; rlen_reg <= {RLEN_BITS{1'h0}}; @@ -241,6 +253,8 @@ module keywrap #(parameter ADDR_BITS = 13) valid_reg <= core_valid; init_reg <= init_new; next_reg <= next_new; + read_reg <= read_new; + write_reg <= write_new; api_rd_delay_reg <= api_rd_delay_new; if (config_we) @@ -273,6 +287,8 @@ module keywrap #(parameter ADDR_BITS = 13) begin : api init_new = 1'h0; next_new = 1'h0; + read_new = 1'h0; + write_new = 1'h0; config_we = 1'h0; rlen_we = 1'h0; key_we = 1'h0; @@ -296,8 +312,10 @@ module keywrap #(parameter ADDR_BITS = 13) // Write access if (address == {{PAD{1'h0}}, ADDR_CTRL}) begin - init_new = write_data[CTRL_INIT_BIT]; - next_new = write_data[CTRL_NEXT_BIT]; + init_new = write_data[CTRL_INIT_BIT]; + next_new = write_data[CTRL_NEXT_BIT]; + read_new = write_data[CTRL_READ_BIT]; + write_new = write_data[CTRL_WRITE_BIT]; end if (address == {{PAD{1'h0}}, ADDR_CONFIG}) @@ -332,7 +350,7 @@ module keywrap #(parameter ADDR_BITS = 13) api_rd_delay_new = CORE_VERSION; if (address == {{PAD{1'h0}}, ADDR_CTRL}) - api_rd_delay_new = {28'h0, keylen_reg, encdec_reg, next_reg, init_reg}; + api_rd_delay_new = {26'h0, keylen_reg, encdec_reg, write_reg, read_reg, next_reg, init_reg}; if (address == {{PAD{1'h0}}, ADDR_STATUS}) api_rd_delay_new = {30'h0, valid_reg, ready_reg}; diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index 6810307..9c2fa50 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -52,6 +52,8 @@ module keywrap_core #(parameter MEM_BITS = 11) input wire init, input wire next, + input wire read, + input wire write, input wire encdec, output wire ready, -- cgit v1.2.3 From aefd88d9fbc525e4d3dc56b9e01e5ff21f9c1ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 18 Sep 2018 12:51:19 +0200 Subject: Increasing control state reg to support more states. Adding first states for read and write key handling. --- src/rtl/keywrap_core.v | 78 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 13 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index 9c2fa50..c517757 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -80,17 +80,21 @@ module keywrap_core #(parameter MEM_BITS = 11) //---------------------------------------------------------------- localparam MAX_ITERATIONS = 6 - 1; - localparam CTRL_IDLE = 4'h0; - localparam CTRL_INIT_WAIT = 4'h1; - localparam CTRL_NEXT_WSTART = 4'h2; - localparam CTRL_NEXT_USTART = 4'h3; - localparam CTRL_NEXT_LOOP0 = 4'h4; - localparam CTRL_NEXT_LOOP = 4'h5; - localparam CTRL_NEXT_WAIT = 4'h6; - localparam CTRL_NEXT_UPDATE = 4'h7; - localparam CTRL_NEXT_WCHECK = 4'h8; - localparam CTRL_NEXT_UCHECK = 4'h9; - localparam CTRL_NEXT_FINALIZE = 4'ha; + localparam CTRL_IDLE = 5'h0; + localparam CTRL_INIT_WAIT = 5'h1; + localparam CTRL_NEXT_WSTART = 5'h2; + localparam CTRL_NEXT_USTART = 5'h3; + localparam CTRL_NEXT_LOOP0 = 5'h4; + localparam CTRL_NEXT_LOOP = 5'h5; + localparam CTRL_NEXT_WAIT = 5'h6; + localparam CTRL_NEXT_UPDATE = 5'h7; + localparam CTRL_NEXT_WCHECK = 5'h8; + localparam CTRL_NEXT_UCHECK = 5'h9; + localparam CTRL_NEXT_FINALIZE = 5'ha; + localparam CTRL_READ_START = 5'h10; + localparam CTRL_READ_END = 5'h11; + localparam CTRL_WRITE_START = 5'h18; + localparam CTRL_WRITE_END = 5'h19; //---------------------------------------------------------------- @@ -125,8 +129,8 @@ module keywrap_core #(parameter MEM_BITS = 11) reg iteration_ctr_set; reg iteration_ctr_rst; - reg [3 : 0] keywrap_core_ctrl_reg; - reg [3 : 0] keywrap_core_ctrl_new; + reg [4 : 0] keywrap_core_ctrl_reg; + reg [4 : 0] keywrap_core_ctrl_new; reg keywrap_core_ctrl_we; @@ -423,6 +427,22 @@ module keywrap_core #(parameter MEM_BITS = 11) keywrap_core_ctrl_new = CTRL_NEXT_USTART; keywrap_core_ctrl_we = 1'h1; end + + if (read) + begin + ready_new = 1'h0; + ready_we = 1'h1; + keywrap_core_ctrl_new = CTRL_READ_START; + keywrap_core_ctrl_we = 1'h1; + end + + if (write) + begin + ready_new = 1'h0; + ready_we = 1'h1; + keywrap_core_ctrl_new = CTRL_WRITE_START; + keywrap_core_ctrl_we = 1'h1; + end end @@ -553,6 +573,38 @@ module keywrap_core #(parameter MEM_BITS = 11) keywrap_core_ctrl_we = 1'h1; end + + CTRL_READ_START: + begin + keywrap_core_ctrl_new = CTRL_READ_END; + keywrap_core_ctrl_we = 1'h1; + end + + + CTRL_READ_END: + begin + ready_new = 1'h1; + ready_we = 1'h1; + keywrap_core_ctrl_new = CTRL_IDLE; + keywrap_core_ctrl_we = 1'h1; + end + + + CTRL_WRITE_START: + begin + keywrap_core_ctrl_new = CTRL_WRITE_END; + keywrap_core_ctrl_we = 1'h1; + end + + + CTRL_WRITE_END: + begin + ready_new = 1'h1; + ready_we = 1'h1; + keywrap_core_ctrl_new = CTRL_IDLE; + keywrap_core_ctrl_we = 1'h1; + end + default: begin -- cgit v1.2.3 From 0c7becd454c9daf400eaff51978e7a27ed88f6c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 18 Sep 2018 14:44:39 +0200 Subject: Adding more functionality needed for the mkm integration. --- src/rtl/keywrap_core.v | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index c517757..9ae1e75 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -96,6 +96,21 @@ module keywrap_core #(parameter MEM_BITS = 11) localparam CTRL_WRITE_START = 5'h18; localparam CTRL_WRITE_END = 5'h19; + // API for mkm used by the core. + localparam MKM_ADDR_CTRL = 8'h08; + localparam MKM_CTRL_READ_BIT = 0; + localparam MKM_CTRL_WRITE_BIT = 1; + localparam MKM_ADDR_STATUS = 8'h09; + localparam MKM_STATUS_READY_BIT = 0; + localparam MKM_STATUS_VALID_BIT = 1; + localparam MKM_ADDR_SCLK_DIV = 8'h0a; + localparam MKM_ADDR_EMEM_ADDR = 8'h10; + localparam MKM_ADDR_EMEM_DATA = 8'h20; + + // Addresses for storage in the mkm + localparam MKM_STATUS_WORD = 8'h00; + localparam MKM_KEY_BASE_WORD = 8'h04; + //---------------------------------------------------------------- // Registers and memories including control signals. @@ -129,6 +144,17 @@ module keywrap_core #(parameter MEM_BITS = 11) reg iteration_ctr_set; reg iteration_ctr_rst; + reg [31 : 0] core_key [0 : 7]; + reg core_key_we; + + reg [2 : 0] mkm_word_ctr_reg; + reg [2 : 0] mkm_word_ctr_new; + reg mkm_word_ctr_we; + + reg [7 : 0] mkm_addr_reg; + reg [7 : 0] mkm_addr_new; + reg mkm_addr_we; + reg [4 : 0] keywrap_core_ctrl_reg; reg [4 : 0] keywrap_core_ctrl_new; reg keywrap_core_ctrl_we; @@ -226,13 +252,20 @@ module keywrap_core #(parameter MEM_BITS = 11) //---------------------------------------------------------------- always @ (posedge clk or negedge reset_n) begin: reg_update + integer i; + if (!reset_n) begin + for (i = 0 ; i < 8 ; i = i + 1) + core_key[i] <= 32'h0; + a_reg <= 64'h0; ready_reg <= 1'h1; valid_reg <= 1'h1; block_ctr_reg <= {(MEM_BITS - 1){1'h0}}; iteration_ctr_reg <= 3'h0; + mkm_word_ctr_reg <= 3'h0; + mkm_addr_reg <= 8'h0; keywrap_core_ctrl_reg <= CTRL_IDLE; end -- cgit v1.2.3 From 241f9157a534a6f9d953fe06273e2abe2693f4ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 21 Sep 2018 16:54:47 +0200 Subject: Adding more infrastructure needed for the integrated mkm. --- src/rtl/keywrap_core.v | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index 9ae1e75..9f9b329 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -64,6 +64,7 @@ module keywrap_core #(parameter MEM_BITS = 11) input wire [255 : 0] key, input wire keylen, output wire [255 : 0] read_key, + output wire [31 : 0] mkm_status, input wire [63 : 0] a_init, output wire [63 : 0] a_result, @@ -144,8 +145,8 @@ module keywrap_core #(parameter MEM_BITS = 11) reg iteration_ctr_set; reg iteration_ctr_rst; - reg [31 : 0] core_key [0 : 7]; - reg core_key_we; + reg [31 : 0] mkm_key [0 : 7]; + reg mkm_key_we; reg [2 : 0] mkm_word_ctr_reg; reg [2 : 0] mkm_word_ctr_new; @@ -155,6 +156,10 @@ module keywrap_core #(parameter MEM_BITS = 11) reg [7 : 0] mkm_addr_new; reg mkm_addr_we; + reg [31 : 0] mkm_status_reg; + reg [31 : 0] mkm_status_new; + reg mkm_status_we; + reg [4 : 0] keywrap_core_ctrl_reg; reg [4 : 0] keywrap_core_ctrl_new; reg keywrap_core_ctrl_we; @@ -242,9 +247,10 @@ module keywrap_core #(parameter MEM_BITS = 11) //---------------------------------------------------------------- // Assignments for ports. //---------------------------------------------------------------- - assign a_result = a_reg; - assign ready = ready_reg; - assign valid = valid_reg; + assign a_result = a_reg; + assign ready = ready_reg; + assign valid = valid_reg; + assign mkm_status = mkm_status_reg; //---------------------------------------------------------------- @@ -257,7 +263,7 @@ module keywrap_core #(parameter MEM_BITS = 11) if (!reset_n) begin for (i = 0 ; i < 8 ; i = i + 1) - core_key[i] <= 32'h0; + mkm_key[i] <= 32'h0; a_reg <= 64'h0; ready_reg <= 1'h1; @@ -266,6 +272,7 @@ module keywrap_core #(parameter MEM_BITS = 11) iteration_ctr_reg <= 3'h0; mkm_word_ctr_reg <= 3'h0; mkm_addr_reg <= 8'h0; + mkm_status_reg <= 32'h0; keywrap_core_ctrl_reg <= CTRL_IDLE; end @@ -274,6 +281,9 @@ module keywrap_core #(parameter MEM_BITS = 11) if (a_we) a_reg <= a_new; + if (mkm_status_we) + mkm_status_reg <= mkm_read_data; + if (ready_we) ready_reg <= ready_new; @@ -428,6 +438,9 @@ module keywrap_core #(parameter MEM_BITS = 11) mkm_we = 1'h0; mkm_address = 8'h0; mkm_write_data = 32'h0; + mkm_word_ctr_we = 1'h0; + mkm_status_we = 1'h0; + keywrap_core_ctrl_new = CTRL_IDLE; keywrap_core_ctrl_we = 1'h0; -- cgit v1.2.3 From 384b029659d9205b32b2d9707c2fa24c554d0b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 25 Sep 2018 13:44:06 +0200 Subject: Integrate the mkmif_core instead of the mkmif wrapper. --- src/rtl/keywrap_core.v | 55 +++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 21 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index 9f9b329..178cea1 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -112,6 +112,8 @@ module keywrap_core #(parameter MEM_BITS = 11) localparam MKM_STATUS_WORD = 8'h00; localparam MKM_KEY_BASE_WORD = 8'h04; + localparam DEFAULT_SCLK_DIV = 16'h0020; + //---------------------------------------------------------------- // Registers and memories including control signals. @@ -182,9 +184,13 @@ module keywrap_core #(parameter MEM_BITS = 11) reg [63 : 0] core_wr_data; wire [63 : 0] core_rd_data; - reg mkm_cs; - reg mkm_we; - reg [7 : 0] mkm_address; + reg mkm_init_op; + reg mkm_read_op; + reg mkm_write_op; + wire mkm_ready; + wire mkm_valid; + reg [15 : 0] mkm_sclk_div; + reg [15 : 0] mkm_addr; reg [31 : 0] mkm_write_data; wire [31 : 0] mkm_read_data; @@ -227,21 +233,27 @@ module keywrap_core #(parameter MEM_BITS = 11) ); - mkmif mkm( - .clk(clk), - .reset_n(reset_n), + mkmif_core mkm( + .clk(clk), + .reset_n(reset_n), + + .spi_sclk(mkm_spi_sclk), + .spi_cs_n(mkm_spi_cs_n), + .spi_do(mkm_spi_do), + .spi_di(mkm_spi_di), - .spi_sclk(mkm_spi_sclk), - .spi_cs_n(mkm_spi_cs_n), - .spi_do(mkm_spi_do), - .spi_di(mkm_spi_di), + .init_op(mkm_init_op), + .read_op(mkm_read_op), + .write_op(mkm_write_op), - .cs(mkm_cs), - .we(mkm_we), - .address(mkm_address), - .write_data(mkm_write_data), - .read_data(mkm_read_data) - ); + .ready(mkm_ready), + .valid(mkm_valid), + + .sclk_div(mkm_sclk_div), + .addr(mkm_addr), + .write_data(mkm_write_data), + .read_data(mkm_read_data) + ); //---------------------------------------------------------------- @@ -434,12 +446,13 @@ module keywrap_core #(parameter MEM_BITS = 11) iteration_ctr_dec = 1'h0; iteration_ctr_set = 1'h0; iteration_ctr_rst = 1'h0; - mkm_cs = 1'h0; - mkm_we = 1'h0; - mkm_address = 8'h0; + + mkm_init_op = 1'h0; + mkm_read_op = 1'h0; + mkm_write_op = 1'h0; + mkm_sclk_div = DEFAULT_SCLK_DIV; + mkm_addr = 16'h0; mkm_write_data = 32'h0; - mkm_word_ctr_we = 1'h0; - mkm_status_we = 1'h0; keywrap_core_ctrl_new = CTRL_IDLE; keywrap_core_ctrl_we = 1'h0; -- cgit v1.2.3 From 139b3e484d9d170c739498bc9de7ee8106af9c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 25 Sep 2018 14:09:49 +0200 Subject: Increased control state space to make room for read and write operations. --- src/rtl/keywrap_core.v | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index 178cea1..5a05b63 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -81,21 +81,21 @@ module keywrap_core #(parameter MEM_BITS = 11) //---------------------------------------------------------------- localparam MAX_ITERATIONS = 6 - 1; - localparam CTRL_IDLE = 5'h0; - localparam CTRL_INIT_WAIT = 5'h1; - localparam CTRL_NEXT_WSTART = 5'h2; - localparam CTRL_NEXT_USTART = 5'h3; - localparam CTRL_NEXT_LOOP0 = 5'h4; - localparam CTRL_NEXT_LOOP = 5'h5; - localparam CTRL_NEXT_WAIT = 5'h6; - localparam CTRL_NEXT_UPDATE = 5'h7; - localparam CTRL_NEXT_WCHECK = 5'h8; - localparam CTRL_NEXT_UCHECK = 5'h9; - localparam CTRL_NEXT_FINALIZE = 5'ha; - localparam CTRL_READ_START = 5'h10; - localparam CTRL_READ_END = 5'h11; - localparam CTRL_WRITE_START = 5'h18; - localparam CTRL_WRITE_END = 5'h19; + localparam CTRL_IDLE = 6'h0; + localparam CTRL_INIT_WAIT = 6'h1; + localparam CTRL_NEXT_WSTART = 6'h2; + localparam CTRL_NEXT_USTART = 6'h3; + localparam CTRL_NEXT_LOOP0 = 6'h4; + localparam CTRL_NEXT_LOOP = 6'h5; + localparam CTRL_NEXT_WAIT = 6'h6; + localparam CTRL_NEXT_UPDATE = 6'h7; + localparam CTRL_NEXT_WCHECK = 6'h8; + localparam CTRL_NEXT_UCHECK = 6'h9; + localparam CTRL_NEXT_FINALIZE = 6'ha; + localparam CTRL_READ_START = 6'h10; + localparam CTRL_READ_END = 6'h11; + localparam CTRL_WRITE_START = 6'h18; + localparam CTRL_WRITE_END = 6'h19; // API for mkm used by the core. localparam MKM_ADDR_CTRL = 8'h08; @@ -162,8 +162,8 @@ module keywrap_core #(parameter MEM_BITS = 11) reg [31 : 0] mkm_status_new; reg mkm_status_we; - reg [4 : 0] keywrap_core_ctrl_reg; - reg [4 : 0] keywrap_core_ctrl_new; + reg [5 : 0] keywrap_core_ctrl_reg; + reg [5 : 0] keywrap_core_ctrl_new; reg keywrap_core_ctrl_we; -- cgit v1.2.3 From d3e94a0efeec9b2cbac41eea9a57dc3eaf848b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 25 Sep 2018 14:35:35 +0200 Subject: Updated the keywrap API to support access to MKM status. Updated keywrap_core to support control of MKM access operations. --- src/rtl/keywrap.v | 101 ++++++++++++++++++++++++++++--------------------- src/rtl/keywrap_core.v | 52 +++++++++++++------------ 2 files changed, 85 insertions(+), 68 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap.v b/src/rtl/keywrap.v index 870a85c..829ddd1 100644 --- a/src/rtl/keywrap.v +++ b/src/rtl/keywrap.v @@ -70,44 +70,47 @@ module keywrap #(parameter ADDR_BITS = 13) //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- - localparam ADDR_NAME0 = 8'h00; - localparam ADDR_NAME1 = 8'h01; - localparam ADDR_VERSION = 8'h02; - - localparam ADDR_CTRL = 8'h08; - localparam CTRL_INIT_BIT = 0; - localparam CTRL_NEXT_BIT = 1; - localparam CTRL_READ_BIT = 2; - localparam CTRL_WRITE_BIT = 3; - - localparam ADDR_STATUS = 8'h09; - localparam STATUS_READY_BIT = 0; - localparam STATUS_VALID_BIT = 1; - - localparam ADDR_CONFIG = 8'h0a; - localparam CTRL_ENCDEC_BIT = 0; - localparam CTRL_KEYLEN_BIT = 1; - - localparam ADDR_RLEN = 8'h0c; - localparam ADDR_A0 = 8'h0e; - localparam ADDR_A1 = 8'h0f; - - localparam ADDR_KEY0 = 8'h10; - localparam ADDR_KEY1 = 8'h11; - localparam ADDR_KEY2 = 8'h12; - localparam ADDR_KEY3 = 8'h13; - localparam ADDR_KEY4 = 8'h14; - localparam ADDR_KEY5 = 8'h15; - localparam ADDR_KEY6 = 8'h16; - localparam ADDR_KEY7 = 8'h17; - - localparam CORE_NAME0 = 32'h6b657920; // "key " - localparam CORE_NAME1 = 32'h77726170; // "wrap" - localparam CORE_VERSION = 32'h302e3830; // "0.80" - - localparam MEM_BITS = ADDR_BITS - 1; - localparam RLEN_BITS = ADDR_BITS - 2; - localparam PAD = ADDR_BITS - 8; + localparam ADDR_NAME0 = 8'h00; + localparam ADDR_NAME1 = 8'h01; + localparam ADDR_VERSION = 8'h02; + + localparam ADDR_CTRL = 8'h08; + localparam CTRL_INIT_BIT = 0; + localparam CTRL_NEXT_BIT = 1; + localparam CTRL_READ_BIT = 2; + localparam CTRL_WRITE_BIT = 3; + + localparam ADDR_STATUS = 8'h09; + localparam STATUS_READY_BIT = 0; + localparam STATUS_VALID_BIT = 1; + + localparam ADDR_CONFIG = 8'h0a; + localparam CONFIG_ENCDEC_BIT = 0; + localparam CONFIG_KEYLEN_BIT = 1; + localparam CONFIG_MKS_BIT = 2; + + localparam ADDR_RLEN = 8'h0c; + localparam ADDR_A0 = 8'h0e; + localparam ADDR_A1 = 8'h0f; + + localparam ADDR_KEY0 = 8'h10; + localparam ADDR_KEY1 = 8'h11; + localparam ADDR_KEY2 = 8'h12; + localparam ADDR_KEY3 = 8'h13; + localparam ADDR_KEY4 = 8'h14; + localparam ADDR_KEY5 = 8'h15; + localparam ADDR_KEY6 = 8'h16; + localparam ADDR_KEY7 = 8'h17; + + localparam ADDR_MSTATUS = 8'h20; + + localparam CORE_NAME0 = 32'h6b657920; // "key " + localparam CORE_NAME1 = 32'h77726170; // "wrap" + localparam CORE_VERSION = 32'h302e3830; // "0.80" + + localparam MEM_BITS = ADDR_BITS - 1; + localparam RLEN_BITS = ADDR_BITS - 2; + localparam PAD = ADDR_BITS - 8; // If set to one, will allow read access to key memory. @@ -130,6 +133,9 @@ module keywrap #(parameter ADDR_BITS = 13) reg write_reg; reg write_new; + reg mkey_mstatus_reg; + reg mkey_mstatus_new; + reg encdec_reg; reg keylen_reg; reg config_we; @@ -164,7 +170,8 @@ module keywrap #(parameter ADDR_BITS = 13) wire core_ready; wire core_valid; wire [255 : 0] core_key; - wire [255 : 0] core_read_key; + wire [255 : 0] core_mkey; + wire [31 : 0] core_mstatus; wire [63 : 0] core_a_init; wire [63 : 0] core_a_result; wire [31 : 0] core_api_rd_data; @@ -201,6 +208,7 @@ module keywrap #(parameter ADDR_BITS = 13) .next(next_reg), .read(read_reg), .write(write_reg), + .mkey_mstatus(mkey_mstatus_reg), .encdec(encdec_reg), .ready(core_ready), @@ -210,7 +218,8 @@ module keywrap #(parameter ADDR_BITS = 13) .key(core_key), .keylen(keylen_reg), - .read_key(core_read_key), + .mkey(core_mkey), + .mstatus(core_mstatus), .a_init(core_a_init), .a_result(core_a_result), @@ -238,6 +247,7 @@ module keywrap #(parameter ADDR_BITS = 13) next_reg <= 1'h0; read_reg <= 1'h0; write_reg <= 1'h0; + mkey_mstatus_reg <= 1'h0; encdec_reg <= 1'h0; keylen_reg <= 1'h0; rlen_reg <= {RLEN_BITS{1'h0}}; @@ -255,12 +265,14 @@ module keywrap #(parameter ADDR_BITS = 13) next_reg <= next_new; read_reg <= read_new; write_reg <= write_new; + mkey_mstatus_reg <= mkey_mstatus_new; api_rd_delay_reg <= api_rd_delay_new; if (config_we) begin - encdec_reg <= write_data[CTRL_ENCDEC_BIT]; - keylen_reg <= write_data[CTRL_KEYLEN_BIT]; + mkey_mstatus_reg <= write_data[CONFIG_MKS_BIT]; + encdec_reg <= write_data[CONFIG_ENCDEC_BIT]; + keylen_reg <= write_data[CONFIG_KEYLEN_BIT]; end if (rlen_we) @@ -364,11 +376,14 @@ module keywrap #(parameter ADDR_BITS = 13) if (address == {{PAD{1'h0}}, ADDR_A1}) api_rd_delay_new = core_a_result[31 : 0]; + if (address == {{PAD{1'h0}}, ADDR_MSTATUS}) + api_rd_delay_new = core_mstatus; + // Warning: Should be disabled after mkmif // integration has been completed. if (DEBUG_MKM_READ) if ((address >= {{PAD{1'h0}},ADDR_KEY0}) && (address <= {{PAD{1'h0}}, ADDR_KEY7})) - api_rd_delay_new = core_read_key[(7 - (address - {{PAD{1'h0}}, ADDR_KEY7})) * 32 +: 32]; + api_rd_delay_new = core_mkey[(7 - (address - {{PAD{1'h0}}, ADDR_KEY7})) * 32 +: 32]; end // else: !if(we) end // if (cs) diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index 5a05b63..8688e31 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -54,6 +54,7 @@ module keywrap_core #(parameter MEM_BITS = 11) input wire next, input wire read, input wire write, + input wire mkey_mstatus, input wire encdec, output wire ready, @@ -63,8 +64,8 @@ module keywrap_core #(parameter MEM_BITS = 11) input wire [255 : 0] key, input wire keylen, - output wire [255 : 0] read_key, - output wire [31 : 0] mkm_status, + output wire [255 : 0] mkey, + output wire [31 : 0] mstatus, input wire [63 : 0] a_init, output wire [63 : 0] a_result, @@ -81,21 +82,22 @@ module keywrap_core #(parameter MEM_BITS = 11) //---------------------------------------------------------------- localparam MAX_ITERATIONS = 6 - 1; - localparam CTRL_IDLE = 6'h0; - localparam CTRL_INIT_WAIT = 6'h1; - localparam CTRL_NEXT_WSTART = 6'h2; - localparam CTRL_NEXT_USTART = 6'h3; - localparam CTRL_NEXT_LOOP0 = 6'h4; - localparam CTRL_NEXT_LOOP = 6'h5; - localparam CTRL_NEXT_WAIT = 6'h6; - localparam CTRL_NEXT_UPDATE = 6'h7; - localparam CTRL_NEXT_WCHECK = 6'h8; - localparam CTRL_NEXT_UCHECK = 6'h9; - localparam CTRL_NEXT_FINALIZE = 6'ha; - localparam CTRL_READ_START = 6'h10; - localparam CTRL_READ_END = 6'h11; - localparam CTRL_WRITE_START = 6'h18; - localparam CTRL_WRITE_END = 6'h19; + localparam CTRL_IDLE = 6'h0; + localparam CTRL_INIT_WAIT = 6'h1; + localparam CTRL_NEXT_WSTART = 6'h2; + localparam CTRL_NEXT_USTART = 6'h3; + localparam CTRL_NEXT_LOOP0 = 6'h4; + localparam CTRL_NEXT_LOOP = 6'h5; + localparam CTRL_NEXT_WAIT = 6'h6; + localparam CTRL_NEXT_UPDATE = 6'h7; + localparam CTRL_NEXT_WCHECK = 6'h8; + localparam CTRL_NEXT_UCHECK = 6'h9; + localparam CTRL_NEXT_FINALIZE = 6'ha; + + localparam CTRL_MKM_RD_START = 6'h10; + localparam CTRL_MKM_RD_END = 6'h11; + localparam CTRL_MKM_WR_START = 6'h18; + localparam CTRL_MKM_WR_END = 6'h19; // API for mkm used by the core. localparam MKM_ADDR_CTRL = 8'h08; @@ -491,7 +493,7 @@ module keywrap_core #(parameter MEM_BITS = 11) begin ready_new = 1'h0; ready_we = 1'h1; - keywrap_core_ctrl_new = CTRL_READ_START; + keywrap_core_ctrl_new = CTRL_MKM_RD_START; keywrap_core_ctrl_we = 1'h1; end @@ -499,7 +501,7 @@ module keywrap_core #(parameter MEM_BITS = 11) begin ready_new = 1'h0; ready_we = 1'h1; - keywrap_core_ctrl_new = CTRL_WRITE_START; + keywrap_core_ctrl_new = CTRL_MKM_WR_START; keywrap_core_ctrl_we = 1'h1; end end @@ -633,14 +635,14 @@ module keywrap_core #(parameter MEM_BITS = 11) end - CTRL_READ_START: + CTRL_MKM_RD_START: begin - keywrap_core_ctrl_new = CTRL_READ_END; + keywrap_core_ctrl_new = CTRL_MKM_RD_END; keywrap_core_ctrl_we = 1'h1; end - CTRL_READ_END: + CTRL_MKM_RD_END: begin ready_new = 1'h1; ready_we = 1'h1; @@ -649,14 +651,14 @@ module keywrap_core #(parameter MEM_BITS = 11) end - CTRL_WRITE_START: + CTRL_MKM_WR_START: begin - keywrap_core_ctrl_new = CTRL_WRITE_END; + keywrap_core_ctrl_new = CTRL_MKM_WR_END; keywrap_core_ctrl_we = 1'h1; end - CTRL_WRITE_END: + CTRL_MKM_WR_END: begin ready_new = 1'h1; ready_we = 1'h1; -- 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/rtl/keywrap.v | 12 ++++++++++ src/rtl/keywrap_core.v | 65 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 69 insertions(+), 8 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap.v b/src/rtl/keywrap.v index 829ddd1..cc6f8ac 100644 --- a/src/rtl/keywrap.v +++ b/src/rtl/keywrap.v @@ -152,6 +152,9 @@ module keywrap #(parameter ADDR_BITS = 13) reg [31 : 0] key_reg [0 : 7]; reg key_we; + reg [31 : 0] mstatus_reg; + reg mstatus_we; + reg [31 : 0] api_rd_delay_reg; reg [31 : 0] api_rd_delay_new; @@ -218,6 +221,7 @@ module keywrap #(parameter ADDR_BITS = 13) .key(core_key), .keylen(keylen_reg), + .status(mstatus_reg), .mkey(core_mkey), .mstatus(core_mstatus), @@ -250,6 +254,7 @@ module keywrap #(parameter ADDR_BITS = 13) mkey_mstatus_reg <= 1'h0; encdec_reg <= 1'h0; keylen_reg <= 1'h0; + mstatus_reg <= 32'h0; rlen_reg <= {RLEN_BITS{1'h0}}; valid_reg <= 1'h0; ready_reg <= 1'h0; @@ -284,6 +289,9 @@ module keywrap #(parameter ADDR_BITS = 13) if (a1_we) a1_reg <= write_data; + if (mstatus_we) + mstatus_reg <= write_data; + if (key_we) key_reg[address[2 : 0]] <= write_data; end @@ -307,6 +315,7 @@ module keywrap #(parameter ADDR_BITS = 13) core_api_we = 1'h0; a0_we = 1'h0; a1_we = 1'h0; + mstatus_we = 1'h0; tmp_read_data = 32'h0; tmp_error = 1'h0; api_rd_delay_new = 32'h0; @@ -342,6 +351,9 @@ module keywrap #(parameter ADDR_BITS = 13) if (address == {{PAD{1'h0}}, ADDR_A1}) a1_we = 1'h1; + if (address == {{PAD{1'h0}}, ADDR_MSTATUS}) + mstatus_we = 1'h1; + if ((address >= {{PAD{1'h0}}, ADDR_KEY0}) && (address <= {{PAD{1'h0}}, ADDR_KEY7})) key_we = 1'h1; diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index 8688e31..00e8391 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -61,9 +61,9 @@ module keywrap_core #(parameter MEM_BITS = 11) output wire valid, input wire [(MEM_BITS - 2) : 0] rlen, - input wire [255 : 0] key, input wire keylen, + input wire [31 : 0] status, output wire [255 : 0] mkey, output wire [31 : 0] mstatus, @@ -95,9 +95,13 @@ module keywrap_core #(parameter MEM_BITS = 11) localparam CTRL_NEXT_FINALIZE = 6'ha; localparam CTRL_MKM_RD_START = 6'h10; - localparam CTRL_MKM_RD_END = 6'h11; + localparam CTRL_MKM_RD_WAIT0 = 6'h11; + localparam CTRL_MKM_RD_STATUS = 6'h12; + localparam CTRL_MKM_RD_END = 6'h13; + localparam CTRL_MKM_WR_START = 6'h18; - localparam CTRL_MKM_WR_END = 6'h19; + localparam CTRL_MKM_WR_WAIT0 = 6'h19; + localparam CTRL_MKM_WR_END = 6'h1a; // API for mkm used by the core. localparam MKM_ADDR_CTRL = 8'h08; @@ -111,8 +115,8 @@ module keywrap_core #(parameter MEM_BITS = 11) localparam MKM_ADDR_EMEM_DATA = 8'h20; // Addresses for storage in the mkm - localparam MKM_STATUS_WORD = 8'h00; - localparam MKM_KEY_BASE_WORD = 8'h04; + localparam MKM_STATUS_WORD = 16'h00; + localparam MKM_KEY_BASE_WORD = 16'h04; localparam DEFAULT_SCLK_DIV = 16'h0020; @@ -264,7 +268,7 @@ module keywrap_core #(parameter MEM_BITS = 11) assign a_result = a_reg; assign ready = ready_reg; assign valid = valid_reg; - assign mkm_status = mkm_status_reg; + assign mstatus = mkm_status_reg; //---------------------------------------------------------------- @@ -637,11 +641,45 @@ module keywrap_core #(parameter MEM_BITS = 11) CTRL_MKM_RD_START: begin - keywrap_core_ctrl_new = CTRL_MKM_RD_END; + mkm_init_op = 1'h1; + keywrap_core_ctrl_new = CTRL_MKM_RD_WAIT0; keywrap_core_ctrl_we = 1'h1; end + CTRL_MKM_RD_WAIT0: + begin + if (mkm_ready) + // MKM should have been initialized. + if (mkey_mstatus) + begin + // Read master key from mkm. + keywrap_core_ctrl_new = CTRL_MKM_RD_END; + keywrap_core_ctrl_we = 1'h1; + end + else + begin + // Read master key status from mkm. + mkm_read_op = 1'h1; + mkm_addr = MKM_STATUS_WORD; + keywrap_core_ctrl_new = CTRL_MKM_RD_STATUS; + keywrap_core_ctrl_we = 1'h1; + end + end + + + CTRL_MKM_RD_STATUS: + begin + if (mkm_ready) + begin + // status should have been read. + mkm_status_we = 1'h1; + keywrap_core_ctrl_new = CTRL_MKM_RD_END; + keywrap_core_ctrl_we = 1'h1; + end + end + + CTRL_MKM_RD_END: begin ready_new = 1'h1; @@ -653,11 +691,22 @@ module keywrap_core #(parameter MEM_BITS = 11) CTRL_MKM_WR_START: begin - keywrap_core_ctrl_new = CTRL_MKM_WR_END; + mkm_init_op = 1'h1; + keywrap_core_ctrl_new = CTRL_MKM_WR_WAIT0; keywrap_core_ctrl_we = 1'h1; end + CTRL_MKM_WR_WAIT0: + begin + if (mkm_ready) + begin + keywrap_core_ctrl_new = CTRL_MKM_WR_END; + keywrap_core_ctrl_we = 1'h1; + end + end + + CTRL_MKM_WR_END: begin ready_new = 1'h1; -- cgit v1.2.3 From 491a5db2c4379af748499691f173874aed19de22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 28 Sep 2018 10:24:53 +0200 Subject: Adding initial version of mkmif wrapper used by keywrap_core to hide protocol complexity. --- src/rtl/keywrap_mkmif.v | 258 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100644 src/rtl/keywrap_mkmif.v (limited to 'src/rtl') diff --git a/src/rtl/keywrap_mkmif.v b/src/rtl/keywrap_mkmif.v new file mode 100644 index 0000000..bb08921 --- /dev/null +++ b/src/rtl/keywrap_mkmif.v @@ -0,0 +1,258 @@ +//====================================================================== +// +// keywrap_mkmif.v +// --------------- +// Wrapper for the mkmif_core. This allow us to simplify the +// integration of the mkmif in keywrap_core. +// +// +// 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 keywrap_mkmif ( + input wire clk, + input wire reset_n, + + output wire mkm_spi_sclk, + output wire mkm_spi_cs_n, + input wire mkm_spi_do, + output wire mkm_spi_di, + + input wire init, + input wire read, + input wire write, + input wire key_status, + output wire ready, + + input wire [31 : 0] wr_status, + output wire [31 : 0] rd_status, + input wire [255 : 0] wr_key, + output wire [255 : 0] rd_key + ); + + + //---------------------------------------------------------------- + // Paramenters and local defines. + //---------------------------------------------------------------- + localparam CTRL_IDLE = 4'h0; + localparam CTRL_INIT_WAIT = 4'h1; + localparam CTRL_NEXT_WSTART = 4'h2; + localparam CTRL_NEXT_USTART = 4'h3; + localparam CTRL_NEXT_LOOP0 = 4'h4; + localparam CTRL_NEXT_LOOP = 4'h5; + localparam CTRL_NEXT_WAIT = 4'h6; + localparam CTRL_NEXT_UPDATE = 4'h7; + localparam CTRL_NEXT_WCHECK = 4'h8; + localparam CTRL_NEXT_UCHECK = 4'h9; + localparam CTRL_NEXT_FINALIZE = 4'ha; + + // Addresses for storage in the mkm + localparam MKM_STATUS_WORD = 16'h00; + localparam MKM_KEY_BASE_WORD = 16'h04; + + localparam DEFAULT_SCLK_DIV = 16'h0020; + + + //---------------------------------------------------------------- + // Registers and memories including control signals. + //---------------------------------------------------------------- + reg [31 : 0] key_reg [0 : 7]; + reg key_we; + + reg [2 : 0] key_word_ctr_reg; + reg [2 : 0] key_word_ctr_new; + reg key_word_ctr_we; + reg key_word_ctr_rst; + reg key_word_ctr_inc; + + reg [31 : 0] status_reg; + reg [31 : 0] status_new; + reg status_we; + + reg ready_reg; + reg ready_new; + reg ready_we; + + reg [3 : 0] keywrap_mkmif_ctrl_reg; + reg [3 : 0] keywrap_mkmif_ctrl_new; + reg keywrap_mkmif_ctrl_we; + + + //---------------------------------------------------------------- + // Wires. + //---------------------------------------------------------------- + reg mkm_init_op; + reg mkm_read_op; + reg mkm_write_op; + wire mkm_ready; + wire mkm_valid; + reg [15 : 0] mkm_sclk_div; + reg [15 : 0] mkm_addr; + reg [31 : 0] mkm_write_data; + wire [31 : 0] mkm_read_data; + + + //---------------------------------------------------------------- + // Instantiations. + //---------------------------------------------------------------- + mkmif_core mkm( + .clk(clk), + .reset_n(reset_n), + + .spi_sclk(mkm_spi_sclk), + .spi_cs_n(mkm_spi_cs_n), + .spi_do(mkm_spi_do), + .spi_di(mkm_spi_di), + + .init_op(mkm_init_op), + .read_op(mkm_read_op), + .write_op(mkm_write_op), + + .ready(mkm_ready), + .valid(mkm_valid), + + .sclk_div(mkm_sclk_div), + .addr(mkm_addr), + .write_data(mkm_write_data), + .read_data(mkm_read_data) + ); + + + //---------------------------------------------------------------- + // Assignments for ports. + //---------------------------------------------------------------- + + + //---------------------------------------------------------------- + // reg_update + //---------------------------------------------------------------- + always @ (posedge clk or negedge reset_n) + begin: reg_update + integer i; + + if (!reset_n) + begin + for (i = 0 ; i < 8 ; i = i + 1) + key[i] <= 32'h0; + + ready_reg <= 1'h1; + status_reg <= 32'h0; + key_word_ctr_reg <= 3'h0; + keywrap_mkmif_ctrl_reg <= CTRL_IDLE; + end + + else + begin + if (ready_we) + ready_reg <= ready_new; + + if (key_we) + key_reg[key_word_ctr_reg] <= mkm_read_data; + + if (status_we) + status_reg <= mkm_read_data; + + if (key_word_ctr_we) + key_word_ctr_reg <= key_word_ctr_new; + + if (keywrap_mkmif_ctrl_we) + keywrap_mkmif_ctrl_reg <= keywrap_mkmif_ctrl_new; + end + end // reg_update + + + //---------------------------------------------------------------- + // key_word_ctr + //---------------------------------------------------------------- + always @* + begin : key_word_ctr + key_word_ctr_new = 3'h0; + key_word_ctr_we = 1'h0; + + if (key_word_ctr_rst) + begin + iteration_ctr_new = 3'h0; + iteration_ctr_we = 1'h1; + end + + if (key_word_ctr_inc) + begin + key_word_ctr_new = key_word_ctr_reg + 1'h1; + key_word_ctr_we = 1'h1; + end + + end + + + //---------------------------------------------------------------- + // keywrap_mkmif_ctrl + //---------------------------------------------------------------- + always @* + begin : keywrap_mkmif_ctrl + ready_new = 1'h0; + ready_we = 1'h0; + key_we = 1'h0; + key_word_ctr_rst = 1'h0; + key_word_ctr_inc = 1'h0; + status_we = 1'h0; + mkm_init_op = 1'h0; + mkm_read_op = 1'h0; + mkm_write_op = 1'h0; + mkm_sclk_div = DEFAULT_SCLK_DIV; + mkm_addr = 16'h0; + mkm_write_data = 32'h0; + + keywrap_mkmif_ctrl_new = CTRL_IDLE; + keywrap_mkmif_ctrl_we = 1'h0; + + case (keywrap_mkmif_ctrl_reg) + CTRL_IDLE: + begin + if (init) + begin + ready_new = 1'h0; + ready_we = 1'h1; + end + end + + default: + begin + + end + endcase // case (keywrap_mkmif_ctrl_reg) + end // keywrap_mkmif_ctrl + +endmodule // keywrap_mkmif + +//====================================================================== +// EOF keywrap_mkmif.v +//====================================================================== -- cgit v1.2.3 From 86d87571a957365be5191cce7503c8c66c41557e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 28 Sep 2018 11:47:27 +0200 Subject: Got all states needed. Added hold registers for address and data to be written. --- src/rtl/keywrap_mkmif.v | 191 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 169 insertions(+), 22 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_mkmif.v b/src/rtl/keywrap_mkmif.v index bb08921..72eaaf4 100644 --- a/src/rtl/keywrap_mkmif.v +++ b/src/rtl/keywrap_mkmif.v @@ -76,10 +76,10 @@ module keywrap_mkmif ( localparam CTRL_NEXT_FINALIZE = 4'ha; // Addresses for storage in the mkm - localparam MKM_STATUS_WORD = 16'h00; - localparam MKM_KEY_BASE_WORD = 16'h04; + localparam MKM_STATUS_WORD = 16'h00; + localparam MKM_KEY_BASE_WORD = 16'h04; - localparam DEFAULT_SCLK_DIV = 16'h0020; + localparam DEFAULT_SCLK_DIV = 16'h0020; //---------------------------------------------------------------- @@ -94,6 +94,14 @@ module keywrap_mkmif ( reg key_word_ctr_rst; reg key_word_ctr_inc; + reg [15 : 0] mkm_addr_reg; + reg [15 : 0] mkm_addr_new; + reg mkm_addr_we; + + reg [31 : 0] mkm_write_data_reg; + reg [31 : 0] mkm_write_data_new; + reg mkm_write_data_we; + reg [31 : 0] status_reg; reg [31 : 0] status_new; reg status_we; @@ -115,7 +123,6 @@ module keywrap_mkmif ( reg mkm_write_op; wire mkm_ready; wire mkm_valid; - reg [15 : 0] mkm_sclk_div; reg [15 : 0] mkm_addr; reg [31 : 0] mkm_write_data; wire [31 : 0] mkm_read_data; @@ -140,9 +147,9 @@ module keywrap_mkmif ( .ready(mkm_ready), .valid(mkm_valid), - .sclk_div(mkm_sclk_div), - .addr(mkm_addr), - .write_data(mkm_write_data), + .sclk_div(DEFAULT_SCLK_DIV), + .addr(mkm_addr_reg), + .write_data(mkm_write_data_reg), .read_data(mkm_read_data) ); @@ -150,6 +157,12 @@ module keywrap_mkmif ( //---------------------------------------------------------------- // Assignments for ports. //---------------------------------------------------------------- + assign ready = ready_reg; + + assign rd_status = status_reg; + + assign rd_key = {key_reg[7], key_reg[6], key_reg[5], key_reg[4], + key_reg[3], key_reg[2], key_reg[1], key_reg[0]}; //---------------------------------------------------------------- @@ -166,6 +179,8 @@ module keywrap_mkmif ( ready_reg <= 1'h1; status_reg <= 32'h0; + mkm_address_reg <= 16'h0; + mkm_write_data_reg <= 32'h0; key_word_ctr_reg <= 3'h0; keywrap_mkmif_ctrl_reg <= CTRL_IDLE; end @@ -175,6 +190,12 @@ module keywrap_mkmif ( if (ready_we) ready_reg <= ready_new; + if (mkm_addr_we) + mkm_addr_reg <= mkm_addr_new; + + if (mkm_write_data_we) + mkm_write_data_reg <= mkm_write_data_new; + if (key_we) key_reg[key_word_ctr_reg] <= mkm_read_data; @@ -218,19 +239,20 @@ module keywrap_mkmif ( //---------------------------------------------------------------- always @* begin : keywrap_mkmif_ctrl - ready_new = 1'h0; - ready_we = 1'h0; - key_we = 1'h0; - key_word_ctr_rst = 1'h0; - key_word_ctr_inc = 1'h0; - status_we = 1'h0; - mkm_init_op = 1'h0; - mkm_read_op = 1'h0; - mkm_write_op = 1'h0; - mkm_sclk_div = DEFAULT_SCLK_DIV; - mkm_addr = 16'h0; - mkm_write_data = 32'h0; - + ready_new = 1'h0; + ready_we = 1'h0; + key_we = 1'h0; + key_word_ctr_rst = 1'h0; + key_word_ctr_inc = 1'h0; + status_we = 1'h0; + mkm_init_op = 1'h0; + mkm_read_op = 1'h0; + mkm_write_op = 1'h0; + mkm_sclk_div = DEFAULT_SCLK_DIV; + mkm_addr_new = 16'h0; + mkm_addr_we = 1'h0; + mkm_write_data_new = 32'h0; + mkm_write_data_we = 1'h0; keywrap_mkmif_ctrl_new = CTRL_IDLE; keywrap_mkmif_ctrl_we = 1'h0; @@ -239,8 +261,133 @@ module keywrap_mkmif ( begin if (init) begin - ready_new = 1'h0; - ready_we = 1'h1; + mkm_init_op = 1'h1; + ready_new = 1'h0; + ready_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WAIT; + keywrap_mkmif_ctrl_we = 1'h1; + end + + if (read) + begin + ready_new = 1'h0; + ready_we = 1'h1; + + if (key_status) + begin + key_word_ctr_rst = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_READ_KEY; + keywrap_mkmif_ctrl_we = 1'h1; + end + else + begin + mkm_read_op = 1'h1; + mkm_addr_new = MKM_STATUS_WORD; + mkm_addr_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_READ_STATUS_WAIT; + keywrap_mkmif_ctrl_we = 1'h1; + end + + if (write) + if (key_status) + begin + key_word_ctr_rst = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY; + keywrap_mkmif_ctrl_we = 1'h1; + end + else + begin + mkm_write_op = 1'h1; + mkm_addr_new = MKM_STATUS_WORD; + mkm_addr_we = 1'h1; + mkm_write_data_new = wr_status; + mkm_write_data_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WAIT; + keywrap_mkmif_ctrl_we = 1'h1; + end + end + end + + CTRL_WAIT: + begin + if (mkm_ready) + begin + ready_new = 1'h1; + ready_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_IDLE; + keywrap_mkmif_ctrl_we = 1'h1; + end + end + + CTRL_READ_STATUS_WAIT: + begin + if (mkm_ready) + begin + status_we = 1'h1; + ready_new = 1'h1; + ready_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_IDLE; + keywrap_mkmif_ctrl_we = 1'h1; + end + end + + CTRL_READ_KEY: + if (key_word_ctr_reg < 8) + begin + mkm_read_op = 1'h1; + mkm_addr_new = MKM_STATUS_WORD + {key_word_ctr_reg, 2'h0}; + mkm_addr_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY_WAIT; + keywrap_mkmif_ctrl_we = 1'h1; + end + else + begin + ready_new = 1'h1; + ready_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_IDLE; + keywrap_mkmif_ctrl_we = 1'h1; + end + end + + CTRL_READ_KEY_WAIT: + begin + if (mkm_ready) + begin + key_we = 1'h1; + key_word_ctr_inc = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_READ_KEY; + keywrap_mkmif_ctrl_we = 1'h1; + end + end + + CTRL_WRITE_KEY: + begin + if (key_word_ctr_reg < 8) + begin + mkm_write_op = 1'h1; + mkm_addr_new = MKM_STATUS_WORD + {key_word_ctr_reg, 2'h0}; + mkm_addr_we = 1'h1; + mkm_write_data_new = key; + mkm_write_data_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY_WAIT; + keywrap_mkmif_ctrl_we = 1'h1; + end + else + begin + ready_new = 1'h1; + ready_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_IDLE; + keywrap_mkmif_ctrl_we = 1'h1; + end + end + + CTRL_WRITE_KEY_WAIT: + begin + if (mkm_ready) + begin + key_word_ctr_inc = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY; + keywrap_mkmif_ctrl_we = 1'h1; end end -- cgit v1.2.3 From d832fcd65677d54b23dce2f08fd7208c21e50564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 28 Sep 2018 12:21:10 +0200 Subject: Completed the functionality that should be in the wrapper. Now its just debugging... --- src/rtl/keywrap_mkmif.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_mkmif.v b/src/rtl/keywrap_mkmif.v index 72eaaf4..31b7c09 100644 --- a/src/rtl/keywrap_mkmif.v +++ b/src/rtl/keywrap_mkmif.v @@ -367,7 +367,7 @@ module keywrap_mkmif ( mkm_write_op = 1'h1; mkm_addr_new = MKM_STATUS_WORD + {key_word_ctr_reg, 2'h0}; mkm_addr_we = 1'h1; - mkm_write_data_new = key; + mkm_write_data_new = key[key_word_ctr_reg * 32 +: 32]; mkm_write_data_we = 1'h1; keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY_WAIT; keywrap_mkmif_ctrl_we = 1'h1; -- cgit v1.2.3 From 9619025dff8a3a28dea0bc9379f8e33cea1c48dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 28 Sep 2018 12:23:07 +0200 Subject: Some whitespace cleanup. --- src/rtl/keywrap_mkmif.v | 52 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_mkmif.v b/src/rtl/keywrap_mkmif.v index 31b7c09..0399a04 100644 --- a/src/rtl/keywrap_mkmif.v +++ b/src/rtl/keywrap_mkmif.v @@ -39,24 +39,24 @@ //====================================================================== module keywrap_mkmif ( - input wire clk, - input wire reset_n, - - output wire mkm_spi_sclk, - output wire mkm_spi_cs_n, - input wire mkm_spi_do, - output wire mkm_spi_di, - - input wire init, - input wire read, - input wire write, - input wire key_status, - output wire ready, - - input wire [31 : 0] wr_status, - output wire [31 : 0] rd_status, - input wire [255 : 0] wr_key, - output wire [255 : 0] rd_key + input wire clk, + input wire reset_n, + + output wire mkm_spi_sclk, + output wire mkm_spi_cs_n, + input wire mkm_spi_do, + output wire mkm_spi_di, + + input wire init, + input wire read, + input wire write, + input wire key_status, + output wire ready, + + input wire [31 : 0] wr_status, + output wire [31 : 0] rd_status, + input wire [255 : 0] wr_key, + output wire [255 : 0] rd_key ); @@ -118,14 +118,14 @@ module keywrap_mkmif ( //---------------------------------------------------------------- // Wires. //---------------------------------------------------------------- - reg mkm_init_op; - reg mkm_read_op; - reg mkm_write_op; - wire mkm_ready; - wire mkm_valid; - reg [15 : 0] mkm_addr; - reg [31 : 0] mkm_write_data; - wire [31 : 0] mkm_read_data; + reg mkm_init_op; + reg mkm_read_op; + reg mkm_write_op; + wire mkm_ready; + wire mkm_valid; + reg [15 : 0] mkm_addr; + reg [31 : 0] mkm_write_data; + wire [31 : 0] mkm_read_data; //---------------------------------------------------------------- -- cgit v1.2.3 From 4da2caadb9219e5126ef15ec133faa36e61049c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 28 Sep 2018 12:37:04 +0200 Subject: Integrated new mkmif_core wrapper. --- src/rtl/keywrap_core.v | 71 +++++++++++++++++-------------------------------- src/rtl/keywrap_mkmif.v | 22 +++++++-------- 2 files changed, 33 insertions(+), 60 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index 00e8391..533cc83 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -153,21 +153,6 @@ module keywrap_core #(parameter MEM_BITS = 11) reg iteration_ctr_set; reg iteration_ctr_rst; - reg [31 : 0] mkm_key [0 : 7]; - reg mkm_key_we; - - reg [2 : 0] mkm_word_ctr_reg; - reg [2 : 0] mkm_word_ctr_new; - reg mkm_word_ctr_we; - - reg [7 : 0] mkm_addr_reg; - reg [7 : 0] mkm_addr_new; - reg mkm_addr_we; - - reg [31 : 0] mkm_status_reg; - reg [31 : 0] mkm_status_new; - reg mkm_status_we; - reg [5 : 0] keywrap_core_ctrl_reg; reg [5 : 0] keywrap_core_ctrl_new; reg keywrap_core_ctrl_we; @@ -190,15 +175,14 @@ module keywrap_core #(parameter MEM_BITS = 11) reg [63 : 0] core_wr_data; wire [63 : 0] core_rd_data; - reg mkm_init_op; - reg mkm_read_op; - reg mkm_write_op; + reg mkm_init; + reg mkm_read; + reg mkm_write; + reg mkm_key_status; wire mkm_ready; - wire mkm_valid; - reg [15 : 0] mkm_sclk_div; - reg [15 : 0] mkm_addr; - reg [31 : 0] mkm_write_data; - wire [31 : 0] mkm_read_data; + wire [255 : 0] mkm_key; + wire [31 : 0] mkm_rd_status; + wire [31 : 0] mkm_wr_status; //---------------------------------------------------------------- @@ -239,27 +223,26 @@ module keywrap_core #(parameter MEM_BITS = 11) ); - mkmif_core mkm( - .clk(clk), - .reset_n(reset_n), - - .spi_sclk(mkm_spi_sclk), - .spi_cs_n(mkm_spi_cs_n), - .spi_do(mkm_spi_do), - .spi_di(mkm_spi_di), + keywrap_mkmif mkmif( + .clk(clk), + .reset_n(reset_n), - .init_op(mkm_init_op), - .read_op(mkm_read_op), - .write_op(mkm_write_op), + .mkm_spi_sclk(mkm_spi_sclk), + .mkm_spi_cs_n(mkm_spi_cs_n), + .mkm_spi_do(mkm_spi_do), + .mkm_spi_di(mkm_spi_di), - .ready(mkm_ready), - .valid(mkm_valid), + .init(mkm_init), + .read(mkm_read), + .write(mkm_write), + .key_status(mkm_key_status), + .ready(mkm_ready), - .sclk_div(mkm_sclk_div), - .addr(mkm_addr), - .write_data(mkm_write_data), - .read_data(mkm_read_data) - ); + .wr_status(mkm_wr_status), + .rd_status(mkm_rd_status), + .wr_key(key), + .rd_key(mkm_key) + ); //---------------------------------------------------------------- @@ -280,17 +263,11 @@ module keywrap_core #(parameter MEM_BITS = 11) if (!reset_n) begin - for (i = 0 ; i < 8 ; i = i + 1) - mkm_key[i] <= 32'h0; - a_reg <= 64'h0; ready_reg <= 1'h1; valid_reg <= 1'h1; block_ctr_reg <= {(MEM_BITS - 1){1'h0}}; iteration_ctr_reg <= 3'h0; - mkm_word_ctr_reg <= 3'h0; - mkm_addr_reg <= 8'h0; - mkm_status_reg <= 32'h0; keywrap_core_ctrl_reg <= CTRL_IDLE; end diff --git a/src/rtl/keywrap_mkmif.v b/src/rtl/keywrap_mkmif.v index 0399a04..082173b 100644 --- a/src/rtl/keywrap_mkmif.v +++ b/src/rtl/keywrap_mkmif.v @@ -63,17 +63,13 @@ module keywrap_mkmif ( //---------------------------------------------------------------- // Paramenters and local defines. //---------------------------------------------------------------- - localparam CTRL_IDLE = 4'h0; - localparam CTRL_INIT_WAIT = 4'h1; - localparam CTRL_NEXT_WSTART = 4'h2; - localparam CTRL_NEXT_USTART = 4'h3; - localparam CTRL_NEXT_LOOP0 = 4'h4; - localparam CTRL_NEXT_LOOP = 4'h5; - localparam CTRL_NEXT_WAIT = 4'h6; - localparam CTRL_NEXT_UPDATE = 4'h7; - localparam CTRL_NEXT_WCHECK = 4'h8; - localparam CTRL_NEXT_UCHECK = 4'h9; - localparam CTRL_NEXT_FINALIZE = 4'ha; + localparam CTRL_IDLE = 3'h0; + localparam CTRL_WAIT = 3'h1; + localparam CTRL_READ_STATUS_WAIT = 3'h2; + localparam CTRL_READ_KEY = 3'h3; + localparam CTRL_READ_KEY_WAIT = 3'h4; + localparam CTRL_WRITE_KEY = 3'h5; + localparam CTRL_WRITE_KEY_WAIT = 3'h6; // Addresses for storage in the mkm localparam MKM_STATUS_WORD = 16'h00; @@ -110,8 +106,8 @@ module keywrap_mkmif ( reg ready_new; reg ready_we; - reg [3 : 0] keywrap_mkmif_ctrl_reg; - reg [3 : 0] keywrap_mkmif_ctrl_new; + reg [2 : 0] keywrap_mkmif_ctrl_reg; + reg [2 : 0] keywrap_mkmif_ctrl_new; reg keywrap_mkmif_ctrl_we; -- 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/rtl/keywrap_core.v | 184 +++++++++++++++--------------------------------- src/rtl/keywrap_mkmif.v | 12 ++-- 2 files changed, 63 insertions(+), 133 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index 533cc83..cf6e00a 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -55,6 +55,7 @@ module keywrap_core #(parameter MEM_BITS = 11) input wire read, input wire write, input wire mkey_mstatus, + input wire mkey_key, input wire encdec, output wire ready, @@ -82,43 +83,19 @@ module keywrap_core #(parameter MEM_BITS = 11) //---------------------------------------------------------------- localparam MAX_ITERATIONS = 6 - 1; - localparam CTRL_IDLE = 6'h0; - localparam CTRL_INIT_WAIT = 6'h1; - localparam CTRL_NEXT_WSTART = 6'h2; - localparam CTRL_NEXT_USTART = 6'h3; - localparam CTRL_NEXT_LOOP0 = 6'h4; - localparam CTRL_NEXT_LOOP = 6'h5; - localparam CTRL_NEXT_WAIT = 6'h6; - localparam CTRL_NEXT_UPDATE = 6'h7; - localparam CTRL_NEXT_WCHECK = 6'h8; - localparam CTRL_NEXT_UCHECK = 6'h9; - localparam CTRL_NEXT_FINALIZE = 6'ha; - - localparam CTRL_MKM_RD_START = 6'h10; - localparam CTRL_MKM_RD_WAIT0 = 6'h11; - localparam CTRL_MKM_RD_STATUS = 6'h12; - localparam CTRL_MKM_RD_END = 6'h13; - - localparam CTRL_MKM_WR_START = 6'h18; - localparam CTRL_MKM_WR_WAIT0 = 6'h19; - localparam CTRL_MKM_WR_END = 6'h1a; - - // API for mkm used by the core. - localparam MKM_ADDR_CTRL = 8'h08; - localparam MKM_CTRL_READ_BIT = 0; - localparam MKM_CTRL_WRITE_BIT = 1; - localparam MKM_ADDR_STATUS = 8'h09; - localparam MKM_STATUS_READY_BIT = 0; - localparam MKM_STATUS_VALID_BIT = 1; - localparam MKM_ADDR_SCLK_DIV = 8'h0a; - localparam MKM_ADDR_EMEM_ADDR = 8'h10; - localparam MKM_ADDR_EMEM_DATA = 8'h20; - - // Addresses for storage in the mkm - localparam MKM_STATUS_WORD = 16'h00; - localparam MKM_KEY_BASE_WORD = 16'h04; - - localparam DEFAULT_SCLK_DIV = 16'h0020; + localparam CTRL_RESET = 4'h0; + localparam CTRL_IDLE = 4'h1; + localparam CTRL_INIT_WAIT = 4'h2; + localparam CTRL_NEXT_WSTART = 4'h3; + localparam CTRL_NEXT_USTART = 4'h4; + localparam CTRL_NEXT_LOOP0 = 4'h5; + localparam CTRL_NEXT_LOOP = 4'h6; + localparam CTRL_NEXT_WAIT = 4'h7; + localparam CTRL_NEXT_UPDATE = 4'h8; + localparam CTRL_NEXT_WCHECK = 4'h9; + localparam CTRL_NEXT_UCHECK = 4'ha; + localparam CTRL_NEXT_FINALIZE = 4'hb; + localparam CTRL_MKM_WAIT = 4'hc; //---------------------------------------------------------------- @@ -153,8 +130,8 @@ module keywrap_core #(parameter MEM_BITS = 11) reg iteration_ctr_set; reg iteration_ctr_rst; - reg [5 : 0] keywrap_core_ctrl_reg; - reg [5 : 0] keywrap_core_ctrl_new; + reg [3 : 0] keywrap_core_ctrl_reg; + reg [3 : 0] keywrap_core_ctrl_new; reg keywrap_core_ctrl_we; @@ -167,6 +144,7 @@ module keywrap_core #(parameter MEM_BITS = 11) wire aes_valid; reg [127 : 0] aes_block; wire [127 : 0] aes_result; + reg [255 : 0] aes_key; reg update_state; @@ -180,7 +158,7 @@ module keywrap_core #(parameter MEM_BITS = 11) reg mkm_write; reg mkm_key_status; wire mkm_ready; - wire [255 : 0] mkm_key; + wire [255 : 0] mkm_rd_key; wire [31 : 0] mkm_rd_status; wire [31 : 0] mkm_wr_status; @@ -212,7 +190,7 @@ module keywrap_core #(parameter MEM_BITS = 11) .init(aes_init), .next(aes_next), - .key(key), + .key(aes_key), .keylen(keylen), .block(aes_block), @@ -235,13 +213,13 @@ module keywrap_core #(parameter MEM_BITS = 11) .init(mkm_init), .read(mkm_read), .write(mkm_write), - .key_status(mkm_key_status), + .key_status(mkey_mstatus), .ready(mkm_ready), .wr_status(mkm_wr_status), .rd_status(mkm_rd_status), .wr_key(key), - .rd_key(mkm_key) + .rd_key(mkm_rd_key) ); @@ -251,7 +229,8 @@ module keywrap_core #(parameter MEM_BITS = 11) assign a_result = a_reg; assign ready = ready_reg; assign valid = valid_reg; - assign mstatus = mkm_status_reg; + assign mkey = mkm_rd_key; + assign mstatus = mkm_rd_status; //---------------------------------------------------------------- @@ -268,7 +247,7 @@ module keywrap_core #(parameter MEM_BITS = 11) valid_reg <= 1'h1; block_ctr_reg <= {(MEM_BITS - 1){1'h0}}; iteration_ctr_reg <= 3'h0; - keywrap_core_ctrl_reg <= CTRL_IDLE; + keywrap_core_ctrl_reg <= CTRL_RESET; end else @@ -276,9 +255,6 @@ module keywrap_core #(parameter MEM_BITS = 11) if (a_we) a_reg <= a_new; - if (mkm_status_we) - mkm_status_reg <= mkm_read_data; - if (ready_we) ready_reg <= ready_new; @@ -407,6 +383,17 @@ module keywrap_core #(parameter MEM_BITS = 11) end + //---------------------------------------------------------------- + // aes_key_mux + //---------------------------------------------------------------- + always @* + begin + if (mkey_key) + aes_key = mkm_rd_key; + else + aes_key = key; + end + //---------------------------------------------------------------- // keywrap_core_ctrl @@ -421,6 +408,9 @@ module keywrap_core #(parameter MEM_BITS = 11) update_state = 1'h0; aes_init = 1'h0; aes_next = 1'h0; + mkm_init = 1'h0; + mkm_read = 1'h0; + mkm_write = 1'h0; block_ctr_dec = 1'h0; block_ctr_inc = 1'h0; block_ctr_rst = 1'h0; @@ -430,18 +420,21 @@ module keywrap_core #(parameter MEM_BITS = 11) iteration_ctr_set = 1'h0; iteration_ctr_rst = 1'h0; - mkm_init_op = 1'h0; - mkm_read_op = 1'h0; - mkm_write_op = 1'h0; - mkm_sclk_div = DEFAULT_SCLK_DIV; - mkm_addr = 16'h0; - mkm_write_data = 32'h0; - keywrap_core_ctrl_new = CTRL_IDLE; keywrap_core_ctrl_we = 1'h0; case (keywrap_core_ctrl_reg) + CTRL_RESET: + begin + mkm_init = 1'h1; + ready_new = 1'h0; + ready_we = 1'h1; + keywrap_core_ctrl_new = CTRL_MKM_WAIT; + keywrap_core_ctrl_we = 1'h0; + end + + CTRL_IDLE: begin if (init) @@ -472,17 +465,20 @@ module keywrap_core #(parameter MEM_BITS = 11) if (read) begin + mkm_write = 1'h1; ready_new = 1'h0; ready_we = 1'h1; - keywrap_core_ctrl_new = CTRL_MKM_RD_START; + mkm_read = 1'h1; + keywrap_core_ctrl_new = CTRL_MKM_WAIT; keywrap_core_ctrl_we = 1'h1; end if (write) begin + mkm_write = 1'h1; ready_new = 1'h0; ready_we = 1'h1; - keywrap_core_ctrl_new = CTRL_MKM_WR_START; + keywrap_core_ctrl_new = CTRL_MKM_WAIT; keywrap_core_ctrl_we = 1'h1; end end @@ -616,85 +612,19 @@ module keywrap_core #(parameter MEM_BITS = 11) end - CTRL_MKM_RD_START: - begin - mkm_init_op = 1'h1; - keywrap_core_ctrl_new = CTRL_MKM_RD_WAIT0; - keywrap_core_ctrl_we = 1'h1; - end - - - CTRL_MKM_RD_WAIT0: - begin - if (mkm_ready) - // MKM should have been initialized. - if (mkey_mstatus) - begin - // Read master key from mkm. - keywrap_core_ctrl_new = CTRL_MKM_RD_END; - keywrap_core_ctrl_we = 1'h1; - end - else - begin - // Read master key status from mkm. - mkm_read_op = 1'h1; - mkm_addr = MKM_STATUS_WORD; - keywrap_core_ctrl_new = CTRL_MKM_RD_STATUS; - keywrap_core_ctrl_we = 1'h1; - end - end - - - CTRL_MKM_RD_STATUS: - begin - if (mkm_ready) - begin - // status should have been read. - mkm_status_we = 1'h1; - keywrap_core_ctrl_new = CTRL_MKM_RD_END; - keywrap_core_ctrl_we = 1'h1; - end - end - - - CTRL_MKM_RD_END: - begin - ready_new = 1'h1; - ready_we = 1'h1; - keywrap_core_ctrl_new = CTRL_IDLE; - keywrap_core_ctrl_we = 1'h1; - end - - - CTRL_MKM_WR_START: - begin - mkm_init_op = 1'h1; - keywrap_core_ctrl_new = CTRL_MKM_WR_WAIT0; - keywrap_core_ctrl_we = 1'h1; - end - - - CTRL_MKM_WR_WAIT0: + CTRL_MKM_WAIT: begin if (mkm_ready) begin - keywrap_core_ctrl_new = CTRL_MKM_WR_END; + ready_new = 1'h1; + ready_we = 1'h1; + keywrap_core_ctrl_new = CTRL_IDLE; keywrap_core_ctrl_we = 1'h1; end end - - CTRL_MKM_WR_END: - begin - ready_new = 1'h1; - ready_we = 1'h1; - keywrap_core_ctrl_new = CTRL_IDLE; - keywrap_core_ctrl_we = 1'h1; - end - default: begin - end endcase // case (keywrap_core_ctrl_reg) end // keywrap_core_ctrl diff --git a/src/rtl/keywrap_mkmif.v b/src/rtl/keywrap_mkmif.v index 082173b..ad2121e 100644 --- a/src/rtl/keywrap_mkmif.v +++ b/src/rtl/keywrap_mkmif.v @@ -171,11 +171,11 @@ module keywrap_mkmif ( if (!reset_n) begin for (i = 0 ; i < 8 ; i = i + 1) - key[i] <= 32'h0; + key_reg[i] <= 32'h0; ready_reg <= 1'h1; status_reg <= 32'h0; - mkm_address_reg <= 16'h0; + mkm_addr_reg <= 16'h0; mkm_write_data_reg <= 32'h0; key_word_ctr_reg <= 3'h0; keywrap_mkmif_ctrl_reg <= CTRL_IDLE; @@ -217,8 +217,8 @@ module keywrap_mkmif ( if (key_word_ctr_rst) begin - iteration_ctr_new = 3'h0; - iteration_ctr_we = 1'h1; + key_word_ctr_new = 3'h0; + key_word_ctr_we = 1'h1; end if (key_word_ctr_inc) @@ -244,7 +244,6 @@ module keywrap_mkmif ( mkm_init_op = 1'h0; mkm_read_op = 1'h0; mkm_write_op = 1'h0; - mkm_sclk_div = DEFAULT_SCLK_DIV; mkm_addr_new = 16'h0; mkm_addr_we = 1'h0; mkm_write_data_new = 32'h0; @@ -328,6 +327,7 @@ module keywrap_mkmif ( end CTRL_READ_KEY: + begin if (key_word_ctr_reg < 8) begin mkm_read_op = 1'h1; @@ -363,7 +363,7 @@ module keywrap_mkmif ( mkm_write_op = 1'h1; mkm_addr_new = MKM_STATUS_WORD + {key_word_ctr_reg, 2'h0}; mkm_addr_we = 1'h1; - mkm_write_data_new = key[key_word_ctr_reg * 32 +: 32]; + mkm_write_data_new = wr_key[key_word_ctr_reg * 32 +: 32]; mkm_write_data_we = 1'h1; keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY_WAIT; keywrap_mkmif_ctrl_we = 1'h1; -- cgit v1.2.3 From aced6ee13af2d15ee0a9ccd8e681faf1519106ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 23 Oct 2018 10:50:22 +0200 Subject: Hardened the keywrap API to not allow reads or writes when the core is busy. --- src/rtl/keywrap.v | 55 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 26 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap.v b/src/rtl/keywrap.v index cc6f8ac..53deaaf 100644 --- a/src/rtl/keywrap.v +++ b/src/rtl/keywrap.v @@ -321,45 +321,48 @@ module keywrap #(parameter ADDR_BITS = 13) api_rd_delay_new = 32'h0; // api_mux - if (address[(ADDR_BITS - 1)]) - tmp_read_data = core_api_rd_data; - else - tmp_read_data = api_rd_delay_reg; + if (core_ready) + if (address[(ADDR_BITS - 1)]) + tmp_read_data = core_api_rd_data; + else + tmp_read_data = api_rd_delay_reg; if (cs) begin if (we) begin - // Write access - if (address == {{PAD{1'h0}}, ADDR_CTRL}) + if (core_ready) begin - init_new = write_data[CTRL_INIT_BIT]; - next_new = write_data[CTRL_NEXT_BIT]; - read_new = write_data[CTRL_READ_BIT]; - write_new = write_data[CTRL_WRITE_BIT]; - end + if (address == {{PAD{1'h0}}, ADDR_CTRL}) + begin + init_new = write_data[CTRL_INIT_BIT]; + next_new = write_data[CTRL_NEXT_BIT]; + read_new = write_data[CTRL_READ_BIT]; + write_new = write_data[CTRL_WRITE_BIT]; + end - if (address == {{PAD{1'h0}}, ADDR_CONFIG}) - config_we = 1'h1; + if (address == {{PAD{1'h0}}, ADDR_CONFIG}) + config_we = 1'h1; - if (address == {{PAD{1'h0}}, ADDR_RLEN}) - rlen_we = 1'h1; + if (address == {{PAD{1'h0}}, ADDR_RLEN}) + rlen_we = 1'h1; - if (address == {{PAD{1'h0}}, ADDR_A0}) - a0_we = 1'h1; + if (address == {{PAD{1'h0}}, ADDR_A0}) + a0_we = 1'h1; - if (address == {{PAD{1'h0}}, ADDR_A1}) - a1_we = 1'h1; + if (address == {{PAD{1'h0}}, ADDR_A1}) + a1_we = 1'h1; - if (address == {{PAD{1'h0}}, ADDR_MSTATUS}) - mstatus_we = 1'h1; + if (address == {{PAD{1'h0}}, ADDR_MSTATUS}) + mstatus_we = 1'h1; - if ((address >= {{PAD{1'h0}}, ADDR_KEY0}) && - (address <= {{PAD{1'h0}}, ADDR_KEY7})) - key_we = 1'h1; + if ((address >= {{PAD{1'h0}}, ADDR_KEY0}) && + (address <= {{PAD{1'h0}}, ADDR_KEY7})) + key_we = 1'h1; - if (address[(ADDR_BITS - 1)]) - core_api_we = 1'h1; + if (address[(ADDR_BITS - 1)]) + core_api_we = 1'h1; + end end // if (we) else begin -- cgit v1.2.3 From 8b4f7c06886b3cb937d11fe9d2bd9a4f62a6d621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 6 Nov 2018 14:30:53 +0100 Subject: Trigger read operation when we should read. --- src/rtl/keywrap_core.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v index cf6e00a..378a61a 100644 --- a/src/rtl/keywrap_core.v +++ b/src/rtl/keywrap_core.v @@ -465,7 +465,7 @@ module keywrap_core #(parameter MEM_BITS = 11) if (read) begin - mkm_write = 1'h1; + mkm_read = 1'h1; ready_new = 1'h0; ready_we = 1'h1; mkm_read = 1'h1; -- 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/rtl/keywrap_mkmif.v | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_mkmif.v b/src/rtl/keywrap_mkmif.v index ad2121e..e2b9302 100644 --- a/src/rtl/keywrap_mkmif.v +++ b/src/rtl/keywrap_mkmif.v @@ -331,7 +331,7 @@ module keywrap_mkmif ( if (key_word_ctr_reg < 8) begin mkm_read_op = 1'h1; - mkm_addr_new = MKM_STATUS_WORD + {key_word_ctr_reg, 2'h0}; + mkm_addr_new = MKM_KEY_BASE_WORD + {key_word_ctr_reg, 2'h0}; mkm_addr_we = 1'h1; keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY_WAIT; keywrap_mkmif_ctrl_we = 1'h1; @@ -361,7 +361,7 @@ module keywrap_mkmif ( if (key_word_ctr_reg < 8) begin mkm_write_op = 1'h1; - mkm_addr_new = MKM_STATUS_WORD + {key_word_ctr_reg, 2'h0}; + mkm_addr_new = MKM_KEY_BASE_WORD + {key_word_ctr_reg, 2'h0}; mkm_addr_we = 1'h1; mkm_write_data_new = wr_key[key_word_ctr_reg * 32 +: 32]; mkm_write_data_we = 1'h1; -- 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/rtl/keywrap_mkmif.v | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_mkmif.v b/src/rtl/keywrap_mkmif.v index e2b9302..88af6f8 100644 --- a/src/rtl/keywrap_mkmif.v +++ b/src/rtl/keywrap_mkmif.v @@ -282,27 +282,33 @@ module keywrap_mkmif ( keywrap_mkmif_ctrl_new = CTRL_READ_STATUS_WAIT; keywrap_mkmif_ctrl_we = 1'h1; end + end + + if (write) + begin + ready_new = 1'h0; + ready_we = 1'h1; - if (write) - if (key_status) - begin - key_word_ctr_rst = 1'h1; - keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY; - keywrap_mkmif_ctrl_we = 1'h1; - end - else - begin - mkm_write_op = 1'h1; - mkm_addr_new = MKM_STATUS_WORD; - mkm_addr_we = 1'h1; - mkm_write_data_new = wr_status; - mkm_write_data_we = 1'h1; - keywrap_mkmif_ctrl_new = CTRL_WAIT; - keywrap_mkmif_ctrl_we = 1'h1; - end + if (key_status) + begin + key_word_ctr_rst = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY; + keywrap_mkmif_ctrl_we = 1'h1; + end + else + begin + mkm_write_op = 1'h1; + mkm_addr_new = MKM_STATUS_WORD; + mkm_addr_we = 1'h1; + mkm_write_data_new = wr_status; + mkm_write_data_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WAIT; + keywrap_mkmif_ctrl_we = 1'h1; + end end end + CTRL_WAIT: begin if (mkm_ready) -- 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/rtl/keywrap_mkmif.v | 142 +++++++++++++++++++++++++++++++----------------- 1 file changed, 92 insertions(+), 50 deletions(-) (limited to 'src/rtl') diff --git a/src/rtl/keywrap_mkmif.v b/src/rtl/keywrap_mkmif.v index 88af6f8..2f7bebf 100644 --- a/src/rtl/keywrap_mkmif.v +++ b/src/rtl/keywrap_mkmif.v @@ -63,13 +63,16 @@ module keywrap_mkmif ( //---------------------------------------------------------------- // Paramenters and local defines. //---------------------------------------------------------------- - localparam CTRL_IDLE = 3'h0; - localparam CTRL_WAIT = 3'h1; - localparam CTRL_READ_STATUS_WAIT = 3'h2; - localparam CTRL_READ_KEY = 3'h3; - localparam CTRL_READ_KEY_WAIT = 3'h4; - localparam CTRL_WRITE_KEY = 3'h5; - localparam CTRL_WRITE_KEY_WAIT = 3'h6; + localparam CTRL_IDLE = 4'h0; + localparam CTRL_WAIT = 4'h1; + localparam CTRL_INIT = 4'h2; + localparam CTRL_READ = 4'h3; + localparam CTRL_READ_STATUS_WAIT = 4'h4; + localparam CTRL_READ_KEY = 4'h5; + localparam CTRL_READ_KEY_WAIT = 4'h6; + localparam CTRL_WRITE = 4'h8; + localparam CTRL_WRITE_KEY = 4'h9; + localparam CTRL_WRITE_KEY_WAIT = 4'ha; // Addresses for storage in the mkm localparam MKM_STATUS_WORD = 16'h00; @@ -106,10 +109,14 @@ module keywrap_mkmif ( reg ready_new; reg ready_we; - reg [2 : 0] keywrap_mkmif_ctrl_reg; - reg [2 : 0] keywrap_mkmif_ctrl_new; + reg [3 : 0] keywrap_mkmif_ctrl_reg; + reg [3 : 0] keywrap_mkmif_ctrl_new; reg keywrap_mkmif_ctrl_we; + reg init_op_reg; + reg read_op_reg; + reg write_op_reg; + //---------------------------------------------------------------- // Wires. @@ -136,9 +143,9 @@ module keywrap_mkmif ( .spi_do(mkm_spi_do), .spi_di(mkm_spi_di), - .init_op(mkm_init_op), - .read_op(mkm_read_op), - .write_op(mkm_write_op), + .init_op(init_op_reg), + .read_op(read_op_reh), + .write_op(write_op_reg), .ready(mkm_ready), .valid(mkm_valid), @@ -178,11 +185,18 @@ module keywrap_mkmif ( mkm_addr_reg <= 16'h0; mkm_write_data_reg <= 32'h0; key_word_ctr_reg <= 3'h0; + init_op_reg <= 1'h0; + read_op_reg <= 1'h0; + write_op_reg <= 1'h0; keywrap_mkmif_ctrl_reg <= CTRL_IDLE; end else begin + init_op_reg <= mkm_init_op; + read_op_reg <= mkm_read_op; + write_op_reg <= mkm_write_op; + if (ready_we) ready_reg <= ready_new; @@ -259,52 +273,50 @@ module keywrap_mkmif ( mkm_init_op = 1'h1; ready_new = 1'h0; ready_we = 1'h1; - keywrap_mkmif_ctrl_new = CTRL_WAIT; + keywrap_mkmif_ctrl_new = CTRL_INIT; keywrap_mkmif_ctrl_we = 1'h1; end if (read) begin - ready_new = 1'h0; - ready_we = 1'h1; - - if (key_status) - begin - key_word_ctr_rst = 1'h1; - keywrap_mkmif_ctrl_new = CTRL_READ_KEY; - keywrap_mkmif_ctrl_we = 1'h1; - end - else - begin - mkm_read_op = 1'h1; - mkm_addr_new = MKM_STATUS_WORD; - mkm_addr_we = 1'h1; - keywrap_mkmif_ctrl_new = CTRL_READ_STATUS_WAIT; - keywrap_mkmif_ctrl_we = 1'h1; - end + ready_new = 1'h0; + ready_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_READ; + keywrap_mkmif_ctrl_we = 1'h1; end if (write) begin - ready_new = 1'h0; - ready_we = 1'h1; - - if (key_status) - begin - key_word_ctr_rst = 1'h1; - keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY; - keywrap_mkmif_ctrl_we = 1'h1; - end - else - begin - mkm_write_op = 1'h1; - mkm_addr_new = MKM_STATUS_WORD; - mkm_addr_we = 1'h1; - mkm_write_data_new = wr_status; - mkm_write_data_we = 1'h1; - keywrap_mkmif_ctrl_new = CTRL_WAIT; - keywrap_mkmif_ctrl_we = 1'h1; - end + ready_new = 1'h0; + ready_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WRITE; + keywrap_mkmif_ctrl_we = 1'h1; + end + end + + + CTRL_INIT: + begin + keywrap_mkmif_ctrl_new = CTRL_WAIT; + keywrap_mkmif_ctrl_we = 1'h1; + end + + + CTRL_READ: + begin + if (key_status) + begin + key_word_ctr_rst = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_READ_KEY; + keywrap_mkmif_ctrl_we = 1'h1; + end + else + begin + mkm_read_op = 1'h1; + mkm_addr_new = MKM_STATUS_WORD; + mkm_addr_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_READ_STATUS_WAIT; + keywrap_mkmif_ctrl_we = 1'h1; end end @@ -320,8 +332,13 @@ module keywrap_mkmif ( end end + CTRL_READ_STATUS_WAIT: begin + ready_new = 1'h1; + ready_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_IDLE; + keywrap_mkmif_ctrl_we = 1'h1; if (mkm_ready) begin status_we = 1'h1; @@ -332,6 +349,7 @@ module keywrap_mkmif ( end end + CTRL_READ_KEY: begin if (key_word_ctr_reg < 8) @@ -351,6 +369,7 @@ module keywrap_mkmif ( end end + CTRL_READ_KEY_WAIT: begin if (mkm_ready) @@ -362,6 +381,28 @@ module keywrap_mkmif ( end end + + CTRL_WRITE: + begin + if (key_status) + begin + key_word_ctr_rst = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY; + keywrap_mkmif_ctrl_we = 1'h1; + end + else + begin + mkm_write_op = 1'h1; + mkm_addr_new = MKM_STATUS_WORD; + mkm_addr_we = 1'h1; + mkm_write_data_new = wr_status; + mkm_write_data_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WAIT; + keywrap_mkmif_ctrl_we = 1'h1; + end + end + + CTRL_WRITE_KEY: begin if (key_word_ctr_reg < 8) @@ -383,6 +424,7 @@ module keywrap_mkmif ( end end + CTRL_WRITE_KEY_WAIT: begin if (mkm_ready) @@ -393,9 +435,9 @@ module keywrap_mkmif ( end end + default: begin - end endcase // case (keywrap_mkmif_ctrl_reg) end // keywrap_mkmif_ctrl -- cgit v1.2.3