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.
This commit is contained in:
riastradh 2020-12-21 16:38:02 +00:00
parent dc3812a1c6
commit 15867ac673
1 changed files with 10 additions and 10 deletions

View File

@ -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 @@ if [ -z "${bootonly}" ]; then
-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