merge mainline into lazy

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-07-07 12:21:53 +02:00
commit 00542307eb
326 changed files with 18667 additions and 4092 deletions

View file

@ -1,7 +1,7 @@
/* deviceiter.c - iterate over system devices */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008 Free Software Foundation, Inc.
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2011 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
@ -286,6 +286,20 @@ get_scsi_disk_name (char *name, int unit)
#endif
}
#ifdef __FreeBSD_kernel__
static void
get_ada_disk_name (char *name, int unit)
{
sprintf (name, "/dev/ada%d", unit);
}
static void
get_ataraid_disk_name (char *name, int unit)
{
sprintf (name, "/dev/ar%d", unit);
}
#endif
#ifdef __linux__
static void
get_virtio_disk_name (char *name, int unit)
@ -620,6 +634,35 @@ grub_util_iterate_devices (int NESTED_FUNC_ATTR (*hook) (const char *, int),
}
}
#ifdef __FreeBSD_kernel__
/* IDE disks using ATA Direct Access driver. */
if (get_kfreebsd_version () >= 800000)
for (i = 0; i < 96; i++)
{
char name[16];
get_ada_disk_name (name, i);
if (check_device_readable_unique (name))
{
if (hook (name, 0))
goto out;
}
}
/* ATARAID disks. */
for (i = 0; i < 8; i++)
{
char name[20];
get_ataraid_disk_name (name, i);
if (check_device_readable_unique (name))
{
if (hook (name, 0))
goto out;
}
}
#endif
#ifdef __linux__
/* Virtio disks. */
for (i = 0; i < 26; i++)

View file

@ -54,12 +54,16 @@ execute_command (char *name, int n, char **args)
return (cmd->func) (cmd, n, args);
}
#define CMD_LS 1
#define CMD_CP 2
#define CMD_CMP 3
#define CMD_HEX 4
#define CMD_CRC 6
#define CMD_BLOCKLIST 7
enum {
CMD_LS = 1,
CMD_CP,
CMD_CAT,
CMD_CMP,
CMD_HEX,
CMD_CRC,
CMD_BLOCKLIST,
CMD_TESTLOAD
};
#define BUF_SIZE 32256
@ -182,6 +186,26 @@ cmd_cp (char *src, char *dest)
fclose (ff);
}
static void
cmd_cat (char *src)
{
auto int cat_hook (grub_off_t ofs, char *buf, int len);
int cat_hook (grub_off_t ofs, char *buf, int len)
{
(void) ofs;
if ((int) fwrite (buf, 1, len, stdout) != len)
{
grub_util_error (_("write error"));
return 1;
}
return 0;
}
read_file (src, cat_hook);
}
static void
cmd_cmp (char *src, char *dest)
{
@ -321,6 +345,9 @@ fstest (int n, char **args)
case CMD_CP:
cmd_cp (args[0], args[1]);
break;
case CMD_CAT:
cmd_cat (args[0]);
break;
case CMD_CMP:
cmd_cmp (args[0], args[1]);
break;
@ -333,6 +360,9 @@ fstest (int n, char **args)
case CMD_BLOCKLIST:
execute_command ("blocklist", n, args);
grub_printf ("\n");
case CMD_TESTLOAD:
execute_command ("testload", n, args);
grub_printf ("\n");
}
for (i = 0; i < num_disks; i++)
@ -356,6 +386,7 @@ static struct argp_option options[] = {
{0, 0, 0 , OPTION_DOC, N_("Commands:"), 1},
{N_("ls PATH"), 0, 0 , OPTION_DOC, N_("List files in PATH."), 1},
{N_("cp FILE LOCAL"), 0, 0, OPTION_DOC, N_("Copy FILE to local file LOCAL."), 1},
{N_("cat FILE"), 0, 0 , OPTION_DOC, N_("Copy FILE to standard output."), 1},
{N_("cmp FILE LOCAL"), 0, 0, OPTION_DOC, N_("Compare FILE with local file LOCAL."), 1},
{N_("hex FILE"), 0, 0 , OPTION_DOC, N_("Hex dump FILE."), 1},
{N_("crc FILE"), 0, 0 , OPTION_DOC, N_("Get crc32 checksum of FILE."), 1},
@ -468,6 +499,11 @@ argp_parser (int key, char *arg, struct argp_state *state)
cmd = CMD_CP;
nparm = 2;
}
else if (!grub_strcmp (arg, "cat"))
{
cmd = CMD_CAT;
nparm = 1;
}
else if (!grub_strcmp (arg, "cmp"))
{
cmd = CMD_CMP;
@ -488,6 +524,11 @@ argp_parser (int key, char *arg, struct argp_state *state)
cmd = CMD_BLOCKLIST;
nparm = 1;
}
else if (!grub_strcmp (arg, "testload"))
{
cmd = CMD_TESTLOAD;
nparm = 1;
}
else
{
fprintf (stderr, _("Invalid command %s.\n"), arg);

View file

@ -74,7 +74,7 @@ if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
elif [ "${platform}" = "ieee1275" ] || [ "${platform}" = "efi" ] ; then
disk_module=
else
disk_module=ata
disk_module=native
fi
# Usage: usage
@ -111,7 +111,7 @@ Install GRUB on your drive.
EOF
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
cat <<EOF
--disk-module=MODULE disk module to use
--disk-module=MODULE disk module to use (biosdisk or native)
EOF
fi
if [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ] ; then
@ -489,6 +489,14 @@ done
# Device abstraction module, if any (lvm, raid).
devabstraction_module="`"$grub_probe" --device-map="${device_map}" --target=abstraction --device "${grub_device}"`"
if [ "x$disk_module" = xata ]; then
disk_module=pata
fi
if [ "x$disk_module" = xnative ]; then
disk_module="pata ahci ohci uhci usbms"
fi
# The order in this list is critical. Be careful when modifying it.
modules="$modules $disk_module"
modules="$modules $fs_module $partmap_module $devabstraction_module"
@ -522,7 +530,7 @@ 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 ] || [ "x${grub_drive}" != "x${install_drive}" ] || ([ "x$platform" != xefi ] && [ "x$platform" != xpc ] && [ x"${target_cpu}-${platform}" != x"sparc64-ieee1275" ]) ; then
if ([ "x$disk_module" != x ] && [ "x$disk_module" != xbiosdisk ]) || [ "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
@ -554,13 +562,13 @@ fi
case "${target_cpu}-${platform}" in
sparc64-ieee1275) mkimage_target=sparc64-ieee1275-raw ;;
mips-yeeloong) mkimage_target=mipsel-yeeloong-elf ;;
mipsel-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 \
mipsel-loongson | i386-coreboot | i386-multiboot | i386-ieee1275 \
| powerpc-ieee1275) imgext=elf ;;
*) imgext=img ;;
esac
@ -569,7 +577,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}" = "mipsel-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"
@ -619,6 +627,9 @@ 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.

View file

@ -95,7 +95,7 @@ do
esac
done
. ${libdir}/grub/grub-mkconfig_lib
. ${libdir}/@PACKAGE@/grub-mkconfig_lib
if [ "x$EUID" = "x" ] ; then
EUID=`id -u`
@ -239,6 +239,8 @@ export GRUB_DEFAULT \
GRUB_CMDLINE_LINUX_DEFAULT \
GRUB_CMDLINE_XEN \
GRUB_CMDLINE_XEN_DEFAULT \
GRUB_CMDLINE_LINUX_XEN_REPLACE \
GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT \
GRUB_CMDLINE_NETBSD \
GRUB_CMDLINE_NETBSD_DEFAULT \
GRUB_TERMINAL_INPUT \

View file

@ -63,7 +63,7 @@ is_path_readable_by_grub ()
# ... 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
if "${grub_probe}" -t abstraction "$path" > /dev/null 2>&1 ; then : ; else
return 1
fi
@ -105,12 +105,6 @@ prepare_grub_to_access_device ()
{
device="$1"
# Abstraction modules aren't auto-loaded.
abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`"
for module in ${abstraction} ; do
echo "insmod ${module}"
done
partmap="`"${grub_probe}" --device "${device}" --target=partmap`"
for module in ${partmap} ; do
case "${module}" in
@ -121,6 +115,12 @@ prepare_grub_to_access_device ()
esac
done
# Abstraction modules aren't auto-loaded.
abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`"
for module in ${abstraction} ; do
echo "insmod ${module}"
done
fs="`"${grub_probe}" --device "${device}" --target=fs`"
for module in ${fs} ; do
echo "insmod ${module}"

View file

@ -30,6 +30,7 @@
#include <grub/misc.h>
#include <grub/offsets.h>
#include <grub/crypto.h>
#include <grub/dl.h>
#include <time.h>
#include <stdio.h>
@ -58,20 +59,23 @@ 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,
IMAGE_QEMU_MIPS_FLASH
} id;
enum
{
PLATFORM_FLAGS_NONE = 0,
PLATFORM_FLAGS_LZMA = 1,
PLATFORM_FLAGS_DECOMPRESSORS = 2
PLATFORM_FLAGS_DECOMPRESSORS = 2,
PLATFORM_FLAGS_MODULES_BEFORE_KERNEL = 4,
} flags;
unsigned prefix;
unsigned prefix_end;
@ -87,12 +91,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,
@ -114,7 +127,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,
@ -136,7 +150,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,
@ -154,7 +169,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,
@ -172,7 +188,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,
@ -192,9 +209,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,
@ -216,7 +236,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,
@ -234,7 +255,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,
@ -246,59 +268,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 = "mipsel-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 = "mipsel-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 = "mipsel-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,
@ -320,7 +365,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,
@ -338,7 +384,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,
@ -355,6 +402,137 @@ 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
| PLATFORM_FLAGS_MODULES_BEFORE_KERNEL),
.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 = "mipsel-qemu_mips",
.names = { "mipsel-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
},
{
.dirname = "mips-qemu_mips",
.names = { "mips-qemu_mips-flash", NULL },
.voidp_sizeof = 4,
.bigendian = 1,
.id = IMAGE_QEMU_MIPS_FLASH,
.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
},
{
.dirname = "mipsel-qemu_mips",
.names = { "mipsel-qemu_mips-flash", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_QEMU_MIPS_FLASH,
.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
},
{
.dirname = "mips-qemu_mips",
.names = { "mips-qemu_mips-elf", NULL },
.voidp_sizeof = 4,
.bigendian = 1,
.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)))
@ -625,6 +803,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
grub_uint64_t start_address;
void *rel_section;
grub_size_t reloc_size, align;
size_t decompress_size;
if (comp == COMPRESSION_AUTO)
comp = image_target->default_compression;
@ -672,27 +851,47 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
grub_util_error (_("prefix is too long"));
strcpy (kernel_img + image_target->prefix, prefix);
if ((image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS)
&& (image_target->total_module_size != TARGET_NO_FIELD))
*((grub_uint32_t *) (kernel_img + image_target->total_module_size))
= grub_host_to_target32 (total_module_size);
if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL)
memmove (kernel_img + total_module_size, kernel_img, kernel_size);
if (image_target->voidp_sizeof == 8)
{
/* Fill in the grub_module_info structure. */
struct grub_module_info64 *modinfo;
modinfo = (struct grub_module_info64 *) (kernel_img + kernel_size);
if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL)
modinfo = (struct grub_module_info64 *) kernel_img;
else
modinfo = (struct grub_module_info64 *) (kernel_img + kernel_size);
memset (modinfo, 0, sizeof (struct grub_module_info64));
modinfo->magic = grub_host_to_target32 (GRUB_MODULE_MAGIC);
modinfo->offset = grub_host_to_target_addr (sizeof (struct grub_module_info64));
modinfo->size = grub_host_to_target_addr (total_module_size);
offset = kernel_size + sizeof (struct grub_module_info64);
if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL)
offset = sizeof (struct grub_module_info64);
else
offset = kernel_size + sizeof (struct grub_module_info64);
}
else
{
/* Fill in the grub_module_info structure. */
struct grub_module_info32 *modinfo;
modinfo = (struct grub_module_info32 *) (kernel_img + kernel_size);
if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL)
modinfo = (struct grub_module_info32 *) kernel_img;
else
modinfo = (struct grub_module_info32 *) (kernel_img + kernel_size);
memset (modinfo, 0, sizeof (struct grub_module_info32));
modinfo->magic = grub_host_to_target32 (GRUB_MODULE_MAGIC);
modinfo->offset = grub_host_to_target_addr (sizeof (struct grub_module_info32));
modinfo->size = grub_host_to_target_addr (total_module_size);
offset = kernel_size + sizeof (struct grub_module_info32);
if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL)
offset = sizeof (struct grub_module_info32);
else
offset = kernel_size + sizeof (struct grub_module_info32);
}
for (p = path_list; p; p = p->next)
@ -743,26 +942,27 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
offset += config_size;
}
if ((image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS)
&& (image_target->total_module_size != TARGET_NO_FIELD))
*((grub_uint32_t *) (kernel_img + image_target->total_module_size))
= grub_host_to_target32 (total_module_size);
grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size);
compress_kernel (image_target, kernel_img, kernel_size + total_module_size,
&core_img, &core_size, comp);
free (kernel_img);
if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS)
kernel_img = core_img + total_module_size;
else
kernel_img = core_img;
grub_util_info ("the core size is 0x%x", core_size);
if (!(image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS)
&& image_target->total_module_size != TARGET_NO_FIELD)
*((grub_uint32_t *) (core_img + image_target->total_module_size))
*((grub_uint32_t *) (kernel_img + image_target->total_module_size))
= grub_host_to_target32 (total_module_size);
if (image_target->kernel_image_size != TARGET_NO_FIELD)
*((grub_uint32_t *) (core_img + image_target->kernel_image_size))
*((grub_uint32_t *) (kernel_img + image_target->kernel_image_size))
= grub_host_to_target32 (kernel_size);
if (image_target->compressed_size != TARGET_NO_FIELD)
*((grub_uint32_t *) (core_img + image_target->compressed_size))
*((grub_uint32_t *) (kernel_img + image_target->compressed_size))
= grub_host_to_target32 (core_size - image_target->raw_size);
/* If we included a drive in our prefix, let GRUB know it doesn't have to
@ -770,9 +970,9 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
if (image_target->install_dos_part != TARGET_NO_FIELD
&& image_target->install_bsd_part != TARGET_NO_FIELD && prefix[0] == '(')
{
*((grub_int32_t *) (core_img + image_target->install_dos_part))
*((grub_int32_t *) (kernel_img + image_target->install_dos_part))
= grub_host_to_target32 (-2);
*((grub_int32_t *) (core_img + image_target->install_bsd_part))
*((grub_int32_t *) (kernel_img + image_target->install_bsd_part))
= grub_host_to_target32 (-2);
}
@ -781,7 +981,6 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
char *full_img;
size_t full_size;
char *decompress_path, *decompress_img;
size_t decompress_size;
const char *name;
switch (comp)
@ -800,12 +999,19 @@ 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);
if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL)
*((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_ADDR))
= grub_host_to_target_addr (image_target->link_addr - total_module_size);
else
*((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_ADDR))
= grub_host_to_target_addr (image_target->link_addr);
full_size = core_size + decompress_size;
full_img = xmalloc (full_size);
@ -902,12 +1108,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);
@ -928,10 +1129,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));
@ -1098,7 +1296,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
rom_img = xmalloc (rom_size);
memset (rom_img, 0, rom_size);
*((grub_int32_t *) (core_img + GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR))
*((grub_int32_t *) (kernel_img + GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR))
= grub_host_to_target32 ((grub_uint32_t) -rom_size);
memcpy (rom_img, core_img, core_size);
@ -1125,6 +1323,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
aout_size = core_size + sizeof (*aout_head);
aout_img = xmalloc (aout_size);
aout_head = aout_img;
grub_memset (aout_head, 0, sizeof (*aout_head));
aout_head->a_midmag = grub_host_to_target32 ((AOUT_MID_SUN << 16)
| AOUT32_OMAGIC);
aout_head->a_text = grub_host_to_target32 (core_size);
@ -1163,29 +1362,48 @@ 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;
grub_uint8_t context[GRUB_MD_SHA512->contextsize];
/* fwstart.img is the only part which can't be testes by using *-elf
target. Check it against the checksum. This checksum is obtained with
sha512sum utility after compiling on Gnewsense.
*/
const grub_uint8_t fwstart_good_hash[] =
{
0x9f, 0x7f, 0x79, 0x47, 0x68, 0x91, 0x61, 0xb3,
0x16, 0x7b, 0xf0, 0x27, 0x1c, 0xf7, 0xaf, 0x05,
0x6c, 0xc1, 0x6f, 0xd2, 0xe7, 0xd1, 0xe9, 0xec,
0x08, 0x87, 0xe5, 0xc8, 0x29, 0xa2, 0x5b, 0x84,
0xf8, 0xa6, 0xec, 0x08, 0xf7, 0xcb, 0x7b, 0x6c,
0xfe, 0x01, 0xfd, 0x5d, 0xba, 0xbf, 0x0d, 0x0f,
0x2e, 0xef, 0xed, 0x7b, 0xfe, 0xc9, 0x4a, 0x85,
0xcf, 0xac, 0x20, 0xd7, 0x01, 0xc5, 0xc5, 0x9c
/* 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,
};
boot_path = grub_util_get_path (dir, "fwstart.img");
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);
@ -1217,7 +1435,104 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
core_size = rom_size;
}
break;
case IMAGE_YEELOONG_ELF:
case IMAGE_QEMU_MIPS_FLASH:
{
char *rom_img;
size_t rom_size;
if (core_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);
memcpy (rom_img, core_img, core_size);
memset (rom_img + core_size, 0,
rom_size - core_size);
free (core_img);
core_img = rom_img;
core_size = rom_size;
}
break;
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);
if (comp == COMPRESSION_NONE)
target_addr = (image_target->link_addr
- total_module_size - decompress_size);
else
target_addr = (image_target->link_addr
- ALIGN_UP(total_module_size + core_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:
@ -1230,7 +1545,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)
@ -1265,7 +1580,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));
@ -1278,21 +1593,26 @@ 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)
target_addr = ALIGN_UP (image_target->link_addr
+ kernel_size + total_module_size, 32);
if (image_target->id == IMAGE_LOONGSON_ELF)
{
if (comp == COMPRESSION_NONE)
target_addr = (image_target->link_addr - decompress_size);
else
target_addr = ALIGN_UP (image_target->link_addr
+ kernel_size + total_module_size, 32);
}
else
target_addr = image_target->link_addr;
ehdr->e_entry = grub_host_to_target32 (target_addr);
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);
@ -1363,7 +1683,6 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
}
grub_util_write_image (core_img, core_size, out);
free (kernel_img);
free (core_img);
free (kernel_path);
@ -1407,12 +1726,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++ = ' ';
}
@ -1482,10 +1801,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);
@ -1580,35 +1901,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) = '/';
if (strncmp (image_target->name, "mipsel-yeeloong",
last - image_target->name) == 0)
{
memcpy (dir + sizeof (GRUB_PKGLIBROOTDIR), "mips-yeeloong",
sizeof ("mips-yeeloong"));
}
else
{
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

@ -27,12 +27,8 @@ libdir=@libdir@
PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
platform=@platform@
host_os=@host_os@
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
localedir=@datadir@/locale
native_platform=@platform@
pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
self=`basename $0`
@ -49,6 +45,12 @@ debug=no
debug_image=
subdir=`echo /boot/grub | sed ${transform}`
pc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-pc
ppc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/powerpc-ieee1275
sparc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/sparc64-ieee1275
i386_ieee1275_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-ieee1275
efi32_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-efi
efi64_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/x86_64-efi
itanium_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/ia64-efi
# Usage: usage
# Print the usage.
@ -64,7 +66,7 @@ Install GRUB on your drive.
--subdir=DIR relative subdirectory on network server
--grub-mkimage=FILE use FILE as grub-mkimage
$self copies GRUB images into net_directory/subdir/${target_cpu}-${platform}
$self copies GRUB images into net_directory/subdir/target_cpu-platform
Report bugs to <bug-grub@gnu.org>.
EOF
@ -200,11 +202,20 @@ process_input_dir ()
config_opt="-c ${grubdir}/load.cfg "
fi
prefix="/${subdir}/${platform}";
case "${platform}" in
i386-pc) mkimage_target=i386-pc-pxe;
netmodules="pxe";
prefix="(pxe)/${subdir}/${platform}";
ext=0 ;;
sparc64-ieee1275) mkimage_target=sparc64-ieee1275-aout;
netmodules="ofnet";
ext=img ;;
*-ieee1275) mkimage_target="${platform}";
netmodules="ofnet";
ext=elf ;;
*-efi) mkimage_target="${platform}";
netmodules="efinet";
ext=efi ;;
*) echo Unsupported platform ${platform};
exit 1;;
esac
@ -213,16 +224,35 @@ process_input_dir ()
source ${subdir}/grub.cfg
EOF
$grub_mkimage ${config_opt} -d "${input_dir}" -O ${mkimage_target} --output=${grubdir}/core.$ext --prefix=$prefix $modules $netmodules || exit 1
$grub_mkimage ${config_opt} -d "${input_dir}" -O ${mkimage_target} --output=${grubdir}/core.$ext --prefix=$prefix $modules $netmodules tftp || exit 1
echo "Netboot directory for ${platform} created. Configure your DHCP server to point to ${subdir}/${platform}/core.$ext"
}
if [ "${override_dir}" = "" ] ; then
if test -e "${pc_dir}" ; then
process_input_dir ${pc_dir} i386-pc
process_input_dir "${pc_dir}" i386-pc
fi
if test -e "${ppc_dir}" ; then
process_input_dir "${ppc_dir}" powerpc-ieee1275
fi
if test -e "${sparc_dir}" ; then
process_input_dir ${sparc_dir} sparc64-ieee1275
fi
if test -e "${i386_ieee1275_dir}" ; then
process_input_dir "${i386_ieee1275_dir}" i386-ieee1275
fi
if test -e "${efi32_dir}" ; then
process_input_dir "${efi32_dir}" i386-efi
fi
if test -e "${efi64_dir}" ; then
process_input_dir "${efi64_dir}" x86_64-efi
fi
if test -e "${itanium_dir}" ; then
process_input_dir "${itanium_dir}" ia64-efi
fi
else
process_input_dir ${override_dir} ${target_cpu}-${native_platform}
source "${override_dir}"/modinfo.sh
process_input_dir "${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform}
fi

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));
@ -270,7 +270,6 @@ main (int argc, char *argv[])
free (bufhex);
free (salthex);
free (salt);
fclose (f);
grub_util_error ("couldn't retrieve random data for salt");
}
fclose (f);

View file

@ -27,8 +27,6 @@ libdir=@libdir@
PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
native_platform=@platform@
pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
self=`basename $0`
@ -160,7 +158,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
@ -231,14 +229,15 @@ if [ "${override_dir}" = "" ] ; then
process_input_dir ${efi64_dir} x86_64-efi
fi
else
process_input_dir ${override_dir} ${target_cpu}-${native_platform}
. "${override_dir}"/modinfo.sh
process_input_dir "${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform}
multiboot_dir=
pc_dir=
efi32_dir=
efi64_dir=
coreboot_dir=
qemu_dir=
case "${target_cpu}-${native_platform}" in
case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
i386-multiboot) multiboot_dir=${override_dir} ;;
i386-coreboot) coreboot_dir=${override_dir} ;;
i386-qemu) qemu_dir=${override_dir} ;;
@ -276,7 +275,7 @@ if test -e "${pc_dir}" ; then
fi
# build multiboot core.img
make_image "${multiboot_dir}" i386-multiboot "${iso9660_dir}/boot/multiboot.img" "ata at_keyboard"
make_image "${multiboot_dir}" i386-multiboot "${iso9660_dir}/boot/multiboot.img" "pata ahci at_keyboard"
if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then
efi_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
@ -297,11 +296,11 @@ if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then
grub_mkisofs_arguments="${grub_mkisofs_arguments} --efi-boot efi.img"
fi
make_image "${qemu_dir}" i386-qemu "${iso9660_dir}/boot/qemu.img" "ata at_keyboard"
make_image "${qemu_dir}" i386-qemu "${iso9660_dir}/boot/qemu.img" "pata at_keyboard"
if [ -e "${iso9660_dir}/boot/qemu.img" ] && [ -d "${rom_directory}" ]; then
cp "${iso9660_dir}/boot/qemu.img" "${rom_directory}/qemu.img"
fi
make_image "${coreboot_dir}" i386-coreboot "${iso9660_dir}/boot/coreboot.elf" "ata at_keyboard"
make_image "${coreboot_dir}" i386-coreboot "${iso9660_dir}/boot/coreboot.elf" "pata ahci at_keyboard"
if [ -e "${iso9660_dir}/boot/coreboot.elf" ] && [ -d "${rom_directory}" ]; then
cp "${iso9660_dir}/boot/coreboot.elf" "${rom_directory}/coreboot.elf"
fi

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

@ -25,7 +25,7 @@ libdir=@libdir@
locale_dir=`echo ${GRUB_PREFIX}/locale | sed ${transform}`
grub_lang=`echo $LANG | cut -d . -f 1`
. ${libdir}/grub/grub-mkconfig_lib
. ${libdir}/@PACKAGE@/grub-mkconfig_lib
# Do this as early as possible, since other commands might depend on it.
# (e.g. the `loadfont' command might need lvm or raid modules)

View file

@ -20,7 +20,7 @@ set -e
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
. ${libdir}/grub/grub-mkconfig_lib
. ${libdir}/@PACKAGE@/grub-mkconfig_lib
CLASS="--class gnu --class os"

View file

@ -21,7 +21,7 @@ prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libdir=@libdir@
. ${libdir}/grub/grub-mkconfig_lib
. ${libdir}/@PACKAGE@/grub-mkconfig_lib
export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR=@localedir@

View file

@ -21,7 +21,7 @@ prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libdir=@libdir@
. ${libdir}/grub/grub-mkconfig_lib
. ${libdir}/@PACKAGE@/grub-mkconfig_lib
export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR=@localedir@
@ -98,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'
@ -131,6 +142,7 @@ case x`uname -m` in
esac
prepare_boot_cache=
prepare_root_cache=
while [ "x$list" != "x" ] ; do
linux=`version_find_latest $list`

View file

@ -21,7 +21,7 @@ prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libdir=@libdir@
. ${libdir}/grub/grub-mkconfig_lib
. ${libdir}/@PACKAGE@/grub-mkconfig_lib
export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR=@localedir@

View file

@ -20,7 +20,7 @@ set -e
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
. ${libdir}/grub/grub-mkconfig_lib
. ${libdir}/@PACKAGE@/grub-mkconfig_lib
case "`uname 2>/dev/null`" in
CYGWIN*) ;;

View file

@ -21,7 +21,7 @@ prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libdir=@libdir@
. ${libdir}/grub/grub-mkconfig_lib
. ${libdir}/@PACKAGE@/grub-mkconfig_lib
export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR=@localedir@
@ -51,6 +51,14 @@ else
LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
fi
# Allow overriding GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT.
if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE}" ]; then
GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX_XEN_REPLACE}"
fi
if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}" ]; then
GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}"
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#/}"

View file

@ -21,7 +21,7 @@ prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
. ${libdir}/grub/grub-mkconfig_lib
. ${libdir}/@PACKAGE@/grub-mkconfig_lib
if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
exit 0

View file

@ -32,11 +32,16 @@ int main(int argc, char **argv)
grub_util_init_nls ();
if (argc != 2)
if (argc != 2 || strcmp (argv[1], "--help") == 0)
{
printf("Usage: %s DEVICE\n", program_name);
return 1;
}
if (strcmp (argv[1], "--version") == 0)
{
printf ("%s\n", PACKAGE_STRING);
return 1;
}
of_path = grub_util_devname_to_ofpath (argv[1]);
printf("%s\n", of_path);

View file

@ -297,6 +297,7 @@ check_sas (char *sysfs_path, int *tgt)
free (path);
free (p);
close (fd);
}
static void
@ -419,6 +420,7 @@ int main(int argc, char **argv)
of_path = grub_util_devname_to_ofpath (argv[1]);
printf("%s\n", of_path);
free (of_path);
return 0;
}

View file

@ -18,6 +18,6 @@ prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
. ${libdir}/grub/grub-mkconfig_lib
. ${libdir}/@PACKAGE@/grub-mkconfig_lib
grub_warn "update-grub_lib is deprecated, use grub-mkconfig_lib instead"