2 * CFI parallel flash with Intel command set emulation
4 * Copyright (c) 2006 Thorsten Zitterell
5 * Copyright (c) 2005 Jocelyn Mayer
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 * For now, this code can emulate flashes of 1, 2 or 4 bytes width.
23 * Supported commands/modes are:
30 * It does not support timings
31 * It does not support flash interleaving
32 * It does not implement software data protection as found in many real chips
33 * It does not implement erase suspend/resume commands
34 * It does not implement multiple sectors erase
36 * It does not implement much more ...
40 #include "hw/block/flash.h"
41 #include "sysemu/block-backend.h"
42 #include "qemu/timer.h"
43 #include "qemu/bitops.h"
44 #include "exec/address-spaces.h"
45 #include "qemu/host-utils.h"
46 #include "hw/sysbus.h"
48 #define PFLASH_BUG(fmt, ...) \
50 fprintf(stderr, "PFLASH: Possible BUG - " fmt, ## __VA_ARGS__); \
54 /* #define PFLASH_DEBUG */
56 #define DPRINTF(fmt, ...) \
58 fprintf(stderr, "PFLASH: " fmt , ## __VA_ARGS__); \
61 #define DPRINTF(fmt, ...) do { } while (0)
64 #define TYPE_CFI_PFLASH01 "cfi.pflash01"
65 #define CFI_PFLASH01(obj) OBJECT_CHECK(pflash_t, (obj), TYPE_CFI_PFLASH01)
71 SysBusDevice parent_obj;
78 uint8_t device_width; /* If 0, device width not specified. */
79 uint8_t max_device_width; /* max device width in bytes */
81 uint8_t wcycle; /* if 0, the flash is read normally */
90 uint8_t cfi_table[0x52];
92 unsigned int writeblock_size;
99 static int pflash_post_load(void *opaque, int version_id);
101 static const VMStateDescription vmstate_pflash = {
102 .name = "pflash_cfi01",
104 .minimum_version_id = 1,
105 .post_load = pflash_post_load,
106 .fields = (VMStateField[]) {
107 VMSTATE_UINT8(wcycle, pflash_t),
108 VMSTATE_UINT8(cmd, pflash_t),
109 VMSTATE_UINT8(status, pflash_t),
110 VMSTATE_UINT64(counter, pflash_t),
111 VMSTATE_END_OF_LIST()
115 static void pflash_timer (void *opaque)
117 pflash_t *pfl = opaque;
119 DPRINTF("%s: command %02x done\n", __func__, pfl->cmd);
122 memory_region_rom_device_set_romd(&pfl->mem, true);
127 /* Perform a CFI query based on the bank width of the flash.
128 * If this code is called we know we have a device_width set for
131 static uint32_t pflash_cfi_query(pflash_t *pfl, hwaddr offset)
137 /* Adjust incoming offset to match expected device-width
138 * addressing. CFI query addresses are always specified in terms of
139 * the maximum supported width of the device. This means that x8
140 * devices and x8/x16 devices in x8 mode behave differently. For
141 * devices that are not used at their max width, we will be
142 * provided with addresses that use higher address bits than
143 * expected (based on the max width), so we will shift them lower
144 * so that they will match the addresses used when
145 * device_width==max_device_width.
147 boff = offset >> (ctz32(pfl->bank_width) +
148 ctz32(pfl->max_device_width) - ctz32(pfl->device_width));
150 if (boff > pfl->cfi_len) {
153 /* Now we will construct the CFI response generated by a single
154 * device, then replicate that for all devices that make up the
155 * bus. For wide parts used in x8 mode, CFI query responses
156 * are different than native byte-wide parts.
158 resp = pfl->cfi_table[boff];
159 if (pfl->device_width != pfl->max_device_width) {
160 /* The only case currently supported is x8 mode for a
163 if (pfl->device_width != 1 || pfl->bank_width > 4) {
164 DPRINTF("%s: Unsupported device configuration: "
165 "device_width=%d, max_device_width=%d\n",
166 __func__, pfl->device_width,
167 pfl->max_device_width);
170 /* CFI query data is repeated, rather than zero padded for
171 * wide devices used in x8 mode.
173 for (i = 1; i < pfl->max_device_width; i++) {
174 resp = deposit32(resp, 8 * i, 8, pfl->cfi_table[boff]);
177 /* Replicate responses for each device in bank. */
178 if (pfl->device_width < pfl->bank_width) {
179 for (i = pfl->device_width;
180 i < pfl->bank_width; i += pfl->device_width) {
181 resp = deposit32(resp, 8 * i, 8 * pfl->device_width, resp);
190 /* Perform a device id query based on the bank width of the flash. */
191 static uint32_t pflash_devid_query(pflash_t *pfl, hwaddr offset)
197 /* Adjust incoming offset to match expected device-width
198 * addressing. Device ID read addresses are always specified in
199 * terms of the maximum supported width of the device. This means
200 * that x8 devices and x8/x16 devices in x8 mode behave
201 * differently. For devices that are not used at their max width,
202 * we will be provided with addresses that use higher address bits
203 * than expected (based on the max width), so we will shift them
204 * lower so that they will match the addresses used when
205 * device_width==max_device_width.
207 boff = offset >> (ctz32(pfl->bank_width) +
208 ctz32(pfl->max_device_width) - ctz32(pfl->device_width));
210 /* Mask off upper bits which may be used in to query block
211 * or sector lock status at other addresses.
212 * Offsets 2/3 are block lock status, is not emulated.
214 switch (boff & 0xFF) {
217 DPRINTF("%s: Manufacturer Code %04x\n", __func__, resp);
221 DPRINTF("%s: Device ID Code %04x\n", __func__, resp);
224 DPRINTF("%s: Read Device Information offset=%x\n", __func__,
229 /* Replicate responses for each device in bank. */
230 if (pfl->device_width < pfl->bank_width) {
231 for (i = pfl->device_width;
232 i < pfl->bank_width; i += pfl->device_width) {
233 resp = deposit32(resp, 8 * i, 8 * pfl->device_width, resp);
240 static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
250 DPRINTF("%s: reading offset " TARGET_FMT_plx " under cmd %02x width %d\n",
251 __func__, offset, pfl->cmd, width);
255 /* This should never happen : reset state & treat it as a read */
256 DPRINTF("%s: unknown command state: %x\n", __func__, pfl->cmd);
259 /* fall through to read code */
261 /* Flash area read */
266 DPRINTF("%s: data offset " TARGET_FMT_plx " %02x\n",
267 __func__, offset, ret);
271 ret = p[offset] << 8;
272 ret |= p[offset + 1];
275 ret |= p[offset + 1] << 8;
277 DPRINTF("%s: data offset " TARGET_FMT_plx " %04x\n",
278 __func__, offset, ret);
282 ret = p[offset] << 24;
283 ret |= p[offset + 1] << 16;
284 ret |= p[offset + 2] << 8;
285 ret |= p[offset + 3];
288 ret |= p[offset + 1] << 8;
289 ret |= p[offset + 2] << 16;
290 ret |= p[offset + 3] << 24;
292 DPRINTF("%s: data offset " TARGET_FMT_plx " %08x\n",
293 __func__, offset, ret);
296 DPRINTF("BUG in %s\n", __func__);
300 case 0x10: /* Single byte program */
301 case 0x20: /* Block erase */
302 case 0x28: /* Block erase */
303 case 0x40: /* single byte program */
304 case 0x50: /* Clear status register */
305 case 0x60: /* Block /un)lock */
306 case 0x70: /* Status Register */
307 case 0xe8: /* Write block */
308 /* Status register read. Return status from each device in
312 if (pfl->device_width && width > pfl->device_width) {
313 int shift = pfl->device_width * 8;
314 while (shift + pfl->device_width * 8 <= width * 8) {
315 ret |= pfl->status << shift;
316 shift += pfl->device_width * 8;
318 } else if (!pfl->device_width && width > 2) {
319 /* Handle 32 bit flash cases where device width is not
320 * set. (Existing behavior before device width added.)
322 ret |= pfl->status << 16;
324 DPRINTF("%s: status %x\n", __func__, ret);
327 if (!pfl->device_width) {
328 /* Preserve old behavior if device width not specified */
329 boff = offset & 0xFF;
330 if (pfl->bank_width == 2) {
332 } else if (pfl->bank_width == 4) {
338 ret = pfl->ident0 << 8 | pfl->ident1;
339 DPRINTF("%s: Manufacturer Code %04x\n", __func__, ret);
342 ret = pfl->ident2 << 8 | pfl->ident3;
343 DPRINTF("%s: Device ID Code %04x\n", __func__, ret);
346 DPRINTF("%s: Read Device Information boff=%x\n", __func__,
352 /* If we have a read larger than the bank_width, combine multiple
353 * manufacturer/device ID queries into a single response.
356 for (i = 0; i < width; i += pfl->bank_width) {
357 ret = deposit32(ret, i * 8, pfl->bank_width * 8,
358 pflash_devid_query(pfl,
359 offset + i * pfl->bank_width));
363 case 0x98: /* Query mode */
364 if (!pfl->device_width) {
365 /* Preserve old behavior if device width not specified */
366 boff = offset & 0xFF;
367 if (pfl->bank_width == 2) {
369 } else if (pfl->bank_width == 4) {
373 if (boff > pfl->cfi_len) {
376 ret = pfl->cfi_table[boff];
379 /* If we have a read larger than the bank_width, combine multiple
380 * CFI queries into a single response.
383 for (i = 0; i < width; i += pfl->bank_width) {
384 ret = deposit32(ret, i * 8, pfl->bank_width * 8,
385 pflash_cfi_query(pfl,
386 offset + i * pfl->bank_width));
395 /* update flash content on disk */
396 static void pflash_update(pflash_t *pfl, int offset,
401 offset_end = offset + size;
402 /* round to sectors */
403 offset = offset >> 9;
404 offset_end = (offset_end + 511) >> 9;
405 blk_write(pfl->blk, offset, pfl->storage + (offset << 9),
406 offset_end - offset);
410 static inline void pflash_data_write(pflash_t *pfl, hwaddr offset,
411 uint32_t value, int width, int be)
413 uint8_t *p = pfl->storage;
415 DPRINTF("%s: block write offset " TARGET_FMT_plx
416 " value %x counter %016" PRIx64 "\n",
417 __func__, offset, value, pfl->counter);
424 p[offset] = value >> 8;
425 p[offset + 1] = value;
428 p[offset + 1] = value >> 8;
433 p[offset] = value >> 24;
434 p[offset + 1] = value >> 16;
435 p[offset + 2] = value >> 8;
436 p[offset + 3] = value;
439 p[offset + 1] = value >> 8;
440 p[offset + 2] = value >> 16;
441 p[offset + 3] = value >> 24;
448 static void pflash_write(pflash_t *pfl, hwaddr offset,
449 uint32_t value, int width, int be)
456 DPRINTF("%s: writing offset " TARGET_FMT_plx " value %08x width %d wcycle 0x%x\n",
457 __func__, offset, value, width, pfl->wcycle);
460 /* Set the device in I/O access mode */
461 memory_region_rom_device_set_romd(&pfl->mem, false);
464 switch (pfl->wcycle) {
470 case 0x10: /* Single Byte Program */
471 case 0x40: /* Single Byte Program */
472 DPRINTF("%s: Single Byte Program\n", __func__);
474 case 0x20: /* Block erase */
476 offset &= ~(pfl->sector_len - 1);
478 DPRINTF("%s: block erase at " TARGET_FMT_plx " bytes %x\n",
479 __func__, offset, (unsigned)pfl->sector_len);
482 memset(p + offset, 0xff, pfl->sector_len);
483 pflash_update(pfl, offset, pfl->sector_len);
485 pfl->status |= 0x20; /* Block erase error */
487 pfl->status |= 0x80; /* Ready! */
489 case 0x50: /* Clear status bits */
490 DPRINTF("%s: Clear status bits\n", __func__);
493 case 0x60: /* Block (un)lock */
494 DPRINTF("%s: Block unlock\n", __func__);
496 case 0x70: /* Status Register */
497 DPRINTF("%s: Read status register\n", __func__);
500 case 0x90: /* Read Device ID */
501 DPRINTF("%s: Read Device information\n", __func__);
504 case 0x98: /* CFI query */
505 DPRINTF("%s: CFI query\n", __func__);
507 case 0xe8: /* Write to buffer */
508 DPRINTF("%s: Write to buffer\n", __func__);
509 pfl->status |= 0x80; /* Ready! */
511 case 0xf0: /* Probe for AMD flash */
512 DPRINTF("%s: Probe for AMD flash\n", __func__);
514 case 0xff: /* Read array mode */
515 DPRINTF("%s: Read array mode\n", __func__);
525 case 0x10: /* Single Byte Program */
526 case 0x40: /* Single Byte Program */
527 DPRINTF("%s: Single Byte Program\n", __func__);
529 pflash_data_write(pfl, offset, value, width, be);
530 pflash_update(pfl, offset, width);
532 pfl->status |= 0x10; /* Programming error */
534 pfl->status |= 0x80; /* Ready! */
537 case 0x20: /* Block erase */
539 if (cmd == 0xd0) { /* confirm */
542 } else if (cmd == 0xff) { /* read array mode */
549 /* Mask writeblock size based on device width, or bank width if
550 * device width not specified.
552 if (pfl->device_width) {
553 value = extract32(value, 0, pfl->device_width * 8);
555 value = extract32(value, 0, pfl->bank_width * 8);
557 DPRINTF("%s: block write of %x bytes\n", __func__, value);
558 pfl->counter = value;
565 } else if (cmd == 0x01) {
568 } else if (cmd == 0xff) {
571 DPRINTF("%s: Unknown (un)locking command\n", __func__);
579 DPRINTF("%s: leaving query mode\n", __func__);
588 case 0xe8: /* Block write */
590 pflash_data_write(pfl, offset, value, width, be);
592 pfl->status |= 0x10; /* Programming error */
598 hwaddr mask = pfl->writeblock_size - 1;
601 DPRINTF("%s: block write finished\n", __func__);
604 /* Flush the entire write buffer onto backing storage. */
605 pflash_update(pfl, offset & mask, pfl->writeblock_size);
607 pfl->status |= 0x10; /* Programming error */
617 case 3: /* Confirm mode */
619 case 0xe8: /* Block write */
624 DPRINTF("%s: unknown command for \"write block\"\n", __func__);
625 PFLASH_BUG("Write block confirm");
634 /* Should never happen */
635 DPRINTF("%s: invalid write state\n", __func__);
641 qemu_log_mask(LOG_UNIMP, "%s: Unimplemented flash cmd sequence "
642 "(offset " TARGET_FMT_plx ", wcycle 0x%x cmd 0x%x value 0x%x)"
643 "\n", __func__, offset, pfl->wcycle, pfl->cmd, value);
646 memory_region_rom_device_set_romd(&pfl->mem, true);
653 static uint64_t pflash_mem_read(void *opaque, hwaddr addr, unsigned len)
655 pflash_t *pfl = opaque;
656 bool be = !!(pfl->features & (1 << PFLASH_BE));
658 return pflash_read(pfl, addr, len, be);
661 static void pflash_mem_write(void *opaque, hwaddr addr, uint64_t value, unsigned len)
663 pflash_t *pfl = opaque;
664 bool be = !!(pfl->features & (1 << PFLASH_BE));
666 pflash_write(pfl, addr, value, len, be);
669 static const MemoryRegionOps pflash_cfi01_ops = {
670 .read = pflash_mem_read,
671 .write = pflash_mem_write,
672 .endianness = DEVICE_NATIVE_ENDIAN,
675 static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
677 pflash_t *pfl = CFI_PFLASH01(dev);
680 uint64_t blocks_per_device, device_len;
682 Error *local_err = NULL;
684 total_len = pfl->sector_len * pfl->nb_blocs;
686 /* These are only used to expose the parameters of each device
687 * in the cfi_table[].
689 num_devices = pfl->device_width ? (pfl->bank_width / pfl->device_width) : 1;
690 blocks_per_device = pfl->nb_blocs / num_devices;
691 device_len = pfl->sector_len * blocks_per_device;
693 /* XXX: to be fixed */
695 if (total_len != (8 * 1024 * 1024) && total_len != (16 * 1024 * 1024) &&
696 total_len != (32 * 1024 * 1024) && total_len != (64 * 1024 * 1024))
700 memory_region_init_rom_device(
701 &pfl->mem, OBJECT(dev),
704 pfl->name, total_len, &local_err);
706 error_propagate(errp, local_err);
710 vmstate_register_ram(&pfl->mem, DEVICE(pfl));
711 pfl->storage = memory_region_get_ram_ptr(&pfl->mem);
712 sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem);
715 /* read the initial flash content */
716 ret = blk_read(pfl->blk, 0, pfl->storage, total_len >> 9);
719 vmstate_unregister_ram(&pfl->mem, DEVICE(pfl));
720 error_setg(errp, "failed to read the initial flash content");
726 pfl->ro = blk_is_read_only(pfl->blk);
731 /* Default to devices being used at their maximum device width. This was
732 * assumed before the device_width support was added.
734 if (!pfl->max_device_width) {
735 pfl->max_device_width = pfl->device_width;
738 pfl->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, pflash_timer, pfl);
742 /* Hardcoded CFI table */
744 /* Standard "QRY" string */
745 pfl->cfi_table[0x10] = 'Q';
746 pfl->cfi_table[0x11] = 'R';
747 pfl->cfi_table[0x12] = 'Y';
748 /* Command set (Intel) */
749 pfl->cfi_table[0x13] = 0x01;
750 pfl->cfi_table[0x14] = 0x00;
751 /* Primary extended table address (none) */
752 pfl->cfi_table[0x15] = 0x31;
753 pfl->cfi_table[0x16] = 0x00;
754 /* Alternate command set (none) */
755 pfl->cfi_table[0x17] = 0x00;
756 pfl->cfi_table[0x18] = 0x00;
757 /* Alternate extended table (none) */
758 pfl->cfi_table[0x19] = 0x00;
759 pfl->cfi_table[0x1A] = 0x00;
761 pfl->cfi_table[0x1B] = 0x45;
763 pfl->cfi_table[0x1C] = 0x55;
764 /* Vpp min (no Vpp pin) */
765 pfl->cfi_table[0x1D] = 0x00;
766 /* Vpp max (no Vpp pin) */
767 pfl->cfi_table[0x1E] = 0x00;
769 pfl->cfi_table[0x1F] = 0x07;
770 /* Timeout for min size buffer write */
771 pfl->cfi_table[0x20] = 0x07;
772 /* Typical timeout for block erase */
773 pfl->cfi_table[0x21] = 0x0a;
774 /* Typical timeout for full chip erase (4096 ms) */
775 pfl->cfi_table[0x22] = 0x00;
777 pfl->cfi_table[0x23] = 0x04;
778 /* Max timeout for buffer write */
779 pfl->cfi_table[0x24] = 0x04;
780 /* Max timeout for block erase */
781 pfl->cfi_table[0x25] = 0x04;
782 /* Max timeout for chip erase */
783 pfl->cfi_table[0x26] = 0x00;
785 pfl->cfi_table[0x27] = ctz32(device_len); /* + 1; */
786 /* Flash device interface (8 & 16 bits) */
787 pfl->cfi_table[0x28] = 0x02;
788 pfl->cfi_table[0x29] = 0x00;
789 /* Max number of bytes in multi-bytes write */
790 if (pfl->bank_width == 1) {
791 pfl->cfi_table[0x2A] = 0x08;
793 pfl->cfi_table[0x2A] = 0x0B;
795 pfl->writeblock_size = 1 << pfl->cfi_table[0x2A];
797 pfl->cfi_table[0x2B] = 0x00;
798 /* Number of erase block regions (uniform) */
799 pfl->cfi_table[0x2C] = 0x01;
800 /* Erase block region 1 */
801 pfl->cfi_table[0x2D] = blocks_per_device - 1;
802 pfl->cfi_table[0x2E] = (blocks_per_device - 1) >> 8;
803 pfl->cfi_table[0x2F] = pfl->sector_len >> 8;
804 pfl->cfi_table[0x30] = pfl->sector_len >> 16;
807 pfl->cfi_table[0x31] = 'P';
808 pfl->cfi_table[0x32] = 'R';
809 pfl->cfi_table[0x33] = 'I';
811 pfl->cfi_table[0x34] = '1';
812 pfl->cfi_table[0x35] = '0';
814 pfl->cfi_table[0x36] = 0x00;
815 pfl->cfi_table[0x37] = 0x00;
816 pfl->cfi_table[0x38] = 0x00;
817 pfl->cfi_table[0x39] = 0x00;
819 pfl->cfi_table[0x3a] = 0x00;
821 pfl->cfi_table[0x3b] = 0x00;
822 pfl->cfi_table[0x3c] = 0x00;
824 pfl->cfi_table[0x3f] = 0x01; /* Number of protection fields */
827 static Property pflash_cfi01_properties[] = {
828 DEFINE_PROP_DRIVE("drive", struct pflash_t, blk),
829 /* num-blocks is the number of blocks actually visible to the guest,
830 * ie the total size of the device divided by the sector length.
831 * If we're emulating flash devices wired in parallel the actual
832 * number of blocks per indvidual device will differ.
834 DEFINE_PROP_UINT32("num-blocks", struct pflash_t, nb_blocs, 0),
835 DEFINE_PROP_UINT64("sector-length", struct pflash_t, sector_len, 0),
836 /* width here is the overall width of this QEMU device in bytes.
837 * The QEMU device may be emulating a number of flash devices
838 * wired up in parallel; the width of each individual flash
839 * device should be specified via device-width. If the individual
840 * devices have a maximum width which is greater than the width
841 * they are being used for, this maximum width should be set via
842 * max-device-width (which otherwise defaults to device-width).
843 * So for instance a 32-bit wide QEMU flash device made from four
844 * 16-bit flash devices used in 8-bit wide mode would be configured
845 * with width = 4, device-width = 1, max-device-width = 2.
847 * If device-width is not specified we default to backwards
848 * compatible behaviour which is a bad emulation of two
849 * 16 bit devices making up a 32 bit wide QEMU device. This
850 * is deprecated for new uses of this device.
852 DEFINE_PROP_UINT8("width", struct pflash_t, bank_width, 0),
853 DEFINE_PROP_UINT8("device-width", struct pflash_t, device_width, 0),
854 DEFINE_PROP_UINT8("max-device-width", struct pflash_t, max_device_width, 0),
855 DEFINE_PROP_BIT("big-endian", struct pflash_t, features, PFLASH_BE, 0),
856 DEFINE_PROP_UINT16("id0", struct pflash_t, ident0, 0),
857 DEFINE_PROP_UINT16("id1", struct pflash_t, ident1, 0),
858 DEFINE_PROP_UINT16("id2", struct pflash_t, ident2, 0),
859 DEFINE_PROP_UINT16("id3", struct pflash_t, ident3, 0),
860 DEFINE_PROP_STRING("name", struct pflash_t, name),
861 DEFINE_PROP_END_OF_LIST(),
864 static void pflash_cfi01_class_init(ObjectClass *klass, void *data)
866 DeviceClass *dc = DEVICE_CLASS(klass);
868 dc->realize = pflash_cfi01_realize;
869 dc->props = pflash_cfi01_properties;
870 dc->vmsd = &vmstate_pflash;
871 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
875 static const TypeInfo pflash_cfi01_info = {
876 .name = TYPE_CFI_PFLASH01,
877 .parent = TYPE_SYS_BUS_DEVICE,
878 .instance_size = sizeof(struct pflash_t),
879 .class_init = pflash_cfi01_class_init,
882 static void pflash_cfi01_register_types(void)
884 type_register_static(&pflash_cfi01_info);
887 type_init(pflash_cfi01_register_types)
889 pflash_t *pflash_cfi01_register(hwaddr base,
890 DeviceState *qdev, const char *name,
893 uint32_t sector_len, int nb_blocs,
894 int bank_width, uint16_t id0, uint16_t id1,
895 uint16_t id2, uint16_t id3, int be)
897 DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
900 qdev_prop_set_drive(dev, "drive", blk, &error_abort);
902 qdev_prop_set_uint32(dev, "num-blocks", nb_blocs);
903 qdev_prop_set_uint64(dev, "sector-length", sector_len);
904 qdev_prop_set_uint8(dev, "width", bank_width);
905 qdev_prop_set_bit(dev, "big-endian", !!be);
906 qdev_prop_set_uint16(dev, "id0", id0);
907 qdev_prop_set_uint16(dev, "id1", id1);
908 qdev_prop_set_uint16(dev, "id2", id2);
909 qdev_prop_set_uint16(dev, "id3", id3);
910 qdev_prop_set_string(dev, "name", name);
911 qdev_init_nofail(dev);
913 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
914 return CFI_PFLASH01(dev);
917 MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl)
922 static int pflash_post_load(void *opaque, int version_id)
924 pflash_t *pfl = opaque;
927 DPRINTF("%s: updating bdrv for %s\n", __func__, pfl->name);
928 pflash_update(pfl, 0, pfl->sector_len * pfl->nb_blocs);