summaryrefslogtreecommitdiffstats
path: root/scripts/genhdimg
diff options
context:
space:
mode:
authorGeorge McCollister <georgem@novatech-llc.com>2009-12-15 17:28:49 -0600
committerMarc Kleine-Budde <mkl@pengutronix.de>2009-12-16 00:49:30 +0100
commit41400fa6647d23a06653bd91baa3a7674ddfa7d1 (patch)
treed2f2d327d9bcbcad30bea4720ccf02fbe0bbd538 /scripts/genhdimg
parent44601f3927a9655dbcef417c0124a9d59f17cc83 (diff)
downloadptxdist-41400fa6647d23a06653bd91baa3a7674ddfa7d1.tar.gz
ptxdist-41400fa6647d23a06653bd91baa3a7674ddfa7d1.tar.xz
[genhdimg] Fixed a problem where genhdimg could generate a corrupt image file
pad() wasn't always padding the output file to the correct length. On some machines dd wasn't reading full blocks which resulted in an incorrectly padded file. pad() now makes one call to dd to write the input file using conv=sync to pad to the nearest 512 byte boundry. Then dd is called again if additional 512 byte '\0' blocks are needed to meet the padding size. Signed-off-by: George McCollister <georgem@novatech-llc.com> Tested-by: George McCollister <georgem@novatech-llc.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'scripts/genhdimg')
-rwxr-xr-xscripts/genhdimg14
1 files changed, 13 insertions, 1 deletions
diff --git a/scripts/genhdimg b/scripts/genhdimg
index 12a0281cc..490a43ade 100755
--- a/scripts/genhdimg
+++ b/scripts/genhdimg
@@ -42,7 +42,19 @@ pad() {
echo "warning: $from truncated. Need $fromsize bytes, but have only $(($blocks * 512))!"
fi
- cat $from /dev/zero | dd bs=512 count=$(($blocks)) >> "$to" 2>/dev/null
+ tosize=$(stat -c "%s" "$to")
+ toblocks_before=$(( $tosize / 512 ))
+
+ dd if="$from" bs=512 count=$blocks conv=sync >> "$to" 2> /dev/null
+
+ tosize=$(stat -c "%s" "$to")
+ toblocks=$(( $tosize / 512 ))
+
+ blocksleft=$(( $blocks - $toblocks + $toblocks_before ))
+
+ if [ $blocksleft -gt 0 ]; then
+ dd if=/dev/zero bs=512 count=$blocksleft >> "$to" 2>/dev/null
+ fi
}