[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 06/11] hw/block/pflash_cfi01: Error out if device length isn't a
From: |
Bernhard Beschow |
Subject: |
[PATCH 06/11] hw/block/pflash_cfi01: Error out if device length isn't a power of two |
Date: |
Thu, 15 Sep 2022 17:25:15 +0200 |
According to the JEDEC standard the device length is communicated to an
OS as an exponent (power of two).
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
---
hw/block/pflash_cfi01.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 0cbc2fb4cb..8c9b3f518a 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -690,7 +690,7 @@ static const MemoryRegionOps pflash_cfi01_ops = {
.endianness = DEVICE_NATIVE_ENDIAN,
};
-static void pflash_cfi01_fill_cfi_table(PFlashCFI01 *pfl)
+static void pflash_cfi01_fill_cfi_table(PFlashCFI01 *pfl, Error **errp)
{
uint64_t blocks_per_device, sector_len_per_device, device_len;
int num_devices;
@@ -708,6 +708,10 @@ static void pflash_cfi01_fill_cfi_table(PFlashCFI01 *pfl)
sector_len_per_device = pfl->sector_len / num_devices;
}
device_len = sector_len_per_device * blocks_per_device;
+ if (ctpop64(device_len) != 1) {
+ error_setg(errp, "Device size must be a power of two.");
+ return;
+ }
/* Hardcoded CFI table */
/* Standard "QRY" string */
@@ -865,7 +869,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error
**errp)
*/
pfl->cmd = 0x00;
pfl->status = 0x80; /* WSM ready */
- pflash_cfi01_fill_cfi_table(pfl);
+ pflash_cfi01_fill_cfi_table(pfl, errp);
}
static void pflash_cfi01_system_reset(DeviceState *dev)
--
2.37.3
- Re: [PATCH 02/11] hw/gpio/meson: Introduce dedicated config switch for hw/gpio/mpc8xxx, (continued)
- [PATCH 03/11] docs/system/ppc/ppce500: Add heading for networking chapter, Bernhard Beschow, 2022/09/15
- [PATCH 04/11] hw/ppc/mpc8544ds: Add platform bus, Bernhard Beschow, 2022/09/15
- [PATCH 05/11] hw/ppc/e500: Remove if statement which is now always true, Bernhard Beschow, 2022/09/15
- [PATCH 06/11] hw/block/pflash_cfi01: Error out if device length isn't a power of two,
Bernhard Beschow <=
- [PATCH 07/11] hw/ppc/e500: Implement pflash handling, Bernhard Beschow, 2022/09/15
- [PATCH 09/11] hw/sd/sdhci: Rename ESDHC_* defines to USDHC_*, Bernhard Beschow, 2022/09/15
- [PATCH 08/11] hw/sd/sdhci-internal: Unexport ESDHC defines, Bernhard Beschow, 2022/09/15