3
# Do post-image-building tasks for arm+mx5, 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 iMX53 QuickStart boards
9
# $2 is the temporary CD build dir
10
# $3 is the image file
12
# Copyright (c) 2009,2011 Canonical
13
# Authors: Oliver Grawert <ogra@canonical.com>
14
# Loïc Minier <loic.minier@canonical.com>
15
# Jani Monoses <jani.monoses@canonical.com>
18
. "$BASEDIR/tools/boot/$DI_CODENAME/common.sh"
38
# Only disk 1* bootable
39
if ([ "$N" != 1 ] && [ "$N" != 1_NONUS ]) || [ "$CDIMAGE_ADDON" ]; then
43
# We only want to do this for vfat images
44
if [ "$IMAGE_FORMAT" == "iso" ]; then
50
# this script creates an image to write to a SD card with a PC partition table;
56
extract_file_from_package() {
63
deb="$("$BASEDIR/tools/apt-selection" cache show "$package" | sed -n 's/^Filename: //p')"
64
if [ "$deb" = "" ]; then
65
log "Package $package not found!"
70
dpkg --fsys-tarfile "$MIRROR/$deb" | tar xf - -C $tmpdir "./$file_to_extract"
71
mv $tmpdir/$file_to_extract ./$output_file_name
75
uboot_package="u-boot-linaro-mx53loco"
76
path_to_uboot="usr/lib/u-boot/mx53loco/u-boot.imx"
78
#for now enable serial console for all flavours
79
board_opts="console=tty0 console=ttymxc0,115200n8"
81
if [ "$PROJECT" = "ubuntu-headless" ] || [ "$PROJECT" = "ubuntu-server" ]; then
82
flavour_opts="debian-installer/framebuffer=false console=ttymxc0,115200n8"
85
log "Extracting bootloader binary from a package"
86
extract_file_from_package $uboot_package $path_to_uboot "u-boot.imx"
89
uboot_initrd="uInitrd"
90
uboot_kernel_addr="0x70000000"
91
uboot_initrd_addr="0x72000000"
92
uboot_script_text="$CDDIR/boot.txt"
93
uboot_script_image="$CDDIR/boot.scr"
95
# FIXME due to the fact that our kernel doesnt use the actual subarch name
96
# we need to hardcode the flavour name here (find-live-filesystem has the
97
# other half of this hack)
100
if [ "$CDIMAGE_PREINSTALLED" = 1 ]; then
101
uboot_input_kernel="$LIVEIMAGES/$FULLARCH.kernel-$FLAVOUR"
102
uboot_input_initrd="$LIVEIMAGES/$FULLARCH.initrd-$FLAVOUR"
103
#uboot_extra_cmdline=" root=/dev/mmcblk0p3 quiet splash"
104
uboot_extra_cmdline=" root=/dev/mmcblk0p3"
106
die "Only preinstalled images supported for the iMX53"
110
MTOOLSRC=$IMAGE.mtoolsrc
112
# Turn our kernel and initrd into a uImage and uInitrd
113
log "Calling uboot-mkimage on kernel and initrd"
115
rm -f $uboot_kernel $uboot_initrd
116
mkimage -A arm -O linux -T kernel -C none -a 0x70008000 -e 0x70008000 -n "Ubuntu Kernel" -d "$uboot_input_kernel" "$uboot_kernel"
117
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x0 -e 0x0 -n "Ubuntu Initrd" -d "$uboot_input_initrd" "$uboot_initrd"
120
# here we will need to create boot.scr and mcopy it too
122
log "Generating boot.scr"
123
cat >"$uboot_script_text" <<EOF
124
fatload mmc 0:2 $uboot_kernel_addr $uboot_kernel
125
fatload mmc 0:2 $uboot_initrd_addr $uboot_initrd
126
setenv bootargs $board_opts $DEFAULT_PRESEED $uboot_extra_cmdline $flavour_opts
127
bootm $uboot_kernel_addr $uboot_initrd_addr
130
mkimage -A arm -T script -C none -n "Ubuntu boot script" -d "$uboot_script_text" "$uboot_script_image"
132
# Move the ext3 filesystem out of the way
135
# mtools sanity checks are getting in the way, so we need to turn its brain off
136
cat > $MTOOLSRC <<EOF
142
#define sectors per track and number of heads. These need to be in sync
143
#with the partition table altering code in the jasper initramfs script.
149
# - 4 MiB of non-filesystem area where the uboot binary resides.
150
# - a 52 MiB VFAT partition holding the kernel and initrd which are read by u-boot
151
# - the EXT3 formatted root partition
155
RESERVED_START_SECTOR=1
156
RESERVED_SIZE=$((4 * 1024 * 1024 - 512))
157
RESERVED_SIZE_SECTORS=$((RESERVED_SIZE / 512))
159
BOOT_START_SECTOR=$(($RESERVED_START_SECTOR + $RESERVED_SIZE_SECTORS))
160
BOOT_SIZE="$((52 * 1024 * 1024))"
161
BOOT_SIZE_SECTORS="$(($BOOT_SIZE / 512))"
163
ROOT_START_SECTOR=$(($BOOT_START_SECTOR + $BOOT_SIZE_SECTORS))
164
IMAGE_SIZE="$(file_length "$EXT3")"
165
IMG_SIZE_SECTORS="$((($LEAD_IN + $RESERVED_SIZE + $BOOT_SIZE + $IMAGE_SIZE + 512 - 1) / 512))"
167
#Create zero-filled file of the required size
169
dd if=/dev/zero of="$IMAGE" bs=512 count=0 seek="$IMG_SIZE_SECTORS"
171
# The ROM loader expects the bootloader binary to be at address 0x400 on the media,
172
# which corresponds to sector 2 for the default sector size of 512.
174
dd if=u-boot.imx of="$IMAGE" conv=notrunc,fsync bs=512 seek=2
176
TRG_SIZE="$(file_length "$IMAGE")"
177
CYLINDERS="$((($TRG_SIZE/$HEADS/$SPT + 512 -1 )/512))"
179
#Use sectors as unit, to better control placement of partitions
181
echo 1,$RESERVED_SIZE_SECTORS,0xDA,-
182
echo $BOOT_START_SECTOR,$BOOT_SIZE_SECTORS,0x0C,-
183
echo $ROOT_START_SECTOR,,,-
184
} | sfdisk -L -H $HEADS -S $SPT -C $CYLINDERS -uS --force $IMAGE
186
VATSTART=$(parted $IMAGE unit B print|grep "^ 2"|awk '{print $2}')
187
VATSIZE=$(LANG=C sfdisk -l ${IMAGE} 2>/dev/null|grep W95 |awk '{print $5}')
189
mkdosfs -F 32 -C $IMAGE.vfat ${VATSIZE}
190
mcopy -i $IMAGE.vfat $uboot_kernel ::uImage
191
mcopy -i $IMAGE.vfat $uboot_initrd ::uInitrd
192
mcopy -i $IMAGE.vfat $uboot_script_image ::boot.scr
193
mcopy -i $IMAGE.vfat $uboot_script_text ::boot.txt
195
# now put the whole vfat into the first partition
196
dd conv=notrunc bs="${VATSTART%B}" if=$IMAGE.vfat of="$IMAGE" seek=1
197
# put ext3 content into the second partition
198
EXT3START=$(parted $IMAGE unit B print|grep "^ 3"|awk '{print $2}')
199
dd conv=notrunc bs="${EXT3START%B}" if=$IMAGE.rootfs of="$IMAGE" seek=1
202
rm -f "$IMAGE.rootfs" "$IMAGE.vfat" "$IMAGE.mtoolsrc" u-boot.imx uImage uInitrd