Paul: Nice investigation + Edgar & Alex
On 10/5/21 8:45 AM, Paul Sokolovsky via Openamp-system-reference wrote:
On Tue, 5 Oct 2021 15:16:48 +0300 Paul Sokolovsky Paul.Sokolovsky@linaro.org wrote:
Hello,
Looking thru notes from the last meeting, I see that Bill noted a need to manually resize a Xilinx SD card image after the build as "pain point". I looked into it, and found a workaround on how to build an image of proper size right away:
--- a/meta-xilinx-bsp/classes/image-types-xilinx-qemu.bbclass +++ b/meta-xilinx-bsp/classes/image-types-xilinx-qemu.bbclass @@ -6,5 +6,5 @@ # 512K). CONVERSIONTYPES_append = " qemu-sd" -CONVERSION_CMD_qemu-sd = "cp ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type} ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}.qemu-sd; truncate -s %512K ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}.qemu-sd" +CONVERSION_CMD_qemu-sd = "cp ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type} ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}.qemu-sd; truncate -s %256M ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}.qemu-sd" CONVERSION_DEPENDS_qemu-sd = "coreutils-native"
[]
A check has been introduced in QEMU to see if image size is power of 2.
So, I assume it's a recent addition to Xilinx QEMU, though I didn't check the sources.
Actually, that's upstream QEMU feature: https://github.com/qemu/qemu/commit/a9bcedd15a5834ca9ae6c3a97933e85ac7edbd36 . So, to properly fix it, we'd need to throw in some Python code to the .bbclass (unless you know a generally available command to adjust file size like that, "truncate" doesn't seem to do that).
This is rather unfortunate upstream change. It basically means you need to create SD images for real SD cards (that are NEVER powers of 2) and QEMU differently.
A 16GB image written to a 16GB SD card will fail 100% of the time as SD card manufactures reserve some of the rated capacity for maintenance and bad block compensation. We talked to Sandisk way back and they suggested that we (beagleboard.org) only use 80% of the rated size for an image. Not all cards will be that bad but some may be.
So if you target a real 16GB card you should make you image 12.8GB at most.
I guess that is why we have a .qemu-sd format to begin with instead of just .img.
This still makes me wonder if QEMU is doing the right thing WRT the CVE. Real cards are NOT powers of 2.
Yes some python is probably needed. I was going to see if it could be put into the wic template but that would mean we need one wic for QEMU-SD and another for .img than can be used with real devices. (IF wic can even do it.)
Thanks for looking, Bill
-- Best Regards, Paul
Linaro.org | Open source software for ARM SoCs Follow Linaro: http://www.facebook.com/pages/Linaro http://twitter.com/#%21/linaroorg - http://www.linaro.org/linaro-blog -- Openamp-system-reference mailing list Openamp-system-reference@lists.openampproject.org https://lists.openampproject.org/mailman/listinfo/openamp-system-reference