root / hw / pflash_cfi01.c @ 00c3a05b
History | View | Annotate | Download (19.9 kB)
1 | 05ee37eb | balrog | /*
|
---|---|---|---|
2 | 05ee37eb | balrog | * CFI parallel flash with Intel command set emulation
|
3 | 05ee37eb | balrog | *
|
4 | 05ee37eb | balrog | * Copyright (c) 2006 Thorsten Zitterell
|
5 | 05ee37eb | balrog | * Copyright (c) 2005 Jocelyn Mayer
|
6 | 05ee37eb | balrog | *
|
7 | 05ee37eb | balrog | * This library is free software; you can redistribute it and/or
|
8 | 05ee37eb | balrog | * modify it under the terms of the GNU Lesser General Public
|
9 | 05ee37eb | balrog | * License as published by the Free Software Foundation; either
|
10 | 05ee37eb | balrog | * version 2 of the License, or (at your option) any later version.
|
11 | 05ee37eb | balrog | *
|
12 | 05ee37eb | balrog | * This library is distributed in the hope that it will be useful,
|
13 | 05ee37eb | balrog | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | 05ee37eb | balrog | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15 | 05ee37eb | balrog | * Lesser General Public License for more details.
|
16 | 05ee37eb | balrog | *
|
17 | 05ee37eb | balrog | * You should have received a copy of the GNU Lesser General Public
|
18 | 8167ee88 | Blue Swirl | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
19 | 05ee37eb | balrog | */
|
20 | 05ee37eb | balrog | |
21 | 05ee37eb | balrog | /*
|
22 | 05ee37eb | balrog | * For now, this code can emulate flashes of 1, 2 or 4 bytes width.
|
23 | 05ee37eb | balrog | * Supported commands/modes are:
|
24 | 05ee37eb | balrog | * - flash read
|
25 | 05ee37eb | balrog | * - flash write
|
26 | 05ee37eb | balrog | * - flash ID read
|
27 | 05ee37eb | balrog | * - sector erase
|
28 | 05ee37eb | balrog | * - CFI queries
|
29 | 05ee37eb | balrog | *
|
30 | 05ee37eb | balrog | * It does not support timings
|
31 | 05ee37eb | balrog | * It does not support flash interleaving
|
32 | 05ee37eb | balrog | * It does not implement software data protection as found in many real chips
|
33 | 05ee37eb | balrog | * It does not implement erase suspend/resume commands
|
34 | 05ee37eb | balrog | * It does not implement multiple sectors erase
|
35 | 05ee37eb | balrog | *
|
36 | 05ee37eb | balrog | * It does not implement much more ...
|
37 | 05ee37eb | balrog | */
|
38 | 05ee37eb | balrog | |
39 | 87ecb68b | pbrook | #include "hw.h" |
40 | 87ecb68b | pbrook | #include "flash.h" |
41 | 87ecb68b | pbrook | #include "block.h" |
42 | 87ecb68b | pbrook | #include "qemu-timer.h" |
43 | cfe5f011 | Avi Kivity | #include "exec-memory.h" |
44 | 05ee37eb | balrog | |
45 | 001faf32 | Blue Swirl | #define PFLASH_BUG(fmt, ...) \
|
46 | 05ee37eb | balrog | do { \
|
47 | 001faf32 | Blue Swirl | printf("PFLASH: Possible BUG - " fmt, ## __VA_ARGS__); \ |
48 | 05ee37eb | balrog | exit(1); \
|
49 | 05ee37eb | balrog | } while(0) |
50 | 05ee37eb | balrog | |
51 | 05ee37eb | balrog | /* #define PFLASH_DEBUG */
|
52 | 05ee37eb | balrog | #ifdef PFLASH_DEBUG
|
53 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) \
|
54 | 05ee37eb | balrog | do { \
|
55 | 001faf32 | Blue Swirl | printf("PFLASH: " fmt , ## __VA_ARGS__); \ |
56 | 05ee37eb | balrog | } while (0) |
57 | 05ee37eb | balrog | #else
|
58 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) do { } while (0) |
59 | 05ee37eb | balrog | #endif
|
60 | 05ee37eb | balrog | |
61 | c227f099 | Anthony Liguori | struct pflash_t {
|
62 | 05ee37eb | balrog | BlockDriverState *bs; |
63 | c227f099 | Anthony Liguori | target_phys_addr_t base; |
64 | c227f099 | Anthony Liguori | target_phys_addr_t sector_len; |
65 | c227f099 | Anthony Liguori | target_phys_addr_t total_len; |
66 | 05ee37eb | balrog | int width;
|
67 | 05ee37eb | balrog | int wcycle; /* if 0, the flash is read normally */ |
68 | 05ee37eb | balrog | int bypass;
|
69 | 05ee37eb | balrog | int ro;
|
70 | 05ee37eb | balrog | uint8_t cmd; |
71 | 05ee37eb | balrog | uint8_t status; |
72 | 05ee37eb | balrog | uint16_t ident[4];
|
73 | 05ee37eb | balrog | uint8_t cfi_len; |
74 | 05ee37eb | balrog | uint8_t cfi_table[0x52];
|
75 | c227f099 | Anthony Liguori | target_phys_addr_t counter; |
76 | b4bf0a9a | Edgar E. Iglesias | unsigned int writeblock_size; |
77 | 05ee37eb | balrog | QEMUTimer *timer; |
78 | cfe5f011 | Avi Kivity | MemoryRegion mem; |
79 | 05ee37eb | balrog | void *storage;
|
80 | 05ee37eb | balrog | }; |
81 | 05ee37eb | balrog | |
82 | 05ee37eb | balrog | static void pflash_timer (void *opaque) |
83 | 05ee37eb | balrog | { |
84 | c227f099 | Anthony Liguori | pflash_t *pfl = opaque; |
85 | 05ee37eb | balrog | |
86 | 05ee37eb | balrog | DPRINTF("%s: command %02x done\n", __func__, pfl->cmd);
|
87 | 05ee37eb | balrog | /* Reset flash */
|
88 | 05ee37eb | balrog | pfl->status ^= 0x80;
|
89 | 05ee37eb | balrog | if (pfl->bypass) {
|
90 | 05ee37eb | balrog | pfl->wcycle = 2;
|
91 | 05ee37eb | balrog | } else {
|
92 | cfe5f011 | Avi Kivity | memory_region_rom_device_set_readable(&pfl->mem, true);
|
93 | 05ee37eb | balrog | pfl->wcycle = 0;
|
94 | 05ee37eb | balrog | } |
95 | 05ee37eb | balrog | pfl->cmd = 0;
|
96 | 05ee37eb | balrog | } |
97 | 05ee37eb | balrog | |
98 | c227f099 | Anthony Liguori | static uint32_t pflash_read (pflash_t *pfl, target_phys_addr_t offset,
|
99 | 3d08ff69 | Blue Swirl | int width, int be) |
100 | 05ee37eb | balrog | { |
101 | c227f099 | Anthony Liguori | target_phys_addr_t boff; |
102 | 05ee37eb | balrog | uint32_t ret; |
103 | 05ee37eb | balrog | uint8_t *p; |
104 | 05ee37eb | balrog | |
105 | 05ee37eb | balrog | ret = -1;
|
106 | 05ee37eb | balrog | boff = offset & 0xFF; /* why this here ?? */ |
107 | 05ee37eb | balrog | |
108 | 05ee37eb | balrog | if (pfl->width == 2) |
109 | 05ee37eb | balrog | boff = boff >> 1;
|
110 | 05ee37eb | balrog | else if (pfl->width == 4) |
111 | 05ee37eb | balrog | boff = boff >> 2;
|
112 | 05ee37eb | balrog | |
113 | fad8c772 | Edgar E. Iglesias | #if 0
|
114 | fad8c772 | Edgar E. Iglesias | DPRINTF("%s: reading offset " TARGET_FMT_plx " under cmd %02x width %d\n",
|
115 | 06adb549 | balrog | __func__, offset, pfl->cmd, width);
|
116 | fad8c772 | Edgar E. Iglesias | #endif
|
117 | 05ee37eb | balrog | switch (pfl->cmd) {
|
118 | 05ee37eb | balrog | case 0x00: |
119 | 05ee37eb | balrog | /* Flash area read */
|
120 | 05ee37eb | balrog | p = pfl->storage; |
121 | 05ee37eb | balrog | switch (width) {
|
122 | 05ee37eb | balrog | case 1: |
123 | 05ee37eb | balrog | ret = p[offset]; |
124 | fad8c772 | Edgar E. Iglesias | DPRINTF("%s: data offset " TARGET_FMT_plx " %02x\n", |
125 | c8b153d7 | ths | __func__, offset, ret); |
126 | 05ee37eb | balrog | break;
|
127 | 05ee37eb | balrog | case 2: |
128 | 3d08ff69 | Blue Swirl | if (be) {
|
129 | 3d08ff69 | Blue Swirl | ret = p[offset] << 8;
|
130 | 3d08ff69 | Blue Swirl | ret |= p[offset + 1];
|
131 | 3d08ff69 | Blue Swirl | } else {
|
132 | 3d08ff69 | Blue Swirl | ret = p[offset]; |
133 | 3d08ff69 | Blue Swirl | ret |= p[offset + 1] << 8; |
134 | 3d08ff69 | Blue Swirl | } |
135 | fad8c772 | Edgar E. Iglesias | DPRINTF("%s: data offset " TARGET_FMT_plx " %04x\n", |
136 | c8b153d7 | ths | __func__, offset, ret); |
137 | 05ee37eb | balrog | break;
|
138 | 05ee37eb | balrog | case 4: |
139 | 3d08ff69 | Blue Swirl | if (be) {
|
140 | 3d08ff69 | Blue Swirl | ret = p[offset] << 24;
|
141 | 3d08ff69 | Blue Swirl | ret |= p[offset + 1] << 16; |
142 | 3d08ff69 | Blue Swirl | ret |= p[offset + 2] << 8; |
143 | 3d08ff69 | Blue Swirl | ret |= p[offset + 3];
|
144 | 3d08ff69 | Blue Swirl | } else {
|
145 | 3d08ff69 | Blue Swirl | ret = p[offset]; |
146 | 3d08ff69 | Blue Swirl | ret |= p[offset + 1] << 8; |
147 | 3d08ff69 | Blue Swirl | ret |= p[offset + 1] << 8; |
148 | 3d08ff69 | Blue Swirl | ret |= p[offset + 2] << 16; |
149 | 3d08ff69 | Blue Swirl | ret |= p[offset + 3] << 24; |
150 | 3d08ff69 | Blue Swirl | } |
151 | fad8c772 | Edgar E. Iglesias | DPRINTF("%s: data offset " TARGET_FMT_plx " %08x\n", |
152 | c8b153d7 | ths | __func__, offset, ret); |
153 | 05ee37eb | balrog | break;
|
154 | 05ee37eb | balrog | default:
|
155 | 05ee37eb | balrog | DPRINTF("BUG in %s\n", __func__);
|
156 | 05ee37eb | balrog | } |
157 | 05ee37eb | balrog | |
158 | 05ee37eb | balrog | break;
|
159 | 05ee37eb | balrog | case 0x20: /* Block erase */ |
160 | 05ee37eb | balrog | case 0x50: /* Clear status register */ |
161 | 05ee37eb | balrog | case 0x60: /* Block /un)lock */ |
162 | 05ee37eb | balrog | case 0x70: /* Status Register */ |
163 | 05ee37eb | balrog | case 0xe8: /* Write block */ |
164 | 05ee37eb | balrog | /* Status register read */
|
165 | 05ee37eb | balrog | ret = pfl->status; |
166 | 05ee37eb | balrog | DPRINTF("%s: status %x\n", __func__, ret);
|
167 | 05ee37eb | balrog | break;
|
168 | 0b2ec6fc | Michael Walle | case 0x90: |
169 | 0b2ec6fc | Michael Walle | switch (boff) {
|
170 | 0b2ec6fc | Michael Walle | case 0: |
171 | 0b2ec6fc | Michael Walle | ret = pfl->ident[0] << 8 | pfl->ident[1]; |
172 | 0b2ec6fc | Michael Walle | DPRINTF("%s: Manufacturer Code %04x\n", __func__, ret);
|
173 | 0b2ec6fc | Michael Walle | break;
|
174 | 0b2ec6fc | Michael Walle | case 1: |
175 | 0b2ec6fc | Michael Walle | ret = pfl->ident[2] << 8 | pfl->ident[3]; |
176 | 0b2ec6fc | Michael Walle | DPRINTF("%s: Device ID Code %04x\n", __func__, ret);
|
177 | 0b2ec6fc | Michael Walle | break;
|
178 | 0b2ec6fc | Michael Walle | default:
|
179 | 0b2ec6fc | Michael Walle | DPRINTF("%s: Read Device Information boff=%x\n", __func__, boff);
|
180 | 0b2ec6fc | Michael Walle | ret = 0;
|
181 | 0b2ec6fc | Michael Walle | break;
|
182 | 0b2ec6fc | Michael Walle | } |
183 | 0b2ec6fc | Michael Walle | break;
|
184 | 05ee37eb | balrog | case 0x98: /* Query mode */ |
185 | 05ee37eb | balrog | if (boff > pfl->cfi_len)
|
186 | 05ee37eb | balrog | ret = 0;
|
187 | 05ee37eb | balrog | else
|
188 | 05ee37eb | balrog | ret = pfl->cfi_table[boff]; |
189 | 05ee37eb | balrog | break;
|
190 | 05ee37eb | balrog | default:
|
191 | 05ee37eb | balrog | /* This should never happen : reset state & treat it as a read */
|
192 | 05ee37eb | balrog | DPRINTF("%s: unknown command state: %x\n", __func__, pfl->cmd);
|
193 | 05ee37eb | balrog | pfl->wcycle = 0;
|
194 | 05ee37eb | balrog | pfl->cmd = 0;
|
195 | 05ee37eb | balrog | } |
196 | 05ee37eb | balrog | return ret;
|
197 | 05ee37eb | balrog | } |
198 | 05ee37eb | balrog | |
199 | 05ee37eb | balrog | /* update flash content on disk */
|
200 | c227f099 | Anthony Liguori | static void pflash_update(pflash_t *pfl, int offset, |
201 | 05ee37eb | balrog | int size)
|
202 | 05ee37eb | balrog | { |
203 | 05ee37eb | balrog | int offset_end;
|
204 | 05ee37eb | balrog | if (pfl->bs) {
|
205 | 05ee37eb | balrog | offset_end = offset + size; |
206 | 05ee37eb | balrog | /* round to sectors */
|
207 | 05ee37eb | balrog | offset = offset >> 9;
|
208 | 05ee37eb | balrog | offset_end = (offset_end + 511) >> 9; |
209 | 05ee37eb | balrog | bdrv_write(pfl->bs, offset, pfl->storage + (offset << 9),
|
210 | 05ee37eb | balrog | offset_end - offset); |
211 | 05ee37eb | balrog | } |
212 | 05ee37eb | balrog | } |
213 | 05ee37eb | balrog | |
214 | c227f099 | Anthony Liguori | static inline void pflash_data_write(pflash_t *pfl, target_phys_addr_t offset, |
215 | 3d08ff69 | Blue Swirl | uint32_t value, int width, int be) |
216 | d361be25 | balrog | { |
217 | d361be25 | balrog | uint8_t *p = pfl->storage; |
218 | d361be25 | balrog | |
219 | fad8c772 | Edgar E. Iglesias | DPRINTF("%s: block write offset " TARGET_FMT_plx
|
220 | fad8c772 | Edgar E. Iglesias | " value %x counter " TARGET_FMT_plx "\n", |
221 | d361be25 | balrog | __func__, offset, value, pfl->counter); |
222 | d361be25 | balrog | switch (width) {
|
223 | d361be25 | balrog | case 1: |
224 | d361be25 | balrog | p[offset] = value; |
225 | d361be25 | balrog | break;
|
226 | d361be25 | balrog | case 2: |
227 | 3d08ff69 | Blue Swirl | if (be) {
|
228 | 3d08ff69 | Blue Swirl | p[offset] = value >> 8;
|
229 | 3d08ff69 | Blue Swirl | p[offset + 1] = value;
|
230 | 3d08ff69 | Blue Swirl | } else {
|
231 | 3d08ff69 | Blue Swirl | p[offset] = value; |
232 | 3d08ff69 | Blue Swirl | p[offset + 1] = value >> 8; |
233 | 3d08ff69 | Blue Swirl | } |
234 | d361be25 | balrog | break;
|
235 | d361be25 | balrog | case 4: |
236 | 3d08ff69 | Blue Swirl | if (be) {
|
237 | 3d08ff69 | Blue Swirl | p[offset] = value >> 24;
|
238 | 3d08ff69 | Blue Swirl | p[offset + 1] = value >> 16; |
239 | 3d08ff69 | Blue Swirl | p[offset + 2] = value >> 8; |
240 | 3d08ff69 | Blue Swirl | p[offset + 3] = value;
|
241 | 3d08ff69 | Blue Swirl | } else {
|
242 | 3d08ff69 | Blue Swirl | p[offset] = value; |
243 | 3d08ff69 | Blue Swirl | p[offset + 1] = value >> 8; |
244 | 3d08ff69 | Blue Swirl | p[offset + 2] = value >> 16; |
245 | 3d08ff69 | Blue Swirl | p[offset + 3] = value >> 24; |
246 | 3d08ff69 | Blue Swirl | } |
247 | d361be25 | balrog | break;
|
248 | d361be25 | balrog | } |
249 | d361be25 | balrog | |
250 | d361be25 | balrog | } |
251 | d361be25 | balrog | |
252 | c227f099 | Anthony Liguori | static void pflash_write(pflash_t *pfl, target_phys_addr_t offset, |
253 | 3d08ff69 | Blue Swirl | uint32_t value, int width, int be) |
254 | 05ee37eb | balrog | { |
255 | 05ee37eb | balrog | uint8_t *p; |
256 | 05ee37eb | balrog | uint8_t cmd; |
257 | 05ee37eb | balrog | |
258 | 05ee37eb | balrog | cmd = value; |
259 | 05ee37eb | balrog | |
260 | fad8c772 | Edgar E. Iglesias | DPRINTF("%s: writing offset " TARGET_FMT_plx " value %08x width %d wcycle 0x%x\n", |
261 | c8b153d7 | ths | __func__, offset, value, width, pfl->wcycle); |
262 | 05ee37eb | balrog | |
263 | e9cbbcac | Edgar E. Iglesias | if (!pfl->wcycle) {
|
264 | e9cbbcac | Edgar E. Iglesias | /* Set the device in I/O access mode */
|
265 | cfe5f011 | Avi Kivity | memory_region_rom_device_set_readable(&pfl->mem, false);
|
266 | e9cbbcac | Edgar E. Iglesias | } |
267 | 05ee37eb | balrog | |
268 | 05ee37eb | balrog | switch (pfl->wcycle) {
|
269 | 05ee37eb | balrog | case 0: |
270 | 05ee37eb | balrog | /* read mode */
|
271 | 05ee37eb | balrog | switch (cmd) {
|
272 | 05ee37eb | balrog | case 0x00: /* ??? */ |
273 | 05ee37eb | balrog | goto reset_flash;
|
274 | d361be25 | balrog | case 0x10: /* Single Byte Program */ |
275 | d361be25 | balrog | case 0x40: /* Single Byte Program */ |
276 | fad8c772 | Edgar E. Iglesias | DPRINTF("%s: Single Byte Program\n", __func__);
|
277 | d361be25 | balrog | break;
|
278 | 05ee37eb | balrog | case 0x20: /* Block erase */ |
279 | 05ee37eb | balrog | p = pfl->storage; |
280 | 05ee37eb | balrog | offset &= ~(pfl->sector_len - 1);
|
281 | 05ee37eb | balrog | |
282 | fad8c772 | Edgar E. Iglesias | DPRINTF("%s: block erase at " TARGET_FMT_plx " bytes " |
283 | fad8c772 | Edgar E. Iglesias | TARGET_FMT_plx "\n",
|
284 | c8b153d7 | ths | __func__, offset, pfl->sector_len); |
285 | 05ee37eb | balrog | |
286 | 05ee37eb | balrog | memset(p + offset, 0xff, pfl->sector_len);
|
287 | 05ee37eb | balrog | pflash_update(pfl, offset, pfl->sector_len); |
288 | 05ee37eb | balrog | pfl->status |= 0x80; /* Ready! */ |
289 | 05ee37eb | balrog | break;
|
290 | 05ee37eb | balrog | case 0x50: /* Clear status bits */ |
291 | 05ee37eb | balrog | DPRINTF("%s: Clear status bits\n", __func__);
|
292 | 05ee37eb | balrog | pfl->status = 0x0;
|
293 | 05ee37eb | balrog | goto reset_flash;
|
294 | 05ee37eb | balrog | case 0x60: /* Block (un)lock */ |
295 | 05ee37eb | balrog | DPRINTF("%s: Block unlock\n", __func__);
|
296 | 05ee37eb | balrog | break;
|
297 | 05ee37eb | balrog | case 0x70: /* Status Register */ |
298 | 05ee37eb | balrog | DPRINTF("%s: Read status register\n", __func__);
|
299 | 05ee37eb | balrog | pfl->cmd = cmd; |
300 | 05ee37eb | balrog | return;
|
301 | 0b2ec6fc | Michael Walle | case 0x90: /* Read Device ID */ |
302 | 0b2ec6fc | Michael Walle | DPRINTF("%s: Read Device information\n", __func__);
|
303 | 0b2ec6fc | Michael Walle | pfl->cmd = cmd; |
304 | 0b2ec6fc | Michael Walle | return;
|
305 | 05ee37eb | balrog | case 0x98: /* CFI query */ |
306 | 05ee37eb | balrog | DPRINTF("%s: CFI query\n", __func__);
|
307 | 05ee37eb | balrog | break;
|
308 | 05ee37eb | balrog | case 0xe8: /* Write to buffer */ |
309 | 05ee37eb | balrog | DPRINTF("%s: Write to buffer\n", __func__);
|
310 | 05ee37eb | balrog | pfl->status |= 0x80; /* Ready! */ |
311 | 05ee37eb | balrog | break;
|
312 | 05ee37eb | balrog | case 0xff: /* Read array mode */ |
313 | 05ee37eb | balrog | DPRINTF("%s: Read array mode\n", __func__);
|
314 | 05ee37eb | balrog | goto reset_flash;
|
315 | 05ee37eb | balrog | default:
|
316 | 05ee37eb | balrog | goto error_flash;
|
317 | 05ee37eb | balrog | } |
318 | 05ee37eb | balrog | pfl->wcycle++; |
319 | 05ee37eb | balrog | pfl->cmd = cmd; |
320 | 05ee37eb | balrog | return;
|
321 | 05ee37eb | balrog | case 1: |
322 | 05ee37eb | balrog | switch (pfl->cmd) {
|
323 | d361be25 | balrog | case 0x10: /* Single Byte Program */ |
324 | d361be25 | balrog | case 0x40: /* Single Byte Program */ |
325 | d361be25 | balrog | DPRINTF("%s: Single Byte Program\n", __func__);
|
326 | 3d08ff69 | Blue Swirl | pflash_data_write(pfl, offset, value, width, be); |
327 | b4bf0a9a | Edgar E. Iglesias | pflash_update(pfl, offset, width); |
328 | d361be25 | balrog | pfl->status |= 0x80; /* Ready! */ |
329 | d361be25 | balrog | pfl->wcycle = 0;
|
330 | d361be25 | balrog | break;
|
331 | 05ee37eb | balrog | case 0x20: /* Block erase */ |
332 | 05ee37eb | balrog | case 0x28: |
333 | 05ee37eb | balrog | if (cmd == 0xd0) { /* confirm */ |
334 | 3656744c | balrog | pfl->wcycle = 0;
|
335 | 05ee37eb | balrog | pfl->status |= 0x80;
|
336 | 9248f413 | aurel32 | } else if (cmd == 0xff) { /* read array mode */ |
337 | 05ee37eb | balrog | goto reset_flash;
|
338 | 05ee37eb | balrog | } else
|
339 | 05ee37eb | balrog | goto error_flash;
|
340 | 05ee37eb | balrog | |
341 | 05ee37eb | balrog | break;
|
342 | 05ee37eb | balrog | case 0xe8: |
343 | 71fb2348 | balrog | DPRINTF("%s: block write of %x bytes\n", __func__, value);
|
344 | 71fb2348 | balrog | pfl->counter = value; |
345 | 05ee37eb | balrog | pfl->wcycle++; |
346 | 05ee37eb | balrog | break;
|
347 | 05ee37eb | balrog | case 0x60: |
348 | 05ee37eb | balrog | if (cmd == 0xd0) { |
349 | 05ee37eb | balrog | pfl->wcycle = 0;
|
350 | 05ee37eb | balrog | pfl->status |= 0x80;
|
351 | 05ee37eb | balrog | } else if (cmd == 0x01) { |
352 | 05ee37eb | balrog | pfl->wcycle = 0;
|
353 | 05ee37eb | balrog | pfl->status |= 0x80;
|
354 | 05ee37eb | balrog | } else if (cmd == 0xff) { |
355 | 05ee37eb | balrog | goto reset_flash;
|
356 | 05ee37eb | balrog | } else {
|
357 | 05ee37eb | balrog | DPRINTF("%s: Unknown (un)locking command\n", __func__);
|
358 | 05ee37eb | balrog | goto reset_flash;
|
359 | 05ee37eb | balrog | } |
360 | 05ee37eb | balrog | break;
|
361 | 05ee37eb | balrog | case 0x98: |
362 | 05ee37eb | balrog | if (cmd == 0xff) { |
363 | 05ee37eb | balrog | goto reset_flash;
|
364 | 05ee37eb | balrog | } else {
|
365 | 05ee37eb | balrog | DPRINTF("%s: leaving query mode\n", __func__);
|
366 | 05ee37eb | balrog | } |
367 | 05ee37eb | balrog | break;
|
368 | 05ee37eb | balrog | default:
|
369 | 05ee37eb | balrog | goto error_flash;
|
370 | 05ee37eb | balrog | } |
371 | 05ee37eb | balrog | return;
|
372 | 05ee37eb | balrog | case 2: |
373 | 05ee37eb | balrog | switch (pfl->cmd) {
|
374 | 05ee37eb | balrog | case 0xe8: /* Block write */ |
375 | 3d08ff69 | Blue Swirl | pflash_data_write(pfl, offset, value, width, be); |
376 | 05ee37eb | balrog | |
377 | 05ee37eb | balrog | pfl->status |= 0x80;
|
378 | 05ee37eb | balrog | |
379 | 05ee37eb | balrog | if (!pfl->counter) {
|
380 | b4bf0a9a | Edgar E. Iglesias | target_phys_addr_t mask = pfl->writeblock_size - 1;
|
381 | b4bf0a9a | Edgar E. Iglesias | mask = ~mask; |
382 | b4bf0a9a | Edgar E. Iglesias | |
383 | 05ee37eb | balrog | DPRINTF("%s: block write finished\n", __func__);
|
384 | 05ee37eb | balrog | pfl->wcycle++; |
385 | b4bf0a9a | Edgar E. Iglesias | /* Flush the entire write buffer onto backing storage. */
|
386 | b4bf0a9a | Edgar E. Iglesias | pflash_update(pfl, offset & mask, pfl->writeblock_size); |
387 | 05ee37eb | balrog | } |
388 | 05ee37eb | balrog | |
389 | 05ee37eb | balrog | pfl->counter--; |
390 | 05ee37eb | balrog | break;
|
391 | 7317b8ca | balrog | default:
|
392 | 7317b8ca | balrog | goto error_flash;
|
393 | 05ee37eb | balrog | } |
394 | 05ee37eb | balrog | return;
|
395 | 05ee37eb | balrog | case 3: /* Confirm mode */ |
396 | 05ee37eb | balrog | switch (pfl->cmd) {
|
397 | 05ee37eb | balrog | case 0xe8: /* Block write */ |
398 | 05ee37eb | balrog | if (cmd == 0xd0) { |
399 | 05ee37eb | balrog | pfl->wcycle = 0;
|
400 | 05ee37eb | balrog | pfl->status |= 0x80;
|
401 | 05ee37eb | balrog | } else {
|
402 | 05ee37eb | balrog | DPRINTF("%s: unknown command for \"write block\"\n", __func__);
|
403 | 05ee37eb | balrog | PFLASH_BUG("Write block confirm");
|
404 | 7317b8ca | balrog | goto reset_flash;
|
405 | 05ee37eb | balrog | } |
406 | 7317b8ca | balrog | break;
|
407 | 7317b8ca | balrog | default:
|
408 | 7317b8ca | balrog | goto error_flash;
|
409 | 05ee37eb | balrog | } |
410 | 05ee37eb | balrog | return;
|
411 | 05ee37eb | balrog | default:
|
412 | 05ee37eb | balrog | /* Should never happen */
|
413 | 05ee37eb | balrog | DPRINTF("%s: invalid write state\n", __func__);
|
414 | 05ee37eb | balrog | goto reset_flash;
|
415 | 05ee37eb | balrog | } |
416 | 05ee37eb | balrog | return;
|
417 | 05ee37eb | balrog | |
418 | 05ee37eb | balrog | error_flash:
|
419 | 05ee37eb | balrog | printf("%s: Unimplemented flash cmd sequence "
|
420 | 42a89d77 | Paul Brook | "(offset " TARGET_FMT_plx ", wcycle 0x%x cmd 0x%x value 0x%x)\n", |
421 | c8b153d7 | ths | __func__, offset, pfl->wcycle, pfl->cmd, value); |
422 | 05ee37eb | balrog | |
423 | 05ee37eb | balrog | reset_flash:
|
424 | cfe5f011 | Avi Kivity | memory_region_rom_device_set_readable(&pfl->mem, true);
|
425 | 05ee37eb | balrog | |
426 | 05ee37eb | balrog | pfl->bypass = 0;
|
427 | 05ee37eb | balrog | pfl->wcycle = 0;
|
428 | 05ee37eb | balrog | pfl->cmd = 0;
|
429 | 05ee37eb | balrog | return;
|
430 | 05ee37eb | balrog | } |
431 | 05ee37eb | balrog | |
432 | 05ee37eb | balrog | |
433 | 3d08ff69 | Blue Swirl | static uint32_t pflash_readb_be(void *opaque, target_phys_addr_t addr) |
434 | 3d08ff69 | Blue Swirl | { |
435 | 3d08ff69 | Blue Swirl | return pflash_read(opaque, addr, 1, 1); |
436 | 3d08ff69 | Blue Swirl | } |
437 | 3d08ff69 | Blue Swirl | |
438 | 3d08ff69 | Blue Swirl | static uint32_t pflash_readb_le(void *opaque, target_phys_addr_t addr) |
439 | 3d08ff69 | Blue Swirl | { |
440 | 3d08ff69 | Blue Swirl | return pflash_read(opaque, addr, 1, 0); |
441 | 3d08ff69 | Blue Swirl | } |
442 | 3d08ff69 | Blue Swirl | |
443 | 3d08ff69 | Blue Swirl | static uint32_t pflash_readw_be(void *opaque, target_phys_addr_t addr) |
444 | 3d08ff69 | Blue Swirl | { |
445 | 3d08ff69 | Blue Swirl | pflash_t *pfl = opaque; |
446 | 3d08ff69 | Blue Swirl | |
447 | 3d08ff69 | Blue Swirl | return pflash_read(pfl, addr, 2, 1); |
448 | 3d08ff69 | Blue Swirl | } |
449 | 3d08ff69 | Blue Swirl | |
450 | 3d08ff69 | Blue Swirl | static uint32_t pflash_readw_le(void *opaque, target_phys_addr_t addr) |
451 | 05ee37eb | balrog | { |
452 | 3d08ff69 | Blue Swirl | pflash_t *pfl = opaque; |
453 | 3d08ff69 | Blue Swirl | |
454 | 3d08ff69 | Blue Swirl | return pflash_read(pfl, addr, 2, 0); |
455 | 05ee37eb | balrog | } |
456 | 05ee37eb | balrog | |
457 | 3d08ff69 | Blue Swirl | static uint32_t pflash_readl_be(void *opaque, target_phys_addr_t addr) |
458 | 05ee37eb | balrog | { |
459 | c227f099 | Anthony Liguori | pflash_t *pfl = opaque; |
460 | 05ee37eb | balrog | |
461 | 3d08ff69 | Blue Swirl | return pflash_read(pfl, addr, 4, 1); |
462 | 05ee37eb | balrog | } |
463 | 05ee37eb | balrog | |
464 | 3d08ff69 | Blue Swirl | static uint32_t pflash_readl_le(void *opaque, target_phys_addr_t addr) |
465 | 05ee37eb | balrog | { |
466 | c227f099 | Anthony Liguori | pflash_t *pfl = opaque; |
467 | 05ee37eb | balrog | |
468 | 3d08ff69 | Blue Swirl | return pflash_read(pfl, addr, 4, 0); |
469 | 05ee37eb | balrog | } |
470 | 05ee37eb | balrog | |
471 | 3d08ff69 | Blue Swirl | static void pflash_writeb_be(void *opaque, target_phys_addr_t addr, |
472 | 3d08ff69 | Blue Swirl | uint32_t value) |
473 | 05ee37eb | balrog | { |
474 | 3d08ff69 | Blue Swirl | pflash_write(opaque, addr, value, 1, 1); |
475 | 05ee37eb | balrog | } |
476 | 05ee37eb | balrog | |
477 | 3d08ff69 | Blue Swirl | static void pflash_writeb_le(void *opaque, target_phys_addr_t addr, |
478 | 3d08ff69 | Blue Swirl | uint32_t value) |
479 | 3d08ff69 | Blue Swirl | { |
480 | 3d08ff69 | Blue Swirl | pflash_write(opaque, addr, value, 1, 0); |
481 | 3d08ff69 | Blue Swirl | } |
482 | 3d08ff69 | Blue Swirl | |
483 | 3d08ff69 | Blue Swirl | static void pflash_writew_be(void *opaque, target_phys_addr_t addr, |
484 | 3d08ff69 | Blue Swirl | uint32_t value) |
485 | 05ee37eb | balrog | { |
486 | c227f099 | Anthony Liguori | pflash_t *pfl = opaque; |
487 | 05ee37eb | balrog | |
488 | 3d08ff69 | Blue Swirl | pflash_write(pfl, addr, value, 2, 1); |
489 | 05ee37eb | balrog | } |
490 | 05ee37eb | balrog | |
491 | 3d08ff69 | Blue Swirl | static void pflash_writew_le(void *opaque, target_phys_addr_t addr, |
492 | 3d08ff69 | Blue Swirl | uint32_t value) |
493 | 05ee37eb | balrog | { |
494 | c227f099 | Anthony Liguori | pflash_t *pfl = opaque; |
495 | 05ee37eb | balrog | |
496 | 3d08ff69 | Blue Swirl | pflash_write(pfl, addr, value, 2, 0); |
497 | 05ee37eb | balrog | } |
498 | 05ee37eb | balrog | |
499 | 3d08ff69 | Blue Swirl | static void pflash_writel_be(void *opaque, target_phys_addr_t addr, |
500 | 3d08ff69 | Blue Swirl | uint32_t value) |
501 | 3d08ff69 | Blue Swirl | { |
502 | 3d08ff69 | Blue Swirl | pflash_t *pfl = opaque; |
503 | 3d08ff69 | Blue Swirl | |
504 | 3d08ff69 | Blue Swirl | pflash_write(pfl, addr, value, 4, 1); |
505 | 3d08ff69 | Blue Swirl | } |
506 | 3d08ff69 | Blue Swirl | |
507 | 3d08ff69 | Blue Swirl | static void pflash_writel_le(void *opaque, target_phys_addr_t addr, |
508 | 3d08ff69 | Blue Swirl | uint32_t value) |
509 | 3d08ff69 | Blue Swirl | { |
510 | 3d08ff69 | Blue Swirl | pflash_t *pfl = opaque; |
511 | 3d08ff69 | Blue Swirl | |
512 | 3d08ff69 | Blue Swirl | pflash_write(pfl, addr, value, 4, 0); |
513 | 3d08ff69 | Blue Swirl | } |
514 | 3d08ff69 | Blue Swirl | |
515 | cfe5f011 | Avi Kivity | static const MemoryRegionOps pflash_cfi01_ops_be = { |
516 | cfe5f011 | Avi Kivity | .old_mmio = { |
517 | cfe5f011 | Avi Kivity | .read = { pflash_readb_be, pflash_readw_be, pflash_readl_be, }, |
518 | cfe5f011 | Avi Kivity | .write = { pflash_writeb_be, pflash_writew_be, pflash_writel_be, }, |
519 | cfe5f011 | Avi Kivity | }, |
520 | cfe5f011 | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
521 | 05ee37eb | balrog | }; |
522 | 05ee37eb | balrog | |
523 | cfe5f011 | Avi Kivity | static const MemoryRegionOps pflash_cfi01_ops_le = { |
524 | cfe5f011 | Avi Kivity | .old_mmio = { |
525 | cfe5f011 | Avi Kivity | .read = { pflash_readb_le, pflash_readw_le, pflash_readl_le, }, |
526 | cfe5f011 | Avi Kivity | .write = { pflash_writeb_le, pflash_writew_le, pflash_writel_le, }, |
527 | cfe5f011 | Avi Kivity | }, |
528 | cfe5f011 | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
529 | 05ee37eb | balrog | }; |
530 | 05ee37eb | balrog | |
531 | 05ee37eb | balrog | /* Count trailing zeroes of a 32 bits quantity */
|
532 | 05ee37eb | balrog | static int ctz32 (uint32_t n) |
533 | 05ee37eb | balrog | { |
534 | 05ee37eb | balrog | int ret;
|
535 | 05ee37eb | balrog | |
536 | 05ee37eb | balrog | ret = 0;
|
537 | 05ee37eb | balrog | if (!(n & 0xFFFF)) { |
538 | 05ee37eb | balrog | ret += 16;
|
539 | 05ee37eb | balrog | n = n >> 16;
|
540 | 05ee37eb | balrog | } |
541 | 05ee37eb | balrog | if (!(n & 0xFF)) { |
542 | 05ee37eb | balrog | ret += 8;
|
543 | 05ee37eb | balrog | n = n >> 8;
|
544 | 05ee37eb | balrog | } |
545 | 05ee37eb | balrog | if (!(n & 0xF)) { |
546 | 05ee37eb | balrog | ret += 4;
|
547 | 05ee37eb | balrog | n = n >> 4;
|
548 | 05ee37eb | balrog | } |
549 | 05ee37eb | balrog | if (!(n & 0x3)) { |
550 | 05ee37eb | balrog | ret += 2;
|
551 | 05ee37eb | balrog | n = n >> 2;
|
552 | 05ee37eb | balrog | } |
553 | 05ee37eb | balrog | if (!(n & 0x1)) { |
554 | 05ee37eb | balrog | ret++; |
555 | 22ed1d34 | Blue Swirl | #if 0 /* This is not necessary as n is never 0 */
|
556 | 05ee37eb | balrog | n = n >> 1;
|
557 | 22ed1d34 | Blue Swirl | #endif
|
558 | 05ee37eb | balrog | } |
559 | 05ee37eb | balrog | #if 0 /* This is not necessary as n is never 0 */
|
560 | 05ee37eb | balrog | if (!n)
|
561 | 05ee37eb | balrog | ret++;
|
562 | 05ee37eb | balrog | #endif
|
563 | 05ee37eb | balrog | |
564 | 05ee37eb | balrog | return ret;
|
565 | 05ee37eb | balrog | } |
566 | 05ee37eb | balrog | |
567 | cfe5f011 | Avi Kivity | pflash_t *pflash_cfi01_register(target_phys_addr_t base, |
568 | cfe5f011 | Avi Kivity | DeviceState *qdev, const char *name, |
569 | cfe5f011 | Avi Kivity | target_phys_addr_t size, |
570 | c8b153d7 | ths | BlockDriverState *bs, uint32_t sector_len, |
571 | 88eeee0a | balrog | int nb_blocs, int width, |
572 | 88eeee0a | balrog | uint16_t id0, uint16_t id1, |
573 | cfe5f011 | Avi Kivity | uint16_t id2, uint16_t id3, int be)
|
574 | 05ee37eb | balrog | { |
575 | c227f099 | Anthony Liguori | pflash_t *pfl; |
576 | c227f099 | Anthony Liguori | target_phys_addr_t total_len; |
577 | d0e7605e | Vijay Kumar | int ret;
|
578 | 05ee37eb | balrog | |
579 | 05ee37eb | balrog | total_len = sector_len * nb_blocs; |
580 | 05ee37eb | balrog | |
581 | 05ee37eb | balrog | /* XXX: to be fixed */
|
582 | c8b153d7 | ths | #if 0
|
583 | 05ee37eb | balrog | if (total_len != (8 * 1024 * 1024) && total_len != (16 * 1024 * 1024) &&
|
584 | 05ee37eb | balrog | total_len != (32 * 1024 * 1024) && total_len != (64 * 1024 * 1024))
|
585 | 05ee37eb | balrog | return NULL;
|
586 | c8b153d7 | ths | #endif
|
587 | 05ee37eb | balrog | |
588 | 7267c094 | Anthony Liguori | pfl = g_malloc0(sizeof(pflash_t));
|
589 | 05ee37eb | balrog | |
590 | cfe5f011 | Avi Kivity | memory_region_init_rom_device( |
591 | cfe5f011 | Avi Kivity | &pfl->mem, be ? &pflash_cfi01_ops_be : &pflash_cfi01_ops_le, pfl, |
592 | cfe5f011 | Avi Kivity | qdev, name, size); |
593 | cfe5f011 | Avi Kivity | pfl->storage = memory_region_get_ram_ptr(&pfl->mem); |
594 | cfe5f011 | Avi Kivity | memory_region_add_subregion(get_system_memory(), base, &pfl->mem); |
595 | 05ee37eb | balrog | |
596 | 05ee37eb | balrog | pfl->bs = bs; |
597 | 05ee37eb | balrog | if (pfl->bs) {
|
598 | 05ee37eb | balrog | /* read the initial flash content */
|
599 | d0e7605e | Vijay Kumar | ret = bdrv_read(pfl->bs, 0, pfl->storage, total_len >> 9); |
600 | d0e7605e | Vijay Kumar | if (ret < 0) { |
601 | cfe5f011 | Avi Kivity | memory_region_del_subregion(get_system_memory(), &pfl->mem); |
602 | cfe5f011 | Avi Kivity | memory_region_destroy(&pfl->mem); |
603 | 7267c094 | Anthony Liguori | g_free(pfl); |
604 | d0e7605e | Vijay Kumar | return NULL; |
605 | d0e7605e | Vijay Kumar | } |
606 | fa879d62 | Markus Armbruster | bdrv_attach_dev_nofail(pfl->bs, pfl); |
607 | 05ee37eb | balrog | } |
608 | 05ee37eb | balrog | #if 0 /* XXX: there should be a bit to set up read-only,
|
609 | 05ee37eb | balrog | * the same way the hardware does (with WP pin).
|
610 | 05ee37eb | balrog | */
|
611 | 05ee37eb | balrog | pfl->ro = 1;
|
612 | 05ee37eb | balrog | #else
|
613 | 05ee37eb | balrog | pfl->ro = 0;
|
614 | 05ee37eb | balrog | #endif
|
615 | 74475455 | Paolo Bonzini | pfl->timer = qemu_new_timer_ns(vm_clock, pflash_timer, pfl); |
616 | 05ee37eb | balrog | pfl->base = base; |
617 | 05ee37eb | balrog | pfl->sector_len = sector_len; |
618 | 05ee37eb | balrog | pfl->total_len = total_len; |
619 | 05ee37eb | balrog | pfl->width = width; |
620 | 05ee37eb | balrog | pfl->wcycle = 0;
|
621 | 05ee37eb | balrog | pfl->cmd = 0;
|
622 | 05ee37eb | balrog | pfl->status = 0;
|
623 | 05ee37eb | balrog | pfl->ident[0] = id0;
|
624 | 05ee37eb | balrog | pfl->ident[1] = id1;
|
625 | 05ee37eb | balrog | pfl->ident[2] = id2;
|
626 | 05ee37eb | balrog | pfl->ident[3] = id3;
|
627 | 05ee37eb | balrog | /* Hardcoded CFI table */
|
628 | 05ee37eb | balrog | pfl->cfi_len = 0x52;
|
629 | 05ee37eb | balrog | /* Standard "QRY" string */
|
630 | 05ee37eb | balrog | pfl->cfi_table[0x10] = 'Q'; |
631 | 05ee37eb | balrog | pfl->cfi_table[0x11] = 'R'; |
632 | 05ee37eb | balrog | pfl->cfi_table[0x12] = 'Y'; |
633 | 05ee37eb | balrog | /* Command set (Intel) */
|
634 | 05ee37eb | balrog | pfl->cfi_table[0x13] = 0x01; |
635 | 05ee37eb | balrog | pfl->cfi_table[0x14] = 0x00; |
636 | 05ee37eb | balrog | /* Primary extended table address (none) */
|
637 | 05ee37eb | balrog | pfl->cfi_table[0x15] = 0x31; |
638 | 05ee37eb | balrog | pfl->cfi_table[0x16] = 0x00; |
639 | 05ee37eb | balrog | /* Alternate command set (none) */
|
640 | 05ee37eb | balrog | pfl->cfi_table[0x17] = 0x00; |
641 | 05ee37eb | balrog | pfl->cfi_table[0x18] = 0x00; |
642 | 05ee37eb | balrog | /* Alternate extended table (none) */
|
643 | 05ee37eb | balrog | pfl->cfi_table[0x19] = 0x00; |
644 | 05ee37eb | balrog | pfl->cfi_table[0x1A] = 0x00; |
645 | 05ee37eb | balrog | /* Vcc min */
|
646 | 05ee37eb | balrog | pfl->cfi_table[0x1B] = 0x45; |
647 | 05ee37eb | balrog | /* Vcc max */
|
648 | 05ee37eb | balrog | pfl->cfi_table[0x1C] = 0x55; |
649 | 05ee37eb | balrog | /* Vpp min (no Vpp pin) */
|
650 | 05ee37eb | balrog | pfl->cfi_table[0x1D] = 0x00; |
651 | 05ee37eb | balrog | /* Vpp max (no Vpp pin) */
|
652 | 05ee37eb | balrog | pfl->cfi_table[0x1E] = 0x00; |
653 | 05ee37eb | balrog | /* Reserved */
|
654 | 05ee37eb | balrog | pfl->cfi_table[0x1F] = 0x07; |
655 | 05ee37eb | balrog | /* Timeout for min size buffer write */
|
656 | 05ee37eb | balrog | pfl->cfi_table[0x20] = 0x07; |
657 | 05ee37eb | balrog | /* Typical timeout for block erase */
|
658 | 05ee37eb | balrog | pfl->cfi_table[0x21] = 0x0a; |
659 | 05ee37eb | balrog | /* Typical timeout for full chip erase (4096 ms) */
|
660 | 05ee37eb | balrog | pfl->cfi_table[0x22] = 0x00; |
661 | 05ee37eb | balrog | /* Reserved */
|
662 | 05ee37eb | balrog | pfl->cfi_table[0x23] = 0x04; |
663 | 05ee37eb | balrog | /* Max timeout for buffer write */
|
664 | 05ee37eb | balrog | pfl->cfi_table[0x24] = 0x04; |
665 | 05ee37eb | balrog | /* Max timeout for block erase */
|
666 | 05ee37eb | balrog | pfl->cfi_table[0x25] = 0x04; |
667 | 05ee37eb | balrog | /* Max timeout for chip erase */
|
668 | 05ee37eb | balrog | pfl->cfi_table[0x26] = 0x00; |
669 | 05ee37eb | balrog | /* Device size */
|
670 | 05ee37eb | balrog | pfl->cfi_table[0x27] = ctz32(total_len); // + 1; |
671 | 05ee37eb | balrog | /* Flash device interface (8 & 16 bits) */
|
672 | 05ee37eb | balrog | pfl->cfi_table[0x28] = 0x02; |
673 | 05ee37eb | balrog | pfl->cfi_table[0x29] = 0x00; |
674 | 05ee37eb | balrog | /* Max number of bytes in multi-bytes write */
|
675 | 4737fa26 | Edgar E. Iglesias | if (width == 1) { |
676 | 4737fa26 | Edgar E. Iglesias | pfl->cfi_table[0x2A] = 0x08; |
677 | 4737fa26 | Edgar E. Iglesias | } else {
|
678 | 4737fa26 | Edgar E. Iglesias | pfl->cfi_table[0x2A] = 0x0B; |
679 | 4737fa26 | Edgar E. Iglesias | } |
680 | b4bf0a9a | Edgar E. Iglesias | pfl->writeblock_size = 1 << pfl->cfi_table[0x2A]; |
681 | b4bf0a9a | Edgar E. Iglesias | |
682 | 05ee37eb | balrog | pfl->cfi_table[0x2B] = 0x00; |
683 | 05ee37eb | balrog | /* Number of erase block regions (uniform) */
|
684 | 05ee37eb | balrog | pfl->cfi_table[0x2C] = 0x01; |
685 | 05ee37eb | balrog | /* Erase block region 1 */
|
686 | 05ee37eb | balrog | pfl->cfi_table[0x2D] = nb_blocs - 1; |
687 | 05ee37eb | balrog | pfl->cfi_table[0x2E] = (nb_blocs - 1) >> 8; |
688 | 05ee37eb | balrog | pfl->cfi_table[0x2F] = sector_len >> 8; |
689 | 05ee37eb | balrog | pfl->cfi_table[0x30] = sector_len >> 16; |
690 | 05ee37eb | balrog | |
691 | 05ee37eb | balrog | /* Extended */
|
692 | 05ee37eb | balrog | pfl->cfi_table[0x31] = 'P'; |
693 | 05ee37eb | balrog | pfl->cfi_table[0x32] = 'R'; |
694 | 05ee37eb | balrog | pfl->cfi_table[0x33] = 'I'; |
695 | 05ee37eb | balrog | |
696 | 05ee37eb | balrog | pfl->cfi_table[0x34] = '1'; |
697 | 05ee37eb | balrog | pfl->cfi_table[0x35] = '1'; |
698 | 05ee37eb | balrog | |
699 | 05ee37eb | balrog | pfl->cfi_table[0x36] = 0x00; |
700 | 05ee37eb | balrog | pfl->cfi_table[0x37] = 0x00; |
701 | 05ee37eb | balrog | pfl->cfi_table[0x38] = 0x00; |
702 | 05ee37eb | balrog | pfl->cfi_table[0x39] = 0x00; |
703 | 05ee37eb | balrog | |
704 | 05ee37eb | balrog | pfl->cfi_table[0x3a] = 0x00; |
705 | 05ee37eb | balrog | |
706 | 05ee37eb | balrog | pfl->cfi_table[0x3b] = 0x00; |
707 | 05ee37eb | balrog | pfl->cfi_table[0x3c] = 0x00; |
708 | 05ee37eb | balrog | |
709 | 05ee37eb | balrog | return pfl;
|
710 | 05ee37eb | balrog | } |
711 | cfe5f011 | Avi Kivity | |
712 | cfe5f011 | Avi Kivity | MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl) |
713 | cfe5f011 | Avi Kivity | { |
714 | cfe5f011 | Avi Kivity | return &fl->mem;
|
715 | cfe5f011 | Avi Kivity | } |