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

« back to all changes in this revision

Viewing changes to tools/boot/yakkety/post-boot-armel+mx5

  • Committer: Adam Conrad
  • Date: 2016-04-22 11:40:33 UTC
  • Revision ID: adconrad@0c3.net-20160422114033-vom9id9ph274tf6b
Copy xenial -> yakkety, and add yakkety 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+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
 
7
#
 
8
# $1 is the CD number
 
9
# $2 is the temporary CD build dir
 
10
# $3 is the image file
 
11
#
 
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>
 
16
#
 
17
 
 
18
. "$BASEDIR/tools/boot/$DI_CODENAME/common.sh"
 
19
 
 
20
# sfdisk is in /sbin
 
21
PATH="$PATH:/sbin"
 
22
 
 
23
set -e
 
24
 
 
25
N="$1"
 
26
CDDIR="$2"
 
27
IMAGE="$3"
 
28
 
 
29
log() {
 
30
    echo "$*" >&2
 
31
}
 
32
 
 
33
die() {
 
34
    log "$@"
 
35
    exit 1
 
36
}
 
37
 
 
38
# Only disk 1* bootable
 
39
if ([ "$N" != 1 ] && [ "$N" != 1_NONUS ]) || [ "$CDIMAGE_ADDON" ]; then
 
40
    exit 0
 
41
fi
 
42
 
 
43
# We only want to do this for vfat images
 
44
if [ "$IMAGE_FORMAT" == "iso" ]; then
 
45
    exit 0
 
46
fi
 
47
 
 
48
cd "$CDDIR/.."
 
49
 
 
50
# this script creates an image to write to a SD card with a PC partition table;
 
51
 
 
52
file_length() {
 
53
    stat -c %s "$1"
 
54
}
 
55
 
 
56
extract_file_from_package() {
 
57
    package=$1
 
58
    file_to_extract=$2
 
59
    output_file_name=$3
 
60
 
 
61
    export UNIVERSE=1
 
62
 
 
63
    deb="$("$BASEDIR/tools/apt-selection" cache show "$package" | sed -n 's/^Filename: //p')"
 
64
    if [ "$deb" = "" ]; then
 
65
        log "Package $package not found!"
 
66
        exit 1
 
67
    fi
 
68
 
 
69
    tmpdir=`mktemp -d`
 
70
    dpkg --fsys-tarfile "$MIRROR/$deb" | tar xf - -C $tmpdir "./$file_to_extract"
 
71
    mv $tmpdir/$file_to_extract ./$output_file_name
 
72
    rm -rf $tmpdir
 
73
}
 
74
 
 
75
uboot_package="u-boot-linaro-mx53loco"
 
76
path_to_uboot="usr/lib/u-boot/mx53loco/u-boot.imx"
 
77
 
 
78
#for now enable serial console for all flavours
 
79
board_opts="console=tty0 console=ttymxc0,115200n8"
 
80
 
 
81
if [ "$PROJECT" = "ubuntu-headless" ] || [ "$PROJECT" = "ubuntu-server" ]; then
 
82
    flavour_opts="debian-installer/framebuffer=false console=ttymxc0,115200n8"
 
83
fi
 
84
 
 
85
log "Extracting bootloader binary from a package"
 
86
extract_file_from_package $uboot_package $path_to_uboot "u-boot.imx"
 
87
 
 
88
uboot_kernel="uImage"
 
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"
 
94
 
 
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)
 
98
FLAVOUR=linaro-lt-mx5
 
99
 
 
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"
 
105
else
 
106
    die "Only preinstalled images supported for the iMX53"
 
107
fi
 
108
 
 
109
EXT3=$IMAGE.rootfs
 
110
MTOOLSRC=$IMAGE.mtoolsrc
 
111
 
 
112
# Turn our kernel and initrd into a uImage and uInitrd
 
113
log "Calling uboot-mkimage on kernel and initrd"
 
114
 
 
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"
 
118
 
 
119
 
 
120
# here we will need to create boot.scr and mcopy it too
 
121
 
 
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
 
128
EOF
 
129
 
 
130
mkimage -A arm -T script -C none -n "Ubuntu boot script" -d "$uboot_script_text" "$uboot_script_image"
 
131
 
 
132
# Move the ext3 filesystem out of the way
 
133
mv $IMAGE $EXT3
 
134
 
 
135
# mtools sanity checks are getting in the way, so we need to turn its brain off
 
136
cat > $MTOOLSRC <<EOF
 
137
mtools_skip_check=1
 
138
EOF
 
139
 
 
140
export MTOOLSRC
 
141
 
 
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.
 
144
 
 
145
SPT=32
 
146
HEADS=128
 
147
 
 
148
# Partition layout:
 
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
 
152
 
 
153
LEAD_IN=512
 
154
 
 
155
RESERVED_START_SECTOR=1
 
156
RESERVED_SIZE=$((4 * 1024 * 1024 - 512))
 
157
RESERVED_SIZE_SECTORS=$((RESERVED_SIZE / 512))
 
158
 
 
159
BOOT_START_SECTOR=$(($RESERVED_START_SECTOR + $RESERVED_SIZE_SECTORS))
 
160
BOOT_SIZE="$((52 * 1024 * 1024))"
 
161
BOOT_SIZE_SECTORS="$(($BOOT_SIZE / 512))"
 
162
 
 
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))"
 
166
 
 
167
#Create zero-filled file of the required size
 
168
 
 
169
dd if=/dev/zero of="$IMAGE" bs=512 count=0 seek="$IMG_SIZE_SECTORS"
 
170
 
 
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.
 
173
 
 
174
dd if=u-boot.imx of="$IMAGE" conv=notrunc,fsync bs=512 seek=2
 
175
 
 
176
TRG_SIZE="$(file_length "$IMAGE")"
 
177
CYLINDERS="$((($TRG_SIZE/$HEADS/$SPT + 512 -1 )/512))"
 
178
 
 
179
#Use sectors as unit, to better control placement of partitions
 
180
{
 
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
 
185
 
 
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}')
 
188
 
 
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
 
194
 
 
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
 
200
 
 
201
# Cleanup
 
202
rm -f "$IMAGE.rootfs" "$IMAGE.vfat" "$IMAGE.mtoolsrc" u-boot.imx uImage uInitrd