參考 cp, cmp 與 erase command之source code
int do_fhtest(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
ulong addr = 0x100e0000, dest = 0x4000000, len = 0x8, size = 2;
ulong count = len;
//erase
flash_sect_erase(0x100e0000, 0x100fffff);
// write to flash
int rc = flash_write(0x3000000, 0x100e0000, count*size);
//flash to mem
//ulong addr = 0x100e0000, dest = 0x4000000, count = 0x10, size = 2;
count = len;
while (count-- > 0)
{
if (size == 4)
{
*((ulong *)dest) = *((ulong *)addr);
}
else if (size == 2)
{
*((ushort *)dest) = *((ushort *)addr);
}
else
{
*((u_char *)dest) = *((u_char *)addr);
}
addr += size;
dest += size;
}
//compare
ulong addr1=0x3000000, addr2=0x4000000;
//ulong addr1=0x100e0000, addr2=0x4000000;
count = len;
while (count-- > 0)
{
if (size == 4)
{
ulong word1 = *(ulong *)addr1;
ulong word2 = *(ulong *)addr2;
if (word1 != word2)
{
printf("word at 0x%08lx (0x%08lx) "
"!= word at 0x%08lx (0x%08lx)\n",
addr1, word1, addr2, word2);
return 0;
}
}
else if (size == 2)
{
ushort hword1 = *(ushort *)addr1;
ushort hword2 = *(ushort *)addr2;
if (hword1 != hword2)
{
printf("halfword at 0x%08lx (0x%04x) "
"!= halfword at 0x%08lx (0x%04x)\n",
addr1, hword1, addr2, hword2);
//printf("FAIL\N");
return 0;
//break;
}
}
addr1 += size;
addr2 += size;
}
printf("PASS\n");
return 0;
}
U_BOOT_CMD
(
untest, 4, 1, do_fhtest,
"flashtest \n",
""
"flashtest \n"
);