1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// flash_legacy.h
|
4 |
|
|
//
|
5 |
|
|
// Flash programming - some internal implementation details.
|
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, 2003, 2004 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
|
43 |
|
|
// Contributors: gthomas, Andrew Lunn
|
44 |
|
|
// Date: 2000-07-14
|
45 |
|
|
// Purpose:
|
46 |
|
|
// Description:
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
//
|
50 |
|
|
//==========================================================================
|
51 |
|
|
|
52 |
|
|
#include <pkgconf/system.h>
|
53 |
|
|
#include <pkgconf/io_flash.h>
|
54 |
|
|
#include <cyg/infra/cyg_type.h>
|
55 |
|
|
#include <cyg/hal/hal_arch.h>
|
56 |
|
|
#include <cyg/hal/hal_cache.h>
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
// Some FLASH devices may require additional support, e.g. to turn on
|
60 |
|
|
// appropriate voltage drivers, before any operation.
|
61 |
|
|
#ifdef CYGIMP_FLASH_ENABLE
|
62 |
|
|
# define FLASH_Enable(__start, __end) CYGIMP_FLASH_ENABLE((void *)__start, (void *)__end)
|
63 |
|
|
extern void CYGIMP_FLASH_ENABLE(void *, void *);
|
64 |
|
|
#else
|
65 |
|
|
# define FLASH_Enable(_start_, _end_) CYG_EMPTY_STATEMENT
|
66 |
|
|
#endif
|
67 |
|
|
#ifdef CYGIMP_FLASH_DISABLE
|
68 |
|
|
# define FLASH_Disable(__start, __end) CYGIMP_FLASH_DISABLE((void *)__start, (void *)__end)
|
69 |
|
|
extern void CYGIMP_FLASH_DISABLE(void *, void *);
|
70 |
|
|
#else
|
71 |
|
|
# define FLASH_Disable(_start_, _end_) CYG_EMPTY_STATEMENT
|
72 |
|
|
#endif
|
73 |
|
|
|
74 |
|
|
//
|
75 |
|
|
// Some platforms have a DIP switch or jumper that tells the software that
|
76 |
|
|
// the flash is write protected.
|
77 |
|
|
//
|
78 |
|
|
#ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT
|
79 |
|
|
externC cyg_bool plf_flash_query_soft_wp(void *addr, int len);
|
80 |
|
|
#endif
|
81 |
|
|
|
82 |
|
|
//---------------------------------------------------------------------------
|
83 |
|
|
// If all of the flash devices handle cache themselves, or do not need any
|
84 |
|
|
// special cache treatment, then the flash macros can be no-ops.
|
85 |
|
|
#ifndef CYGHWR_IO_FLASH_DEVICE_NEEDS_CACHE_HANDLED
|
86 |
|
|
# undef HAL_FLASH_CACHES_OFF
|
87 |
|
|
# undef HAL_FLASH_CACHES_ON
|
88 |
|
|
# undef HAL_FLASH_CACHES_STATE
|
89 |
|
|
# define HAL_FLASH_CACHES_OFF(_d_, _i_) CYG_EMPTY_STATEMENT
|
90 |
|
|
# define HAL_FLASH_CACHES_ON(_d_, _i_) CYG_EMPTY_STATEMENT
|
91 |
|
|
# define HAL_FLASH_CACHES_STATE(_d_, _i_) CYG_EMPTY_STATEMENT
|
92 |
|
|
#endif
|
93 |
|
|
|
94 |
|
|
// Execution of flash code must be done inside a
|
95 |
|
|
// HAL_FLASH_CACHES_OFF/HAL_FLASH_CACHES_ON region - disabling the
|
96 |
|
|
// cache on unified cache systems is necessary to prevent burst access
|
97 |
|
|
// to the flash area being programmed. With Harvard style caches, only
|
98 |
|
|
// the data cache needs to be disabled, but the instruction cache is
|
99 |
|
|
// disabled for consistency.
|
100 |
|
|
|
101 |
|
|
// Targets may provide alternative implementations for these macros in
|
102 |
|
|
// the hal_cache.h (or var/plf) files.
|
103 |
|
|
|
104 |
|
|
// The first part below is a generic, optimal implementation. The
|
105 |
|
|
// second part is the old implementation that has been tested to work
|
106 |
|
|
// on some targets - but it is not be suitable for targets that would
|
107 |
|
|
// do burst access to the flash (it does not disable the data cache).
|
108 |
|
|
|
109 |
|
|
// Both implementations must be called with interrupts disabled.
|
110 |
|
|
|
111 |
|
|
// NOTE: Do _not_ change any of the below macros without checking that
|
112 |
|
|
// the changed code still works on _all_ platforms that rely on these
|
113 |
|
|
// macros. There is no such thing as logical and correct when dealing
|
114 |
|
|
// with different cache and IO models, so _do not_ mess with this code
|
115 |
|
|
// unless you test it properly afterwards.
|
116 |
|
|
|
117 |
|
|
#ifndef HAL_FLASH_CACHES_OFF
|
118 |
|
|
|
119 |
|
|
// Some drivers have only been tested with the old macros below.
|
120 |
|
|
#ifndef HAL_FLASH_CACHES_OLD_MACROS
|
121 |
|
|
|
122 |
|
|
#ifdef HAL_CACHE_UNIFIED
|
123 |
|
|
|
124 |
|
|
// Note: the ucache code has not been tested yet on any target.
|
125 |
|
|
#define HAL_FLASH_CACHES_OFF(_d_, _i_) \
|
126 |
|
|
CYG_MACRO_START \
|
127 |
|
|
_i_ = 0; /* avoids warning */ \
|
128 |
|
|
HAL_UCACHE_IS_ENABLED(_d_); \
|
129 |
|
|
HAL_UCACHE_SYNC(); \
|
130 |
|
|
HAL_UCACHE_INVALIDATE_ALL(); \
|
131 |
|
|
HAL_UCACHE_DISABLE(); \
|
132 |
|
|
CYG_MACRO_END
|
133 |
|
|
|
134 |
|
|
#define HAL_FLASH_CACHES_ON(_d_, _i_) \
|
135 |
|
|
CYG_MACRO_START \
|
136 |
|
|
if (_d_) HAL_UCACHE_ENABLE(); \
|
137 |
|
|
CYG_MACRO_END
|
138 |
|
|
|
139 |
|
|
#else // HAL_CACHE_UNIFIED
|
140 |
|
|
|
141 |
|
|
#define HAL_FLASH_CACHES_OFF(_d_, _i_) \
|
142 |
|
|
CYG_MACRO_START \
|
143 |
|
|
_i_ = 0; /* avoids warning */ \
|
144 |
|
|
HAL_DCACHE_IS_ENABLED(_d_); \
|
145 |
|
|
HAL_DCACHE_SYNC(); \
|
146 |
|
|
HAL_DCACHE_INVALIDATE_ALL(); \
|
147 |
|
|
HAL_DCACHE_DISABLE(); \
|
148 |
|
|
HAL_ICACHE_INVALIDATE_ALL(); \
|
149 |
|
|
CYG_MACRO_END
|
150 |
|
|
|
151 |
|
|
#define HAL_FLASH_CACHES_ON(_d_, _i_) \
|
152 |
|
|
CYG_MACRO_START \
|
153 |
|
|
if (_d_) HAL_DCACHE_ENABLE(); \
|
154 |
|
|
CYG_MACRO_END
|
155 |
|
|
|
156 |
|
|
#endif // HAL_CACHE_UNIFIED
|
157 |
|
|
|
158 |
|
|
#else // HAL_FLASH_CACHES_OLD_MACROS
|
159 |
|
|
|
160 |
|
|
// Note: This implementation is broken as it will always enable the i-cache
|
161 |
|
|
// even if it was not enabled before. It also doesn't work if the
|
162 |
|
|
// target uses burst access to flash since the d-cache is left enabled.
|
163 |
|
|
// However, this does not mean you can change this code! Leave it as
|
164 |
|
|
// is - if you want a different implementation, provide it in the
|
165 |
|
|
// arch/var/platform cache header file.
|
166 |
|
|
|
167 |
|
|
#define HAL_FLASH_CACHES_OFF(_d_, _i_) \
|
168 |
|
|
_d_ = 0; /* avoids warning */ \
|
169 |
|
|
_i_ = 0; /* avoids warning */ \
|
170 |
|
|
HAL_DCACHE_SYNC(); \
|
171 |
|
|
HAL_ICACHE_DISABLE();
|
172 |
|
|
|
173 |
|
|
#define HAL_FLASH_CACHES_ON(_d_, _i_) \
|
174 |
|
|
HAL_ICACHE_ENABLE();
|
175 |
|
|
|
176 |
|
|
#endif // HAL_FLASH_CACHES_OLD_MACROS
|
177 |
|
|
|
178 |
|
|
#endif // HAL_FLASH_CACHES_OFF
|
179 |
|
|
|
180 |
|
|
#ifndef HAL_FLASH_CACHES_STATE
|
181 |
|
|
# define HAL_FLASH_CACHES_STATE(_d_, _i_) int _d_, _i_
|
182 |
|
|
#endif
|