~cyphermox/debian-cd/ubuntu-server-live

« back to all changes in this revision

Viewing changes to tools/boot/artful/post-boot-armel+omap

  • Committer: Adam Conrad
  • Date: 2017-04-25 21:27:20 UTC
  • Revision ID: adconrad@0c3.net-20170425212720-re2dgv8stz51tyv8
Copy zesty -> artful, and add artful to CONF.sh

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
3
# Do post-image-building tasks for arm+omap, 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
CDDIR="$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" == "iso" ]; then
 
49
    exit 0
 
50
fi
 
51
 
 
52
cd "$CDDIR/.."
 
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
# OMAP3 requires very specific CHS partitioning that can't easy be done with parted
 
59
# so we'll use sfdisk to properly make the necessary partition layout
 
60
 
 
61
# globals (please adjust or autodetect or whatever (based on SUBARCH))
 
62
# note thses  paths point to manually unpacked .debs on my disk atm
 
63
 
 
64
file_length() {
 
65
    stat -c %s "$1"
 
66
}
 
67
 
 
68
extract_file_from_package() {
 
69
    package=$1
 
70
    file_to_extract=$2
 
71
    output_file_name=$3 
 
72
 
 
73
    deb="$("$BASEDIR/tools/apt-selection" cache show "$package" | sed -n 's/^Filename: //p')"
 
74
    if [ "$deb" = "" ]; then
 
75
        log "Package $package not found!" 
 
76
        exit 1
 
77
    fi
 
78
 
 
79
    tmpdir=`mktemp -d`
 
80
    dpkg --fsys-tarfile "$MIRROR/$deb" | tar xf - -C $tmpdir "./$file_to_extract"
 
81
    mv $tmpdir/$file_to_extract ./$output_file_name
 
82
    rm -rf $tmpdir
 
83
}
 
84
 
 
85
# This is common across all configurations
 
86
if [ "${FULLARCH##*+}" = "omap" ]; then
 
87
    path_to_xloader="usr/lib/u-boot/omap3_beagle/MLO"
 
88
 
 
89
    uboot_package="u-boot-linaro-omap3-beagle"
 
90
    path_to_uboot="usr/lib/u-boot/omap3_beagle/u-boot.bin"
 
91
 
 
92
    xloader_package=$uboot_package
 
93
 
 
94
    v_opts=""
 
95
    board_opts=""
 
96
elif [ "${FULLARCH##*+}" = "omap4" ]; then
 
97
    path_to_xloader="usr/lib/u-boot/omap4_panda/MLO"
 
98
 
 
99
    uboot_package="u-boot-linaro-omap4-panda"
 
100
    path_to_uboot="usr/lib/u-boot/omap4_panda/u-boot.bin"
 
101
 
 
102
    xloader_package=$uboot_package
 
103
 
 
104
    board_opts=""
 
105
    v_opts=""
 
106
else
 
107
    die "Unknown OMAP subarch"
 
108
fi
 
109
 
 
110
if [ "$PROJECT" = "ubuntu-headless" ] || [ "$PROJECT" = "ubuntu-server" ]; then
 
111
    serial_opts="debian-installer/framebuffer=false console=ttyO2,115200n8"
 
112
fi
 
113
 
 
114
log "Extracting bootloader from main archive"
 
115
extract_file_from_package $xloader_package $path_to_xloader "MLO"
 
116
extract_file_from_package $uboot_package $path_to_uboot "u-boot.bin"
 
117
 
 
118
uboot_kernel="uImage"
 
119
uboot_initrd="uInitrd"
 
120
uboot_kernel_addr="0x80000000"
 
121
uboot_ramdisk_addr="0x81600000"
 
122
uboot_script_addr="0x1000"
 
123
uenv_script_text="$CDDIR/uEnv.txt"
 
124
preenv_script_text="$CDDIR/preEnv.txt"
 
125
preenv_script_text_serial="$CDDIR/preEnv.txt-serial"
 
126
 
 
127
if [ "$CDIMAGE_INSTALL_BASE" = 1 ]; then
 
128
    uboot_desc="Ubuntu Alternate Installer"
 
129
    uboot_input_kernel="$CDDIR/cdrom/uImage.in"
 
130
    uboot_input_initrd="$CDDIR/cdrom/uInitrd.in"
 
131
    uboot_extra_cmdline=" cdrom-detect/try-usb=true"
 
132
 
 
133
    mkdir -p "`dirname "$uboot_input_kernel"`"
 
134
    cp -lf "$SUBARCH/cdrom/vmlinuz"   "$uboot_input_kernel"
 
135
    cp -lf "$SUBARCH/cdrom/initrd.gz" "$uboot_input_initrd"
 
136
fi
 
137
 
 
138
if [ "$CDIMAGE_LIVE" = 1 ]; then
 
139
    uboot_desc="Ubuntu LiveCD"
 
140
    uboot_input_kernel="$CDDIR/casper/filesystem.kernel-$SUBARCH"
 
141
    uboot_input_initrd="$CDDIR/casper/filesystem.initrd-$SUBARCH"
 
142
    uboot_extra_cmdline=" fixrtc quiet splash -- boot=casper only-ubiquity"
 
143
fi
 
144
 
 
145
if [ "$CDIMAGE_PREINSTALLED" = 1 ]; then
 
146
    uboot_desc="Ubuntu Preinstalled Image"
 
147
    uboot_input_kernel="$LIVEIMAGES/$FULLARCH.kernel-$SUBARCH"
 
148
    uboot_input_initrd="$LIVEIMAGES/$FULLARCH.initrd-$SUBARCH"
 
149
    uboot_extra_cmdline=" root=/dev/mmcblk0p2 fixrtc quiet splash"
 
150
fi
 
151
 
 
152
EXT3=$IMAGE.rootfs
 
153
MTOOLSRC=$IMAGE.mtoolsrc
 
154
 
 
155
# Turn our kernel and initrd into a uImage and uInitrd
 
156
log "Calling uboot-mkimage on kernel and ramdisk"
 
157
 
 
158
rm -f $uboot_kernel $uboot_initrd
 
159
mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 -n "Ubuntu Kernel" -d "$uboot_input_kernel" "$uboot_kernel"
 
160
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x0 -e 0x0 -n "Ubuntu Initrd" -d "$uboot_input_initrd" "$uboot_initrd"
 
161
 
 
162
log "Creating default uEnv.txt"
 
163
cat >"$uenv_script_text" <<EOF
 
164
bootcmd=fatload mmc 0:1 0x80000000 uImage;fatload mmc 0:1 0x81600000 uInitrd; bootm 0x80000000 0x81600000
 
165
uenvcmd=boot
 
166
EOF
 
167
 
 
168
log "Creating default preEnv.txt"
 
169
cat >"$preenv_script_text" <<EOF
 
170
bootargs=$v_opts $board_opts $DEFAULT_PRESEED $uboot_extra_cmdline
 
171
EOF
 
172
 
 
173
if [ -n "$serial_opts" ]; then
 
174
        log "Serial options exist, creating default preEnv.txt-serial"
 
175
cat >"$preenv_script_text_serial" <<EOF
 
176
bootargs=$v_opts $board_opts $DEFAULT_PRESEED $uboot_extra_cmdline $serial_opts
 
177
EOF
 
178
fi
 
179
 
 
180
# Move the ext3 filesystem out of the way
 
181
mv $IMAGE $EXT3
 
182
 
 
183
# mtools sanity checks are getting in the way, so we need to turn its brain off
 
184
cat > $MTOOLSRC <<EOF
 
185
mtools_skip_check=1
 
186
EOF
 
187
 
 
188
export MTOOLSRC
 
189
 
 
190
#define sectors per track and number of heads. These need to be in sync
 
191
#with the partition table altering code in the jasper initramfs script.
 
192
 
 
193
SPT=32
 
194
HEADS=128
 
195
 
 
196
# we leave 72MB for the vfat that carries u-boot, MLO, uImage,
 
197
# uInitrd and boot.scr. The actual partition size is slightly
 
198
# less than 72M as the first track is unused.
 
199
# The root partition starts exactly at 72MB so at a 4MB boundary
 
200
 
 
201
LEAD_IN="$(($SPT * 512))"
 
202
BOOT_SIZE="$((72 * 1024 * 1024 - $SPT * 512))"
 
203
BOOT_SIZE_SECTORS="$(($BOOT_SIZE / 512))"
 
204
ROOT_START_SECTOR=$(($SPT + $BOOT_SIZE_SECTORS))
 
205
IMAGE_SIZE="$(file_length "$EXT3")"
 
206
IMG_SIZE_BLOCKS="$((($LEAD_IN + $BOOT_SIZE + $IMAGE_SIZE + 512 - 1) / 512))"
 
207
 
 
208
dd if=/dev/zero of="$IMAGE" bs=512 count=0 seek="$IMG_SIZE_BLOCKS" >/dev/null 2>&1
 
209
 
 
210
TRG_SIZE="$(file_length "$IMAGE")"
 
211
CYLINDERS="$((($TRG_SIZE/$HEADS/$SPT + 512 -1 )/512))"
 
212
 
 
213
#Use sectors as unit, to better control placement of partitions
 
214
{
 
215
    echo $SPT,$BOOT_SIZE_SECTORS,0x0C,*
 
216
    echo $ROOT_START_SECTOR,,,-
 
217
} | sfdisk -L -D -H $HEADS -S $SPT -C $CYLINDERS -uS --force $IMAGE
 
218
 
 
219
VATSTART=$(parted $IMAGE unit B print|grep "^ 1"|awk '{print $2}')
 
220
VATSIZE=$(LANG=C fdisk -l ${IMAGE} 2>/dev/null|grep W95 |awk '{print $5}')
 
221
 
 
222
mkdosfs -F 32 -C $IMAGE.vfat ${VATSIZE} >/dev/null 2>&1
 
223
mcopy -i $IMAGE.vfat MLO ::MLO
 
224
mcopy -i $IMAGE.vfat u-boot.bin ::u-boot.bin
 
225
mcopy -i $IMAGE.vfat $uboot_kernel ::uImage
 
226
mcopy -i $IMAGE.vfat $uboot_initrd ::uInitrd
 
227
mcopy -i $IMAGE.vfat $uenv_script_text ::uEnv.txt
 
228
mcopy -i $IMAGE.vfat $preenv_script_text ::preEnv.txt
 
229
if [ -e "$preenv_script_text_serial" ]; then
 
230
        mcopy -i $IMAGE.vfat $preenv_script_text_serial ::preEnv.txt-serial
 
231
fi
 
232
 
 
233
# now put the whole vfat into the first partition
 
234
dd conv=notrunc bs="${VATSTART%B}" if=$IMAGE.vfat of="$IMAGE" seek=1 >/dev/null 2>&1
 
235
rm $IMAGE.vfat
 
236
 
 
237
# put ext3 content into the second partition
 
238
EXT3START=$(parted $IMAGE unit B print|grep "^ 2"|awk '{print $2}')
 
239
dd conv=notrunc bs="${EXT3START%B}" if=$IMAGE.rootfs of="$IMAGE" seek=1 >/dev/null 2>&1
 
240
 
 
241
# Cleanup
 
242
rm -f "$IMAGE.rootfs" "$IMAGE.vfat" "$IMAGE.mtoolsrc" MLO u-boot.bin uImage uInitrd
 
243
rm -f "$uboot_script_image" "$uboot_script_image_serial"
 
244
rm -f "$uboot_script_text" "$uboot_script_text_serial"