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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [devs/] [flash/] [synth/] [v2_0/] [tests/] [flash1.c] - Blame information for rev 565

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/* Hay, the copyright is usefull 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 Red Hat, 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 version.
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23
// for more details.
24
//
25
// You should have received a copy of the GNU General Public License along
26
// with eCos; if not, write to the Free Software Foundation, Inc.,
27
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28
//
29
// As a special exception, if other files instantiate templates or use macros
30
// or inline functions from this file, or you compile this file and link it
31
// with other works to produce a work based on this file, this file does not
32
// by itself cause the resulting work to be covered by the GNU General Public
33
// License. However the source code for this file must still be made available
34
// in accordance with section (3) of the GNU General Public License.
35
//
36
// This exception does not invalidate any other reasons why a work based on
37
// this file might be covered by the GNU General Public License.
38
//
39
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40
// at http://sources.redhat.com/ecos/ecos-license/
41
// -------------------------------------------
42
//####ECOSGPLCOPYRIGHTEND####
43
//==========================================================================
44
//#####DESCRIPTIONBEGIN####
45
//
46
// Author(s):           andrew.lunn@ascom.ch
47
// Contributors:        andrew.lunn
48
// Date:                2000-10-31
49
// Purpose:             Test a flash driver
50
// Description:         Try out a number of flash operations and make sure
51
//                      what is in the flash is what we expeect.
52
//
53
//####DESCRIPTIONEND####
54
//
55
//==========================================================================
56
";
57
 
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
    char data[1024];
83
    void *flash_start, *flash_end;
84
    int block_size, blocks;
85
    char *prog_start;
86
    unsigned char * ptr;
87
 
88
    CYG_TEST_INIT();
89
 
90
    ret=flash_init(NULL,0,(_printf *)diag_printf);
91
 
92
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_init");
93
 
94
    flash_dev_query(data);
95
    CYG_TEST_PASS_FAIL(!strncmp(data,"Linux Synthetic Flash",sizeof(data)),
96
                       "flash_query");
97
 
98
    ret = flash_get_limits(NULL,&flash_start,&flash_end);
99
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_limits");
100
 
101
    ret = flash_get_block_info(&block_size, &blocks);
102
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_block_info");
103
 
104
    /* Erase the whole flash. Not recommended on real hardware since this
105
     will probably erase the bootloader etc!!! */
106
    ret=flash_erase(flash_start,block_size * blocks,NULL);
107
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase1");
108
 
109
    /* check that its actually been erased, and test the mmap area */
110
    for (ptr=flash_start,ret=0; ptr < (unsigned char *)flash_end; ptr++) {
111
        if (*ptr != 0xff) {
112
            ret++;
113
        }
114
    }
115
 
116
    CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");
117
 
118
    ret = flash_program(flash_start,&copyright,sizeof(copyright),NULL);
119
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program1");
120
 
121
    /* Check the contents made it into the flash */
122
    CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)),
123
                       "flash program contents");
124
 
125
    /* .. and check nothing else changed */
126
    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
127
         ptr < (unsigned char *)flash_end; ptr++) {
128
        if (*ptr != 0xff) {
129
            ret++;
130
        }
131
    }
132
 
133
    CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");
134
 
135
    /* Program over a block boundary */
136
    prog_start = (unsigned char *)flash_start + block_size - sizeof(copyright)/2;
137
    ret = flash_program(prog_start,&copyright,sizeof(copyright),NULL);
138
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program2");
139
 
140
    /* Check the first version is still OK */
141
    CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)),
142
                       "Original contents");
143
 
144
    CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)),
145
                       "New program contents");
146
 
147
    /* Check the bit in between is still erased */
148
    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
149
         ptr < (unsigned char *)prog_start; ptr++) {
150
        if (*ptr != 0xff) {
151
            ret++;
152
        }
153
    }
154
    CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
155
 
156
    /* Erase the second block and make sure the first is not erased */
157
    ret=flash_erase((void *)((unsigned)flash_start+block_size),
158
                    block_size,NULL);
159
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase2");
160
 
161
    /* Check the erase worked */
162
    for (ptr=(unsigned char *)flash_start+block_size,ret=0;
163
         ptr < (unsigned char *)flash_start+block_size*2; ptr++) {
164
        if (*ptr != 0xff) {
165
            ret++;
166
        }
167
    }
168
 
169
    CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
170
 
171
    /* Lastly check the first half of the copyright message is still there */
172
    CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)/2),
173
                       "Block 1 OK");
174
 
175
#if 0
176
    /* This test it fatal! Its not run by default!
177
     Check the flash is read only, by trying to write to it. We expect
178
     to get an exception */
179
 
180
    *(char *)flash_start = 'a';
181
#endif
182
 
183
    CYG_TEST_PASS_FINISH("flash1");
184
}
185
 
186
#endif /* ifndef NA_MSG */
187
 
188
/* EOF flash1.c */

powered by: WebSVN 2.1.0

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