software/bios/sdram: add random addressing to memtest

testing memories with linear access is not good enough. Adding random addressing allow us to detect more eventual issues on our L2 cache or SDRAM controller.
This commit is contained in:
Florent Kermarrec 2015-03-27 15:49:16 +01:00
parent 340014dbac
commit f85a4f004b
1 changed files with 40 additions and 12 deletions

View File

@ -422,13 +422,16 @@ int sdrlevel(void)
#endif /* CSR_DDRPHY_BASE */ #endif /* CSR_DDRPHY_BASE */
#define TEST_SIZE (2*1024*1024) #define TEST_DATA_SIZE (2*1024*1024)
#define TEST_RANDOM_DATA 1 #define TEST_RANDOM_DATA 1
#define TEST_ADDR_SIZE 32*1024
#define TEST_RANDOM_ADDR 1
#define ONEZERO 0xAAAAAAAA #define ONEZERO 0xAAAAAAAA
#define ZEROONE 0x55555555 #define ZEROONE 0x55555555
static unsigned int seed_to_data(unsigned int seed, int random) static unsigned int seed_to_data_32(unsigned int seed, int random)
{ {
if (random) if (random)
return 1664525*seed + 1013904223; return 1664525*seed + 1013904223;
@ -436,11 +439,20 @@ static unsigned int seed_to_data(unsigned int seed, int random)
return seed + 1; return seed + 1;
} }
static unsigned short seed_to_data_16(unsigned short seed, int random)
{
if (random)
return 25173*seed + 13849;
else
return seed + 1;
}
int memtest_silent(void) int memtest_silent(void)
{ {
volatile unsigned int *array = (unsigned int *)MAIN_RAM_BASE; volatile unsigned int *array = (unsigned int *)MAIN_RAM_BASE;
int i; int i;
unsigned int seed; unsigned int seed_32;
unsigned short seed_16;
unsigned int error_cnt; unsigned int error_cnt;
/* test data bus */ /* test data bus */
@ -463,19 +475,35 @@ int memtest_silent(void)
} }
/* test counter or random data */ /* test counter or random data */
seed = 0; seed_32 = 0;
for(i=0;i<TEST_SIZE/4;i++) { for(i=0;i<TEST_DATA_SIZE/4;i++) {
seed = seed_to_data(seed, TEST_RANDOM_DATA); seed_32 = seed_to_data_32(seed_32, TEST_RANDOM_DATA);
array[i] = seed; array[i] = seed_32;
} }
seed = 0; seed_32 = 0;
error_cnt = 0; error_cnt = 0;
for(i=0;i<TEST_SIZE/4;i++) { for(i=0;i<TEST_DATA_SIZE/4;i++) {
seed = seed_to_data(seed, TEST_RANDOM_DATA); seed_32 = seed_to_data_32(seed_32, TEST_RANDOM_DATA);
if(array[i] != seed) if(array[i] != seed_32)
error_cnt++; error_cnt++;
} }
/* test random addressing */
seed_16 = 0;
for(i=0;i<TEST_ADDR_SIZE/4;i++) {
seed_16 = seed_to_data_16(seed_16, TEST_RANDOM_ADDR);
array[(unsigned int) seed_16] = i;
}
seed_16 = 0;
error_cnt = 0;
for(i=0;i<TEST_ADDR_SIZE/4;i++) {
seed_16 = seed_to_data_16(seed_16, TEST_RANDOM_ADDR);
if(array[(unsigned int) seed_16] != i)
error_cnt++;
}
return error_cnt; return error_cnt;
} }
@ -485,7 +513,7 @@ int memtest(void)
e = memtest_silent(); e = memtest_silent();
if(e != 0) { if(e != 0) {
printf("Memtest failed: %d/%d words incorrect\n", e, TEST_SIZE/4); printf("Memtest failed: %d/%d words incorrect\n", e, TEST_DATA_SIZE/4 + TEST_ADDR_SIZE/4);
return 0; return 0;
} else { } else {
printf("Memtest OK\n"); printf("Memtest OK\n");