From e1ecd7bf85518356eb1f3e9b209788b6e23ab904 Mon Sep 17 00:00:00 2001 From: Ilko Iliev Date: Fri, 8 Mar 2019 14:19:45 +0100 Subject: [PATCH 3/4] main.c: add target memory test Add short and long memory test functions. The short memory test checks two 32-bit word at the beginning of target memory. The long memory test is not activated by default and it checks endless the whole target memory. --- main.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/main.c b/main.c index 48e9cbb..3837d74 100644 --- a/main.c +++ b/main.c @@ -36,6 +36,7 @@ #include "backup.h" #include "secure.h" #include "sfr_aicredir.h" +#include "debug.h" #ifdef CONFIG_HW_DISPLAY_BANNER static void display_banner (void) @@ -44,6 +45,91 @@ static void display_banner (void) } #endif +#ifdef CONFIG_LONG_TEST +/*! + * @brief Perform a long memory test + * @param addr - start address + * @param len - length in bytes + * @return + */ +static int mem_test_long(int loop, unsigned int addr, int len) +{ +#define BLOCK_SIZE_MB (4 * 1024 * 1024) + + unsigned int *pp; + int ii, jj, num_err = 0; + + dbg_printf("%d. Testing DDR @ %x, %d MB\n", loop, addr, len / 1024 / 1024); + dbg_printf(" Writing DDR "); + + pp = (unsigned int *)addr; + for (ii = 0; ii < len / 4; ii++) + { + if (ii) + *pp++ = ii | (0x2A << 26); + else + *pp++ = ii | (0x15 << 26); + + if (!((ii+1) % (1024 * 1024))) + dbg_printf("."); + } + + int ss = 0; + dbg_printf("\n" " Reading DDR "); + pp = (unsigned int *)addr; + for (ii = 0; ii < len / BLOCK_SIZE_MB; ii++) + { + int nn = 0; + for (jj = 0; jj < BLOCK_SIZE_MB /4; jj++) + { + if ((*pp & 0x03FFFFFF)!= ss) + nn++; + + int tt = (ss) ? 0x2A : 0x15; + + if ((*pp & ~0x03FFFFFF) != (tt << 26)) + nn++; + + pp++; + ss++; + } + + num_err += nn; + if (nn) + { + if (nn < 10) + dbg_printf("%d", nn); + else + dbg_printf("#"); + } + else + dbg_printf("."); + } + + ss /= (1024 * 1024); + ss *= 4; + + dbg_printf("\n" " Number of errors = %d\n\n", num_err); + + return num_err; +} +#endif + +/*! + * @brief Test two 32-bit words + * @param addr + * @return + */ +static int mem_test_short(unsigned int *addr) +{ + addr[0] = 0x12345678; + addr[1] = 0x11223344; + addr[2] = 0; + addr[3] = 0xFFFFFFFF; + + return ((addr[0] != 0x12345678) || (addr[1] != 0x11223344)) ? 1 : 0; +} + int main(void) { #if !defined(CONFIG_LOAD_NONE) @@ -80,6 +166,22 @@ int main(void) display_banner(); #endif + int stat = mem_test_short((unsigned int *)JUMP_ADDR); + if ( stat ) + { + dbg_printf("-E- memory check at jump address %x failed\r\n", JUMP_ADDR); + while(1); + } + +#if defined(CONFIG_LONG_TEST) + /* Endless memory test */ + int i = 0; + while (1) + { + mem_test_long(i++, 0x70000000, 1024 * 1024 * 128); + } +#endif /* CONFIG_LONG_TEST */ + #ifdef CONFIG_REDIRECT_ALL_INTS_AIC redirect_interrupts_to_nsaic(); #endif -- 2.17.1