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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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