Mercurial > ecos
comparison packages/devs/flash/arm/sa1100mm/current/src/sa1100mm_flash.c @ 134:d2f49caf9e38 ecos-sw-2000-11-03
Merge from eCos master repository on 2000-11-03-09:00:49-GMT
| author | jlarmour |
|---|---|
| date | Fri, 03 Nov 2000 21:17:40 +0000 |
| parents | |
| children | 6b5f480c6929 |
comparison
equal
deleted
inserted
replaced
| 133:98d71f4d8243 | 134:d2f49caf9e38 |
|---|---|
| 1 //========================================================================== | |
| 2 // | |
| 3 // sa1100mm_flash.c | |
| 4 // | |
| 5 // Flash programming | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
| 9 // | |
| 10 // ------------------------------------------- | |
| 11 // The contents of this file are subject to the Red Hat eCos Public License | |
| 12 // Version 1.1 (the "License"); you may not use this file except in | |
| 13 // compliance with the License. You may obtain a copy of the License at | |
| 14 // http://www.redhat.com/ | |
| 15 // | |
| 16 // Software distributed under the License is distributed on an "AS IS" | |
| 17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 18 // License for the specific language governing rights and limitations under | |
| 19 // the License. | |
| 20 // | |
| 21 // The Original Code is eCos - Embedded Configurable Operating System, | |
| 22 // released September 30, 1998. | |
| 23 // | |
| 24 // The Initial Developer of the Original Code is Red Hat. | |
| 25 // Portions created by Red Hat are | |
| 26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | |
| 27 // All Rights Reserved. | |
| 28 // ------------------------------------------- | |
| 29 // | |
| 30 //####COPYRIGHTEND#### | |
| 31 //========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): gthomas | |
| 35 // Contributors: gthomas, dmoseley | |
| 36 // Date: 2000-07-26 | |
| 37 // Purpose: | |
| 38 // Description: | |
| 39 // | |
| 40 //####DESCRIPTIONEND#### | |
| 41 // | |
| 42 //========================================================================== | |
| 43 | |
| 44 #include <pkgconf/hal.h> | |
| 45 #include <cyg/hal/hal_arch.h> | |
| 46 #include <cyg/hal/hal_cache.h> | |
| 47 | |
| 48 #define _FLASH_PRIVATE_ | |
| 49 #include <cyg/io/flash.h> | |
| 50 | |
| 51 #include "flash.h" | |
| 52 | |
| 53 int | |
| 54 flash_hwr_init(void) | |
| 55 { | |
| 56 unsigned char data[96]; | |
| 57 extern char flash_query, flash_query_end; | |
| 58 typedef int code_fun(unsigned char *); | |
| 59 code_fun *_flash_query; | |
| 60 int code_len, stat, num_regions, region_size; | |
| 61 | |
| 62 // Copy 'program' code to RAM for execution | |
| 63 code_len = (unsigned long)&flash_query_end - (unsigned long)&flash_query; | |
| 64 _flash_query = (code_fun *)flash_info.work_space; | |
| 65 memcpy(_flash_query, &flash_query, code_len); | |
| 66 HAL_DCACHE_SYNC(); // Should guarantee this code will run | |
| 67 HAL_ICACHE_DISABLE(); // is also required to avoid old contents | |
| 68 | |
| 69 stat = (*_flash_query)(data); | |
| 70 | |
| 71 HAL_ICACHE_ENABLE(); | |
| 72 | |
| 73 if ((data[0] == FLASH_Intel_code) && | |
| 74 (data[4] == FLASH_28F016SV_low) && | |
| 75 (data[5] == FLASH_28F016SV_hi)) { | |
| 76 num_regions = 32; | |
| 77 region_size = 0x20000; | |
| 78 flash_info.block_size = region_size; | |
| 79 flash_info.blocks = num_regions; | |
| 80 flash_info.start = (void *)0x08000000; | |
| 81 flash_info.end = (void *)(0x08000000+(num_regions*region_size)); | |
| 82 return FLASH_ERR_OK; | |
| 83 } else { | |
| 84 printf("Can't identify FLASH, sorry\n"); | |
| 85 diag_dump_buf(data, sizeof(data)); | |
| 86 return FLASH_ERR_HWR; | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 // Map a hardware status to a package error | |
| 91 int | |
| 92 flash_hwr_map_error(int err) | |
| 93 { | |
| 94 if (err & 0x7E) { | |
| 95 if (err & 0x10) { | |
| 96 return FLASH_ERR_PROGRAM; | |
| 97 } else | |
| 98 if (err & 0x20) { | |
| 99 return FLASH_ERR_ERASE; | |
| 100 } else | |
| 101 return FLASH_ERR_HWR; // FIXME | |
| 102 } else { | |
| 103 return FLASH_ERR_OK; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 // See if a range of FLASH addresses overlaps currently running code | |
| 108 bool | |
| 109 flash_code_overlaps(void *start, void *end) | |
| 110 { | |
| 111 extern char _stext, _etext; | |
| 112 | |
| 113 return ((((unsigned long)&_stext >= (unsigned long)start) && | |
| 114 ((unsigned long)&_stext < (unsigned long)end)) || | |
| 115 (((unsigned long)&_etext >= (unsigned long)start) && | |
| 116 ((unsigned long)&_etext < (unsigned long)end))); | |
| 117 } |
