方法比较简单, 参考redboot原有的命令即可.参考代码如下:
contact msn: jinglexy@yahoo.com.cn
static void
do_memtest(int argc, char *argv[])
{
struct option_info opts[6];
int start_addr;
int test_size;
int test_count;
bool b1 = false, b2 = false, b3 = false;
bool succ = true;
int tmp;
int curr_addr;
int i;
// 获取参数
init_opts(&opts[0], 'a', true, OPTION_ARG_TYPE_NUM,
(void *)&start_addr, (bool *)&b1, "base address");
init_opts(&opts[1], 's', true, OPTION_ARG_TYPE_NUM,
(void *)&test_size, (bool *)&b2, "length");
init_opts(&opts[2], 'c', true, OPTION_ARG_TYPE_NUM,
(void *)&test_count, (bool *)&b3, "test count");
if (!scan_opts(argc, argv, 1, opts, 3, 0, 0, "")) {
return;
}
if(b1) {
diag_printf("b1 set\n");
} else {
diag_printf("b1 not set\n");
return;
}
if(b2) {
diag_printf("b2 set\n");
} else {
diag_printf("b2 not set\n");
return;
}
if(b3) {
diag_printf("b3 set\n");
} else {
diag_printf("b3 not set\n");
return;
}
#if 0
if(!b1 || ! b2) {
diag_printf("arg err: memtest -a 0x1000000 -s 0x2000(a is addr, s is size)\n");
return -1;
}
#endif
// 测试内存
diag_printf("usage: memtest -a 0x1000000 -s 0x2000 -c 2(a is addr, s is size, c is count)\n");
diag_printf("begin test, start: 0x%x, size: 0x%x, count: %d\n", start_addr, test_size, test_count);
#if 1
for(i = 0; i < test_count; i++) {
curr_addr = start_addr;
while(curr_addr < start_addr + test_size) {
// 写入0xa5a5a5a5
#define TEST_VALUE1 0xa5a5a5a5
*(int *)curr_addr = TEST_VALUE1;
if(TEST_VALUE1 != *(int *)curr_addr) {
succ = false;
goto out1;
}
// 写入0x5a5a5a5a
#define TEST_VALUE2 0x5a5a5a5a
*(int *)curr_addr = TEST_VALUE2;
if(TEST_VALUE2 != *(int *)curr_addr) {
succ = false;
goto out1;
}
curr_addr += 4;
}
diag_printf("test cross %d succ\n", i + 1);
}
#endif
out1:
// 测试结果
if(succ)
diag_printf("test succ\n");
else
diag_printf("test err@0x%x\n", curr_addr);
}
RedBoot_cmd("memtest",
"usage: memtest -a 0x1000000 -s 0x2000 -c 2(a is addr, s is size, c is count)",
"",
do_memtest
);
static void
do_setmem(int argc, char *argv[])
{
struct option_info opts[4];
int mem_addr;
int mem_value;
bool b1 = false, b2 = false;
// 获取参数
init_opts(&opts[0], 'a', true, OPTION_ARG_TYPE_NUM,
(void *)&mem_addr, (bool *)&b1, "mem address");
init_opts(&opts[1], 'v', true, OPTION_ARG_TYPE_NUM,
(void *)&mem_value, (bool *)&b2, "mem value");
if (!scan_opts(argc, argv, 1, opts, 2, 0, 0, "")) {
return;
}
if(b1) {
diag_printf("b1 set\n");
} else {
diag_printf("b1 not set\n");
return;
}
if(b2) {
diag_printf("b2 set\n");
} else {
diag_printf("b2 not set\n");
return;
}
#if 0
if(!b1 || ! b2) {
diag_printf("arg err: memtest -a 0x1000000 -s 0x2000(a is addr, s is size)\n");
return -1;
}
#endif
// 测试内存
diag_printf("usage: setmem -a 0x1000000 -v 0x2000(a is addr, v is value)\n");
diag_printf("mem addr: 0x%x, value: 0x%x\n", mem_addr, mem_value);
*(int *)mem_addr = mem_value;
}
RedBoot_cmd("setmem",
"usage: setmem -a 0x1000000 -v 0x2000(a is addr, v is value)",
"",
do_setmem
);
测试方法:
测试内存:
内存范围: 256M : 0x0~0x100 00000
memtest -a 0x100000 -s 0xfe00000 -c 2
memtest -a 0x800000 -s 0x2000000 -c 10 从8M开始测试32M, 第4次复位
memtest -a 0x800000 -s 0xe000000 -c 10 10ok, 1failed
memtest -a 0x800000 -s 0xe800000 -c 10
memtest -a 0x800000 -s 0xf000000 -c 10
memtest -a 0x1000000 -s 0x2000 -c 2
memtest -a 0x1000000 -s 0x2000 -c 2
memtest -a 0x1000000 -s 0x2000 -c 2
memtest -a 0x1000000 -s 0x2000 -c 2
memtest -a 0x1000000 -s 0x2000 -c 2
memtest -a 0x1000000 -s 0x2000 -c 2
memtest -a 0x1000000 -s 0x2000 -c 2
memtest -a 0x1000000 -s 0x2000 -c 2
memtest -a 0x1000000 -s 0x2000 -c 2
memtest -a 0x1000000 -s 0x2000 -c 2
memtest -a 0x1000000 -s 0x2000 -c 2
memtest -a 0x1000000 -s 0x2000 -c 2
memtest -a 0x1000000 -s 0x2000 -c 2
设置内存(寄存器):
dump -b 0xcc00e504 -l 4
setmem -a 0xcc00e504 -v 0xf1110006
dump -b 0xcc00e504 -l 4
阅读(1944) | 评论(0) | 转发(0) |