1 | /************************************************************************** |
---|
2 | * |
---|
3 | * Copyright (c) 2013 Alcatel-Lucent |
---|
4 | * |
---|
5 | * Alcatel Lucent licenses this file to You under the Apache License, |
---|
6 | * Version 2.0 (the "License"); you may not use this file except in |
---|
7 | * compliance with the License. A copy of the License is contained the |
---|
8 | * file LICENSE at the top level of this repository. |
---|
9 | * You may also obtain a copy of the License at: |
---|
10 | * |
---|
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
12 | * |
---|
13 | * Unless required by applicable law or agreed to in writing, software |
---|
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
16 | * See the License for the specific language governing permissions and |
---|
17 | * limitations under the License. |
---|
18 | * |
---|
19 | ************************************************************************** |
---|
20 | * |
---|
21 | * flash.h: |
---|
22 | * |
---|
23 | * Device-independent macros and data structures used by flash driver. |
---|
24 | * |
---|
25 | * Original author: Ed Sutter (ed.sutter@alcatel-lucent.com) |
---|
26 | * |
---|
27 | */ |
---|
28 | #ifndef _FLASH_H_ |
---|
29 | #define _FLASH_H_ |
---|
30 | |
---|
31 | #define FLASH_PROTECT_WINDOW_CLOSED 0 |
---|
32 | #define ALL_SECTORS -1 |
---|
33 | |
---|
34 | #ifndef FLASH_LOOP_TIMEOUT |
---|
35 | #define FLASH_LOOP_TIMEOUT 1000000 |
---|
36 | #endif |
---|
37 | |
---|
38 | #define FLASH_LOCK 1 |
---|
39 | #define FLASH_UNLOCK 2 |
---|
40 | #define FLASH_LOCKDWN 3 |
---|
41 | #define FLASH_LOCKQRY 4 |
---|
42 | #define FLASH_LOCKABLE 5 /* query driver for lock support */ |
---|
43 | |
---|
44 | /* Device ID used for ram that is "pretending" to be a flash bank. */ |
---|
45 | #define FLASHRAM 0x9999 |
---|
46 | |
---|
47 | struct flashdesc { |
---|
48 | unsigned long id; /* manufacturer & device id */ |
---|
49 | char *desc; /* ascii string */ |
---|
50 | }; |
---|
51 | |
---|
52 | struct sectorinfo { |
---|
53 | long size; /* size of sector */ |
---|
54 | int snum; /* number of sector (amongst possibly */ |
---|
55 | /* several devices) */ |
---|
56 | int protected; /* if set, sector is protected by window */ |
---|
57 | unsigned char *begin; /* base address of sector */ |
---|
58 | unsigned char *end; /* end address of sector */ |
---|
59 | }; |
---|
60 | |
---|
61 | struct flashinfo { |
---|
62 | unsigned long id; /* manufacturer & device id */ |
---|
63 | unsigned char *base; /* base address of device */ |
---|
64 | unsigned char *end; /* end address of device */ |
---|
65 | int sectorcnt; /* number of sectors */ |
---|
66 | int width; /* 1, 2, or 4 */ |
---|
67 | int (*fltype)(struct flashinfo *); |
---|
68 | int (*flerase)(struct flashinfo *, int); |
---|
69 | #if INCLUDE_FLASHREAD |
---|
70 | int (*flread)(struct flashinfo *,unsigned char *,\ |
---|
71 | unsigned char *,long); |
---|
72 | #endif |
---|
73 | int (*flwrite)(struct flashinfo *,unsigned char *,\ |
---|
74 | unsigned char *,long); |
---|
75 | int (*flewrite)(struct flashinfo *,unsigned char *,\ |
---|
76 | unsigned char *,long); |
---|
77 | int (*fllock)(struct flashinfo *,int,int); |
---|
78 | struct sectorinfo *sectors; |
---|
79 | }; |
---|
80 | |
---|
81 | extern int FlashTrace; |
---|
82 | extern int FlashProtectWindow; |
---|
83 | extern int FlashCurrentBank; |
---|
84 | extern struct flashinfo FlashBank[FLASHBANKS]; |
---|
85 | extern int flashopload(unsigned long *begin,unsigned long *end, \ |
---|
86 | unsigned long *copy,int size); |
---|
87 | |
---|
88 | extern int showflashtype(unsigned long, int); |
---|
89 | extern int showflashinfo(char *); |
---|
90 | extern int flashopload(unsigned long *,unsigned long *,unsigned long *,int); |
---|
91 | extern int flashtype(struct flashinfo *); |
---|
92 | extern int flasherase(int snum); |
---|
93 | extern int flashwrite(struct flashinfo *,unsigned char *,unsigned char *,long); |
---|
94 | extern int flashewrite(unsigned char *,unsigned char *,long); |
---|
95 | extern int flasherased(unsigned char *,unsigned char *); |
---|
96 | extern int flashlock(int, int); |
---|
97 | extern int flashlocked(int, int); |
---|
98 | extern int addrtosector(unsigned char *,int *,int *,unsigned char **); |
---|
99 | extern struct flashinfo *snumtofdev(int); |
---|
100 | extern struct flashinfo *addrtobank(unsigned char *); |
---|
101 | extern int sectortoaddr(int,int *,unsigned char **); |
---|
102 | extern int flashbankinfo(int,unsigned char **,unsigned char **,int *); |
---|
103 | extern void LowerFlashProtectWindow(void); |
---|
104 | extern int AppFlashWrite(unsigned char *,unsigned char *,long); |
---|
105 | extern int AppFlashEraseAll(void); |
---|
106 | extern int AppFlashErase(int); |
---|
107 | extern int srange(char *,int *,int *); |
---|
108 | extern int sectorProtect(char *,int); |
---|
109 | extern int FlashOpNotSupported(void); |
---|
110 | extern int FlashLockNotSupported(struct flashinfo *,int,int); |
---|
111 | extern int lastlargesector(int,unsigned char *,int,int *,int *,unsigned char **); |
---|
112 | extern int lastflashsector(void); |
---|
113 | extern int FlashRamInit(int, int, struct flashinfo *,struct sectorinfo *,int *); |
---|
114 | extern int InFlashSpace(unsigned char *begin, int size); |
---|
115 | extern int FlashOpOverride(void *flashinfo,int get,int bank); |
---|
116 | |
---|
117 | #define NotAligned16(add) ((long)add & 1) |
---|
118 | #define NotAligned32(add) ((long)add & 3) |
---|
119 | |
---|
120 | #ifdef FLASHRAM_BASE |
---|
121 | extern int ramSectors[]; |
---|
122 | extern struct sectorinfo sinfoRAM[]; |
---|
123 | #endif |
---|
124 | |
---|
125 | #endif |
---|