Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/distrib/utils/embedded embedded/mkimage: Pad image with zero...



details:   https://anonhg.NetBSD.org/src/rev/6cdfa9ca2139
branches:  trunk
changeset: 948229:6cdfa9ca2139
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Dec 21 16:38:02 2020 +0000

description:
embedded/mkimage: Pad image with zeros to multiple of 4 MB plus 1 MB.

Otherwise, there may not be enough space after the ffs partition for a
gpt, leading to very confusing results.

diffstat:

 distrib/utils/embedded/mkimage |  20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diffs (37 lines):

diff -r 5936a8c1dded -r 6cdfa9ca2139 distrib/utils/embedded/mkimage
--- a/distrib/utils/embedded/mkimage    Mon Dec 21 11:30:59 2020 +0000
+++ b/distrib/utils/embedded/mkimage    Mon Dec 21 16:38:02 2020 +0000
@@ -1,5 +1,5 @@
 #!/bin/sh
-# $NetBSD: mkimage,v 1.75 2020/07/17 15:16:34 jmcneill Exp $
+# $NetBSD: mkimage,v 1.76 2020/12/21 16:38:02 riastradh Exp $
 #
 # Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -259,17 +259,17 @@
            -F "$tmp/selected_sets" ${image} "${release}" "${mnt}"
 fi
 
+cursize="$(getsize "${image}")"
 if [ "${size}" = 0 ]; then
-       size="$(getsize "${image}")"
+       size="${cursize}"
+       # Round up to a multiple of 4m and add 1m of slop.
+       alignunit=$((4*1024*1024))
+       alignsize=$((alignunit*((cursize + alignunit - 1)/alignunit)))
+       alignsize=$((alignsize + 1024*1024))
+       if [ $cursize -lt $alignsize ]; then
+               head -c "$((alignsize - cursize))" < /dev/zero >> "${image}"
+       fi
 fi
-newsize=$((${size} / 2 / 1024))
-compare=$((${newsize} * 2 * 1024))
-while [ "${compare}" != "${size}" ]
-do    
-       size="$((size + size - compare))"  
-       newsize="$((${size} / 2 / 1024))"
-       compare="$((${newsize} * 2 * 1024))"
-done                      
 
 if $gpt; then
        if $gpt_hybrid; then



Home | Main Index | Thread Index | Old Index