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

**URL:** <https://hub.mender.io/t/potential-error-in-mender-bootimg-bbclass-leads-to-incorrect-boot-partition/6015>\
**Category:** General Discussions\
**Tags:** yocto\
**Created:** [July 18, 2023, 3:27pm UTC](https://hub.mender.io/t/potential-error-in-mender-bootimg-bbclass-leads-to-incorrect-boot-partition/6015 "2023-07-18T15:27:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cchciose](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/cchciose/32/1947_2.png) [@cchciose](https://hub.mender.io/u/cchciose)\
**Post date:** [July 18, 2023, 3:27pm UTC](https://hub.mender.io/t/potential-error-in-mender-bootimg-bbclass-leads-to-incorrect-boot-partition/6015/1 "2023-07-18T15:27:44Z")

</div>

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 :

```auto
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 \

```

---

<div class="post-metadata">

**Author:** ![TheYoctoJester](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/theyoctojester/32/1444_2.png) [@TheYoctoJester](https://hub.mender.io/u/TheYoctoJester)\
**Post date:** [July 19, 2023, 8:34am UTC](https://hub.mender.io/t/potential-error-in-mender-bootimg-bbclass-leads-to-incorrect-boot-partition/6015/2 "2023-07-19T08:34:13Z")

</div>

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 🙂

Thanks,  
Josef

---

<div class="post-metadata">

**Author:** ![kacf](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kacf/32/146_2.png) [@kacf](https://hub.mender.io/u/kacf)\
**Post date:** [July 19, 2023, 8:47am UTC](https://hub.mender.io/t/potential-error-in-mender-bootimg-bbclass-leads-to-incorrect-boot-partition/6015/3 "2023-07-19T08:47:01Z")

</div>

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.
