mirror of
https://git.proxmox.com/git/grub2
synced 2025-07-21 07:40:30 +00:00

Currently multiboot2 protocol loads image exactly at address specified in ELF or multiboot2 header. This solution works quite well on legacy BIOS platforms. It is possible because memory regions are placed at predictable addresses (though I was not able to find any spec which says that it is strong requirement, so, it looks that it is just a goodwill of hardware designers). However, EFI platforms are more volatile. Even if required memory regions live at specific addresses then they are sometimes simply not free (e.g. used by boot/runtime services on Dell PowerEdge R820 and OVMF). This means that you are not able to just set up final image destination on build time. You have to provide method to relocate image contents to real load address which is usually different than load address specified in ELF and multiboot2 headers. This patch provides all needed machinery to do self relocation in image code. First of all GRUB2 reads min_addr (min. load addr), max_addr (max. load addr), align (required image alignment), preference (it says which memory regions are preferred by image, e.g. none, low, high) from multiboot_header_tag_relocatable header tag contained in binary (at this stage load addresses from multiboot2 and/or ELF headers are ignored). Later loader tries to fulfill request (not only that one) and if it succeeds then it informs image about real load address via multiboot_tag_load_base_addr tag. At this stage GRUB2 role is finished. Starting from now executable must cope with relocations itself using whole static and dynamic knowledge provided by boot loader. This patch does not provide functionality which could do relocations using ELF relocation data. However, I was asked by Konrad Rzeszutek Wilk and Vladimir 'phcoder' Serbinenko to investigate that thing. It looks that relevant machinery could be added to existing code (including this patch) without huge effort. Additionally, ELF relocation could live in parallel with self relocation provided by this patch. However, during research I realized that first of all we should establish the details how ELF relocatable image should look like and how it should be build. At least to build proper test/example files. So, this patch just provides support for self relocatable images. If ELF file with relocs is loaded then GRUB2 complains loudly and ignores it. Support for such files will be added later. This patch was tested with Xen image which uses that functionality. However, this Xen feature is still under development and new patchset will be released in about 2-3 weeks. Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com> Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
122 lines
3.6 KiB
C
122 lines
3.6 KiB
C
/* multiboot.h - multiboot header file with grub definitions. */
|
|
/*
|
|
* GRUB -- GRand Unified Bootloader
|
|
* Copyright (C) 2003,2007,2008,2010 Free Software Foundation, Inc.
|
|
*
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef GRUB_MULTIBOOT_HEADER
|
|
#define GRUB_MULTIBOOT_HEADER 1
|
|
|
|
#include <grub/file.h>
|
|
|
|
#ifdef GRUB_USE_MULTIBOOT2
|
|
#include <multiboot2.h>
|
|
/* Same thing as far as our loader is concerned. */
|
|
#define MULTIBOOT_BOOTLOADER_MAGIC MULTIBOOT2_BOOTLOADER_MAGIC
|
|
#define MULTIBOOT_HEADER_MAGIC MULTIBOOT2_HEADER_MAGIC
|
|
#else
|
|
#include <multiboot.h>
|
|
#endif
|
|
|
|
#include <grub/types.h>
|
|
#include <grub/err.h>
|
|
|
|
#ifndef GRUB_USE_MULTIBOOT2
|
|
typedef enum
|
|
{
|
|
GRUB_MULTIBOOT_QUIRKS_NONE = 0,
|
|
GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE = 1,
|
|
GRUB_MULTIBOOT_QUIRK_MODULES_AFTER_KERNEL = 2
|
|
} grub_multiboot_quirks_t;
|
|
extern grub_multiboot_quirks_t grub_multiboot_quirks;
|
|
#endif
|
|
|
|
extern struct grub_relocator *grub_multiboot_relocator;
|
|
|
|
void grub_multiboot (int argc, char *argv[]);
|
|
void grub_module (int argc, char *argv[]);
|
|
|
|
void grub_multiboot_set_accepts_video (int val);
|
|
grub_err_t grub_multiboot_make_mbi (grub_uint32_t *target);
|
|
void grub_multiboot_free_mbi (void);
|
|
grub_err_t grub_multiboot_init_mbi (int argc, char *argv[]);
|
|
grub_err_t grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
|
|
int argc, char *argv[]);
|
|
void grub_multiboot_set_bootdev (void);
|
|
void
|
|
grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,
|
|
unsigned shndx, void *data);
|
|
|
|
grub_uint32_t grub_get_multiboot_mmap_count (void);
|
|
grub_err_t grub_multiboot_set_video_mode (void);
|
|
|
|
/* FIXME: support coreboot as well. */
|
|
#if defined (GRUB_MACHINE_PCBIOS)
|
|
#define GRUB_MACHINE_HAS_VBE 1
|
|
#else
|
|
#define GRUB_MACHINE_HAS_VBE 0
|
|
#endif
|
|
|
|
#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_QEMU)
|
|
#define GRUB_MACHINE_HAS_VGA_TEXT 1
|
|
#else
|
|
#define GRUB_MACHINE_HAS_VGA_TEXT 0
|
|
#endif
|
|
|
|
#if defined (GRUB_MACHINE_EFI) || defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT)
|
|
#define GRUB_MACHINE_HAS_ACPI 1
|
|
#else
|
|
#define GRUB_MACHINE_HAS_ACPI 0
|
|
#endif
|
|
|
|
#define GRUB_MULTIBOOT_CONSOLE_EGA_TEXT 1
|
|
#define GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER 2
|
|
|
|
grub_err_t
|
|
grub_multiboot_set_console (int console_type, int accepted_consoles,
|
|
int width, int height, int depth,
|
|
int console_required);
|
|
grub_err_t
|
|
grub_multiboot_load (grub_file_t file, const char *filename);
|
|
|
|
struct mbi_load_data
|
|
{
|
|
grub_file_t file;
|
|
const char *filename;
|
|
void *buffer;
|
|
unsigned int mbi_ver;
|
|
int relocatable;
|
|
grub_uint32_t min_addr;
|
|
grub_uint32_t max_addr;
|
|
grub_size_t align;
|
|
grub_uint32_t preference;
|
|
grub_uint32_t link_base_addr;
|
|
grub_uint32_t load_base_addr;
|
|
int avoid_efi_boot_services;
|
|
};
|
|
typedef struct mbi_load_data mbi_load_data_t;
|
|
|
|
/* Load ELF32 or ELF64. */
|
|
grub_err_t
|
|
grub_multiboot_load_elf (mbi_load_data_t *mld);
|
|
|
|
extern grub_size_t grub_multiboot_pure_size;
|
|
extern grub_size_t grub_multiboot_alloc_mbi;
|
|
extern grub_uint32_t grub_multiboot_payload_eip;
|
|
|
|
|
|
#endif /* ! GRUB_MULTIBOOT_HEADER */
|