qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] pflash_cfi01: fix per device sector length in CFI table
@ 2017-01-12 10:35 David Engraf
  2017-01-12 10:42 ` Peter Maydell
  0 siblings, 1 reply; 9+ messages in thread
From: David Engraf @ 2017-01-12 10:35 UTC (permalink / raw)
  To: kwolf, mreitz, qemu-block; +Cc: qemu-devel, peter.maydell

[-- Attachment #1: Type: text/plain, Size: 739 bytes --]

The CFI entry for sector length must be set to sector length per device. 
This is important for boards using multiple devices like the ARM 
Vexpress board (width = 4, device-width = 2).

Linux and u-boots calculate the size ratio by dividing both values:

size_ratio = info->portwidth / info->chipwidth;

After that the sector length will be multiplied by the size_ratio, thus 
the CFI entry for sector length is doubled. When Linux or u-boot send a 
sector erase, they expect to erase the doubled sector length, but QEMU 
only erases the board specified sector length.

This patch fixes the sector length in the CFI table to match the length 
per device, equal to blocks_per_device.

Signed-off-by: David Engraf <david.engraf@sysgo.com>


[-- Attachment #2: fix_pflash_sector_len.patch --]
[-- Type: text/x-patch, Size: 1422 bytes --]

diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 5f0ee9d..8bb61e4 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -703,7 +703,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
     pflash_t *pfl = CFI_PFLASH01(dev);
     uint64_t total_len;
     int ret;
-    uint64_t blocks_per_device, device_len;
+    uint64_t blocks_per_device, sector_len_per_device, device_len;
     int num_devices;
     Error *local_err = NULL;
 
@@ -727,7 +727,8 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
      */
     num_devices = pfl->device_width ? (pfl->bank_width / pfl->device_width) : 1;
     blocks_per_device = pfl->nb_blocs / num_devices;
-    device_len = pfl->sector_len * blocks_per_device;
+    sector_len_per_device = pfl->sector_len / num_devices;
+    device_len = sector_len_per_device * blocks_per_device;
 
     /* XXX: to be fixed */
 #if 0
@@ -839,8 +840,8 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
     /* Erase block region 1 */
     pfl->cfi_table[0x2D] = blocks_per_device - 1;
     pfl->cfi_table[0x2E] = (blocks_per_device - 1) >> 8;
-    pfl->cfi_table[0x2F] = pfl->sector_len >> 8;
-    pfl->cfi_table[0x30] = pfl->sector_len >> 16;
+    pfl->cfi_table[0x2F] = sector_len_per_device >> 8;
+    pfl->cfi_table[0x30] = sector_len_per_device >> 16;
 
     /* Extended */
     pfl->cfi_table[0x31] = 'P';

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-01-27 15:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-12 10:35 [Qemu-devel] [PATCH] pflash_cfi01: fix per device sector length in CFI table David Engraf
2017-01-12 10:42 ` Peter Maydell
2017-01-12 11:36   ` Andrew Jones
2017-01-12 12:01     ` David Engraf
2017-01-16 10:26     ` Dr. David Alan Gilbert
2017-01-17 16:48       ` [Qemu-devel] [PATCH v2] " David Engraf
2017-01-27 14:31     ` [Qemu-devel] [PATCH] " Peter Maydell
2017-01-27 14:54       ` Peter Maydell
2017-01-27 15:13         ` Andrew Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).