diff options
author | Darren Hart <dvhart@linux.intel.com> | 2014-07-16 14:16:04 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-07-19 00:09:00 +0100 |
commit | 172c5601d46a13aba209f6bf1cfa99649bdb77b2 (patch) | |
tree | 2435ebd0e76a4aa03856634f13421f88b747a1d0 /scripts/contrib | |
parent | 049100a9a7a6d2da18f8f85017313b890e9d02cc (diff) | |
download | poky-172c5601d46a13aba209f6bf1cfa99649bdb77b2.tar.gz |
mkefidisk.sh: Reduce output and add verbose flag
Remove superfluous output from commands, add a -v verbose flag, and
cleanup output.
(From OE-Core rev: 0742bcd437362eb31b40e35f7331f191a1e070d0)
Signed-off-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/contrib')
-rwxr-xr-x | scripts/contrib/mkefidisk.sh | 114 |
1 files changed, 67 insertions, 47 deletions
diff --git a/scripts/contrib/mkefidisk.sh b/scripts/contrib/mkefidisk.sh index 85e58ef865..7ec373ef56 100755 --- a/scripts/contrib/mkefidisk.sh +++ b/scripts/contrib/mkefidisk.sh | |||
@@ -20,6 +20,10 @@ | |||
20 | 20 | ||
21 | LANG=C | 21 | LANG=C |
22 | 22 | ||
23 | # Set to 1 to enable additional output | ||
24 | DEBUG=0 | ||
25 | OUT="/dev/null" | ||
26 | |||
23 | # | 27 | # |
24 | # Defaults | 28 | # Defaults |
25 | # | 29 | # |
@@ -30,7 +34,7 @@ SWAP_RATIO=5 | |||
30 | 34 | ||
31 | # Cleanup after die() | 35 | # Cleanup after die() |
32 | cleanup() { | 36 | cleanup() { |
33 | echo "Syncing and unmounting devices..." | 37 | debug "Syncing and unmounting devices" |
34 | # Unmount anything we mounted | 38 | # Unmount anything we mounted |
35 | unmount $ROOTFS_MNT || error "Failed to unmount $ROOTFS_MNT" | 39 | unmount $ROOTFS_MNT || error "Failed to unmount $ROOTFS_MNT" |
36 | unmount $BOOTFS_MNT || error "Failed to unmount $BOOTFS_MNT" | 40 | unmount $BOOTFS_MNT || error "Failed to unmount $BOOTFS_MNT" |
@@ -38,7 +42,7 @@ cleanup() { | |||
38 | unmount $HDDIMG_MNT || error "Failed to unmount $HDDIMG_MNT" | 42 | unmount $HDDIMG_MNT || error "Failed to unmount $HDDIMG_MNT" |
39 | 43 | ||
40 | # Remove the TMPDIR | 44 | # Remove the TMPDIR |
41 | echo "Removing temporary files..." | 45 | debug "Removing temporary files" |
42 | if [ -d "$TMPDIR" ]; then | 46 | if [ -d "$TMPDIR" ]; then |
43 | rm -rf $TMPDIR || error "Failed to remove $TMPDIR" | 47 | rm -rf $TMPDIR || error "Failed to remove $TMPDIR" |
44 | fi | 48 | fi |
@@ -71,9 +75,15 @@ die() { | |||
71 | cleanup | 75 | cleanup |
72 | exit 1 | 76 | exit 1 |
73 | } | 77 | } |
78 | debug() { | ||
79 | if [ $DEBUG -eq 1 ]; then | ||
80 | echo "$1" | ||
81 | fi | ||
82 | } | ||
74 | 83 | ||
75 | usage() { | 84 | usage() { |
76 | echo "Usage: $(basename $0) DEVICE HDDIMG TARGET_DEVICE" | 85 | echo "Usage: $(basename $0) [-v] DEVICE HDDIMG TARGET_DEVICE" |
86 | echo " -v: Verbose debug" | ||
77 | echo " DEVICE: The device to write the image to, e.g. /dev/sdh" | 87 | echo " DEVICE: The device to write the image to, e.g. /dev/sdh" |
78 | echo " HDDIMG: The hddimg file to generate the efi disk from" | 88 | echo " HDDIMG: The hddimg file to generate the efi disk from" |
79 | echo " TARGET_DEVICE: The device the target will boot from, e.g. /dev/mmcblk0" | 89 | echo " TARGET_DEVICE: The device the target will boot from, e.g. /dev/mmcblk0" |
@@ -82,7 +92,6 @@ usage() { | |||
82 | image_details() { | 92 | image_details() { |
83 | IMG=$1 | 93 | IMG=$1 |
84 | info "Image details" | 94 | info "Image details" |
85 | echo "=============" | ||
86 | echo " image: $(stat --printf '%N\n' $IMG)" | 95 | echo " image: $(stat --printf '%N\n' $IMG)" |
87 | echo " size: $(stat -L --printf '%s bytes\n' $IMG)" | 96 | echo " size: $(stat -L --printf '%s bytes\n' $IMG)" |
88 | echo " modified: $(stat -L --printf '%y\n' $IMG)" | 97 | echo " modified: $(stat -L --printf '%y\n' $IMG)" |
@@ -95,7 +104,6 @@ device_details() { | |||
95 | BLOCK_SIZE=512 | 104 | BLOCK_SIZE=512 |
96 | 105 | ||
97 | info "Device details" | 106 | info "Device details" |
98 | echo "==============" | ||
99 | echo " device: $DEVICE" | 107 | echo " device: $DEVICE" |
100 | if [ -f "/sys/class/block/$DEV/device/vendor" ]; then | 108 | if [ -f "/sys/class/block/$DEV/device/vendor" ]; then |
101 | echo " vendor: $(cat /sys/class/block/$DEV/device/vendor)" | 109 | echo " vendor: $(cat /sys/class/block/$DEV/device/vendor)" |
@@ -118,7 +126,7 @@ device_details() { | |||
118 | unmount_device() { | 126 | unmount_device() { |
119 | grep -q $DEVICE /proc/mounts | 127 | grep -q $DEVICE /proc/mounts |
120 | if [ $? -eq 0 ]; then | 128 | if [ $? -eq 0 ]; then |
121 | warn "$DEVICE listed in /proc/mounts, attempting to unmount..." | 129 | warn "$DEVICE listed in /proc/mounts, attempting to unmount" |
122 | umount $DEVICE* 2>/dev/null | 130 | umount $DEVICE* 2>/dev/null |
123 | return $? | 131 | return $? |
124 | fi | 132 | fi |
@@ -128,7 +136,7 @@ unmount_device() { | |||
128 | unmount() { | 136 | unmount() { |
129 | grep -q $1 /proc/mounts | 137 | grep -q $1 /proc/mounts |
130 | if [ $? -eq 0 ]; then | 138 | if [ $? -eq 0 ]; then |
131 | echo "Unmounting $1..." | 139 | debug "Unmounting $1" |
132 | umount $1 | 140 | umount $1 |
133 | return $? | 141 | return $? |
134 | fi | 142 | fi |
@@ -138,11 +146,17 @@ unmount() { | |||
138 | # | 146 | # |
139 | # Parse and validate arguments | 147 | # Parse and validate arguments |
140 | # | 148 | # |
141 | if [ $# -ne 3 ]; then | 149 | if [ $# -lt 3 ] || [ $# -gt 4 ]; then |
142 | usage | 150 | usage |
143 | exit 1 | 151 | exit 1 |
144 | fi | 152 | fi |
145 | 153 | ||
154 | if [ "$1" = "-v" ]; then | ||
155 | DEBUG=1 | ||
156 | OUT="1" | ||
157 | shift | ||
158 | fi | ||
159 | |||
146 | DEVICE=$1 | 160 | DEVICE=$1 |
147 | HDDIMG=$2 | 161 | HDDIMG=$2 |
148 | TARGET_DEVICE=$3 | 162 | TARGET_DEVICE=$3 |
@@ -230,34 +244,39 @@ fi | |||
230 | TARGET_ROOTFS=$TARGET_DEVICE${TARGET_PART_PREFIX}2 | 244 | TARGET_ROOTFS=$TARGET_DEVICE${TARGET_PART_PREFIX}2 |
231 | TARGET_SWAP=$TARGET_DEVICE${TARGET_PART_PREFIX}3 | 245 | TARGET_SWAP=$TARGET_DEVICE${TARGET_PART_PREFIX}3 |
232 | 246 | ||
233 | echo "*****************" | 247 | echo "" |
234 | echo "Boot partition size: $BOOT_SIZE MB ($BOOTFS)" | 248 | info "Boot partition size: $BOOT_SIZE MB ($BOOTFS)" |
235 | echo "ROOTFS partition size: $ROOTFS_SIZE MB ($ROOTFS)" | 249 | info "ROOTFS partition size: $ROOTFS_SIZE MB ($ROOTFS)" |
236 | echo "Swap partition size: $SWAP_SIZE MB ($SWAP)" | 250 | info "Swap partition size: $SWAP_SIZE MB ($SWAP)" |
237 | echo "*****************" | 251 | echo "" |
238 | |||
239 | echo "Deleting partition table on $DEVICE ..." | ||
240 | dd if=/dev/zero of=$DEVICE bs=512 count=2 > /dev/null || die "Failed to zero beginning of $DEVICE" | ||
241 | 252 | ||
242 | # Use MSDOS by default as GPT cannot be reliably distributed in disk image form | 253 | # Use MSDOS by default as GPT cannot be reliably distributed in disk image form |
243 | # as it requires the backup table to be on the last block of the device, which | 254 | # as it requires the backup table to be on the last block of the device, which |
244 | # of course varies from device to device. | 255 | # of course varies from device to device. |
245 | echo "Creating new partition table (MSDOS) on $DEVICE ..." | ||
246 | parted $DEVICE mklabel msdos || die "Failed to create MSDOS partition table" | ||
247 | 256 | ||
248 | echo "Creating boot partition on $BOOTFS" | 257 | info "Partitioning installation media ($DEVICE)" |
249 | parted $DEVICE mkpart primary 0% $BOOT_SIZE || die "Failed to create BOOT partition" | ||
250 | 258 | ||
251 | echo "Enabling boot flag on $BOOTFS" | 259 | debug "Deleting partition table on $DEVICE" |
252 | parted $DEVICE set 1 boot on || die "Failed to enable boot flag" | 260 | dd if=/dev/zero of=$DEVICE bs=512 count=2 >$OUT 2>1 || die "Failed to zero beginning of $DEVICE" |
253 | 261 | ||
254 | echo "Creating ROOTFS partition on $ROOTFS" | 262 | debug "Creating new partition table (MSDOS) on $DEVICE" |
255 | parted $DEVICE mkpart primary $ROOTFS_START $ROOTFS_END || die "Failed to create ROOTFS partition" | 263 | parted $DEVICE mklabel msdos >$OUT 2>1 || die "Failed to create MSDOS partition table" |
256 | 264 | ||
257 | echo "Creating swap partition on $SWAP" | 265 | debug "Creating boot partition on $BOOTFS" |
258 | parted $DEVICE mkpart primary $SWAP_START 100% || die "Failed to create SWAP partition" | 266 | parted $DEVICE mkpart primary 0% $BOOT_SIZE >$OUT 2>1 || die "Failed to create BOOT partition" |
259 | 267 | ||
260 | parted $DEVICE print | 268 | debug "Enabling boot flag on $BOOTFS" |
269 | parted $DEVICE set 1 boot on >$OUT 2>1 || die "Failed to enable boot flag" | ||
270 | |||
271 | debug "Creating ROOTFS partition on $ROOTFS" | ||
272 | parted $DEVICE mkpart primary $ROOTFS_START $ROOTFS_END >$OUT 2>1 || die "Failed to create ROOTFS partition" | ||
273 | |||
274 | debug "Creating swap partition on $SWAP" | ||
275 | parted $DEVICE mkpart primary $SWAP_START 100% >$OUT 2>1 || die "Failed to create SWAP partition" | ||
276 | |||
277 | if [ $DEBUG -eq 1 ]; then | ||
278 | parted $DEVICE print | ||
279 | fi | ||
261 | 280 | ||
262 | 281 | ||
263 | # | 282 | # |
@@ -269,38 +288,37 @@ unmount_device || die "Failed to unmount $DEVICE partitions" | |||
269 | # | 288 | # |
270 | # Format $DEVICE partitions | 289 | # Format $DEVICE partitions |
271 | # | 290 | # |
272 | echo "" | 291 | info "Formating partitions" |
273 | echo "Formatting $BOOTFS as vfat..." | 292 | debug "Formatting $BOOTFS as vfat" |
274 | if [ ! "${DEVICE#/dev/loop}" = "${DEVICE}" ]; then | 293 | if [ ! "${DEVICE#/dev/loop}" = "${DEVICE}" ]; then |
275 | mkfs.vfat -I $BOOTFS -n "EFI" || die "Failed to format $BOOTFS" | 294 | mkfs.vfat -I $BOOTFS -n "EFI" >$OUT 2>1 || die "Failed to format $BOOTFS" |
276 | else | 295 | else |
277 | mkfs.vfat $BOOTFS -n "EFI" || die "Failed to format $BOOTFS" | 296 | mkfs.vfat $BOOTFS -n "EFI" >$OUT 2>1 || die "Failed to format $BOOTFS" |
278 | fi | 297 | fi |
279 | 298 | ||
280 | echo "Formatting $ROOTFS as ext3..." | 299 | debug "Formatting $ROOTFS as ext3" |
281 | mkfs.ext3 -F $ROOTFS -L "ROOT" || die "Failed to format $ROOTFS" | 300 | mkfs.ext3 -F $ROOTFS -L "ROOT" >$OUT 2>1 || die "Failed to format $ROOTFS" |
282 | 301 | ||
283 | echo "Formatting swap partition...($SWAP)" | 302 | debug "Formatting swap partition ($SWAP)" |
284 | mkswap $SWAP || die "Failed to prepare swap" | 303 | mkswap $SWAP >$OUT 2>1 || die "Failed to prepare swap" |
285 | 304 | ||
286 | 305 | ||
287 | # | 306 | # |
288 | # Installing to $DEVICE | 307 | # Installing to $DEVICE |
289 | # | 308 | # |
290 | echo "" | 309 | debug "Mounting images and device in preparation for installation" |
291 | echo "Mounting images and device in preparation for installation..." | 310 | mount -o loop $HDDIMG $HDDIMG_MNT >$OUT 2>1 || error "Failed to mount $HDDIMG" |
292 | mount -o loop $HDDIMG $HDDIMG_MNT || error "Failed to mount $HDDIMG" | 311 | mount -o loop $HDDIMG_MNT/rootfs.img $HDDIMG_ROOTFS_MNT >$OUT 2>1 || error "Failed to mount rootfs.img" |
293 | mount -o loop $HDDIMG_MNT/rootfs.img $HDDIMG_ROOTFS_MNT || error "Failed to mount rootfs.img" | 312 | mount $ROOTFS $ROOTFS_MNT >$OUT 2>1 || error "Failed to mount $ROOTFS on $ROOTFS_MNT" |
294 | mount $ROOTFS $ROOTFS_MNT || error "Failed to mount $ROOTFS on $ROOTFS_MNT" | 313 | mount $BOOTFS $BOOTFS_MNT >$OUT 2>1 || error "Failed to mount $BOOTFS on $BOOTFS_MNT" |
295 | mount $BOOTFS $BOOTFS_MNT || error "Failed to mount $BOOTFS on $BOOTFS_MNT" | ||
296 | 314 | ||
297 | echo "Preparing boot partition..." | 315 | info "Preparing boot partition" |
298 | EFIDIR="$BOOTFS_MNT/EFI/BOOT" | 316 | EFIDIR="$BOOTFS_MNT/EFI/BOOT" |
299 | cp $HDDIMG_MNT/vmlinuz $BOOTFS_MNT || error "Failed to copy vmlinuz" | 317 | cp $HDDIMG_MNT/vmlinuz $BOOTFS_MNT >$OUT 2>1 || error "Failed to copy vmlinuz" |
300 | # Copy the efi loader and configs (booti*.efi and grub.cfg if it exists) | 318 | # Copy the efi loader and configs (booti*.efi and grub.cfg if it exists) |
301 | cp -r $HDDIMG_MNT/EFI $BOOTFS_MNT || error "Failed to copy EFI dir" | 319 | cp -r $HDDIMG_MNT/EFI $BOOTFS_MNT >$OUT 2>1 || error "Failed to copy EFI dir" |
302 | # Silently ignore a missing gummiboot loader dir (we might just be a GRUB image) | 320 | # Silently ignore a missing gummiboot loader dir (we might just be a GRUB image) |
303 | cp -r $HDDIMG_MNT/loader $BOOTFS_MNT 2> /dev/null | 321 | cp -r $HDDIMG_MNT/loader $BOOTFS_MNT >$OUT 2>1 |
304 | 322 | ||
305 | # Update the boot loaders configurations for an installed image | 323 | # Update the boot loaders configurations for an installed image |
306 | # Remove any existing root= kernel parameters and: | 324 | # Remove any existing root= kernel parameters and: |
@@ -331,7 +349,7 @@ GUMMI_CFG="$GUMMI_ENTRIES/boot.conf" | |||
331 | if [ -d "$GUMMI_ENTRIES" ]; then | 349 | if [ -d "$GUMMI_ENTRIES" ]; then |
332 | info "Configuring Gummiboot" | 350 | info "Configuring Gummiboot" |
333 | # remove the install target if it exists | 351 | # remove the install target if it exists |
334 | rm $GUMMI_ENTRIES/install.conf &> /dev/null | 352 | rm $GUMMI_ENTRIES/install.conf >$OUT 2>1 |
335 | 353 | ||
336 | if [ ! -e "$GUMMI_CFG" ]; then | 354 | if [ ! -e "$GUMMI_CFG" ]; then |
337 | echo "ERROR: $GUMMI_CFG not found" | 355 | echo "ERROR: $GUMMI_CFG not found" |
@@ -348,7 +366,7 @@ fi | |||
348 | 366 | ||
349 | 367 | ||
350 | info "Copying ROOTFS files (this may take a while)" | 368 | info "Copying ROOTFS files (this may take a while)" |
351 | cp -a $HDDIMG_ROOTFS_MNT/* $ROOTFS_MNT || die "Root FS copy failed" | 369 | cp -a $HDDIMG_ROOTFS_MNT/* $ROOTFS_MNT >$OUT 2>1 || die "Root FS copy failed" |
352 | 370 | ||
353 | echo "$TARGET_SWAP swap swap defaults 0 0" >> $ROOTFS_MNT/etc/fstab | 371 | echo "$TARGET_SWAP swap swap defaults 0 0" >> $ROOTFS_MNT/etc/fstab |
354 | 372 | ||
@@ -361,6 +379,7 @@ fi | |||
361 | # Call cleanup to unmount devices and images and remove the TMPDIR | 379 | # Call cleanup to unmount devices and images and remove the TMPDIR |
362 | cleanup | 380 | cleanup |
363 | 381 | ||
382 | echo "" | ||
364 | if [ $WARNINGS -ne 0 ] && [ $ERRORS -eq 0 ]; then | 383 | if [ $WARNINGS -ne 0 ] && [ $ERRORS -eq 0 ]; then |
365 | echo "${YELLOW}Installation completed with warnings${CLEAR}" | 384 | echo "${YELLOW}Installation completed with warnings${CLEAR}" |
366 | echo "${YELLOW}Warnings: $WARNINGS${CLEAR}" | 385 | echo "${YELLOW}Warnings: $WARNINGS${CLEAR}" |
@@ -371,3 +390,4 @@ elif [ $ERRORS -ne 0 ]; then | |||
371 | else | 390 | else |
372 | success "Installation completed successfully" | 391 | success "Installation completed successfully" |
373 | fi | 392 | fi |
393 | echo "" | ||