memtst.c

来自「适合KS8695X」· C语言 代码 · 共 591 行 · 第 1/2 页

C
591
字号
/*
 * (C) Copyright 2001
 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 *
 */

/* NOT Used yet...
  add following code to PIP405.c :
int testdram (void)
{
	unsigned char s[32];
	int i;

	i = getenv_r ("testmem", s, 32);
	if (i != 0) {
		i = (int) simple_strtoul (s, NULL, 10);
		if ((i > 0) && (i < 0xf)) {
			printf ("testing ");
			i = mem_test (0, ramsize, i);
			if (i > 0)
				printf ("ERROR ");
			else
				printf ("Ok ");
		}
	}
	return (1);
}
*/


#include <common.h>
#include <asm/processor.h>
#include <405gp_i2c.h>

#define FALSE           0
#define TRUE            1

#define TEST_QUIET 			8
#define TEST_SHOW_PROG 	4
#define TEST_SHOW_ERR 	2
#define TEST_SHOW_ALL		1

#define TESTPAT1 0xAA55AA55
#define TESTPAT2 0x55AA55AA
#define TEST_PASSED 0
#define TEST_FAILED 1
#define MEGABYTE (1024*1024)


typedef struct {
	volatile unsigned long pat1;
	volatile unsigned long pat2;
} RAM_MEMTEST_PATTERN2;

typedef struct {
	volatile unsigned long addr;
} RAM_MEMTEST_ADDRLINE;

static __inline unsigned long Swap_32 (unsigned long val)
{
	return (((val << 16) & 0xFFFF0000) | ((val >> 16) & 0x0000FFFF));
}

void testm_puts (int quiet, char *buf)
{
	if ((quiet & TEST_SHOW_ALL) == TEST_SHOW_ALL)
		puts (buf);
}


void Write_Error (int mode, unsigned long addr, unsigned long expected,
				  unsigned long actual)
{

	char dispbuf[64];

	sprintf (dispbuf, "\n ERROR @ 0x%08lX: (exp: 0x%08lX act: 0x%08lX) ",
			 addr, expected, actual);
	testm_puts (((mode & TEST_SHOW_ERR) ==
				 TEST_SHOW_ERR) ? TEST_SHOW_ALL : mode, dispbuf);
}


/*
 * fills the memblock of <size> bytes from <startaddr> with pat1 and pat2
 */


void RAM_MemTest_WritePattern2 (unsigned long startaddr,
								unsigned long size, unsigned long pat1,
								unsigned long pat2)
{
	RAM_MEMTEST_PATTERN2 *p, *pe;

	p = (RAM_MEMTEST_PATTERN2 *) startaddr;
	pe = (RAM_MEMTEST_PATTERN2 *) (startaddr + size);

	while (p < pe) {
		p->pat1 = pat1;
		p->pat2 = pat2;
		p++;
	}							/* endwhile */
}

/*
 * checks the memblock of <size> bytes from <startaddr> with pat1 and pat2
 * returns the address of the first error or NULL if all is well
 */

void *RAM_MemTest_CheckPattern2 (int mode, unsigned long startaddr,
								 unsigned long size, unsigned long pat1,
								 unsigned long pat2)
{
	RAM_MEMTEST_PATTERN2 *p, *pe;
	unsigned long actual1, actual2;

	p = (RAM_MEMTEST_PATTERN2 *) startaddr;
	pe = (RAM_MEMTEST_PATTERN2 *) (startaddr + size);

	while (p < pe) {
		actual1 = p->pat1;
		actual2 = p->pat2;

		if (actual1 != pat1) {
			Write_Error (mode, (unsigned long) &(p->pat1), pat1, actual1);
			return ((void *) &(p->pat1));
		}
		/* endif */
		if (actual2 != pat2) {
			Write_Error (mode, (unsigned long) &(p->pat2), pat2, actual2);
			return ((void *) &(p->pat2));
		}
		/* endif */
		p++;
	}							/* endwhile */

	return (NULL);
}

/*
 * fills the memblock of <size> bytes from <startaddr> with the address
 */

void RAM_MemTest_WriteAddrLine (unsigned long startaddr,
								unsigned long size, int swapped)
{
	RAM_MEMTEST_ADDRLINE *p, *pe;

	p = (RAM_MEMTEST_ADDRLINE *) startaddr;
	pe = (RAM_MEMTEST_ADDRLINE *) (startaddr + size);

	if (!swapped) {
		while (p < pe) {
			p->addr = (unsigned long) p;
			p++;
		}						/* endwhile */
	} else {
		while (p < pe) {
			p->addr = Swap_32 ((unsigned long) p);
			p++;
		}						/* endwhile */
	}							/* endif */
}

/*
 * checks the memblock of <size> bytes from <startaddr>
 * returns the address of the error or NULL if all is well
 */

void *RAM_MemTest_CheckAddrLine (int mode, unsigned long startaddr,
								 unsigned long size, int swapped)
{
	RAM_MEMTEST_ADDRLINE *p, *pe;
	unsigned long actual, expected;

	p = (RAM_MEMTEST_ADDRLINE *) startaddr;
	pe = (RAM_MEMTEST_ADDRLINE *) (startaddr + size);

	if (!swapped) {
		while (p < pe) {
			actual = p->addr;
			expected = (unsigned long) p;
			if (actual != expected) {
				Write_Error (mode, (unsigned long) &(p->addr), expected,
							 actual);
				return ((void *) &(p->addr));
			}					/* endif */
			p++;
		}						/* endwhile */
	} else {
		while (p < pe) {
			actual = p->addr;
			expected = Swap_32 ((unsigned long) p);
			if (actual != expected) {
				Write_Error (mode, (unsigned long) &(p->addr), expected,
							 actual);
				return ((void *) &(p->addr));
			}					/* endif */
			p++;
		}						/* endwhile */
	}							/* endif */

	return (NULL);
}

/*
 * checks the memblock of <size> bytes from <startaddr+size>
 * returns the address of the error or NULL if all is well
 */

void *RAM_MemTest_CheckAddrLineReverse (int mode, unsigned long startaddr,
										unsigned long size, int swapped)
{
	RAM_MEMTEST_ADDRLINE *p, *pe;
	unsigned long actual, expected;

	p = (RAM_MEMTEST_ADDRLINE *) (startaddr + size - sizeof (p->addr));
	pe = (RAM_MEMTEST_ADDRLINE *) startaddr;

	if (!swapped) {
		while (p > pe) {
			actual = p->addr;
			expected = (unsigned long) p;
			if (actual != expected) {
				Write_Error (mode, (unsigned long) &(p->addr), expected,
							 actual);
				return ((void *) &(p->addr));
			}					/* endif */
			p--;
		}						/* endwhile */
	} else {
		while (p > pe) {
			actual = p->addr;
			expected = Swap_32 ((unsigned long) p);
			if (actual != expected) {
				Write_Error (mode, (unsigned long) &(p->addr), expected,
							 actual);
				return ((void *) &(p->addr));
			}					/* endif */
			p--;
		}						/* endwhile */
	}							/* endif */

	return (NULL);
}

/*
 * fills the memblock of <size> bytes from <startaddr> with walking bit pattern
 */

void RAM_MemTest_WriteWalkBit (unsigned long startaddr, unsigned long size)
{
	volatile unsigned long *p, *pe;
	unsigned long i;

	p = (unsigned long *) startaddr;
	pe = (unsigned long *) (startaddr + size);
	i = 0;

	while (p < pe) {
		*p = 1UL << i;
		i = (i + 1 + (((unsigned long) p) >> 7)) % 32;
		p++;
	}							/* endwhile */
}

/*
 * checks the memblock of <size> bytes from <startaddr>
 * returns the address of the error or NULL if all is well
 */

void *RAM_MemTest_CheckWalkBit (int mode, unsigned long startaddr,
								unsigned long size)
{
	volatile unsigned long *p, *pe;
	unsigned long actual, expected;
	unsigned long i;

⌨️ 快捷键说明

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