fi
case "${target_cpu}-${platform}" in
- i386-pc) mkimage_target=i386-pc ;;
sparc64-ieee1275) mkimage_target=sparc64-ieee1275-raw ;;
mips-yeeloong) mkimage_target=mipsel-yeeloong-elf ;;
- *) mkimage_target=i386-coreboot;
+ *) mkimage_target="${target_cpu}-${platform}" ;;
esac
-if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
- $grub_mkimage ${config_opt} -O ${mkimage_target} --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
+case "${target_cpu}-${platform}" in
+ i386-efi | x86_64-efi) imgext=efi ;;
+ mips-yeeloong | i386-coreboot | i386-multiboot | i386-ieee1275 \
+ | powerpc-ieee1275) imgext=elf ;;
+ *) imgext=img ;;
+esac
+
+
+$grub_mkimage ${config_opt} -O ${mkimage_target} --output=${grubdir}/core.${imgext} --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
+
+# Backward-compatibility kludges
+if [ "${target_cpu}-${platform}" = "mips-yeeloong" ]; then
+ cp ${grubdir}/core.${imgext} /boot/grub.elf
+elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ]; then
+ cp ${grubdir}/core.${imgext} /boot/grub/grub
+elif [ "${target_cpu}-${platform}" = "i386-efi" ] || [ "${target_cpu}-${platform}" = "x86_64-efi" ]; then
+ $grub_mkimage ${config_opt} -O ${mkimage_target} --output=${grubdir}/grub.efi --prefix="" $modules || exit 1
+fi
- # Verify readability of a few critical files
- for file in grubenv normal.mod core.${imgext} ; do
- if is_path_readable_by_grub ${grubdir}/${file} ${grub_device} ${relative_grubdir}/${file} ; then : ; else
- echo "GRUB is unable to read ${grubdir}/${file}" >&2
- exit 1
- fi
- done
+
+# Perform the platform-dependent install
+if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
# Now perform the installation.
- $grub_setup ${setup_verbose} ${setup_force} --directory=${grubdir} --device-map=${device_map} \
- ${install_device} || exit 1
-elif [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
- $grub_mkimage ${config_opt} -d ${pkglibdir} -O ${mkimage_target} --output=/boot/grub.elf --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
-else
- $grub_mkimage -O ${mkimage_target} ${config_opt} -d ${pkglibdir} --output=/boot/multiboot.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
+ $grub_setup ${setup_verbose} ${setup_force} --directory=${grubdir} \
+ --device-map=${device_map} ${install_device} || exit 1
+elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ]; then
+ if [ x"$update_nvram" = xyes ]; then
+ set $ofpathname dummy
+ if test -f "$1"; then
+ :
+ else
+ echo "$1: Not found." 1>&2
+ exit 1
+ fi
+ set $nvsetenv dummy
+ if test -f "$1"; then
+ :
+ else
+ echo "$1: Not found." 1>&2
+ exit 1
+ fi
+ # Get the Open Firmware device tree path translation.
+ dev=`echo $grub_device | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`
+ partno=`echo $grub_device | sed -e 's/.*[^0-9]\([0-9]\+\)$/\1/'`
+ ofpath=`$ofpathname $dev` || {
+ echo "Couldn't find Open Firmware device tree path for $dev."
+ echo "You will have to set boot-device manually."
+ exit 1
+ }
+
+ # Point boot-device at the new grub install
+ boot_device="$ofpath:$partno,"`grub-mkrelpath ${grubdir}/core.${imgext} | sed 's,/,\\\\,g'`
+ "$nvsetenv" boot-device "$boot_device" || {
+ echo "$nvsetenv failed."
+ echo "You will have to set boot-device manually. At the Open Firmware prompt, type:"
+ echo " setenv boot-device $boot_device"
+ exit 1
+ }
+ fi
+elif [ x"$platform" = xefi ]; then
+ cp ${grubdir}/core.${imgext} ${efidir}/${efi_file}
+
+ # Try to make this image bootable using the EFI Boot Manager, if available.
+ if test "$removable" = no && test -n "$efi_distributor" && \
+ test -n "$efibootmgr"; then
+ # On Linux, we need the efivars kernel modules.
+ case "$host_os" in
+ linux*)
+ modprobe -q efivars 2>/dev/null || true ;;
+ esac
+
+ # Delete old entries from the same distributor.
+ for bootnum in `efibootmgr | grep '^Boot[0-9]' | \
+ fgrep -i " $efi_distributor" | cut -b5-8`; do
+ efibootmgr $efi_quiet -b "$bootnum" -B
+ done
+
+ # Add a new entry for the image we just created. efibootmgr needs to be
+ # given the disk device and partition number separately, so we have to
+ # fiddle about with grub-probe to get hold of this reasonably reliably.
+ # Use fresh device map text to avoid any problems with stale data, since
+ # all we need here is a one-to-one mapping.
+ clean_devmap="$($grub_mkdevicemap --device-map=/dev/stdout)"
+ efidir_drive="$(echo "$clean_devmap" | $grub_probe --target=drive --device-map=/dev/stdin "$efidir")"
+ if test -z "$efidir_drive"; then
+ echo "Can't find GRUB drive for $efidir; unable to create EFI Boot Manager entry." >&2
+ else
+ efidir_disk="$(echo "$clean_devmap" | grep "^$(echo "$efidir_drive" | sed 's/,[^)]*//')" | cut -f2)"
+ efidir_part="$(echo "$efidir_drive" | sed 's/^([^,]*,[^0-9]*//; s/[^0-9].*//')"
+ efibootmgr $efi_quiet -c -d "$efidir_disk" -p "$efidir_part" -w \
+ -L "$GRUB_DISTRIBUTOR" -l "\\EFI\\$efi_distributor\\$efi_file"
+ fi
+ fi
fi
echo "Installation finished. No error reported."