Patchwork [1/2] bootimg: Use mcopy to construct the hddimg

login
register
mail settings
Submitter Darren Hart
Date Dec. 16, 2011, 6:14 a.m.
Message ID <33febd68cae9e482a7d35c230a0b875849e86669.1324015563.git.dvhart@linux.intel.com>
Download mbox | patch
Permalink /patch/17095/
State Accepted
Commit 92d2ea1a306354c6565a1b05b51b5719e481840f
Headers show

Comments

Darren Hart - Dec. 16, 2011, 6:14 a.m.
The initial directory support (-d) added to mkdosfs has proven to be incomplete
and non-compliant with FAT. Rather than continue to maintain this feature and
work around the various issues, we can use mcopy to construct the image.

bootimg.bbclass already depends on mtools-native (although it may not have
needed to previously). No new dependencies are introduced. The image created
passes dosfsck cleanly. Remove the call to dosfsck.

mcopy reported an error with the image we were creating:
Total number of sectors (107574) not a multiple of sectors per track (32)!

Add some logic to ensure the total sector count is an integral number of sectors
per track, including forcing the logical sector size to 512 in the mkdosfs
command.

The du -bks arguments are contradictory, -b is equivalent to "--apparent-size
--block-size=1" and -k is --block-size=1K. If reordered, -kbs will report the
disk usage in bytes insteadk of 1k blocks. Eliminate the ambiguity by using:
du --apparent-size -ks

Signed-off-by: Darren Hart <dvhart@linux.intel.com>
CC: Nitin A. Kamble <nitin.a.kamble@intel.com>
---
 meta/classes/bootimg.bbclass |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)
Richard Purdie - Dec. 16, 2011, 4:18 p.m.
On Thu, 2011-12-15 at 22:14 -0800, Darren Hart wrote:
> The initial directory support (-d) added to mkdosfs has proven to be incomplete
> and non-compliant with FAT. Rather than continue to maintain this feature and
> work around the various issues, we can use mcopy to construct the image.
> 
> bootimg.bbclass already depends on mtools-native (although it may not have
> needed to previously). No new dependencies are introduced. The image created
> passes dosfsck cleanly. Remove the call to dosfsck.
> 
> mcopy reported an error with the image we were creating:
> Total number of sectors (107574) not a multiple of sectors per track (32)!
> 
> Add some logic to ensure the total sector count is an integral number of sectors
> per track, including forcing the logical sector size to 512 in the mkdosfs
> command.
> 
> The du -bks arguments are contradictory, -b is equivalent to "--apparent-size
> --block-size=1" and -k is --block-size=1K. If reordered, -kbs will report the
> disk usage in bytes insteadk of 1k blocks. Eliminate the ambiguity by using:
> du --apparent-size -ks
> 
> Signed-off-by: Darren Hart <dvhart@linux.intel.com>
> CC: Nitin A. Kamble <nitin.a.kamble@intel.com>
> ---
>  meta/classes/bootimg.bbclass |   18 +++++++++++++-----
>  1 files changed, 13 insertions(+), 5 deletions(-)

Merged into master, thanks.

I'm going to hold off 2/2 to give other users a chance to migrate to
mcopy.

Cheers,

Richard

Patch

diff --git a/meta/classes/bootimg.bbclass b/meta/classes/bootimg.bbclass
index 8ec07a0..b50202f 100644
--- a/meta/classes/bootimg.bbclass
+++ b/meta/classes/bootimg.bbclass
@@ -103,13 +103,21 @@  build_hddimg() {
 			grubefi_hddimg_populate
 		fi
 
-		# Determine the block count for the final image
-		BLOCKS=`du -bks ${HDDDIR} | cut -f 1`
+		# Determine the 1024 byte block count for the final image.
+		BLOCKS=`du --apparent-size -ks ${HDDDIR} | cut -f 1`
 		SIZE=`expr $BLOCKS + ${BOOTIMG_EXTRA_SPACE}`
 
-		mkdosfs -n ${BOOTIMG_VOLUME_ID} -d ${HDDDIR} \
-		        -C ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg $SIZE
-		dosfsck -a -l ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg || true
+		# Ensure total sectors is an integral number of sectors per
+		# track or mcopy will complain. Sectors are 512 bytes, and and
+		# we generate images with 32 sectors per track. This calculation
+		# is done in blocks, which are twice the size of sectors, thus
+		# the 16 instead of 32.
+		SIZE=$(expr $SIZE + $(expr 16 - $(expr $SIZE % 16)))
+
+		IMG=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg
+		mkdosfs -n ${BOOTIMG_VOLUME_ID} -S 512 -C ${IMG} ${SIZE}
+		# Copy HDDDIR recursively into the image file directly
+		mcopy -i ${IMG} -s ${HDDDIR}/* ::/
 
 		if [ "${PCBIOS}" = "1" ]; then
 			syslinux_hddimg_install