[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] hw/riscv: virt: Remove size restriction for pflash
From: |
Sunil V L |
Subject: |
Re: [PATCH] hw/riscv: virt: Remove size restriction for pflash |
Date: |
Mon, 7 Nov 2022 16:53:53 +0530 |
On Mon, Nov 07, 2022 at 05:57:45PM +0800, maobibo wrote:
>
>
> 在 2022/11/6 22:39, Sunil V L 写道:
> > The pflash implementation currently assumes fixed size of the
> > backend storage. Due to this, the backend storage file needs to be
> > exactly of size 32M. Otherwise, there will be an error like below.
> >
> > "device requires 33554432 bytes, block backend provides 3145728 bytes"
> >
> > Fix this issue by using the actual size of the backing store.
> >
> > Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
> > ---
> > hw/riscv/virt.c | 33 +++++++++++++++++++++++++--------
> > 1 file changed, 25 insertions(+), 8 deletions(-)
> >
> > diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> > index a5bc7353b4..aad175fa31 100644
> > --- a/hw/riscv/virt.c
> > +++ b/hw/riscv/virt.c
> > @@ -49,6 +49,7 @@
> > #include "hw/pci/pci.h"
> > #include "hw/pci-host/gpex.h"
> > #include "hw/display/ramfb.h"
> > +#include "sysemu/block-backend.h"
> >
> > /*
> > * The virt machine physical address space used by some of the devices
> > @@ -144,10 +145,17 @@ static void virt_flash_map1(PFlashCFI01 *flash,
> > MemoryRegion *sysmem)
> > {
> > DeviceState *dev = DEVICE(flash);
> > + BlockBackend *blk;
> > + hwaddr real_size;
> >
> > - assert(QEMU_IS_ALIGNED(size, VIRT_FLASH_SECTOR_SIZE));
> > - assert(size / VIRT_FLASH_SECTOR_SIZE <= UINT32_MAX);
> > - qdev_prop_set_uint32(dev, "num-blocks", size / VIRT_FLASH_SECTOR_SIZE);
> > + blk = pflash_cfi01_get_blk(flash);
> > +
> > + real_size = blk ? blk_getlength(blk): size;
> > +
> > + assert(real_size);
> > + assert(QEMU_IS_ALIGNED(real_size, VIRT_FLASH_SECTOR_SIZE));
> > + assert(real_size / VIRT_FLASH_SECTOR_SIZE <= UINT32_MAX);
> How about add one sentence?
> assert(real_size <= size);
>
> As defined VIRT_FLASH memory space, the total memory space size 64M,
> Pflash0/Pflash1 cannot be more than 32M. Supposing real size of pflash0
> is 33M, there will be conflict with address space of pflash1.
>
> regards
> bibo, mao
>
Good catch!. Thank you. Will add it in V2.
Thanks
Sunil