summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Hart <dvhart@linux.intel.com>2012-07-30 23:18:44 (GMT)
committerDarren Hart <dvhart@linux.intel.com>2012-07-30 23:24:01 (GMT)
commitc10b3557ee6c9d48be93791b1481fe7c14d990bb (patch)
tree1dab9c0ff7237682ce9f21d2b089c82dc4eaa96d
parent46b58ca46f9c9d29831a600a8ce3dcffaef2a654 (diff)
downloadmeta-intel-c10b3557ee6c9d48be93791b1481fe7c14d990bb.tar.gz
fri2: Add mkefidisk.sh script
As the denzil release of the Yocto Project does not yet have a functional EFI installer, provide a script (mkefidisk.sh) to install a live image to a device which can then be booted on the target. The script requires root privileges. See the usage statement for details. Signed-off-by: Darren Hart <dvhart@linux.intel.com>
-rwxr-xr-xmeta-fri2/scripts/mkefidisk.sh252
1 files changed, 252 insertions, 0 deletions
diff --git a/meta-fri2/scripts/mkefidisk.sh b/meta-fri2/scripts/mkefidisk.sh
new file mode 100755
index 0000000..233cf2e
--- /dev/null
+++ b/meta-fri2/scripts/mkefidisk.sh
@@ -0,0 +1,252 @@
1#!/bin/sh
2#
3# Copyright (c) 2012, Intel Corporation.
4# All rights reserved.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14# the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19#
20
21#
22# Defaults
23#
24# 20 Mb for the boot partition
25BOOT_SIZE=20
26# 5% for swap
27SWAP_RATIO=5
28
29function usage() {
30 echo "Usage: $(basename $0) DEVICE HDDIMG TARGET_DEVICE"
31}
32
33function image_details() {
34 IMG=$1
35 echo "Image details"
36 echo "============="
37 echo " image: $(stat --printf '%N\n' $IMG)"
38 echo " size: $(stat -L --printf '%s bytes\n' $IMG)"
39 echo " modified: $(stat -L --printf '%y\n' $IMG)"
40 echo " type: $(file -L -b $IMG)"
41 echo ""
42}
43
44function device_details() {
45 DEV=$1
46 BLOCK_SIZE=512
47
48 echo "Device details"
49 echo "=============="
50 echo " device: $DEVICE"
51 if [ -f "/sys/class/block/$DEV/device/vendor" ]; then
52 echo " vendor: $(cat /sys/class/block/$DEV/device/vendor)"
53 else
54 echo " vendor: UNKOWN"
55 fi
56 if [ -f "/sys/class/block/$DEV/device/model" ]; then
57 echo " model: $(cat /sys/class/block/$DEV/device/model)"
58 else
59 echo " model: UNKNOWN"
60 fi
61 if [ -f "/sys/class/block/$DEV/size" ]; then
62 echo " size: $[$(cat /sys/class/block/$DEV/size)*BLOCK_SIZE] bytes"
63 else
64 echo " size: UNKNOWN"
65 fi
66 echo ""
67}
68
69
70#
71# Parse and validate arguments
72#
73if [ $# -ne 3 ]; then
74 usage
75 exit 1
76fi
77
78DEVICE=$1
79HDDIMG=$2
80TARGET_DEVICE=$3
81
82if [ ! -w "$DEVICE" ]; then
83 echo "ERROR: Device $DEVICE does not exist or is not writable"
84 usage
85 exit 1
86fi
87
88if [ ! -e "$HDDIMG" ]; then
89 echo "ERROR: HDDIMG $HDDIMG does not exist"
90 usage
91 exit 1
92fi
93
94
95#
96# Check if any $DEVICE partitions are mounted
97#
98grep -q $DEVICE /proc/mounts
99if [ $? -eq 0 ]; then
100 echo "ERROR: $DEVICE partitions mounted:"
101 grep $DEVICE /proc/mounts | cut -f 1 -d " "
102 echo "Unmount the partitions listed and try again."
103 exit 1
104fi
105
106
107#
108# Confirm device with user
109#
110image_details $HDDIMG
111device_details $(basename $DEVICE)
112echo -n "Prepare EFI image on $DEVICE [y/N]? "
113read RESPONSE
114if [ "$RESPONSE" != "y" ]; then
115 echo "Image creation aborted"
116 exit 0
117fi
118
119
120#
121# Partition $DEVICE
122#
123DEVICE_SIZE=$(parted $DEVICE unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//")
124SWAP_SIZE=$((DEVICE_SIZE*SWAP_RATIO/100))
125ROOTFS_SIZE=$((DEVICE_SIZE-BOOT_SIZE-SWAP_SIZE))
126ROOTFS_START=$((BOOT_SIZE))
127ROOTFS_END=$((ROOTFS_START+ROOTFS_SIZE))
128SWAP_START=$((ROOTFS_END))
129
130# MMC devices are special in a couple of ways
131# 1) they use a partition prefix character 'p'
132# 2) they are detected asynchronously (need ROOTWAIT)
133PART_PREFIX=""
134if [ ! "${DEVICE#/dev/mmcblk}" = "${DEVICE}" ]; then
135 PART_PREFIX="p"
136fi
137BOOTFS=$DEVICE${PART_PREFIX}1
138ROOTFS=$DEVICE${PART_PREFIX}2
139SWAP=$DEVICE${PART_PREFIX}3
140
141ROOTWAIT=""
142TARGET_PART_PREFIX=""
143if [ ! "${TARGET_DEVICE#/dev/mmcblk}" = "${TARGET_DEVICE}" ]; then
144 TARGET_PART_PREFIX="p"
145 ROOTWAIT="rootwait"
146fi
147TARGET_ROOTFS=$TARGET_DEVICE${TARGET_PART_PREFIX}2
148TARGET_SWAP=$TARGET_DEVICE${TARGET_PART_PREFIX}3
149
150echo "*****************"
151echo "Boot partition size: $BOOT_SIZE MB ($BOOTFS)"
152echo "ROOTFS partition size: $ROOTFS_SIZE MB ($ROOTFS)"
153echo "Swap partition size: $SWAP_SIZE MB ($SWAP)"
154echo "*****************"
155echo "Deleting partition table on $DEVICE ..."
156dd if=/dev/zero of=$DEVICE bs=512 count=2
157
158echo "Creating new partition table (GPT) on $DEVICE ..."
159parted $DEVICE mklabel gpt
160
161echo "Creating boot partition on $BOOTFS"
162parted $DEVICE mkpart primary 0% $BOOT_SIZE
163
164echo "Creating ROOTFS partition on $ROOTFS"
165parted $DEVICE mkpart primary $ROOTFS_START $ROOTFS_END
166
167echo "Creating swap partition on $SWAP"
168parted $DEVICE mkpart primary $SWAP_START 100%
169
170parted $DEVICE print
171
172
173#
174# Format $DEVICE partitions
175#
176echo ""
177echo "Formatting $BOOTFS as vfat..."
178mkfs.vfat $BOOTFS
179
180echo "Formatting $ROOTFS as ext3..."
181mkfs.ext3 $ROOTFS
182
183echo "Formatting swap partition...($SWAP)"
184mkswap $SWAP
185
186
187#
188# Installing to $DEVICE
189#
190echo ""
191echo "Mounting images and device in preparation for installation..."
192TMPDIR=$(mktemp -d mkefidisk-XXX)
193if [ $? -ne 0 ]; then
194 echo "ERROR: Failed to create temporary mounting directory."
195 exit 1
196fi
197HDDIMG_MNT=$TMPDIR/hddimg
198HDDIMG_ROOTFS_MNT=$TMPDIR/hddimg_rootfs
199ROOTFS_MNT=$TMPDIR/rootfs
200BOOTFS_MNT=$TMPDIR/bootfs
201mkdir $HDDIMG_MNT
202mkdir $HDDIMG_ROOTFS_MNT
203mkdir $ROOTFS_MNT
204mkdir $BOOTFS_MNT
205
206mount -o loop $HDDIMG $HDDIMG_MNT
207mount -o loop $HDDIMG_MNT/rootfs.img $HDDIMG_ROOTFS_MNT
208mount $ROOTFS $ROOTFS_MNT
209mount $BOOTFS $BOOTFS_MNT
210
211echo "Copying ROOTFS files..."
212cp -a $HDDIMG_ROOTFS_MNT/* $ROOTFS_MNT
213
214echo "$TARGET_SWAP swap swap defaults 0 0" >> $ROOTFS_MNT/etc/fstab
215
216# We dont want udev to mount our root device while we're booting...
217if [ -d $ROOTFS_MNT/etc/udev/ ] ; then
218 echo "$TARGET_DEVICE" >> $ROOTFS_MNT/etc/udev/mount.blacklist
219fi
220
221umount $ROOTFS_MNT
222umount $HDDIMG_ROOTFS_MNT
223
224echo "Preparing boot partition..."
225EFIDIR="$BOOTFS_MNT/EFI/BOOT"
226mkdir -p $EFIDIR
227GRUBCFG="$EFIDIR/grub.cfg"
228
229cp $HDDIMG_MNT/vmlinuz $BOOTFS_MNT
230# Copy the efi loader and config (booti*.efi and grub.cfg)
231cp $HDDIMG_MNT/EFI/BOOT/* $EFIDIR
232
233# Update grub config for the installed image
234# Delete the install entry
235sed -i "/menuentry 'install'/,/^}/d" $GRUBCFG
236# Delete the initrd lines
237sed -i "/initrd /d" $GRUBCFG
238# Delete any LABEL= strings
239sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG
240# Replace the ramdisk root with the install device and include other options
241sed -i "s@ root=[^ ]*@ root=$TARGET_ROOTFS rw $ROOTWAIT quiet@" $GRUBCFG
242
243# Provide a startup.nsh script for older firmware with non-standard boot
244# directories and paths.
245echo "bootia32.efi" > $BOOTFS_MNT/startup.nsh
246
247umount $BOOTFS_MNT
248umount $HDDIMG_MNT
249rm -rf $TMPDIR
250sync
251
252echo "Installation complete."