ecctest.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifdef ECC_TEST
  2. static inline void ecc_off(void)
  3. {
  4. *(volatile int *)(INTERNAL_REG_BASE_ADDR+0x4b4) &= ~0x00200000;
  5. }
  6. static inline void ecc_on(void)
  7. {
  8. *(volatile int *)(INTERNAL_REG_BASE_ADDR+0x4b4) |= 0x00200000;
  9. }
  10. static int putshex(const char *buf, int len)
  11. {
  12. int i;
  13. for (i=0;i<len;i++) {
  14. printf("%02x", buf[i]);
  15. }
  16. return 0;
  17. }
  18. static int char_memcpy(void *d, const void *s, int len)
  19. {
  20. int i;
  21. char *cd=d;
  22. const char *cs=s;
  23. for(i=0;i<len;i++) {
  24. *(cd++)=*(cs++);
  25. }
  26. return 0;
  27. }
  28. static int memory_test(char *buf)
  29. {
  30. const char src[][16]={
  31. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  32. {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
  33. {0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02},
  34. {0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04},
  35. {0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08},
  36. {0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10},
  37. {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20},
  38. {0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40},
  39. {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80},
  40. {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55},
  41. {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa},
  42. {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}
  43. };
  44. const int foo[] = {0};
  45. int i,j,a;
  46. printf("\ntest @ %d %p\n", foo[0], buf);
  47. for(i=0;i<12;i++) {
  48. for(a=0;a<8;a++) {
  49. const char *s=src[i]+a;
  50. int align=(unsigned)(s)&0x7;
  51. /* ecc_off(); */
  52. memcpy(buf,s,8);
  53. /* ecc_on(); */
  54. putshex(s,8);
  55. if(memcmp(buf,s,8)) {
  56. putc('\n');
  57. putshex(buf,8);
  58. printf(" [FAIL] (%p) align=%d\n", s, align);
  59. for(j=0;j<8;j++) {
  60. s[j]==buf[j]?puts(" "):printf("%02x", (s[j])^(buf[j]));
  61. }
  62. putc('\n');
  63. } else {
  64. printf(" [PASS] (%p) align=%d\n", s, align);
  65. }
  66. /* ecc_off(); */
  67. char_memcpy(buf,s,8);
  68. /* ecc_on(); */
  69. putshex(s,8);
  70. if(memcmp(buf,s,8)) {
  71. putc('\n');
  72. putshex(buf,8);
  73. printf(" [FAIL] (%p) align=%d\n", s, align);
  74. for(j=0;j<8;j++) {
  75. s[j]==buf[j]?puts(" "):printf("%02x", (s[j])^(buf[j]));
  76. }
  77. putc('\n');
  78. } else {
  79. printf(" [PASS] (%p) align=%d\n", s, align);
  80. }
  81. }
  82. }
  83. return 0;
  84. }
  85. #endif