mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-03-12 18:16:55 -04:00
fpga: Only allow system reset in firmware mode and syscalls
This commit is contained in:
parent
9e317666d3
commit
77fc5cf578
@ -547,7 +547,9 @@ module tk1 #(
|
|||||||
end
|
end
|
||||||
|
|
||||||
if (address == ADDR_SYSTEM_RESET) begin
|
if (address == ADDR_SYSTEM_RESET) begin
|
||||||
system_reset_new = 1'h1;
|
if (!app_mode) begin
|
||||||
|
system_reset_new = 1'h1;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if ((address >= ADDR_CDI_FIRST) && (address <= ADDR_CDI_LAST)) begin
|
if ((address >= ADDR_CDI_FIRST) && (address <= ADDR_CDI_LAST)) begin
|
||||||
|
@ -56,6 +56,8 @@ module tb_tk1 ();
|
|||||||
localparam ADDR_CPU_MON_FIRST = 8'h61;
|
localparam ADDR_CPU_MON_FIRST = 8'h61;
|
||||||
localparam ADDR_CPU_MON_LAST = 8'h62;
|
localparam ADDR_CPU_MON_LAST = 8'h62;
|
||||||
|
|
||||||
|
localparam ADDR_SYSTEM_RESET = 8'h70;
|
||||||
|
|
||||||
localparam ADDR_SPI_EN = 8'h80;
|
localparam ADDR_SPI_EN = 8'h80;
|
||||||
localparam ADDR_SPI_XFER = 8'h81;
|
localparam ADDR_SPI_XFER = 8'h81;
|
||||||
localparam ADDR_SPI_DATA = 8'h82;
|
localparam ADDR_SPI_DATA = 8'h82;
|
||||||
@ -84,6 +86,7 @@ module tb_tk1 ();
|
|||||||
reg tb_cpu_instr;
|
reg tb_cpu_instr;
|
||||||
reg tb_cpu_valid;
|
reg tb_cpu_valid;
|
||||||
wire tb_force_trap;
|
wire tb_force_trap;
|
||||||
|
wire tb_system_reset;
|
||||||
|
|
||||||
wire [14 : 0] tb_ram_addr_rand;
|
wire [14 : 0] tb_ram_addr_rand;
|
||||||
wire [31 : 0] tb_ram_data_rand;
|
wire [31 : 0] tb_ram_data_rand;
|
||||||
@ -132,6 +135,7 @@ module tb_tk1 ();
|
|||||||
.cpu_instr (tb_cpu_instr),
|
.cpu_instr (tb_cpu_instr),
|
||||||
.cpu_valid (tb_cpu_valid),
|
.cpu_valid (tb_cpu_valid),
|
||||||
.force_trap(tb_force_trap),
|
.force_trap(tb_force_trap),
|
||||||
|
.system_reset(tb_system_reset),
|
||||||
|
|
||||||
.ram_addr_rand(tb_ram_addr_rand),
|
.ram_addr_rand(tb_ram_addr_rand),
|
||||||
.ram_data_rand(tb_ram_data_rand),
|
.ram_data_rand(tb_ram_data_rand),
|
||||||
@ -1120,6 +1124,45 @@ module tb_tk1 ();
|
|||||||
endtask // test12
|
endtask // test12
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------
|
||||||
|
// test13()
|
||||||
|
// System reset
|
||||||
|
//----------------------------------------------------------------
|
||||||
|
task test13;
|
||||||
|
begin
|
||||||
|
tc_ctr = tc_ctr + 1;
|
||||||
|
|
||||||
|
$display("");
|
||||||
|
$display("--- test13: Reset allowed from firmware mode.");
|
||||||
|
tb_syscall = 0;
|
||||||
|
reset_dut();
|
||||||
|
|
||||||
|
write_word(ADDR_SYSTEM_RESET, 32'h1);
|
||||||
|
check_equal(tb_system_reset, 1);
|
||||||
|
|
||||||
|
$display("--- test13: Reset not allowed from app mode.");
|
||||||
|
reset_dut();
|
||||||
|
fetch_instruction(APP_RAM_START);
|
||||||
|
|
||||||
|
write_word(ADDR_SYSTEM_RESET, 32'h1);
|
||||||
|
check_equal(tb_system_reset, 0);
|
||||||
|
|
||||||
|
$display("--- test13: Reset allowed from syscall.");
|
||||||
|
reset_dut();
|
||||||
|
fetch_instruction(APP_RAM_START);
|
||||||
|
tb_syscall = 1;
|
||||||
|
|
||||||
|
write_word(ADDR_SYSTEM_RESET, 32'h1);
|
||||||
|
check_equal(tb_system_reset, 1);
|
||||||
|
|
||||||
|
tb_syscall = 0;
|
||||||
|
|
||||||
|
$display("--- test13: completed.");
|
||||||
|
$display("");
|
||||||
|
end
|
||||||
|
endtask // test13
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
// exit_with_error_code()
|
// exit_with_error_code()
|
||||||
//
|
//
|
||||||
@ -1161,6 +1204,7 @@ module tb_tk1 ();
|
|||||||
test10();
|
test10();
|
||||||
test11();
|
test11();
|
||||||
test12();
|
test12();
|
||||||
|
test13();
|
||||||
|
|
||||||
display_test_result();
|
display_test_result();
|
||||||
$display("");
|
$display("");
|
||||||
|
@ -20,6 +20,7 @@ volatile uint32_t *uds = (volatile uint32_t *)TK1_MMIO_UDS_FIRST;
|
|||||||
volatile uint32_t *cdi = (volatile uint32_t *)TK1_MMIO_TK1_CDI_FIRST;
|
volatile uint32_t *cdi = (volatile uint32_t *)TK1_MMIO_TK1_CDI_FIRST;
|
||||||
volatile uint32_t *udi = (volatile uint32_t *)TK1_MMIO_TK1_UDI_FIRST;
|
volatile uint32_t *udi = (volatile uint32_t *)TK1_MMIO_TK1_UDI_FIRST;
|
||||||
volatile uint8_t *fw_ram = (volatile uint8_t *)TK1_MMIO_FW_RAM_BASE;
|
volatile uint8_t *fw_ram = (volatile uint8_t *)TK1_MMIO_FW_RAM_BASE;
|
||||||
|
volatile uint32_t *system_reset = (volatile uint32_t *)TK1_MMIO_TK1_SYSTEM_RESET;
|
||||||
volatile uint32_t *timer = (volatile uint32_t *)TK1_MMIO_TIMER_TIMER;
|
volatile uint32_t *timer = (volatile uint32_t *)TK1_MMIO_TIMER_TIMER;
|
||||||
volatile uint32_t *timer_prescaler = (volatile uint32_t *)TK1_MMIO_TIMER_PRESCALER;
|
volatile uint32_t *timer_prescaler = (volatile uint32_t *)TK1_MMIO_TIMER_PRESCALER;
|
||||||
volatile uint32_t *timer_status = (volatile uint32_t *)TK1_MMIO_TIMER_STATUS;
|
volatile uint32_t *timer_status = (volatile uint32_t *)TK1_MMIO_TIMER_STATUS;
|
||||||
@ -192,6 +193,11 @@ int main(void)
|
|||||||
anyfailed = 1;
|
anyfailed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Should NOT be able to reset Tkey from app mode
|
||||||
|
puts("\r\nTesting system reset...");
|
||||||
|
*system_reset = 1;
|
||||||
|
puts("done.\r\n");
|
||||||
|
|
||||||
// Test FW_RAM.
|
// Test FW_RAM.
|
||||||
*fw_ram = 0x21;
|
*fw_ram = 0x21;
|
||||||
if (*fw_ram == 0x21) {
|
if (*fw_ram == 0x21) {
|
||||||
|
@ -17,6 +17,7 @@ volatile uint32_t *uds = (volatile uint32_t *)TK1_MMIO_UDS_FIRST;
|
|||||||
volatile uint32_t *cdi = (volatile uint32_t *)TK1_MMIO_TK1_CDI_FIRST;
|
volatile uint32_t *cdi = (volatile uint32_t *)TK1_MMIO_TK1_CDI_FIRST;
|
||||||
volatile uint32_t *udi = (volatile uint32_t *)TK1_MMIO_TK1_UDI_FIRST;
|
volatile uint32_t *udi = (volatile uint32_t *)TK1_MMIO_TK1_UDI_FIRST;
|
||||||
volatile uint8_t *fw_ram = (volatile uint8_t *)TK1_MMIO_FW_RAM_BASE;
|
volatile uint8_t *fw_ram = (volatile uint8_t *)TK1_MMIO_FW_RAM_BASE;
|
||||||
|
volatile uint32_t *system_reset = (volatile uint32_t *)TK1_MMIO_TK1_SYSTEM_RESET;
|
||||||
volatile uint32_t *timer = (volatile uint32_t *)TK1_MMIO_TIMER_TIMER;
|
volatile uint32_t *timer = (volatile uint32_t *)TK1_MMIO_TIMER_TIMER;
|
||||||
volatile uint32_t *timer_prescaler = (volatile uint32_t *)TK1_MMIO_TIMER_PRESCALER;
|
volatile uint32_t *timer_prescaler = (volatile uint32_t *)TK1_MMIO_TIMER_PRESCALER;
|
||||||
volatile uint32_t *timer_status = (volatile uint32_t *)TK1_MMIO_TIMER_STATUS;
|
volatile uint32_t *timer_status = (volatile uint32_t *)TK1_MMIO_TIMER_STATUS;
|
||||||
@ -355,9 +356,12 @@ int main(void)
|
|||||||
}
|
}
|
||||||
puts("\r\n");
|
puts("\r\n");
|
||||||
|
|
||||||
puts("Now echoing what you type...\r\n");
|
puts("Now echoing what you type...Type + to reset device\r\n");
|
||||||
for (;;) {
|
for (;;) {
|
||||||
in = readbyte(&mode, &mode_bytes_left);
|
in = readbyte(&mode, &mode_bytes_left);
|
||||||
|
if (in == '+') {
|
||||||
|
*system_reset = 1;
|
||||||
|
}
|
||||||
|
|
||||||
writebyte(MODE_CDC);
|
writebyte(MODE_CDC);
|
||||||
writebyte(1);
|
writebyte(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user