diff mbox series

[v3] wic: Add support for variable sector size when creating ESP

Message ID 20250915064137.4025945-1-macpaul.lin@mediatek.com
State New
Headers show
Series [v3] wic: Add support for variable sector size when creating ESP | expand

Commit Message

Macpaul Lin Sept. 15, 2025, 6:41 a.m. UTC
Derive sector_size from the WIC_SECTOR_SIZE BitBake variable.
Recalculate blocks to align with the chosen sector size.
While the default sector size of mkdosfs is 512 bytes.
Pass -S <sector_size> to align the setting of WIC_SECTOR_SIZE.

Signed-off-by: Macpaul Lin <macpaul.lin@mediatek.com>
---
 scripts/lib/wic/plugins/source/bootimg_efi.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Changes for v2:
 - drop --sector-size, use get_bitbake_var("WIC_SECTOR_SIZE") instead.
 - drop value filter of sector-size.
 - drop creating new sub-varible for 'part'.

Changes for v3:
 - Add -v option back for mkdosfs.
 - Round up the value of blocks instead of round dwon.
diff mbox series

Patch

diff --git a/scripts/lib/wic/plugins/source/bootimg_efi.py b/scripts/lib/wic/plugins/source/bootimg_efi.py
index cf16705a285a..288fe6a15a7d 100644
--- a/scripts/lib/wic/plugins/source/bootimg_efi.py
+++ b/scripts/lib/wic/plugins/source/bootimg_efi.py
@@ -415,8 +415,19 @@  class BootimgEFIPlugin(SourcePlugin):
 
         label = part.label if part.label else "ESP"
 
-        dosfs_cmd = "mkdosfs -v -n %s -i %s -C %s %d" % \
-                    (label, part.fsuuid, bootimg, blocks)
+        # define sector size, default is 512 for mkdosfs
+        sector_size_str = get_bitbake_var('WIC_SECTOR_SIZE')
+        if sector_size_str is not None and str(sector_size_str).isdigit():
+            sector_size = int(sector_size_str)
+        else:
+            sector_size = 512
+
+        size_bytes = blocks * 1024
+        blocks = (size_bytes + sector_size - 1) // sector_size
+
+        dosfs_cmd = "mkdosfs -v -n %s -i %s -C %s %d -S %d" % \
+                    (label, part.fsuuid, bootimg, blocks, sector_size)
+
         exec_native_cmd(dosfs_cmd, native_sysroot)
         logger.debug("mkdosfs:\n%s" % (str(out)))