aboutsummaryrefslogtreecommitdiff
path: root/src/rtl
diff options
context:
space:
mode:
authorJoachim StroĢˆmbergson <joachim@secworks.se>2018-09-28 11:47:27 +0200
committerJoachim StroĢˆmbergson <joachim@secworks.se>2018-09-28 11:47:27 +0200
commit86d87571a957365be5191cce7503c8c66c41557e (patch)
tree9451c1c8d82dbafea6b1df716bdfb5c605e1fbc4 /src/rtl
parent491a5db2c4379af748499691f173874aed19de22 (diff)
Got all states needed. Added hold registers for address and data to be written.
Diffstat (limited to 'src/rtl')
-rw-r--r--src/rtl/keywrap_mkmif.v191
1 files changed, 169 insertions, 22 deletions
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