software/libbase/memtest: reorder functions.

This commit is contained in:
Florent Kermarrec 2020-06-25 08:47:57 +02:00
parent 00d1118d41
commit e2f9a82529
2 changed files with 48 additions and 48 deletions

View File

@ -3,11 +3,11 @@
#include <stdbool.h>
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 */

View File

@ -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;
@ -203,22 +203,22 @@ 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 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");