hw/block/pflash_cfi01: Limit maximum flash size to 256 MiB
PATCH 1/1 hw/block/pflash_cfi01: Limit maximum flash size to 256 MiB
As of this commit, the biggest CFI01 NOR flash documented is the Micron PC28F00BP33EF. Its size is 2 GiB (256 MiB).
Actually this "2Gb device employs a virtual chip enable feature, which combines two 1Gb die with a common chip enable".
Since we do not want to model unrealistic hardware, cap the current model to this maximum. At least we have a datasheet to refer.
If a bigger flash is provided, the user get this warning:
qemu-system-aarch64: Initialization of device cfi.pflash01 failed: Maximum supported CFI flash size is 16 MiB.
Note, the sbsa-ref ARM machine introduced in commit 64580903c2b already uses a pair of 256 MiB flash devices.
--- hw/block/pflash_cfi01.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/block/pflash_cfi01.c +10 -0
@@ -37,6 +37,8 @@*/ #include "qemu/osdep.h" +#include "qemu/units.h" +#include "qemu/cutils.h" #include "hw/block/block.h" #include "hw/block/flash.h" #include "hw/qdev-properties.h"
@@ -68,6 +70,8 @@ do { \#define PFLASH_BE 0#define PFLASH_SECURE 1 +#define PFLASH_SIZE_MAX (256 * MiB)/* Micron PC28F00BP33EF */ +struct PFlashCFI01 {/*< private >*/ SysBusDevice parent_obj;
@@ -717,6 +721,12 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) } total_len = pfl->sector_len * pfl->nb_blocs; +if (total_len >PFLASH_SIZE_MAX ) { +char *maxsz =size_to_str (PFLASH_SIZE_MAX ); +error_setg (errp,"Maximum supported CFI flash size is %s." , maxsz); +g_free (maxsz); +return ; + }/* These are only used to expose the parameters of each device * in the cfi_table[].
Signature · 1 line
2.21.3
Quoted 2 lines · Philippe Mathieu-Daudé
As of this commit, the biggest CFI01 NOR flash documented is the Micron PC28F00BP33EF. Its size is 2 GiB (256 MiB).
I don't understand what "2 GiB (256 MiB)" means; please clarify.
Quoted 46 lines
Actually this "2Gb device employs a virtual chip enable feature, which combines two 1Gb die with a common chip enable".
Since we do not want to model unrealistic hardware, cap the current model to this maximum. At least we have a datasheet to refer.
If a bigger flash is provided, the user get this warning:
qemu-system-aarch64: Initialization of device cfi.pflash01 failed: Maximum supported CFI flash size is 16 MiB.
Note, the sbsa-ref ARM machine introduced in commit
64580903c2balready uses a pair of 256 MiB flash devices.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/block/pflash_cfi01.c | 10 ++++++++++ 1 file changed, 10 insertions(+)hw/block/pflash_cfi01.c +4
-0@@ -37,6 +37,8 @@*/ #include "qemu/osdep.h" +#include "qemu/units.h" +#include "qemu/cutils.h" #include "hw/block/block.h" #include "hw/block/flash.h" #include "hw/qdev-properties.h" @@ -68,6 +70,8 @@ do { \#define PFLASH_BE 0#define PFLASH_SECURE 1 +#define PFLASH_SIZE_MAX (256 * MiB)/* Micron PC28F00BP33EF */ +struct PFlashCFI01 {/*< private >*/ SysBusDevice parent_obj;@@ -717,6 +721,12 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) }
hw/block/pflash_cfi01.c static void pflash_cfi01_realize(DeviceState *dev, Error **errp) · line 732
Quoted 10 lines
hw/block/pflash_cfi01.c +6
-0total_len = pfl->sector_len * pfl->nb_blocs; +if (total_len >PFLASH_SIZE_MAX ) { +char *maxsz =size_to_str (PFLASH_SIZE_MAX ); +error_setg (errp,"Maximum supported CFI flash size is %s." , maxsz); +g_free (maxsz); +return ; + }/* These are only used to expose the parameters of each device * in the cfi_table[].
I'm unsure how strong the argument is, "we do not want to model unrealistic hardware", but I do think the patch does what it says on the tin (modulo the one part in the commit message that I don't understand).
With the commit message clarified
(I expect & hope people will provide better reviews than mine.)
Thanks
Laszlo
Quoted 11 lines · Philippe Mathieu-Daudé
As of this commit, the biggest CFI01 NOR flash documented is the Micron PC28F00BP33EF. Its size is 2 GiB (256 MiB).
Actually this "2Gb device employs a virtual chip enable feature, which combines two 1Gb die with a common chip enable".
Since we do not want to model unrealistic hardware, cap the current model to this maximum. At least we have a datasheet to refer.
Quoted 6 lines
If a bigger flash is provided, the user get this warning:
qemu-system-aarch64: Initialization of device cfi.pflash01 failed: Maximum supported CFI flash size is 16 MiB.
Note, the sbsa-ref ARM machine introduced in commit
64580903c2balready uses a pair of 256 MiB flash devices.
What problem is this check solving? Is there some implementation imposed limitation or a limit within the flash header format that means larger sizes don't work? If so, what's the restriction?
thanks
-- PMM
Hi Peter,
Quoted 4 lines · Peter Maydell
Quoted 3 lines · Philippe Mathieu-Daudé
As of this commit, the biggest CFI01 NOR flash documented is the Micron PC28F00BP33EF. Its size is 2 GiB (256 MiB).
Oops, read as "2 Gbit (256 Mbyte)".
Quoted 11 lines
Quoted 11 lines
Actually this "2Gb device employs a virtual chip enable feature, which combines two 1Gb die with a common chip enable".
Since we do not want to model unrealistic hardware, cap the current model to this maximum. At least we have a datasheet to refer.
If a bigger flash is provided, the user get this warning:
qemu-system-aarch64: Initialization of device cfi.pflash01 failed: Maximum supported CFI flash size is 16 MiB.
Also here read "256 MiB" (I capped to 16MiB to test the patch).
Quoted 7 lines
Quoted 3 lines
Note, the sbsa-ref ARM machine introduced in commit
64580903c2balready uses a pair of 256 MiB flash devices.What problem is this check solving? Is there some implementation imposed limitation or a limit within the flash header format that means larger sizes don't work? If so, what's the restriction?
I am not confident maintaining virtual device with no specifications. If someone come with a datasheet for a pflash > 256MB then we can add another commit to relax this restriction.
If someone is forced to use a >256MB and such hardware does not exist, I'd rather have a document in docs/specs/pflash_cfi01.rst describing the CFI fields.
IOW this is not a hardware limitation, but a maintenance protection.
I am worried with the recent EDK2 activity with the SBSA-ref, and I don't want to give false hope to developers that they can create any kind of pflash with the current device model.
If I reword this better in the commit description, is my argument acceptable?
Thanks,
Phil.
Quoted 4 lines
thanks
-- PMM
Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Peter Maydell
What problem is this check solving? Is there some implementation imposed limitation or a limit within the flash header format that means larger sizes don't work? If so, what's the restriction?
I am not confident maintaining virtual device with no specifications.
This isn't a virtual device, is it? The CFI spec exists and defines what these flash devices behave like.
Quoted 6 lines
If someone come with a datasheet for a pflash > 256MB then we can add another commit to relax this restriction.
If someone is forced to use a >256MB and such hardware does not exist, I'd rather have a document indocs/specs/pflash_cfi01.rstdescribing the CFI fields.
Quoted 8 lines
IOW this is not a hardware limitation, but a maintenance protection.
I am worried with the recent EDK2 activity with the SBSA-ref, and I don't want to give false hope to developers that they can create any kind of pflash with the current device model.
If I reword this better in the commit description, is my argument acceptable?
Not really; I think we should know what we're limiting against. Currently you're checking total_len, but this is just sector_len * nb_blocs, so if there's a problem with silly large values then it's probably actually a problem with one of those being over-sized which would still show up even if the total_len was less than 256MB.
(I suspect the underlying limit here is what the cfi_table entries 0x2D..0x30 impose on blocks_per_device and sector_len_per_device.)
thanks
-- PMM
Quoted 26 lines · Peter Maydell
Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Peter Maydell
What problem is this check solving? Is there some implementation imposed limitation or a limit within the flash header format that means larger sizes don't work? If so, what's the restriction?
I am not confident maintaining virtual device with no specifications.
This isn't a virtual device, is it? The CFI spec exists and defines what these flash devices behave like.
Quoted 6 lines
If someone come with a datasheet for a pflash > 256MB then we can add another commit to relax this restriction.
If someone is forced to use a >256MB and such hardware does not exist, I'd rather have a document indocs/specs/pflash_cfi01.rstdescribing the CFI fields.Quoted 8 lines
IOW this is not a hardware limitation, but a maintenance protection.
I am worried with the recent EDK2 activity with the SBSA-ref, and I don't want to give false hope to developers that they can create any kind of pflash with the current device model.
If I reword this better in the commit description, is my argument acceptable?
Quoted 7 lines
Not really; I think we should know what we're limiting against. Currently you're checking
total_len, but this is justsector_len*nb_blocs, so if there's a problem with silly large values then it's probably actually a problem with one of those being over-sized which would still show up even if thetotal_lenwas less than 256MB.
(I suspect the underlying limit here is what thecfi_tableentries 0x2D..0x30 impose onblocks_per_deviceandsector_len_per_device.)
What I'm working on is a whitelist of the few models our machines really use, but it is taking time. Meanwhile I wanted to at least limit the total size.
I'll try to finish my whitelist effort before someone try to use a
Quoted 6 lines
256MB flash.
thanks
-- PMM
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Peter Maydell
Not really; I think we should know what we're limiting against. Currently you're checking
total_len, but this is justsector_len*nb_blocs, so if there's a problem with silly large values then it's probably actually a problem with one of those being over-sized which would still show up even if thetotal_lenwas less than 256MB.
(I suspect the underlying limit here is what thecfi_tableentries 0x2D..0x30 impose onblocks_per_deviceandsector_len_per_device.)
Quoted 3 lines
What I'm working on is a whitelist of the few models our machines really use, but it is taking time. Meanwhile I wanted to at least limit the total size.
I don't see what we would be whitelisting, though. The only way to create a flash device is from hand-written C code in the board model. If a new board model does something weird we can catch that in code review. Sanity checks on whether the properties supplied by the board code make sense might be useful; randomly saying "you can't have a flash device unless it's one we've seen before" makes less sense to me, because it just means we'll end up adding to the whitelist every time.
thanks
-- PMM