Skip to content

Commit

Permalink
hw/sd/sdcard: Fix calculation of size when using eMMC boot partitions
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jan Luebbe <[email protected]>
Fixes: c8cb198 ("hw/sd/sdcard: Support boot area in emmc image")
Tested-by: Guenter Roeck <[email protected]>
Reviewed-by: Cédric Le Goater <[email protected]>
(cherry picked from commit c078298)
Signed-off-by: Michael Tokarev <[email protected]>
  • Loading branch information
jluebbe authored and Michael Tokarev committed Nov 5, 2024
1 parent cbfbd13 commit e30319c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hw/sd/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e30319c

Please sign in to comment.