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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [flash/] [synthv2/] [current/] [tests/] [flash2.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
"//      flash2.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
 
68
#include <string.h>
69
 
70
#ifndef CYGINT_ISO_STRING_STRFUNCS
71
# define NA_MSG "Need string functions for test"
72
#endif
73
 
74
#ifdef NA_MSG
75
void cyg_user_start(void)
76
{
77
    CYG_TEST_INIT();
78
    CYG_TEST_NA( NA_MSG );
79
}
80
#else
81
 
82
//==========================================================================
83
// main
84
 
85
void cyg_user_start(void)
86
{
87
    int ret;
88
    cyg_flashaddr_t flash_start=0, flash_end=0;
89
    cyg_flash_info_t info;
90
    cyg_uint32 i=0;
91
    cyg_uint32 j;
92
    int block_size=0, blocks=0;
93
    cyg_flashaddr_t prog_start;
94
    unsigned char * ptr;
95
 
96
    CYG_TEST_INIT();
97
 
98
    cyg_flash_set_global_printf((cyg_flash_printf *)&diag_printf);
99
    ret=cyg_flash_init(NULL);
100
 
101
    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_init");
102
 
103
    do {
104
      ret = cyg_flash_get_info(i, &info);
105
      if (ret == CYG_FLASH_ERR_OK) {
106
        diag_printf("INFO: Nth=%d, start=%p, end=%p\n",
107
                    i, (void *) info.start, (void *) info.end);
108
        if (i == 0) {
109
          flash_start = info.start;
110
          flash_end = info.end;
111
          block_size = info.block_info[0].block_size;
112
          blocks = info.block_info[0].blocks;
113
        }
114
        for (j=0;j < info.num_block_infos; j++) {
115
          diag_printf("INFO:\t block_size %zd, blocks %u\n",
116
                      info.block_info[j].block_size,
117
                      info.block_info[j].blocks);
118
        }
119
      }
120
      i++;
121
    } while (ret != CYG_FLASH_ERR_INVALID);
122
 
123
    /* Erase the whole flash. Not recommended on real hardware since this
124
     will probably erase the bootloader etc!!! */
125
    ret=cyg_flash_erase(flash_start,block_size * blocks,NULL);
126
    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase1");
127
 
128
    /* check that its actually been erased, and test the mmap area */
129
    for (ptr=(unsigned char *)flash_start,ret=0;
130
         ptr <= (unsigned char *)flash_end; ptr++) {
131
        if (*ptr != 0xff) {
132
            ret++;
133
        }
134
    }
135
 
136
    CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");
137
 
138
    ret = cyg_flash_program(flash_start,&copyright,sizeof(copyright),NULL);
139
    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program1");
140
 
141
    /* Check the contents made it into the flash */
142
    CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
143
                                copyright,sizeof(copyright)),
144
                       "flash program contents");
145
 
146
    /* .. and check nothing else changed */
147
    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
148
         ptr < (unsigned char *)flash_end; ptr++) {
149
        if (*ptr != 0xff) {
150
            ret++;
151
        }
152
    }
153
 
154
    CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");
155
 
156
    /* Program over a block boundary */
157
    prog_start = flash_start + block_size - sizeof(copyright)/2;
158
    ret = cyg_flash_program(prog_start,&copyright,sizeof(copyright),NULL);
159
    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program2");
160
 
161
    /* Check the first version is still OK */
162
    CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
163
                                copyright,
164
                                sizeof(copyright)),
165
                       "Original contents");
166
 
167
    CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
168
                                copyright,
169
                                sizeof(copyright)),
170
                       "New program contents");
171
 
172
    /* Check the bit in between is still erased */
173
    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
174
         ptr < (unsigned char *)prog_start; ptr++) {
175
        if (*ptr != 0xff) {
176
            ret++;
177
        }
178
    }
179
    CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
180
 
181
    /* Erase the second block and make sure the first is not erased */
182
    ret=cyg_flash_erase(flash_start+block_size,block_size,NULL);
183
    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase2");
184
 
185
    /* Check the erase worked */
186
    for (ptr=(unsigned char *)flash_start+block_size,ret=0;
187
         ptr < (unsigned char *)flash_start+block_size*2;
188
         ptr++) {
189
        if (*ptr != 0xff) {
190
            ret++;
191
        }
192
    }
193
 
194
    CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
195
 
196
    /* Lastly check the first half of the copyright message is still there */
197
    CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
198
                                copyright,
199
                                sizeof(copyright)/2),
200
                       "Block 1 OK");
201
 
202
#if 0
203
    /* This test is be fatal! Its not run by default!
204
     Check the flash is read only, by trying to write to it. We expect
205
     to get an exception */
206
 
207
    *(char *)flash_start = 'a';
208
#endif
209
 
210
    CYG_TEST_PASS_FINISH("flash2");
211
}
212
 
213
#endif /* ifndef NA_MSG */
214
 
215
/* EOF flash2.c */

powered by: WebSVN 2.1.0

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