3
# Do post-image-building tasks for armel+dove, to make vfat images bootable;
4
# this script encapsulates the VFAT image in a PC partition image, with
5
# unpartitioned data holding boot data; this is very board specific and targets
6
# the Marvell Dove reference boards (e.g. Y0/Y1) but might work on other Dove
10
# $2 is the temporary CD build dir
11
# $3 is the image file
13
# Copyright (c) 2009 Canonical
14
# Authors: Oliver Grawert <ogra@canonical.com>
15
# Loïc Minier <loic.minier@canonical.com>
16
# Michael Casadevall <michael.casadevall@canonical.com>
19
# - use safer -m flag of parted (needs a newer parted)
20
# - add splash to cmdline (doesn't work right now; LP: #358362)
22
. "$BASEDIR/tools/boot/$DI_CODENAME/common.sh"
42
# Only disk 1* bootable
43
if ([ "$N" != 1 ] && [ "$N" != 1_NONUS ]) || [ "$CDIMAGE_ADDON" ]; then
47
# We only want to do this for vfat images
48
if [ "$IMAGE_FORMAT" != "vfat" ]; then
54
# this script creates an image to write to a SD card with a PC partition table;
55
# the first partition is the vfat passed as $3 ($IMAGE) and contains the
58
# the PC partitions have addresses which are constrained by what can be
59
# expressed in CHS / LBA; non-CHS aligned values scare fdisk, but parted is
60
# fine with pure LBA addresses on 512 bytes boundaries, so we use that
66
IMAGE_SIZE="$(file_length "$IMAGE")"
68
# round size to next block; note we add 512 for MBR + partition table; also
69
# note we assume blocks of 512 B
70
IMG_SIZE_BLOCKS="$(((512 + $IMAGE_SIZE + 512 - 1) / 512))"
72
# rename the VFAT image out of the way for the disk image
73
mv -f "$IMAGE" "$IMAGE.vfat"
79
# create the blank disk image (and this is a sparse file)
80
dd if=/dev/zero of="$IMAGE" bs=512 count=0 seek="$IMG_SIZE_BLOCKS" 2>/dev/null
82
# create partition table
83
log "initializing disk label (MBR and partition table)..."
84
parted -s "$IMAGE" mklabel msdos
86
# outputs actual partition start offset, end offset, and length, suffixed with
91
LANG=C parted -s "$IMAGE" unit B print | awk "/^ $n / { print \$2 \" \" \$3 \" \" \$4 }"
93
# safer version using parted -m; needs newer parted
94
#LANG=C parted -m -s "$IMAGE" unit B print | grep "^$n:" | cut -d: -f 2,3,4 --output-delimiter=" "
97
# read disk size, or rather last disk byte, with a "B" char at the end of the
99
# safer version using parted -m; needs newer parted
100
#DISK_END_B="$(LANG=C parted -m -s "$IMAGE" unit B print | tail -1 | cut -d : -f 2)"
101
DISK_END_B="$(LANG=C parted -s "$IMAGE" unit B print | sed -rn 's/^Disk [^:]+: ([0-9]+B)$/\1/p')"
103
# create partition for the VFAT
104
log "creating VFAT partition..."
105
parted -s "$IMAGE" mkpart primary fat32 0 "$((${DISK_END_B%B} - 1))B"
107
VFAT_LEN_B="`(set -- $(get_part_data 1); echo "$3")`"
108
if [ "${VFAT_LEN_B%B}" -lt "$IMAGE_SIZE" ]; then
109
die "VFAT partition length is $VFAT_LEN_B and doesn't leave enough room for VFAT ${IMAGE_SIZE}B"
112
VFAT_START_B="`(set -- $(get_part_data 1); echo "$1")`"
113
log "writing vfat contents..."
114
dd conv=notrunc bs="${VFAT_START_B%B}" if="$IMAGE.vfat" of="$IMAGE" seek=1 2>/dev/null
116
# VFAT isn't needed anymore