Commit 8b390fef58e6e134243f44e88efe508aa2a31ab4

Authored by Tim Gover
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 4  
5 5 TMP_DIR=""
6 6 TMP_IMAGE=""
7   -IMAGE_SIZE=0
  7 +IMAGE_SIZE=${IMAGE_SIZE:-0}
8 8 MEGABYTE=$((1024 * 1024))
9 9 BOOT_MOUNT=""
10 10 LOOP=""
11   -NAME=$(basename $0)
  11 +NAME="$(basename "$0")"
12 12  
13 13 # Define these environment variables to override mkfs options
14 14 SECTOR_SIZE=${SECTOR_SIZE:-512}
... ... @@ -57,7 +57,7 @@ mountfs() {
57 57 image="$1"
58 58  
59 59 LOOP=$(losetup -f)
60   - losetup ${LOOP} "${image}"
  60 + losetup "${LOOP}" "${image}"
61 61 [ -e "${LOOP}" ] || die "Failed to create loop device ${LOOP}"
62 62  
63 63 BOOT_MOUNT=$(mktemp -d)
... ... @@ -69,11 +69,14 @@ mountfs() {
69 69  
70 70 unmount_image() {
71 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 75 fi
74 76  
75 77 if [ -n "${LOOP}" ]; then
76 78 losetup -d "${LOOP}"
  79 + LOOP=""
77 80 fi
78 81 }
79 82  
... ... @@ -113,13 +116,15 @@ createstaging() {
113 116 content="${TMP_DIR}/content.tar"
114 117 echo "$(cd "${staging}"; ls -R)"
115 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 129 echo "Using IMAGE_SIZE of ${IMAGE_SIZE}"
125 130  
... ...