diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build/efi-image | 85 | ||||
-rwxr-xr-x | scripts/build/grub-cpmodules | 55 |
2 files changed, 140 insertions, 0 deletions
diff --git a/scripts/build/efi-image b/scripts/build/efi-image new file mode 100755 index 000000000..724095f5c --- /dev/null +++ b/scripts/build/efi-image @@ -0,0 +1,85 @@ +#! /bin/sh +set -e + +# Copyright (C) 2010, 2011 Canonical Ltd. +# Author: Colin Watson <cjwatson@ubuntu.com> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + +# Make an EFI boot image. + +if [ -z "$1" ] || [ -z "$2" ]; then + echo "usage: $0 OUTPUT-DIRECTORY GRUB-PLATFORM EFI-NAME NETBOOT-PREFIX" + exit 1 +fi + +outdir="$1" +platform="$2" +efi_name="$3" +netboot_prefix="$4" + +memdisk_img= +workdir= + +cleanup () { + [ -z "$memdisk_img" ] || rm -f "$memdisk_img" + [ -z "$workdir" ] || rm -rf "$workdir" +} +trap cleanup EXIT HUP INT QUIT TERM + +rm -rf "$outdir" +mkdir -p "$outdir" + +memdisk_img="$(mktemp efi-image.XXXXXX)" +workdir="$(mktemp -d efi-image.XXXXXX)" + +# Skeleton configuration file which finds the real boot disk. +mkdir -p "$workdir/boot/grub" +cat >"$workdir/boot/grub/grub.cfg" <<EOF +search --file --set=root /.disk/info +set prefix=(\$root)/boot/grub +source \$prefix/$platform/grub.cfg +EOF + +mkdir -p "$outdir/boot/grub/$platform" +(for i in /usr/lib/grub/$platform/part_*.mod; do + i=`echo $i | sed 's?^.*/??g;s?\.mod$??g;'` + echo "insmod $i" + done; \ + echo "source /boot/grub/grub.cfg") >"$outdir/boot/grub/$platform/grub.cfg" + +# Build the core image. +(cd "$workdir"; tar -cf - boot) >"$memdisk_img" +grub-mkimage -O "$platform" -m "$memdisk_img" \ + -o "$workdir/boot$efi_name.efi" -p '(memdisk)/boot/grub' \ + search iso9660 configfile normal memdisk tar part_msdos part_gpt fat + +grub-mkimage -O "$platform" \ + -o "$outdir/bootnet$efi_name.efi" -p "$netboot_prefix/grub" \ + search configfile normal efinet tftp net + +# Stuff it into a FAT filesystem, making it as small as possible. 24KiB +# headroom seems to be enough; (x+31)/32*32 rounds up to multiple of 32. +mkfs.msdos -C "$outdir/efi.img" \ + $(( ($(stat -c %s "$workdir/boot$efi_name.efi") / 1024 + 55) \ + / 32 * 32 )) +mmd -i "$outdir/efi.img" ::efi +mmd -i "$outdir/efi.img" ::efi/boot +mcopy -i "$outdir/efi.img" "$workdir/boot$efi_name.efi" \ + "::efi/boot/boot$efi_name.efi" + +grub-cpmodules "$outdir" "$platform" + +exit 0 diff --git a/scripts/build/grub-cpmodules b/scripts/build/grub-cpmodules new file mode 100755 index 000000000..437ebdf2b --- /dev/null +++ b/scripts/build/grub-cpmodules @@ -0,0 +1,55 @@ +#! /bin/sh +set -e + +# Copyright (C) 2010, 2011 Canonical Ltd. +# Author: Colin Watson <cjwatson@ubuntu.com> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + +# Copy GRUB modules. + +# TODO: take the modules list as parameter, and only include the needed modules, using moddeps.lst to get dependencies + +if [ -z "$1" ] || [ -z "$2" ]; then + echo "usage: $0 OUTPUT-DIRECTORY GRUB-PLATFORM" + exit 1 +fi + +outdir="$1" +platform="$2" + +# Copy over GRUB modules, except for those already built in. +cp -a "/usr/lib/grub/$platform"/*.lst "$outdir/boot/grub/$platform/" +for x in "/usr/lib/grub/$platform"/*.mod; do + # TODO: Some of these exclusions are based on knowledge of module + # dependencies. It would be nice to have a way to read the module + # list directly out of the image. + case $(basename "$x" .mod) in + configfile|fshelp|iso9660|memdisk|search|search_fs_file|search_fs_uuid|search_label|tar) + # included in boot image + ;; + affs|afs|afs_be|befs|befs_be|minix|nilfs2|sfs|zfs|zfsinfo) + # unnecessary filesystem modules + ;; + example_functional_test|functional_test|hello) + # other cruft + ;; + *) + cp -a "$x" "$outdir/boot/grub/$platform/" + ;; + esac +done + +exit 0 |