root / hw / pflash_cfi01.c @ 03f48b07
History | View | Annotate | Download (20.5 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 | de8efe8f | Jordan Justen | if (!pfl->ro) {
|
287 | de8efe8f | Jordan Justen | memset(p + offset, 0xff, pfl->sector_len);
|
288 | de8efe8f | Jordan Justen | pflash_update(pfl, offset, pfl->sector_len); |
289 | de8efe8f | Jordan Justen | } else {
|
290 | de8efe8f | Jordan Justen | pfl->status |= 0x20; /* Block erase error */ |
291 | de8efe8f | Jordan Justen | } |
292 | 05ee37eb | balrog | pfl->status |= 0x80; /* Ready! */ |
293 | 05ee37eb | balrog | break;
|
294 | 05ee37eb | balrog | case 0x50: /* Clear status bits */ |
295 | 05ee37eb | balrog | DPRINTF("%s: Clear status bits\n", __func__);
|
296 | 05ee37eb | balrog | pfl->status = 0x0;
|
297 | 05ee37eb | balrog | goto reset_flash;
|
298 | 05ee37eb | balrog | case 0x60: /* Block (un)lock */ |
299 | 05ee37eb | balrog | DPRINTF("%s: Block unlock\n", __func__);
|
300 | 05ee37eb | balrog | break;
|
301 | 05ee37eb | balrog | case 0x70: /* Status Register */ |
302 | 05ee37eb | balrog | DPRINTF("%s: Read status register\n", __func__);
|
303 | 05ee37eb | balrog | pfl->cmd = cmd; |
304 | 05ee37eb | balrog | return;
|
305 | 0b2ec6fc | Michael Walle | case 0x90: /* Read Device ID */ |
306 | 0b2ec6fc | Michael Walle | DPRINTF("%s: Read Device information\n", __func__);
|
307 | 0b2ec6fc | Michael Walle | pfl->cmd = cmd; |
308 | 0b2ec6fc | Michael Walle | return;
|
309 | 05ee37eb | balrog | case 0x98: /* CFI query */ |
310 | 05ee37eb | balrog | DPRINTF("%s: CFI query\n", __func__);
|
311 | 05ee37eb | balrog | break;
|
312 | 05ee37eb | balrog | case 0xe8: /* Write to buffer */ |
313 | 05ee37eb | balrog | DPRINTF("%s: Write to buffer\n", __func__);
|
314 | 05ee37eb | balrog | pfl->status |= 0x80; /* Ready! */ |
315 | 05ee37eb | balrog | break;
|
316 | 05ee37eb | balrog | case 0xff: /* Read array mode */ |
317 | 05ee37eb | balrog | DPRINTF("%s: Read array mode\n", __func__);
|
318 | 05ee37eb | balrog | goto reset_flash;
|
319 | 05ee37eb | balrog | default:
|
320 | 05ee37eb | balrog | goto error_flash;
|
321 | 05ee37eb | balrog | } |
322 | 05ee37eb | balrog | pfl->wcycle++; |
323 | 05ee37eb | balrog | pfl->cmd = cmd; |
324 | 05ee37eb | balrog | return;
|
325 | 05ee37eb | balrog | case 1: |
326 | 05ee37eb | balrog | switch (pfl->cmd) {
|
327 | d361be25 | balrog | case 0x10: /* Single Byte Program */ |
328 | d361be25 | balrog | case 0x40: /* Single Byte Program */ |
329 | d361be25 | balrog | DPRINTF("%s: Single Byte Program\n", __func__);
|
330 | de8efe8f | Jordan Justen | if (!pfl->ro) {
|
331 | de8efe8f | Jordan Justen | pflash_data_write(pfl, offset, value, width, be); |
332 | de8efe8f | Jordan Justen | pflash_update(pfl, offset, width); |
333 | de8efe8f | Jordan Justen | } else {
|
334 | de8efe8f | Jordan Justen | pfl->status |= 0x10; /* Programming error */ |
335 | de8efe8f | Jordan Justen | } |
336 | d361be25 | balrog | pfl->status |= 0x80; /* Ready! */ |
337 | d361be25 | balrog | pfl->wcycle = 0;
|
338 | d361be25 | balrog | break;
|
339 | 05ee37eb | balrog | case 0x20: /* Block erase */ |
340 | 05ee37eb | balrog | case 0x28: |
341 | 05ee37eb | balrog | if (cmd == 0xd0) { /* confirm */ |
342 | 3656744c | balrog | pfl->wcycle = 0;
|
343 | 05ee37eb | balrog | pfl->status |= 0x80;
|
344 | 9248f413 | aurel32 | } else if (cmd == 0xff) { /* read array mode */ |
345 | 05ee37eb | balrog | goto reset_flash;
|
346 | 05ee37eb | balrog | } else
|
347 | 05ee37eb | balrog | goto error_flash;
|
348 | 05ee37eb | balrog | |
349 | 05ee37eb | balrog | break;
|
350 | 05ee37eb | balrog | case 0xe8: |
351 | 71fb2348 | balrog | DPRINTF("%s: block write of %x bytes\n", __func__, value);
|
352 | 71fb2348 | balrog | pfl->counter = value; |
353 | 05ee37eb | balrog | pfl->wcycle++; |
354 | 05ee37eb | balrog | break;
|
355 | 05ee37eb | balrog | case 0x60: |
356 | 05ee37eb | balrog | if (cmd == 0xd0) { |
357 | 05ee37eb | balrog | pfl->wcycle = 0;
|
358 | 05ee37eb | balrog | pfl->status |= 0x80;
|
359 | 05ee37eb | balrog | } else if (cmd == 0x01) { |
360 | 05ee37eb | balrog | pfl->wcycle = 0;
|
361 | 05ee37eb | balrog | pfl->status |= 0x80;
|
362 | 05ee37eb | balrog | } else if (cmd == 0xff) { |
363 | 05ee37eb | balrog | goto reset_flash;
|
364 | 05ee37eb | balrog | } else {
|
365 | 05ee37eb | balrog | DPRINTF("%s: Unknown (un)locking command\n", __func__);
|
366 | 05ee37eb | balrog | goto reset_flash;
|
367 | 05ee37eb | balrog | } |
368 | 05ee37eb | balrog | break;
|
369 | 05ee37eb | balrog | case 0x98: |
370 | 05ee37eb | balrog | if (cmd == 0xff) { |
371 | 05ee37eb | balrog | goto reset_flash;
|
372 | 05ee37eb | balrog | } else {
|
373 | 05ee37eb | balrog | DPRINTF("%s: leaving query mode\n", __func__);
|
374 | 05ee37eb | balrog | } |
375 | 05ee37eb | balrog | break;
|
376 | 05ee37eb | balrog | default:
|
377 | 05ee37eb | balrog | goto error_flash;
|
378 | 05ee37eb | balrog | } |
379 | 05ee37eb | balrog | return;
|
380 | 05ee37eb | balrog | case 2: |
381 | 05ee37eb | balrog | switch (pfl->cmd) {
|
382 | 05ee37eb | balrog | case 0xe8: /* Block write */ |
383 | de8efe8f | Jordan Justen | if (!pfl->ro) {
|
384 | de8efe8f | Jordan Justen | pflash_data_write(pfl, offset, value, width, be); |
385 | de8efe8f | Jordan Justen | } else {
|
386 | de8efe8f | Jordan Justen | pfl->status |= 0x10; /* Programming error */ |
387 | de8efe8f | Jordan Justen | } |
388 | 05ee37eb | balrog | |
389 | 05ee37eb | balrog | pfl->status |= 0x80;
|
390 | 05ee37eb | balrog | |
391 | 05ee37eb | balrog | if (!pfl->counter) {
|
392 | b4bf0a9a | Edgar E. Iglesias | target_phys_addr_t mask = pfl->writeblock_size - 1;
|
393 | b4bf0a9a | Edgar E. Iglesias | mask = ~mask; |
394 | b4bf0a9a | Edgar E. Iglesias | |
395 | 05ee37eb | balrog | DPRINTF("%s: block write finished\n", __func__);
|
396 | 05ee37eb | balrog | pfl->wcycle++; |
397 | de8efe8f | Jordan Justen | if (!pfl->ro) {
|
398 | de8efe8f | Jordan Justen | /* Flush the entire write buffer onto backing storage. */
|
399 | de8efe8f | Jordan Justen | pflash_update(pfl, offset & mask, pfl->writeblock_size); |
400 | de8efe8f | Jordan Justen | } else {
|
401 | de8efe8f | Jordan Justen | pfl->status |= 0x10; /* Programming error */ |
402 | de8efe8f | Jordan Justen | } |
403 | 05ee37eb | balrog | } |
404 | 05ee37eb | balrog | |
405 | 05ee37eb | balrog | pfl->counter--; |
406 | 05ee37eb | balrog | break;
|
407 | 7317b8ca | balrog | default:
|
408 | 7317b8ca | balrog | goto error_flash;
|
409 | 05ee37eb | balrog | } |
410 | 05ee37eb | balrog | return;
|
411 | 05ee37eb | balrog | case 3: /* Confirm mode */ |
412 | 05ee37eb | balrog | switch (pfl->cmd) {
|
413 | 05ee37eb | balrog | case 0xe8: /* Block write */ |
414 | 05ee37eb | balrog | if (cmd == 0xd0) { |
415 | 05ee37eb | balrog | pfl->wcycle = 0;
|
416 | 05ee37eb | balrog | pfl->status |= 0x80;
|
417 | 05ee37eb | balrog | } else {
|
418 | 05ee37eb | balrog | DPRINTF("%s: unknown command for \"write block\"\n", __func__);
|
419 | 05ee37eb | balrog | PFLASH_BUG("Write block confirm");
|
420 | 7317b8ca | balrog | goto reset_flash;
|
421 | 05ee37eb | balrog | } |
422 | 7317b8ca | balrog | break;
|
423 | 7317b8ca | balrog | default:
|
424 | 7317b8ca | balrog | goto error_flash;
|
425 | 05ee37eb | balrog | } |
426 | 05ee37eb | balrog | return;
|
427 | 05ee37eb | balrog | default:
|
428 | 05ee37eb | balrog | /* Should never happen */
|
429 | 05ee37eb | balrog | DPRINTF("%s: invalid write state\n", __func__);
|
430 | 05ee37eb | balrog | goto reset_flash;
|
431 | 05ee37eb | balrog | } |
432 | 05ee37eb | balrog | return;
|
433 | 05ee37eb | balrog | |
434 | 05ee37eb | balrog | error_flash:
|
435 | 05ee37eb | balrog | printf("%s: Unimplemented flash cmd sequence "
|
436 | 42a89d77 | Paul Brook | "(offset " TARGET_FMT_plx ", wcycle 0x%x cmd 0x%x value 0x%x)\n", |
437 | c8b153d7 | ths | __func__, offset, pfl->wcycle, pfl->cmd, value); |
438 | 05ee37eb | balrog | |
439 | 05ee37eb | balrog | reset_flash:
|
440 | cfe5f011 | Avi Kivity | memory_region_rom_device_set_readable(&pfl->mem, true);
|
441 | 05ee37eb | balrog | |
442 | 05ee37eb | balrog | pfl->bypass = 0;
|
443 | 05ee37eb | balrog | pfl->wcycle = 0;
|
444 | 05ee37eb | balrog | pfl->cmd = 0;
|
445 | 05ee37eb | balrog | return;
|
446 | 05ee37eb | balrog | } |
447 | 05ee37eb | balrog | |
448 | 05ee37eb | balrog | |
449 | 3d08ff69 | Blue Swirl | static uint32_t pflash_readb_be(void *opaque, target_phys_addr_t addr) |
450 | 3d08ff69 | Blue Swirl | { |
451 | 3d08ff69 | Blue Swirl | return pflash_read(opaque, addr, 1, 1); |
452 | 3d08ff69 | Blue Swirl | } |
453 | 3d08ff69 | Blue Swirl | |
454 | 3d08ff69 | Blue Swirl | static uint32_t pflash_readb_le(void *opaque, target_phys_addr_t addr) |
455 | 3d08ff69 | Blue Swirl | { |
456 | 3d08ff69 | Blue Swirl | return pflash_read(opaque, addr, 1, 0); |
457 | 3d08ff69 | Blue Swirl | } |
458 | 3d08ff69 | Blue Swirl | |
459 | 3d08ff69 | Blue Swirl | static uint32_t pflash_readw_be(void *opaque, target_phys_addr_t addr) |
460 | 3d08ff69 | Blue Swirl | { |
461 | 3d08ff69 | Blue Swirl | pflash_t *pfl = opaque; |
462 | 3d08ff69 | Blue Swirl | |
463 | 3d08ff69 | Blue Swirl | return pflash_read(pfl, addr, 2, 1); |
464 | 3d08ff69 | Blue Swirl | } |
465 | 3d08ff69 | Blue Swirl | |
466 | 3d08ff69 | Blue Swirl | static uint32_t pflash_readw_le(void *opaque, target_phys_addr_t addr) |
467 | 05ee37eb | balrog | { |
468 | 3d08ff69 | Blue Swirl | pflash_t *pfl = opaque; |
469 | 3d08ff69 | Blue Swirl | |
470 | 3d08ff69 | Blue Swirl | return pflash_read(pfl, addr, 2, 0); |
471 | 05ee37eb | balrog | } |
472 | 05ee37eb | balrog | |
473 | 3d08ff69 | Blue Swirl | static uint32_t pflash_readl_be(void *opaque, target_phys_addr_t addr) |
474 | 05ee37eb | balrog | { |
475 | c227f099 | Anthony Liguori | pflash_t *pfl = opaque; |
476 | 05ee37eb | balrog | |
477 | 3d08ff69 | Blue Swirl | return pflash_read(pfl, addr, 4, 1); |
478 | 05ee37eb | balrog | } |
479 | 05ee37eb | balrog | |
480 | 3d08ff69 | Blue Swirl | static uint32_t pflash_readl_le(void *opaque, target_phys_addr_t addr) |
481 | 05ee37eb | balrog | { |
482 | c227f099 | Anthony Liguori | pflash_t *pfl = opaque; |
483 | 05ee37eb | balrog | |
484 | 3d08ff69 | Blue Swirl | return pflash_read(pfl, addr, 4, 0); |
485 | 05ee37eb | balrog | } |
486 | 05ee37eb | balrog | |
487 | 3d08ff69 | Blue Swirl | static void pflash_writeb_be(void *opaque, target_phys_addr_t addr, |
488 | 3d08ff69 | Blue Swirl | uint32_t value) |
489 | 05ee37eb | balrog | { |
490 | 3d08ff69 | Blue Swirl | pflash_write(opaque, addr, value, 1, 1); |
491 | 05ee37eb | balrog | } |
492 | 05ee37eb | balrog | |
493 | 3d08ff69 | Blue Swirl | static void pflash_writeb_le(void *opaque, target_phys_addr_t addr, |
494 | 3d08ff69 | Blue Swirl | uint32_t value) |
495 | 3d08ff69 | Blue Swirl | { |
496 | 3d08ff69 | Blue Swirl | pflash_write(opaque, addr, value, 1, 0); |
497 | 3d08ff69 | Blue Swirl | } |
498 | 3d08ff69 | Blue Swirl | |
499 | 3d08ff69 | Blue Swirl | static void pflash_writew_be(void *opaque, target_phys_addr_t addr, |
500 | 3d08ff69 | Blue Swirl | uint32_t value) |
501 | 05ee37eb | balrog | { |
502 | c227f099 | Anthony Liguori | pflash_t *pfl = opaque; |
503 | 05ee37eb | balrog | |
504 | 3d08ff69 | Blue Swirl | pflash_write(pfl, addr, value, 2, 1); |
505 | 05ee37eb | balrog | } |
506 | 05ee37eb | balrog | |
507 | 3d08ff69 | Blue Swirl | static void pflash_writew_le(void *opaque, target_phys_addr_t addr, |
508 | 3d08ff69 | Blue Swirl | uint32_t value) |
509 | 05ee37eb | balrog | { |
510 | c227f099 | Anthony Liguori | pflash_t *pfl = opaque; |
511 | 05ee37eb | balrog | |
512 | 3d08ff69 | Blue Swirl | pflash_write(pfl, addr, value, 2, 0); |
513 | 05ee37eb | balrog | } |
514 | 05ee37eb | balrog | |
515 | 3d08ff69 | Blue Swirl | static void pflash_writel_be(void *opaque, target_phys_addr_t addr, |
516 | 3d08ff69 | Blue Swirl | uint32_t value) |
517 | 3d08ff69 | Blue Swirl | { |
518 | 3d08ff69 | Blue Swirl | pflash_t *pfl = opaque; |
519 | 3d08ff69 | Blue Swirl | |
520 | 3d08ff69 | Blue Swirl | pflash_write(pfl, addr, value, 4, 1); |
521 | 3d08ff69 | Blue Swirl | } |
522 | 3d08ff69 | Blue Swirl | |
523 | 3d08ff69 | Blue Swirl | static void pflash_writel_le(void *opaque, target_phys_addr_t addr, |
524 | 3d08ff69 | Blue Swirl | uint32_t value) |
525 | 3d08ff69 | Blue Swirl | { |
526 | 3d08ff69 | Blue Swirl | pflash_t *pfl = opaque; |
527 | 3d08ff69 | Blue Swirl | |
528 | 3d08ff69 | Blue Swirl | pflash_write(pfl, addr, value, 4, 0); |
529 | 3d08ff69 | Blue Swirl | } |
530 | 3d08ff69 | Blue Swirl | |
531 | cfe5f011 | Avi Kivity | static const MemoryRegionOps pflash_cfi01_ops_be = { |
532 | cfe5f011 | Avi Kivity | .old_mmio = { |
533 | cfe5f011 | Avi Kivity | .read = { pflash_readb_be, pflash_readw_be, pflash_readl_be, }, |
534 | cfe5f011 | Avi Kivity | .write = { pflash_writeb_be, pflash_writew_be, pflash_writel_be, }, |
535 | cfe5f011 | Avi Kivity | }, |
536 | cfe5f011 | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
537 | 05ee37eb | balrog | }; |
538 | 05ee37eb | balrog | |
539 | cfe5f011 | Avi Kivity | static const MemoryRegionOps pflash_cfi01_ops_le = { |
540 | cfe5f011 | Avi Kivity | .old_mmio = { |
541 | cfe5f011 | Avi Kivity | .read = { pflash_readb_le, pflash_readw_le, pflash_readl_le, }, |
542 | cfe5f011 | Avi Kivity | .write = { pflash_writeb_le, pflash_writew_le, pflash_writel_le, }, |
543 | cfe5f011 | Avi Kivity | }, |
544 | cfe5f011 | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
545 | 05ee37eb | balrog | }; |
546 | 05ee37eb | balrog | |
547 | 05ee37eb | balrog | /* Count trailing zeroes of a 32 bits quantity */
|
548 | 05ee37eb | balrog | static int ctz32 (uint32_t n) |
549 | 05ee37eb | balrog | { |
550 | 05ee37eb | balrog | int ret;
|
551 | 05ee37eb | balrog | |
552 | 05ee37eb | balrog | ret = 0;
|
553 | 05ee37eb | balrog | if (!(n & 0xFFFF)) { |
554 | 05ee37eb | balrog | ret += 16;
|
555 | 05ee37eb | balrog | n = n >> 16;
|
556 | 05ee37eb | balrog | } |
557 | 05ee37eb | balrog | if (!(n & 0xFF)) { |
558 | 05ee37eb | balrog | ret += 8;
|
559 | 05ee37eb | balrog | n = n >> 8;
|
560 | 05ee37eb | balrog | } |
561 | 05ee37eb | balrog | if (!(n & 0xF)) { |
562 | 05ee37eb | balrog | ret += 4;
|
563 | 05ee37eb | balrog | n = n >> 4;
|
564 | 05ee37eb | balrog | } |
565 | 05ee37eb | balrog | if (!(n & 0x3)) { |
566 | 05ee37eb | balrog | ret += 2;
|
567 | 05ee37eb | balrog | n = n >> 2;
|
568 | 05ee37eb | balrog | } |
569 | 05ee37eb | balrog | if (!(n & 0x1)) { |
570 | 05ee37eb | balrog | ret++; |
571 | 22ed1d34 | Blue Swirl | #if 0 /* This is not necessary as n is never 0 */
|
572 | 05ee37eb | balrog | n = n >> 1;
|
573 | 22ed1d34 | Blue Swirl | #endif
|
574 | 05ee37eb | balrog | } |
575 | 05ee37eb | balrog | #if 0 /* This is not necessary as n is never 0 */
|
576 | 05ee37eb | balrog | if (!n)
|
577 | 05ee37eb | balrog | ret++;
|
578 | 05ee37eb | balrog | #endif
|
579 | 05ee37eb | balrog | |
580 | 05ee37eb | balrog | return ret;
|
581 | 05ee37eb | balrog | } |
582 | 05ee37eb | balrog | |
583 | cfe5f011 | Avi Kivity | pflash_t *pflash_cfi01_register(target_phys_addr_t base, |
584 | cfe5f011 | Avi Kivity | DeviceState *qdev, const char *name, |
585 | cfe5f011 | Avi Kivity | target_phys_addr_t size, |
586 | c8b153d7 | ths | BlockDriverState *bs, uint32_t sector_len, |
587 | 88eeee0a | balrog | int nb_blocs, int width, |
588 | 88eeee0a | balrog | uint16_t id0, uint16_t id1, |
589 | cfe5f011 | Avi Kivity | uint16_t id2, uint16_t id3, int be)
|
590 | 05ee37eb | balrog | { |
591 | c227f099 | Anthony Liguori | pflash_t *pfl; |
592 | c227f099 | Anthony Liguori | target_phys_addr_t total_len; |
593 | d0e7605e | Vijay Kumar | int ret;
|
594 | 05ee37eb | balrog | |
595 | 05ee37eb | balrog | total_len = sector_len * nb_blocs; |
596 | 05ee37eb | balrog | |
597 | 05ee37eb | balrog | /* XXX: to be fixed */
|
598 | c8b153d7 | ths | #if 0
|
599 | 05ee37eb | balrog | if (total_len != (8 * 1024 * 1024) && total_len != (16 * 1024 * 1024) &&
|
600 | 05ee37eb | balrog | total_len != (32 * 1024 * 1024) && total_len != (64 * 1024 * 1024))
|
601 | 05ee37eb | balrog | return NULL;
|
602 | c8b153d7 | ths | #endif
|
603 | 05ee37eb | balrog | |
604 | 7267c094 | Anthony Liguori | pfl = g_malloc0(sizeof(pflash_t));
|
605 | 05ee37eb | balrog | |
606 | cfe5f011 | Avi Kivity | memory_region_init_rom_device( |
607 | cfe5f011 | Avi Kivity | &pfl->mem, be ? &pflash_cfi01_ops_be : &pflash_cfi01_ops_le, pfl, |
608 | c5705a77 | Avi Kivity | name, size); |
609 | c5705a77 | Avi Kivity | vmstate_register_ram(&pfl->mem, qdev); |
610 | cfe5f011 | Avi Kivity | pfl->storage = memory_region_get_ram_ptr(&pfl->mem); |
611 | cfe5f011 | Avi Kivity | memory_region_add_subregion(get_system_memory(), base, &pfl->mem); |
612 | 05ee37eb | balrog | |
613 | 05ee37eb | balrog | pfl->bs = bs; |
614 | 05ee37eb | balrog | if (pfl->bs) {
|
615 | 05ee37eb | balrog | /* read the initial flash content */
|
616 | d0e7605e | Vijay Kumar | ret = bdrv_read(pfl->bs, 0, pfl->storage, total_len >> 9); |
617 | d0e7605e | Vijay Kumar | if (ret < 0) { |
618 | cfe5f011 | Avi Kivity | memory_region_del_subregion(get_system_memory(), &pfl->mem); |
619 | c5705a77 | Avi Kivity | vmstate_unregister_ram(&pfl->mem, qdev); |
620 | cfe5f011 | Avi Kivity | memory_region_destroy(&pfl->mem); |
621 | 7267c094 | Anthony Liguori | g_free(pfl); |
622 | d0e7605e | Vijay Kumar | return NULL; |
623 | d0e7605e | Vijay Kumar | } |
624 | fa879d62 | Markus Armbruster | bdrv_attach_dev_nofail(pfl->bs, pfl); |
625 | 05ee37eb | balrog | } |
626 | de8efe8f | Jordan Justen | |
627 | de8efe8f | Jordan Justen | if (pfl->bs) {
|
628 | de8efe8f | Jordan Justen | pfl->ro = bdrv_is_read_only(pfl->bs); |
629 | de8efe8f | Jordan Justen | } else {
|
630 | de8efe8f | Jordan Justen | pfl->ro = 0;
|
631 | de8efe8f | Jordan Justen | } |
632 | de8efe8f | Jordan Justen | |
633 | 74475455 | Paolo Bonzini | pfl->timer = qemu_new_timer_ns(vm_clock, pflash_timer, pfl); |
634 | 05ee37eb | balrog | pfl->base = base; |
635 | 05ee37eb | balrog | pfl->sector_len = sector_len; |
636 | 05ee37eb | balrog | pfl->total_len = total_len; |
637 | 05ee37eb | balrog | pfl->width = width; |
638 | 05ee37eb | balrog | pfl->wcycle = 0;
|
639 | 05ee37eb | balrog | pfl->cmd = 0;
|
640 | 05ee37eb | balrog | pfl->status = 0;
|
641 | 05ee37eb | balrog | pfl->ident[0] = id0;
|
642 | 05ee37eb | balrog | pfl->ident[1] = id1;
|
643 | 05ee37eb | balrog | pfl->ident[2] = id2;
|
644 | 05ee37eb | balrog | pfl->ident[3] = id3;
|
645 | 05ee37eb | balrog | /* Hardcoded CFI table */
|
646 | 05ee37eb | balrog | pfl->cfi_len = 0x52;
|
647 | 05ee37eb | balrog | /* Standard "QRY" string */
|
648 | 05ee37eb | balrog | pfl->cfi_table[0x10] = 'Q'; |
649 | 05ee37eb | balrog | pfl->cfi_table[0x11] = 'R'; |
650 | 05ee37eb | balrog | pfl->cfi_table[0x12] = 'Y'; |
651 | 05ee37eb | balrog | /* Command set (Intel) */
|
652 | 05ee37eb | balrog | pfl->cfi_table[0x13] = 0x01; |
653 | 05ee37eb | balrog | pfl->cfi_table[0x14] = 0x00; |
654 | 05ee37eb | balrog | /* Primary extended table address (none) */
|
655 | 05ee37eb | balrog | pfl->cfi_table[0x15] = 0x31; |
656 | 05ee37eb | balrog | pfl->cfi_table[0x16] = 0x00; |
657 | 05ee37eb | balrog | /* Alternate command set (none) */
|
658 | 05ee37eb | balrog | pfl->cfi_table[0x17] = 0x00; |
659 | 05ee37eb | balrog | pfl->cfi_table[0x18] = 0x00; |
660 | 05ee37eb | balrog | /* Alternate extended table (none) */
|
661 | 05ee37eb | balrog | pfl->cfi_table[0x19] = 0x00; |
662 | 05ee37eb | balrog | pfl->cfi_table[0x1A] = 0x00; |
663 | 05ee37eb | balrog | /* Vcc min */
|
664 | 05ee37eb | balrog | pfl->cfi_table[0x1B] = 0x45; |
665 | 05ee37eb | balrog | /* Vcc max */
|
666 | 05ee37eb | balrog | pfl->cfi_table[0x1C] = 0x55; |
667 | 05ee37eb | balrog | /* Vpp min (no Vpp pin) */
|
668 | 05ee37eb | balrog | pfl->cfi_table[0x1D] = 0x00; |
669 | 05ee37eb | balrog | /* Vpp max (no Vpp pin) */
|
670 | 05ee37eb | balrog | pfl->cfi_table[0x1E] = 0x00; |
671 | 05ee37eb | balrog | /* Reserved */
|
672 | 05ee37eb | balrog | pfl->cfi_table[0x1F] = 0x07; |
673 | 05ee37eb | balrog | /* Timeout for min size buffer write */
|
674 | 05ee37eb | balrog | pfl->cfi_table[0x20] = 0x07; |
675 | 05ee37eb | balrog | /* Typical timeout for block erase */
|
676 | 05ee37eb | balrog | pfl->cfi_table[0x21] = 0x0a; |
677 | 05ee37eb | balrog | /* Typical timeout for full chip erase (4096 ms) */
|
678 | 05ee37eb | balrog | pfl->cfi_table[0x22] = 0x00; |
679 | 05ee37eb | balrog | /* Reserved */
|
680 | 05ee37eb | balrog | pfl->cfi_table[0x23] = 0x04; |
681 | 05ee37eb | balrog | /* Max timeout for buffer write */
|
682 | 05ee37eb | balrog | pfl->cfi_table[0x24] = 0x04; |
683 | 05ee37eb | balrog | /* Max timeout for block erase */
|
684 | 05ee37eb | balrog | pfl->cfi_table[0x25] = 0x04; |
685 | 05ee37eb | balrog | /* Max timeout for chip erase */
|
686 | 05ee37eb | balrog | pfl->cfi_table[0x26] = 0x00; |
687 | 05ee37eb | balrog | /* Device size */
|
688 | 05ee37eb | balrog | pfl->cfi_table[0x27] = ctz32(total_len); // + 1; |
689 | 05ee37eb | balrog | /* Flash device interface (8 & 16 bits) */
|
690 | 05ee37eb | balrog | pfl->cfi_table[0x28] = 0x02; |
691 | 05ee37eb | balrog | pfl->cfi_table[0x29] = 0x00; |
692 | 05ee37eb | balrog | /* Max number of bytes in multi-bytes write */
|
693 | 4737fa26 | Edgar E. Iglesias | if (width == 1) { |
694 | 4737fa26 | Edgar E. Iglesias | pfl->cfi_table[0x2A] = 0x08; |
695 | 4737fa26 | Edgar E. Iglesias | } else {
|
696 | 4737fa26 | Edgar E. Iglesias | pfl->cfi_table[0x2A] = 0x0B; |
697 | 4737fa26 | Edgar E. Iglesias | } |
698 | b4bf0a9a | Edgar E. Iglesias | pfl->writeblock_size = 1 << pfl->cfi_table[0x2A]; |
699 | b4bf0a9a | Edgar E. Iglesias | |
700 | 05ee37eb | balrog | pfl->cfi_table[0x2B] = 0x00; |
701 | 05ee37eb | balrog | /* Number of erase block regions (uniform) */
|
702 | 05ee37eb | balrog | pfl->cfi_table[0x2C] = 0x01; |
703 | 05ee37eb | balrog | /* Erase block region 1 */
|
704 | 05ee37eb | balrog | pfl->cfi_table[0x2D] = nb_blocs - 1; |
705 | 05ee37eb | balrog | pfl->cfi_table[0x2E] = (nb_blocs - 1) >> 8; |
706 | 05ee37eb | balrog | pfl->cfi_table[0x2F] = sector_len >> 8; |
707 | 05ee37eb | balrog | pfl->cfi_table[0x30] = sector_len >> 16; |
708 | 05ee37eb | balrog | |
709 | 05ee37eb | balrog | /* Extended */
|
710 | 05ee37eb | balrog | pfl->cfi_table[0x31] = 'P'; |
711 | 05ee37eb | balrog | pfl->cfi_table[0x32] = 'R'; |
712 | 05ee37eb | balrog | pfl->cfi_table[0x33] = 'I'; |
713 | 05ee37eb | balrog | |
714 | 05ee37eb | balrog | pfl->cfi_table[0x34] = '1'; |
715 | 05ee37eb | balrog | pfl->cfi_table[0x35] = '1'; |
716 | 05ee37eb | balrog | |
717 | 05ee37eb | balrog | pfl->cfi_table[0x36] = 0x00; |
718 | 05ee37eb | balrog | pfl->cfi_table[0x37] = 0x00; |
719 | 05ee37eb | balrog | pfl->cfi_table[0x38] = 0x00; |
720 | 05ee37eb | balrog | pfl->cfi_table[0x39] = 0x00; |
721 | 05ee37eb | balrog | |
722 | 05ee37eb | balrog | pfl->cfi_table[0x3a] = 0x00; |
723 | 05ee37eb | balrog | |
724 | 05ee37eb | balrog | pfl->cfi_table[0x3b] = 0x00; |
725 | 05ee37eb | balrog | pfl->cfi_table[0x3c] = 0x00; |
726 | 05ee37eb | balrog | |
727 | 05ee37eb | balrog | return pfl;
|
728 | 05ee37eb | balrog | } |
729 | cfe5f011 | Avi Kivity | |
730 | cfe5f011 | Avi Kivity | MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl) |
731 | cfe5f011 | Avi Kivity | { |
732 | cfe5f011 | Avi Kivity | return &fl->mem;
|
733 | cfe5f011 | Avi Kivity | } |