merge mainline and various cleanups

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-05-17 14:02:18 +02:00
commit 3666d5f636
380 changed files with 14873 additions and 1961 deletions

View file

@ -111,7 +111,8 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
file = grub_file_open (pathname);
if (!file)
{
grub_util_error (_("cannot open file %s"), pathname);
grub_util_error (_("cannot open file %s:%s"), pathname,
grub_errmsg);
return;
}
@ -221,6 +222,14 @@ cmd_cmp (char *src, char *dest)
grub_util_error (_("seek error"));
read_file (src, cmp_hook);
{
grub_uint64_t pre;
pre = ftell (ff);
fseek (ff, 0, SEEK_END);
if (pre != ftell (ff))
grub_util_error (_("unexpected end of file"));
}
fclose (ff);
}

View file

@ -64,7 +64,7 @@ if test -f "${sysconfdir}/default/grub" ; then
. "${sysconfdir}/default/grub"
fi
bootloader_id="$(echo "$GRUB_DISTRIBUTOR" | tr '[A-Z]' '[a-z]' | cut -d' ' -f1)"
bootloader_id="$(echo "$GRUB_DISTRIBUTOR" | tr 'A-Z' 'a-z' | cut -d' ' -f1)"
if test -z "$bootloader_id"; then
bootloader_id=grub
fi
@ -270,6 +270,11 @@ if test "x$install_device" = x && ([ "${target_cpu}-${platform}" = "i386-pc" ] \
exit 1
fi
if ! ([ "${target_cpu}-${platform}" = "i386-pc" ] \
|| [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ]); then
install_device=
fi
# If the debugging feature is enabled, print commands.
setup_verbose=
if test x"$debug" = xyes; then
@ -362,7 +367,7 @@ if [ x"$platform" = xefi ]; then
case "$target_cpu" in
i386)
efi_file=BOOTIA32.EFI ;;
x86-64)
x86_64)
efi_file=BOOTX64.EFI ;;
# GRUB does not yet support these architectures, but they're defined
# by the specification so we include them here to ease future
@ -376,7 +381,7 @@ if [ x"$platform" = xefi ]; then
case "$target_cpu" in
i386)
efi_file=grubia32.efi ;;
x86-64)
x86_64)
efi_file=grubx64.efi ;;
# GRUB does not yet support these architectures, but they're defined
# by the specification so we include them here to ease future
@ -462,7 +467,8 @@ fi
fs_module="`"$grub_probe" --device-map="${device_map}" --target=fs --device "${grub_device}"`"
if test "x$fs_module" = x ; then
echo "Auto-detection of a filesystem of ${grub_device} failed." 1>&2
echo "Please report this together with the output of \"$grub_probe --device-map=\"${device_map}\" --target=fs -v ${grubdir}\" to <bug-grub@gnu.org>" 1>&2
echo "Try with --recheck." 1>&2
echo "If the problem persists please report this together with the output of \"$grub_probe --device-map=\"${device_map}\" --target=fs -v ${grubdir}\" to <bug-grub@gnu.org>" 1>&2
exit 1
fi
@ -516,27 +522,24 @@ if [ "x${devabstraction_module}" = "x" ] ; then
# Strip partition number
grub_partition="`echo "${grub_drive}" | sed -e 's/^[^,]*[,)]//; s/)$//'`"
grub_drive="`echo "${grub_drive}" | sed -e s/,[a-z0-9,]*//g`"
if [ "$disk_module" = ata ] ; then
if [ "$disk_module" = ata ] || [ "x${grub_drive}" != "x${install_drive}" ] || ([ "x$platform" != xefi ] && [ "x$platform" != xpc ] && [ x"${target_cpu}-${platform}" != x"sparc64-ieee1275" ]) ; then
# generic method (used on coreboot and ata mod)
uuid="`"$grub_probe" --device-map="${device_map}" --target=fs_uuid --device "${grub_device}"`"
if [ "x${uuid}" = "x" ] ; then
echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
if [ "x$platform" != xefi ] && [ "x$platform" != xpc ] && [ x"${target_cpu}-${platform}" != x"sparc64-ieee1275" ]; then
echo "UUID needed with $platform, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
elif [ "$disk_module" = ata ]; then
echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
else
echo "UUID needed with cross-disk installs, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
fi
exit 1
fi
echo "search.fs_uuid ${uuid} root " >> "${grubdir}/load.cfg"
echo 'set prefix=($root)'"${relative_grubdir}" >> "${grubdir}/load.cfg"
config_opt="-c ${grubdir}/load.cfg "
modules="$modules search_fs_uuid"
elif [ "x${grub_drive}" != "x${install_drive}" ] ; then
uuid="`"$grub_probe" --device-map="${device_map}" --target=fs_uuid --device "${grub_device}"`"
if [ "x${uuid}" = "x" ] ; then
echo "You attempted a cross-disk install, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
exit 1
fi
echo "search.fs_uuid ${uuid} root " >> ${grubdir}/load.cfg
echo 'set prefix=($root)'"${relative_grubdir}" >> ${grubdir}/load.cfg
config_opt="-c ${grubdir}/load.cfg "
modules="$modules search_fs_uuid"
elif [ "x$platform" = xefi ] || [ "x$platform" = xpc ]; then
# we need to hardcode the partition number in the core image's prefix.
if [ x"$grub_partition" = x ]; then
@ -551,13 +554,13 @@ fi
case "${target_cpu}-${platform}" in
sparc64-ieee1275) mkimage_target=sparc64-ieee1275-raw ;;
mips-yeeloong) mkimage_target=mipsel-yeeloong-elf ;;
mips-loongson) mkimage_target=mipsel-loongson-elf ;;
*) mkimage_target="${target_cpu}-${platform}" ;;
esac
case "${target_cpu}-${platform}" in
i386-efi | x86_64-efi) imgext=efi ;;
mips-yeeloong | i386-coreboot | i386-multiboot | i386-ieee1275 \
mips-loongson | i386-coreboot | i386-multiboot | i386-ieee1275 \
| powerpc-ieee1275) imgext=elf ;;
*) imgext=img ;;
esac
@ -566,7 +569,7 @@ esac
"$grub_mkimage" ${config_opt} -d "${pkglibdir}" -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
if [ "${target_cpu}-${platform}" = "mips-loongson" ]; then
cp "${grubdir}/core.${imgext}" "${bootdir}"/grub.elf
elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ]; then
cp "${grubdir}/core.${imgext}" "${grubdir}/grub"
@ -616,8 +619,15 @@ elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${pla
exit 1
}
fi
elif [ x"${target_cpu}-${platform}" = xmips-arc ]; then
dvhtool -d "${install_device}" --unix-to-vh "{grubdir}/core.${imgext}" grub
echo "You will have to set SystemPartition and OSLoader manually."
elif [ x"$platform" = xefi ]; then
cp "${grubdir}/core.${imgext}" "${efidir}/${efi_file}"
# For old macs. Suggested by Peter Jones.
if [ x$target_cpu = xi386 ]; then
cp "${grubdir}/core.${imgext}" "${efidir}/boot.efi"
fi
# Try to make this image bootable using the EFI Boot Manager, if available.
efibootmgr="`which efibootmgr`"

View file

@ -280,6 +280,8 @@ for i in ${grub_mkconfig_dir}/* ; do
case "$i" in
# emacsen backup files. FIXME: support other editors
*~) ;;
# emacsen autosave files. FIXME: support other editors
\#*\#) ;;
*)
if grub_file_is_not_garbage "$i" && test -x "$i" ; then
echo

View file

@ -16,19 +16,19 @@
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
datarootdir=@datarootdir@
datadir=@datadir@
bindir=@bindir@
sbindir=@sbindir@
pkgdatadir=${datadir}/`echo @PACKAGE_TARNAME@ | sed "${transform}"`
prefix="@prefix@"
exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@"
datadir="@datadir@"
bindir="@bindir@"
sbindir="@sbindir@"
pkgdatadir="${datadir}/`echo "@PACKAGE_TARNAME@" | sed "${transform}"`"
if test "x$grub_probe" = x; then
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
grub_probe="${sbindir}/`echo grub-probe | sed "${transform}"`"
fi
if test "x$grub_mkrelpath" = x; then
grub_mkrelpath=${bindir}/`echo grub-mkrelpath | sed ${transform}`
grub_mkrelpath="${bindir}/`echo grub-mkrelpath | sed "${transform}"`"
fi
if $(which gettext >/dev/null 2>/dev/null) ; then
@ -44,20 +44,26 @@ grub_warn ()
make_system_path_relative_to_its_root ()
{
${grub_mkrelpath} $1
"${grub_mkrelpath}" "$1"
}
is_path_readable_by_grub ()
{
path=$1
path="$1"
# abort if path doesn't exist
if test -e $path ; then : ;else
if test -e "$path" ; then : ;else
return 1
fi
# abort if file is in a filesystem we can't read
if ${grub_probe} -t fs $path > /dev/null 2>&1 ; then : ; else
if "${grub_probe}" -t fs "$path" > /dev/null 2>&1 ; then : ; else
return 1
fi
# ... or if we can't figure out the abstraction module, for example if
# memberlist fails on an LVM volume group.
if ${grub_probe} -t abstraction $path > /dev/null 2>&1 ; then : ; else
return 1
fi
@ -66,24 +72,24 @@ is_path_readable_by_grub ()
convert_system_path_to_grub_path ()
{
path=$1
path="$1"
grub_warn "convert_system_path_to_grub_path() is deprecated. Use prepare_grub_to_access_device() instead."
# abort if GRUB can't access the path
if is_path_readable_by_grub ${path} ; then : ; else
if is_path_readable_by_grub "${path}" ; then : ; else
return 1
fi
if drive=`${grub_probe} -t drive $path` ; then : ; else
if drive="`"${grub_probe}" -t drive "$path"`" ; then : ; else
return 1
fi
if relative_path=`make_system_path_relative_to_its_root $path` ; then : ; else
if relative_path="`make_system_path_relative_to_its_root "$path"`" ; then : ; else
return 1
fi
echo ${drive}${relative_path}
echo "${drive}${relative_path}"
}
save_default_entry ()
@ -97,15 +103,15 @@ EOF
prepare_grub_to_access_device ()
{
device=$1
device="$1"
# Abstraction modules aren't auto-loaded.
abstraction="`${grub_probe} --device ${device} --target=abstraction`"
abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`"
for module in ${abstraction} ; do
echo "insmod ${module}"
done
partmap="`${grub_probe} --device ${device} --target=partmap`"
partmap="`"${grub_probe}" --device "${device}" --target=partmap`"
for module in ${partmap} ; do
case "${module}" in
netbsd | openbsd)
@ -115,15 +121,15 @@ prepare_grub_to_access_device ()
esac
done
fs="`${grub_probe} --device ${device} --target=fs`"
fs="`"${grub_probe}" --device "${device}" --target=fs`"
for module in ${fs} ; do
echo "insmod ${module}"
done
# If there's a filesystem UUID that GRUB is capable of identifying, use it;
# otherwise set root as per value in device.map.
echo "set root='`${grub_probe} --device ${device} --target=drive`'"
if fs_uuid="`${grub_probe} --device ${device} --target=fs_uuid 2> /dev/null`" ; then
echo "set root='`"${grub_probe}" --device "${device}" --target=drive`'"
if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
echo "search --no-floppy --fs-uuid --set=root ${fs_uuid}"
fi
}
@ -143,21 +149,21 @@ grub_file_is_not_garbage ()
version_test_numeric ()
{
local a=$1
local cmp=$2
local b=$3
local a="$1"
local cmp="$2"
local b="$3"
if [ "$a" = "$b" ] ; then
case $cmp in
case "$cmp" in
ge|eq|le) return 0 ;;
gt|lt) return 1 ;;
esac
fi
if [ "$cmp" = "lt" ] ; then
c=$a
a=$b
b=$c
c="$a"
a="$b"
b="$c"
fi
if (echo $a ; echo $b) | sort -n | head -n 1 | grep -qx $b ; then
if (echo "$a" ; echo "$b") | sort -n | head -n 1 | grep -qx "$b" ; then
return 0
else
return 1
@ -166,25 +172,25 @@ version_test_numeric ()
version_test_gt ()
{
local a=`echo $1 | sed -e "s/[^-]*-//"`
local b=`echo $2 | sed -e "s/[^-]*-//"`
local a="`echo "$1" | sed -e "s/[^-]*-//"`"
local b="`echo "$2" | sed -e "s/[^-]*-//"`"
local cmp=gt
if [ "x$b" = "x" ] ; then
return 0
fi
case $a:$b in
case "$a:$b" in
*.old:*.old) ;;
*.old:*) a=`echo -n $a | sed -e s/\.old$//` ; cmp=gt ;;
*:*.old) b=`echo -n $b | sed -e s/\.old$//` ; cmp=ge ;;
*.old:*) a="`echo -n "$a" | sed -e 's/\.old$//'`" ; cmp=gt ;;
*:*.old) b="`echo -n "$b" | sed -e 's/\.old$//'`" ; cmp=ge ;;
esac
version_test_numeric $a $cmp $b
return $?
version_test_numeric "$a" "$cmp" "$b"
return "$?"
}
version_find_latest ()
{
local a=""
for i in $@ ; do
for i in "$@" ; do
if version_test_gt "$i" "$a" ; then
a="$i"
fi
@ -196,7 +202,7 @@ version_find_latest ()
# printf; so this turns ' into \'. Note that you must use the output of
# this function in a printf format string.
gettext_quoted () {
$gettext "$@" | sed "s/'/'\\\\\\\\''/g"
"$gettext" "$@" | sed "s/'/'\\\\\\\\''/g"
}
# Run the first argument through gettext_quoted, and then pass that and all
@ -209,9 +215,9 @@ gettext_printf () {
}
uses_abstraction () {
device=$1
device="$1"
abstraction="`${grub_probe} --device ${device} --target=abstraction`"
abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`"
for module in ${abstraction}; do
if test "x${module}" = "x$2"; then
return 0

View file

@ -29,6 +29,8 @@
#include <grub/util/resolve.h>
#include <grub/misc.h>
#include <grub/offsets.h>
#include <grub/crypto.h>
#include <grub/dl.h>
#include <time.h>
#include <stdio.h>
@ -57,14 +59,15 @@ typedef enum {
struct image_target_desc
{
const char *name;
const char *dirname;
const char *names[6];
grub_size_t voidp_sizeof;
int bigendian;
enum {
IMAGE_I386_PC, IMAGE_EFI, IMAGE_COREBOOT,
IMAGE_SPARC64_AOUT, IMAGE_SPARC64_RAW, IMAGE_I386_IEEE1275,
IMAGE_YEELOONG_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH,
IMAGE_I386_PC_PXE
IMAGE_LOONGSON_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH,
IMAGE_FULOONG_FLASH, IMAGE_I386_PC_PXE, IMAGE_MIPS_ARC
} id;
enum
{
@ -86,12 +89,21 @@ struct image_target_desc
grub_uint64_t link_addr;
unsigned mod_gap, mod_align;
grub_compression_t default_compression;
grub_uint16_t pe_target;
};
#define EFI64_HEADER_SIZE ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE \
+ GRUB_PE32_SIGNATURE_SIZE \
+ sizeof (struct grub_pe32_coff_header) \
+ sizeof (struct grub_pe64_optional_header) \
+ 4 * sizeof (struct grub_pe32_section_table), \
GRUB_PE32_SECTION_ALIGNMENT)
struct image_target_desc image_targets[] =
{
{
.name = "i386-coreboot",
.dirname = "i386-coreboot",
.names = { "i386-coreboot", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_COREBOOT,
@ -113,7 +125,8 @@ struct image_target_desc image_targets[] =
.mod_align = GRUB_KERNEL_I386_COREBOOT_MOD_ALIGN
},
{
.name = "i386-multiboot",
.dirname = "i386-multiboot",
.names = { "i386-multiboot", NULL},
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_COREBOOT,
@ -135,7 +148,8 @@ struct image_target_desc image_targets[] =
.mod_align = GRUB_KERNEL_I386_COREBOOT_MOD_ALIGN
},
{
.name = "i386-pc",
.dirname = "i386-pc",
.names = { "i386-pc", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_I386_PC,
@ -153,7 +167,8 @@ struct image_target_desc image_targets[] =
.link_addr = GRUB_KERNEL_I386_PC_LINK_ADDR
},
{
.name = "i386-pc-pxe",
.dirname = "i386-pc",
.names = { "i386-pc-pxe", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_I386_PC_PXE,
@ -171,7 +186,8 @@ struct image_target_desc image_targets[] =
.link_addr = GRUB_KERNEL_I386_PC_LINK_ADDR
},
{
.name = "i386-efi",
.dirname = "i386-efi",
.names = { "i386-efi", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_EFI,
@ -191,9 +207,12 @@ struct image_target_desc image_targets[] =
GRUB_PE32_SECTION_ALIGNMENT),
.install_dos_part = TARGET_NO_FIELD,
.install_bsd_part = TARGET_NO_FIELD,
.pe_target = GRUB_PE32_MACHINE_I386,
.elf_target = EM_386,
},
{
.name = "i386-ieee1275",
.dirname = "i386-ieee1275",
.names = { "i386-ieee1275", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_I386_IEEE1275,
@ -215,7 +234,8 @@ struct image_target_desc image_targets[] =
.link_align = 4,
},
{
.name = "i386-qemu",
.dirname = "i386-qemu",
.names = { "i386-qemu", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_QEMU,
@ -233,7 +253,8 @@ struct image_target_desc image_targets[] =
.link_addr = GRUB_KERNEL_I386_QEMU_LINK_ADDR
},
{
.name = "x86_64-efi",
.dirname = "x86_64-efi",
.names = { "x86_64-efi", NULL },
.voidp_sizeof = 8,
.bigendian = 0,
.id = IMAGE_EFI,
@ -245,59 +266,82 @@ struct image_target_desc image_targets[] =
.kernel_image_size = TARGET_NO_FIELD,
.compressed_size = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE
+ GRUB_PE32_SIGNATURE_SIZE
+ sizeof (struct grub_pe32_coff_header)
+ sizeof (struct grub_pe64_optional_header)
+ 4 * sizeof (struct grub_pe32_section_table),
GRUB_PE32_SECTION_ALIGNMENT),
.vaddr_offset = EFI64_HEADER_SIZE,
.install_dos_part = TARGET_NO_FIELD,
.install_bsd_part = TARGET_NO_FIELD,
.pe_target = GRUB_PE32_MACHINE_X86_64,
.elf_target = EM_X86_64,
},
{
.name = "mipsel-yeeloong-flash",
.dirname = "mips-loongson",
.names = { "mipsel-yeeloong-flash", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_YEELOONG_FLASH,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.prefix = GRUB_KERNEL_MIPS_YEELOONG_PREFIX,
.prefix_end = GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END,
.prefix = GRUB_KERNEL_MIPS_LOONGSON_PREFIX,
.prefix_end = GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END,
.raw_size = 0,
.total_module_size = GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE,
.total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE,
.compressed_size = TARGET_NO_FIELD,
.kernel_image_size = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.install_dos_part = TARGET_NO_FIELD,
.install_bsd_part = TARGET_NO_FIELD,
.link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR,
.link_addr = GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN,
.link_align = GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN,
.default_compression = COMPRESSION_NONE
},
{
.name = "mipsel-yeeloong-elf",
.dirname = "mips-loongson",
.names = { "mipsel-fuloong-flash", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_YEELOONG_ELF,
.id = IMAGE_FULOONG_FLASH,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.prefix = GRUB_KERNEL_MIPS_YEELOONG_PREFIX,
.prefix_end = GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END,
.prefix = GRUB_KERNEL_MIPS_LOONGSON_PREFIX,
.prefix_end = GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END,
.raw_size = 0,
.total_module_size = GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE,
.total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE,
.compressed_size = TARGET_NO_FIELD,
.kernel_image_size = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.install_dos_part = TARGET_NO_FIELD,
.install_bsd_part = TARGET_NO_FIELD,
.link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR,
.link_addr = GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN,
.link_align = GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN,
.default_compression = COMPRESSION_NONE
},
{
.name = "powerpc-ieee1275",
.dirname = "mips-loongson",
.names = { "mipsel-loongson-elf", "mipsel-yeeloong-elf",
"mipsel-fuloong-elf", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_LOONGSON_ELF,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.prefix = GRUB_KERNEL_MIPS_LOONGSON_PREFIX,
.prefix_end = GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END,
.raw_size = 0,
.total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE,
.compressed_size = TARGET_NO_FIELD,
.kernel_image_size = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.install_dos_part = TARGET_NO_FIELD,
.install_bsd_part = TARGET_NO_FIELD,
.link_addr = GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN,
.default_compression = COMPRESSION_NONE
},
{
.dirname = "powerpc-ieee1275",
.names = { "powerpc-ieee1275", NULL },
.voidp_sizeof = 4,
.bigendian = 1,
.id = IMAGE_PPC,
@ -319,7 +363,8 @@ struct image_target_desc image_targets[] =
.link_align = 4
},
{
.name = "sparc64-ieee1275-raw",
.dirname = "sparc64-ieee1275",
.names = { "sparc64-ieee1275-raw", NULL },
.voidp_sizeof = 8,
.bigendian = 1,
.id = IMAGE_SPARC64_RAW,
@ -337,7 +382,8 @@ struct image_target_desc image_targets[] =
.link_addr = GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR
},
{
.name = "sparc64-ieee1275-aout",
.dirname = "sparc64-ieee1275",
.names = { "sparc64-ieee1275-aout", NULL },
.voidp_sizeof = 8,
.bigendian = 1,
.id = IMAGE_SPARC64_AOUT,
@ -354,6 +400,70 @@ struct image_target_desc image_targets[] =
.install_bsd_part = TARGET_NO_FIELD,
.link_addr = GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR
},
{
.dirname = "ia64-efi",
.names = {"ia64-efi", NULL},
.voidp_sizeof = 8,
.bigendian = 0,
.id = IMAGE_EFI,
.flags = PLATFORM_FLAGS_NONE,
.prefix = GRUB_KERNEL_IA64_EFI_PREFIX,
.prefix_end = GRUB_KERNEL_IA64_EFI_PREFIX_END,
.raw_size = 0,
.total_module_size = TARGET_NO_FIELD,
.kernel_image_size = TARGET_NO_FIELD,
.compressed_size = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = EFI64_HEADER_SIZE,
.install_dos_part = TARGET_NO_FIELD,
.install_bsd_part = TARGET_NO_FIELD,
.pe_target = GRUB_PE32_MACHINE_IA64,
.elf_target = EM_IA_64,
},
{
.dirname = "mips-arc",
.names = {"mips-arc", NULL},
.voidp_sizeof = 4,
.bigendian = 1,
.id = IMAGE_MIPS_ARC,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.prefix = GRUB_KERNEL_MIPS_ARC_PREFIX,
.prefix_end = GRUB_KERNEL_MIPS_ARC_PREFIX_END,
.raw_size = 0,
.total_module_size = GRUB_KERNEL_MIPS_ARC_TOTAL_MODULE_SIZE,
.compressed_size = TARGET_NO_FIELD,
.kernel_image_size = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.install_dos_part = TARGET_NO_FIELD,
.install_bsd_part = TARGET_NO_FIELD,
.link_addr = GRUB_KERNEL_MIPS_ARC_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_ARC_LINK_ALIGN,
.default_compression = COMPRESSION_NONE
},
{
.dirname = "mips-qemu_mips",
.names = { "mips-qemu_mips-elf", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_LOONGSON_ELF,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.prefix = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX,
.prefix_end = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END,
.raw_size = 0,
.total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE,
.compressed_size = TARGET_NO_FIELD,
.kernel_image_size = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.install_dos_part = TARGET_NO_FIELD,
.install_bsd_part = TARGET_NO_FIELD,
.link_addr = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN,
.default_compression = COMPRESSION_NONE
},
};
#define grub_target_to_host32(x) (grub_target_to_host32_real (image_target, (x)))
@ -799,10 +909,10 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
decompress_size = grub_util_get_image_size (decompress_path);
decompress_img = grub_util_read_image (decompress_path);
*((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE))
*((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_LOONGSON_COMPRESSED_SIZE))
= grub_host_to_target32 (core_size);
*((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_YEELOONG_UNCOMPRESSED_SIZE))
*((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_SIZE))
= grub_host_to_target32 (kernel_size + total_module_size);
full_size = core_size + decompress_size;
@ -901,12 +1011,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
+ 4 * sizeof (struct grub_pe32_section_table),
GRUB_PE32_SECTION_ALIGNMENT);
else
header_size = ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE
+ GRUB_PE32_SIGNATURE_SIZE
+ sizeof (struct grub_pe32_coff_header)
+ sizeof (struct grub_pe64_optional_header)
+ 4 * sizeof (struct grub_pe32_section_table),
GRUB_PE32_SECTION_ALIGNMENT);
header_size = EFI64_HEADER_SIZE;
reloc_addr = ALIGN_UP (header_size + core_size,
image_target->section_align);
@ -927,10 +1032,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
/* The COFF file header. */
c = (struct grub_pe32_coff_header *) (header + GRUB_PE32_MSDOS_STUB_SIZE
+ GRUB_PE32_SIGNATURE_SIZE);
if (image_target->voidp_sizeof == 4)
c->machine = grub_host_to_target16 (GRUB_PE32_MACHINE_I386);
else
c->machine = grub_host_to_target16 (GRUB_PE32_MACHINE_X86_64);
c->machine = grub_host_to_target16 (image_target->pe_target);
c->num_sections = grub_host_to_target16 (4);
c->time = grub_host_to_target32 (time (0));
@ -1162,17 +1264,63 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
}
break;
case IMAGE_YEELOONG_FLASH:
case IMAGE_FULOONG_FLASH:
{
char *rom_img;
size_t rom_size;
char *boot_path, *boot_img;
size_t boot_size;
boot_path = grub_util_get_path (dir, "fwstart.img");
grub_uint8_t context[GRUB_MD_SHA512->contextsize];
/* fwstart.img is the only part which can't be tested by using *-elf
target. Check it against the checksum. */
const grub_uint8_t yeeloong_fwstart_good_hash[512 / 8] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
/* None yet. */
const grub_uint8_t fuloong_fwstart_good_hash[512 / 8] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const grub_uint8_t *fwstart_good_hash;
if (image_target->id == IMAGE_FULOONG_FLASH)
{
fwstart_good_hash = fuloong_fwstart_good_hash;
boot_path = grub_util_get_path (dir, "fwstart_fuloong.img");
}
else
{
fwstart_good_hash = yeeloong_fwstart_good_hash;
boot_path = grub_util_get_path (dir, "fwstart.img");
}
boot_size = grub_util_get_image_size (boot_path);
boot_img = grub_util_read_image (boot_path);
rom_size = ALIGN_UP (core_size + boot_size, 512 * 1024);
grub_memset (context, 0, sizeof (context));
GRUB_MD_SHA512->init (context);
GRUB_MD_SHA512->write (context, boot_img, boot_size);
GRUB_MD_SHA512->final (context);
if (grub_memcmp (GRUB_MD_SHA512->read (context), fwstart_good_hash,
GRUB_MD_SHA512->mdlen) != 0)
grub_util_warn ("fwstart.img doesn't match the known good version. "
"Proceed at your own risk");
if (core_size + boot_size > 512 * 1024)
grub_util_error ("firmware image is too big");
rom_size = 512 * 1024;
rom_img = xmalloc (rom_size);
memset (rom_img, 0, rom_size);
@ -1189,7 +1337,77 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
core_size = rom_size;
}
break;
case IMAGE_YEELOONG_ELF:
case IMAGE_MIPS_ARC:
{
char *ecoff_img;
struct ecoff_header {
grub_uint16_t magic;
grub_uint16_t nsec;
grub_uint32_t time;
grub_uint32_t syms;
grub_uint32_t nsyms;
grub_uint16_t opt;
grub_uint16_t flags;
grub_uint16_t magic2;
grub_uint16_t version;
grub_uint32_t textsize;
grub_uint32_t datasize;
grub_uint32_t bsssize;
grub_uint32_t entry;
grub_uint32_t text_start;
grub_uint32_t data_start;
grub_uint32_t bss_start;
grub_uint32_t gprmask;
grub_uint32_t cprmask[4];
grub_uint32_t gp_value;
};
struct ecoff_section
{
char name[8];
grub_uint32_t paddr;
grub_uint32_t vaddr;
grub_uint32_t size;
grub_uint32_t file_offset;
grub_uint32_t reloc;
grub_uint32_t gp;
grub_uint16_t nreloc;
grub_uint16_t ngp;
grub_uint32_t flags;
};
struct ecoff_header *head;
struct ecoff_section *section;
grub_uint32_t target_addr;
size_t program_size;
program_size = ALIGN_ADDR (core_size);
target_addr = image_target->link_addr - ALIGN_UP(program_size, 1048576)
- (1 << 20);
ecoff_img = xmalloc (program_size + sizeof (*head) + sizeof (*section));
grub_memset (ecoff_img, 0, program_size + sizeof (*head) + sizeof (*section));
head = (void *) ecoff_img;
section = (void *) (head + 1);
head->magic = grub_host_to_target16 (0x160);
head->nsec = grub_host_to_target16 (1);
head->time = grub_host_to_target32 (0);
head->opt = grub_host_to_target16 (0x38);
head->flags = grub_host_to_target16 (0x207);
head->magic2 = grub_host_to_target16 (0x107);
head->textsize = grub_host_to_target32 (program_size);
head->entry = grub_host_to_target32 (target_addr);
head->text_start = grub_host_to_target32 (target_addr);
head->data_start = grub_host_to_target32 (target_addr + program_size);
grub_memcpy (section->name, ".text", sizeof (".text") - 1);
section->vaddr = grub_host_to_target32 (target_addr);
section->size = grub_host_to_target32 (program_size);
section->file_offset = grub_host_to_target32 (sizeof (*head) + sizeof (*section));
memcpy (section + 1, core_img, core_size);
free (core_img);
core_img = ecoff_img;
core_size = program_size + sizeof (*head) + sizeof (*section);
}
break;
case IMAGE_LOONGSON_ELF:
case IMAGE_PPC:
case IMAGE_COREBOOT:
case IMAGE_I386_IEEE1275:
@ -1202,7 +1420,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
int header_size, footer_size = 0;
int phnum = 1;
if (image_target->id != IMAGE_YEELOONG_ELF)
if (image_target->id != IMAGE_LOONGSON_ELF)
phnum += 2;
if (note)
@ -1237,7 +1455,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
/* No section headers. */
ehdr->e_shoff = grub_host_to_target32 (0);
if (image_target->id == IMAGE_YEELOONG_ELF)
if (image_target->id == IMAGE_LOONGSON_ELF)
ehdr->e_shentsize = grub_host_to_target16 (0);
else
ehdr->e_shentsize = grub_host_to_target16 (sizeof (Elf32_Shdr));
@ -1250,7 +1468,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
phdr->p_offset = grub_host_to_target32 (header_size);
phdr->p_flags = grub_host_to_target32 (PF_R | PF_W | PF_X);
if (image_target->id == IMAGE_YEELOONG_ELF)
if (image_target->id == IMAGE_LOONGSON_ELF)
target_addr = ALIGN_UP (image_target->link_addr
+ kernel_size + total_module_size, 32);
else
@ -1259,12 +1477,12 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
phdr->p_vaddr = grub_host_to_target32 (target_addr);
phdr->p_paddr = grub_host_to_target32 (target_addr);
phdr->p_align = grub_host_to_target32 (align > image_target->link_align ? align : image_target->link_align);
if (image_target->id == IMAGE_YEELOONG_ELF)
if (image_target->id == IMAGE_LOONGSON_ELF)
ehdr->e_flags = grub_host_to_target32 (0x1000 | EF_MIPS_NOREORDER
| EF_MIPS_PIC | EF_MIPS_CPIC);
else
ehdr->e_flags = 0;
if (image_target->id == IMAGE_YEELOONG_ELF)
if (image_target->id == IMAGE_LOONGSON_ELF)
{
phdr->p_filesz = grub_host_to_target32 (core_size);
phdr->p_memsz = grub_host_to_target32 (core_size);
@ -1379,12 +1597,12 @@ usage (int status)
char *ptr;
unsigned i;
for (i = 0; i < ARRAY_SIZE (image_targets); i++)
format_len += strlen (image_targets[i].name) + 2;
format_len += strlen (image_targets[i].names[0]) + 2;
ptr = formats = xmalloc (format_len);
for (i = 0; i < ARRAY_SIZE (image_targets); i++)
{
strcpy (ptr, image_targets[i].name);
ptr += strlen (image_targets[i].name);
strcpy (ptr, image_targets[i].names[0]);
ptr += strlen (image_targets[i].names[0]);
*ptr++ = ',';
*ptr++ = ' ';
}
@ -1454,10 +1672,12 @@ main (int argc, char *argv[])
case 'O':
{
unsigned i;
unsigned i, j;
for (i = 0; i < ARRAY_SIZE (image_targets); i++)
if (strcmp (optarg, image_targets[i].name) == 0)
image_target = &image_targets[i];
for (j = 0; image_targets[i].names[j]
&& j < ARRAY_SIZE (image_targets[i].names); j++)
if (strcmp (optarg, image_targets[i].names[j]) == 0)
image_target = &image_targets[i];
if (!image_target)
{
printf ("unknown target format %s\n", optarg);
@ -1552,25 +1772,19 @@ main (int argc, char *argv[])
if (!dir)
{
const char *last;
last = strchr (image_target->name, '-');
if (last)
last = strchr (last + 1, '-');
if (!last)
last = image_target->name + strlen (image_target->name);
dir = xmalloc (sizeof (GRUB_PKGLIBROOTDIR) + (last - image_target->name)
+ 1);
dir = xmalloc (sizeof (GRUB_PKGLIBROOTDIR)
+ grub_strlen (image_target->dirname) + 1);
memcpy (dir, GRUB_PKGLIBROOTDIR, sizeof (GRUB_PKGLIBROOTDIR) - 1);
*(dir + sizeof (GRUB_PKGLIBROOTDIR) - 1) = '/';
memcpy (dir + sizeof (GRUB_PKGLIBROOTDIR), image_target->name,
last - image_target->name);
*(dir + sizeof (GRUB_PKGLIBROOTDIR) + (last - image_target->name)) = 0;
strcpy (dir + sizeof (GRUB_PKGLIBROOTDIR), image_target->dirname);
}
generate_image (dir, prefix ? : DEFAULT_DIRECTORY, fp,
argv + optind, memdisk, config,
image_target, note, comp);
fflush (fp);
fsync (fileno (fp));
fclose (fp);
if (dir)

View file

@ -56,6 +56,7 @@ static Elf_Addr
SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections,
Elf_Shdr *symtab_section, Elf_Addr *section_addresses,
Elf_Half section_entsize, Elf_Half num_sections,
void *jumpers, Elf_Addr jumpers_addr,
struct image_target_desc *image_target)
{
Elf_Word symtab_size, sym_size, num_syms;
@ -65,6 +66,7 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections,
Elf_Word i;
Elf_Shdr *strtab_section;
const char *strtab;
grub_uint64_t *jptr = jumpers;
strtab_section
= (Elf_Shdr *) ((char *) sections
@ -101,9 +103,19 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections,
else if (index >= num_sections)
grub_util_error ("section %d does not exist", index);
sym->st_value = (grub_target_to_host32 (sym->st_value)
sym->st_value = (grub_target_to_host (sym->st_value)
+ section_addresses[index]);
grub_util_info ("locating %s at 0x%x", name, sym->st_value);
if (image_target->elf_target == EM_IA_64 && ELF_ST_TYPE (sym->st_info)
== STT_FUNC)
{
*jptr = sym->st_value;
sym->st_value = (char *) jptr - (char *) jumpers + jumpers_addr;
jptr++;
*jptr = 0;
jptr++;
}
grub_util_info ("locating %s at 0x%x", name, sym->st_value, section_addresses[index]);
if (! start_address)
if (strcmp (name, "_start") == 0 || strcmp (name, "start") == 0)
@ -134,6 +146,152 @@ SUFFIX (get_target_address) (Elf_Ehdr *e, Elf_Shdr *s, Elf_Addr offset,
return (Elf_Addr *) ((char *) e + grub_target_to_host32 (s->sh_offset) + offset);
}
static Elf_Addr
SUFFIX (count_funcs) (Elf_Ehdr *e, Elf_Shdr *symtab_section,
struct image_target_desc *image_target)
{
Elf_Word symtab_size, sym_size, num_syms;
Elf_Off symtab_offset;
Elf_Addr start_address = 0;
Elf_Sym *sym;
Elf_Word i;
int ret = 0;
symtab_size = grub_target_to_host (symtab_section->sh_size);
sym_size = grub_target_to_host (symtab_section->sh_entsize);
symtab_offset = grub_target_to_host (symtab_section->sh_offset);
num_syms = symtab_size / sym_size;
for (i = 0, sym = (Elf_Sym *) ((char *) e + symtab_offset);
i < num_syms;
i++, sym = (Elf_Sym *) ((char *) sym + sym_size))
if (ELF_ST_TYPE (sym->st_info) == STT_FUNC)
ret++;
return ret;
}
#ifdef MKIMAGE_ELF64
struct unaligned_uint32
{
grub_uint32_t val;
} __attribute__ ((packed));
#define MASK20 ((1 << 20) - 1)
#define MASK19 ((1 << 19) - 1)
static void
add_value_to_slot_20b (grub_addr_t addr, grub_uint32_t value)
{
struct unaligned_uint32 *p;
switch (addr & 3)
{
case 0:
p = (struct unaligned_uint32 *) ((addr & ~3ULL) + 2);
p->val = ((((((p->val >> 2) & MASK20) + value) & MASK20) << 2)
| (p->val & ~(MASK20 << 2)));
break;
case 1:
p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 7);
p->val = ((((((p->val >> 3) & MASK20) + value) & MASK20) << 3)
| (p->val & ~(MASK20 << 3)));
break;
case 2:
p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 12);
p->val = ((((((p->val >> 4) & MASK20) + value) & MASK20) << 4)
| (p->val & ~(MASK20 << 4)));
break;
}
}
#define MASKF21 ( ((1 << 23) - 1) & ~((1 << 7) | (1 << 8)) )
static grub_uint32_t
add_value_to_slot_21_real (grub_uint32_t a, grub_uint32_t value)
{
grub_uint32_t high, mid, low, c;
low = (a & 0x00007f);
mid = (a & 0x7fc000) >> 7;
high = (a & 0x003e00) << 7;
c = (low | mid | high) + value;
return (c & 0x7f) | ((c << 7) & 0x7fc000) | ((c >> 7) & 0x0003e00); //0x003e00
}
static void
add_value_to_slot_21 (grub_addr_t addr, grub_uint32_t value)
{
struct unaligned_uint32 *p;
switch (addr & 3)
{
case 0:
p = (struct unaligned_uint32 *) ((addr & ~3ULL) + 2);
p->val = ((add_value_to_slot_21_real (((p->val >> 2) & MASKF21), value) & MASKF21) << 2) | (p->val & ~(MASKF21 << 2));
break;
case 1:
p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 7);
p->val = ((add_value_to_slot_21_real (((p->val >> 3) & MASKF21), value) & MASKF21) << 3) | (p->val & ~(MASKF21 << 3));
break;
case 2:
p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 12);
p->val = ((add_value_to_slot_21_real (((p->val >> 4) & MASKF21), value) & MASKF21) << 4) | (p->val & ~(MASKF21 << 4));
break;
}
}
struct ia64_kernel_trampoline
{
/* nop.m */
grub_uint8_t nop[5];
/* movl r15 = addr*/
grub_uint8_t addr_hi[6];
grub_uint8_t e0;
grub_uint8_t addr_lo[4];
grub_uint8_t jump[0x20];
};
static grub_uint8_t nopm[5] =
{
/* [MLX] nop.m 0x0 */
0x05, 0x00, 0x00, 0x00, 0x01
};
static grub_uint8_t jump[0x20] =
{
/* [MMI] add r15=r15,r1;; */
0x0b, 0x78, 0x3c, 0x02, 0x00, 0x20,
/* ld8 r16=[r15],8 */
0x00, 0x41, 0x3c, 0x30, 0x28, 0xc0,
/* mov r14=r1;; */
0x01, 0x08, 0x00, 0x84,
/* [MIB] ld8 r1=[r15] */
0x11, 0x08, 0x00, 0x1e, 0x18, 0x10,
/* mov b6=r16 */
0x60, 0x80, 0x04, 0x80, 0x03, 0x00,
/* br.few b6;; */
0x60, 0x00, 0x80, 0x00
};
static void
make_trampoline (struct ia64_kernel_trampoline *tr, grub_uint64_t addr)
{
grub_memcpy (tr->nop, nopm, sizeof (tr->nop));
tr->addr_hi[0] = ((addr & 0xc00000) >> 16);
tr->addr_hi[1] = (addr >> 24) & 0xff;
tr->addr_hi[2] = (addr >> 32) & 0xff;
tr->addr_hi[3] = (addr >> 40) & 0xff;
tr->addr_hi[4] = (addr >> 48) & 0xff;
tr->addr_hi[5] = (addr >> 56) & 0xff;
tr->e0 = 0xe0;
tr->addr_lo[0] = ((addr & 0x000f) << 4) | 0x01;
tr->addr_lo[1] = (((addr & 0x0070) >> 4) | ((addr & 0x070000) >> 11)
| ((addr & 0x200000) >> 17));
tr->addr_lo[2] = ((addr & 0x1f80) >> 5) | ((addr & 0x180000) >> 19);
tr->addr_lo[3] = ((addr & 0xe000) >> 13) | 0x60;
grub_memcpy (tr->jump, jump, sizeof (tr->jump));
}
#endif
/* Deal with relocation information. This function relocates addresses
within the virtual address space starting from 0. So only relative
addresses can be fully resolved. Absolute addresses must be relocated
@ -142,10 +300,15 @@ static void
SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
Elf_Addr *section_addresses,
Elf_Half section_entsize, Elf_Half num_sections,
const char *strtab, struct image_target_desc *image_target)
const char *strtab,
char *pe_target, Elf_Addr tramp_off,
Elf_Addr got_off,
struct image_target_desc *image_target)
{
Elf_Half i;
Elf_Shdr *s;
struct ia64_kernel_trampoline *tr = (void *) (pe_target + tramp_off);
grub_uint64_t *gpptr = (void *) (pe_target + got_off);
for (i = 0, s = sections;
i < num_sections;
@ -200,7 +363,9 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
addend = (s->sh_type == grub_target_to_host32 (SHT_RELA)) ?
r->r_addend : 0;
if (image_target->voidp_sizeof == 4)
switch (image_target->elf_target)
{
case EM_386:
switch (ELF_R_TYPE (info))
{
case R_386_NONE:
@ -224,11 +389,12 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
*target, offset);
break;
default:
grub_util_error ("unknown relocation type %d",
grub_util_error ("unknown relocation type 0x%x",
ELF_R_TYPE (info));
break;
}
else
break;
case EM_X86_64:
switch (ELF_R_TYPE (info))
{
@ -270,6 +436,85 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
ELF_R_TYPE (info));
break;
}
break;
#ifdef MKIMAGE_ELF64
case EM_IA_64:
switch (ELF_R_TYPE (info))
{
case R_IA64_PCREL21B:
{
grub_uint64_t noff;
make_trampoline (tr, addend + sym_addr);
noff = ((char *) tr - (char *) pe_target
- target_section_addr - (offset & ~3)) >> 4;
tr++;
if (noff & ~MASK19)
grub_util_error ("trampoline offset too big (%lx)",
noff);
add_value_to_slot_20b ((grub_addr_t) target, noff);
}
break;
case R_IA64_LTOFF22X:
case R_IA64_LTOFF22:
{
Elf_Sym *sym;
sym = (Elf_Sym *) ((char *) e
+ grub_target_to_host32 (symtab_section->sh_offset)
+ ELF_R_SYM (info) * grub_target_to_host32 (symtab_section->sh_entsize));
if (ELF_ST_TYPE (sym->st_info) == STT_FUNC)
sym_addr = grub_target_to_host64 (*(grub_uint64_t *) (pe_target
+ sym->st_value
- image_target->vaddr_offset));
}
case R_IA64_LTOFF_FPTR22:
*gpptr = grub_host_to_target64 (addend + sym_addr);
add_value_to_slot_21 ((grub_addr_t) target,
(char *) gpptr - (char *) pe_target
+ image_target->vaddr_offset);
gpptr++;
break;
case R_IA64_GPREL22:
add_value_to_slot_21 ((grub_addr_t) target,
addend + sym_addr);
break;
case R_IA64_PCREL64LSB:
*target = grub_host_to_target64 (grub_target_to_host64 (*target)
+ addend + sym_addr
- target_section_addr - offset
- image_target->vaddr_offset);
break;
case R_IA64_SEGREL64LSB:
*target = grub_host_to_target64 (grub_target_to_host64 (*target)
+ addend + sym_addr - target_section_addr);
break;
case R_IA64_DIR64LSB:
case R_IA64_FPTR64LSB:
*target = grub_host_to_target64 (grub_target_to_host64 (*target)
+ addend + sym_addr);
grub_util_info ("relocating a direct entry to 0x%"
PRIxGRUB_UINT64_T " at the offset 0x%x",
*target, offset);
break;
/* We treat LTOFF22X as LTOFF22, so we can ignore LDXMOV. */
case R_IA64_LDXMOV:
break;
default:
grub_util_error ("unknown relocation type 0x%x",
ELF_R_TYPE (info));
break;
}
break;
#endif
default:
grub_util_error ("unknown architecture type %d",
image_target->elf_target);
}
}
}
}
@ -312,7 +557,7 @@ SUFFIX (add_fixup_entry) (struct fixup_block_list **cblock, grub_uint16_t type,
b->block_size += 2;
}
}
else if (b->block_size & (8 - 1))
else while (b->block_size & (8 - 1))
{
/* If not aligned with a 32-bit boundary, add
a padding entry. */
@ -374,9 +619,11 @@ static Elf_Addr
SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out,
Elf_Addr *section_addresses, Elf_Shdr *sections,
Elf_Half section_entsize, Elf_Half num_sections,
const char *strtab, struct image_target_desc *image_target)
const char *strtab,
Elf_Addr jumpers, grub_size_t njumpers,
struct image_target_desc *image_target)
{
Elf_Half i;
unsigned i;
Elf_Shdr *s;
struct fixup_block_list *lst, *lst0;
Elf_Addr current_address = 0;
@ -384,8 +631,7 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out,
lst = lst0 = xmalloc (sizeof (*lst) + 2 * 0x1000);
memset (lst, 0, sizeof (*lst) + 2 * 0x1000);
for (i = 0, s = sections;
i < num_sections;
for (i = 0, s = sections; i < num_sections;
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
if ((s->sh_type == grub_cpu_to_le32 (SHT_REL)) ||
(s->sh_type == grub_cpu_to_le32 (SHT_RELA)))
@ -417,8 +663,9 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out,
info = grub_le_to_cpu32 (r->r_info);
/* Necessary to relocate only absolute addresses. */
if (image_target->voidp_sizeof == 4)
switch (image_target->elf_target)
{
case EM_386:
if (ELF_R_TYPE (info) == R_386_32)
{
Elf_Addr addr;
@ -431,9 +678,8 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out,
addr, 0, current_address,
image_target);
}
}
else
{
break;
case EM_X86_64:
if ((ELF_R_TYPE (info) == R_X86_64_32) ||
(ELF_R_TYPE (info) == R_X86_64_32S))
{
@ -452,10 +698,57 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out,
0, current_address,
image_target);
}
break;
case EM_IA_64:
switch (ELF_R_TYPE (info))
{
case R_IA64_PCREL64LSB:
case R_IA64_LDXMOV:
case R_IA64_PCREL21B:
case R_IA64_LTOFF_FPTR22:
case R_IA64_LTOFF22X:
case R_IA64_LTOFF22:
case R_IA64_GPREL22:
case R_IA64_SEGREL64LSB:
break;
case R_IA64_FPTR64LSB:
case R_IA64_DIR64LSB:
#if 1
{
Elf_Addr addr;
addr = section_address + offset;
grub_util_info ("adding a relocation entry for 0x%llx", addr);
current_address
= SUFFIX (add_fixup_entry) (&lst,
GRUB_PE32_REL_BASED_DIR64,
addr,
0, current_address,
image_target);
}
#endif
break;
default:
grub_util_error ("unknown relocation type 0x%x",
ELF_R_TYPE (info));
break;
}
break;
default:
grub_util_error ("unknown machine type 0x%x", image_target->elf_target);
}
}
}
if (image_target->elf_target == EM_IA_64)
for (i = 0; i < njumpers; i++)
current_address = SUFFIX (add_fixup_entry) (&lst,
GRUB_PE32_REL_BASED_DIR64,
jumpers + 8 * i,
0, current_address,
image_target);
current_address = SUFFIX (add_fixup_entry) (&lst, 0, 0, 1, current_address, image_target);
{
@ -617,7 +910,10 @@ SUFFIX (load_image) (const char *kernel_path, grub_size_t *exec_size,
Elf_Off section_offset;
Elf_Half section_entsize;
grub_size_t kernel_size;
grub_size_t ia64jmp_off = 0, ia64_toff = 0, ia64_got_off = 0;
unsigned ia64jmpnum = 0;
Elf_Shdr *symtab_section;
grub_size_t got = 0;
*start = 0;
@ -696,23 +992,31 @@ SUFFIX (load_image) (const char *kernel_path, grub_size_t *exec_size,
break;
}
#ifdef MKIMAGE_ELF64
if (image_target->elf_target == EM_IA_64)
{
grub_size_t tramp;
*kernel_sz = ALIGN_UP (*kernel_sz, 16);
grub_ia64_dl_get_tramp_got_size (e, &tramp, &got);
tramp *= sizeof (struct ia64_kernel_trampoline);
ia64_toff = *kernel_sz;
*kernel_sz += ALIGN_UP (tramp, 16);
ia64jmp_off = *kernel_sz;
ia64jmpnum = SUFFIX (count_funcs) (e, symtab_section,
image_target);
*kernel_sz += 16 * ia64jmpnum;
ia64_got_off = *kernel_sz;
*kernel_sz += ALIGN_UP (got * sizeof (grub_uint64_t), 16);
}
#endif
if (! symtab_section)
grub_util_error ("no symbol table");
*start = SUFFIX (relocate_symbols) (e, sections, symtab_section,
section_vaddresses, section_entsize,
num_sections, image_target);
if (*start == 0)
grub_util_error ("start symbol is not defined");
/* Resolve addresses in the virtual address space. */
SUFFIX (relocate_addresses) (e, sections, section_addresses, section_entsize,
num_sections, strtab, image_target);
*reloc_size = SUFFIX (make_reloc_section) (e, reloc_section,
section_vaddresses, sections,
section_entsize, num_sections,
strtab, image_target);
}
else
{
@ -722,6 +1026,34 @@ SUFFIX (load_image) (const char *kernel_path, grub_size_t *exec_size,
out_img = xmalloc (*kernel_sz + total_module_size);
if (image_target->id == IMAGE_EFI)
{
*start = SUFFIX (relocate_symbols) (e, sections, symtab_section,
section_vaddresses, section_entsize,
num_sections,
(char *) out_img + ia64jmp_off,
ia64jmp_off
+ image_target->vaddr_offset,
image_target);
if (*start == 0)
grub_util_error ("start symbol is not defined");
/* Resolve addresses in the virtual address space. */
SUFFIX (relocate_addresses) (e, sections, section_addresses,
section_entsize,
num_sections, strtab,
out_img, ia64_toff, ia64_got_off,
image_target);
*reloc_size = SUFFIX (make_reloc_section) (e, reloc_section,
section_vaddresses, sections,
section_entsize, num_sections,
strtab, ia64jmp_off
+ image_target->vaddr_offset,
2 * ia64jmpnum + got,
image_target);
}
for (i = 0, s = sections;
i < num_sections;
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))

View file

@ -248,7 +248,7 @@ main (int argc, char *argv[])
{
FILE *f;
size_t rd;
f = fopen ("/dev/random", "rb");
f = fopen ("/dev/urandom", "rb");
if (!f)
{
memset (pass1, 0, strlen (pass1));

View file

@ -160,7 +160,7 @@ process_input_dir ()
input_dir="$1"
platform="$2"
mkdir -p ${iso9660_dir}/boot/grub/${platform}
for file in ${input_dir}/*.mod; do
for file in "${input_dir}/"*.mod "${input_dir}/"efiemu32.o "${input_dir}/"efiemu64.o; do
if test -f "$file"; then
cp -f "$file" ${iso9660_dir}/boot/grub/${platform}/
fi
@ -286,6 +286,10 @@ if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then
make_image "${efi64_dir}" x86_64-efi "${efi_dir}"/efi/boot/bootx64.efi ""
# build bootia32.efi
make_image "${efi32_dir}" i386-efi "${efi_dir}"/efi/boot/bootia32.efi ""
if [ -e "${efi_dir}"/efi/boot/bootia32.efi ]; then
# For old macs. Suggested by Peter Jones.
cp "${efi_dir}"/efi/boot/bootia32.efi "${efi_dir}"/efi/boot/boot.efi
fi
mformat -C -f 2880 -L 16 -i "${iso9660_dir}"/efi.img ::
mcopy -s -i "${iso9660_dir}"/efi.img ${efi_dir}/efi ::/

View file

@ -79,11 +79,12 @@ Report bugs to <%s>.\n", program_name, PACKAGE_BUGREPORT);
#define BSS_SECTION 4
#define MODNAME_SECTION 5
#define MODDEPS_SECTION 6
#define SYMTAB_SECTION 7
#define STRTAB_SECTION 8
#define MODLICENSE_SECTION 7
#define SYMTAB_SECTION 8
#define STRTAB_SECTION 9
#define REL_SECTION 9
#define MAX_SECTIONS 12
#define REL_SECTION 10
#define MAX_SECTIONS 16
#define STRTAB_BLOCK 256
@ -96,7 +97,7 @@ int num_sections;
grub_uint32_t offset;
static int
insert_string (char *name)
insert_string (const char *name)
{
int len, result;
@ -124,6 +125,8 @@ write_section_data (FILE* fp, char *image,
{
int *section_map;
int i;
char *pe_strtab = (image + pe_chdr->symtab_offset
+ pe_chdr->num_symbols * sizeof (struct grub_pe32_symbol));
section_map = xmalloc ((pe_chdr->num_sections + 1) * sizeof (int));
section_map[0] = 0;
@ -131,31 +134,42 @@ write_section_data (FILE* fp, char *image,
for (i = 0; i < pe_chdr->num_sections; i++, pe_shdr++)
{
grub_uint32_t idx;
const char *name = pe_shdr->name;
if (! strcmp (pe_shdr->name, ".text"))
if (name[0] == '/' && isdigit (name[1]))
{
char t[sizeof (pe_shdr->name) + 1];
memcpy (t, name, sizeof (pe_shdr->name));
t[sizeof (pe_shdr->name)] = 0;
name = pe_strtab + atoi (t + 1);
}
if (! strcmp (name, ".text"))
{
idx = TEXT_SECTION;
shdr[idx].sh_flags = SHF_ALLOC | SHF_EXECINSTR;
}
else if (! strcmp (pe_shdr->name, ".rdata"))
else if (! strcmp (name, ".rdata"))
{
idx = RDATA_SECTION;
shdr[idx].sh_flags = SHF_ALLOC;
}
else if (! strcmp (pe_shdr->name, ".data"))
else if (! strcmp (name, ".data"))
{
idx = DATA_SECTION;
shdr[idx].sh_flags = SHF_ALLOC | SHF_WRITE;
}
else if (! strcmp (pe_shdr->name, ".bss"))
else if (! strcmp (name, ".bss"))
{
idx = BSS_SECTION;
shdr[idx].sh_flags = SHF_ALLOC | SHF_WRITE;
}
else if (! strcmp (pe_shdr->name, ".modname"))
else if (! strcmp (name, ".modname"))
idx = MODNAME_SECTION;
else if (! strcmp (pe_shdr->name, ".moddeps"))
else if (! strcmp (name, ".moddeps"))
idx = MODDEPS_SECTION;
else if (strcmp (name, ".module_license") == 0)
idx = MODLICENSE_SECTION;
else
{
section_map[i + 1] = -1;
@ -181,14 +195,14 @@ write_section_data (FILE* fp, char *image,
if (pe_shdr->relocations_offset)
{
char name[5 + strlen (pe_shdr->name)];
char relname[5 + strlen (name)];
if (num_sections >= MAX_SECTIONS)
grub_util_error ("too many sections");
sprintf (name, ".rel%s", pe_shdr->name);
sprintf (relname, ".rel%s", name);
shdr[num_sections].sh_name = insert_string (name);
shdr[num_sections].sh_name = insert_string (relname);
shdr[num_sections].sh_link = i;
shdr[num_sections].sh_info = idx;
@ -197,7 +211,7 @@ write_section_data (FILE* fp, char *image,
num_sections++;
}
else
shdr[idx].sh_name = insert_string (pe_shdr->name);
shdr[idx].sh_name = insert_string (name);
}
return section_map;

View file

@ -399,6 +399,15 @@ setup (const char *dir,
}
#endif
/* Copy the partition table. */
if (dest_partmap ||
(!allow_floppy && !grub_util_biosdisk_is_floppy (dest_dev->disk)))
memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC);
free (tmp_img);
if (! dest_partmap)
{
grub_util_warn (_("Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea."));
@ -410,14 +419,6 @@ setup (const char *dir,
goto unable_to_embed;
}
/* Copy the partition table. */
if (dest_partmap)
memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC);
free (tmp_img);
if (!dest_partmap->embed)
{
grub_util_warn ("Partition style '%s' doesn't support embeding",
@ -519,9 +520,7 @@ unable_to_embed:
core_path_dev = grub_make_system_path_relative_to_its_root (core_path_dev_full);
free (core_path_dev_full);
/* It is a Good Thing to sync two times. */
sync ();
sync ();
grub_util_biosdisk_flush (root_dev->disk);
#define MAX_TRIES 5
@ -582,7 +581,7 @@ unable_to_embed:
grub_util_info ("error message = %s", grub_errmsg);
grub_errno = GRUB_ERR_NONE;
sync ();
grub_util_biosdisk_flush (root_dev->disk);
sleep (1);
}
@ -673,8 +672,8 @@ unable_to_embed:
grub_util_error ("%s", grub_errmsg);
/* Sync is a Good Thing. */
sync ();
grub_util_biosdisk_flush (root_dev->disk);
grub_util_biosdisk_flush (dest_dev->disk);
free (core_path);
free (core_img);
@ -972,7 +971,15 @@ main (int argc, char *argv[])
char **devicelist;
int i;
devicelist = grub_util_raid_getmembers (dest_dev);
if (arguments.device[0] == '/')
devicelist = grub_util_raid_getmembers (arguments.device);
else
{
char *devname;
devname = xasprintf ("/dev/%s", dest_dev);
devicelist = grub_util_raid_getmembers (dest_dev);
free (devname);
}
for (i = 0; devicelist[i]; i++)
{

View file

@ -132,6 +132,19 @@ if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT_PATH}"` ; then
set gfxmode=${GRUB_GFXMODE}
load_video
insmod gfxterm
EOF
# Gettext variables and module
if [ "x${LANG}" != "xC" ] && [ -d "${locale_dir}" ] ; then
prepare_grub_to_access_device $(${grub_probe} --target=device ${locale_dir}) | sed -e "s/^/ /"
cat << EOF
set locale_dir=(\$root)$(make_system_path_relative_to_its_root ${locale_dir})
set lang=${grub_lang}
insmod gettext
EOF
fi
cat <<EOF
fi
EOF
fi
@ -210,16 +223,6 @@ EOF
fi
fi
# Gettext variables and module
if [ "x${LANG}" != "xC" ] && [ -d "${locale_dir}" ] ; then
prepare_grub_to_access_device $(${grub_probe} --target=device ${locale_dir})
cat << EOF
set locale_dir=(\$root)$(make_system_path_relative_to_its_root ${locale_dir})
set lang=${grub_lang}
insmod gettext
EOF
fi
make_timeout ()
{
if [ "x${1}" != "x" ] ; then

View file

@ -28,7 +28,7 @@ if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
OS=GNU
else
OS="${GRUB_DISTRIBUTOR} GNU/Hurd"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}"
fi
at_least_one=false

View file

@ -31,7 +31,7 @@ CLASS="--class os"
case "${GRUB_DISTRIBUTOR}" in
Debian)
OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) --class gnu-kfreebsd --class gnu ${CLASS}"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) --class gnu-kfreebsd --class gnu ${CLASS}"
;;
*)
OS="FreeBSD"
@ -110,7 +110,11 @@ EOF
;;
esac
load_kfreebsd_module ${kfreebsd_fs} false
if [ x${kfreebsd_fs} = xufs ]; then
load_kfreebsd_module ${kfreebsd_fs} true
else
load_kfreebsd_module ${kfreebsd_fs} false
fi
cat << EOF
set kFreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${kfreebsd_device}

View file

@ -32,7 +32,7 @@ if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
OS=GNU/Linux
else
OS="${GRUB_DISTRIBUTOR} GNU/Linux"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}"
fi
# loop-AES arranges things so that /dev/loop/X can be our root device, but
@ -51,6 +51,14 @@ else
LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
fi
if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then
rootsubvol="`make_system_path_relative_to_its_root /`"
rootsubvol="${rootsubvol#/}"
if [ "x${rootsubvol}" != x ]; then
GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
fi
fi
linux_entry ()
{
os="$1"
@ -73,8 +81,8 @@ linux_entry ()
cat << EOF
load_video
EOF
if grep -qx "CONFIG_FB_EFI=y" /boot/config-${version} 2> /dev/null \
&& grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" /boot/config-${version} 2> /dev/null; then
if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
&& grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
cat << EOF
set gfxpayload=keep
EOF
@ -90,10 +98,21 @@ EOF
EOF
fi
if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
cat << EOF
insmod gzio
EOF
if [ x$dirname = x/ ]; then
if [ -z "${prepare_root_cache}" ]; then
prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/")"
fi
printf '%s\n' "${prepare_root_cache}"
else
if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
fi
printf '%s\n' "${prepare_boot_cache}"
fi
printf '%s\n' "${prepare_boot_cache}"
message="$(gettext_printf "Loading Linux %s ..." ${version})"
cat << EOF
echo '$message'
@ -111,10 +130,19 @@ EOF
EOF
}
list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* ; do
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
done`
case x`uname -m` in
xi?86 | xx86_64)
list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
done` ;;
*)
list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
done` ;;
esac
prepare_boot_cache=
prepare_root_cache=
while [ "x$list" != "x" ] ; do
linux=`version_find_latest $list`
@ -130,21 +158,28 @@ while [ "x$list" != "x" ] ; do
for i in "initrd.img-${version}" "initrd-${version}.img" \
"initrd-${version}" "initramfs-${version}.img" \
"initrd.img-${alt_version}" "initrd-${alt_version}.img" \
"initrd-${alt_version}" "initramfs-${alt_version}.img"; do
"initrd-${alt_version}" "initramfs-${alt_version}.img" \
"initramfs-genkernel-${version}" \
"initramfs-genkernel-${alt_version}"; do
if test -e "${dirname}/${i}" ; then
initrd="$i"
break
fi
done
initramfs=
for i in "config-${version}" "config-${alt_version}"; do
if test -e "${dirname}/${i}" ; then
initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${dirname}/${i}" | cut -f2 -d= | tr -d \"`
config=
for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
if test -e "${i}" ; then
config="${i}"
break
fi
done
initramfs=
if test -n "${config}" ; then
initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
fi
if test -n "${initrd}" ; then
echo "Found initrd image: ${dirname}/${initrd}" >&2
elif test -z "${initramfs}" ; then

View file

@ -32,7 +32,7 @@ if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
OS=GNU/Linux
else
OS="${GRUB_DISTRIBUTOR} GNU/Linux"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}"
fi
# loop-AES arranges things so that /dev/loop/X can be our root device, but
@ -51,6 +51,14 @@ else
LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
fi
if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then
rootsubvol="`make_system_path_relative_to_its_root /`"
rootsubvol="${rootsubvol#/}"
if [ "x${rootsubvol}" != x ]; then
GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
fi
fi
linux_entry ()
{
os="$1"
@ -93,11 +101,24 @@ EOF
EOF
}
linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do
linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* /boot/kernel-*; do
if grub_file_is_not_garbage "$i"; then
basename=$(basename $i)
version=$(echo $basename | sed -e "s,^[^0-9]*-,,g")
if grub_file_is_not_garbage "$i" && grep -qx "CONFIG_XEN_DOM0=y" /boot/config-${version} 2> /dev/null ; then echo -n "$i " ; fi
done`
dirname=$(dirname $i)
config=
for j in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
if test -e "${j}" ; then
config="${j}"
break
fi
done
if (grep -qx "CONFIG_XEN_DOM0=y" "${config}" 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" "${config}" 2> /dev/null); then echo -n "$i " ; fi
fi
done`
if [ "x${linux_list}" = "x" ] ; then
exit 0
fi
xen_list=`for i in /boot/xen*; do
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
done`
@ -124,7 +145,9 @@ while [ "x${xen_list}" != "x" ] ; do
initrd=
for i in "initrd.img-${version}" "initrd-${version}.img" \
"initrd-${version}" "initrd.img-${alt_version}" \
"initrd-${alt_version}.img" "initrd-${alt_version}"; do
"initrd-${alt_version}.img" "initrd-${alt_version}" \
"initramfs-genkernel-${version}" \
"initramfs-genkernel-${alt_version}" ; do
if test -e "${dirname}/${i}" ; then
initrd="$i"
break

View file

@ -91,7 +91,12 @@ for cipher_file in cipher_files:
f = open (infile, "r")
fw = open (outfile, "w")
fw.write ("/* This file was automatically imported with \n")
fw.write (" import_gcry.py. Please don't modify it */\n");
fw.write (" import_gcry.py. Please don't modify it */\n")
fw.write ("#include <grub/dl.h>\n")
# Whole libgcrypt is distributed under GPLv3+ or compatible
if isc:
fw.write ("GRUB_MOD_LICENSE (\"GPLv3+\");\n")
ciphernames = []
mdnames = []
hold = False

View file

@ -36,25 +36,18 @@
#include <linux/raid/md_u.h>
char **
grub_util_raid_getmembers (char *name)
grub_util_raid_getmembers (const char *name)
{
int fd, ret, i, j;
char *devname;
char **devicelist;
mdu_version_t version;
mdu_array_info_t info;
mdu_disk_info_t disk;
devname = xmalloc (strlen (name) + 6);
strcpy (devname, "/dev/");
strcpy (devname+5, name);
fd = open (devname, O_RDONLY);
fd = open (name, O_RDONLY);
if (fd == -1)
grub_util_error ("can't open %s: %s", devname, strerror (errno));
free (devname);
grub_util_error ("can't open %s: %s", name, strerror (errno));
ret = ioctl (fd, RAID_VERSION, &version);
if (ret != 0)