1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#ifndef _FLASH_H_
25#define _FLASH_H_
26
27#ifndef CONFIG_SYS_NO_FLASH
28
29
30
31
32typedef struct {
33 ulong size;
34 ushort sector_count;
35 ulong flash_id;
36 ulong start[CONFIG_SYS_MAX_FLASH_SECT];
37 uchar protect[CONFIG_SYS_MAX_FLASH_SECT];
38#ifdef CONFIG_SYS_FLASH_CFI
39 uchar portwidth;
40 uchar chipwidth;
41 ushort buffer_size;
42 ulong erase_blk_tout;
43 ulong write_tout;
44 ulong buffer_write_tout;
45 ushort vendor;
46 ushort cmd_reset;
47 ushort interface;
48 ushort legacy_unlock;
49 ushort manufacturer_id;
50 ushort device_id;
51 ushort device_id2;
52 ushort ext_addr;
53 ushort cfi_version;
54 ushort cfi_offset;
55 ulong addr_unlock1;
56 ulong addr_unlock2;
57 const char *name;
58#endif
59} flash_info_t;
60
61typedef unsigned long flash_sect_t;
62
63
64
65
66#define FLASH_CFI_8BIT 0x01
67#define FLASH_CFI_16BIT 0x02
68#define FLASH_CFI_32BIT 0x04
69#define FLASH_CFI_64BIT 0x08
70
71
72
73#define FLASH_CFI_BY8 0x01
74#define FLASH_CFI_BY16 0x02
75#define FLASH_CFI_BY32 0x04
76#define FLASH_CFI_BY64 0x08
77
78#define CFI_FLASH_SHIFT_WIDTH 3
79
80
81
82#define FLASH_CFI_X8 0x00
83#define FLASH_CFI_X16 0x01
84#define FLASH_CFI_X8X16 0x02
85#define FLASH_CFI_X16X32 0x05
86
87
88#define CFI_FLASH_SHIFT_WIDTH 3
89
90
91
92extern unsigned long flash_init (void);
93extern void flash_print_info (flash_info_t *);
94extern int flash_erase (flash_info_t *, int, int);
95extern int flash_sect_erase (ulong addr_first, ulong addr_last);
96extern int flash_sect_protect (int flag, ulong addr_first, ulong addr_last);
97extern int flash_sect_roundb (ulong *addr);
98extern unsigned long flash_sector_size(flash_info_t *info, flash_sect_t sect);
99extern void flash_set_verbose(uint);
100
101
102extern void flash_protect (int flag, ulong from, ulong to, flash_info_t *info);
103extern int flash_write (char *, ulong, ulong);
104extern flash_info_t *addr2info (ulong);
105extern int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt);
106
107
108#ifdef CONFIG_FLASH_CFI_MTD
109extern int cfi_mtd_init(void);
110#endif
111
112
113#if defined(CONFIG_SYS_FLASH_PROTECTION)
114extern int flash_real_protect(flash_info_t *info, long sector, int prot);
115extern void flash_read_user_serial(flash_info_t * info, void * buffer, int offset, int len);
116extern void flash_read_factory_serial(flash_info_t * info, void * buffer, int offset, int len);
117#endif
118
119#ifdef CONFIG_FLASH_CFI_LEGACY
120extern ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info);
121extern int jedec_flash_match(flash_info_t *info, ulong base);
122#define CFI_CMDSET_AMD_LEGACY 0xFFF0
123#endif
124
125#if defined(CONFIG_SYS_FLASH_CFI)
126extern flash_info_t *flash_get_info(ulong base);
127#endif
128
129
130
131
132#define ERR_OK 0
133#define ERR_TIMOUT 1
134#define ERR_NOT_ERASED 2
135#define ERR_PROTECTED 4
136#define ERR_INVAL 8
137#define ERR_ALIGN 16
138#define ERR_UNKNOWN_FLASH_VENDOR 32
139#define ERR_UNKNOWN_FLASH_TYPE 64
140#define ERR_PROG_ERROR 128
141
142
143
144
145#define FLAG_PROTECT_SET 0x01
146#define FLAG_PROTECT_CLEAR 0x02
147#define FLAG_PROTECT_INVALID 0x03
148
149
150
151#define FLAG_SETENV 0x80
152
153
154
155
156
157
158#define AMD_MANUFACT 0x00010001
159#define FUJ_MANUFACT 0x00040004
160#define ATM_MANUFACT 0x001F001F
161#define STM_MANUFACT 0x00200020
162#define SST_MANUFACT 0x00BF00BF
163#define MT_MANUFACT 0x00890089
164#define INTEL_MANUFACT 0x00890089
165#define INTEL_ALT_MANU 0x00B000B0
166#define MX_MANUFACT 0x00C200C2
167#define TOSH_MANUFACT 0x00980098
168#define MT2_MANUFACT 0x002C002C
169#define EXCEL_MANUFACT 0x004A004A
170#define AMIC_MANUFACT 0x00370037
171#define WINB_MANUFACT 0x00DA00DA
172
173
174#define EON_MANUFACT 0x011C011C
175
176
177
178
179#define MT_ID_28F400_T 0x44704470
180#define MT_ID_28F400_B 0x44714471
181
182#define AMD_ID_LV040B 0x4F
183
184
185#define AMD_ID_F033C 0xA3
186
187
188#define AMD_ID_F065D 0x93
189
190
191#define ATM_ID_LV040 0x13
192
193
194#define AMD_ID_F040B 0xA4
195
196
197#define STM_ID_M29W040B 0xE3
198
199
200#define AMD_ID_F080B 0xD5
201
202
203#define AMD_ID_F016D 0xAD
204#define AMD_ID_F032B 0x41
205#define AMD_ID_LV116DT 0xC7
206#define AMD_ID_LV116DB 0x4C
207#define AMD_ID_LV016B 0xc8
208
209#define AMD_ID_PL160CB 0x22452245
210
211#define AMD_ID_LV400T 0x22B922B9
212#define AMD_ID_LV400B 0x22BA22BA
213
214#define AMD_ID_LV033C 0xA3
215#define AMD_ID_LV065D 0x93
216
217#define AMD_ID_LV800T 0x22DA22DA
218#define AMD_ID_LV800B 0x225B225B
219
220#define AMD_ID_LV160T 0x22C422C4
221#define AMD_ID_LV160B 0x22492249
222
223#define AMD_ID_DL163T 0x22282228
224#define AMD_ID_DL163B 0x222B222B
225
226#define AMD_ID_LV320T 0x22F622F6
227#define MX_ID_LV320T 0x22A722A7
228#define AMD_ID_LV320B 0x22F922F9
229#define MX_ID_LV320B 0x22A822A8
230
231#define AMD_ID_DL322T 0x22552255
232#define AMD_ID_DL322B 0x22562256
233#define AMD_ID_DL323T 0x22502250
234#define AMD_ID_DL323B 0x22532253
235#define AMD_ID_DL324T 0x225C225C
236#define AMD_ID_DL324B 0x225F225F
237
238#define AMD_ID_DL640 0x227E227E
239#define AMD_ID_MIRROR 0x227E227E
240#define AMD_ID_DL640G_2 0x22022202
241#define AMD_ID_DL640G_3 0x22012201
242#define AMD_ID_LV640U_2 0x220C220C
243#define AMD_ID_LV640U_3 0x22012201
244#define AMD_ID_LV640MT_2 0x22102210
245#define AMD_ID_LV640MT_3 0x22012201
246#define AMD_ID_LV640MB_2 0x22102210
247#define AMD_ID_LV640MB_3 0x22002200
248#define AMD_ID_LV128U_2 0x22122212
249#define AMD_ID_LV128U_3 0x22002200
250#define AMD_ID_LV256U_2 0x22122212
251#define AMD_ID_LV256U_3 0x22012201
252#define AMD_ID_GL064M_2 0x22132213
253#define AMD_ID_GL064M_3 0x22012201
254#define AMD_ID_GL064MT_2 0x22102210
255#define AMD_ID_GL064MT_3 0x22012201
256#define AMD_ID_GL128N_2 0x22212221
257#define AMD_ID_GL128N_3 0x22012201
258
259
260#define AMD_ID_LV320B_2 0x221A221A
261#define AMD_ID_LV320B_3 0x22002200
262
263#define AMD_ID_LV640U 0x22D722D7
264#define AMD_ID_LV650U 0x22D722D7
265
266#define ATM_ID_BV1614 0x000000C0
267#define ATM_ID_BV1614A 0x000000C8
268#define ATM_ID_BV6416 0x000000D6
269
270#define FUJI_ID_29F800BA 0x22582258
271#define FUJI_ID_29F800TA 0x22D622D6
272#define FUJI_ID_29LV650UE 0x22d722d7
273
274#define SST_ID_xF200A 0x27892789
275#define SST_ID_xF400A 0x27802780
276#define SST_ID_xF800A 0x27812781
277#define SST_ID_xF160A 0x27822782
278#define SST_ID_xF1601 0x234B234B
279#define SST_ID_xF1602 0x234A234A
280#define SST_ID_xF3201 0x235B235B
281#define SST_ID_xF3202 0x235A235A
282#define SST_ID_xF6401 0x236B236B
283#define SST_ID_xF6402 0x236A236A
284#define SST_ID_xF020 0xBFD6BFD6
285#define SST_ID_xF040 0xBFD7BFD7
286
287#define STM_ID_F040B 0xE2
288
289
290#define STM_ID_x800AB 0x005B005B
291#define STM_ID_29W320DT 0x22CA22CA
292#define STM_ID_29W320DB 0x22CB22CB
293#define STM_ID_29W320ET 0x22562256
294#define STM_ID_29W320EB 0x22572257
295#define STM_ID_29W040B 0x00E300E3
296#define FLASH_PSD4256GV 0x00E9
297
298#define INTEL_ID_28F016S 0x66a066a0
299#define INTEL_ID_28F800B3T 0x88928892
300#define INTEL_ID_28F800B3B 0x88938893
301#define INTEL_ID_28F160B3T 0x88908890
302#define INTEL_ID_28F160B3B 0x88918891
303#define INTEL_ID_28F320B3T 0x88968896
304#define INTEL_ID_28F320B3B 0x88978897
305#define INTEL_ID_28F640B3T 0x88988898
306#define INTEL_ID_28F640B3B 0x88998899
307#define INTEL_ID_28F160F3B 0x88F488F4
308
309#define INTEL_ID_28F800C3T 0x88C088C0
310#define INTEL_ID_28F800C3B 0x88C188C1
311#define INTEL_ID_28F160C3T 0x88C288C2
312#define INTEL_ID_28F160C3B 0x88C388C3
313#define INTEL_ID_28F320C3T 0x88C488C4
314#define INTEL_ID_28F320C3B 0x88C588C5
315#define INTEL_ID_28F640C3T 0x88CC88CC
316#define INTEL_ID_28F640C3B 0x88CD88CD
317
318#define INTEL_ID_28F128J3 0x89188918
319#define INTEL_ID_28F320J5 0x00140014
320#define INTEL_ID_28F640J5 0x00150015
321#define INTEL_ID_28F320J3A 0x00160016
322#define INTEL_ID_28F640J3A 0x00170017
323#define INTEL_ID_28F128J3A 0x00180018
324#define INTEL_ID_28F256J3A 0x001D001D
325#define INTEL_ID_28F256L18T 0x880D880D
326#define INTEL_ID_28F64K3 0x88018801
327#define INTEL_ID_28F128K3 0x88028802
328#define INTEL_ID_28F256K3 0x88038803
329#define INTEL_ID_28F64P30T 0x88178817
330#define INTEL_ID_28F64P30B 0x881A881A
331#define INTEL_ID_28F128P30T 0x88188818
332#define INTEL_ID_28F128P30B 0x881B881B
333#define INTEL_ID_28F256P30T 0x88198819
334#define INTEL_ID_28F256P30B 0x881C881C
335
336#define INTEL_ID_28F160S3 0x00D000D0
337#define INTEL_ID_28F320S3 0x00D400D4
338
339
340#define SHARP_ID_28F016SCL 0xAAAAAAAA
341#define SHARP_ID_28F016SCZ 0xA0A0A0A0
342#define SHARP_ID_28F008SC 0xA6A6A6A6
343
344
345#define TOSH_ID_FVT160 0xC2
346#define TOSH_ID_FVB160 0x43
347#define PHILIPS_LPC2292 0x0401FF13
348
349
350
351
352
353
354
355#define FLASH_AM040 0x0001
356
357
358
359
360
361#define FLASH_AM400T 0x0002
362#define FLASH_AM400B 0x0003
363#define FLASH_AM800T 0x0004
364#define FLASH_AM800B 0x0005
365#define FLASH_AM116DT 0x0026
366#define FLASH_AM116DB 0x0027
367#define FLASH_AM160T 0x0006
368#define FLASH_AM160LV 0x0046
369#define FLASH_AM160B 0x0007
370#define FLASH_AM320T 0x0008
371#define FLASH_AM320B 0x0009
372
373#define FLASH_AM080 0x000A
374
375
376#define FLASH_AMDL322T 0x0010
377#define FLASH_AMDL322B 0x0011
378#define FLASH_AMDL323T 0x0012
379#define FLASH_AMDL323B 0x0013
380#define FLASH_AMDL324T 0x0014
381#define FLASH_AMDL324B 0x0015
382
383#define FLASH_AMDLV033C 0x0018
384#define FLASH_AMDLV065D 0x001A
385
386#define FLASH_AMDL640 0x0016
387#define FLASH_AMD016 0x0018
388#define FLASH_AMDL640MB 0x0019
389#define FLASH_AMDL640MT 0x001A
390
391#define FLASH_SST200A 0x0040
392#define FLASH_SST400A 0x0042
393#define FLASH_SST800A 0x0044
394#define FLASH_SST160A 0x0046
395#define FLASH_SST320 0x0048
396#define FLASH_SST640 0x004A
397#define FLASH_SST020 0x0024
398#define FLASH_SST040 0x000E
399
400#define FLASH_STM800AB 0x0051
401#define FLASH_STMW320DT 0x0052
402#define FLASH_STMW320DB 0x0053
403#define FLASH_STM320DB 0x00CB
404#define FLASH_STM800DT 0x00D7
405#define FLASH_STM800DB 0x005B
406
407#define FLASH_28F400_T 0x0062
408#define FLASH_28F400_B 0x0063
409
410#define FLASH_INTEL800T 0x0074
411#define FLASH_INTEL800B 0x0075
412#define FLASH_INTEL160T 0x0076
413#define FLASH_INTEL160B 0x0077
414#define FLASH_INTEL320T 0x0078
415#define FLASH_INTEL320B 0x0079
416#define FLASH_INTEL640T 0x007A
417#define FLASH_INTEL640B 0x007B
418
419#define FLASH_28F008S5 0x0080
420#define FLASH_28F016SV 0x0081
421#define FLASH_28F800_B 0x0083
422#define FLASH_AM29F800B 0x0084
423#define FLASH_28F320J5 0x0085
424#define FLASH_28F160S3 0x0086
425#define FLASH_28F320S3 0x0088
426#define FLASH_AM640U 0x0090
427#define FLASH_AM033C 0x0091
428#define FLASH_LH28F016SCT 0x0092
429#define FLASH_28F160F3B 0x0093
430#define FLASH_AM065D 0x0093
431
432#define FLASH_28F640J5 0x0099
433
434#define FLASH_28F800C3T 0x009A
435#define FLASH_28F800C3B 0x009B
436#define FLASH_28F160C3T 0x009C
437#define FLASH_28F160C3B 0x009D
438#define FLASH_28F320C3T 0x009E
439#define FLASH_28F320C3B 0x009F
440#define FLASH_28F640C3T 0x00A0
441#define FLASH_28F640C3B 0x00A1
442#define FLASH_AMLV320U 0x00A2
443
444#define FLASH_AM033 0x00A3
445#define FLASH_AM065 0x0093
446#define FLASH_AT040 0x00A5
447
448#define FLASH_AMLV640U 0x00A4
449#define FLASH_AMLV128U 0x00A6
450#define FLASH_AMLV320B 0x00A7
451#define FLASH_AMLV320T 0x00A8
452#define FLASH_AMLV256U 0x00AA
453#define FLASH_MXLV320B 0x00AB
454#define FLASH_MXLV320T 0x00AC
455#define FLASH_28F256L18T 0x00B0
456#define FLASH_AMDL163T 0x00B2
457#define FLASH_AMDL163B 0x00B3
458#define FLASH_28F64K3 0x00B4
459#define FLASH_28F128K3 0x00B6
460#define FLASH_28F256K3 0x00B8
461
462#define FLASH_28F320J3A 0x00C0
463#define FLASH_28F640J3A 0x00C2
464#define FLASH_28F128J3A 0x00C4
465#define FLASH_28F256J3A 0x00C6
466
467#define FLASH_FUJLV650 0x00D0
468#define FLASH_MT28S4M16LC 0x00E1
469#define FLASH_S29GL064M 0x00F0
470#define FLASH_S29GL128N 0x00F1
471
472#define FLASH_UNKNOWN 0xFFFF
473
474
475
476
477#define FLASH_MAN_AMD 0x00000000
478#define FLASH_MAN_FUJ 0x00010000
479#define FLASH_MAN_BM 0x00020000
480#define FLASH_MAN_MX 0x00030000
481#define FLASH_MAN_STM 0x00040000
482#define FLASH_MAN_TOSH 0x00050000
483#define FLASH_MAN_EXCEL 0x00060000
484#define FLASH_MAN_SST 0x00100000
485#define FLASH_MAN_INTEL 0x00300000
486#define FLASH_MAN_MT 0x00400000
487#define FLASH_MAN_SHARP 0x00500000
488#define FLASH_MAN_ATM 0x00600000
489#define FLASH_MAN_CFI 0x01000000
490
491
492#define FLASH_TYPEMASK 0x0000FFFF
493#define FLASH_VENDMASK 0xFFFF0000
494
495#define FLASH_AMD_COMP 0x000FFFFF
496
497
498
499#define FLASH_BTYPE 0x0001
500
501
502
503
504
505
506
507#define FLASH_ERASE_TIMEOUT 120000
508#define FLASH_WRITE_TIMEOUT 500
509
510#endif
511
512#endif
513