~tsimonq2/debian-cd/lubuntu-cosmic-changes

« back to all changes in this revision

Viewing changes to tools/boot/oneiric/post-boot-armel+dove

  • Committer: Colin Watson
  • Date: 2011-04-30 16:06:44 UTC
  • Revision ID: cjwatson@canonical.com-20110430160644-0g6ldw3d4rpilkin
add CONF.sh bits for oneiric; copy natty -> oneiric elsewhere

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
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
 
7
# boards
 
8
#
 
9
# $1 is the CD number
 
10
# $2 is the temporary CD build dir
 
11
# $3 is the image file
 
12
#
 
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>
 
17
#
 
18
# TODO
 
19
# - use safer -m flag of parted (needs a newer parted)
 
20
# - add splash to cmdline (doesn't work right now; LP: #358362)
 
21
 
 
22
. "$BASEDIR/tools/boot/$DI_CODENAME/common.sh"
 
23
 
 
24
# parted is in /sbin
 
25
PATH="$PATH:/sbin"
 
26
 
 
27
set -e
 
28
 
 
29
N="$1"
 
30
CDROOT="$2"
 
31
IMAGE="$3"
 
32
 
 
33
log() {
 
34
    echo "$*" >&2
 
35
}
 
36
 
 
37
die() {
 
38
    log "$@"
 
39
    exit 1
 
40
}
 
41
 
 
42
# Only disk 1* bootable
 
43
if ([ "$N" != 1 ] && [ "$N" != 1_NONUS ]) || [ "$CDIMAGE_ADDON" ]; then
 
44
    exit 0
 
45
fi
 
46
 
 
47
# We only want to do this for vfat images
 
48
if [ "$IMAGE_FORMAT" != "vfat" ]; then
 
49
    exit 0
 
50
fi
 
51
 
 
52
cd "$CDROOT/.."
 
53
 
 
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
 
56
# root fs.
 
57
 
 
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
 
61
 
 
62
file_length() {
 
63
    stat -c %s "$1"
 
64
}
 
65
 
 
66
IMAGE_SIZE="$(file_length "$IMAGE")"
 
67
 
 
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))"
 
71
 
 
72
# rename the VFAT image out of the way for the disk image
 
73
mv -f "$IMAGE" "$IMAGE.vfat"
 
74
 
 
75
hex2dec() {
 
76
    printf "%d\n" "$1"
 
77
}
 
78
 
 
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
 
81
 
 
82
# create partition table
 
83
log "initializing disk label (MBR and partition table)..."
 
84
parted -s "$IMAGE" mklabel msdos
 
85
 
 
86
# outputs actual partition start offset, end offset, and length, suffixed with
 
87
# B
 
88
get_part_data() {
 
89
    local n="$1"
 
90
 
 
91
    LANG=C parted -s "$IMAGE" unit B print | awk "/^ $n / { print \$2 \" \" \$3 \" \" \$4 }"
 
92
 
 
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=" "
 
95
}
 
96
 
 
97
# read disk size, or rather last disk byte, with a "B" char at the end of the
 
98
# output
 
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')"
 
102
 
 
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"
 
106
 
 
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"
 
110
fi
 
111
 
 
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
 
115
 
 
116
# VFAT isn't needed anymore
 
117
rm -f "$IMAGE.vfat"