grub/util/ia64/efi/grub-install.in
Robert Millan 2c40cc7868 Import Tristan Gingold's ia64 port
(based on patch sent to grub-devel by Tristan in 2008-01-28)
2010-01-18 14:17:47 +00:00

233 lines
6.5 KiB
Bash

#! /bin/sh
# Install GRUB on your EFI partition.
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
#
# GRUB 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 3 of the License, or
# (at your option) any later version.
#
# GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
# Initialize some variables.
prefix=@prefix@
exec_prefix=@exec_prefix@
sbindir=@sbindir@
bindir=@bindir@
libdir=@libdir@
datadir=@datadir@
PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
platform=@platform@
pkglibdir=${libdir}/${PACKAGE_TARNAME}/${target_cpu}-${platform}
pkgdatadir=${datadir}/${PACKAGE_TARNAME}
TARGET_CC=@TARGET_CC@
TARGET_CFLAGS="@TARGET_CFLAGS@"
TARGET_CPPFLAGS="@TARGET_CPPFLAGS@"
TARGET_LDFLAGS="@TARGET_LDFLAGS@"
OBJCOPY=@OBJCOPY@
grub_setup=${sbindir}/grub-setup
grub_mkimage=${bindir}/grub-mkimage
grub_mkdevicemap=${sbindir}/grub-mkdevicemap
grub_probefs=${sbindir}/grub-probefs
rootdir=
grub_prefix=/boot/grub
modules=
install_device=
recheck=no
debug=no
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: grub-install [OPTION] install_device
Install GRUB on your drive.
-h, --help print this message and exit
-v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES
--root-directory=DIR install GRUB images under the directory DIR
instead of the root directory
--grub-setup=FILE use FILE as grub-setup
--grub-mkimage=FILE use FILE as grub-mkimage
--grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
--grub-probefs=FILE use FILE as grub-probefs
--no-floppy do not probe any floppy drive
--recheck probe a device map even if it already exists
INSTALL_DEVICE can be a GRUB device name or a system device filename.
grub-install copies GRUB images into the DIR/boot directory specfied by
--root-directory, and uses grub-setup to install grub into the boot
sector.
Report bugs to <bug-grub@gnu.org>.
EOF
}
# Check the arguments.
for option in "$@"; do
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "grub-install (GNU GRUB ${PACKAGE_VERSION})"
exit 0 ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
--grub-setup=*)
grub_setup=`echo "$option" | sed 's/--grub-setup=//'` ;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
--grub-mkdevicemap=*)
grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
--grub-probefs=*)
grub_probefs=`echo "$option" | sed 's/--grub-probefs=//'` ;;
--pkglibdir=*)
pkglibdir=`echo "$option" | sed 's/--pkglibdir=//'` ;;
--pkgdatadir=*)
pkgdatadir=`echo "$option" | sed 's/--pkgdatadir=//'` ;;
--recheck)
recheck=yes ;;
# This is an undocumented feature...
--debug)
debug=yes ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
if test "x$install_device" != x; then
echo "More than one install_devices?" 1>&2
usage
exit 1
fi
install_device="${option}" ;;
esac
done
#if test "x$install_device" = x; then
# echo "install_device not specified." 1>&2
# usage
# exit 1
#fi
# If the debugging feature is enabled, print commands.
if test $debug = yes; then
set -x
fi
# Initialize these directories here, since ROOTDIR was initialized.
bootdir=${rootdir}/boot/efi
grubdir=${bootdir}/grub
device_map=${grubdir}/device.map
# Create the GRUB directory if it is not present.
test -d "$bootdir" || mkdir "$bootdir" || exit 1
test -d "$grubdir" || mkdir "$grubdir" || exit 1
# Copy the GRUB images to the GRUB directory.
if false; then
for file in ${grubdir}/*.mod ${grubdir}/*.lst; do
if test -f $file; then
rm -f $file || exit 1
fi
done
for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
cp -f $file ${grubdir} || exit 1
done
fi
# Create the core image. First, auto-detect the filesystme module.
#fs_module=`$grub_probefs --device-map=${device_map} ${grubdir}`
#if test "x$fs_module" = x -a "x$modules" = x; then
# echo "Auto-detection of a filesystem module failed." 1>&2
# echo "Please specify the module with the option \`--modules' explicitly." 1>&2
# exit 1
#fi
# Typically, _chain and pc are required.
modules="$modules $fs_module _chain"
modules="kernel gzio gpt fat normal ls cat fshelp help _linux linux $modules"
modules="$modules memmap systab boot"
if [ $debug = yes ]; then
tmpdir=.
else
tmpdir=`mktemp -d /tmp/grub.XXXXXXXXXX` || exit 1
trap "rm -rf $tmpdir" 1 2 13 15
fi
# Generate init/fini for modules.
modfile=$tmpdir/mod.c
echo "/* Dummy modules. */" > $modfile
list=""
init_list=""
fini_list=""
for m in $modules; do
file="$pkglibdir/${m}.mod"
name=`nm $file | sed -n "/ r grub_module_name/ s/.* r grub_module_name_\(.*\)/\1/p"`
init=`nm $file | sed -n "/ T grub_module_.*_init/ s/.* T //p"`
fini=`nm $file | sed -n "/ T grub_module_.*_fini/ s/.* T //p"`
init_list="$init_list $init"
fini_list="$fini_list $fini"
arg="\"$name\",${init:-0},${fini:-0}"
list="$list $arg"
done
echo "extern void grub_init_module (const char *, void (*init)(void *), void (*fini)(void));" >> $modfile
echo "extern void grub_init_modules (void);" >> $modfile
for m in $init_list; do
echo "extern void $m(void *);" >> $modfile
done
for m in $fini_list; do
echo "extern void $m(void);" >> $modfile
done
echo "void grub_init_modules (void)" >> $modfile
echo "{" >> $modfile
for m in $list; do
echo " grub_init_module($m);" >> $modfile
done
echo "}" >> $modfile
$TARGET_CC -c $TARGET_CFLAGS -o $tmpdir/mod.o $modfile
mod_objs=
for m in $modules; do mod_objs="$mod_objs $pkglibdir/${m}.mod"; done
ld -pie -nostdlib -T $pkgdatadir/elf_ia64_efi.lds \
$mod_objs $tmpdir/mod.o -o $tmpdir/grub.elf
if ! $bindir/grub-elf2pe $tmpdir/grub.elf $grubdir/grub.efi; then
echo "Failed to build efi binary"
[ $debug = no ] && rm -rf $tmpdir
exit 1
fi
echo "grub.efi generated"
[ $debug = no ] && rm -rf $tmpdir
# Bye.
exit 0