2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2009-02-24 13:19:46 +00:00
|
|
|
* Copyright (C) 2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-21 23:32:33 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-21 23:32:33 +00:00
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <grub/elf.h>
|
|
|
|
#include <grub/util/misc.h>
|
|
|
|
#include <grub/util/resolve.h>
|
|
|
|
#include <grub/kernel.h>
|
|
|
|
#include <grub/efi/pe32.h>
|
2007-06-21 21:01:11 +00:00
|
|
|
#include <grub/machine/kernel.h>
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
|
2009-06-27 03:01:42 +00:00
|
|
|
#if GRUB_TARGET_WORDSIZE == 32
|
|
|
|
# define grub_le_to_cpu(val) grub_le_to_cpu32(val)
|
|
|
|
#elif GRUB_TARGET_WORDSIZE == 64
|
|
|
|
# define grub_le_to_cpu(val) grub_le_to_cpu64(val)
|
2008-07-17 09:50:26 +00:00
|
|
|
#endif
|
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
static const grub_uint8_t stub[] = GRUB_PE32_MSDOS_STUB;
|
|
|
|
|
2008-07-17 09:50:26 +00:00
|
|
|
static inline Elf_Addr
|
|
|
|
align_address (Elf_Addr addr, unsigned alignment)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
|
|
|
return (addr + alignment - 1) & ~(alignment - 1);
|
|
|
|
}
|
|
|
|
|
2008-07-17 09:50:26 +00:00
|
|
|
static inline Elf_Addr
|
|
|
|
align_pe32_section (Elf_Addr addr)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
|
|
|
return align_address (addr, GRUB_PE32_SECTION_ALIGNMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the whole kernel image. Return the pointer to a read image,
|
|
|
|
and store the size in bytes in *SIZE. */
|
|
|
|
static char *
|
2009-06-04 19:32:46 +00:00
|
|
|
read_kernel_module (const char *dir, size_t *size)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
|
|
|
char *kernel_image;
|
|
|
|
char *kernel_path;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
kernel_path = grub_util_get_path (dir, "kernel.mod");
|
|
|
|
*size = grub_util_get_image_size (kernel_path);
|
|
|
|
kernel_image = grub_util_read_image (kernel_path);
|
|
|
|
free (kernel_path);
|
|
|
|
|
|
|
|
return kernel_image;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return if the ELF header is valid. */
|
|
|
|
static int
|
2008-07-17 09:50:26 +00:00
|
|
|
check_elf_header (Elf_Ehdr *e, size_t size)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
|
|
|
if (size < sizeof (*e)
|
|
|
|
|| e->e_ident[EI_MAG0] != ELFMAG0
|
|
|
|
|| e->e_ident[EI_MAG1] != ELFMAG1
|
|
|
|
|| e->e_ident[EI_MAG2] != ELFMAG2
|
|
|
|
|| e->e_ident[EI_MAG3] != ELFMAG3
|
|
|
|
|| e->e_ident[EI_VERSION] != EV_CURRENT
|
|
|
|
|| e->e_version != grub_cpu_to_le32 (EV_CURRENT)
|
2008-07-17 09:50:26 +00:00
|
|
|
|| ((e->e_ident[EI_CLASS] != ELFCLASS32) &&
|
|
|
|
(e->e_ident[EI_CLASS] != ELFCLASS64))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
|| e->e_ident[EI_DATA] != ELFDATA2LSB
|
2008-07-17 09:50:26 +00:00
|
|
|
|| ((e->e_machine != grub_cpu_to_le16 (EM_386)) &&
|
|
|
|
(e->e_machine != grub_cpu_to_le16 (EM_X86_64))))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the starting address right after the header,
|
|
|
|
aligned by the section alignment. Allocate 4 section tables for
|
|
|
|
.text, .data, .reloc, and mods. */
|
2008-07-17 09:50:26 +00:00
|
|
|
static Elf_Addr
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
get_starting_section_address (void)
|
|
|
|
{
|
|
|
|
return align_pe32_section (sizeof (struct grub_pe32_header)
|
|
|
|
+ 4 * sizeof (struct grub_pe32_section_table));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine if this section is a text section. Return false if this
|
|
|
|
section is not allocated. */
|
|
|
|
static int
|
2008-07-17 09:50:26 +00:00
|
|
|
is_text_section (Elf_Shdr *s)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
|
|
|
return ((s->sh_flags & grub_cpu_to_le32 (SHF_EXECINSTR | SHF_ALLOC))
|
|
|
|
== grub_cpu_to_le32 (SHF_EXECINSTR | SHF_ALLOC));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine if this section is a data section. This assumes that
|
|
|
|
BSS is also a data section, since the converter initializes BSS
|
|
|
|
when producing PE32 to avoid a bug in EFI implementations. */
|
|
|
|
static int
|
2008-07-17 09:50:26 +00:00
|
|
|
is_data_section (Elf_Shdr *s)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
|
|
|
return (s->sh_flags & grub_cpu_to_le32 (SHF_ALLOC)
|
|
|
|
&& ! (s->sh_flags & grub_cpu_to_le32 (SHF_EXECINSTR)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Locate section addresses by merging code sections and data sections
|
|
|
|
into .text and .data, respectively. Return the array of section
|
|
|
|
addresses. */
|
2008-07-17 09:50:26 +00:00
|
|
|
static Elf_Addr *
|
|
|
|
locate_sections (Elf_Shdr *sections, Elf_Half section_entsize,
|
|
|
|
Elf_Half num_sections, const char *strtab)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Addr current_address;
|
|
|
|
Elf_Addr *section_addresses;
|
|
|
|
Elf_Shdr *s;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
section_addresses = xmalloc (sizeof (*section_addresses) * num_sections);
|
|
|
|
memset (section_addresses, 0, sizeof (*section_addresses) * num_sections);
|
|
|
|
|
|
|
|
current_address = get_starting_section_address ();
|
|
|
|
|
|
|
|
/* .text */
|
|
|
|
for (i = 0, s = sections;
|
|
|
|
i < num_sections;
|
2008-07-17 09:50:26 +00:00
|
|
|
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (is_text_section (s))
|
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Word align = grub_le_to_cpu32 (s->sh_addralign);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
const char *name = strtab + grub_le_to_cpu32 (s->sh_name);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (align)
|
|
|
|
current_address = align_address (current_address, align);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
grub_util_info ("locating the section %s at 0x%x",
|
|
|
|
name, current_address);
|
|
|
|
section_addresses[i] = current_address;
|
|
|
|
current_address += grub_le_to_cpu32 (s->sh_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
current_address = align_pe32_section (current_address);
|
|
|
|
|
|
|
|
/* .data */
|
|
|
|
for (i = 0, s = sections;
|
|
|
|
i < num_sections;
|
2008-07-17 09:50:26 +00:00
|
|
|
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (is_data_section (s))
|
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Word align = grub_le_to_cpu32 (s->sh_addralign);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
const char *name = strtab + grub_le_to_cpu32 (s->sh_name);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (align)
|
|
|
|
current_address = align_address (current_address, align);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
grub_util_info ("locating the section %s at 0x%x",
|
|
|
|
name, current_address);
|
|
|
|
section_addresses[i] = current_address;
|
|
|
|
current_address += grub_le_to_cpu32 (s->sh_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return section_addresses;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the symbol table section, if any. */
|
2008-07-17 09:50:26 +00:00
|
|
|
static Elf_Shdr *
|
|
|
|
find_symtab_section (Elf_Shdr *sections,
|
|
|
|
Elf_Half section_entsize, Elf_Half num_sections)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Shdr *s;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
for (i = 0, s = sections;
|
|
|
|
i < num_sections;
|
2008-07-17 09:50:26 +00:00
|
|
|
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (s->sh_type == grub_cpu_to_le32 (SHT_SYMTAB))
|
|
|
|
return s;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the address of the string table. */
|
|
|
|
static const char *
|
2008-07-17 09:50:26 +00:00
|
|
|
find_strtab (Elf_Ehdr *e, Elf_Shdr *sections, Elf_Half section_entsize)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Shdr *s;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
char *strtab;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2008-07-17 09:50:26 +00:00
|
|
|
s = (Elf_Shdr *) ((char *) sections
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
+ grub_le_to_cpu16 (e->e_shstrndx) * section_entsize);
|
|
|
|
strtab = (char *) e + grub_le_to_cpu32 (s->sh_offset);
|
|
|
|
return strtab;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Relocate symbols; note that this function overwrites the symbol table.
|
|
|
|
Return the address of a start symbol. */
|
2008-07-17 09:50:26 +00:00
|
|
|
static Elf_Addr
|
|
|
|
relocate_symbols (Elf_Ehdr *e, Elf_Shdr *sections,
|
|
|
|
Elf_Shdr *symtab_section, Elf_Addr *section_addresses,
|
|
|
|
Elf_Half section_entsize, Elf_Half num_sections)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Word symtab_size, sym_size, num_syms;
|
|
|
|
Elf_Off symtab_offset;
|
|
|
|
Elf_Addr start_address = 0;
|
|
|
|
Elf_Sym *sym;
|
|
|
|
Elf_Word i;
|
|
|
|
Elf_Shdr *strtab_section;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
const char *strtab;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
strtab_section
|
2008-07-17 09:50:26 +00:00
|
|
|
= (Elf_Shdr *) ((char *) sections
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
+ (grub_le_to_cpu32 (symtab_section->sh_link)
|
|
|
|
* section_entsize));
|
|
|
|
strtab = (char *) e + grub_le_to_cpu32 (strtab_section->sh_offset);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
symtab_size = grub_le_to_cpu32 (symtab_section->sh_size);
|
|
|
|
sym_size = grub_le_to_cpu32 (symtab_section->sh_entsize);
|
|
|
|
symtab_offset = grub_le_to_cpu32 (symtab_section->sh_offset);
|
|
|
|
num_syms = symtab_size / sym_size;
|
|
|
|
|
2008-07-17 09:50:26 +00:00
|
|
|
for (i = 0, sym = (Elf_Sym *) ((char *) e + symtab_offset);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
i < num_syms;
|
2008-07-17 09:50:26 +00:00
|
|
|
i++, sym = (Elf_Sym *) ((char *) sym + sym_size))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Section index;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
const char *name;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
name = strtab + grub_le_to_cpu32 (sym->st_name);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
index = grub_le_to_cpu16 (sym->st_shndx);
|
2008-07-17 09:50:26 +00:00
|
|
|
if (index == STN_ABS)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if ((index == STN_UNDEF))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
|
|
|
if (sym->st_name)
|
|
|
|
grub_util_error ("undefined symbol %s", name);
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (index >= num_sections)
|
|
|
|
grub_util_error ("section %d does not exist", index);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
sym->st_value = (grub_le_to_cpu32 (sym->st_value)
|
|
|
|
+ section_addresses[index]);
|
|
|
|
grub_util_info ("locating %s at 0x%x", name, sym->st_value);
|
|
|
|
|
|
|
|
if (! start_address)
|
|
|
|
if (strcmp (name, "_start") == 0 || strcmp (name, "start") == 0)
|
|
|
|
start_address = sym->st_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return start_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the address of a symbol at the index I in the section S. */
|
2008-07-17 09:50:26 +00:00
|
|
|
static Elf_Addr
|
|
|
|
get_symbol_address (Elf_Ehdr *e, Elf_Shdr *s, Elf_Word i)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Sym *sym;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2008-07-17 09:50:26 +00:00
|
|
|
sym = (Elf_Sym *) ((char *) e
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
+ grub_le_to_cpu32 (s->sh_offset)
|
|
|
|
+ i * grub_le_to_cpu32 (s->sh_entsize));
|
|
|
|
return sym->st_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the address of a modified value. */
|
2008-07-17 09:50:26 +00:00
|
|
|
static Elf_Addr *
|
|
|
|
get_target_address (Elf_Ehdr *e, Elf_Shdr *s, Elf_Addr offset)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
return (Elf_Addr *) ((char *) e + grub_le_to_cpu32 (s->sh_offset) + offset);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
again by a PE32 relocator when loaded. */
|
|
|
|
static void
|
2008-07-17 09:50:26 +00:00
|
|
|
relocate_addresses (Elf_Ehdr *e, Elf_Shdr *sections,
|
|
|
|
Elf_Addr *section_addresses,
|
|
|
|
Elf_Half section_entsize, Elf_Half num_sections,
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
const char *strtab)
|
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Half i;
|
|
|
|
Elf_Shdr *s;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
for (i = 0, s = sections;
|
|
|
|
i < num_sections;
|
2008-07-17 09:50:26 +00:00
|
|
|
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)))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Rela *r;
|
|
|
|
Elf_Word rtab_size, r_size, num_rs;
|
|
|
|
Elf_Off rtab_offset;
|
|
|
|
Elf_Shdr *symtab_section;
|
|
|
|
Elf_Word target_section_index;
|
|
|
|
Elf_Addr target_section_addr;
|
|
|
|
Elf_Shdr *target_section;
|
|
|
|
Elf_Word j;
|
|
|
|
|
|
|
|
symtab_section = (Elf_Shdr *) ((char *) sections
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
+ (grub_le_to_cpu32 (s->sh_link)
|
|
|
|
* section_entsize));
|
|
|
|
target_section_index = grub_le_to_cpu32 (s->sh_info);
|
|
|
|
target_section_addr = section_addresses[target_section_index];
|
2008-07-17 09:50:26 +00:00
|
|
|
target_section = (Elf_Shdr *) ((char *) sections
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
+ (target_section_index
|
|
|
|
* section_entsize));
|
|
|
|
|
|
|
|
grub_util_info ("dealing with the relocation section %s for %s",
|
|
|
|
strtab + grub_le_to_cpu32 (s->sh_name),
|
|
|
|
strtab + grub_le_to_cpu32 (target_section->sh_name));
|
|
|
|
|
|
|
|
rtab_size = grub_le_to_cpu32 (s->sh_size);
|
|
|
|
r_size = grub_le_to_cpu32 (s->sh_entsize);
|
|
|
|
rtab_offset = grub_le_to_cpu32 (s->sh_offset);
|
|
|
|
num_rs = rtab_size / r_size;
|
|
|
|
|
2008-07-17 09:50:26 +00:00
|
|
|
for (j = 0, r = (Elf_Rela *) ((char *) e + rtab_offset);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
j < num_rs;
|
2008-07-17 09:50:26 +00:00
|
|
|
j++, r = (Elf_Rela *) ((char *) r + r_size))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Addr info;
|
|
|
|
Elf_Addr offset;
|
|
|
|
Elf_Addr sym_addr;
|
2009-06-04 19:32:46 +00:00
|
|
|
Elf_Addr *target;
|
|
|
|
Elf_Addr addend;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2008-07-17 09:50:26 +00:00
|
|
|
offset = grub_le_to_cpu (r->r_offset);
|
2008-07-16 06:55:42 +00:00
|
|
|
target = get_target_address (e, target_section, offset);
|
2008-07-17 09:50:26 +00:00
|
|
|
info = grub_le_to_cpu (r->r_info);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
sym_addr = get_symbol_address (e, symtab_section,
|
2008-07-17 09:50:26 +00:00
|
|
|
ELF_R_SYM (info));
|
|
|
|
|
2009-06-04 19:32:46 +00:00
|
|
|
addend = (s->sh_type == grub_cpu_to_le32 (SHT_RELA)) ?
|
|
|
|
r->r_addend : 0;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
|
2008-07-17 09:50:26 +00:00
|
|
|
switch (ELF_R_TYPE (info))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
#if GRUB_TARGET_SIZEOF_VOID_P == 4
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
case R_386_NONE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_386_32:
|
|
|
|
/* This is absolute. */
|
2009-06-04 19:32:46 +00:00
|
|
|
*target = grub_cpu_to_le32 (grub_le_to_cpu32 (*target)
|
|
|
|
+ addend + sym_addr);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
grub_util_info ("relocating an R_386_32 entry to 0x%x at the offset 0x%x",
|
|
|
|
*target, offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_386_PC32:
|
|
|
|
/* This is relative. */
|
2009-06-04 19:32:46 +00:00
|
|
|
*target = grub_cpu_to_le32 (grub_le_to_cpu32 (*target)
|
|
|
|
+ addend + sym_addr
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
- target_section_addr - offset);
|
|
|
|
grub_util_info ("relocating an R_386_PC32 entry to 0x%x at the offset 0x%x",
|
|
|
|
*target, offset);
|
|
|
|
break;
|
|
|
|
|
2008-07-17 09:50:26 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
case R_X86_64_NONE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_X86_64_64:
|
2009-06-10 21:04:23 +00:00
|
|
|
*target = grub_cpu_to_le64 (grub_le_to_cpu64 (*target)
|
2009-06-04 19:32:46 +00:00
|
|
|
+ addend + sym_addr);
|
2008-07-17 09:50:26 +00:00
|
|
|
grub_util_info ("relocating an R_X86_64_64 entry to 0x%llx at the offset 0x%llx",
|
|
|
|
*target, offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_X86_64_PC32:
|
|
|
|
{
|
|
|
|
grub_uint32_t *t32 = (grub_uint32_t *) target;
|
2009-06-04 19:32:46 +00:00
|
|
|
*t32 = grub_cpu_to_le64 (grub_le_to_cpu32 (*t32)
|
|
|
|
+ addend + sym_addr
|
2008-07-17 09:50:26 +00:00
|
|
|
- target_section_addr - offset);
|
|
|
|
grub_util_info ("relocating an R_X86_64_PC32 entry to 0x%x at the offset 0x%llx",
|
|
|
|
*t32, offset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case R_X86_64_32:
|
|
|
|
case R_X86_64_32S:
|
|
|
|
{
|
|
|
|
grub_uint32_t *t32 = (grub_uint32_t *) target;
|
2009-06-04 19:32:46 +00:00
|
|
|
*t32 = grub_cpu_to_le64 (grub_le_to_cpu32 (*t32)
|
|
|
|
+ addend + sym_addr);
|
2008-07-17 09:50:26 +00:00
|
|
|
grub_util_info ("relocating an R_X86_64_32(S) entry to 0x%x at the offset 0x%llx",
|
|
|
|
*t32, offset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
default:
|
|
|
|
grub_util_error ("unknown relocation type %d",
|
2008-07-17 09:50:26 +00:00
|
|
|
ELF_R_TYPE (info));
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
write_padding (FILE *out, size_t size)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
if (fputc (0, out) == EOF)
|
|
|
|
grub_util_error ("padding failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a PE32's fixup entry for a relocation. Return the resulting address
|
|
|
|
after having written to the file OUT. */
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Addr
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
add_fixup_entry (struct grub_pe32_fixup_block **block, grub_uint16_t type,
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Addr addr, int flush, Elf_Addr current_address,
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
FILE *out)
|
|
|
|
{
|
|
|
|
struct grub_pe32_fixup_block *b = *block;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
/* First, check if it is necessary to write out the current block. */
|
|
|
|
if (b)
|
|
|
|
{
|
|
|
|
if (flush || addr < b->page_rva || b->page_rva + 0x1000 <= addr)
|
|
|
|
{
|
|
|
|
grub_uint32_t size;
|
|
|
|
|
|
|
|
if (flush)
|
|
|
|
{
|
|
|
|
/* Add as much padding as necessary to align the address
|
|
|
|
with a section boundary. */
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Addr next_address;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
unsigned padding_size;
|
|
|
|
size_t index;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
next_address = current_address + b->block_size;
|
|
|
|
padding_size = ((align_pe32_section (next_address)
|
|
|
|
- next_address)
|
|
|
|
>> 1);
|
|
|
|
index = ((b->block_size - sizeof (*b)) >> 1);
|
|
|
|
grub_util_info ("adding %d padding fixup entries", padding_size);
|
|
|
|
while (padding_size--)
|
|
|
|
{
|
|
|
|
b->entries[index++] = 0;
|
|
|
|
b->block_size += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (b->block_size & (8 - 1))
|
|
|
|
{
|
|
|
|
/* If not aligned with a 32-bit boundary, add
|
|
|
|
a padding entry. */
|
|
|
|
size_t index;
|
|
|
|
|
|
|
|
grub_util_info ("adding a padding fixup entry");
|
|
|
|
index = ((b->block_size - sizeof (*b)) >> 1);
|
|
|
|
b->entries[index] = 0;
|
|
|
|
b->block_size += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flush it. */
|
|
|
|
grub_util_info ("writing %d bytes of a fixup block starting at 0x%x",
|
|
|
|
b->block_size, b->page_rva);
|
|
|
|
size = b->block_size;
|
|
|
|
current_address += size;
|
|
|
|
b->page_rva = grub_cpu_to_le32 (b->page_rva);
|
|
|
|
b->block_size = grub_cpu_to_le32 (b->block_size);
|
|
|
|
if (fwrite (b, size, 1, out) != 1)
|
|
|
|
grub_util_error ("write failed");
|
|
|
|
free (b);
|
|
|
|
*block = b = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! flush)
|
|
|
|
{
|
|
|
|
grub_uint16_t entry;
|
|
|
|
size_t index;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
/* If not allocated yet, allocate a block with enough entries. */
|
|
|
|
if (! b)
|
|
|
|
{
|
|
|
|
*block = b = xmalloc (sizeof (*b) + 2 * 0x1000);
|
|
|
|
|
|
|
|
/* The spec does not mention the requirement of a Page RVA.
|
|
|
|
Here, align the address with a 4K boundary for safety. */
|
|
|
|
b->page_rva = (addr & ~(0x1000 - 1));
|
|
|
|
b->block_size = sizeof (*b);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sanity check. */
|
|
|
|
if (b->block_size >= sizeof (*b) + 2 * 0x1000)
|
|
|
|
grub_util_error ("too many fixup entries");
|
|
|
|
|
|
|
|
/* Add a new entry. */
|
|
|
|
index = ((b->block_size - sizeof (*b)) >> 1);
|
|
|
|
entry = GRUB_PE32_FIXUP_ENTRY (type, addr - b->page_rva);
|
|
|
|
b->entries[index] = grub_cpu_to_le16 (entry);
|
|
|
|
b->block_size += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return current_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write out zeros to make space for the header. */
|
2008-07-17 09:50:26 +00:00
|
|
|
static Elf_Addr
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
make_header_space (FILE *out)
|
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Addr addr;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
addr = get_starting_section_address ();
|
|
|
|
write_padding (out, addr);
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write text sections. */
|
2008-07-17 09:50:26 +00:00
|
|
|
static Elf_Addr
|
|
|
|
write_text_sections (FILE *out, Elf_Addr current_address,
|
|
|
|
Elf_Ehdr *e, Elf_Shdr *sections,
|
|
|
|
Elf_Half section_entsize, Elf_Half num_sections,
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
const char *strtab)
|
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Half i;
|
|
|
|
Elf_Shdr *s;
|
|
|
|
Elf_Addr addr;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
for (i = 0, s = sections;
|
|
|
|
i < num_sections;
|
2008-07-17 09:50:26 +00:00
|
|
|
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (is_text_section (s))
|
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Word align = grub_le_to_cpu32 (s->sh_addralign);
|
|
|
|
Elf_Off offset = grub_le_to_cpu32 (s->sh_offset);
|
|
|
|
Elf_Word size = grub_le_to_cpu32 (s->sh_size);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
const char *name = strtab + grub_le_to_cpu32 (s->sh_name);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (align)
|
|
|
|
{
|
|
|
|
addr = align_address (current_address, align);
|
|
|
|
if (current_address != addr)
|
|
|
|
{
|
|
|
|
grub_util_info ("padding %d bytes for the ELF section alignment",
|
|
|
|
addr - current_address);
|
|
|
|
write_padding (out, addr - current_address);
|
|
|
|
current_address = addr;
|
|
|
|
}
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
grub_util_info ("writing the text section %s at 0x%x",
|
|
|
|
name, current_address);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (fwrite ((char *) e + offset, size, 1, out) != 1)
|
|
|
|
grub_util_error ("write failed");
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
current_address += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = align_pe32_section (current_address);
|
|
|
|
if (addr != current_address)
|
|
|
|
{
|
|
|
|
grub_util_info ("padding %d bytes for the PE32 section alignment",
|
|
|
|
addr - current_address);
|
|
|
|
write_padding (out, addr - current_address);
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write data sections. */
|
2008-07-17 09:50:26 +00:00
|
|
|
static Elf_Addr
|
|
|
|
write_data_sections (FILE *out, Elf_Addr current_address,
|
|
|
|
Elf_Ehdr *e, Elf_Shdr *sections,
|
|
|
|
Elf_Half section_entsize, Elf_Half num_sections,
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
const char *strtab)
|
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Half i;
|
|
|
|
Elf_Shdr *s;
|
|
|
|
Elf_Addr addr;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
for (i = 0, s = sections;
|
|
|
|
i < num_sections;
|
2008-07-17 09:50:26 +00:00
|
|
|
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (is_data_section (s))
|
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Word align = grub_le_to_cpu32 (s->sh_addralign);
|
|
|
|
Elf_Off offset = grub_le_to_cpu32 (s->sh_offset);
|
|
|
|
Elf_Word size = grub_le_to_cpu32 (s->sh_size);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
const char *name = strtab + grub_le_to_cpu32 (s->sh_name);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (align)
|
|
|
|
{
|
|
|
|
addr = align_address (current_address, align);
|
|
|
|
if (current_address != addr)
|
|
|
|
{
|
|
|
|
grub_util_info ("padding %d bytes for the ELF section alignment",
|
|
|
|
addr - current_address);
|
|
|
|
write_padding (out, addr - current_address);
|
|
|
|
current_address = addr;
|
|
|
|
}
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
grub_util_info ("writing the data section %s at 0x%x",
|
|
|
|
name, current_address);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (s->sh_type == grub_cpu_to_le32 (SHT_NOBITS))
|
|
|
|
write_padding (out, size);
|
|
|
|
else
|
|
|
|
if (fwrite ((char *) e + offset, size, 1, out) != 1)
|
|
|
|
grub_util_error ("write failed");
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
current_address += size;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
addr = align_pe32_section (current_address);
|
|
|
|
if (addr != current_address)
|
|
|
|
{
|
|
|
|
grub_util_info ("padding %d bytes for the PE32 section alignment",
|
|
|
|
addr - current_address);
|
|
|
|
write_padding (out, addr - current_address);
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write modules. */
|
2008-07-17 09:50:26 +00:00
|
|
|
static Elf_Addr
|
|
|
|
make_mods_section (FILE *out, Elf_Addr current_address,
|
2006-04-20 04:29:17 +00:00
|
|
|
const char *dir, char *mods[])
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
2006-04-20 04:29:17 +00:00
|
|
|
struct grub_util_path_list *path_list;
|
|
|
|
grub_size_t total_module_size;
|
|
|
|
struct grub_util_path_list *p;
|
|
|
|
struct grub_module_info modinfo;
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Addr addr;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
|
2009-06-04 19:32:46 +00:00
|
|
|
memset (&modinfo, 0, sizeof (modinfo));
|
|
|
|
|
2006-04-20 04:29:17 +00:00
|
|
|
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-20 04:29:17 +00:00
|
|
|
total_module_size = sizeof (struct grub_module_info);
|
|
|
|
for (p = path_list; p; p = p->next)
|
|
|
|
{
|
|
|
|
total_module_size += (grub_util_get_image_size (p->name)
|
|
|
|
+ sizeof (struct grub_module_header));
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_util_info ("the total module size is 0x%x", total_module_size);
|
|
|
|
|
|
|
|
modinfo.magic = grub_cpu_to_le32 (GRUB_MODULE_MAGIC);
|
|
|
|
modinfo.offset = grub_cpu_to_le32 (sizeof (modinfo));
|
|
|
|
modinfo.size = grub_cpu_to_le32 (total_module_size);
|
|
|
|
|
|
|
|
if (fwrite (&modinfo, sizeof (modinfo), 1, out) != 1)
|
|
|
|
grub_util_error ("write failed");
|
|
|
|
|
|
|
|
for (p = path_list; p; p = p->next)
|
|
|
|
{
|
|
|
|
struct grub_module_header header;
|
|
|
|
size_t mod_size;
|
|
|
|
char *mod_image;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-06-04 19:32:46 +00:00
|
|
|
memset (&header, 0, sizeof (header));
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-20 04:29:17 +00:00
|
|
|
grub_util_info ("adding module %s", p->name);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-20 04:29:17 +00:00
|
|
|
mod_size = grub_util_get_image_size (p->name);
|
2008-08-02 12:17:44 +00:00
|
|
|
header.type = grub_cpu_to_le32 (OBJ_TYPE_ELF);
|
2006-04-20 04:29:17 +00:00
|
|
|
header.size = grub_cpu_to_le32 (mod_size + sizeof (header));
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-20 04:29:17 +00:00
|
|
|
mod_image = grub_util_read_image (p->name);
|
|
|
|
|
|
|
|
if (fwrite (&header, sizeof (header), 1, out) != 1
|
|
|
|
|| fwrite (mod_image, mod_size, 1, out) != 1)
|
|
|
|
grub_util_error ("write failed");
|
|
|
|
|
|
|
|
free (mod_image);
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-20 04:29:17 +00:00
|
|
|
for (p = path_list; p; )
|
|
|
|
{
|
|
|
|
struct grub_util_path_list *q;
|
|
|
|
|
|
|
|
q = p->next;
|
|
|
|
free (p);
|
|
|
|
p = q;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-20 04:29:17 +00:00
|
|
|
current_address += total_module_size;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-20 04:29:17 +00:00
|
|
|
addr = align_pe32_section (current_address);
|
|
|
|
if (addr != current_address)
|
|
|
|
{
|
|
|
|
grub_util_info ("padding %d bytes for the PE32 section alignment",
|
|
|
|
addr - current_address);
|
|
|
|
write_padding (out, addr - current_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
return addr;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make a .reloc section. */
|
2008-07-17 09:50:26 +00:00
|
|
|
static Elf_Addr
|
|
|
|
make_reloc_section (FILE *out, Elf_Addr current_address, Elf_Ehdr *e,
|
|
|
|
Elf_Addr *section_addresses, Elf_Shdr *sections,
|
|
|
|
Elf_Half section_entsize, Elf_Half num_sections,
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
const char *strtab)
|
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Half i;
|
|
|
|
Elf_Shdr *s;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
struct grub_pe32_fixup_block *fixup_block = 0;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
for (i = 0, s = sections;
|
|
|
|
i < num_sections;
|
2008-07-17 09:50:26 +00:00
|
|
|
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)))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Rel *r;
|
|
|
|
Elf_Word rtab_size, r_size, num_rs;
|
|
|
|
Elf_Off rtab_offset;
|
|
|
|
Elf_Addr section_address;
|
|
|
|
Elf_Word j;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
grub_util_info ("translating the relocation section %s",
|
|
|
|
strtab + grub_le_to_cpu32 (s->sh_name));
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
rtab_size = grub_le_to_cpu32 (s->sh_size);
|
|
|
|
r_size = grub_le_to_cpu32 (s->sh_entsize);
|
|
|
|
rtab_offset = grub_le_to_cpu32 (s->sh_offset);
|
|
|
|
num_rs = rtab_size / r_size;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
section_address = section_addresses[grub_le_to_cpu32 (s->sh_info)];
|
|
|
|
|
2008-07-17 09:50:26 +00:00
|
|
|
for (j = 0, r = (Elf_Rel *) ((char *) e + rtab_offset);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
j < num_rs;
|
2008-07-17 09:50:26 +00:00
|
|
|
j++, r = (Elf_Rel *) ((char *) r + r_size))
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Addr info;
|
|
|
|
Elf_Addr offset;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
|
|
|
|
offset = grub_le_to_cpu32 (r->r_offset);
|
|
|
|
info = grub_le_to_cpu32 (r->r_info);
|
|
|
|
|
|
|
|
/* Necessary to relocate only absolute addresses. */
|
2008-07-17 09:50:26 +00:00
|
|
|
#if GRUB_TARGET_SIZEOF_VOID_P == 4
|
|
|
|
if (ELF_R_TYPE (info) == R_386_32)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Addr addr;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
|
|
|
|
addr = section_address + offset;
|
|
|
|
grub_util_info ("adding a relocation entry for 0x%x", addr);
|
|
|
|
current_address = add_fixup_entry (&fixup_block,
|
|
|
|
GRUB_PE32_REL_BASED_HIGHLOW,
|
|
|
|
addr, 0, current_address,
|
|
|
|
out);
|
|
|
|
}
|
2008-07-17 09:50:26 +00:00
|
|
|
#else
|
2009-02-24 13:19:46 +00:00
|
|
|
if ((ELF_R_TYPE (info) == R_X86_64_32) ||
|
2008-07-17 09:50:26 +00:00
|
|
|
(ELF_R_TYPE (info) == R_X86_64_32S))
|
2009-02-24 13:19:46 +00:00
|
|
|
{
|
|
|
|
grub_util_error ("Can\'t add fixup entry for R_X86_64_32(S)");
|
|
|
|
}
|
|
|
|
else if (ELF_R_TYPE (info) == R_X86_64_64)
|
2008-07-17 09:50:26 +00:00
|
|
|
{
|
|
|
|
Elf_Addr addr;
|
|
|
|
|
|
|
|
addr = section_address + offset;
|
|
|
|
grub_util_info ("adding a relocation entry for 0x%llx", addr);
|
|
|
|
current_address = add_fixup_entry (&fixup_block,
|
2009-02-24 13:19:46 +00:00
|
|
|
GRUB_PE32_REL_BASED_DIR64,
|
|
|
|
addr,
|
|
|
|
0, current_address,
|
2008-07-17 09:50:26 +00:00
|
|
|
out);
|
|
|
|
}
|
|
|
|
#endif
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
current_address = add_fixup_entry (&fixup_block, 0, 0, 1,
|
|
|
|
current_address, out);
|
|
|
|
|
|
|
|
return current_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the header. */
|
|
|
|
static void
|
2008-07-17 09:50:26 +00:00
|
|
|
make_header (FILE *out, Elf_Addr text_address, Elf_Addr data_address,
|
|
|
|
Elf_Addr mods_address, Elf_Addr reloc_address,
|
|
|
|
Elf_Addr end_address, Elf_Addr start_address)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
|
|
|
struct grub_pe32_header header;
|
|
|
|
struct grub_pe32_coff_header *c;
|
|
|
|
struct grub_pe32_optional_header *o;
|
|
|
|
struct grub_pe32_section_table text_section, data_section;
|
|
|
|
struct grub_pe32_section_table mods_section, reloc_section;
|
|
|
|
|
|
|
|
/* The magic. */
|
|
|
|
memset (&header, 0, sizeof (header));
|
|
|
|
memcpy (header.msdos_stub, stub, sizeof (header.msdos_stub));
|
|
|
|
memcpy (header.signature, "PE\0\0", sizeof (header.signature));
|
|
|
|
|
|
|
|
/* The COFF file header. */
|
|
|
|
c = &header.coff_header;
|
2008-07-17 09:50:26 +00:00
|
|
|
#if GRUB_TARGET_SIZEOF_VOID_P == 4
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
c->machine = grub_cpu_to_le16 (GRUB_PE32_MACHINE_I386);
|
2008-07-17 09:50:26 +00:00
|
|
|
#else
|
|
|
|
c->machine = grub_cpu_to_le16 (GRUB_PE32_MACHINE_X86_64);
|
|
|
|
#endif
|
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
c->num_sections = grub_cpu_to_le16 (4);
|
|
|
|
c->time = grub_cpu_to_le32 (time (0));
|
|
|
|
c->optional_header_size = grub_cpu_to_le16 (sizeof (header.optional_header));
|
|
|
|
c->characteristics = grub_cpu_to_le16 (GRUB_PE32_EXECUTABLE_IMAGE
|
|
|
|
| GRUB_PE32_LINE_NUMS_STRIPPED
|
2008-07-17 09:50:26 +00:00
|
|
|
#if GRUB_TARGET_SIZEOF_VOID_P == 4
|
|
|
|
| GRUB_PE32_32BIT_MACHINE
|
|
|
|
#endif
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
| GRUB_PE32_LOCAL_SYMS_STRIPPED
|
2008-07-17 09:50:26 +00:00
|
|
|
| GRUB_PE32_DEBUG_STRIPPED);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
|
|
|
|
/* The PE Optional header. */
|
|
|
|
o = &header.optional_header;
|
|
|
|
o->magic = grub_cpu_to_le16 (GRUB_PE32_PE32_MAGIC);
|
|
|
|
o->code_size = grub_cpu_to_le32 (data_address - text_address);
|
|
|
|
o->data_size = grub_cpu_to_le32 (reloc_address - data_address);
|
|
|
|
o->bss_size = 0;
|
|
|
|
o->entry_addr = grub_cpu_to_le32 (start_address);
|
|
|
|
o->code_base = grub_cpu_to_le32 (text_address);
|
2008-07-17 09:50:26 +00:00
|
|
|
#if GRUB_TARGET_SIZEOF_VOID_P == 4
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
o->data_base = grub_cpu_to_le32 (data_address);
|
2008-07-17 09:50:26 +00:00
|
|
|
#endif
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
o->image_base = 0;
|
|
|
|
o->section_alignment = grub_cpu_to_le32 (GRUB_PE32_SECTION_ALIGNMENT);
|
|
|
|
o->file_alignment = grub_cpu_to_le32 (GRUB_PE32_FILE_ALIGNMENT);
|
|
|
|
o->image_size = grub_cpu_to_le32 (end_address);
|
|
|
|
o->header_size = grub_cpu_to_le32 (text_address);
|
|
|
|
o->subsystem = grub_cpu_to_le16 (GRUB_PE32_SUBSYSTEM_EFI_APPLICATION);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
/* Do these really matter? */
|
|
|
|
o->stack_reserve_size = grub_cpu_to_le32 (0x10000);
|
|
|
|
o->stack_commit_size = grub_cpu_to_le32 (0x10000);
|
|
|
|
o->heap_reserve_size = grub_cpu_to_le32 (0x10000);
|
|
|
|
o->heap_commit_size = grub_cpu_to_le32 (0x10000);
|
|
|
|
|
|
|
|
o->num_data_directories = grub_cpu_to_le32 (GRUB_PE32_NUM_DATA_DIRECTORIES);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
o->base_relocation_table.rva = grub_cpu_to_le32 (reloc_address);
|
|
|
|
o->base_relocation_table.size = grub_cpu_to_le32 (end_address
|
|
|
|
- reloc_address);
|
|
|
|
|
|
|
|
/* The sections. */
|
|
|
|
memset (&text_section, 0, sizeof (text_section));
|
|
|
|
strcpy (text_section.name, ".text");
|
|
|
|
text_section.virtual_size = grub_cpu_to_le32 (data_address - text_address);
|
|
|
|
text_section.virtual_address = grub_cpu_to_le32 (text_address);
|
|
|
|
text_section.raw_data_size = grub_cpu_to_le32 (data_address - text_address);
|
|
|
|
text_section.raw_data_offset = grub_cpu_to_le32 (text_address);
|
|
|
|
text_section.characteristics = grub_cpu_to_le32 (GRUB_PE32_SCN_CNT_CODE
|
|
|
|
| GRUB_PE32_SCN_MEM_EXECUTE
|
|
|
|
| GRUB_PE32_SCN_MEM_READ);
|
|
|
|
|
|
|
|
memset (&data_section, 0, sizeof (data_section));
|
|
|
|
strcpy (data_section.name, ".data");
|
|
|
|
data_section.virtual_size = grub_cpu_to_le32 (mods_address - data_address);
|
|
|
|
data_section.virtual_address = grub_cpu_to_le32 (data_address);
|
|
|
|
data_section.raw_data_size = grub_cpu_to_le32 (mods_address - data_address);
|
|
|
|
data_section.raw_data_offset = grub_cpu_to_le32 (data_address);
|
|
|
|
data_section.characteristics
|
|
|
|
= grub_cpu_to_le32 (GRUB_PE32_SCN_CNT_INITIALIZED_DATA
|
|
|
|
| GRUB_PE32_SCN_MEM_READ
|
|
|
|
| GRUB_PE32_SCN_MEM_WRITE);
|
|
|
|
|
|
|
|
memset (&mods_section, 0, sizeof (mods_section));
|
|
|
|
strcpy (mods_section.name, "mods");
|
|
|
|
mods_section.virtual_size = grub_cpu_to_le32 (reloc_address - mods_address);
|
|
|
|
mods_section.virtual_address = grub_cpu_to_le32 (mods_address);
|
|
|
|
mods_section.raw_data_size = grub_cpu_to_le32 (reloc_address - mods_address);
|
|
|
|
mods_section.raw_data_offset = grub_cpu_to_le32 (mods_address);
|
|
|
|
mods_section.characteristics
|
|
|
|
= grub_cpu_to_le32 (GRUB_PE32_SCN_CNT_INITIALIZED_DATA
|
|
|
|
| GRUB_PE32_SCN_MEM_READ
|
|
|
|
| GRUB_PE32_SCN_MEM_WRITE);
|
|
|
|
|
|
|
|
memset (&reloc_section, 0, sizeof (reloc_section));
|
|
|
|
strcpy (reloc_section.name, ".reloc");
|
|
|
|
reloc_section.virtual_size = grub_cpu_to_le32 (end_address - reloc_address);
|
|
|
|
reloc_section.virtual_address = grub_cpu_to_le32 (reloc_address);
|
|
|
|
reloc_section.raw_data_size = grub_cpu_to_le32 (end_address - reloc_address);
|
|
|
|
reloc_section.raw_data_offset = grub_cpu_to_le32 (reloc_address);
|
|
|
|
reloc_section.characteristics
|
|
|
|
= grub_cpu_to_le32 (GRUB_PE32_SCN_CNT_INITIALIZED_DATA
|
|
|
|
| GRUB_PE32_SCN_MEM_DISCARDABLE
|
|
|
|
| GRUB_PE32_SCN_MEM_READ);
|
|
|
|
|
|
|
|
/* Write them out. */
|
2008-04-02 01:49:18 +00:00
|
|
|
if (fseeko (out, 0, SEEK_SET) < 0)
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
grub_util_error ("seek failed");
|
|
|
|
|
|
|
|
if (fwrite (&header, sizeof (header), 1, out) != 1
|
|
|
|
|| fwrite (&text_section, sizeof (text_section), 1, out) != 1
|
|
|
|
|| fwrite (&data_section, sizeof (data_section), 1, out) != 1
|
|
|
|
|| fwrite (&mods_section, sizeof (mods_section), 1, out) != 1
|
|
|
|
|| fwrite (&reloc_section, sizeof (reloc_section), 1, out) != 1)
|
|
|
|
grub_util_error ("write failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert an ELF relocatable object into an EFI Application (PE32). */
|
|
|
|
void
|
2007-06-21 21:01:11 +00:00
|
|
|
convert_elf (const char *dir, char *prefix, FILE *out, char *mods[])
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{
|
|
|
|
char *kernel_image;
|
|
|
|
size_t kernel_size;
|
|
|
|
const char *strtab;
|
2008-07-17 09:50:26 +00:00
|
|
|
Elf_Ehdr *e;
|
|
|
|
Elf_Shdr *sections;
|
|
|
|
Elf_Off section_offset;
|
|
|
|
Elf_Half section_entsize;
|
|
|
|
Elf_Half num_sections;
|
|
|
|
Elf_Addr *section_addresses;
|
|
|
|
Elf_Shdr *symtab_section;
|
|
|
|
Elf_Addr start_address;
|
|
|
|
Elf_Addr text_address, data_address, reloc_address, mods_address;
|
|
|
|
Elf_Addr end_address;
|
2009-06-04 19:32:46 +00:00
|
|
|
Elf_Shdr *s;
|
|
|
|
int i;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
|
|
|
|
/* Get the kernel image and check the format. */
|
2009-06-04 19:32:46 +00:00
|
|
|
kernel_image = read_kernel_module (dir, &kernel_size);
|
2008-07-17 09:50:26 +00:00
|
|
|
e = (Elf_Ehdr *) kernel_image;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (! check_elf_header (e, kernel_size))
|
|
|
|
grub_util_error ("invalid ELF header");
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
section_offset = grub_cpu_to_le32 (e->e_shoff);
|
|
|
|
section_entsize = grub_cpu_to_le16 (e->e_shentsize);
|
|
|
|
num_sections = grub_cpu_to_le16 (e->e_shnum);
|
2008-07-17 09:50:26 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (kernel_size < section_offset + section_entsize * num_sections)
|
|
|
|
grub_util_error ("invalid ELF format");
|
|
|
|
|
2008-07-17 09:50:26 +00:00
|
|
|
sections = (Elf_Shdr *) (kernel_image + section_offset);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
strtab = find_strtab (e, sections, section_entsize);
|
|
|
|
|
2009-06-04 19:32:46 +00:00
|
|
|
for (i = 0, s = sections;
|
|
|
|
i < num_sections;
|
|
|
|
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
|
|
|
if (is_text_section (s))
|
|
|
|
{
|
|
|
|
Elf_Off offset = grub_le_to_cpu32 (s->sh_offset);
|
|
|
|
|
|
|
|
if (GRUB_KERNEL_MACHINE_PREFIX + strlen (prefix) + 1 > GRUB_KERNEL_MACHINE_DATA_END)
|
|
|
|
grub_util_error ("prefix too long");
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-06-04 19:32:46 +00:00
|
|
|
strcpy (kernel_image + offset + GRUB_KERNEL_MACHINE_PREFIX, prefix);
|
|
|
|
break;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
/* Relocate sections then symbols in the virtual address space. */
|
|
|
|
section_addresses = locate_sections (sections, section_entsize,
|
|
|
|
num_sections, strtab);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
symtab_section = find_symtab_section (sections,
|
|
|
|
section_entsize, num_sections);
|
|
|
|
if (! symtab_section)
|
|
|
|
grub_util_error ("no symbol table");
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
start_address = relocate_symbols (e, sections, symtab_section,
|
|
|
|
section_addresses, section_entsize,
|
|
|
|
num_sections);
|
|
|
|
if (start_address == 0)
|
|
|
|
grub_util_error ("start symbol is not defined");
|
|
|
|
|
|
|
|
/* Resolve addresses in the virtual address space. */
|
|
|
|
relocate_addresses (e, sections, section_addresses, section_entsize,
|
|
|
|
num_sections, strtab);
|
|
|
|
|
|
|
|
/* Generate a PE32 image file. The strategy is to dump binary data first,
|
|
|
|
then fill up the header. */
|
|
|
|
text_address = make_header_space (out);
|
|
|
|
data_address = write_text_sections (out, text_address, e, sections,
|
|
|
|
section_entsize, num_sections,
|
|
|
|
strtab);
|
|
|
|
mods_address = write_data_sections (out, data_address, e, sections,
|
|
|
|
section_entsize, num_sections,
|
|
|
|
strtab);
|
2006-04-20 04:29:17 +00:00
|
|
|
reloc_address = make_mods_section (out, mods_address, dir, mods);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
end_address = make_reloc_section (out, reloc_address, e, section_addresses,
|
|
|
|
sections, section_entsize, num_sections,
|
|
|
|
strtab);
|
|
|
|
make_header (out, text_address, data_address, mods_address,
|
|
|
|
reloc_address, end_address, start_address);
|
|
|
|
|
|
|
|
/* Clean up. */
|
|
|
|
free (section_addresses);
|
|
|
|
free (kernel_image);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct option options[] =
|
|
|
|
{
|
|
|
|
{"directory", required_argument, 0, 'd'},
|
2007-06-21 21:01:11 +00:00
|
|
|
{"prefix", required_argument, 0, 'p'},
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
{"output", required_argument, 0, 'o'},
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"version", no_argument, 0, 'V'},
|
|
|
|
{"verbose", no_argument, 0, 'v'},
|
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage (int status)
|
|
|
|
{
|
|
|
|
if (status)
|
|
|
|
fprintf (stderr, "Try ``grub-mkimage --help'' for more information.\n");
|
|
|
|
else
|
|
|
|
printf ("\
|
|
|
|
Usage: grub-mkimage -o FILE [OPTION]... [MODULES]\n\
|
|
|
|
\n\
|
|
|
|
Make a bootable image of GRUB.\n\
|
|
|
|
\n\
|
2009-06-17 06:07:36 +00:00
|
|
|
-d, --directory=DIR use images and modules under DIR [default=%s]\n\
|
|
|
|
-p, --prefix=DIR set grub_prefix directory [default=%s]\n\
|
|
|
|
-o, --output=FILE output a generated image to FILE\n\
|
|
|
|
-h, --help display this message and exit\n\
|
|
|
|
-V, --version print version information and exit\n\
|
|
|
|
-v, --verbose print verbose messages\n\
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
\n\
|
|
|
|
Report bugs to <%s>.\n\
|
2007-06-21 21:01:11 +00:00
|
|
|
", GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
|
|
|
|
exit (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char *output = NULL;
|
|
|
|
char *dir = NULL;
|
2007-06-21 21:01:11 +00:00
|
|
|
char *prefix = NULL;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
|
|
|
|
progname = "grub-mkimage";
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2007-06-21 21:01:11 +00:00
|
|
|
int c = getopt_long (argc, argv, "d:p:o:hVv", options, 0);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'd':
|
|
|
|
if (dir)
|
|
|
|
free (dir);
|
|
|
|
dir = xstrdup (optarg);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage (0);
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (output)
|
|
|
|
free (output);
|
|
|
|
output = xstrdup (optarg);
|
|
|
|
break;
|
2007-06-21 21:01:11 +00:00
|
|
|
case 'p':
|
|
|
|
if (prefix)
|
|
|
|
free (prefix);
|
|
|
|
prefix = xstrdup (optarg);
|
|
|
|
break;
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
case 'V':
|
|
|
|
printf ("grub-mkimage (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION);
|
|
|
|
return 0;
|
|
|
|
case 'v':
|
|
|
|
verbosity++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage (1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! output)
|
|
|
|
usage (1);
|
|
|
|
|
|
|
|
fp = fopen (output, "wb");
|
|
|
|
if (! fp)
|
|
|
|
grub_util_error ("cannot open %s", output);
|
|
|
|
|
2007-06-21 21:01:11 +00:00
|
|
|
convert_elf (dir ? : GRUB_LIBDIR, prefix ? : DEFAULT_DIRECTORY, fp, argv + optind);
|
2006-04-18 Yoshinori K. Okuji <okuji@enbug.org>
* DISTLIST: Added conf/i386-efi.mk, conf/i386-efi.rmk,
include/grub/efi/api.h, include/grub/efi/console_control.h,
include/grub/efi/efi.h, include/grub/efi/pe32.h,
include/grub/i386/efi/time.h, kern/efi/efi.c,
kern/i386/efi/init.c, kern/i386/efi/startup.S,
and util/i386/efi/grub-mkimage.c.
* Makefile.in (RMKFILES): Added i386-efi.rmk.
* genmk.rb (PModule#rule): Do not export symbols if
#{prefix}_EXPORTS is set to "no".
* conf/i386-efi.mk: New file.
* conf/i386-efi.rmk: Likewise.
* include/grub/efi/api.h: Likewise.
* include/grub/efi/console_control.h: Likewise.
* include/grub/efi/efi.h: Likewise.
* include/grub/efi/pe32.h: Likewise.
* include/grub/i386/efi/time.h: Likewise.
* kern/efi/efi.c: Likewise.
* kern/i386/efi/init.c: Likewise.
* kern/i386/efi/startup.S: Likewise.
* util/i386/efi/grub-mkimage.c: Likewise.
2006-04-18 06:18:15 +00:00
|
|
|
|
|
|
|
fclose (fp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|