From: Jan Luebbe Date: Mon, 28 Oct 2024 16:23:08 +0000 (+0100) Subject: hw/sd/sdcard: Fix calculation of size when using eMMC boot partitions X-Git-Tag: pull-vmclock-20250108~87^2~8 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c078298301a8c72fe12da85d94372689196628bc;p=users%2Fdwmw2%2Fqemu.git hw/sd/sdcard: Fix calculation of size when using eMMC boot partitions The sd_bootpart_offset() function calculates the *runtime* offset which changes as the guest switches between accessing the main user data area and the boot partitions by writing to the EXT_CSD_PART_CONFIG_ACC_MASK bits, so it shouldn't be used to calculate the main user data area size. Instead, subtract the boot_part_size directly (twice, as there are two identical boot partitions defined by the eMMC spec). Suggested-by: Cédric Le Goater Signed-off-by: Jan Luebbe Fixes: c8cb19876d3e ("hw/sd/sdcard: Support boot area in emmc image") Tested-by: Guenter Roeck Reviewed-by: Cédric Le Goater --- diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b2e2d58e01..f9bd03f3fd 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -834,7 +834,9 @@ static void sd_reset(DeviceState *dev) sect = 0; } size = sect << HWBLOCK_SHIFT; - size -= sd_bootpart_offset(sd); + if (sd_is_emmc(sd)) { + size -= sd->boot_part_size * 2; + } sect = sd_addr_to_wpnum(size) + 1;