Add more complete fw_ram test; let testfw have stack in RAM

Signed-off-by: Daniel Lublin <daniel@lublin.se>
This commit is contained in:
Daniel Lublin 2023-03-14 10:55:19 +01:00
parent 5fe7ba7f9d
commit 7a97f1ee5f
No known key found for this signature in database
GPG Key ID: 75BD0FEB8D3E7830
3 changed files with 106 additions and 13 deletions

View File

@ -87,7 +87,7 @@ FIRMWARE_OBJS = \
TESTFW_OBJS = \
$(P)/fw/testfw/main.o \
$(P)/fw/tk1/start.o \
$(P)/fw/testfw/start.o \
$(P)/fw/tk1/proto.o \
$(P)/fw/tk1/lib.o \
$(P)/fw/tk1/blake2s/blake2s.o
@ -103,8 +103,10 @@ all: application_fpga.bin
# incorrect BRAM_FW_SIZE
# -------------------------------------------------------------------
%_size_mismatch: %.elf phony_explicit
@test $$($(SIZE) $< | awk 'NR==2{print $$4}') -le $$(( 32 / 8 * $(BRAM_FW_SIZE) )) || \
(echo "The 'BRAM_FW_SIZE' variable needs to be increased" && false)
@test $$($(SIZE) $< | awk 'NR==2{print $$4}') -le $$(( 32 / 8 * $(BRAM_FW_SIZE) )) \
|| { printf "The 'BRAM_FW_SIZE' variable needs to be increased\n"; \
[[ $< =~ testfw ]] && printf "Note that testfw fits if built with -Os\n"; \
false; }
# can't make implicit rule .PHONY
phony_explicit:

View File

@ -105,6 +105,42 @@ uint32_t wait_timer_tick(uint32_t last_timer)
}
}
void zero_fwram()
{
for (int i = 0; i < TK1_MMIO_FW_RAM_SIZE; i++) {
fw_ram[i] = 0x00;
}
}
int check_fwram_zero_except(unsigned int offset, uint8_t expected_val)
{
int failed = 0;
for (unsigned int i = 0; i < TK1_MMIO_FW_RAM_SIZE; i++) {
uint32_t addr = TK1_MMIO_FW_RAM_BASE + i;
uint8_t *p = (uint8_t *)addr;
uint8_t val = *(volatile uint8_t *)p;
int failed_now = 0;
if (i == offset) {
if (val != expected_val) {
failed_now = 1;
puts(" wrong value at: ");
}
} else {
if (val != 0) {
failed_now = 1;
puts(" not zero at: ");
}
}
if (failed_now) {
failed = 1;
reverseword(&addr);
puthexn((uint8_t *)&addr, 4);
puts("\r\n");
}
}
return failed;
}
int main()
{
// Function pointer to blake2s()
@ -171,12 +207,14 @@ int main()
anyfailed = 1;
}
// Test FW-RAM.
*fw_ram = 0x12;
if (*fw_ram != 0x12) {
puts("FAIL: Can't write and read FW RAM in fw mode\r\n");
anyfailed = 1;
// Test FW_RAM.
puts("Testing FW_RAM (takes 15s on hw)...\r\n");
for (unsigned int i = 0; i < TK1_MMIO_FW_RAM_SIZE; i++) {
zero_fwram();
*(volatile uint8_t *)(TK1_MMIO_FW_RAM_BASE + i) = 0x42;
anyfailed = check_fwram_zero_except(i, 0x42);
}
puts("\r\n");
uint32_t sw = *switch_app;
if (sw != 0) {
@ -190,10 +228,6 @@ int main()
// Turn on application mode.
// -------------------------
// Set up another stack because fw_ram is not available
// anymore in app_mode.
asm volatile("li sp, 0x40006ff0");
*switch_app = 1;
sw = *switch_app;
@ -228,7 +262,7 @@ int main()
anyfailed = 1;
}
// Test FW-RAM.
// Test FW_RAM.
*fw_ram = 0x21;
if (*fw_ram == 0x21) {
puts("FAIL: Write and read FW RAM in app-mode\r\n");

View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2022, 2023 - Tillitis AB
* SPDX-License-Identifier: GPL-2.0-only
*/
.section ".text.init"
.globl _start
_start:
li x1, 0
li x2, 0
li x3, 0
li x4, 0
li x5, 0
li x6, 0
li x7, 0
li x8, 0
li x9, 0
li x10,0
li x11,0
li x12,0
li x13,0
li x14,0
li x15,0
li x16,0
li x17,0
li x18,0
li x19,0
li x20,0
li x21,0
li x22,0
li x23,0
li x24,0
li x25,0
li x26,0
li x27,0
li x28,0
li x29,0
li x30,0
li x31,0
/* Clear all RAM */
li a0, 0x40000000 // TK1_RAM_BASE
li a1, 0x40020000 // TK1_RAM_BASE + TK1_RAM_SIZE
clear:
sw zero, 0(a0)
addi a0, a0, 4
blt a0, a1, clear
/*
* For testfw we init stack at top of RAM
*/
li sp, 0x40020000 // TK1_RAM_BASE + TK1_RAM_SIZE
call main
loop:
j loop