- added flashtest

git-svn-id: http://moon:8086/svn/mips@174 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
2021-11-21 15:18:54 +00:00
parent 76a6b4fa89
commit c07ba24e60
2 changed files with 549 additions and 1 deletions
+10 -1
View File
@@ -3,7 +3,7 @@ BOARD ?=ml402
include ../make/mips_app.mk
PROG-ml402 = $(addprefix $(BUILD_DIR)/, hello.elf testbench.elf test_irq.elf dhry.elf queens.elf stanford.elf paranoia.elf rmd160_test.elf Bessel.elf whet.elf phrasen.elf dttl.elf richards_benchmark.elf test_exception.elf life.elf r3.elf gunzip.elf basic_math.elf jman_patches.elf jman_patchmeshes.elf jman_polys.elf test_hpi.elf test_vga.elf test_fft.elf)
PROG-ml402 = $(addprefix $(BUILD_DIR)/, hello.elf testbench.elf test_irq.elf dhry.elf queens.elf stanford.elf paranoia.elf rmd160_test.elf Bessel.elf whet.elf phrasen.elf dttl.elf richards_benchmark.elf test_exception.elf life.elf r3.elf gunzip.elf basic_math.elf jman_patches.elf jman_patchmeshes.elf jman_polys.elf test_hpi.elf test_vga.elf test_fft.elf flashtest.elf)
PROG-denano = $(addprefix $(BUILD_DIR)/, hello.elf dhry.elf queens.elf stanford.elf paranoia.elf rmd160_test.elf Bessel.elf whet.elf phrasen.elf dttl.elf richards_benchmark.elf test_exception.elf testbench_denano.elf)
PROG-sim = $(addprefix $(BUILD_DIR)/, hello.elf test_exception_sim.elf)
@@ -12,6 +12,15 @@ all: $(PROG-$(BOARD))
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/flashtest.elf: $(BUILD_DIR) flashtest.c
$(CC) $(CFLAGS) -o $@ -O2 flashtest.c $(LIBS) >$@.map
$(OBJDUMP) -d $@ > $@.dis
$(OBJCOPY) $@ -O binary $@.bin
$(OBJCOPY) -O srec $@ $@.srec
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
cat $@.srec | $(PACKHEX) > $@.pack
$(OBJCOPY) -O ihex -I binary $@.flash.bin $@.hex
$(BUILD_DIR)/test_fft.elf: $(BUILD_DIR) test_fft.c
$(CC) $(CFLAGS) -o $@ -O2 fft.c test_fft.c $(LIBS) >$@.map
$(OBJDUMP) -d $@ > $@.dis
+539
View File
@@ -0,0 +1,539 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <sys/times.h>
#include <sys/time.h>
#include <libsys.h>
#include <cop0.h>
#include <gpio.h>
#include <irq.h>
#include <mips_gfx.h>
#include <mips_ps2.h>
#include "cfiflash.c"
#define TEST16_ERROR -1
int IsEndianBig(void)
{
uint8_t *pBuf;
uint32_t word;
word = 0x12345678;
pBuf = (uint8_t*)&word;
if (((*pBuf+0) == 0x12) && (*(pBuf+1) == 0x34) && (*(pBuf+2) == 0x56) && (*(pBuf+3) == 0x78))
{
return 1;
}
if (((*pBuf+0) == 0x78) && (*(pBuf+1) == 0x56) && (*(pBuf+2) == 0x34) && (*(pBuf+3) == 0x12))
{
return 0;
}
return -1;
}
void PrintCPUinfo(void)
{
int result, rev_id;
int cache_size, cache_line;
int eb;
char *cpu_type_str[7] = {"invalid", "R2000", "R3000", "R6000", "R4000", "reserved", "R6000A"};
// Print Status register
result = CP0_SR_read();
printf("--------------------------------------------------\n");
printf("Status : %8.8X\n", result);
// Print Revision
result = CP0_PRID_read();
rev_id = (result >> 8) & 0xFF;
printf("CPU type : MIPS ");
if ((rev_id > 0) && (rev_id < 0x07))
{
printf(cpu_type_str[rev_id]);
printf(" Rev. ");
rev_id = result & 0xFF;
printf("%d", rev_id);
}
else
printf("Unknown");
eb = IsEndianBig();
if (eb)
printf(" [Big-endian]\n");
if (!eb)
printf(" [Little-endian]\n");
if (eb < 0)
printf(" [Unknown endian]\n");
cache_size = (result >> 16) & 7;
cache_line = (result >> 19) & 7;
printf("I-Cache : %d kBytes (%d Bytes per line)\n", 4*(int)pow(2.0, (double)(8+cache_size))/1024, 4*(int)pow(2.0, (double)(cache_line)));
cache_size = (result >> 24) & 7;
cache_line = (result >> 27) & 7;
printf("D-Cache : %d kBytes (%d Bytes per line)\n", 4*(int)pow(2.0, (double)(8+cache_size))/1024, 4*(int)pow(2.0, (double)(cache_line)));
printf("--------------------------------------------------\n");
}
#define TEST_SIZE (16*1024*1024) // Bytes
#define SMALL_TEST_SIZE (8192) // Bytes
#define FLASH_SIZE (8*1024*1024) // Bytes
int Test16_MemTest(void)
{
int result, i, j, cnt, size;
uint8_t *ram8 = NULL;
uint16_t *ram16 = NULL;
uint32_t *ram32 = NULL;
uint32_t volatile *pFlashIO = (uint32_t*)SYS_FLASH_IO;
uint32_t volatile *pFlashMem = (uint32_t*)SYS_FLASH_MEM;
uint32_t volatile *pROM = (uint32_t*)0xBFC00000;
uint32_t volatile *pVGA_src0 = (uint32_t*)SYS_VGA_BLIT_SRC0_ADDR;
uint32_t volatile *pVGA_dst = (uint32_t*)SYS_VGA_BLIT_DST_ADDR;
uint32_t volatile *pVGA_dimx_src0 = (uint32_t*)SYS_VGA_BLIT_SRC0_DIMX;
uint32_t volatile *pVGA_dimx_dst = (uint32_t*)SYS_VGA_BLIT_DST_DIMX;
uint32_t volatile *pVGA_nx = (uint32_t*)SYS_VGA_BLIT_NX;
uint32_t volatile *pVGA_ny = (uint32_t*)SYS_VGA_BLIT_NY;
uint32_t volatile *pVGA_ctrl = (uint32_t*)SYS_VGA_CTRL;
uint32_t volatile *pVGA_moffs_0 = (uint32_t*)SYS_VGA_FB_FRONT;
uint32_t volatile *pVGA_moffs_1 = (uint32_t*)SYS_VGA_FB_BACK;
uint32_t volatile *pVGA_const_color = (uint32_t*)SYS_VGA_BLIT_COLOR;
uint32_t *pSrc32, *pDst32;
uint32_t start, end;
uint32_t color_cycle[12] = {0x000000FF, 0x00808080, 0x0000FFFF, 0x00808080, 0x0000FF00, 0x00808080, 0x00FFFF00, 0x00808080, 0x00FF0000, 0x00808080, 0x00FF00FF, 0x00808080};
pSrc32 = (uint32_t*)calloc(TEST_SIZE/4,sizeof(uint32_t));
pDst32 = (uint32_t*)calloc(TEST_SIZE/4,sizeof(uint32_t));
// Memtest BEGIN
printf("Dump first 16 bytes of flash blocks\n");
for (i=0; i < FLASH_SIZE; i += 0x40000)
memdump((uint8_t*)(pFlashIO+i/4), 0, 16, 16);
printf("\n");
printf("SDRAM Memory Test\n");
printf("Test size %d kByte\n\n", TEST_SIZE/1024);
ram8 = (uint8_t*)pDst32;
printf("Zeroize SDRAM (memset)...");
start = clock();
memset(ram8, 0, TEST_SIZE);
end = clock();
printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
printf("Zeroize SDRAM (8-Bit access)...");
start = clock();
for (i=0; i < TEST_SIZE; i++)
ram8[i] = (uint8_t)0;
end = clock();
printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
ram16 = (uint16_t*)pDst32;
printf("Zeroize SDRAM (16-Bit access)...");
start = clock();
for (i=0; i < TEST_SIZE/2; i++)
ram16[i] = (uint16_t)0;
end = clock();
printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
ram32 = (uint32_t*)pDst32;
printf("Zeroize SDRAM (32-Bit access)...");
start = clock();
for (i=0; i < TEST_SIZE/4; i++)
ram32[i] = (uint32_t)0;
end = clock();
printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
ram8 = (uint8_t*)pDst32;
printf("Write SDRAM (8-Bit access)...");
start = clock();
for (i=0; i < TEST_SIZE; i++)
ram8[i] = (uint8_t)i;
end = clock();
printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
printf("Verify SDRAM (8-Bit access)...");
start = clock();
for (i=TEST_SIZE-1; i >= 0; i--)
if (ram8[i] != (uint8_t)i)
break;
end = clock();
i++;
if (i)
{
printf("failed\r\n");
return TEST16_ERROR;
}
else
printf("passed (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
ram16 = (uint16_t*)pDst32;
printf("Write SDRAM (16-Bit access)...");
start = clock();
for (i=0; i < TEST_SIZE/2; i++)
ram16[i] = (uint16_t)i;
end = clock();
printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
printf("Verify SDRAM (16-Bit access)...");
start = clock();
for (i=TEST_SIZE/2-1; i >= 0; i--)
if (ram16[i] != (uint16_t)i)
break;
end = clock();
i++;
if (i)
{
printf("failed\r\n");
return TEST16_ERROR;
}
else
printf("passed (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
ram32 = (uint32_t*)pDst32;
printf("Write SDRAM (32-Bit access)...");
start = clock();
for (i=0; i < TEST_SIZE/4; i++)
{
ram32[i] = (uint32_t)i;
}
end = clock();
printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
printf("Verify SDRAM (32-Bit access)...");
start = clock();
for (i=TEST_SIZE/4-1; i >= 0; i--)
{
if (ram32[i] != (uint32_t)i)
break;
}
end = clock();
i++;
if (i)
{
printf("failed\r\n");
return TEST16_ERROR;
}
else
printf("passed (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
printf("\n");
printf("Small data test (size = %d kByte)\n", SMALL_TEST_SIZE/1024);
printf("Write SDRAM (32-Bit access)...");
ram32 = (uint32_t*)pDst32;
start = clock();
for (j=0; j < TEST_SIZE/SMALL_TEST_SIZE; j++)
for (i=0; i < SMALL_TEST_SIZE/4; i++)
ram32[i] = (uint32_t)i;
end = clock();
printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
// -------------------------------------------------------------------
// Verify
printf("Verify SDRAM (32-Bit access)...");
start = clock();
for (j=0; j < TEST_SIZE/SMALL_TEST_SIZE; j++)
for (i=SMALL_TEST_SIZE/4-1; i >= 0; i--)
if (ram32[i] != (uint32_t)i)
break;
end = clock();
i++;
if (i)
{
printf("failed\r\n");
return TEST16_ERROR;
}
else
printf("passed (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
for (i=1024; i < 4*65536; i *= 2)
{
printf("Memcpy() (%d kByte)...", i/1024);
start = clock();
for (j=0; j < TEST_SIZE/i; j++)
memcpy(pDst32, pSrc32, i);
end = clock();
printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
}
for (i=1024; i < 4*65536; i *= 2)
{
printf("_GFX_copy32() (%d kByte)...", i/1024);
start = clock();
for (j=0; j < TEST_SIZE/i; j++)
_GFX_copy32(pDst32, pSrc32, i/4);
end = clock();
printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
}
// -------------------------------------------------------------------
printf("\n");
printf("Memcpy() Flash(IO) => SDRAM \n");
printf("Copying %d kBytes...", FLASH_SIZE/(1024));
start = clock();
memcpy(pDst32, (uint32_t*)pFlashIO, FLASH_SIZE);
end = clock();
printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
printf("\n");
printf("Memcpy() Flash(MEM) => SDRAM \n");
printf("Copying %d kBytes...", FLASH_SIZE/(1024));
start = clock();
memcpy(pDst32, (uint32_t*)pFlashMem, FLASH_SIZE);
end = clock();
printf("done (%.2f MByte/s)\n", (double)TEST_SIZE/(1024*1024*(double)(end-start)/CLOCKS_PER_SEC));
printf("\n");
size = 0x2000;
memcpy(pDst32, (uint32_t*)pROM, size);
printf("Verify boot ROM...");
for (i=size/4-1; i >= 0; i--)
if (pDst32[i] != pROM[i])
break;
i++;
if (i)
{
printf("failed\r\n");
return TEST16_ERROR;
}
else
printf("passed\r\n");
DCACHE_invalidate_all();
printf("pFlashIO = %08X\n", pFlashIO);
printf("pFlashMem = %08X\n", pFlashMem);
printf("Verify FLASH(IO) <=> FLASH(MEM)...");
for (i=0; i < FLASH_SIZE/4; i++)
{
if (pFlashIO[i] != pFlashMem[i])
{
printf("\nfailed at offset = %08X", i << 2);
printf("\nfound %08X <=> %08X", pFlashIO[i], pFlashMem[i]);
}
}
printf("\n");
if (i != FLASH_SIZE/4)
{
printf("failed\n");
memdump((uint8_t*)&pFlashIO[i], 0, 16, 256);
memdump((uint8_t*)&pFlashMem[i], 0, 16, 256);
}
else
{
printf("passed\n");
}
// memdump((uint8_t*)pSrc32, 0, 16, size);
// memdump((uint8_t*)0x40000000, 0, 16, 1024);
// Memtest END
// ----------------------------------------------------------
free(pSrc32);
free(pDst32);
sputs("\r\n");
return 0;
}
void flash_print_info(flash_t *pFlash)
{
flash_info_t *pInfo = &pFlash->info;
printf("Base address = %08X\n", pFlash->pBase);
printf("Endianess = %08X\n", pFlash->eb);
printf("Flash size = %08X\n", pInfo->flashsize);
printf("Block size = %08X\n", pInfo->blocksize);
printf("nblocks = %08X\n", pInfo->nblocks);
printf("wbuf_size = %08X\n", pInfo->wbuf_size);
printf("if_width = %08X\n", pInfo->if_width);
printf("num_flash = %08X\n", pInfo->num_flash);
}
void create_data(void *pData, size_t size)
{
uint8_t *pData8 = (uint8_t*)pData;
for (size_t i=0; i < size; i++)
{
int r = rand();
pData8[i] = (uint8_t)r;
}
}
void flashtest(flash_t *pFlash)
{
flash_info_t *pInfo = &pFlash->info;
uint32_t addr = pInfo->blocksize;
printf("--------------------------------------------\n");
printf("CFI API\n");
printf("--------------------------------------------\n");
while(addr < pInfo->flashsize)
{
uint32_t result = cfi_block_is_locked(pFlash, addr/4);
printf("cfi_block_is_locked(%08X) = %08X\n", addr, result);
if (result == 0)
{
result = cfi_block_erase(pFlash, addr/4);
printf("cfi_block_erase(%08X) = %08X\n", addr, result);
}
addr += pInfo->blocksize;
};
addr = pInfo->blocksize;
size_t size = pInfo->blocksize;
printf("--------------------------------------------\n");
printf("Flash API\n");
printf("--------------------------------------------\n");
srand(0x3101970);
void *data = malloc(size);
while(addr < pInfo->flashsize)
{
uint32_t result = flash_erase(pFlash, addr, size);
printf("flash_erase(%08X) = %08X\n", addr, result);
if (result != 0)
{
break;
}
create_data(data, size);
result = flash_program(pFlash, addr, data, size);
printf("flash_program(%08X) = %08X\n", addr, result);
if (result != 0)
{
break;
}
result = flash_verify(pFlash, addr, data, size);
printf("flash_verify(%08X) = %08X\n", addr, result);
if (result != 0)
{
break;
}
addr += pInfo->blocksize;
};
}
int main (void)
{
int result, i, j, cnt, size;
uint32_t volatile *pUART_baud = (uint32_t*)SYS_UART_BAUD;
uint32_t volatile *pUART_stat = (uint32_t*)SYS_UART_STAT;
uint32_t volatile *pGPIO = (uint32_t*)SYS_GPIO_0_DATA;
uint32_t volatile *pReg_usec = (uint32_t*)SYS_TIMER_USEC;
uint32_t volatile *pReg_sec = (uint32_t*)SYS_TIMER_SEC;
uint32_t volatile *pSSRAM = (uint32_t*)SYS_SSRAM_IO;
uint32_t volatile *pTim_ctrl = (uint32_t*)SYS_ITIM_CTRL;
uint32_t volatile *pTim_stat = (uint32_t*)SYS_ITIM_STAT;
uint32_t volatile *pTim0_cnt = (uint32_t*)SYS_ITIM0_CNT;
uint32_t volatile *pTim0_cmp = (uint32_t*)SYS_ITIM0_CMP;
uint32_t volatile *pTim1_cnt = (uint32_t*)SYS_ITIM1_CNT;
uint32_t volatile *pTim1_cmp = (uint32_t*)SYS_ITIM1_CMP;
uint32_t volatile *pVGA_cgcol = (uint32_t*)SYS_VGA_CGCOL;
uint32_t *pFlashPicture = (uint32_t*)(SYS_FLASH_MEM + 0x00600000);
uint32_t volatile *pVGA_src0 = (uint32_t*)SYS_VGA_BLIT_SRC0_ADDR;
uint32_t volatile *pVGA_dst = (uint32_t*)SYS_VGA_BLIT_DST_ADDR;
uint32_t volatile *pVGA_dimx_src0 = (uint32_t*)SYS_VGA_BLIT_SRC0_DIMX;
uint32_t volatile *pVGA_dimx_dst = (uint32_t*)SYS_VGA_BLIT_DST_DIMX;
uint32_t volatile *pVGA_nx = (uint32_t*)SYS_VGA_BLIT_NX;
uint32_t volatile *pVGA_ny = (uint32_t*)SYS_VGA_BLIT_NY;
uint32_t volatile *pVGA_ctrl = (uint32_t*)SYS_VGA_CTRL;
uint32_t volatile *pVGA_moffs_0 = (uint32_t*)SYS_VGA_FB_FRONT;
uint32_t volatile *pVGA_const_color = (uint32_t*)SYS_VGA_BLIT_COLOR;
uint32_t screen_res_x, screen_res_y, screen_fps;
uint64_t *pBuf64_0, *pBuf64_1;
time_t curr_date;
struct tm *pDate, date;
uint32_t start, end;
char sel[80];
struct timeval time_sec;
uint32_t *pPic;
gpio_if_t gpio_if;
pPic = (uint32_t*)malloc(800*600*sizeof(uint32_t));
memcpy(pPic, pFlashPicture, 800*600*sizeof(uint32_t));
size_t g_cnt = 1;
gpio_init(&gpio_if, SYS_GPIO_0_BASE);
*pVGA_cgcol = 0x00FFFFFF;
*pTim0_cnt = 0;
*pTim1_cnt = 0;
*pTim0_cmp = 0x40000;
*pTim1_cmp = 100000000;
*pTim_stat = (1 << 2) | (1 << 0);
*pTim_ctrl = (3 << 2);
// *pUART_baud = 1;
setbuf(stdout, NULL);
PrintCPUinfo();
gpio_write(&gpio_if, GPIO_0_MDIO_RST, GPIO_0_ALIGN_MDIO, GPIO_DATA_OFFSET, 1);
sleep(100);
gpio_write(&gpio_if, GPIO_0_MDIO_RST, GPIO_0_ALIGN_MDIO, GPIO_DATA_OFFSET, 0);
flash_t flash;
flash_find(&flash, SYS_FLASH_IO);
flash_print_info(&flash);
flashtest(&flash);
printf("\n");
cnt = 0;
do
{
gpio_write(&gpio_if, GPIO_0_MASK_LED, GPIO_0_ALIGN_LED, GPIO_DATA_OFFSET, cnt);
// printf("-------------------------------------------\n");
// printf("-- Mem Test -------------------------------\n");
// printf("-------------------------------------------\n");
// result = Test16_MemTest();
// if (IS_ERROR(result))
// break;
// printf("passed\n\n");
printf("Iteration %d: Passed\n", cnt);
curr_date = time(NULL);
pDate = gmtime(&curr_date);
puts(asctime(pDate));
cnt++;
// printf("V=%.17e\n", pow((double)cnt-1, (double)cnt));
} while(0);
printf("End of program\n");
return 1;
}