Mercurial > flash_v2
comparison packages/io/flash/current/src/flash.c @ 141:450e4e1f1e80 ecos-sw-2000-11-27
Merge from eCos master repository on 2000-11-27-23:09:27-GMT
| author | jlarmour |
|---|---|
| date | Tue, 28 Nov 2000 00:03:34 +0000 |
| parents | a9ac27ec7abc |
| children | 6b5f480c6929 |
comparison
equal
deleted
inserted
replaced
| 140:b9721305fd46 | 141:450e4e1f1e80 |
|---|---|
| 49 #include <cyg/hal/hal_cache.h> | 49 #include <cyg/hal/hal_cache.h> |
| 50 | 50 |
| 51 #define _FLASH_PRIVATE_ | 51 #define _FLASH_PRIVATE_ |
| 52 #include <cyg/io/flash.h> | 52 #include <cyg/io/flash.h> |
| 53 | 53 |
| 54 | |
| 54 // When this flag is set, | 55 // When this flag is set, |
| 55 #undef RAM_FLASH_DEV_DEBUG | 56 #undef RAM_FLASH_DEV_DEBUG |
| 56 #if !defined(CYG_HAL_STARTUP_RAM) && defined(RAM_FLASH_DEV_DEBUG) | 57 #if !defined(CYG_HAL_STARTUP_RAM) && defined(RAM_FLASH_DEV_DEBUG) |
| 57 # warning "Can only enable the flash debugging when configured for RAM startup" | 58 # warning "Can only enable the flash debugging when configured for RAM startup" |
| 58 # undef RAM_FLASH_DEV_DEBUG | 59 # undef RAM_FLASH_DEV_DEBUG |
| 109 } | 110 } |
| 110 *block_size = flash_info.block_size; | 111 *block_size = flash_info.block_size; |
| 111 *blocks = flash_info.blocks; | 112 *blocks = flash_info.blocks; |
| 112 return FLASH_ERR_OK; | 113 return FLASH_ERR_OK; |
| 113 } | 114 } |
| 114 | |
| 115 int | 115 int |
| 116 flash_erase(void *addr, int len, void **err_addr) | 116 flash_erase(void *addr, int len, void **err_addr) |
| 117 { | 117 { |
| 118 unsigned short *block, *end_addr; | 118 unsigned short *block, *end_addr; |
| 119 int stat = 0; | 119 int stat = 0; |
| 120 extern char flash_erase_block, flash_erase_block_end; | 120 extern char flash_erase_block, flash_erase_block_end; |
| 121 int code_len; | 121 int code_len; |
| 122 typedef int code_fun(unsigned short *); | 122 typedef int code_fun(unsigned short *); |
| 123 code_fun *_flash_erase_block; | 123 code_fun *_flash_erase_block; |
| 124 int d_cache, i_cache; | |
| 124 | 125 |
| 125 if (!flash_info.init) { | 126 if (!flash_info.init) { |
| 126 return FLASH_ERR_NOT_INIT; | 127 return FLASH_ERR_NOT_INIT; |
| 127 } | 128 } |
| 128 | 129 |
| 129 // Copy 'erase' code to RAM for execution | 130 // Copy 'erase' code to RAM for execution |
| 130 code_len = (unsigned long)&flash_erase_block_end - (unsigned long)&flash_erase_block; | 131 code_len = (unsigned long)&flash_erase_block_end - (unsigned long)&flash_erase_block; |
| 131 _flash_erase_block = (code_fun *)flash_info.work_space; | 132 _flash_erase_block = (code_fun *)flash_info.work_space; |
| 132 memcpy(_flash_erase_block, &flash_erase_block, code_len); | 133 memcpy(_flash_erase_block, &flash_erase_block, code_len); |
| 133 HAL_DCACHE_SYNC(); // Should guarantee this code will run | 134 |
| 134 HAL_ICACHE_DISABLE(); // is also required to avoid old contents | 135 HAL_FLASH_CACHES_OFF(d_cache, i_cache); |
| 135 | |
| 136 block = (unsigned short *)((unsigned long)addr & flash_info.block_mask); | 136 block = (unsigned short *)((unsigned long)addr & flash_info.block_mask); |
| 137 end_addr = (unsigned short *)((unsigned long)addr+len); | 137 end_addr = (unsigned short *)((unsigned long)addr+len); |
| 138 | 138 |
| 139 printf("... Erase from %p-%p: ", block, end_addr); | 139 printf("... Erase from %p-%p: ", block, end_addr); |
| 140 | 140 |
| 149 break; | 149 break; |
| 150 } | 150 } |
| 151 block += flash_info.block_size / sizeof(*block); | 151 block += flash_info.block_size / sizeof(*block); |
| 152 printf("."); | 152 printf("."); |
| 153 } | 153 } |
| 154 HAL_ICACHE_ENABLE(); | 154 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
| 155 printf("\n"); | 155 printf("\n"); |
| 156 return (stat); | 156 return (stat); |
| 157 } | 157 } |
| 158 | 158 |
| 159 int | 159 int |
| 164 extern char flash_program_buf, flash_program_buf_end; | 164 extern char flash_program_buf, flash_program_buf_end; |
| 165 typedef int code_fun(unsigned short *, unsigned short *, int); | 165 typedef int code_fun(unsigned short *, unsigned short *, int); |
| 166 code_fun *_flash_program_buf; | 166 code_fun *_flash_program_buf; |
| 167 unsigned short *addr = (unsigned short *)_addr; | 167 unsigned short *addr = (unsigned short *)_addr; |
| 168 unsigned short *data = (unsigned short *)_data; | 168 unsigned short *data = (unsigned short *)_data; |
| 169 int d_cache, i_cache; | |
| 169 | 170 |
| 170 if (!flash_info.init) { | 171 if (!flash_info.init) { |
| 171 return FLASH_ERR_NOT_INIT; | 172 return FLASH_ERR_NOT_INIT; |
| 172 } | 173 } |
| 173 | 174 |
| 174 // Copy 'program' code to RAM for execution | 175 // Copy 'program' code to RAM for execution |
| 175 code_len = (unsigned long)&flash_program_buf_end - (unsigned long)&flash_program_buf; | 176 code_len = (unsigned long)&flash_program_buf_end - (unsigned long)&flash_program_buf; |
| 176 _flash_program_buf = (code_fun *)flash_info.work_space; | 177 _flash_program_buf = (code_fun *)flash_info.work_space; |
| 177 memcpy(_flash_program_buf, &flash_program_buf, code_len); | 178 memcpy(_flash_program_buf, &flash_program_buf, code_len); |
| 178 HAL_DCACHE_SYNC(); // Should guarantee this code will run | 179 HAL_FLASH_CACHES_OFF(d_cache, i_cache); |
| 179 HAL_ICACHE_DISABLE(); // is also required to avoid old contents | 180 |
| 180 | 181 printf("... Program from %p-%p at %p: ", data, (void*)(((unsigned long)data)+len), addr); |
| 181 printf("... Program from %p-%p at %p: ", data, ((unsigned long)data)+len, addr); | |
| 182 | 182 |
| 183 while (len > 0) { | 183 while (len > 0) { |
| 184 size = len; | 184 size = len; |
| 185 if (size > flash_info.block_size) size = flash_info.block_size; | 185 if (size > flash_info.block_size) size = flash_info.block_size; |
| 186 #ifdef RAM_FLASH_DEV_DEBUG | 186 #ifdef RAM_FLASH_DEV_DEBUG |
| 195 printf("."); | 195 printf("."); |
| 196 len -= size; | 196 len -= size; |
| 197 addr += size/sizeof(*addr); | 197 addr += size/sizeof(*addr); |
| 198 data += size/sizeof(*data); | 198 data += size/sizeof(*data); |
| 199 } | 199 } |
| 200 HAL_ICACHE_ENABLE(); | 200 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
| 201 printf("\n"); | 201 printf("\n"); |
| 202 return (stat); | 202 return (stat); |
| 203 } | 203 } |
| 204 | 204 |
| 205 #if 0 < CYGHWR_IO_FLASH_BLOCK_LOCKING // This is an *interface* | 205 #if 0 < CYGHWR_IO_FLASH_BLOCK_LOCKING // This is an *interface* |
| 211 int stat = 0; | 211 int stat = 0; |
| 212 extern char flash_lock_block, flash_lock_block_end; | 212 extern char flash_lock_block, flash_lock_block_end; |
| 213 int code_len; | 213 int code_len; |
| 214 typedef int code_fun(unsigned short *); | 214 typedef int code_fun(unsigned short *); |
| 215 code_fun *_flash_lock_block; | 215 code_fun *_flash_lock_block; |
| 216 int d_cache, i_cache; | |
| 216 | 217 |
| 217 if (!flash_info.init) { | 218 if (!flash_info.init) { |
| 218 return FLASH_ERR_NOT_INIT; | 219 return FLASH_ERR_NOT_INIT; |
| 219 } | 220 } |
| 220 | 221 |
| 221 // Copy 'lock' code to RAM for execution | 222 // Copy 'lock' code to RAM for execution |
| 222 code_len = (unsigned long)&flash_lock_block_end - (unsigned long)&flash_lock_block; | 223 code_len = (unsigned long)&flash_lock_block_end - (unsigned long)&flash_lock_block; |
| 223 _flash_lock_block = (code_fun *)flash_info.work_space; | 224 _flash_lock_block = (code_fun *)flash_info.work_space; |
| 224 memcpy(_flash_lock_block, &flash_lock_block, code_len); | 225 memcpy(_flash_lock_block, &flash_lock_block, code_len); |
| 225 HAL_DCACHE_SYNC(); // Should guarantee this code will run | 226 HAL_FLASH_CACHES_OFF(d_cache, i_cache); |
| 226 HAL_ICACHE_DISABLE(); // is also required to avoid old contents | |
| 227 | 227 |
| 228 block = (unsigned short *)((unsigned long)addr & flash_info.block_mask); | 228 block = (unsigned short *)((unsigned long)addr & flash_info.block_mask); |
| 229 end_addr = (unsigned short *)((unsigned long)addr+len); | 229 end_addr = (unsigned short *)((unsigned long)addr+len); |
| 230 | 230 |
| 231 printf("... Lock from %p-%p: ", block, end_addr); | 231 printf("... Lock from %p-%p: ", block, end_addr); |
| 241 break; | 241 break; |
| 242 } | 242 } |
| 243 block += flash_info.block_size / sizeof(*block); | 243 block += flash_info.block_size / sizeof(*block); |
| 244 printf("."); | 244 printf("."); |
| 245 } | 245 } |
| 246 HAL_ICACHE_ENABLE(); | 246 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
| 247 printf("\n"); | 247 printf("\n"); |
| 248 return (stat); | 248 return (stat); |
| 249 } | 249 } |
| 250 | 250 |
| 251 int | 251 int |
| 255 int stat = 0; | 255 int stat = 0; |
| 256 extern char flash_unlock_block, flash_unlock_block_end; | 256 extern char flash_unlock_block, flash_unlock_block_end; |
| 257 int code_len; | 257 int code_len; |
| 258 typedef int code_fun(unsigned short *, int, int); | 258 typedef int code_fun(unsigned short *, int, int); |
| 259 code_fun *_flash_unlock_block; | 259 code_fun *_flash_unlock_block; |
| 260 int d_cache, i_cache; | |
| 260 | 261 |
| 261 if (!flash_info.init) { | 262 if (!flash_info.init) { |
| 262 return FLASH_ERR_NOT_INIT; | 263 return FLASH_ERR_NOT_INIT; |
| 263 } | 264 } |
| 264 | 265 |
| 265 // Copy 'lock' code to RAM for execution | 266 // Copy 'lock' code to RAM for execution |
| 266 code_len = (unsigned long)&flash_unlock_block_end - (unsigned long)&flash_unlock_block; | 267 code_len = (unsigned long)&flash_unlock_block_end - (unsigned long)&flash_unlock_block; |
| 267 _flash_unlock_block = (code_fun *)flash_info.work_space; | 268 _flash_unlock_block = (code_fun *)flash_info.work_space; |
| 268 memcpy(_flash_unlock_block, &flash_unlock_block, code_len); | 269 memcpy(_flash_unlock_block, &flash_unlock_block, code_len); |
| 269 HAL_DCACHE_SYNC(); // Should guarantee this code will run | 270 HAL_FLASH_CACHES_OFF(d_cache, i_cache); |
| 270 HAL_ICACHE_DISABLE(); // is also required to avoid old contents | |
| 271 | 271 |
| 272 block = (unsigned short *)((unsigned long)addr & flash_info.block_mask); | 272 block = (unsigned short *)((unsigned long)addr & flash_info.block_mask); |
| 273 end_addr = (unsigned short *)((unsigned long)addr+len); | 273 end_addr = (unsigned short *)((unsigned long)addr+len); |
| 274 | 274 |
| 275 printf("... Unlock from %p-%p: ", block, end_addr); | 275 printf("... Unlock from %p-%p: ", block, end_addr); |
| 285 break; | 285 break; |
| 286 } | 286 } |
| 287 block += flash_info.block_size / sizeof(*block); | 287 block += flash_info.block_size / sizeof(*block); |
| 288 printf("."); | 288 printf("."); |
| 289 } | 289 } |
| 290 HAL_ICACHE_ENABLE(); | 290 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
| 291 printf("\n"); | 291 printf("\n"); |
| 292 return (stat); | 292 return (stat); |
| 293 } | 293 } |
| 294 #endif | 294 #endif |
| 295 | 295 |
