grub2/0014-mkimage-Pass-layout-to-mkimage_generate_elfXX-rather.patch
Peter Jones 31cddd6fc0 Add some features to do-rebase
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-07-10 15:11:55 -04:00

166 lines
8.0 KiB
Diff

From a35ac854308b0af7c86c2c7b199f6abdfa2110b0 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <phcoder@gmail.com>
Date: Mon, 8 May 2017 17:32:15 +0200
Subject: [PATCH] mkimage: Pass layout to mkimage_generate_elfXX rather than
some fields.
This allows easier extension of this function without having too long of
arguments list.
---
util/grub-mkimagexx.c | 35 ++++++++++++++++++-----------------
util/mkimage.c | 4 ++--
include/grub/util/mkimage.h | 8 ++++----
3 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
index e63f148e48c..3fab93e2088 100644
--- a/util/grub-mkimagexx.c
+++ b/util/grub-mkimagexx.c
@@ -185,8 +185,8 @@ grub_arm_reloc_jump24 (grub_uint32_t *target, Elf32_Addr sym_addr)
void
SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc *image_target,
int note, char **core_img, size_t *core_size,
- Elf_Addr target_addr, grub_size_t align,
- size_t kernel_size, size_t bss_size)
+ Elf_Addr target_addr,
+ struct grub_mkimage_layout *layout)
{
char *elf_img;
size_t program_size;
@@ -214,7 +214,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
footer_size += XEN_NOTE_SIZE;
}
header_size = ALIGN_UP (sizeof (*ehdr) + phnum * sizeof (*phdr)
- + shnum * sizeof (*shdr) + string_size, align);
+ + shnum * sizeof (*shdr) + string_size, layout->align);
program_size = ALIGN_ADDR (*core_size);
@@ -258,7 +258,8 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
ehdr->e_entry = grub_host_to_target32 (target_addr);
phdr->p_vaddr = grub_host_to_target32 (target_addr);
phdr->p_paddr = grub_host_to_target32 (target_addr);
- phdr->p_align = grub_host_to_target32 (align > image_target->link_align ? align : image_target->link_align);
+ phdr->p_align = grub_host_to_target32 (layout->align > image_target->link_align ?
+ layout->align : image_target->link_align);
if (image_target->id == IMAGE_LOONGSON_ELF)
ehdr->e_flags = grub_host_to_target32 (0x1000 | EF_MIPS_NOREORDER
| EF_MIPS_PIC | EF_MIPS_CPIC);
@@ -272,27 +273,27 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
else
{
grub_uint32_t target_addr_mods;
- phdr->p_filesz = grub_host_to_target32 (kernel_size);
- phdr->p_memsz = grub_host_to_target32 (kernel_size + bss_size);
+ phdr->p_filesz = grub_host_to_target32 (layout->kernel_size);
+ phdr->p_memsz = grub_host_to_target32 (layout->kernel_size + layout->bss_size);
phdr++;
phdr->p_type = grub_host_to_target32 (PT_GNU_STACK);
- phdr->p_offset = grub_host_to_target32 (header_size + kernel_size);
+ phdr->p_offset = grub_host_to_target32 (header_size + layout->kernel_size);
phdr->p_paddr = phdr->p_vaddr = phdr->p_filesz = phdr->p_memsz = 0;
phdr->p_flags = grub_host_to_target32 (PF_R | PF_W | PF_X);
phdr->p_align = grub_host_to_target32 (image_target->link_align);
phdr++;
phdr->p_type = grub_host_to_target32 (PT_LOAD);
- phdr->p_offset = grub_host_to_target32 (header_size + kernel_size);
+ phdr->p_offset = grub_host_to_target32 (header_size + layout->kernel_size);
phdr->p_flags = grub_host_to_target32 (PF_R | PF_W | PF_X);
phdr->p_filesz = phdr->p_memsz
- = grub_host_to_target32 (*core_size - kernel_size);
+ = grub_host_to_target32 (*core_size - layout->kernel_size);
if (image_target->id == IMAGE_COREBOOT)
target_addr_mods = GRUB_KERNEL_I386_COREBOOT_MODULES_ADDR;
else
- target_addr_mods = ALIGN_UP (target_addr + kernel_size + bss_size
+ target_addr_mods = ALIGN_UP (target_addr + layout->kernel_size + layout->bss_size
+ image_target->mod_gap,
image_target->mod_align);
phdr->p_vaddr = grub_host_to_target_addr (target_addr_mods);
@@ -434,7 +435,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
shdr->sh_size = grub_host_to_target32 (string_size);
shdr->sh_link = grub_host_to_target32 (0);
shdr->sh_info = grub_host_to_target32 (0);
- shdr->sh_addralign = grub_host_to_target32 (align);
+ shdr->sh_addralign = grub_host_to_target32 (layout->align);
shdr->sh_entsize = grub_host_to_target32 (0);
shdr++;
@@ -445,10 +446,10 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
shdr->sh_type = grub_host_to_target32 (SHT_PROGBITS);
shdr->sh_addr = grub_host_to_target_addr (target_addr);
shdr->sh_offset = grub_host_to_target_addr (header_size);
- shdr->sh_size = grub_host_to_target32 (kernel_size);
+ shdr->sh_size = grub_host_to_target32 (layout->kernel_size);
shdr->sh_link = grub_host_to_target32 (0);
shdr->sh_info = grub_host_to_target32 (0);
- shdr->sh_addralign = grub_host_to_target32 (align);
+ shdr->sh_addralign = grub_host_to_target32 (layout->align);
shdr->sh_entsize = grub_host_to_target32 (0);
shdr++;
@@ -456,9 +457,9 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
shdr->sh_name = grub_host_to_target32 (ptr - str_start);
ptr += sizeof ("mods");
shdr->sh_type = grub_host_to_target32 (SHT_PROGBITS);
- shdr->sh_addr = grub_host_to_target_addr (target_addr + kernel_size);
- shdr->sh_offset = grub_host_to_target_addr (header_size + kernel_size);
- shdr->sh_size = grub_host_to_target32 (*core_size - kernel_size);
+ shdr->sh_addr = grub_host_to_target_addr (target_addr + layout->kernel_size);
+ shdr->sh_offset = grub_host_to_target_addr (header_size + layout->kernel_size);
+ shdr->sh_size = grub_host_to_target32 (*core_size - layout->kernel_size);
shdr->sh_link = grub_host_to_target32 (0);
shdr->sh_info = grub_host_to_target32 (0);
shdr->sh_addralign = grub_host_to_target32 (image_target->voidp_sizeof);
@@ -471,7 +472,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
shdr->sh_name = grub_host_to_target32 (ptr - str_start);
ptr += sizeof (".xen");
shdr->sh_type = grub_host_to_target32 (SHT_PROGBITS);
- shdr->sh_addr = grub_host_to_target_addr (target_addr + kernel_size);
+ shdr->sh_addr = grub_host_to_target_addr (target_addr + layout->kernel_size);
shdr->sh_offset = grub_host_to_target_addr (program_size + header_size);
shdr->sh_size = grub_host_to_target32 (XEN_NOTE_SIZE);
shdr->sh_link = grub_host_to_target32 (0);
diff --git a/util/mkimage.c b/util/mkimage.c
index 9ad4cfe4223..528166c87ac 100644
--- a/util/mkimage.c
+++ b/util/mkimage.c
@@ -1638,10 +1638,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
target_addr = image_target->link_addr;
if (image_target->voidp_sizeof == 4)
grub_mkimage_generate_elf32 (image_target, note, &core_img, &core_size,
- target_addr, layout.align, layout.kernel_size, layout.bss_size);
+ target_addr, &layout);
else
grub_mkimage_generate_elf64 (image_target, note, &core_img, &core_size,
- target_addr, layout.align, layout.kernel_size, layout.bss_size);
+ target_addr, &layout);
}
break;
}
diff --git a/include/grub/util/mkimage.h b/include/grub/util/mkimage.h
index 1a18708a89c..b3a5ca132bc 100644
--- a/include/grub/util/mkimage.h
+++ b/include/grub/util/mkimage.h
@@ -51,13 +51,13 @@ grub_mkimage_load_image64 (const char *kernel_path,
void
grub_mkimage_generate_elf32 (const struct grub_install_image_target_desc *image_target,
int note, char **core_img, size_t *core_size,
- Elf32_Addr target_addr, grub_size_t align,
- size_t kernel_size, size_t bss_size);
+ Elf32_Addr target_addr,
+ struct grub_mkimage_layout *layout);
void
grub_mkimage_generate_elf64 (const struct grub_install_image_target_desc *image_target,
int note, char **core_img, size_t *core_size,
- Elf64_Addr target_addr, grub_size_t align,
- size_t kernel_size, size_t bss_size);
+ Elf64_Addr target_addr,
+ struct grub_mkimage_layout *layout);
struct grub_install_image_target_desc
{