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"
Interesting, that comment on that file says:
# Define the 'qemu-sd' conversion type # # This conversion type pads any image to the 512K boundary to ensure that the # image file can be used directly with QEMU's SD emulation which requires the # block device to match that of valid SD card sizes (which are multiples of # 512K).
As can be seen, the care was taken to pad the SD card image already, but seems that QEMU requirements got changed after that. And my change is indeed just a workaround, as it makes the image be padded to 256MB, which works as intended up to 512MB of the image size (and not practical for small images either).
A quick googling up led me to https://support.xilinx.com/s/article/76596 which says:
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.
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).
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
Thanks for looking into this Paul.
I had some issues with receiving emails past two days on my Xilinx accoutns, I just saw your email.
On 10/5/21 8:31 AM, Bill Mills via Openamp-system-reference wrote:
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
openamp-system-reference@lists.openampproject.org