|
3017
|
1 //============================================================================= |
|
|
2 // |
|
|
3 // eccequiv.c |
|
|
4 // |
|
|
5 // Given two software ECC algorithms, confirms their equivalence. |
|
|
6 // |
|
|
7 //============================================================================= |
|
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
|
9 // ------------------------------------------- |
|
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
|
11 // Copyright (C) 2009 eCosCentric Limited. |
|
|
12 // |
|
|
13 // eCos is free software; you can redistribute it and/or modify it under |
|
|
14 // the terms of the GNU General Public License as published by the Free |
|
|
15 // Software Foundation; either version 2 or (at your option) any later |
|
|
16 // version. |
|
|
17 // |
|
|
18 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
|
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
|
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
|
21 // for more details. |
|
|
22 // |
|
|
23 // You should have received a copy of the GNU General Public License |
|
|
24 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
|
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
|
26 // |
|
|
27 // As a special exception, if other files instantiate templates or use |
|
|
28 // macros or inline functions from this file, or you compile this file |
|
|
29 // and link it with other works to produce a work based on this file, |
|
|
30 // this file does not by itself cause the resulting work to be covered by |
|
|
31 // the GNU General Public License. However the source code for this file |
|
|
32 // must still be made available in accordance with section (3) of the GNU |
|
|
33 // General Public License v2. |
|
|
34 // |
|
|
35 // This exception does not invalidate any other reasons why a work based |
|
|
36 // on this file might be covered by the GNU General Public License. |
|
|
37 // ------------------------------------------- |
|
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
|
|
39 //============================================================================= |
|
|
40 //#####DESCRIPTIONBEGIN#### |
|
|
41 // |
|
|
42 // Author(s): wry |
|
|
43 // Date: 2009-11-06 |
|
|
44 // |
|
|
45 //####DESCRIPTIONEND#### |
|
|
46 //============================================================================= |
|
|
47 |
|
|
48 #include <cyg/infra/cyg_ass.h> |
|
|
49 #include <cyg/infra/testcase.h> |
|
|
50 #include <cyg/nand/nand.h> |
|
|
51 #include <cyg/nand/nand_devtab.h> |
|
|
52 #include <cyg/nand/util.h> |
|
|
53 #include <cyg/infra/diag.h> |
|
|
54 #include <stdio.h> |
|
|
55 #include <string.h> |
|
|
56 #include "ar4prng.inl" |
|
|
57 |
|
|
58 #define MUST(what) do { CYG_TEST_CHECK((what), #what); } while(0) |
|
|
59 |
|
|
60 __externC cyg_nand_ecc_t linux_mtd_ecc; |
|
|
61 |
|
|
62 static CYG_NAND_DEVICE(fakenand, 0, 0, 0, &linux_mtd_ecc, 0); |
|
|
63 static CYG_NAND_DEVICE(fakenand2, 0, 0, 0, &mtd_ecc256_fast, 0); |
|
|
64 |
|
|
65 void init_fakenand(void) |
|
|
66 { |
|
|
67 if (fakenand.is_inited) |
|
|
68 return; |
|
|
69 |
|
|
70 fakenand.is_inited = 1; |
|
|
71 fakenand.pf = diag_printf; |
|
|
72 fakenand.page_bits = 11; // 2048 byte test pattern. |
|
|
73 fakenand.oob = &nand_mtd_oob_64; |
|
|
74 |
|
|
75 fakenand2.is_inited = 1; |
|
|
76 fakenand2.pf = diag_printf; |
|
|
77 fakenand2.page_bits = 11; // 2048 byte test pattern. |
|
|
78 fakenand2.oob = &nand_mtd_oob_64; |
|
|
79 } |
|
|
80 |
|
|
81 |
|
|
82 void ecc(cyg_nand_device *dev, const CYG_BYTE *data, CYG_BYTE *out) |
|
|
83 { |
|
|
84 if (dev->ecc->init) |
|
|
85 dev->ecc->init(dev); |
|
|
86 dev->ecc->calc_wr(dev, data, out); |
|
|
87 } |
|
|
88 |
|
|
89 const char msg[]="ECC equivalence check"; |
|
|
90 |
|
|
91 #define ECC_BUFFER_SIZE 10 |
|
|
92 CYG_BYTE buf[CYGNUM_NAND_PAGEBUFFER]; |
|
|
93 CYG_BYTE ecc1[ECC_BUFFER_SIZE], ecc2[ECC_BUFFER_SIZE]; |
|
|
94 |
|
|
95 ar4ctx rng; |
|
|
96 extern unsigned char _stext[], _etext[]; |
|
|
97 |
|
|
98 int cyg_user_start(void) |
|
|
99 { |
|
|
100 cyg_nand_device *dev = &fakenand, *dev2 = &fakenand2; |
|
|
101 int i, fails=0; |
|
|
102 |
|
|
103 CYG_TEST_INIT(); |
|
|
104 CYG_TEST_INFO(msg); |
|
|
105 |
|
|
106 #define datasize (fakenand.ecc->data_size) |
|
|
107 #define eccsize (fakenand.ecc->ecc_size) |
|
|
108 |
|
|
109 CYG_ASSERTC(fakenand.ecc->data_size == fakenand2.ecc->data_size); |
|
|
110 CYG_ASSERTC(fakenand.ecc->ecc_size == fakenand2.ecc->ecc_size); |
|
|
111 |
|
|
112 CYG_ASSERTC(datasize <= CYGNUM_NAND_PAGEBUFFER); |
|
|
113 CYG_ASSERTC(eccsize <= ECC_BUFFER_SIZE); |
|
|
114 |
|
|
115 diag_printf("ECC sizes: data %d, ecc %d\n", datasize, eccsize); |
|
|
116 |
|
|
117 ar4prng_init(&rng,_stext, _etext-_stext); |
|
|
118 |
|
|
119 #define N_RUNS 10000 |
|
|
120 |
|
|
121 for (i=0; i<N_RUNS; i++) { |
|
|
122 ar4prng_many(&rng, buf, datasize); |
|
|
123 ecc(dev, buf, ecc1); |
|
|
124 ecc(dev2, buf, ecc2); |
|
|
125 if (0 != memcmp(ecc1, ecc2, eccsize)) { |
|
|
126 ++fails; |
|
|
127 } |
|
|
128 } |
|
|
129 |
|
|
130 if (fails) { |
|
|
131 diag_printf("FAIL: %d mismatches\n", fails); |
|
|
132 CYG_TEST_FAIL_FINISH(msg); |
|
|
133 } else |
|
|
134 CYG_TEST_PASS_FINISH(msg); |
|
|
135 } |
|
|
136 |