Commit 8b390fef58e6e134243f44e88efe508aa2a31ab4
Committed by
Phil Elwell
1 parent
6154fe2e
make-boot-image: Enable the image size to be specified
Fix some minor shellcheck warnings
Showing
1 changed file
with
16 additions
and
11 deletions
tools/make-boot-image
| @@ -4,11 +4,11 @@ set -e | @@ -4,11 +4,11 @@ set -e | ||
| 4 | 4 | ||
| 5 | TMP_DIR="" | 5 | TMP_DIR="" |
| 6 | TMP_IMAGE="" | 6 | TMP_IMAGE="" |
| 7 | -IMAGE_SIZE=0 | 7 | +IMAGE_SIZE=${IMAGE_SIZE:-0} |
| 8 | MEGABYTE=$((1024 * 1024)) | 8 | MEGABYTE=$((1024 * 1024)) |
| 9 | BOOT_MOUNT="" | 9 | BOOT_MOUNT="" |
| 10 | LOOP="" | 10 | LOOP="" |
| 11 | -NAME=$(basename $0) | 11 | +NAME="$(basename "$0")" |
| 12 | 12 | ||
| 13 | # Define these environment variables to override mkfs options | 13 | # Define these environment variables to override mkfs options |
| 14 | SECTOR_SIZE=${SECTOR_SIZE:-512} | 14 | SECTOR_SIZE=${SECTOR_SIZE:-512} |
| @@ -57,7 +57,7 @@ mountfs() { | @@ -57,7 +57,7 @@ mountfs() { | ||
| 57 | image="$1" | 57 | image="$1" |
| 58 | 58 | ||
| 59 | LOOP=$(losetup -f) | 59 | LOOP=$(losetup -f) |
| 60 | - losetup ${LOOP} "${image}" | 60 | + losetup "${LOOP}" "${image}" |
| 61 | [ -e "${LOOP}" ] || die "Failed to create loop device ${LOOP}" | 61 | [ -e "${LOOP}" ] || die "Failed to create loop device ${LOOP}" |
| 62 | 62 | ||
| 63 | BOOT_MOUNT=$(mktemp -d) | 63 | BOOT_MOUNT=$(mktemp -d) |
| @@ -69,11 +69,14 @@ mountfs() { | @@ -69,11 +69,14 @@ mountfs() { | ||
| 69 | 69 | ||
| 70 | unmount_image() { | 70 | unmount_image() { |
| 71 | if [ -d "${BOOT_MOUNT}" ]; then | 71 | if [ -d "${BOOT_MOUNT}" ]; then |
| 72 | - umount "${BOOT_MOUNT}" > /dev/null || true | 72 | + umount "${BOOT_MOUNT}" > /dev/null 2>&1 || true |
| 73 | + rmdir "${BOOT_MOUNT}" | ||
| 74 | + BOOT_MOUNT="" | ||
| 73 | fi | 75 | fi |
| 74 | 76 | ||
| 75 | if [ -n "${LOOP}" ]; then | 77 | if [ -n "${LOOP}" ]; then |
| 76 | losetup -d "${LOOP}" | 78 | losetup -d "${LOOP}" |
| 79 | + LOOP="" | ||
| 77 | fi | 80 | fi |
| 78 | } | 81 | } |
| 79 | 82 | ||
| @@ -113,13 +116,15 @@ createstaging() { | @@ -113,13 +116,15 @@ createstaging() { | ||
| 113 | content="${TMP_DIR}/content.tar" | 116 | content="${TMP_DIR}/content.tar" |
| 114 | echo "$(cd "${staging}"; ls -R)" | 117 | echo "$(cd "${staging}"; ls -R)" |
| 115 | tar -cf "${content}" "${staging}" > /dev/null 2>&1 | 118 | tar -cf "${content}" "${staging}" > /dev/null 2>&1 |
| 116 | - IMAGE_SIZE=$(stat --printf "%s" "${content}") | ||
| 117 | - IMAGE_SIZE=$(((IMAGE_SIZE + 1023) / 1024)) | ||
| 118 | - rm -f "${content}" | ||
| 119 | - | ||
| 120 | - # Add a little padding for FAT etc and convert to megabytes | ||
| 121 | - IMAGE_SIZE=$((IMAGE_SIZE + FAT_OVERHEAD)) | ||
| 122 | - IMAGE_SIZE=$(((IMAGE_SIZE + 1023) / 1024)) | 119 | + if [ "${IMAGE_SIZE}" = 0 ]; then |
| 120 | + IMAGE_SIZE=$(stat --printf "%s" "${content}") | ||
| 121 | + IMAGE_SIZE=$(((IMAGE_SIZE + 1023) / 1024)) | ||
| 122 | + rm -f "${content}" | ||
| 123 | + | ||
| 124 | + # Add a little padding for FAT etc and convert to megabytes | ||
| 125 | + IMAGE_SIZE=$((IMAGE_SIZE + FAT_OVERHEAD)) | ||
| 126 | + IMAGE_SIZE=$(((IMAGE_SIZE + 1023) / 1024)) | ||
| 127 | + fi | ||
| 123 | 128 | ||
| 124 | echo "Using IMAGE_SIZE of ${IMAGE_SIZE}" | 129 | echo "Using IMAGE_SIZE of ${IMAGE_SIZE}" |
| 125 | 130 |