From c19c343ecfdb9ab04f99ca87e85fb2167c624da5 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Mon, 7 Dec 2020 14:05:13 +0100 Subject: [PATCH] software/libbase: add memtest_access before testing bus/addr/data to exit early if bus errors are detected. --- litex/soc/software/include/base/memtest.h | 1 + litex/soc/software/libbase/memtest.c | 36 +++++++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/litex/soc/software/include/base/memtest.h b/litex/soc/software/include/base/memtest.h index c8b793235..864a7fdf6 100644 --- a/litex/soc/software/include/base/memtest.h +++ b/litex/soc/software/include/base/memtest.h @@ -3,6 +3,7 @@ #include +int memtest_access(unsigned int *addr); int memtest_bus(unsigned int *addr, unsigned long size); int memtest_addr(unsigned int *addr, unsigned long size, int random); int memtest_data(unsigned int *addr, unsigned long size, int random); diff --git a/litex/soc/software/libbase/memtest.c b/litex/soc/software/libbase/memtest.c index 779858a3c..d6f112614 100644 --- a/litex/soc/software/libbase/memtest.c +++ b/litex/soc/software/libbase/memtest.c @@ -39,6 +39,27 @@ static unsigned short seed_to_data_16(unsigned short seed, int random) return random ? lfsr(16, seed) : seed + 1; } +int memtest_access(unsigned int *addr) +{ + volatile unsigned int *array = addr; + int bus_errors; + + /* Get current bus errors */ + bus_errors = ctrl_bus_errors_read(); + + /* Check bus Read/Write */ + array[0] = ONEZERO; + array[1] = array[0]; + array[0] = ZEROONE; + array[1] = array[0]; + if (ctrl_bus_errors_read() - bus_errors) { + printf("memtest_access error @ 0x%0x, exiting memtest.\n", addr); + return 1; + } + + return 0; +} + int memtest_bus(unsigned int *addr, unsigned long size) { volatile unsigned int *array = addr; @@ -62,13 +83,13 @@ int memtest_bus(unsigned int *addr, unsigned long size) if(rdata != ONEZERO) { errors++; #ifdef MEMTEST_BUS_DEBUG - printf("memtest_bus error @ 0x%0x: 0x%08x vs 0x%08x\n", i, rdata, ONEZERO); + printf("memtest_bus error @ 0x%0x: 0x%08x vs 0x%08x\n", addr + i, rdata, ONEZERO); #endif } } /* Write Zero/One pattern */ - for(i = 0; i < size/4; i++) { + for(i=0; i < size/4; i++) { array[i] = ZEROONE; } @@ -77,12 +98,12 @@ int memtest_bus(unsigned int *addr, unsigned long size) flush_l2_cache(); /* Read/Verify One/Zero pattern */ - for(i = 0; i < size/4; i++) { + for(i=0; i