blob: b5058b3abe77dbea84488f03a8b32225f3004653 [file] [log] [blame]
wdenk452cfd62002-11-19 11:04:11 +00001/*
2 * (C) Copyright 2001
3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
4 *
5 * (C) Copyright 2002
6 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27#include <common.h>
28#include <flash.h>
29#include <asm/io.h>
30#include <memio.h>
31
32/*---------------------------------------------------------------------*/
33#undef DEBUG_FLASH
wdenk452cfd62002-11-19 11:04:11 +000034
35#ifdef DEBUG_FLASH
wdenk874ac262003-07-24 23:38:38 +000036#define DEBUGF(fmt,args...) printf(fmt ,##args)
wdenk452cfd62002-11-19 11:04:11 +000037#else
38#define DEBUGF(fmt,args...)
39#endif
40/*---------------------------------------------------------------------*/
41
Marian Balakowicz513b4a12005-10-11 19:09:42 +020042flash_info_t flash_info[];
wdenk452cfd62002-11-19 11:04:11 +000043
44static ulong flash_get_size (ulong addr, flash_info_t *info);
45static int flash_get_offsets (ulong base, flash_info_t *info);
46static int write_word (flash_info_t *info, ulong dest, ulong data);
47static void flash_reset (ulong addr);
48
49int flash_xd_nest;
50
51static void flash_to_xd(void)
52{
53 unsigned char x;
54
55 flash_xd_nest ++;
56
57 if (flash_xd_nest == 1)
58 {
59 DEBUGF("Flash on XD\n");
60 x = pci_read_cfg_byte(0, 0, 0x74);
61 pci_write_cfg_byte(0, 0, 0x74, x|1);
62 }
63}
64
65static void flash_to_mem(void)
66{
67 unsigned char x;
68
69 flash_xd_nest --;
wdenk57b2d802003-06-27 21:31:46 +000070
wdenk452cfd62002-11-19 11:04:11 +000071 if (flash_xd_nest == 0)
72 {
73 DEBUGF("Flash on memory bus\n");
74 x = pci_read_cfg_byte(0, 0, 0x74);
75 pci_write_cfg_byte(0, 0, 0x74, x&0xFE);
76 }
77}
78
79unsigned long flash_init_old(void)
80{
81 int i;
82
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020083 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++)
wdenk452cfd62002-11-19 11:04:11 +000084 {
85 flash_info[i].flash_id = FLASH_UNKNOWN;
86 flash_info[i].sector_count = 0;
87 flash_info[i].size = 0;
88 }
89
90
91 return 1;
92}
93
94unsigned long flash_init (void)
95{
96 unsigned int i;
97 unsigned long flash_size = 0;
98
99 flash_xd_nest = 0;
100
101 flash_to_xd();
102
103 /* Init: no FLASHes known */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200104 for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
wdenk452cfd62002-11-19 11:04:11 +0000105 flash_info[i].flash_id = FLASH_UNKNOWN;
106 flash_info[i].sector_count = 0;
107 flash_info[i].size = 0;
108 }
109
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200110 DEBUGF("\n## Get flash size @ 0x%08x\n", CONFIG_SYS_FLASH_BASE);
wdenk452cfd62002-11-19 11:04:11 +0000111
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200112 flash_size = flash_get_size (CONFIG_SYS_FLASH_BASE, flash_info);
wdenk452cfd62002-11-19 11:04:11 +0000113
114 DEBUGF("## Flash bank size: %08lx\n", flash_size);
115
116 if (flash_size) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200117#if CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE && \
118 CONFIG_SYS_MONITOR_BASE < CONFIG_SYS_FLASH_BASE + CONFIG_SYS_FLASH_MAX_SIZE
wdenk452cfd62002-11-19 11:04:11 +0000119 /* monitor protection ON by default */
120 flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200121 CONFIG_SYS_MONITOR_BASE,
122 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
wdenk452cfd62002-11-19 11:04:11 +0000123 &flash_info[0]);
124#endif
125
Jean-Christophe PLAGNIOL-VILLARD53db4cd2008-09-10 22:48:04 +0200126#ifdef CONFIG_ENV_IS_IN_FLASH
wdenk452cfd62002-11-19 11:04:11 +0000127 /* ENV protection ON by default */
128 flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200129 CONFIG_ENV_ADDR,
130 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
wdenk452cfd62002-11-19 11:04:11 +0000131 &flash_info[0]);
132#endif
133
134 } else {
wdenk874ac262003-07-24 23:38:38 +0000135 printf ("Warning: the BOOT Flash is not initialised !");
wdenk452cfd62002-11-19 11:04:11 +0000136 }
137
138 flash_to_mem();
139
140 return flash_size;
141}
142
143/*
144 * The following code cannot be run from FLASH!
145 */
146static ulong flash_get_size (ulong addr, flash_info_t *info)
147{
148 short i;
149 uchar value;
150 uchar *x = (uchar *)addr;
151
152 flash_to_xd();
153
154 /* Write auto select command: read Manufacturer ID */
155 x[0x0555] = 0xAA;
Peter Tyser745e27e2009-04-20 11:09:05 -0500156 __asm__ volatile ("sync\n eieio");
wdenk452cfd62002-11-19 11:04:11 +0000157 x[0x02AA] = 0x55;
Peter Tyser745e27e2009-04-20 11:09:05 -0500158 __asm__ volatile ("sync\n eieio");
wdenk452cfd62002-11-19 11:04:11 +0000159 x[0x0555] = 0x90;
Peter Tyser745e27e2009-04-20 11:09:05 -0500160 __asm__ volatile ("sync\n eieio");
wdenk452cfd62002-11-19 11:04:11 +0000161
162 value = x[0];
Peter Tyser745e27e2009-04-20 11:09:05 -0500163 __asm__ volatile ("sync\n eieio");
wdenk452cfd62002-11-19 11:04:11 +0000164
165 DEBUGF("Manuf. ID @ 0x%08lx: 0x%08x\n", (ulong)addr, value);
166
167 switch (value | (value << 16)) {
168 case AMD_MANUFACT:
169 info->flash_id = FLASH_MAN_AMD;
170 break;
171
172 case FUJ_MANUFACT:
173 info->flash_id = FLASH_MAN_FUJ;
174 break;
175
176 case STM_MANUFACT:
177 info->flash_id = FLASH_MAN_STM;
178 break;
179
180 default:
181 info->flash_id = FLASH_UNKNOWN;
182 info->sector_count = 0;
183 info->size = 0;
184 flash_reset (addr);
185 return 0;
186 }
187
188 value = x[1];
Peter Tyser745e27e2009-04-20 11:09:05 -0500189 __asm__ volatile ("sync\n eieio");
wdenk452cfd62002-11-19 11:04:11 +0000190
191 DEBUGF("Device ID @ 0x%08lx: 0x%08x\n", addr+1, value);
192
193 switch (value) {
194 case AMD_ID_F040B:
195 DEBUGF("Am29F040B\n");
196 info->flash_id += FLASH_AM040;
197 info->sector_count = 8;
198 info->size = 0x00080000;
199 break; /* => 512 kB */
200
201 case AMD_ID_LV040B:
202 DEBUGF("Am29LV040B\n");
203 info->flash_id += FLASH_AM040;
204 info->sector_count = 8;
205 info->size = 0x00080000;
206 break; /* => 512 kB */
207
208 case AMD_ID_LV400T:
209 DEBUGF("Am29LV400T\n");
210 info->flash_id += FLASH_AM400T;
211 info->sector_count = 11;
212 info->size = 0x00100000;
213 break; /* => 1 MB */
214
215 case AMD_ID_LV400B:
216 DEBUGF("Am29LV400B\n");
217 info->flash_id += FLASH_AM400B;
218 info->sector_count = 11;
219 info->size = 0x00100000;
220 break; /* => 1 MB */
221
222 case AMD_ID_LV800T:
223 DEBUGF("Am29LV800T\n");
224 info->flash_id += FLASH_AM800T;
225 info->sector_count = 19;
226 info->size = 0x00200000;
227 break; /* => 2 MB */
228
229 case AMD_ID_LV800B:
230 DEBUGF("Am29LV400B\n");
231 info->flash_id += FLASH_AM800B;
232 info->sector_count = 19;
233 info->size = 0x00200000;
234 break; /* => 2 MB */
235
236 case AMD_ID_LV160T:
237 DEBUGF("Am29LV160T\n");
238 info->flash_id += FLASH_AM160T;
239 info->sector_count = 35;
240 info->size = 0x00400000;
241 break; /* => 4 MB */
242
243 case AMD_ID_LV160B:
244 DEBUGF("Am29LV160B\n");
245 info->flash_id += FLASH_AM160B;
246 info->sector_count = 35;
247 info->size = 0x00400000;
248 break; /* => 4 MB */
249
250 case AMD_ID_LV320T:
251 DEBUGF("Am29LV320T\n");
252 info->flash_id += FLASH_AM320T;
253 info->sector_count = 67;
254 info->size = 0x00800000;
255 break; /* => 8 MB */
256
257#if 0
258 /* Has the same ID as AMD_ID_LV320T, to be fixed */
259 case AMD_ID_LV320B:
260 DEBUGF("Am29LV320B\n");
261 info->flash_id += FLASH_AM320B;
262 info->sector_count = 67;
263 info->size = 0x00800000;
264 break; /* => 8 MB */
265#endif
266
267 case AMD_ID_LV033C:
268 DEBUGF("Am29LV033C\n");
269 info->flash_id += FLASH_AM033C;
270 info->sector_count = 64;
271 info->size = 0x01000000;
272 break; /* => 16Mb */
273
274 case STM_ID_F040B:
275 DEBUGF("M29F040B\n");
276 info->flash_id += FLASH_AM040;
277 info->sector_count = 8;
278 info->size = 0x00080000;
279 break; /* => 512 kB */
280
281 default:
282 info->flash_id = FLASH_UNKNOWN;
283 flash_reset (addr);
284 flash_to_mem();
285 return (0); /* => no or unknown flash */
286
287 }
288
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200289 if (info->sector_count > CONFIG_SYS_MAX_FLASH_SECT) {
wdenk874ac262003-07-24 23:38:38 +0000290 printf ("** ERROR: sector count %d > max (%d) **\n",
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200291 info->sector_count, CONFIG_SYS_MAX_FLASH_SECT);
292 info->sector_count = CONFIG_SYS_MAX_FLASH_SECT;
wdenk452cfd62002-11-19 11:04:11 +0000293 }
294
295 if (! flash_get_offsets (addr, info)) {
296 flash_reset (addr);
297 flash_to_mem();
298 return 0;
299 }
300
301 /* check for protected sectors */
302 for (i = 0; i < info->sector_count; i++) {
303 /* read sector protection at sector address, (A7 .. A0) = 0x02 */
304 /* D0 = 1 if protected */
305 value = in8(info->start[i] + 2);
306 iobarrier_rw();
307 info->protect[i] = (value & 1) != 0;
308 }
309
310 /*
311 * Reset bank to read mode
312 */
313 flash_reset (addr);
314
315 flash_to_mem();
316
317 return (info->size);
318}
319
320static int flash_get_offsets (ulong base, flash_info_t *info)
321{
322 unsigned int i;
323
324 switch (info->flash_id & FLASH_TYPEMASK) {
325 case FLASH_AM040:
326 /* set sector offsets for uniform sector type */
327 for (i = 0; i < info->sector_count; i++) {
328 info->start[i] = base + i * info->size /
wdenk57b2d802003-06-27 21:31:46 +0000329 info->sector_count;
wdenk452cfd62002-11-19 11:04:11 +0000330 }
331 break;
332 default:
333 return 0;
334 }
335
336 return 1;
337}
338
339int flash_erase (flash_info_t *info, int s_first, int s_last)
340{
341 volatile ulong addr = info->start[0];
342 int flag, prot, sect, l_sect;
343 ulong start, now, last;
344
345 flash_to_xd();
346
347 if (s_first < 0 || s_first > s_last) {
348 if (info->flash_id == FLASH_UNKNOWN) {
wdenk874ac262003-07-24 23:38:38 +0000349 printf ("- missing\n");
wdenk452cfd62002-11-19 11:04:11 +0000350 } else {
wdenk874ac262003-07-24 23:38:38 +0000351 printf ("- no sectors to erase\n");
wdenk452cfd62002-11-19 11:04:11 +0000352 }
353 flash_to_mem();
354 return 1;
355 }
356
357 if (info->flash_id == FLASH_UNKNOWN) {
wdenk874ac262003-07-24 23:38:38 +0000358 printf ("Can't erase unknown flash type %08lx - aborted\n",
wdenk452cfd62002-11-19 11:04:11 +0000359 info->flash_id);
360 flash_to_mem();
361 return 1;
362 }
363
364 prot = 0;
365 for (sect=s_first; sect<=s_last; ++sect) {
366 if (info->protect[sect]) {
367 prot++;
368 }
369 }
370
371 if (prot) {
wdenk874ac262003-07-24 23:38:38 +0000372 printf ("- Warning: %d protected sectors will not be erased!\n",
wdenk452cfd62002-11-19 11:04:11 +0000373 prot);
374 } else {
wdenk874ac262003-07-24 23:38:38 +0000375 printf ("");
wdenk452cfd62002-11-19 11:04:11 +0000376 }
377
378 l_sect = -1;
379
380 /* Disable interrupts which might cause a timeout here */
381 flag = disable_interrupts();
382
383 out8(addr + 0x555, 0xAA);
384 iobarrier_rw();
385 out8(addr + 0x2AA, 0x55);
386 iobarrier_rw();
387 out8(addr + 0x555, 0x80);
388 iobarrier_rw();
389 out8(addr + 0x555, 0xAA);
390 iobarrier_rw();
391 out8(addr + 0x2AA, 0x55);
392 iobarrier_rw();
393
394 /* Start erase on unprotected sectors */
395 for (sect = s_first; sect<=s_last; sect++) {
396 if (info->protect[sect] == 0) { /* not protected */
397 addr = info->start[sect];
398 out8(addr, 0x30);
399 iobarrier_rw();
400 l_sect = sect;
401 }
402 }
403
404 /* re-enable interrupts if necessary */
405 if (flag)
406 enable_interrupts();
407
408 /* wait at least 80us - let's wait 1 ms */
wdenk874ac262003-07-24 23:38:38 +0000409 udelay (1000);
wdenk452cfd62002-11-19 11:04:11 +0000410
411 /*
412 * We wait for the last triggered sector
413 */
414 if (l_sect < 0)
415 goto DONE;
416
wdenk874ac262003-07-24 23:38:38 +0000417 start = get_timer (0);
wdenk452cfd62002-11-19 11:04:11 +0000418 last = start;
419 addr = info->start[l_sect];
420
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200421 DEBUGF ("Start erase timeout: %d\n", CONFIG_SYS_FLASH_ERASE_TOUT);
wdenk452cfd62002-11-19 11:04:11 +0000422
423 while ((in8(addr) & 0x80) != 0x80) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200424 if ((now = get_timer(start)) > CONFIG_SYS_FLASH_ERASE_TOUT) {
wdenk874ac262003-07-24 23:38:38 +0000425 printf ("Timeout\n");
wdenk452cfd62002-11-19 11:04:11 +0000426 flash_reset (info->start[0]);
427 flash_to_mem();
428 return 1;
429 }
430 /* show that we're waiting */
431 if ((now - last) > 1000) { /* every second */
wdenk874ac262003-07-24 23:38:38 +0000432 putc ('.');
wdenk452cfd62002-11-19 11:04:11 +0000433 last = now;
434 }
435 iobarrier_rw();
436 }
437
438DONE:
439 /* reset to read mode */
440 flash_reset (info->start[0]);
441 flash_to_mem();
442
wdenk874ac262003-07-24 23:38:38 +0000443 printf (" done\n");
wdenk452cfd62002-11-19 11:04:11 +0000444 return 0;
445}
446
447/*
448 * Copy memory to flash, returns:
449 * 0 - OK
450 * 1 - write timeout
451 * 2 - Flash not erased
452 */
453int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
454{
455 ulong cp, wp, data;
456 int i, l, rc;
457 ulong out_cnt = 0;
458
459 flash_to_xd();
460
461 wp = (addr & ~3); /* get lower word aligned address */
462
463 /*
464 * handle unaligned start bytes
465 */
466 if ((l = addr - wp) != 0) {
467 data = 0;
468 for (i=0, cp=wp; i<l; ++i, ++cp) {
469 data = (data << 8) | (*(uchar *)cp);
470 }
471 for (; i<4 && cnt>0; ++i) {
472 data = (data << 8) | *src++;
473 --cnt;
474 ++cp;
475 }
476 for (; cnt==0 && i<4; ++i, ++cp) {
477 data = (data << 8) | (*(uchar *)cp);
478 }
479
480 if ((rc = write_word(info, wp, data)) != 0) {
wdenk57b2d802003-06-27 21:31:46 +0000481 flash_to_mem();
wdenk452cfd62002-11-19 11:04:11 +0000482 return (rc);
483 }
484 wp += 4;
485 }
486
wdenk874ac262003-07-24 23:38:38 +0000487 putc(219);
wdenk452cfd62002-11-19 11:04:11 +0000488
489 /*
490 * handle word aligned part
491 */
492 while (cnt >= 4) {
wdenk57b2d802003-06-27 21:31:46 +0000493 if (out_cnt>26214)
wdenk452cfd62002-11-19 11:04:11 +0000494 {
wdenk874ac262003-07-24 23:38:38 +0000495 putc(219);
wdenk452cfd62002-11-19 11:04:11 +0000496 out_cnt = 0;
497 }
498 data = 0;
499 for (i=0; i<4; ++i) {
500 data = (data << 8) | *src++;
501 }
502 if ((rc = write_word(info, wp, data)) != 0) {
503 flash_to_mem();
504 return (rc);
505 }
506 wp += 4;
507 cnt -= 4;
508 out_cnt += 4;
509 }
510
511 if (cnt == 0) {
512 flash_to_mem();
513 return (0);
514 }
515
516 /*
517 * handle unaligned tail bytes
518 */
519 data = 0;
520 for (i=0, cp=wp; i<4 && cnt>0; ++i, ++cp) {
521 data = (data << 8) | *src++;
522 --cnt;
523 }
524 for (; i<4; ++i, ++cp) {
525 data = (data << 8) | (*(uchar *)cp);
526 }
527
528 flash_to_mem();
529 return (write_word(info, wp, data));
530}
531
532/*
533 * Write a word to Flash, returns:
534 * 0 - OK
535 * 1 - write timeout
536 * 2 - Flash not erased
537 */
538static int write_word (flash_info_t *info, ulong dest, ulong data)
539{
540 volatile ulong addr = info->start[0];
541 ulong start;
542 int i;
543
544 flash_to_xd();
545
546 /* Check if Flash is (sufficiently) erased */
547 if ((in32(dest) & data) != data) {
548 flash_to_mem();
549 return (2);
550 }
551
552 /* write each byte out */
553 for (i = 0; i < 4; i++) {
554 char *data_ch = (char *)&data;
555 int flag = disable_interrupts();
556
557 out8(addr + 0x555, 0xAA);
558 iobarrier_rw();
559 out8(addr + 0x2AA, 0x55);
560 iobarrier_rw();
561 out8(addr + 0x555, 0xA0);
562 iobarrier_rw();
563 out8(dest+i, data_ch[i]);
564 iobarrier_rw();
565
566 /* re-enable interrupts if necessary */
567 if (flag)
568 enable_interrupts();
569
570 /* data polling for D7 */
wdenk874ac262003-07-24 23:38:38 +0000571 start = get_timer (0);
wdenk452cfd62002-11-19 11:04:11 +0000572 while ((in8(dest+i) & 0x80) != (data_ch[i] & 0x80)) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200573 if (get_timer(start) > CONFIG_SYS_FLASH_WRITE_TOUT) {
wdenk452cfd62002-11-19 11:04:11 +0000574 flash_reset (addr);
575 flash_to_mem();
576 return (1);
577 }
578 iobarrier_rw();
579 }
580 }
581
582 flash_reset (addr);
583 flash_to_mem();
584 return (0);
585}
586
587/*
588 * Reset bank to read mode
589 */
590static void flash_reset (ulong addr)
591{
wdenk57b2d802003-06-27 21:31:46 +0000592 flash_to_xd();
wdenk452cfd62002-11-19 11:04:11 +0000593 out8(addr, 0xF0); /* reset bank */
594 iobarrier_rw();
595 flash_to_mem();
596}
597
598void flash_print_info (flash_info_t *info)
599{
600 int i;
601
602 if (info->flash_id == FLASH_UNKNOWN) {
wdenk874ac262003-07-24 23:38:38 +0000603 printf ("missing or unknown FLASH type\n");
wdenk452cfd62002-11-19 11:04:11 +0000604 return;
605 }
606
607 switch (info->flash_id & FLASH_VENDMASK) {
wdenk874ac262003-07-24 23:38:38 +0000608 case FLASH_MAN_AMD: printf ("AMD "); break;
609 case FLASH_MAN_FUJ: printf ("FUJITSU "); break;
610 case FLASH_MAN_BM: printf ("BRIGHT MICRO "); break;
611 case FLASH_MAN_STM: printf ("SGS THOMSON "); break;
612 default: printf ("Unknown Vendor "); break;
wdenk452cfd62002-11-19 11:04:11 +0000613 }
614
615 switch (info->flash_id & FLASH_TYPEMASK) {
wdenk874ac262003-07-24 23:38:38 +0000616 case FLASH_AM040: printf ("29F040 or 29LV040 (4 Mbit, uniform sectors)\n");
wdenk452cfd62002-11-19 11:04:11 +0000617 break;
wdenk874ac262003-07-24 23:38:38 +0000618 case FLASH_AM400B: printf ("AM29LV400B (4 Mbit, bottom boot sect)\n");
wdenk452cfd62002-11-19 11:04:11 +0000619 break;
wdenk874ac262003-07-24 23:38:38 +0000620 case FLASH_AM400T: printf ("AM29LV400T (4 Mbit, top boot sector)\n");
wdenk452cfd62002-11-19 11:04:11 +0000621 break;
wdenk874ac262003-07-24 23:38:38 +0000622 case FLASH_AM800B: printf ("AM29LV800B (8 Mbit, bottom boot sect)\n");
wdenk452cfd62002-11-19 11:04:11 +0000623 break;
wdenk874ac262003-07-24 23:38:38 +0000624 case FLASH_AM800T: printf ("AM29LV800T (8 Mbit, top boot sector)\n");
wdenk452cfd62002-11-19 11:04:11 +0000625 break;
wdenk874ac262003-07-24 23:38:38 +0000626 case FLASH_AM160B: printf ("AM29LV160B (16 Mbit, bottom boot sect)\n");
wdenk452cfd62002-11-19 11:04:11 +0000627 break;
wdenk874ac262003-07-24 23:38:38 +0000628 case FLASH_AM160T: printf ("AM29LV160T (16 Mbit, top boot sector)\n");
wdenk452cfd62002-11-19 11:04:11 +0000629 break;
wdenk874ac262003-07-24 23:38:38 +0000630 case FLASH_AM320B: printf ("AM29LV320B (32 Mbit, bottom boot sect)\n");
wdenk452cfd62002-11-19 11:04:11 +0000631 break;
wdenk874ac262003-07-24 23:38:38 +0000632 case FLASH_AM320T: printf ("AM29LV320T (32 Mbit, top boot sector)\n");
wdenk452cfd62002-11-19 11:04:11 +0000633 break;
wdenk874ac262003-07-24 23:38:38 +0000634 default: printf ("Unknown Chip Type\n");
wdenk452cfd62002-11-19 11:04:11 +0000635 break;
636 }
637
638 if (info->size % 0x100000 == 0) {
wdenk874ac262003-07-24 23:38:38 +0000639 printf (" Size: %ld MB in %d Sectors\n",
wdenk452cfd62002-11-19 11:04:11 +0000640 info->size / 0x100000, info->sector_count);
641 } else if (info->size % 0x400 == 0) {
wdenk874ac262003-07-24 23:38:38 +0000642 printf (" Size: %ld KB in %d Sectors\n",
wdenk57b2d802003-06-27 21:31:46 +0000643 info->size / 0x400, info->sector_count);
wdenk452cfd62002-11-19 11:04:11 +0000644 } else {
wdenk874ac262003-07-24 23:38:38 +0000645 printf (" Size: %ld B in %d Sectors\n",
wdenk57b2d802003-06-27 21:31:46 +0000646 info->size, info->sector_count);
wdenk452cfd62002-11-19 11:04:11 +0000647 }
648
wdenk874ac262003-07-24 23:38:38 +0000649 printf (" Sector Start Addresses:");
wdenk452cfd62002-11-19 11:04:11 +0000650 for (i=0; i<info->sector_count; ++i) {
651 if ((i % 5) == 0)
wdenk874ac262003-07-24 23:38:38 +0000652 printf ("\n ");
653 printf (" %08lX%s",
wdenk452cfd62002-11-19 11:04:11 +0000654 info->start[i],
655 info->protect[i] ? " (RO)" : " "
656 );
657 }
wdenk874ac262003-07-24 23:38:38 +0000658 printf ("\n");
wdenk452cfd62002-11-19 11:04:11 +0000659}