diff options
author | George McCollister <georgem@novatech-llc.com> | 2009-12-15 17:28:49 -0600 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2009-12-16 13:06:05 +0100 |
commit | 816f7248523d364a8394c8e8e62f00216964db4e (patch) | |
tree | b9d7b0fbdfbbadd7090817c65857a73221af75f8 | |
parent | 83c8891093fc4d2228a3dbf16b7ac03f0e845b35 (diff) | |
download | ptxdist-816f7248523d364a8394c8e8e62f00216964db4e.tar.gz ptxdist-816f7248523d364a8394c8e8e62f00216964db4e.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>
Cherry-picked from master: 41400fa6647d23a06653bd91baa3a7674ddfa7d1
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rwxr-xr-x | scripts/genhdimg | 14 |
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 } |