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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [flash/] [intel/] [strata/] [current/] [src/] [strata.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      strata.c
4
//
5
//      Flash programming
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    gthomas, hmt
43
// Contributors: gthomas
44
// Date:         2001-02-14
45
// Purpose:      
46
// Description:  
47
//              
48
//####DESCRIPTIONEND####
49
//
50
//==========================================================================
51
 
52
#include <pkgconf/system.h>
53
#include <pkgconf/hal.h>
54
#include <cyg/hal/hal_arch.h>
55
 
56
#include <cyg/io/flash.h>
57
 
58
#include "strata.h"
59
 
60
#define _si(p) ((p[1]<<8)|p[0])
61
 
62
extern void diag_dump_buf(void *buf, CYG_ADDRWORD len);
63
 
64
extern int strncmp(const char *s1, const char *s2, size_t len);
65
extern void *memcpy( void *, const void *, size_t );
66
 
67
int
68
flash_hwr_init(void)
69
{
70
    struct FLASH_query data, *qp;
71
    int num_regions, region_size, buffer_size;
72
 
73
    flash_dev_query(&data);
74
    qp = &data;
75
    if ( ((qp->manuf_code == FLASH_Intel_code) ||
76
          (qp->manuf_code == FLASH_STMicro_code))
77
#ifdef CYGOPT_FLASH_IS_BOOTBLOCK
78
         // device types go as follows: 0x90 for 16-bits, 0xD0 for 8-bits,
79
         // plus 0 or 1 for -T (Top Boot) or -B (Bottom Boot)
80
         //     [FIXME: whatever that means :FIXME]
81
         // [I think it means the boot blocks are top/bottom of addr space]
82
         // plus the following size codes:
83
         //    0: 16Mbit    2:  8Mbit    4:  4Mbit
84
         //    6: 32Mbit    8: 64Mbit
85
#if 16 == CYGNUM_FLASH_WIDTH         
86
         && (0x90 == (0xF0 & qp->device_code)) // 16-bit devices
87
#elif 8 == CYGNUM_FLASH_WIDTH
88
         && (0xD0 == (0xF0 & qp->device_code)) // 8-bit devices
89
#else
90
         && 0
91
#error Only understand 16 and 8-bit bootblock flash types
92
#endif
93
        ) {
94
        int lookup[] = { 16, 8, 4, 32, 64 };
95
#define BLOCKSIZE (0x10000)
96
        region_size = BLOCKSIZE;
97
        num_regions = qp->device_code & 0x0F;
98
        num_regions >>= 1;
99
        if ( num_regions > 4 )
100
            goto flash_type_unknown;
101
        num_regions = lookup[num_regions];
102
        num_regions *= 1024 * 1024;     // to bits
103
        num_regions /= 8;               // to bytes
104
        num_regions /= BLOCKSIZE;       // to blocks
105
        buffer_size = 0;
106
#else // CYGOPT_FLASH_IS_BOOTBLOCK
107
         && (strncmp(qp->id, "QRY", 3) == 0)) {
108
        num_regions = _si(qp->num_regions)+1;
109
        region_size = _si(qp->region_size)*256;
110
        if (_si(qp->buffer_size)) {
111
            buffer_size = CYGNUM_FLASH_DEVICES << _si(qp->buffer_size);
112
        } else {
113
            buffer_size = 0;
114
        }
115
#endif // Not CYGOPT_FLASH_IS_BOOTBLOCK
116
 
117
        flash_info.block_size = region_size*CYGNUM_FLASH_DEVICES;
118
        flash_info.buffer_size = buffer_size;
119
        flash_info.blocks = num_regions;
120
        flash_info.start = (void *)CYGNUM_FLASH_BASE;
121
        flash_info.end = (void *)(CYGNUM_FLASH_BASE +
122
                        (num_regions*region_size*CYGNUM_FLASH_DEVICES));
123
#ifdef CYGNUM_FLASH_BASE_MASK
124
        // Then this gives us a maximum size for the (visible) device.
125
        // This is to cope with oversize devices fitted, with some high
126
        // address lines ignored.
127
        if ( ((unsigned int)flash_info.start & CYGNUM_FLASH_BASE_MASK) !=
128
             (((unsigned int)flash_info.end - 1) & CYGNUM_FLASH_BASE_MASK ) ) {
129
            // then the size of the device appears to span >1 device-worth!
130
            unsigned int x;
131
            x = (~(CYGNUM_FLASH_BASE_MASK)) + 1; // expected device size
132
            x += (unsigned int)flash_info.start;
133
            if ( x < (unsigned int)flash_info.end ) { // 2nd sanity check
134
                (*flash_info.pf)("\nFLASH: Oversized device!  End addr %p changed to %p\n",
135
                       flash_info.end, (void *)x );
136
                flash_info.end = (void *)x;
137
                // Also adjust the block count else unlock crashes!
138
                x = ((cyg_uint8 *)flash_info.end - (cyg_uint8 *)flash_info.start)
139
                    / flash_info.block_size;
140
                flash_info.blocks = x;
141
            }
142
        }
143
#endif // CYGNUM_FLASH_BASE_MASK
144
 
145
        return FLASH_ERR_OK;
146
    }
147
#ifdef CYGOPT_FLASH_IS_BOOTBLOCK
148
 flash_type_unknown:
149
#endif
150
    (*flash_info.pf)("Can't identify FLASH, sorry, man %x, dev %x, id [%4s] \n",
151
           qp->manuf_code, qp->device_code, qp->id );
152
    diag_dump_buf(qp, sizeof(data));
153
    return FLASH_ERR_HWR;
154
}
155
 
156
// Map a hardware status to a package error
157
int
158
flash_hwr_map_error(int err)
159
{
160
    if (err & FLASH_ErrorMask) {
161
        (*flash_info.pf)("Err = %x\n", err);
162
        if (err & FLASH_ErrorProgram)
163
            return FLASH_ERR_PROGRAM;
164
        else if (err & FLASH_ErrorErase)
165
            return FLASH_ERR_ERASE;
166
        else
167
            return FLASH_ERR_HWR;  // FIXME
168
    } else {
169
        return FLASH_ERR_OK;
170
    }
171
}
172
 
173
// See if a range of FLASH addresses overlaps currently running code
174
bool
175
flash_code_overlaps(void *start, void *end)
176
{
177
    extern char _stext[], _etext[];
178
 
179
    return ((((unsigned long)&_stext >= (unsigned long)start) &&
180
             ((unsigned long)&_stext < (unsigned long)end)) ||
181
            (((unsigned long)&_etext >= (unsigned long)start) &&
182
             ((unsigned long)&_etext < (unsigned long)end)));
183
}
184
 
185
// EOF strata.c

powered by: WebSVN 2.1.0

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