Query block device backing flash for size and use that instead of
requiring the block device being exactly 64M in size.  This allows
to use edk2 firmware builds without padding, i.e. use QEMU_EFI.fd
(which is /way/ smaller than 64M) as-is.

-rw-r--r--. 1 root root 67108864 Dec 12 23:45 QEMU_EFI-pflash.raw
-rw-r--r--. 1 root root  2097152 Dec 12 23:45 QEMU_EFI.fd

Signed-off-by: Gerd Hoffmann <[email protected]>
---
 hw/arm/virt.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index b87135085610..c71ae2cd73f7 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -43,6 +43,7 @@
 #include "hw/vfio/vfio-amd-xgbe.h"
 #include "hw/display/ramfb.h"
 #include "net/net.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/device_tree.h"
 #include "sysemu/numa.h"
 #include "sysemu/runstate.h"
@@ -1134,6 +1135,21 @@ static void virt_flash_map1(PFlashCFI01 *flash,
                             MemoryRegion *sysmem)
 {
     DeviceState *dev = DEVICE(flash);
+    BlockBackend *blk;
+
+    blk = pflash_cfi01_get_blk(flash);
+    if (blk) {
+        hwaddr blksize = blk_getlength(blk);
+
+        if (blksize == 0 || blksize > size ||
+            !QEMU_IS_ALIGNED(size, VIRT_FLASH_SECTOR_SIZE)) {
+            error_report("system firmware block device %s"
+                         " has invalid size %" PRId64,
+                         blk_name(blk), size);
+            exit(1);
+        }
+        size = blksize;
+    }
 
     assert(QEMU_IS_ALIGNED(size, VIRT_FLASH_SECTOR_SIZE));
     assert(size / VIRT_FLASH_SECTOR_SIZE <= UINT32_MAX);
-- 
2.38.1


Reply via email to