OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [flash/] [synthv2/] [current/] [tests/] [flash3.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/* Hay, the copyright is usefull for something! */
2
 
3
static char copyright[] =
4
"//=========================================================================="
5
"//"
6
"//      flash3.c"
7
"//"
8
"//      Test flash operations for the synth target synth flash driver"
9
"//"
10
"//=========================================================================="
11
"// ####ECOSGPLCOPYRIGHTBEGIN####                                          "
12
"// -------------------------------------------                            "
13
"// This file is part of eCos, the Embedded Configurable Operating System. "
14
"// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc. "
15
"//                                                                   "
16
"// eCos is free software; you can redistribute it and/or modify it under  "
17
"// the terms of the GNU General Public License as published by the Free   "
18
"// Software Foundation; either version 2 or (at your option) any later    "
19
"// version.                                                               "
20
"//                                                                   "
21
"// eCos is distributed in the hope that it will be useful, but WITHOUT    "
22
"// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or  "
23
"// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License  "
24
"// for more details.                                                      "
25
"//                                                                   "
26
"// You should have received a copy of the GNU General Public License      "
27
"// along with eCos; if not, write to the Free Software Foundation, Inc.,  "
28
"// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.          "
29
"//                                                                   "
30
"// As a special exception, if other files instantiate templates or use    "
31
"// macros or inline functions from this file, or you compile this file    "
32
"// and link it with other works to produce a work based on this file,     "
33
"// this file does not by itself cause the resulting work to be covered by "
34
"// the GNU General Public License. However the source code for this file  "
35
"// must still be made available in accordance with section (3) of the GNU "
36
"// General Public License v2.                                             "
37
"//                                                                   "
38
"// This exception does not invalidate any other reasons why a work based  "
39
"// on this file might be covered by the GNU General Public License.       "
40
"// -------------------------------------------                            "
41
"// ####ECOSGPLCOPYRIGHTEND####                                            "
42
"//=========================================================================="
43
"//#####DESCRIPTIONBEGIN####"
44
"//"
45
"// Author(s):           andrew.lunn@ascom.ch"
46
"// Contributors:        andrew.lunn"
47
"// Date:                2000-10-31"
48
"// Purpose:             Test a flash driver"
49
"// Description:         Try out a number of flash operations and make sure"
50
"//                      what is in the flash is what we expeect."
51
"//                      "
52
"//####DESCRIPTIONEND####"
53
"//"
54
"//==========================================================================&"
55
;
56
 
57
#include <pkgconf/system.h>
58
#ifdef CYGPKG_DEVS_FLASH_SYNTH_V2
59
#include <pkgconf/devs_flash_synth_v2.h>
60
#endif
61
#ifdef CYGPKG_DEVS_FLASH_SYNTH
62
#include <pkgconf/devs_flash_synth.h>
63
#endif
64
#include <cyg/io/flash.h>
65
#include <cyg/infra/testcase.h>
66
#include <cyg/infra/diag.h>
67
#include <cyg/flash/synth.h>
68
 
69
#include <string.h>
70
 
71
#ifndef CYGINT_ISO_STRING_STRFUNCS
72
# define NA_MSG "Need string functions for test"
73
#endif
74
 
75
#ifdef NA_MSG
76
void cyg_user_start(void)
77
{
78
    CYG_TEST_INIT();
79
    CYG_TEST_NA( NA_MSG );
80
}
81
#else
82
 
83
static struct cyg_flash_synth_priv synth_flash_priv3 = {
84
    .block_size         = CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE,
85
    .blocks             = CYGNUM_FLASH_SYNTH_V2_NUMBLOCKS,
86
    .boot_block_size    = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCKSIZE,
87
    .boot_blocks        = CYGNUM_FLASH_SYNTH_V2_NUMBOOT_BLOCKS,
88
    .boot_block_bottom  = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCK_BOTTOM,
89
    .filename           = "synth.flash3",
90
    .flashfd            = -1
91
};
92
 
93
CYG_FLASH_DRIVER(cyg_flash_synth_flashdev_flash3,
94
                 &cyg_flash_synth_funs,
95
                 0,             // flags
96
                 0x40020000,    // start
97
                 0,             // end, filled in by init
98
                 0,             // number of block_info's, filled in by init
99
                 synth_flash_priv3.block_info,
100
                 &synth_flash_priv3);
101
 
102
//==========================================================================
103
// main
104
 
105
void cyg_user_start(void)
106
{
107
    int ret;
108
    cyg_flashaddr_t flash_start=0, flash_end=0;
109
    cyg_flash_info_t info;
110
    cyg_uint32 i=0;
111
    cyg_uint32 j;
112
    int block_size=0, blocks=0;
113
    cyg_flashaddr_t prog_start;
114
    unsigned char * ptr;
115
    size_t copyright_len;
116
 
117
    CYG_TEST_INIT();
118
 
119
    // Reference the flash dev so the linker does not throw it away
120
    CYG_REFERENCE_OBJECT(cyg_flash_synth_flashdev_flash3);
121
 
122
    cyg_flash_set_global_printf((cyg_flash_printf *)&diag_printf);
123
    ret=cyg_flash_init(NULL);
124
 
125
    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_init");
126
 
127
    do {
128
      ret = cyg_flash_get_info(i, &info);
129
      if (ret == CYG_FLASH_ERR_OK) {
130
        diag_printf("INFO: Nth=%d, start=%p, end=%p\n",
131
                    i, (void *) info.start, (void *) info.end);
132
        if (i == 0) {
133
          flash_start = info.start;
134
          flash_end = info.end;
135
          block_size = info.block_info[0].block_size;
136
          blocks = info.block_info[0].blocks;
137
        }
138
 
139
        for (j=0;j < info.num_block_infos; j++) {
140
          diag_printf("INFO:\t block_size %zd, blocks %u\n",
141
                      info.block_info[j].block_size,
142
                      info.block_info[j].blocks);
143
        }
144
      }
145
      i++;
146
    } while (ret != CYG_FLASH_ERR_INVALID);
147
 
148
    /* Erase the whole flash. Not recommended on real hardware since this
149
     will probably erase the bootloader etc!!! */
150
    ret=cyg_flash_erase(flash_start,block_size * blocks,NULL);
151
    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase1");
152
 
153
    /* check that its actually been erased, and test the mmap area */
154
    for (ptr=(unsigned char *)flash_start,ret=0;
155
         ptr <= (unsigned char *)flash_end; ptr++) {
156
        if (*ptr != 0xff) {
157
            ret++;
158
        }
159
    }
160
 
161
    CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");
162
 
163
    // With small blocks we have to use less of the copyright messages
164
    // Since we make assumptions about fitting the message into a
165
    // block.
166
    if (block_size < sizeof(copyright)*2/3) {
167
      copyright_len = block_size / 3;
168
    } else {
169
      copyright_len = sizeof(copyright);
170
    }
171
 
172
    ret = cyg_flash_program(flash_start,&copyright,copyright_len,NULL);
173
    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program1");
174
 
175
    /* Check the contents made it into the flash */
176
    CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
177
                                copyright,copyright_len),
178
                       "flash program contents");
179
 
180
    /* .. and check nothing else changed */
181
    for (ptr=(unsigned char *)flash_start+copyright_len,ret=0;
182
         ptr < (unsigned char *)flash_end; ptr++) {
183
        if (*ptr != 0xff) {
184
            ret++;
185
        }
186
    }
187
 
188
    CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");
189
 
190
    prog_start = flash_start + block_size - copyright_len/2;
191
    ret = cyg_flash_program(prog_start,&copyright,copyright_len,NULL);
192
    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program2");
193
 
194
    /* Check the first version is still OK */
195
    CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
196
                                copyright,
197
                                copyright_len),
198
                       "Original contents");
199
 
200
    CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
201
                                copyright,
202
                                copyright_len),
203
                       "New program contents");
204
 
205
    /* Check the bit in between is still erased */
206
    for (ptr=(unsigned char *)flash_start+copyright_len,ret=0;
207
         ptr < (unsigned char *)prog_start; ptr++) {
208
        if (*ptr != 0xff) {
209
            ret++;
210
        }
211
    }
212
    CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
213
 
214
    /* Erase the second block and make sure the first is not erased */
215
    ret=cyg_flash_erase(flash_start+block_size,block_size,NULL);
216
    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase2");
217
 
218
    /* Check the erase worked */
219
    for (ptr=(unsigned char *)flash_start+block_size,ret=0;
220
         ptr < (unsigned char *)flash_start+block_size*2;
221
         ptr++) {
222
        if (*ptr != 0xff) {
223
            ret++;
224
        }
225
    }
226
 
227
    CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
228
 
229
    /* Lastly check the first half of the copyright message is still there */
230
    CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
231
                                copyright,
232
                                copyright_len/2),
233
                       "Block 1 OK");
234
 
235
#if 0
236
    /* This test is be fatal! Its not run by default!
237
     Check the flash is read only, by trying to write to it. We expect
238
     to get an exception */
239
 
240
    *(char *)flash_start = 'a';
241
#endif
242
 
243
    CYG_TEST_PASS_FINISH("flash3");
244
}
245
 
246
#endif /* ifndef NA_MSG */
247
 
248
/* EOF flash3.c */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.