comparison packages/devs/flash/intel/bootblock/current/src/bootblock_flash.c @ 136:a9ac27ec7abc ecos-sw-2000-11-17

Merge from eCos master repository on 2000-11-17-18:24:25-GMT
author jlarmour
date Fri, 17 Nov 2000 23:16:43 +0000
parents
children 289bf90c6a9b
comparison
equal deleted inserted replaced
135:3bc2abeae9ff 136:a9ac27ec7abc
1 //==========================================================================
2 //
3 // bootblock_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, jskov
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 #define _si(p) ((p[0]<<8)|p[1])
54
55 #define DEBUG 0
56
57 int
58 flash_hwr_init(void)
59 {
60 unsigned short data[4];
61 extern char flash_query, flash_query_end;
62 typedef int code_fun(unsigned char *);
63 code_fun *_flash_query;
64 int code_len, stat, num_regions, region_size;
65
66 // Copy 'program' code to RAM for execution
67 code_len = (unsigned long)&flash_query_end - (unsigned long)&flash_query;
68 _flash_query = (code_fun *)flash_info.work_space;
69 memcpy(_flash_query, &flash_query, code_len);
70 HAL_DCACHE_SYNC(); // Should guarantee this code will run
71
72 stat = (*_flash_query)(data);
73 #if DEBUG
74 printf("stat = %x\n", stat);
75 dump_buf(data, sizeof(data));
76 #endif
77
78 if (data[0] != FLASH_Intel_code) {
79 printf("Not Intel = %x\n", data[0]);
80 return FLASH_ERR_HWR;
81 }
82
83 // FIXME: More devices, comments, etc
84 if (data[1] == (unsigned short)0x8897) {
85 num_regions = 64*2;
86 region_size = 0x20000;
87 } else if (data[1] == (unsigned short)0x88f4) {
88 num_regions = 32*4; // 4 devices in serial, each having 32 regions
89 region_size = 0x10000;
90 } else {
91 printf("Unknown device type: %x\n", data[1]);
92 return FLASH_ERR_HWR;
93 }
94
95 // Hard wired for now FIXME
96 flash_info.block_size = region_size;
97 flash_info.blocks = num_regions;
98 flash_info.start = (void *)0;//0x10000000 FIXME;
99 flash_info.end = (void *)(0x10000000+(num_regions*region_size));
100 return FLASH_ERR_OK;
101 }
102
103 // Map a hardware status to a package error
104 int
105 flash_hwr_map_error(int err)
106 {
107 if (err & 0x007E007E) {
108 printf("Err = %x\n", err);
109 if (err & 0x00400040) {
110 return FLASH_ERR_ERASE_SUSPEND;
111 } else
112 if (err & 0x00040004) {
113 return FLASH_ERR_PROGRAM_SUSPEND;
114 } else
115 if (err & 0x00020002) {
116 return FLASH_ERR_PROTECT;
117 } else
118 if (err & 0x00100010) {
119 return FLASH_ERR_PROGRAM;
120 } else
121 if (err & 0x00200020) {
122 return FLASH_ERR_ERASE;
123 } else
124 return FLASH_ERR_HWR; // FIXME
125 } else {
126 return FLASH_ERR_OK;
127 }
128 }
129
130 // See if a range of FLASH addresses overlaps currently running code
131 bool
132 flash_code_overlaps(void *start, void *end)
133 {
134 extern char _stext, _etext;
135
136 return ((((unsigned long)&_stext >= (unsigned long)start) &&
137 ((unsigned long)&_stext < (unsigned long)end)) ||
138 (((unsigned long)&_etext >= (unsigned long)start) &&
139 ((unsigned long)&_etext < (unsigned long)end)));
140 }