|  | @@ -18,7 +18,7 @@ static void data_check(volatile uint32_t *p, uint32_t expect)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      if (readback != expect) {
 | 
	
		
			
				|  |  |  	if (rate_limit) {
 | 
	
		
			
				|  |  | -	    con_printf("\r\n%p : read %08x expected %08x\r\n",
 | 
	
		
			
				|  |  | +	    con_printf("\n%p : read %08x expected %08x\n",
 | 
	
		
			
				|  |  |  		       p, readback, expect);
 | 
	
		
			
				|  |  |  	    rate_limit--;
 | 
	
		
			
				|  |  |  	}
 | 
	
	
		
			
				|  | @@ -46,7 +46,7 @@ static void test_sdram(void)
 | 
	
		
			
				|  |  |      uint32_t w = 0;
 | 
	
		
			
				|  |  |      uint32_t n;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    con_printf("Testing SDRAM from 0x%08x to 0x%08x, stride 0x%08x...\r\n",
 | 
	
		
			
				|  |  | +    con_printf("Testing SDRAM from 0x%08x to 0x%08x, stride 0x%08x...\n",
 | 
	
		
			
				|  |  |  	       SDRAM_ADDR, SDRAM_END, stride);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      err_char = '-';
 | 
	
	
		
			
				|  | @@ -69,7 +69,7 @@ static void test_sdram(void)
 | 
	
		
			
				|  |  |  	w = (w + stride) & SDRAM_MASK;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    con_puts("\r\nReading back to check for aliases...\r\n");
 | 
	
		
			
				|  |  | +    con_puts("\nReading back to check for aliases...\n");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      rate_limit = ERROR_RATELIMIT;
 | 
	
		
			
				|  |  |      for (n = 1, w = 0; n <= sdram_words; n++) {
 | 
	
	
		
			
				|  | @@ -86,7 +86,7 @@ static void test_sdram(void)
 | 
	
		
			
				|  |  |  	w = (w - stride) & SDRAM_MASK;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    con_printf("\rSDRAM test complete, time = %u ms\r\n",
 | 
	
		
			
				|  |  | +    con_printf("\nSDRAM test complete, time = %u ms\n",
 | 
	
		
			
				|  |  |  	       (rdtime() - start_time)/(CPU_HZ/1000));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      stride *= 3;
 | 
	
	
		
			
				|  | @@ -94,40 +94,24 @@ static void test_sdram(void)
 | 
	
		
			
				|  |  |      stride = (stride & ~3) | 4;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -#define SDRAM_DONE IODEVRL(2,0)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -void main(void)
 | 
	
		
			
				|  |  | +static void test_download(void)
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | -    static const char hello[] = /* "\f\033[2J\033[H" */
 | 
	
		
			
				|  |  | -	"\r\n\n*** Hello, World! ***\r\n"
 | 
	
		
			
				|  |  | -	"Firmware compiled on: " __DATE__ " " __TIME__ "\r\n\n";
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    /* The data section is not reinitialized on reset */
 | 
	
		
			
				|  |  | -    static unsigned int loops = 1;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    uint8_t led = 0;
 | 
	
		
			
				|  |  | -    uint32_t done;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    con_set_baudrate(115200);
 | 
	
		
			
				|  |  | -    set_led(led = 0);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    while (!SDRAM_DONE)
 | 
	
		
			
				|  |  | -	/* wait */;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    done = rdtime();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    con_puts(hello);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    con_printf("This is loop: %u\n", loops++);
 | 
	
		
			
				|  |  | -    con_printf("SDRAM download took %u us\n", done/(CPU_HZ/1000000));
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      volatile uint32_t *p = (uint32_t *)SDRAM_ADDR;
 | 
	
		
			
				|  |  |      const unsigned int words = 128*1024;
 | 
	
		
			
				|  |  |      unsigned int ok = words;
 | 
	
		
			
				|  |  |      uint32_t val = 0x00001111;
 | 
	
		
			
				|  |  | +    unsigned int ratelimit = ERROR_RATELIMIT;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      for (unsigned int w = 0; w < words; w++) {
 | 
	
		
			
				|  |  | -	if (*p++ != val)
 | 
	
		
			
				|  |  | +	uint32_t ram = *p;
 | 
	
		
			
				|  |  | +	if (ram != val) {
 | 
	
		
			
				|  |  |  	    ok--;
 | 
	
		
			
				|  |  | +	    if (ratelimit) {
 | 
	
		
			
				|  |  | +		ratelimit--;
 | 
	
		
			
				|  |  | +		con_printf("%p : 0x%08x expected 0x%08x\n", p, ram, val);
 | 
	
		
			
				|  |  | +	    }
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	p++;
 | 
	
		
			
				|  |  |  	val = (val * 0x89abcdef) +
 | 
	
		
			
				|  |  |  	    (uint32_t)((val * 0x89abcdefULL) >> 32) +
 | 
	
		
			
				|  |  |  	    (w * 0x76543210);
 | 
	
	
		
			
				|  | @@ -144,15 +128,49 @@ void main(void)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	con_putc('\n');
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/* Make sure we don't leave anything in SDRAM that could be a false negative */
 | 
	
		
			
				|  |  | +static void scrub_sdram(void)
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    volatile uint32_t *p;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    for (p = (uint32_t *)SDRAM_ADDR; p < (uint32_t *)SDRAM_END; p++)
 | 
	
		
			
				|  |  | +	*p = 0xdeadbeef;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +void main(void)
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    static const char hello[] =
 | 
	
		
			
				|  |  | +	"\n*** Hello, World! ***\n"
 | 
	
		
			
				|  |  | +	"Firmware compiled on: " __DATE__ " " __TIME__ "\n\n";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /* The data section is not reinitialized on reset */
 | 
	
		
			
				|  |  | +    static unsigned int loops = 1;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    uint8_t led = 0;
 | 
	
		
			
				|  |  | +    uint32_t done;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    con_set_baudrate(115200);
 | 
	
		
			
				|  |  | +    set_led(led = 0);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    while (!ROMCOPY_DONE)
 | 
	
		
			
				|  |  | +	pause();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    done = rdtime();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    con_puts(hello);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    con_printf("This is loop: %u\n", loops++);
 | 
	
		
			
				|  |  | +    con_printf("SDRAM download took %u us\n", done/(CPU_HZ/1000000));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    test_download();
 | 
	
		
			
				|  |  |      test_sdram();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    p = (uint32_t *)SDRAM_ADDR;
 | 
	
		
			
				|  |  | -    for (unsigned int w = 0; w < words; w++)
 | 
	
		
			
				|  |  | -	*p++ = 0xdeadbeef;
 | 
	
		
			
				|  |  | +    scrub_sdram();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    udelay(4000000);
 | 
	
		
			
				|  |  | -    con_puts("*** Doing reset ***\r\n\n");
 | 
	
		
			
				|  |  | +    udelay(2000000);
 | 
	
		
			
				|  |  | +    con_puts("*** Doing reset ***\n");
 | 
	
		
			
				|  |  |      con_flush();
 | 
	
		
			
				|  |  |      while ( 1 )
 | 
	
		
			
				|  |  |        RESET_CMD = 1;
 |