rom_test.c

来自「uboot底层驱动」· C语言 代码 · 共 120 行

C
120
字号
#include "my_printf.h"#include "erase_copy.h"#define		ERASEBLOCKSIZE		0x2000#define addr_base 0x20000000int ERRl = 0;int adrrl_test(int addr_start, int addr_end){	int i = 0;	int k;		int count = (addr_end-addr_start+1) / ERASEBLOCKSIZE + 1; 		k =  (addr_start-addr_base) / ERASEBLOCKSIZE;	for (; i < count; i++)	{				NorFlash_unlock(addr_base + (k+i)*ERASEBLOCKSIZE);		NorFlash_bolckerase(addr_base + (k+i)*ERASEBLOCKSIZE);	}  for (i = 0; i<(addr_end-addr_start); i++, i++)		 NorFlash_write(addr_start+i, i);	for (i=0; i<(addr_end-addr_start); i++,i++)		if ( i != NorFlash_read(addr_start + i) )		{			my_printf("addr bus error\n\r");			ERRl = 1;			return 1;		}	ERRl = 0;}	int flash_test(int addr_start, int addr_end){	int i = 0;	int j = -1;	int erase_count;	//do {	for (; i < (addr_end-addr_start); )	{		if ( (erase_count = (addr_start+i-addr_base) / ERASEBLOCKSIZE) > j)		{			j = erase_count;			NorFlash_unlock(addr_base + erase_count*ERASEBLOCKSIZE);			NorFlash_bolckerase(addr_base + erase_count*ERASEBLOCKSIZE);			//my_printf("erase ok once time\n\r"); 		} 				NorFlash_write(addr_start+i, 0x5555);		NorFlash_write(addr_start+i+2, 0xaaaa);		if ( (NorFlash_read(addr_start+i) != 0x5555) || (NorFlash_read(addr_start+i+2) != 0xaaaa)  )		{			/*if ( NorFlash_read(addr_base+i) == 0xffff )			{				addr_test(addr_base, i+1+1);				if ( 1== ERR )					return 1;				my_printf("sdram 0x%x\r\n", i+1+1);					return 0;			}			else*/				ERRl = 1;		}		if ( 1==ERRl ) 		{			my_printf("sdram or data bus error\r\n");			return 1;		}		i++;		i++;		i++;		i++;	}		 i = 0;	 j = -1;		//do {	for (; i < (addr_end-addr_start); )	{		if ( (erase_count = (addr_start+i-addr_base) / ERASEBLOCKSIZE) > j)		{			j = erase_count;			NorFlash_unlock(addr_base + erase_count*ERASEBLOCKSIZE);			NorFlash_bolckerase(addr_base + erase_count*ERASEBLOCKSIZE);			//my_printf("erase ok once time\n\r"); 		}		NorFlash_write(addr_start+i, 0xaaaa);		NorFlash_write(addr_start+i+2, 0x5555);		if ( (NorFlash_read(addr_start+i) != 0xaaaa) || (NorFlash_read(addr_start+i+2) != 0x5555) )			ERRl = 1;		if ( 1==ERRl ) 		{			my_printf("sdram or data bus error\r\n");			return 1;		}		i++;		i++;		i++;		i++;	}	//adrrl_test(addr_start, addr_end);	if ( 0==ERRl )			my_printf("flash test ok!\n\r");				//} while (1);}							

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?