1 |
786 |
skrzyp |
//=================================================================
|
2 |
|
|
//
|
3 |
|
|
// flash1.c
|
4 |
|
|
//
|
5 |
|
|
// Simple tests for FLASH drivers
|
6 |
|
|
//
|
7 |
|
|
//=================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
|
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): gthomas
|
43 |
|
|
// Contributors:
|
44 |
|
|
// Date: 2004-04-24
|
45 |
|
|
// Description: Simple test of FLASH I/O.
|
46 |
|
|
//
|
47 |
|
|
// Options:
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
|
50 |
|
|
// #define DEBUG_PRINTFS
|
51 |
|
|
|
52 |
|
|
#include <pkgconf/hal.h>
|
53 |
|
|
#include <pkgconf/io_flash.h>
|
54 |
|
|
#include CYGHWR_MEMORY_LAYOUT_H
|
55 |
|
|
|
56 |
|
|
#include <cyg/infra/diag.h>
|
57 |
|
|
#include <cyg/infra/testcase.h>
|
58 |
|
|
|
59 |
|
|
#include <cyg/io/flash.h>
|
60 |
|
|
#include <cyg/hal/hal_if.h>
|
61 |
|
|
|
62 |
|
|
#ifndef CYGSEM_IO_FLASH_LEGACY_API
|
63 |
|
|
externC void
|
64 |
|
|
cyg_start( void )
|
65 |
|
|
{
|
66 |
|
|
CYG_TEST_INIT();
|
67 |
|
|
CYG_TEST_NA("Only usable with legacy API");
|
68 |
|
|
}
|
69 |
|
|
#else
|
70 |
|
|
externC void
|
71 |
|
|
cyg_start( void )
|
72 |
|
|
{
|
73 |
|
|
int stat;
|
74 |
|
|
void *err_addr;
|
75 |
|
|
CYG_ADDRWORD flash_start, flash_end;
|
76 |
|
|
void **flash_start_addr = (void *)&flash_start;
|
77 |
|
|
void **flash_end_addr = (void *)&flash_end;
|
78 |
|
|
void *flash_test_start, *flash_addr;
|
79 |
|
|
cyg_int32 flash_block_size, flash_num_blocks;
|
80 |
|
|
CYG_ADDRWORD test_buf1, test_buf2;
|
81 |
|
|
cyg_uint32 *lp1, *lp2;
|
82 |
|
|
int i, len;
|
83 |
|
|
cyg_bool passed, ok;
|
84 |
|
|
|
85 |
|
|
CYG_TEST_INIT();
|
86 |
|
|
|
87 |
|
|
#if 0
|
88 |
|
|
int j;
|
89 |
|
|
|
90 |
|
|
diag_printf("Testing udelay: ");
|
91 |
|
|
for (i = 0; i < 30; i++) {
|
92 |
|
|
for (j = 0; j < 1000; j++) {
|
93 |
|
|
CYGACC_CALL_IF_DELAY_US(1000); // Should be 1 second
|
94 |
|
|
}
|
95 |
|
|
diag_printf(".");
|
96 |
|
|
}
|
97 |
|
|
diag_printf("\n");
|
98 |
|
|
#endif
|
99 |
|
|
|
100 |
|
|
passed = true;
|
101 |
|
|
|
102 |
|
|
if ((stat = flash_init(diag_printf)) != 0) {
|
103 |
|
|
diag_printf("FLASH: driver init failed: %s\n", flash_errmsg(stat));
|
104 |
|
|
CYG_TEST_FAIL_FINISH("FLASH driver init failed");
|
105 |
|
|
}
|
106 |
|
|
flash_get_limits((void *)0, flash_start_addr, flash_end_addr);
|
107 |
|
|
// Keep 'end' address as last valid location, to avoid wrap around problems
|
108 |
|
|
flash_end = flash_end - 1;
|
109 |
|
|
flash_get_block_info(&flash_block_size, &flash_num_blocks);
|
110 |
|
|
|
111 |
|
|
diag_printf("FLASH: 0x%x - 0x%x, %d blocks of 0x%x bytes each.\n",
|
112 |
|
|
flash_start, flash_end + 1, flash_num_blocks,
|
113 |
|
|
flash_block_size);
|
114 |
|
|
|
115 |
|
|
// Verify that the testing limits are within the bounds of the
|
116 |
|
|
// physical device. Also verify that the size matches with
|
117 |
|
|
// the erase block size on the device
|
118 |
|
|
if ((CYGNUM_IO_FLASH_TEST_OFFSET > (flash_end - flash_start)) ||
|
119 |
|
|
((CYGNUM_IO_FLASH_TEST_OFFSET + CYGNUM_IO_FLASH_TEST_LENGTH) > (flash_end - flash_start))) {
|
120 |
|
|
CYG_TEST_FAIL_FINISH("FLASH test region outside physical limits");
|
121 |
|
|
}
|
122 |
|
|
if ((CYGNUM_IO_FLASH_TEST_LENGTH % flash_block_size) != 0) {
|
123 |
|
|
CYG_TEST_FAIL_FINISH("FLASH test region must be integral multiple of erase block size");
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
// Allocate two buffers large enough for the test
|
127 |
|
|
test_buf1 = (CYG_ADDRWORD)CYGMEM_SECTION_heap1;
|
128 |
|
|
test_buf2 = test_buf1 + CYGNUM_IO_FLASH_TEST_LENGTH;
|
129 |
|
|
if (CYGMEM_SECTION_heap1_SIZE < (CYGNUM_IO_FLASH_TEST_LENGTH * 2)) {
|
130 |
|
|
CYG_TEST_FAIL_FINISH("FLASH not enough heap space - reduce size of test region");
|
131 |
|
|
}
|
132 |
|
|
diag_printf("... Using test buffers at %p and %p\n", (void *)test_buf1, (void *)test_buf2);
|
133 |
|
|
flash_test_start = (void *)(flash_start + CYGNUM_IO_FLASH_TEST_OFFSET);
|
134 |
|
|
|
135 |
|
|
#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
|
136 |
|
|
// Unlock test
|
137 |
|
|
diag_printf("... Unlock test\n");
|
138 |
|
|
ok = true;
|
139 |
|
|
if ((stat = flash_unlock(flash_test_start,
|
140 |
|
|
CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
|
141 |
|
|
diag_printf("FLASH: unlock failed: %s\n", flash_errmsg(stat));
|
142 |
|
|
ok = false;
|
143 |
|
|
}
|
144 |
|
|
#endif
|
145 |
|
|
|
146 |
|
|
// Erase test
|
147 |
|
|
diag_printf("... Erase test\n");
|
148 |
|
|
ok = true;
|
149 |
|
|
if ((stat = flash_erase(flash_test_start,
|
150 |
|
|
CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
|
151 |
|
|
diag_printf("FLASH: erase failed: %s\n", flash_errmsg(stat));
|
152 |
|
|
ok = false;
|
153 |
|
|
}
|
154 |
|
|
if (ok && (stat = flash_read(flash_test_start, (void *)test_buf1,
|
155 |
|
|
CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
|
156 |
|
|
diag_printf("FLASH: read/verify after erase failed: %s\n", flash_errmsg(stat));
|
157 |
|
|
ok = false;
|
158 |
|
|
}
|
159 |
|
|
lp1 = (cyg_uint32 *)test_buf1;
|
160 |
|
|
for (i = 0; i < CYGNUM_IO_FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) {
|
161 |
|
|
if (*lp1++ != 0xFFFFFFFF) {
|
162 |
|
|
diag_printf("FLASH: non-erased data found at offset %x\n", (CYG_ADDRWORD)(lp1-1) - test_buf1);
|
163 |
|
|
diag_dump_buf((void *)(lp1-1), 32);
|
164 |
|
|
ok = false;
|
165 |
|
|
break;
|
166 |
|
|
}
|
167 |
|
|
}
|
168 |
|
|
// Try reading in little pieces
|
169 |
|
|
len = CYGNUM_IO_FLASH_TEST_LENGTH;
|
170 |
|
|
flash_addr = flash_test_start;
|
171 |
|
|
while (len > 0) {
|
172 |
|
|
if ((stat = flash_read(flash_addr, (void *)test_buf1, 0x200, &err_addr)) != CYG_FLASH_ERR_OK) {
|
173 |
|
|
diag_printf("FLASH: read[short]/verify after erase failed: %s\n", flash_errmsg(stat));
|
174 |
|
|
ok = false;
|
175 |
|
|
break;
|
176 |
|
|
}
|
177 |
|
|
flash_addr = (cyg_uint8 *)flash_addr + 0x200;
|
178 |
|
|
len -= 0x200;
|
179 |
|
|
lp1 = (cyg_uint32 *)test_buf1;
|
180 |
|
|
for (i = 0; i < 0x200; i += sizeof(cyg_uint32)) {
|
181 |
|
|
if (*lp1++ != 0xFFFFFFFF) {
|
182 |
|
|
diag_printf("FLASH: non-erased data found at offset %p\n",
|
183 |
|
|
(cyg_uint8 *)flash_addr + (CYG_ADDRWORD)((lp1-1) - test_buf1));
|
184 |
|
|
diag_dump_buf((void *)(lp1-1), 32);
|
185 |
|
|
ok = false;
|
186 |
|
|
len = 0;
|
187 |
|
|
break;
|
188 |
|
|
}
|
189 |
|
|
}
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
if (!ok) {
|
193 |
|
|
CYG_TEST_INFO("FLASH erase failed");
|
194 |
|
|
passed = false;
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
// Simple write/verify test
|
198 |
|
|
diag_printf("... Write/verify test\n");
|
199 |
|
|
lp1 = (cyg_uint32 *)test_buf1;
|
200 |
|
|
for (i = 0; i < CYGNUM_IO_FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) {
|
201 |
|
|
*lp1 = (cyg_uint32)lp1;
|
202 |
|
|
lp1++;
|
203 |
|
|
}
|
204 |
|
|
ok = true;
|
205 |
|
|
if (ok && (stat = flash_program(flash_test_start, (void *)test_buf1,
|
206 |
|
|
CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
|
207 |
|
|
diag_printf("FLASH: write failed: %s\n", flash_errmsg(stat));
|
208 |
|
|
ok = false;
|
209 |
|
|
}
|
210 |
|
|
if (ok && (stat = flash_read(flash_test_start, (void *)test_buf2,
|
211 |
|
|
CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
|
212 |
|
|
diag_printf("FLASH: read/verify after write failed: %s\n", flash_errmsg(stat));
|
213 |
|
|
ok = false;
|
214 |
|
|
}
|
215 |
|
|
lp1 = (cyg_uint32 *)test_buf1;
|
216 |
|
|
lp2 = (cyg_uint32 *)test_buf2;
|
217 |
|
|
for (i = 0; i < CYGNUM_IO_FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) {
|
218 |
|
|
if (*lp2++ != *lp1++) {
|
219 |
|
|
diag_printf("FLASH: incorrect data found at offset %x\n", (CYG_ADDRWORD)(lp2-1) - test_buf2);
|
220 |
|
|
diag_dump_buf((void *)(lp2-1), 32);
|
221 |
|
|
ok = false;
|
222 |
|
|
break;
|
223 |
|
|
}
|
224 |
|
|
}
|
225 |
|
|
// Try reading in little pieces
|
226 |
|
|
len = CYGNUM_IO_FLASH_TEST_LENGTH;
|
227 |
|
|
flash_addr = flash_test_start;
|
228 |
|
|
lp1 = (cyg_uint32 *)test_buf1;
|
229 |
|
|
lp2 = (cyg_uint32 *)test_buf2;
|
230 |
|
|
while (len > 0) {
|
231 |
|
|
if ((stat = flash_read(flash_addr, lp2, 0x200, &err_addr)) != CYG_FLASH_ERR_OK) {
|
232 |
|
|
diag_printf("FLASH: read[short]/verify after erase failed: %s\n", flash_errmsg(stat));
|
233 |
|
|
ok = false;
|
234 |
|
|
break;
|
235 |
|
|
}
|
236 |
|
|
flash_addr = (cyg_uint8 *)flash_addr + 0x200;
|
237 |
|
|
len -= 0x200;
|
238 |
|
|
for (i = 0; i < 0x200; i += sizeof(cyg_uint32)) {
|
239 |
|
|
if (*lp2++ != *lp1++) {
|
240 |
|
|
diag_printf("FLASH: incorrect data found at offset %p\n",
|
241 |
|
|
(cyg_uint8 *)flash_addr + (CYG_ADDRWORD)((lp2-1) - test_buf2));
|
242 |
|
|
diag_dump_buf((void *)(lp2-1), 32);
|
243 |
|
|
ok = false;
|
244 |
|
|
len = 0;
|
245 |
|
|
break;
|
246 |
|
|
}
|
247 |
|
|
}
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
if (!ok) {
|
251 |
|
|
CYG_TEST_INFO("FLASH write/verify failed");
|
252 |
|
|
}
|
253 |
|
|
|
254 |
|
|
#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
|
255 |
|
|
// Lock test
|
256 |
|
|
diag_printf("... Lock test\n");
|
257 |
|
|
ok = true;
|
258 |
|
|
if ((stat = flash_lock(flash_test_start,
|
259 |
|
|
CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
|
260 |
|
|
diag_printf("FLASH: unlock failed: %s\n", flash_errmsg(stat));
|
261 |
|
|
ok = false;
|
262 |
|
|
}
|
263 |
|
|
#endif
|
264 |
|
|
|
265 |
|
|
if (passed) {
|
266 |
|
|
CYG_TEST_PASS_FINISH("FLASH test1");
|
267 |
|
|
} else {
|
268 |
|
|
CYG_TEST_FAIL_FINISH("FLASH test1");
|
269 |
|
|
}
|
270 |
|
|
}
|
271 |
|
|
#endif
|
272 |
|
|
|
273 |
|
|
// EOF flash1.c
|