uboot/board/evb64260/ecctest.c
<<
>>
Prefs
   1indent: Standard input:27: Warning:old style assignment ambiguity in "=*".  Assuming "= *"
   2
   3#ifdef ECC_TEST
   4static inline void ecc_off (void)
   5{
   6        *(volatile int *) (INTERNAL_REG_BASE_ADDR + 0x4b4) &= ~0x00200000;
   7}
   8
   9static inline void ecc_on (void)
  10{
  11        *(volatile int *) (INTERNAL_REG_BASE_ADDR + 0x4b4) |= 0x00200000;
  12}
  13
  14static int putshex (const char *buf, int len)
  15{
  16        int i;
  17
  18        for (i = 0; i < len; i++) {
  19                printf ("%02x", buf[i]);
  20        }
  21        return 0;
  22}
  23
  24static int char_memcpy (void *d, const void *s, int len)
  25{
  26        int i;
  27        char *cd = d;
  28        const char *cs = s;
  29
  30        for (i = 0; i < len; i++) {
  31                *(cd++) = *(cs++);
  32        }
  33        return 0;
  34}
  35
  36static int memory_test (char *buf)
  37{
  38        const char src[][16] = {
  39                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  40                {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  41                 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
  42                {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
  43                 0x02, 0x02, 0x02, 0x02, 0x02, 0x02},
  44                {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  45                 0x04, 0x04, 0x04, 0x04, 0x04, 0x04},
  46                {0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
  47                 0x08, 0x08, 0x08, 0x08, 0x08, 0x08},
  48                {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
  49                 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
  50                {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  51                 0x20, 0x20, 0x20, 0x20, 0x20, 0x20},
  52                {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
  53                 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
  54                {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
  55                 0x80, 0x80, 0x80, 0x80, 0x80, 0x80},
  56                {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  57                 0x55, 0x55, 0x55, 0x55, 0x55, 0x55},
  58                {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  59                 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa},
  60                {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  61                 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
  62        };
  63        const int foo[] = { 0 };
  64        int i, j, a;
  65
  66        printf ("\ntest @ %d %p\n", foo[0], buf);
  67        for (i = 0; i < 12; i++) {
  68                for (a = 0; a < 8; a++) {
  69                        const char *s = src[i] + a;
  70                        int align = (unsigned) (s) & 0x7;
  71
  72                        /* ecc_off(); */
  73                        memcpy (buf, s, 8);
  74                        /* ecc_on(); */
  75                        putshex (s, 8);
  76                        if (memcmp (buf, s, 8)) {
  77                                putc ('\n');
  78                                putshex (buf, 8);
  79                                printf (" [FAIL] (%p) align=%d\n", s, align);
  80                                for (j = 0; j < 8; j++) {
  81                                        s[j] == buf[j] ? puts ("  ") :
  82                                                printf ("%02x",
  83                                                        (s[j]) ^ (buf[j]));
  84                                }
  85                                putc ('\n');
  86                        } else {
  87                                printf (" [PASS] (%p) align=%d\n", s, align);
  88                        }
  89                        /* ecc_off(); */
  90                        char_memcpy (buf, s, 8);
  91                        /* ecc_on(); */
  92                        putshex (s, 8);
  93                        if (memcmp (buf, s, 8)) {
  94                                putc ('\n');
  95                                putshex (buf, 8);
  96                                printf (" [FAIL] (%p) align=%d\n", s, align);
  97                                for (j = 0; j < 8; j++) {
  98                                        s[j] == buf[j] ? puts ("  ") :
  99                                                printf ("%02x",
 100                                                        (s[j]) ^ (buf[j]));
 101                                }
 102                                putc ('\n');
 103                        } else {
 104                                printf (" [PASS] (%p) align=%d\n", s, align);
 105                        }
 106                }
 107        }
 108
 109        return 0;
 110}
 111#endif
 112