From: Florent Kermarrec Date: Thu, 25 Jun 2020 06:47:57 +0000 (+0200) Subject: software/libbase/memtest: reorder functions. X-Git-Tag: 24jan2021_ls180~147 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e2f9a82529f546f4586b9809b082e6bf668dc5a2;p=litex.git software/libbase/memtest: reorder functions. --- diff --git a/litex/soc/software/include/base/memtest.h b/litex/soc/software/include/base/memtest.h index 11196083..c8b79323 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 d3193dab..4ab7f48f 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,33 +83,33 @@ int memtest_bus(unsigned int *addr, unsigned long size) return errors; } -int memtest_data(unsigned int *addr, unsigned long size, int random) +int memtest_addr(unsigned int *addr, unsigned long size, int random) { volatile unsigned int *array = addr; int i, errors; - unsigned int seed_32; - unsigned int rdata; + unsigned short seed_16; + unsigned short rdata; errors = 0; - seed_32 = 1; + seed_16 = 1; for(i = 0; i < size/4; i++) { - seed_32 = seed_to_data_32(seed_32, random); - array[i] = seed_32; + seed_16 = seed_to_data_16(seed_16, random); + array[(unsigned int) seed_16] = i; } - seed_32 = 1; + seed_16 = 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) { + seed_16 = seed_to_data_16(seed_16, random); + rdata = array[(unsigned int) seed_16]; + if(rdata != i) { errors++; -#ifdef MEMTEST_DATA_DEBUG - printf("[data 0x%0x]: 0x%08x vs 0x%08x\n", i, rdata, seed_32); +#ifdef MEMTEST_ADDR_DEBUG + printf("[addr 0x%0x]: 0x%08x vs 0x%08x\n", i, rdata, i); #endif } } @@ -117,33 +117,33 @@ int memtest_data(unsigned int *addr, unsigned long size, int random) return errors; } -int memtest_addr(unsigned int *addr, unsigned long size, int random) +int memtest_data(unsigned int *addr, unsigned long size, int random) { volatile unsigned int *array = addr; int i, errors; - unsigned short seed_16; - unsigned short rdata; + unsigned int seed_32; + unsigned int rdata; errors = 0; - seed_16 = 1; + seed_32 = 1; for(i = 0; i < size/4; i++) { - seed_16 = seed_to_data_16(seed_16, random); - array[(unsigned int) seed_16] = i; + seed_32 = seed_to_data_32(seed_32, random); + array[i] = seed_32; } - seed_16 = 1; + seed_32 = 1; flush_cpu_dcache(); #ifdef CONFIG_L2_SIZE flush_l2_cache(); #endif for(i = 0; i < size/4; i++) { - seed_16 = seed_to_data_16(seed_16, random); - rdata = array[(unsigned int) seed_16]; - if(rdata != i) { + seed_32 = seed_to_data_32(seed_32, random); + rdata = array[i]; + if(rdata != seed_32) { errors++; -#ifdef MEMTEST_ADDR_DEBUG - printf("[addr 0x%0x]: 0x%08x vs 0x%08x\n", i, rdata, i); +#ifdef MEMTEST_DATA_DEBUG + printf("[data 0x%0x]: 0x%08x vs 0x%08x\n", i, rdata, seed_32); #endif } } @@ -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");