FPGA: Add CPU instruction address SPI access control

Add logic that checks if the CPU is reading an instruction
      to execute from ROM or not. If instructions are read
      from ROM, access to the SPI from the API is granted, and
      signals between the SPI master and a slave are allowed.

      If instructions are not read from ROM, any API access
      is blocked. and between the SPI master and a
      slave are disabled.

Signed-off-by: Joachim Strömbergson <joachim@assured.se>
This commit is contained in:
Joachim Strömbergson 2024-06-24 15:13:10 +02:00 committed by Daniel Jobson
parent 7f93b7817b
commit f6fa5ae2f9
No known key found for this signature in database
GPG Key ID: 3707A9DBF4BB8F1A

View File

@ -109,6 +109,8 @@ module tk1(
localparam FW_RAM_FIRST = 32'hd0000000;
localparam FW_RAM_LAST = 32'hd00007ff;
localparam ROM_PREFIX = 2'h0;
//----------------------------------------------------------------
// Registers including update variables and write enable.
@ -162,6 +164,8 @@ module tk1(
reg force_trap_reg;
reg force_trap_set;
reg spi_access_ok;
//----------------------------------------------------------------
// Wires.
@ -231,13 +235,13 @@ module tk1(
.clk(clk),
.reset_n(reset_n),
.spi_ss(spi_ss),
.spi_sck(spi_sck),
.spi_mosi(spi_mosi),
.spi_miso(spi_miso),
.spi_ss((spi_ss & ~spi_access_ok)),
.spi_sck((spi_sck & spi_access_ok)),
.spi_mosi((spi_mosi & spi_access_ok)),
.spi_miso((spi_miso & spi_access_ok)),
.spi_enable(spi_enable),
.spi_enable_vld(spi_enable_vld),
.spi_enable((spi_enable & spi_access_ok)),
.spi_enable_vld((spi_enable_vld & spi_access_ok)),
.spi_start(spi_start),
.spi_tx_data(spi_tx_data),
.spi_tx_data_vld(spi_tx_data_vld),
@ -384,6 +388,23 @@ module tk1(
end
//----------------------------------------------------------------
// spi_access_control
//
// Logic thar controls if any access to the SPI master is done
// by FW-code.
//----------------------------------------------------------------
always @*
begin : spi_access_control
if ((cpu_valid & cpu_instr) & (cpu_addr[31 : 30] == ROM_PREFIX)) begin
spi_access_ok = 1'h1;
end
else begin
spi_access_ok = 1'h0;
end
end
//----------------------------------------------------------------
// security_monitor
//