~ubuntu-branches/debian/sid/flashrom/sid

« back to all changes in this revision

Viewing changes to 82802ab.c

  • Committer: Package Import Robot
  • Author(s): Uwe Hermann
  • Date: 2012-02-20 11:54:48 UTC
  • mfrom: (1.3.14)
  • Revision ID: package-import@ubuntu.com-20120220115448-53057dgdnwisuhrc
Tags: 0.9.5+r1503-1
* New upstream release.
* debian/docs: Add mysteries_intel.txt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "flash.h"
30
30
#include "chipdrivers.h"
31
31
 
32
 
// I need that Berkeley bit-map printer
33
32
void print_status_82802ab(uint8_t status)
34
33
{
35
34
        msg_cdbg("%s", status & 0x80 ? "Ready:" : "Busy:");
41
40
        msg_cdbg("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:");
42
41
}
43
42
 
44
 
int probe_82802ab(struct flashchip *flash)
 
43
int probe_82802ab(struct flashctx *flash)
45
44
{
46
45
        chipaddr bios = flash->virtual_memory;
47
 
        uint8_t id1, id2;
48
 
        uint8_t flashcontent1, flashcontent2;
 
46
        uint8_t id1, id2, flashcontent1, flashcontent2;
49
47
        int shifted = (flash->feature_bits & FEATURE_ADDR_SHIFTED) != 0;
50
48
 
51
49
        /* Reset to get a clean state */
52
 
        chip_writeb(0xFF, bios);
 
50
        chip_writeb(flash, 0xFF, bios);
53
51
        programmer_delay(10);
54
52
 
55
53
        /* Enter ID mode */
56
 
        chip_writeb(0x90, bios);
 
54
        chip_writeb(flash, 0x90, bios);
57
55
        programmer_delay(10);
58
56
 
59
 
        id1 = chip_readb(bios + (0x00 << shifted));
60
 
        id2 = chip_readb(bios + (0x01 << shifted));
 
57
        id1 = chip_readb(flash, bios + (0x00 << shifted));
 
58
        id2 = chip_readb(flash, bios + (0x01 << shifted));
61
59
 
62
60
        /* Leave ID mode */
63
 
        chip_writeb(0xFF, bios);
 
61
        chip_writeb(flash, 0xFF, bios);
64
62
 
65
63
        programmer_delay(10);
66
64
 
69
67
        if (!oddparity(id1))
70
68
                msg_cdbg(", id1 parity violation");
71
69
 
72
 
        /* Read the product ID location again. We should now see normal flash contents. */
73
 
        flashcontent1 = chip_readb(bios + (0x00 << shifted));
74
 
        flashcontent2 = chip_readb(bios + (0x01 << shifted));
 
70
        /*
 
71
         * Read the product ID location again. We should now see normal
 
72
         * flash contents.
 
73
         */
 
74
        flashcontent1 = chip_readb(flash, bios + (0x00 << shifted));
 
75
        flashcontent2 = chip_readb(flash, bios + (0x01 << shifted));
75
76
 
76
77
        if (id1 == flashcontent1)
77
78
                msg_cdbg(", id1 is normal flash content");
88
89
        return 1;
89
90
}
90
91
 
91
 
uint8_t wait_82802ab(struct flashchip *flash)
 
92
uint8_t wait_82802ab(struct flashctx *flash)
92
93
{
93
94
        uint8_t status;
94
95
        chipaddr bios = flash->virtual_memory;
95
96
 
96
 
        chip_writeb(0x70, bios);
97
 
        if ((chip_readb(bios) & 0x80) == 0) {   // it's busy
98
 
                while ((chip_readb(bios) & 0x80) == 0) ;
 
97
        chip_writeb(flash, 0x70, bios);
 
98
        if ((chip_readb(flash, bios) & 0x80) == 0) {    // it's busy
 
99
                while ((chip_readb(flash, bios) & 0x80) == 0) ;
99
100
        }
100
101
 
101
 
        status = chip_readb(bios);
 
102
        status = chip_readb(flash, bios);
102
103
 
103
104
        /* Reset to get a clean state */
104
 
        chip_writeb(0xFF, bios);
 
105
        chip_writeb(flash, 0xFF, bios);
105
106
 
106
107
        return status;
107
108
}
108
109
 
109
 
int unlock_82802ab(struct flashchip *flash)
 
110
int unlock_82802ab(struct flashctx *flash)
110
111
{
111
112
        int i;
112
113
        //chipaddr wrprotect = flash->virtual_registers + page + 2;
113
114
 
114
115
        for (i = 0; i < flash->total_size * 1024; i+= flash->page_size)
115
 
        {
116
 
                chip_writeb(0, flash->virtual_registers + i + 2);
117
 
        }
 
116
                chip_writeb(flash, 0, flash->virtual_registers + i + 2);
118
117
 
119
118
        return 0;
120
119
}
121
120
 
122
 
int erase_block_82802ab(struct flashchip *flash, unsigned int page, unsigned int pagesize)
 
121
int erase_block_82802ab(struct flashctx *flash, unsigned int page,
 
122
                        unsigned int pagesize)
123
123
{
124
124
        chipaddr bios = flash->virtual_memory;
125
125
        uint8_t status;
126
126
 
127
127
        // clear status register
128
 
        chip_writeb(0x50, bios + page);
 
128
        chip_writeb(flash, 0x50, bios + page);
129
129
 
130
130
        // now start it
131
 
        chip_writeb(0x20, bios + page);
132
 
        chip_writeb(0xd0, bios + page);
 
131
        chip_writeb(flash, 0x20, bios + page);
 
132
        chip_writeb(flash, 0xd0, bios + page);
133
133
        programmer_delay(10);
134
134
 
135
135
        // now let's see what the register is
141
141
}
142
142
 
143
143
/* chunksize is 1 */
144
 
int write_82802ab(struct flashchip *flash, uint8_t *src, int start, int len)
 
144
int write_82802ab(struct flashctx *flash, uint8_t *src, unsigned int start,
 
145
                  unsigned int len)
145
146
{
146
147
        int i;
147
148
        chipaddr dst = flash->virtual_memory + start;
148
149
 
149
150
        for (i = 0; i < len; i++) {
150
151
                /* transfer data from source to destination */
151
 
                chip_writeb(0x40, dst);
152
 
                chip_writeb(*src++, dst++);
 
152
                chip_writeb(flash, 0x40, dst);
 
153
                chip_writeb(flash, *src++, dst++);
153
154
                wait_82802ab(flash);
154
155
        }
155
156
 
157
158
        return 0;
158
159
}
159
160
 
160
 
int unlock_28f004s5(struct flashchip *flash)
 
161
int unlock_28f004s5(struct flashctx *flash)
161
162
{
162
163
        chipaddr bios = flash->virtual_memory;
163
164
        uint8_t mcfg, bcfg, need_unlock = 0, can_unlock = 0;
164
165
        int i;
165
166
 
166
167
        /* Clear status register */
167
 
        chip_writeb(0x50, bios);
 
168
        chip_writeb(flash, 0x50, bios);
168
169
 
169
170
        /* Read identifier codes */
170
 
        chip_writeb(0x90, bios);
 
171
        chip_writeb(flash, 0x90, bios);
171
172
 
172
173
        /* Read master lock-bit */
173
 
        mcfg = chip_readb(bios + 0x3);
 
174
        mcfg = chip_readb(flash, bios + 0x3);
174
175
        msg_cdbg("master lock is ");
175
176
        if (mcfg) {
176
177
                msg_cdbg("locked!\n");
178
179
                msg_cdbg("unlocked!\n");
179
180
                can_unlock = 1;
180
181
        }
181
 
        
 
182
 
182
183
        /* Read block lock-bits */
183
184
        for (i = 0; i < flash->total_size * 1024; i+= (64 * 1024)) {
184
 
                bcfg = chip_readb(bios + i + 2); // read block lock config
 
185
                bcfg = chip_readb(flash, bios + i + 2); // read block lock config
185
186
                msg_cdbg("block lock at %06x is %slocked!\n", i, bcfg ? "" : "un");
186
187
                if (bcfg) {
187
188
                        need_unlock = 1;
189
190
        }
190
191
 
191
192
        /* Reset chip */
192
 
        chip_writeb(0xFF, bios);
193
 
 
194
 
        /* Unlock: clear block lock-bits, if needed */
195
 
        if (can_unlock && need_unlock) {
196
 
                msg_cdbg("Unlock: ");
197
 
                chip_writeb(0x60, bios);
198
 
                chip_writeb(0xD0, bios);
199
 
                chip_writeb(0xFF, bios);
 
193
        chip_writeb(flash, 0xFF, bios);
 
194
 
 
195
        /* Unlock: clear block lock-bits, if needed */
 
196
        if (can_unlock && need_unlock) {
 
197
                msg_cdbg("Unlock: ");
 
198
                chip_writeb(flash, 0x60, bios);
 
199
                chip_writeb(flash, 0xD0, bios);
 
200
                chip_writeb(flash, 0xFF, bios);
 
201
                msg_cdbg("Done!\n");
 
202
        }
 
203
 
 
204
        /* Error: master locked or a block is locked */
 
205
        if (!can_unlock && need_unlock) {
 
206
                msg_cerr("At least one block is locked and lockdown is active!\n");
 
207
                return -1;
 
208
        }
 
209
 
 
210
        return 0;
 
211
}
 
212
 
 
213
int unlock_lh28f008bjt(struct flashctx *flash)
 
214
{
 
215
        chipaddr bios = flash->virtual_memory;
 
216
        uint8_t mcfg, bcfg;
 
217
        uint8_t need_unlock = 0, can_unlock = 0;
 
218
        int i;
 
219
 
 
220
        /* Wait if chip is busy */
 
221
        wait_82802ab(flash);
 
222
 
 
223
        /* Read identifier codes */
 
224
        chip_writeb(flash, 0x90, bios);
 
225
 
 
226
        /* Read master lock-bit */
 
227
        mcfg = chip_readb(flash, bios + 0x3);
 
228
        msg_cdbg("master lock is ");
 
229
        if (mcfg) {
 
230
                msg_cdbg("locked!\n");
 
231
        } else {
 
232
                msg_cdbg("unlocked!\n");
 
233
                can_unlock = 1;
 
234
        }
 
235
 
 
236
        /* Read block lock-bits, 8 * 8 KB + 15 * 64 KB */
 
237
        for (i = 0; i < flash->total_size * 1024;
 
238
             i += (i >= (64 * 1024) ? 64 * 1024 : 8 * 1024)) {
 
239
                bcfg = chip_readb(flash, bios + i + 2); /* read block lock config */
 
240
                msg_cdbg("block lock at %06x is %slocked!\n", i,
 
241
                         bcfg ? "" : "un");
 
242
                if (bcfg)
 
243
                        need_unlock = 1;
 
244
        }
 
245
 
 
246
        /* Reset chip */
 
247
        chip_writeb(flash, 0xFF, bios);
 
248
 
 
249
        /* Unlock: clear block lock-bits, if needed */
 
250
        if (can_unlock && need_unlock) {
 
251
                msg_cdbg("Unlock: ");
 
252
                chip_writeb(flash, 0x60, bios);
 
253
                chip_writeb(flash, 0xD0, bios);
 
254
                chip_writeb(flash, 0xFF, bios);
 
255
                wait_82802ab(flash);
200
256
                msg_cdbg("Done!\n");
201
257
        }
202
258