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
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" == "iso" ]; 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
# 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
61
# globals (please adjust or autodetect or whatever (based on SUBARCH))
62
# note thses paths point to manually unpacked .debs on my disk atm
68
extract_file_from_package() {
73
deb="$("$BASEDIR/tools/apt-selection" cache show "$package" | sed -n 's/^Filename: //p')"
74
if [ "$deb" = "" ]; then
75
log "Package $package not found!"
80
dpkg --fsys-tarfile "$MIRROR/$deb" | tar xf - -C $tmpdir "./$file_to_extract"
81
mv $tmpdir/$file_to_extract ./$output_file_name
85
# This is common across all configurations
86
if [ "${FULLARCH##*+}" = "omap" ]; then
87
path_to_xloader="usr/lib/u-boot/omap3_beagle/MLO"
89
uboot_package="u-boot-linaro-omap3-beagle"
90
path_to_uboot="usr/lib/u-boot/omap3_beagle/u-boot.bin"
92
xloader_package=$uboot_package
96
elif [ "${FULLARCH##*+}" = "omap4" ]; then
97
path_to_xloader="usr/lib/u-boot/omap4_panda/MLO"
99
uboot_package="u-boot-linaro-omap4-panda"
100
path_to_uboot="usr/lib/u-boot/omap4_panda/u-boot.bin"
102
xloader_package=$uboot_package
107
die "Unknown OMAP subarch"
110
if [ "$PROJECT" = "ubuntu-headless" ] || [ "$PROJECT" = "ubuntu-server" ]; then
111
serial_opts="debian-installer/framebuffer=false console=ttyO2,115200n8"
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"
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"
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"
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"
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"
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"
153
MTOOLSRC=$IMAGE.mtoolsrc
155
# Turn our kernel and initrd into a uImage and uInitrd
156
log "Calling uboot-mkimage on kernel and ramdisk"
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"
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
168
log "Creating default preEnv.txt"
169
cat >"$preenv_script_text" <<EOF
170
bootargs=$v_opts $board_opts $DEFAULT_PRESEED $uboot_extra_cmdline
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
180
# Move the ext3 filesystem out of the way
183
# mtools sanity checks are getting in the way, so we need to turn its brain off
184
cat > $MTOOLSRC <<EOF
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.
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
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))"
208
dd if=/dev/zero of="$IMAGE" bs=512 count=0 seek="$IMG_SIZE_BLOCKS" >/dev/null 2>&1
210
TRG_SIZE="$(file_length "$IMAGE")"
211
CYLINDERS="$((($TRG_SIZE/$HEADS/$SPT + 512 -1 )/512))"
213
#Use sectors as unit, to better control placement of partitions
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
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}')
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
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
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
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"