Mercurial > flash_v2
annotate packages/io/flash/current/src/flash.c @ 1741:9464c6747e99
Sort out the various loops to cope with boundary conditions,
especially flash devices mapped right at the top of memory.
| author | bartv |
|---|---|
| date | Sat, 20 Nov 2004 19:27:26 +0000 |
| parents | 3f6b1c304c7a |
| children | a668b95e5f2e |
| rev | line source |
|---|---|
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
1 //========================================================================== |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
2 // |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
3 // flash.c |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
4 // |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
5 // Flash programming |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
6 // |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
7 //========================================================================== |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
8 //####ECOSGPLCOPYRIGHTBEGIN#### |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
9 // ------------------------------------------- |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
11 // Copyright (C) 2004 Andrew Lunn |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
12 // Copyright (C) 2004 eCosCentric Ltd. |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
13 // Copyright (C) 2003 Gary Thomas |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
15 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
16 // eCos is free software; you can redistribute it and/or modify it under |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
17 // the terms of the GNU General Public License as published by the Free |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
18 // Software Foundation; either version 2 or (at your option) any later version. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
19 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
23 // for more details. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
24 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
25 // You should have received a copy of the GNU General Public License along |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
26 // with eCos; if not, write to the Free Software Foundation, Inc., |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
28 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
29 // As a special exception, if other files instantiate templates or use macros |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
30 // or inline functions from this file, or you compile this file and link it |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
31 // with other works to produce a work based on this file, this file does not |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
32 // by itself cause the resulting work to be covered by the GNU General Public |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
33 // License. However the source code for this file must still be made available |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
34 // in accordance with section (3) of the GNU General Public License. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
35 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
36 // This exception does not invalidate any other reasons why a work based on |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
37 // this file might be covered by the GNU General Public License. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
38 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
|
210
d2c90368aeef
Merge from eCos master repository on 2002-05-23-21:39:14-BST
jlarmour
parents:
208
diff
changeset
|
40 // at http://sources.redhat.com/ecos/ecos-license/ |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
41 // ------------------------------------------- |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
42 //####ECOSGPLCOPYRIGHTEND#### |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
43 //========================================================================== |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
44 //#####DESCRIPTIONBEGIN#### |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
45 // |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
46 // Author(s): gthomas |
| 1706 | 47 // Contributors: gthomas, Andrew Lunn |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
48 // Date: 2000-07-26 |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
49 // Purpose: |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
50 // Description: |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
51 // |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
52 //####DESCRIPTIONEND#### |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
53 // |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
54 //========================================================================== |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
55 |
|
119
77cec8369160
Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents:
117
diff
changeset
|
56 #include <pkgconf/system.h> |
|
77cec8369160
Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents:
117
diff
changeset
|
57 #include <pkgconf/io_flash.h> |
| 1706 | 58 #ifdef CYGPKG_KERNEL |
| 59 #include <cyg/kernel/kapi.h> | |
| 60 #endif | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
61 #include <cyg/hal/hal_arch.h> |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
62 #include <cyg/hal/hal_intr.h> |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
63 #include <cyg/hal/hal_cache.h> |
| 1706 | 64 #include <cyg/hal/hal_tables.h> |
| 65 #include <cyg/infra/cyg_ass.h> | |
|
191
678094f34118
Merge from eCos master repository on 2001-10-19-06:43:02-BST
jlarmour
parents:
177
diff
changeset
|
66 #include <string.h> |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
67 |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
68 #define _FLASH_PRIVATE_ |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
69 #include <cyg/io/flash.h> |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
70 |
|
143
6b5f480c6929
Merge from eCos master repository on 2000-12-08-02:09:36-GMT
jlarmour
parents:
141
diff
changeset
|
71 // When this flag is set, do not actually jump to the relocated code. |
| 1706 | 72 // This can be used for running the function in place (RAM startup |
| 73 // only), allowing calls to diag_printf() and similar. | |
|
136
a9ac27ec7abc
Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents:
121
diff
changeset
|
74 #undef RAM_FLASH_DEV_DEBUG |
|
a9ac27ec7abc
Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents:
121
diff
changeset
|
75 #if !defined(CYG_HAL_STARTUP_RAM) && defined(RAM_FLASH_DEV_DEBUG) |
|
a9ac27ec7abc
Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents:
121
diff
changeset
|
76 # warning "Can only enable the flash debugging when configured for RAM startup" |
|
a9ac27ec7abc
Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents:
121
diff
changeset
|
77 #endif |
| 1400 | 78 |
| 1706 | 79 // Has the FLASH IO library been initialise? |
| 80 static bool init = false; | |
| 81 // We have a linked list of flash drivers. This is the head of the | |
| 82 // list | |
| 83 static struct cyg_flash_dev *flash_head = NULL; | |
| 84 | |
| 85 // This array contains entries for all flash devices that are | |
| 86 // installed in the system. | |
| 87 __externC struct cyg_flash_dev cyg_flashdevtab[]; | |
| 88 CYG_HAL_TABLE_BEGIN(cyg_flashdevtab, cyg_flashdev); | |
| 89 | |
| 90 // end of the flashdev table | |
| 91 __externC struct cyg_flash_dev cyg_flashdevtab_end; | |
| 92 CYG_HAL_TABLE_END(cyg_flashdevtab_end, cyg_flashdev); | |
| 1400 | 93 |
| 1706 | 94 // Sort the linked list into ascending order of flash address. Use a |
| 95 // primitive ripple sort, but since we don't expect to have many | |
| 96 // devices this should be OK. | |
| 97 static void flash_sort(void) | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
98 { |
| 1706 | 99 bool moved; |
| 100 struct cyg_flash_dev *dev, **previous_next; | |
| 101 | |
| 102 // If there is zero or one device, short cut | |
| 103 if (flash_head == NULL || flash_head->next == NULL) | |
| 104 return; | |
| 105 | |
| 106 do { | |
| 107 moved=false; | |
| 108 for (dev=flash_head, previous_next=&flash_head; | |
| 109 dev->next; | |
| 110 previous_next = &dev->next, dev=dev->next ){ | |
| 111 if (dev->start > dev->next->start) { | |
| 112 *previous_next=dev->next; | |
| 113 dev->next = (*previous_next)->next; | |
| 114 (*previous_next)->next = dev; | |
| 115 moved=true; | |
| 116 break; | |
| 117 } | |
| 118 } | |
| 119 } while (moved); | |
| 120 } | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
121 |
| 1706 | 122 // Walk the linked list and see if there are any overlaps in the |
| 123 // addresses the devices claim to use using. | |
| 124 static bool flash_check_overlap(void) | |
| 125 { | |
| 126 struct cyg_flash_dev *dev; | |
| 127 | |
| 128 // If there is zero or one device, short cut | |
| 129 if (flash_head == NULL || flash_head->next == NULL) | |
| 130 return false; | |
| 131 | |
| 132 for (dev=flash_head; dev->next; dev=dev->next){ | |
| 133 if (dev->end >= dev->next->start) | |
| 134 return true; | |
| 135 } | |
| 136 return false; | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
137 } |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
138 |
| 1706 | 139 // Initialise all registered device. Any device that fails to |
| 140 // initialise we leave dev->init as false. Then sort the devices into | |
| 141 // ascending order of address and put them into a linked list. Lastly | |
| 142 // check if we have any overlap of the addresses. | |
| 143 __externC int | |
| 144 cyg_flash_init(cyg_flash_printf *pf) | |
|
154
e2d866e32dac
Merge from eCos master repository on 2001-02-26-23:18:05-GMT
jlarmour
parents:
151
diff
changeset
|
145 { |
| 1706 | 146 int err; |
| 147 struct cyg_flash_dev * dev; | |
| 148 | |
| 149 if (init) return CYG_FLASH_ERR_OK; | |
| 150 init = true; | |
| 151 | |
| 152 for (dev = &cyg_flashdevtab[0]; dev != &cyg_flashdevtab_end; dev++) { | |
| 153 dev->pf = pf; | |
| 154 #ifdef CYGPKG_KERNEL | |
| 155 cyg_mutex_init(&dev->mutex); | |
| 156 #endif | |
| 157 | |
| 158 err = dev->funs->flash_init(dev); | |
| 159 if (err != CYG_FLASH_ERR_OK) { | |
| 160 continue; | |
| 161 } | |
| 162 CYG_ASSERT(dev->funs, "No flash functions"); | |
| 163 CYG_ASSERT(dev->num_block_infos, "No number of block infoss"); | |
| 164 CYG_ASSERT(dev->block_info, "No block infos"); | |
| 165 CYG_ASSERT(!(((cyg_flashaddr_t)dev->block_info >= dev->start) && | |
| 166 ((cyg_flashaddr_t)dev->block_info < dev->end)), | |
| 167 "Block info is in the flash"); | |
| 168 CYG_ASSERT(dev->funs->flash_erase_block, "No erase function"); | |
| 169 CYG_ASSERT(dev->funs->flash_program, "No program function"); | |
| 170 CYG_ASSERT(dev->funs->flash_hwr_map_error, "No hwr map error function"); | |
|
1729
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
171 #ifdef CYGDBG_USE_ASSERTS |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
172 { |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
173 int i; |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
174 cyg_flashaddr_t addr = dev->start; |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
175 for (i = 0; i < dev->num_block_infos; i++) { |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
176 addr += dev->block_info[i].block_size * dev->block_info[i].blocks; |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
177 } |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
178 CYG_ASSERT(dev->end == addr-1, "Invalid end address"); |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
179 } |
|
e290a0372578
* src/flash.c (cyg_flash_init): Add assert checking that the
asl
parents:
1723
diff
changeset
|
180 #endif |
| 1706 | 181 dev->init = true; |
| 182 dev->next = flash_head; | |
| 183 flash_head = dev; | |
| 184 } | |
| 185 | |
| 186 flash_sort(); | |
| 187 | |
| 188 if (flash_check_overlap()) { | |
| 189 return CYG_FLASH_ERR_INVALID; | |
| 190 } | |
| 191 return CYG_FLASH_ERR_OK; | |
|
154
e2d866e32dac
Merge from eCos master repository on 2001-02-26-23:18:05-GMT
jlarmour
parents:
151
diff
changeset
|
192 } |
|
e2d866e32dac
Merge from eCos master repository on 2001-02-26-23:18:05-GMT
jlarmour
parents:
151
diff
changeset
|
193 |
| 1706 | 194 // Is the address within one of the flash drivers? |
| 195 __externC int | |
| 196 cyg_flash_verify_addr(const cyg_flashaddr_t address) | |
|
143
6b5f480c6929
Merge from eCos master repository on 2000-12-08-02:09:36-GMT
jlarmour
parents:
141
diff
changeset
|
197 { |
| 1706 | 198 struct cyg_flash_dev * dev; |
| 199 | |
| 200 if (!init) return CYG_FLASH_ERR_NOT_INIT; | |
| 201 | |
| 202 for (dev = flash_head; dev; dev=dev->next) { | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
203 if ((dev->start <= address) && (address <= dev->end)) |
| 1706 | 204 return CYG_FLASH_ERR_OK; |
| 205 } | |
| 206 return CYG_FLASH_ERR_INVALID; | |
|
143
6b5f480c6929
Merge from eCos master repository on 2000-12-08-02:09:36-GMT
jlarmour
parents:
141
diff
changeset
|
207 } |
|
6b5f480c6929
Merge from eCos master repository on 2000-12-08-02:09:36-GMT
jlarmour
parents:
141
diff
changeset
|
208 |
| 1706 | 209 // See if a range of FLASH addresses overlaps currently running code |
| 210 __externC bool cyg_flash_code_overlaps(const cyg_flashaddr_t start, | |
| 211 const cyg_flashaddr_t end) | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
212 { |
| 1706 | 213 extern char _stext[], _etext[]; |
| 214 | |
| 215 return ((((unsigned long)&_stext >= (unsigned long)start) && | |
| 216 ((unsigned long)&_stext < (unsigned long)end)) || | |
| 217 (((unsigned long)&_etext >= (unsigned long)start) && | |
| 218 ((unsigned long)&_etext < (unsigned long)end))); | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
219 } |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
220 |
| 1706 | 221 // Return information about the Nth driver |
| 222 __externC int | |
| 223 cyg_flash_get_info(cyg_uint32 Nth, cyg_flash_info_t * info) | |
| 224 { | |
| 225 struct cyg_flash_dev * dev; | |
| 226 | |
| 227 if (!init) return CYG_FLASH_ERR_NOT_INIT; | |
| 228 | |
| 229 for (dev = flash_head; dev && Nth; dev=dev->next, Nth--) | |
| 230 ; | |
| 231 if (dev && !Nth) { | |
| 232 info->start = dev->start; | |
| 233 info->end = dev->end; | |
| 234 info->num_block_infos = dev->num_block_infos; | |
| 235 info->block_info = dev->block_info; | |
| 236 return CYG_FLASH_ERR_OK; | |
| 237 } | |
| 238 return CYG_FLASH_ERR_INVALID; | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
239 } |
|
157
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
156
diff
changeset
|
240 |
| 1706 | 241 // Return information about the flash at the given address |
| 242 __externC int | |
| 243 cyg_flash_get_info_addr(cyg_flashaddr_t flash_base, cyg_flash_info_t * info) | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
244 { |
| 1706 | 245 struct cyg_flash_dev *dev; |
| 246 | |
| 247 if (!init) return CYG_FLASH_ERR_NOT_INIT; | |
| 248 | |
| 249 for (dev = flash_head; dev ; dev=dev->next) { | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
250 if ((dev->start <= flash_base) && ( flash_base <= dev->end)) { |
| 1706 | 251 info->start = dev->start; |
| 252 info->end = dev->end; | |
| 253 info->num_block_infos = dev->num_block_infos; | |
| 254 info->block_info = dev->block_info; | |
| 255 return CYG_FLASH_ERR_OK; | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
256 } |
| 1706 | 257 } |
| 258 return CYG_FLASH_ERR_INVALID; | |
| 259 } | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
260 |
| 1706 | 261 #ifdef CYGPKG_KERNEL |
| 262 //Lock the mutex's for a range of addresses | |
| 263 __externC int | |
| 264 cyg_flash_mutex_lock(const cyg_flashaddr_t from, const size_t len) | |
| 265 { | |
| 266 struct cyg_flash_dev * dev; | |
| 267 int err; | |
| 268 | |
| 269 if (!init) return CYG_FLASH_ERR_NOT_INIT; | |
| 270 | |
| 271 for (dev = flash_head; dev ; dev=dev->next) { | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
272 if ((dev->start <= from) && ( from <= dev->end)) { |
| 1706 | 273 cyg_mutex_lock(&dev->mutex); |
| 274 if (dev->end > from+len) { | |
| 275 return CYG_FLASH_ERR_OK; | |
| 276 } else { // Check off by one? | |
| 277 //The region is bigger than this driver. Recurse | |
| 278 err = cyg_flash_mutex_lock(dev->end+1, (len - (dev->end - from))); | |
| 279 if (err != CYG_FLASH_ERR_OK) { | |
| 280 // Something went wrong, unlock what we just locked | |
| 281 cyg_mutex_unlock(&dev->mutex); | |
| 282 } | |
| 283 return err; | |
| 284 } | |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
285 } |
| 1706 | 286 } |
| 287 return CYG_FLASH_ERR_INVALID; | |
| 288 } | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
289 |
| 1706 | 290 //Unlock the mutex's for a range of addresses |
| 291 __externC int | |
| 292 cyg_flash_mutex_unlock(const cyg_flashaddr_t from, const size_t len) | |
| 293 { | |
| 294 struct cyg_flash_dev * dev; | |
| 295 int err; | |
| 296 | |
| 297 if (!init) return CYG_FLASH_ERR_NOT_INIT; | |
| 298 | |
| 299 for (dev = flash_head; dev ; dev=dev->next) { | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
300 if ((dev->start <= from) && ( from <= dev->end)) { |
| 1706 | 301 cyg_mutex_unlock(&dev->mutex); |
| 302 if (dev->end > from+len) { | |
| 303 return CYG_FLASH_ERR_OK; | |
| 304 } else { // Check off by one? | |
| 305 //The region is bigger than this driver. Recurse | |
| 306 err = cyg_flash_mutex_unlock(dev->end+1, (len - (dev->end - from))); | |
| 307 return err; | |
| 308 } | |
| 309 } | |
| 310 } | |
| 311 return CYG_FLASH_ERR_INVALID; | |
| 312 } | |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
313 #endif |
|
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
314 |
| 1706 | 315 // Return the size of the block which is at the given address |
| 316 static size_t | |
| 317 flash_block_size(struct cyg_flash_dev *dev, const cyg_flashaddr_t addr) | |
| 318 { | |
| 319 int i; | |
| 320 size_t offset; | |
| 321 | |
| 322 | |
| 323 CYG_ASSERT((addr >= dev->start) && (addr <= dev->end), "Not inside device"); | |
| 324 | |
| 325 offset = addr - dev->start; | |
| 326 for (i=0; i < dev->num_block_infos; i++) { | |
| 327 if (offset < (dev->block_info[i].blocks * dev->block_info[i].block_size)) | |
| 328 return dev->block_info[i].block_size; | |
| 329 offset = offset - | |
| 330 (dev->block_info[i].blocks * dev->block_info[i].block_size); | |
| 331 } | |
| 332 CYG_FAIL("Programming error"); | |
| 333 return 0; | |
| 334 } | |
| 335 | |
| 336 // Return the size of the block which is at the given address | |
| 337 __externC size_t | |
| 338 cyg_flash_block_size(const cyg_flashaddr_t flash_base) | |
| 339 { | |
| 340 struct cyg_flash_dev * dev; | |
| 341 | |
| 342 if (!init) return CYG_FLASH_ERR_NOT_INIT; | |
| 343 | |
| 344 for (dev = flash_head; | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
345 dev && !((dev->start <= flash_base) && ( flash_base <= dev->end)); |
| 1706 | 346 dev=dev->next) |
| 347 ; | |
| 348 if (!dev) return CYG_FLASH_ERR_INVALID; | |
| 349 | |
| 350 return flash_block_size(dev, flash_base); | |
| 351 } | |
| 352 | |
|
1723
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
353 // Return the first address of a block. The flash might not be aligned |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
354 // in terms of its block size. So we have to be careful and use |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
355 // offsets. |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
356 static inline cyg_flashaddr_t |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
357 flash_block_begin(cyg_flashaddr_t addr, struct cyg_flash_dev *dev) |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
358 { |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
359 size_t block_size; |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
360 cyg_flashaddr_t offset; |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
361 |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
362 block_size = flash_block_size(dev, addr); |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
363 |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
364 offset = addr - dev->start; |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
365 offset = (offset / block_size) * block_size; |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
366 return offset + dev->start; |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
367 } |
|
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
368 |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
195
diff
changeset
|
369 |
| 1706 | 370 __externC int |
| 371 cyg_flash_erase(const cyg_flashaddr_t flash_base, | |
| 372 const size_t len, | |
| 373 cyg_flashaddr_t *err_address) | |
| 374 { | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
375 cyg_flashaddr_t block, end_addr; |
| 1706 | 376 struct cyg_flash_dev * dev; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
377 size_t erase_count; |
| 1706 | 378 int stat = CYG_FLASH_ERR_OK; |
| 379 int d_cache, i_cache; | |
| 380 | |
| 381 if (!init) return CYG_FLASH_ERR_NOT_INIT; | |
| 382 | |
| 383 #ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
384 if (plf_flash_query_soft_wp(flash_base,len)) |
| 1706 | 385 return CYG_FLASH_ERR_PROTECT; |
| 386 #endif | |
| 387 | |
| 388 for (dev = flash_head; | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
389 dev && !((dev->start <= flash_base) && ( flash_base <= dev->end)); |
| 1706 | 390 dev=dev->next) |
| 391 ; | |
| 392 if (!dev) return CYG_FLASH_ERR_INVALID; | |
| 393 | |
| 394 #ifdef CYGPKG_KERNEL | |
| 395 cyg_mutex_lock(&dev->mutex); | |
| 396 #endif | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
397 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
398 // Check whether or not we are going past the end of this device, on |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
399 // to the next one. If so the next device will be handled by a |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
400 // recursive call later on. |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
401 if (len > (dev->end + 1 - flash_base)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
402 end_addr = dev->end; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
403 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
404 end_addr = flash_base + len - 1; |
| 1706 | 405 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
406 // erase can only happen on a block boundary, so adjust for this |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
407 block = flash_block_begin(flash_base, dev); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
408 erase_count = (end_addr + 1) - block; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
409 |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
410 #ifdef CYGSEM_IO_FLASH_CHATTER |
| 1706 | 411 dev->pf("... Erase from %p-%p: ", (void*)block, (void*)end_addr); |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
412 #endif |
| 1706 | 413 |
| 414 HAL_FLASH_CACHES_OFF(d_cache, i_cache); | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
415 FLASH_Enable(flash_base, end_addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
416 while (erase_count > 0) { |
| 1706 | 417 int i; |
| 418 unsigned char *dp; | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
419 bool erased = false; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
420 size_t block_size = flash_block_size(dev, block); |
| 1706 | 421 |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
422 // Pad to the block boundary, if necessary |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
423 if (erase_count < block_size) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
424 erase_count = block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
425 } |
|
1723
0cc13d07a67e
* src/flash.c: Support flash blocks of arbitary size. The
asl
parents:
1722
diff
changeset
|
426 |
| 1706 | 427 // If there is a read function it probably means the flash |
| 428 // cannot be read directly. | |
| 429 if (!dev->funs->flash_read) { | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
430 erased = true; |
| 1706 | 431 dp = (unsigned char *)block; |
| 432 for (i = 0; i < block_size; i++) { | |
| 433 if (*dp++ != (unsigned char)0xFF) { | |
| 434 erased = false; | |
| 435 break; | |
| 436 } | |
| 437 } | |
| 438 } | |
| 439 if (!erased) { | |
| 440 stat = dev->funs->flash_erase_block(dev,block); | |
| 441 stat = dev->funs->flash_hwr_map_error(dev,stat); | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
442 } |
| 1706 | 443 if (CYG_FLASH_ERR_OK != stat && err_address) { |
| 444 *err_address = block; | |
| 445 break; | |
| 446 } | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
447 block += block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
448 erase_count -= block_size; |
| 1706 | 449 #ifdef CYGSEM_IO_FLASH_CHATTER |
| 450 dev->pf("."); | |
| 451 #endif | |
| 452 } | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
453 FLASH_Disable(flash_base, end_addr); |
| 1706 | 454 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
455 #ifdef CYGSEM_IO_FLASH_CHATTER |
| 1706 | 456 dev->pf("\n"); |
| 457 #endif | |
| 458 #ifdef CYGPKG_KERNEL | |
| 459 cyg_mutex_unlock(&dev->mutex); | |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
460 #endif |
| 1706 | 461 if (stat != CYG_FLASH_ERR_OK) { |
| 462 return stat; | |
| 463 } | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
464 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
465 // If there are multiple flash devices in series the erase operation |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
466 // may touch successive devices. This can be handled by recursion. |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
467 // The stack overheads should be minimal because the number of |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
468 // devices will be small. |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
469 if (len > (dev->end + 1 - flash_base)) { |
| 1706 | 470 return cyg_flash_erase(dev->end+1, |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
471 len - (dev->end + 1 - flash_base), |
| 1706 | 472 err_address); |
| 473 } | |
| 474 return CYG_FLASH_ERR_OK; | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
475 } |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
476 |
| 1706 | 477 __externC int |
| 478 cyg_flash_program(const cyg_flashaddr_t flash_base, | |
| 479 void *ram_base, | |
| 480 const size_t len, | |
| 481 cyg_flashaddr_t *err_address) | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
482 { |
| 1706 | 483 struct cyg_flash_dev * dev; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
484 cyg_flashaddr_t addr, end_addr, block; |
| 1706 | 485 unsigned char * ram = ram_base; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
486 size_t write_count, offset; |
| 1706 | 487 int stat = CYG_FLASH_ERR_OK; |
| 488 int d_cache, i_cache; | |
| 489 | |
| 490 if (!init) return CYG_FLASH_ERR_NOT_INIT; | |
| 491 | |
|
174
38892b97b685
Merge from eCos master repository on 2001-07-28-00:17:32-BST
jlarmour
parents:
163
diff
changeset
|
492 #ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT |
| 1706 | 493 if (plf_flash_query_soft_wp(addr,len)) |
| 494 return CYG_FLASH_ERR_PROTECT; | |
|
174
38892b97b685
Merge from eCos master repository on 2001-07-28-00:17:32-BST
jlarmour
parents:
163
diff
changeset
|
495 #endif |
| 1706 | 496 |
| 497 for (dev = flash_head; | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
498 dev && !((dev->start <= flash_base) && ( flash_base <= dev->end)); |
| 1706 | 499 dev=dev->next) |
| 500 ; | |
| 501 if (!dev) return CYG_FLASH_ERR_INVALID; | |
| 502 | |
| 503 #ifdef CYGPKG_KERNEL | |
| 504 cyg_mutex_lock(&dev->mutex); | |
| 505 #endif | |
| 506 addr = flash_base; | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
507 if (len > (dev->end + 1 - flash_base)) { |
| 1706 | 508 end_addr = dev->end; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
509 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
510 end_addr = flash_base + len - 1; |
| 1706 | 511 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
512 write_count = (end_addr + 1) - flash_base; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
513 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
514 // The first write may be in the middle of a block. Do the necessary |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
515 // adjustment here rather than inside the loop. |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
516 block = flash_block_begin(flash_base, dev); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
517 if (addr == block) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
518 offset = 0; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
519 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
520 offset = addr - block; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
521 } |
| 1706 | 522 |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
523 #ifdef CYGSEM_IO_FLASH_CHATTER |
| 1706 | 524 dev->pf("... Program from %p-%p to %p: ", ram_base, |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
525 ((CYG_ADDRESS)ram_base)+write_count, addr); |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
526 #endif |
| 1706 | 527 |
| 528 HAL_FLASH_CACHES_OFF(d_cache, i_cache); | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
529 FLASH_Enable(flash_base, end_addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
530 while (write_count > 0) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
531 size_t block_size = flash_block_size(dev, addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
532 size_t this_write; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
533 if (write_count > (block_size - offset)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
534 this_write = block_size - offset; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
535 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
536 this_write = write_count; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
537 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
538 // Only the first block may need the offset. |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
539 offset = 0; |
| 1706 | 540 |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
541 stat = dev->funs->flash_program(dev, addr, ram, this_write); |
| 1706 | 542 stat = dev->funs->flash_hwr_map_error(dev,stat); |
|
157
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
156
diff
changeset
|
543 #ifdef CYGSEM_IO_FLASH_VERIFY_PROGRAM |
| 1706 | 544 if (CYG_FLASH_ERR_OK == stat) // Claims to be OK |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
545 if (!dev->funs->flash_read && memcmp((void *)addr, ram, this_write) != 0) { |
| 1706 | 546 stat = CYG_FLASH_ERR_DRV_VERIFY; |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
547 #ifdef CYGSEM_IO_FLASH_CHATTER |
| 1706 | 548 dev->pf("V"); |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
549 #endif |
| 1706 | 550 } |
|
157
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
156
diff
changeset
|
551 #endif |
| 1706 | 552 if (CYG_FLASH_ERR_OK != stat && err_address) { |
| 553 *err_address = addr; | |
| 554 break; | |
| 555 } | |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
556 #ifdef CYGSEM_IO_FLASH_CHATTER |
| 1706 | 557 dev->pf("."); |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
558 #endif |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
559 write_count -= this_write; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
560 addr += this_write; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
561 ram += this_write; |
| 1706 | 562 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
563 FLASH_Disable(flash_base, end_addr); |
| 1706 | 564 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
565 #ifdef CYGSEM_IO_FLASH_CHATTER |
| 1706 | 566 dev->pf("\n"); |
| 567 #endif | |
| 568 #ifdef CYGPKG_KERNEL | |
| 569 cyg_mutex_unlock(&dev->mutex); | |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
570 #endif |
| 1706 | 571 if (stat != CYG_FLASH_ERR_OK) { |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
572 return (stat); |
| 1706 | 573 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
574 if (len > (dev->end + 1 - flash_base)) { |
| 1706 | 575 return cyg_flash_program(dev->end+1, ram, |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
576 len - (dev->end + 1 - flash_base), |
| 1706 | 577 err_address); |
| 578 } | |
| 579 return CYG_FLASH_ERR_OK; | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
580 } |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
581 |
| 1706 | 582 __externC int |
| 583 cyg_flash_read(cyg_flashaddr_t flash_base, | |
| 584 const void *ram_base, | |
| 585 const size_t len, | |
| 586 cyg_flashaddr_t *err_address) | |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
587 { |
| 1706 | 588 struct cyg_flash_dev * dev; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
589 cyg_flashaddr_t addr, end_addr, block; |
| 1706 | 590 unsigned char * ram = (unsigned char *)ram_base; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
591 size_t read_count, offset; |
| 1706 | 592 int stat = CYG_FLASH_ERR_OK; |
| 593 int d_cache, i_cache; | |
| 594 | |
| 595 if (!init) return CYG_FLASH_ERR_NOT_INIT; | |
| 596 | |
| 597 for (dev = flash_head; | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
598 dev && !((dev->start <= flash_base) && ( flash_base <= dev->end)); |
| 1706 | 599 dev=dev->next) |
| 600 ; | |
| 601 if (!dev) return CYG_FLASH_ERR_INVALID; | |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
602 |
| 1706 | 603 #ifdef CYGPKG_KERNEL |
| 604 cyg_mutex_lock(&dev->mutex); | |
| 605 #endif | |
| 606 addr = flash_base; | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
607 if (len > (dev->end + 1 - flash_base)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
608 end_addr = dev->end; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
609 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
610 end_addr = flash_base + len - 1; |
| 1706 | 611 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
612 read_count = (end_addr + 1) - flash_base; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
613 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
614 // The first read may be in the middle of a block. Do the necessary |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
615 // adjustment here rather than inside the loop. |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
616 block = flash_block_begin(flash_base, dev); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
617 if (addr == block) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
618 offset = 0; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
619 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
620 offset = addr - block; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
621 } |
| 1706 | 622 |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
623 #ifdef CYGSEM_IO_FLASH_CHATTER |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
624 dev->pf("... Read from %p-%p to %p: ", addr, end_addr, ram_base); |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
625 #endif |
| 1706 | 626 |
| 627 HAL_FLASH_CACHES_OFF(d_cache, i_cache); | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
628 FLASH_Enable(flash_base, end_addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
629 while (read_count > 0) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
630 size_t block_size = flash_block_size(dev, addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
631 size_t this_read; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
632 if (read_count > (block_size - offset)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
633 this_read = block_size - offset; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
634 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
635 this_read = read_count; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
636 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
637 // Only the first block may need the offset |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
638 offset = 0; |
| 1706 | 639 |
| 640 if (dev->funs->flash_read) { | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
641 stat = dev->funs->flash_read(dev, addr, ram, this_read); |
| 1706 | 642 stat = dev->funs->flash_hwr_map_error(dev,stat); |
| 643 } else { | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
644 memcpy(ram, (void *)addr, this_read); |
| 1706 | 645 stat = CYG_FLASH_ERR_OK; |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
646 } |
| 1706 | 647 if (CYG_FLASH_ERR_OK != stat && err_address) { |
| 648 *err_address = addr; | |
| 649 break; | |
| 650 } | |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
651 #ifdef CYGSEM_IO_FLASH_CHATTER |
| 1706 | 652 dev->pf("."); |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
653 #endif |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
654 read_count -= this_read; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
655 addr += this_read; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
656 ram += this_read; |
| 1706 | 657 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
658 FLASH_Disable(flash_base, end_addr); |
| 1706 | 659 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
| 660 #ifdef CYGSEM_IO_FLASH_CHATTER | |
| 661 dev->pf("\n"); | |
| 662 #endif | |
| 663 #ifdef CYGPKG_KERNEL | |
| 664 cyg_mutex_unlock(&dev->mutex); | |
| 665 #endif | |
| 666 if (stat != CYG_FLASH_ERR_OK) { | |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
667 return (stat); |
| 1706 | 668 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
669 if (len > (dev->end + 1 - flash_base)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
670 return cyg_flash_read(dev->end+1, ram, |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
671 len - (dev->end + 1 - flash_base), |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
672 err_address); |
| 1706 | 673 } |
| 674 return CYG_FLASH_ERR_OK; | |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
675 } |
|
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
676 |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
174
diff
changeset
|
677 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING |
| 1706 | 678 __externC int |
| 679 cyg_flash_lock(const cyg_flashaddr_t flash_base, | |
| 680 const size_t len, | |
| 681 cyg_flashaddr_t *err_address) | |
|
119
77cec8369160
Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents:
117
diff
changeset
|
682 { |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
683 cyg_flashaddr_t block, end_addr; |
| 1706 | 684 struct cyg_flash_dev * dev; |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
685 size_t lock_count; |
| 1706 | 686 int stat = CYG_FLASH_ERR_OK; |
| 687 int d_cache, i_cache; | |
| 688 | |
| 689 if (!init) return CYG_FLASH_ERR_NOT_INIT; | |
| 690 | |
|
174
38892b97b685
Merge from eCos master repository on 2001-07-28-00:17:32-BST
jlarmour
parents:
163
diff
changeset
|
691 #ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT |
| 1706 | 692 if (plf_flash_query_soft_wp(addr,len)) |
| 693 return CYG_FLASH_ERR_PROTECT; | |
|
174
38892b97b685
Merge from eCos master repository on 2001-07-28-00:17:32-BST
jlarmour
parents:
163
diff
changeset
|
694 #endif |
| 1706 | 695 |
| 696 for (dev = flash_head; | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
697 dev && !((dev->start <= flash_base) && ( flash_base <= dev->end)); |
| 1706 | 698 dev=dev->next) |
| 699 ; | |
| 700 if (!dev) return CYG_FLASH_ERR_INVALID; | |
| 701 if (!dev->funs->flash_block_lock) return CYG_FLASH_ERR_INVALID; | |
|
119
77cec8369160
Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents:
117
diff
changeset
|
702 |
| 1706 | 703 #ifdef CYGPKG_KERNEL |
| 704 cyg_mutex_lock(&dev->mutex); | |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
705 #endif |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
706 if (len > (dev->end + 1 - flash_base)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
707 end_addr = dev->end; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
708 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
709 end_addr = flash_base + len - 1; |
| 1706 | 710 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
711 block = flash_block_begin(flash_base, dev); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
712 lock_count = (end_addr + 1) - block; |
| 1706 | 713 |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
714 #ifdef CYGSEM_IO_FLASH_CHATTER |
| 1706 | 715 dev->pf("... Locking from %p-%p: ", (void*)block, (void*)end_addr); |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
716 #endif |
| 1706 | 717 |
| 718 HAL_FLASH_CACHES_OFF(d_cache, i_cache); | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
719 FLASH_Enable(flash_base, end_addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
720 while (lock_count > 0) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
721 size_t block_size = flash_block_size(dev, block); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
722 if (lock_count < block_size) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
723 lock_count = block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
724 } |
| 1706 | 725 stat = dev->funs->flash_block_lock(dev,block); |
| 726 stat = dev->funs->flash_hwr_map_error(dev,stat); | |
| 727 | |
| 728 if (CYG_FLASH_ERR_OK != stat && err_address) { | |
|
1715
868c3fa9315f
* src/flash.c: Make the flock lock/unlock code compile without
asl
parents:
1706
diff
changeset
|
729 *err_address = block; |
| 1706 | 730 break; |
|
119
77cec8369160
Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents:
117
diff
changeset
|
731 } |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
732 block += block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
733 lock_count -= block_size; |
| 1706 | 734 #ifdef CYGSEM_IO_FLASH_CHATTER |
| 735 dev->pf("."); | |
| 736 #endif | |
| 737 } | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
738 FLASH_Disable(flash_base, end_addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
739 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
740 #ifdef CYGSEM_IO_FLASH_CHATTER |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
741 dev->pf("\n"); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
742 #endif |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
743 #ifdef CYGPKG_KERNEL |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
744 cyg_mutex_unlock(&dev->mutex); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
745 #endif |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
746 if (stat != CYG_FLASH_ERR_OK) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
747 return stat; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
748 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
749 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
750 // Recurse if necessary for the next device |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
751 if (len > (dev->end + 1 - flash_base)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
752 return cyg_flash_lock(dev->end+1, |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
753 len - (dev->end + 1 - flash_base), |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
754 err_address); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
755 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
756 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
757 return CYG_FLASH_ERR_OK; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
758 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
759 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
760 __externC int |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
761 cyg_flash_unlock(const cyg_flashaddr_t flash_base, |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
762 const size_t len, |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
763 cyg_flashaddr_t *err_address) |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
764 { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
765 cyg_flashaddr_t block, end_addr; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
766 struct cyg_flash_dev * dev; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
767 size_t unlock_count; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
768 int stat = CYG_FLASH_ERR_OK; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
769 int d_cache, i_cache; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
770 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
771 if (!init) return CYG_FLASH_ERR_NOT_INIT; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
772 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
773 #ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
774 if (plf_flash_query_soft_wp(addr,len)) |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
775 return CYG_FLASH_ERR_PROTECT; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
776 #endif |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
777 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
778 for (dev = flash_head; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
779 dev && !((dev->start <= flash_base) && ( flash_base <= dev->end)); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
780 dev=dev->next) |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
781 ; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
782 if (!dev) return CYG_FLASH_ERR_INVALID; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
783 if (!dev->funs->flash_block_unlock) return CYG_FLASH_ERR_INVALID; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
784 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
785 #ifdef CYGPKG_KERNEL |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
786 cyg_mutex_lock(&dev->mutex); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
787 #endif |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
788 if (len > (dev->end + 1 - flash_base)) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
789 end_addr = dev->end; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
790 } else { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
791 end_addr = flash_base + len - 1; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
792 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
793 block = flash_block_begin(flash_base, dev); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
794 unlock_count = (end_addr + 1) - block; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
795 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
796 #ifdef CYGSEM_IO_FLASH_CHATTER |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
797 dev->pf("... Unlocking from %p-%p: ", (void*)block, (void*)end_addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
798 #endif |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
799 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
800 HAL_FLASH_CACHES_OFF(d_cache, i_cache); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
801 FLASH_Enable(flash_base, end_addr); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
802 while (unlock_count > 0) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
803 size_t block_size = flash_block_size(dev, block); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
804 if (unlock_count < block_size) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
805 unlock_count = block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
806 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
807 stat = dev->funs->flash_block_unlock(dev,block); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
808 stat = dev->funs->flash_hwr_map_error(dev,stat); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
809 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
810 if (CYG_FLASH_ERR_OK != stat && err_address) { |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
811 *err_address = block; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
812 break; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
813 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
814 block += block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
815 unlock_count -= block_size; |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
816 |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
817 #ifdef CYGSEM_IO_FLASH_CHATTER |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
818 dev->pf("."); |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
819 #endif |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
820 } |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
821 FLASH_Disable(flash_base, end_addr); |
| 1706 | 822 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
823 #ifdef CYGSEM_IO_FLASH_CHATTER |
| 1706 | 824 dev->pf("\n"); |
| 825 #endif | |
| 826 #ifdef CYGPKG_KERNEL | |
| 827 cyg_mutex_unlock(&dev->mutex); | |
|
1223
dbcfe4e0dbd2
New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
210
diff
changeset
|
828 #endif |
| 1706 | 829 if (stat != CYG_FLASH_ERR_OK) { |
| 830 return stat; | |
| 831 } | |
| 832 | |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
833 // Recurse if necessary for the next device |
|
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
834 if (len > (dev->end + 1 - flash_base)) { |
| 1706 | 835 return cyg_flash_lock(dev->end+1, |
|
1741
9464c6747e99
Sort out the various loops to cope with boundary conditions,
bartv
parents:
1730
diff
changeset
|
836 len - (dev->end + 1 - flash_base), |
| 1706 | 837 err_address); |
| 838 } | |
| 839 return CYG_FLASH_ERR_OK; | |
|
119
77cec8369160
Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents:
117
diff
changeset
|
840 } |
|
77cec8369160
Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents:
117
diff
changeset
|
841 #endif |
|
77cec8369160
Merge from eCos master repository on 2000-09-01-07:47:03-BST
jlarmour
parents:
117
diff
changeset
|
842 |
| 1706 | 843 const char * |
| 844 cyg_flash_errmsg(const int err) | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
845 { |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
846 switch (err) { |
| 1706 | 847 case CYG_FLASH_ERR_OK: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
848 return "No error - operation complete"; |
| 1706 | 849 case CYG_FLASH_ERR_ERASE_SUSPEND: |
|
136
a9ac27ec7abc
Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents:
121
diff
changeset
|
850 return "Device is in erase suspend state"; |
| 1706 | 851 case CYG_FLASH_ERR_PROGRAM_SUSPEND: |
|
136
a9ac27ec7abc
Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents:
121
diff
changeset
|
852 return "Device is in program suspend state"; |
| 1706 | 853 case CYG_FLASH_ERR_INVALID: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
854 return "Invalid FLASH address"; |
| 1706 | 855 case CYG_FLASH_ERR_ERASE: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
856 return "Error trying to erase"; |
| 1706 | 857 case CYG_FLASH_ERR_LOCK: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
858 return "Error trying to lock/unlock"; |
| 1706 | 859 case CYG_FLASH_ERR_PROGRAM: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
860 return "Error trying to program"; |
| 1706 | 861 case CYG_FLASH_ERR_PROTOCOL: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
862 return "Generic error"; |
| 1706 | 863 case CYG_FLASH_ERR_PROTECT: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
864 return "Device/region is write-protected"; |
| 1706 | 865 case CYG_FLASH_ERR_NOT_INIT: |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
866 return "FLASH sub-system not initialized"; |
| 1706 | 867 case CYG_FLASH_ERR_DRV_VERIFY: |
|
143
6b5f480c6929
Merge from eCos master repository on 2000-12-08-02:09:36-GMT
jlarmour
parents:
141
diff
changeset
|
868 return "Data verify failed after operation"; |
| 1706 | 869 case CYG_FLASH_ERR_DRV_TIMEOUT: |
|
154
e2d866e32dac
Merge from eCos master repository on 2001-02-26-23:18:05-GMT
jlarmour
parents:
151
diff
changeset
|
870 return "Driver timed out waiting for device"; |
| 1706 | 871 case CYG_FLASH_ERR_DRV_WRONG_PART: |
|
154
e2d866e32dac
Merge from eCos master repository on 2001-02-26-23:18:05-GMT
jlarmour
parents:
151
diff
changeset
|
872 return "Driver does not support device"; |
| 1706 | 873 case CYG_FLASH_ERR_LOW_VOLTAGE: |
|
156
b939e9cada46
Merge from eCos master repository on 2001-03-29-21:44:39-BST
jlarmour
parents:
154
diff
changeset
|
874 return "Device reports low voltage"; |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
875 default: |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
876 return "Unknown error"; |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
877 } |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff
changeset
|
878 } |
|
151
25e238959bae
Merge from eCos master repository on 2001-02-12-23:44:24-GMT
jlarmour
parents:
143
diff
changeset
|
879 |
|
25e238959bae
Merge from eCos master repository on 2001-02-12-23:44:24-GMT
jlarmour
parents:
143
diff
changeset
|
880 // EOF io/flash/..../flash.c |
