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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [flash/] [synth/] [current/] [tests/] [flash1.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 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 <cyg/io/flash.h>
58
#include <cyg/infra/testcase.h>
59
#include <cyg/infra/diag.h>
60
 
61
#include <string.h>
62
 
63
#ifndef CYGINT_ISO_STRING_STRFUNCS
64
# define NA_MSG "Need string functions for test"
65
#endif
66
#ifndef CYGSEM_IO_FLASH_LEGACY_API
67
# define NA_MSG "Need legacy IO FLASH API for test"
68
#endif
69
 
70
#ifdef NA_MSG
71
void cyg_user_start(void)
72
{
73
    CYG_TEST_INIT();
74
    CYG_TEST_NA( NA_MSG );
75
}
76
#else
77
 
78
//==========================================================================
79
// main
80
 
81
void cyg_user_start(void)
82
{
83
    int ret;
84
    char data[1024];
85
    void *flash_start, *flash_end;
86
    int block_size, blocks;
87
    char *prog_start;
88
    unsigned char * ptr;
89
 
90
    CYG_TEST_INIT();
91
 
92
    ret=flash_init((_printf *)diag_printf);
93
 
94
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_init");
95
 
96
    flash_dev_query(data);
97
    CYG_TEST_PASS_FAIL(!strncmp(data,"Linux Synthetic Flash",sizeof(data)),
98
                       "flash_query");
99
 
100
    ret = flash_get_limits(NULL,&flash_start,&flash_end);
101
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_limits");
102
 
103
    ret = flash_get_block_info(&block_size, &blocks);
104
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_block_info");
105
 
106
    /* Erase the whole flash. Not recommended on real hardware since this
107
     will probably erase the bootloader etc!!! */
108
    ret=flash_erase(flash_start,block_size * blocks,NULL);
109
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase1");
110
 
111
    /* check that its actually been erased, and test the mmap area */
112
    for (ptr=flash_start,ret=0; ptr < (unsigned char *)flash_end; ptr++) {
113
        if (*ptr != 0xff) {
114
            ret++;
115
        }
116
    }
117
 
118
    CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");
119
 
120
    ret = flash_program(flash_start,&copyright,sizeof(copyright),NULL);
121
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program1");
122
 
123
    /* Check the contents made it into the flash */
124
    CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)),
125
                       "flash program contents");
126
 
127
    /* .. and check nothing else changed */
128
    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
129
         ptr < (unsigned char *)flash_end; ptr++) {
130
        if (*ptr != 0xff) {
131
            ret++;
132
        }
133
    }
134
 
135
    CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");
136
 
137
    /* Program over a block boundary */
138
    prog_start = (char *)flash_start + block_size - sizeof(copyright)/2;
139
    ret = flash_program(prog_start,&copyright,sizeof(copyright),NULL);
140
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program2");
141
 
142
    /* Check the first version is still OK */
143
    CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)),
144
                       "Original contents");
145
 
146
    CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)),
147
                       "New program contents");
148
 
149
    /* Check the bit in between is still erased */
150
    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
151
         ptr < (unsigned char *)prog_start; ptr++) {
152
        if (*ptr != 0xff) {
153
            ret++;
154
        }
155
    }
156
    CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
157
 
158
    /* Erase the second block and make sure the first is not erased */
159
    ret=flash_erase((void *)((unsigned)flash_start+block_size),
160
                    block_size,NULL);
161
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase2");
162
 
163
    /* Check the erase worked */
164
    for (ptr=(unsigned char *)flash_start+block_size,ret=0;
165
         ptr < (unsigned char *)flash_start+block_size*2; ptr++) {
166
        if (*ptr != 0xff) {
167
            ret++;
168
        }
169
    }
170
 
171
    CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
172
 
173
    /* Lastly check the first half of the copyright message is still there */
174
    CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)/2),
175
                       "Block 1 OK");
176
 
177
#if 0
178
    /* This test it fatal! Its not run by default!
179
     Check the flash is read only, by trying to write to it. We expect
180
     to get an exception */
181
 
182
    *(char *)flash_start = 'a';
183
#endif
184
 
185
    CYG_TEST_PASS_FINISH("flash1");
186
}
187
 
188
#endif /* ifndef NA_MSG */
189
 
190
/* EOF flash1.c */

powered by: WebSVN 2.1.0

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