Hi Philippe,
Just tried out your patch on latest master, and I noticed I couldn't apply it without getting this error:
$ git am ~/Downloads/patches/\[PATCH\ 2_2\]\ hw_sd_sdcard\:\ Do\ not\ allow\ invalid\ SD\ card\ sizes\ -\ Philippe\ Mathieu-Daudé\ \<
f4bug@amsat.org\>\ -\ 2020-07-07\ 1521.eml
Applying: hw/sd/sdcard: Do not allow invalid SD card sizes
error: patch failed: hw/sd/sd.c:2130
error: hw/sd/sd.c: patch does not apply
Patch failed at 0001 hw/sd/sdcard: Do not allow invalid SD card sizes
Use 'git am --show-current-patch' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
The first patch did go OK. Maybe this one just needs to be rebased, or I made a mistake.
So I manually copy & pasted the change into hw/sd/sd.c to test it.
It looks like the check works, but my concern is that with this change, we will be getting this error on 'off-the-shelf' images as well.
For example, the latest Raspbian image size also isn't a power of two:
$ ./arm-softmmu/qemu-system-arm -M raspi2 -sd ~/Downloads/2020-05-27-raspios-buster-lite-armhf.img -nographic
WARNING: Image format was not specified for '/home/me/Downloads/2020-05-27-raspios-buster-lite-armhf.img' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
qemu-system-arm: Invalid SD card size: 1.73 GiB (expecting at least 2 GiB)
If we do decide that the change is needed, I would like to propose that we also give the user some instructions
on how to fix it, maybe some 'dd' command? In my opinion that should also go in some of the documentation file(s),
possibly also in the one for the OrangePi PC at docs/system/arm/orangepi.rst (I can also provide a patch for that if you wish).
Kind regards,
Niek