From e2f9a82529f546f4586b9809b082e6bf668dc5a2 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 25 Jun 2020 08:47:57 +0200 Subject: [PATCH] software/libbase/memtest: reorder functions. --- litex/soc/software/include/base/memtest.h | 8 +-- litex/soc/software/libbase/memtest.c | 88 +++++++++++------------ 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/litex/soc/software/include/base/memtest.h b/litex/soc/software/include/base/memtest.h index 111960830..c8b793235 100644 --- a/litex/soc/software/include/base/memtest.h +++ b/litex/soc/software/include/base/memtest.h @@ -3,11 +3,11 @@ #include -int memtest(unsigned int *addr, unsigned long maxsize); -void memspeed(unsigned int *addr, unsigned long size, bool read_only); - +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); -int memtest_bus(unsigned int *addr, unsigned long size); + +void memspeed(unsigned int *addr, unsigned long size, bool read_only); +int memtest(unsigned int *addr, unsigned long maxsize); #endif /* __MEMTEST_H */ diff --git a/litex/soc/software/libbase/memtest.c b/litex/soc/software/libbase/memtest.c index d3193dab5..4ab7f48fa 100644 --- a/litex/soc/software/libbase/memtest.c +++ b/litex/soc/software/libbase/memtest.c @@ -11,6 +11,9 @@ // #define MEMTEST_DATA_DEBUG // #define MEMTEST_ADDR_DEBUG +#define ONEZERO 0xAAAAAAAA +#define ZEROONE 0x55555555 + #ifndef MEMTEST_BUS_SIZE #define MEMTEST_BUS_SIZE (512) #endif @@ -25,9 +28,6 @@ #endif #define MEMTEST_ADDR_RANDOM 0 -#define ONEZERO 0xAAAAAAAA -#define ZEROONE 0x55555555 - static unsigned int seed_to_data_32(unsigned int seed, int random) { return random ? lfsr(32, seed) : seed + 1; @@ -83,40 +83,6 @@ int memtest_bus(unsigned int *addr, unsigned long size) return errors; } -int memtest_data(unsigned int *addr, unsigned long size, int random) -{ - volatile unsigned int *array = addr; - int i, errors; - unsigned int seed_32; - unsigned int rdata; - - errors = 0; - seed_32 = 1; - - for(i = 0; i < size/4; i++) { - seed_32 = seed_to_data_32(seed_32, random); - array[i] = seed_32; - } - - seed_32 = 1; - flush_cpu_dcache(); -#ifdef CONFIG_L2_SIZE - flush_l2_cache(); -#endif - for(i = 0; i < size/4; i++) { - seed_32 = seed_to_data_32(seed_32, random); - rdata = array[i]; - if(rdata != seed_32) { - errors++; -#ifdef MEMTEST_DATA_DEBUG - printf("[data 0x%0x]: 0x%08x vs 0x%08x\n", i, rdata, seed_32); -#endif - } - } - - return errors; -} - int memtest_addr(unsigned int *addr, unsigned long size, int random) { volatile unsigned int *array = addr; @@ -151,6 +117,40 @@ int memtest_addr(unsigned int *addr, unsigned long size, int random) return errors; } +int memtest_data(unsigned int *addr, unsigned long size, int random) +{ + volatile unsigned int *array = addr; + int i, errors; + unsigned int seed_32; + unsigned int rdata; + + errors = 0; + seed_32 = 1; + + for(i = 0; i < size/4; i++) { + seed_32 = seed_to_data_32(seed_32, random); + array[i] = seed_32; + } + + seed_32 = 1; + flush_cpu_dcache(); +#ifdef CONFIG_L2_SIZE + flush_l2_cache(); +#endif + for(i = 0; i < size/4; i++) { + seed_32 = seed_to_data_32(seed_32, random); + rdata = array[i]; + if(rdata != seed_32) { + errors++; +#ifdef MEMTEST_DATA_DEBUG + printf("[data 0x%0x]: 0x%08x vs 0x%08x\n", i, rdata, seed_32); +#endif + } + } + + return errors; +} + void memspeed(unsigned int *addr, unsigned long size, bool read_only) { volatile unsigned int *array = addr; @@ -202,23 +202,23 @@ void memspeed(unsigned int *addr, unsigned long size, bool read_only) int memtest(unsigned int *addr, unsigned long maxsize) { int bus_errors, data_errors, addr_errors; - unsigned long bus_size = MEMTEST_BUS_SIZE < maxsize ? MEMTEST_BUS_SIZE : maxsize; - unsigned long data_size = MEMTEST_DATA_SIZE < maxsize ? MEMTEST_DATA_SIZE : maxsize; + unsigned long bus_size = MEMTEST_BUS_SIZE < maxsize ? MEMTEST_BUS_SIZE : maxsize; unsigned long addr_size = MEMTEST_ADDR_SIZE < maxsize ? MEMTEST_ADDR_SIZE : maxsize; + unsigned long data_size = MEMTEST_DATA_SIZE < maxsize ? MEMTEST_DATA_SIZE : maxsize; bus_errors = memtest_bus(addr, bus_size); if(bus_errors != 0) printf("Memtest bus failed: %d/%d errors\n", bus_errors, bus_size/4); - data_errors = memtest_data(addr, data_size, MEMTEST_DATA_RANDOM); - if(data_errors != 0) - printf("Memtest data failed: %d/%d errors\n", data_errors, data_size/4); - addr_errors = memtest_addr(addr, addr_size, MEMTEST_ADDR_RANDOM); if(addr_errors != 0) printf("Memtest addr failed: %d/%d errors\n", addr_errors, addr_size/4); - if(bus_errors + data_errors + addr_errors != 0) + data_errors = memtest_data(addr, data_size, MEMTEST_DATA_RANDOM); + if(data_errors != 0) + printf("Memtest data failed: %d/%d errors\n", data_errors, data_size/4); + + if(bus_errors + addr_errors + data_errors != 0) return 0; else { printf("Memtest OK\n");