Potential error in mender-bootimg.bbclass leads to incorrect boot partition

I’m using meta-mender/meta-mender-core with a Toradex Apalis imx8 board (branch kirkstone).
When I copy the sdimg to a SD card with bmaptool, the 1st vfat boot partition is incorrect. Normal files are here, but the partition shows a lot of errors.

After investigating, I think there is an error in the mender-bootimg.bbclass.

The following patch corrects this error :

diff --git a/meta-mender-core/classes/mender-bootimg.bbclass b/meta-mender-core/classes/mender-bootimg.bbclass
index 755772f7..12ed7690 100644
--- a/meta-mender-core/classes/mender-bootimg.bbclass
+++ b/meta-mender-core/classes/mender-bootimg.bbclass
@@ -25,7 +25,7 @@ IMAGE_CMD:bootimg() {
 
         mender_merge_bootfs_and_image_boot_files
         rm -f "${WORKDIR}/boot.${MENDER_BOOT_PART_FSTYPE_TO_GEN}"
-        dd if=/dev/zero of="${WORKDIR}/boot.${MENDER_BOOT_PART_FSTYPE_TO_GEN}" count=0 bs=1M seek=${MENDER_BOOT_PART_SIZE_MB}
+        dd if=/dev/zero of="${WORKDIR}/boot.${MENDER_BOOT_PART_FSTYPE_TO_GEN}" bs=1M count=${MENDER_BOOT_PART_SIZE_MB}
         if [ ${MENDER_BOOT_PART_FSTYPE_TO_GEN} = "vfat" ]; then
             mkfs.${MENDER_BOOT_PART_FSTYPE_TO_GEN} \
                 $force_flag \
1 Like

Hi @cchciose,

Thanks for sharing! I actually ran into similar problems on another board, but never got round to figure it out. Will verify and merge accordingly :slight_smile:

Thanks,
Josef

This fix should be fine I think. The existing code just exploits sparse files as an optimization, but not all tools are guaranteed to handle them correctly. What you suggest is equally valid. Feel free to submit a pull request for this.

1 Like