annotate loadtools/flashid.c @ 554:c44f3bf0e4d5

CHANGES: Am29DL640G flash support documented
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 04 Jan 2020 17:54:07 +0000
parents 3886a8a40809
children f229efbfd581
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
506
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Flash device detection code lives here
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "flash.h"
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 extern struct flash_device flashdev_28F160C3T;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern struct flash_device flashdev_28F320C3T;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern struct flash_device flashdev_28F640C3T;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern struct flash_device flashdev_28F640C3B;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern struct flash_device flashdev_28F640W30T;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern struct flash_device flashdev_28F640W30B;
553
3886a8a40809 fc-loadtool: added support for old Am29DL640G flash chip
Mychaela Falconia <falcon@freecalypso.org>
parents: 523
diff changeset
17 extern struct flash_device flashdev_Am29DL640G;
506
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern struct flash_device flashdev_PL129J;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern struct flash_device flashdev_PL129N;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern struct flash_device flashdev_K5A32xx_T;
523
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
21 extern struct flash_device flashdev_K5L33xx_A;
506
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern int flash_global_config;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern struct flash_bank_info flash_bank_info[2];
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 static
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 run_cfi_check(bi, table)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 struct flash_bank_info *bi;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 struct cfi_check *table;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 struct cfi_check *tp;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 uint16_t rdword;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 for (tp = table; tp->offset >= 0; tp++) {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (do_r16(bi->base_addr + (tp->offset << 1), &rdword) < 0)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (rdword != tp->expect_val)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 return(0);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return(1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 static
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 try_device(bi, dev)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 struct flash_bank_info *bi;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 struct flash_device *dev;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 int rc;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 printf("Appears to be %s or compatible, checking CFI\n", dev->name);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (do_w16(bi->base_addr + 0xAA, 0x98)) {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 fprintf(stderr, "unexpected response to w16 - aborting\n");
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 rc = run_cfi_check(bi, dev->cfi_table);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (rc < 0)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 return(rc);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (!rc) {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 fprintf(stderr, "Error: CFI mismatch, unsafe to continue\n");
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 printf("Confirmed %s or compatible\n", dev->name);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 bi->device = dev;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 return(0);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 static
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 spansion_pl129j_or_n(bi)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 struct flash_bank_info *bi;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 int rc;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 printf("Spansion PL129J or PL129N, looking at CFI\n");
507
c942be3c7997 new flash support works for PL129N on the Pirelli
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
74 /* need to go back to read array first, CFI cmd ignored otherwise */
c942be3c7997 new flash support works for PL129N on the Pirelli
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
75 if (do_w16(bi->base_addr + 0xAAA, 0xF0)) {
c942be3c7997 new flash support works for PL129N on the Pirelli
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
76 bad_w16: fprintf(stderr, "unexpected response to w16 - aborting\n");
506
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
507
c942be3c7997 new flash support works for PL129N on the Pirelli
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
79 if (do_w16(bi->base_addr + 0xAAA, 0x98))
c942be3c7997 new flash support works for PL129N on the Pirelli
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
80 goto bad_w16;
506
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 rc = run_cfi_check(bi, flashdev_PL129N.cfi_table);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (rc < 0)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 return(rc);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 if (rc) {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 printf("Found PL129N\n");
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 bi->device = &flashdev_PL129N;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 return(0);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 rc = run_cfi_check(bi, flashdev_PL129J.cfi_table);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (rc < 0)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 return(rc);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (rc) {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 printf("Found PL129J\n");
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 bi->device = &flashdev_PL129J;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 return(0);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 fprintf(stderr, "Error: no matching CFI found\n");
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 static
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 amd_extended_id(bi)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 struct flash_bank_info *bi;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 uint16_t ext1, ext2;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106
507
c942be3c7997 new flash support works for PL129N on the Pirelli
Mychaela Falconia <falcon@freecalypso.org>
parents: 506
diff changeset
107 printf("AMD-style extended ID device, reading extended ID\n");
506
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 if (do_r16(bi->base_addr + 0x1C, &ext1) < 0)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 if (do_r16(bi->base_addr + 0x1E, &ext2) < 0)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 printf("Extended ID: %04X %04X\n", ext1, ext2);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 if (ext1 == 0x2221 && ext2 == 0x2200)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 return spansion_pl129j_or_n(bi);
553
3886a8a40809 fc-loadtool: added support for old Am29DL640G flash chip
Mychaela Falconia <falcon@freecalypso.org>
parents: 523
diff changeset
115 if (ext1 == 0x2202 && ext2 == 0x2201)
3886a8a40809 fc-loadtool: added support for old Am29DL640G flash chip
Mychaela Falconia <falcon@freecalypso.org>
parents: 523
diff changeset
116 return try_device(bi, &flashdev_Am29DL640G);
506
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 fprintf(stderr, "Error: unknown device ID\n");
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120
523
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
121 static
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
122 samsung_extended_id(bi)
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
123 struct flash_bank_info *bi;
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
124 {
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
125 uint16_t ext1, ext2;
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
126
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
127 printf("Samsung extended ID device, reading extended ID\n");
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
128 if (do_r16(bi->base_addr + 0x1C, &ext1) < 0)
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
129 return(-1);
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
130 if (do_r16(bi->base_addr + 0x1E, &ext2) < 0)
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
131 return(-1);
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
132 printf("Extended ID: %04X %04X\n", ext1, ext2);
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
133 if (ext1 == 0x2503 && ext2 == 0x2501)
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
134 return try_device(bi, &flashdev_K5L33xx_A);
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
135 fprintf(stderr, "Error: unknown device ID\n");
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
136 return(-1);
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
137 }
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
138
506
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 static struct idmap {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 uint16_t manuf_id;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 uint16_t dev_id;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 int (*handler)();
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 void *extra_arg;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 } device_id_table[] = {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 /* AMD/Spansion devices */
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 {0x0001, 0x227E, amd_extended_id, 0},
511
0212edcec4d2 loadtools/flashid.c: added alt ID for 28F320C3T equiv in Mot C139
Mychaela Falconia <falcon@freecalypso.org>
parents: 507
diff changeset
147 /* 28F160C3T and 28F320C3T equivalents found in some Mot C1xx phones */
0212edcec4d2 loadtools/flashid.c: added alt ID for 28F320C3T equiv in Mot C139
Mychaela Falconia <falcon@freecalypso.org>
parents: 507
diff changeset
148 {0x0020, 0x88BA, try_device, &flashdev_28F320C3T},
506
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 {0x0020, 0x88CE, try_device, &flashdev_28F160C3T},
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 /* Intel flash chips */
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 {0x0089, 0x8854, try_device, &flashdev_28F640W30T},
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 {0x0089, 0x8855, try_device, &flashdev_28F640W30B},
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 {0x0089, 0x8864, try_device, &flashdev_28F640W30T},
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 {0x0089, 0x88C2, try_device, &flashdev_28F160C3T},
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 {0x0089, 0x88C4, try_device, &flashdev_28F320C3T},
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 {0x0089, 0x88CC, try_device, &flashdev_28F640C3T},
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 {0x0089, 0x88CD, try_device, &flashdev_28F640C3B},
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 /* Samsung flash */
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 {0x00EC, 0x22A0, try_device, &flashdev_K5A32xx_T},
523
9a478d33b3ca fc-loadtool: added Samsung K5L33xx_A flash support for GTM900
Mychaela Falconia <falcon@freecalypso.org>
parents: 511
diff changeset
160 {0x00EC, 0x257E, samsung_extended_id, 0},
506
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 /* table search terminator */
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 {0, 0, 0, 0}
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 };
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 flash_detect(bank, repeat)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 struct flash_bank_info *bi;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 uint16_t manuf_id, dev_id;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 struct idmap *tp;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 int rc;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 bi = flash_bank_info + bank;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 if (bi->detect_done && !repeat)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 return(0);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 printf("Autodetecting flash chip type\n");
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 if (do_w16(bi->base_addr + 0xAAA, 0xAA)) {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 bad_w16: fprintf(stderr,
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 "unexpected response to w16 in read ID cmd sequence - aborting\n");
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 }
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 if (do_w16(bi->base_addr + 0x554, 0x55))
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 goto bad_w16;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 if (do_w16(bi->base_addr + 0xAAA, 0x90))
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 goto bad_w16;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 if (do_r16(bi->base_addr, &manuf_id) < 0)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 if (do_r16(bi->base_addr + 2, &dev_id) < 0)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 printf("Basic device ID: %04X %04X\n", manuf_id, dev_id);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 for (tp = device_id_table; tp->handler; tp++)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 if (tp->manuf_id == manuf_id && tp->dev_id == dev_id)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 break;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 if (!tp->handler) {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 fprintf(stderr, "Error: unknown device ID\n");
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 }
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 rc = tp->handler(bi, tp->extra_arg);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 if (rc < 0)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 return(rc);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 /* got the device, see if it is compatible with global config */
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 if (bi->device->required_global_config > flash_global_config) {
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 fprintf(stderr,
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 "Error: detected flash device is not compatible with the configured mapping\n");
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 return(-1);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 }
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 /* good to go */
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 if (bi->device->bank_geom[1] && bank)
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 bi->geom = bi->device->bank_geom[1];
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 else
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 bi->geom = bi->device->bank_geom[0];
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 bi->ops = bi->device->cmdset;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 bi->detect_done = 1;
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 /* return device to read array mode */
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 return bi->ops->reset_cmd(bi);
0dd2c87c1b63 fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 }