liblitedram/bist: add sdram_hw_test function

It allows to perform a memtest (similar to `sdram_test`), but using DMAs
and bypassing system bus. This way, one can test ranges such above 4 GiB,
which was the limit with `sdram_test` due to address_width being limited
to 32 bits.

Signed-off-by: Michal Sieron <msieron@antmicro.com>
This commit is contained in:
Michal Sieron 2023-01-09 16:44:33 +01:00
parent e7e1b16027
commit dbf030e4cf
2 changed files with 51 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include <console.h>
#include <liblitedram/bist.h>
#include <liblitedram/utils.h>
#include <generated/sdram_phy.h>
#define SDRAM_TEST_BASE 0x00000000
@ -157,4 +158,52 @@ void sdram_bist(uint32_t burst_length, uint32_t random)
}
}
int sdram_hw_test(uint64_t origin, uint64_t size, uint64_t burst_length) {
uint64_t burst_size = SDRAM_TEST_DATA_BYTES * burst_length;
uint64_t old_burst_size = burst_size;
int errors = 0;
uint64_t supported_memory = sdram_get_supported_memory();
if (origin >= supported_memory) {
printf("Selected origin out of memory bounds! Supported memory: ");
print_size(supported_memory);
printf("\n");
return 0;
}
if (origin + size > supported_memory) {
printf("Test would go out of memory bounds. Clipping size to memory end: ");
print_size(supported_memory);
printf("\n");
size = supported_memory - origin;
}
for (uint64_t address = origin; address < origin + size; address += burst_size) {
if (address + burst_size > size) {
old_burst_size = burst_size;
burst_size = size - address;
}
if (burst_size < SDRAM_TEST_DATA_BYTES || old_burst_size < burst_size)
break;
sdram_bist_write(address, burst_size);
sdram_bist_read(address, burst_size);
errors += sdram_checker_errors_read();
print_progress(" SDRAM HW test:", origin, address - origin + burst_size);
}
if (burst_size < SDRAM_TEST_DATA_BYTES || old_burst_size < burst_size) {
printf("\nTest would go out of memory bounds. Finished early at the end: ");
print_size(supported_memory);
}
printf("\n");
return errors;
}
#endif

View File

@ -5,6 +5,8 @@
#define __SDRAM_BIST_H
#include <stdint.h>
void sdram_bist(uint32_t burst_length, uint32_t random);
int sdram_hw_test(uint64_t origin, uint64_t size, uint64_t burst_length);
#endif /* __SDRAM_BIST_H */