dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0468-util-mkimage-Use-grub_host_to_target32-instead-of-gr.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Peter Jones <pjones@redhat.com>
80913e
Date: Mon, 15 Feb 2021 13:59:21 +0100
80913e
Subject: [PATCH] util/mkimage: Use grub_host_to_target32() instead of
80913e
 grub_cpu_to_le32()
80913e
80913e
The latter doesn't take into account the target image endianness. There is
80913e
a grub_cpu_to_le32_compile_time() but no compile time variant for function
80913e
grub_host_to_target32(). So, let's keep using the other one for this case.
80913e
80913e
Signed-off-by: Peter Jones <pjones@redhat.com>
80913e
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
80913e
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
---
80913e
 util/mkimage.c | 44 ++++++++++++++++++++++----------------------
80913e
 1 file changed, 22 insertions(+), 22 deletions(-)
80913e
80913e
diff --git a/util/mkimage.c b/util/mkimage.c
80913e
index 64f4f139832..601521d34cf 100644
80913e
--- a/util/mkimage.c
80913e
+++ b/util/mkimage.c
80913e
@@ -1290,10 +1290,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
80913e
 	       + sizeof (struct grub_pe32_coff_header));
80913e
 	    o->magic = grub_host_to_target16 (GRUB_PE32_PE32_MAGIC);
80913e
 	    o->code_size = grub_host_to_target32 (layout.exec_size);
80913e
-	    o->data_size = grub_cpu_to_le32 (reloc_addr - layout.exec_size
80913e
+	    o->data_size = grub_host_to_target32 (reloc_addr - layout.exec_size
80913e
 					     - header_size);
80913e
-	    o->entry_addr = grub_cpu_to_le32 (layout.start_address);
80913e
-	    o->code_base = grub_cpu_to_le32 (header_size);
80913e
+	    o->entry_addr = grub_host_to_target32 (layout.start_address);
80913e
+	    o->code_base = grub_host_to_target32 (header_size);
80913e
 
80913e
 	    o->data_base = grub_host_to_target32 (header_size + layout.exec_size);
80913e
 
80913e
@@ -1327,10 +1327,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
80913e
 	       + sizeof (struct grub_pe32_coff_header));
80913e
 	    o->magic = grub_host_to_target16 (GRUB_PE32_PE64_MAGIC);
80913e
 	    o->code_size = grub_host_to_target32 (layout.exec_size);
80913e
-	    o->data_size = grub_cpu_to_le32 (reloc_addr - layout.exec_size
80913e
+	    o->data_size = grub_host_to_target32 (reloc_addr - layout.exec_size
80913e
 					     - header_size);
80913e
-	    o->entry_addr = grub_cpu_to_le32 (layout.start_address);
80913e
-	    o->code_base = grub_cpu_to_le32 (header_size);
80913e
+	    o->entry_addr = grub_host_to_target32 (layout.start_address);
80913e
+	    o->code_base = grub_host_to_target32 (header_size);
80913e
 	    o->image_base = 0;
80913e
 	    o->section_alignment = grub_host_to_target32 (image_target->section_align);
80913e
 	    o->file_alignment = grub_host_to_target32 (image_target->section_align);
80913e
@@ -1354,10 +1354,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
80913e
 	/* The sections.  */
80913e
 	text_section = sections;
80913e
 	strcpy (text_section->name, ".text");
80913e
-	text_section->virtual_size = grub_cpu_to_le32 (layout.exec_size);
80913e
-	text_section->virtual_address = grub_cpu_to_le32 (header_size);
80913e
-	text_section->raw_data_size = grub_cpu_to_le32 (layout.exec_size);
80913e
-	text_section->raw_data_offset = grub_cpu_to_le32 (header_size);
80913e
+	text_section->virtual_size = grub_host_to_target32 (layout.exec_size);
80913e
+	text_section->virtual_address = grub_host_to_target32 (header_size);
80913e
+	text_section->raw_data_size = grub_host_to_target32 (layout.exec_size);
80913e
+	text_section->raw_data_offset = grub_host_to_target32 (header_size);
80913e
 	text_section->characteristics = grub_cpu_to_le32_compile_time (
80913e
 						  GRUB_PE32_SCN_CNT_CODE
80913e
 						| GRUB_PE32_SCN_MEM_EXECUTE
80913e
@@ -1365,10 +1365,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
80913e
 
80913e
 	data_section = text_section + 1;
80913e
 	strcpy (data_section->name, ".data");
80913e
-	data_section->virtual_size = grub_cpu_to_le32 (layout.kernel_size - layout.exec_size);
80913e
-	data_section->virtual_address = grub_cpu_to_le32 (header_size + layout.exec_size);
80913e
-	data_section->raw_data_size = grub_cpu_to_le32 (layout.kernel_size - layout.exec_size);
80913e
-	data_section->raw_data_offset = grub_cpu_to_le32 (header_size + layout.exec_size);
80913e
+	data_section->virtual_size = grub_host_to_target32 (layout.kernel_size - layout.exec_size);
80913e
+	data_section->virtual_address = grub_host_to_target32 (header_size + layout.exec_size);
80913e
+	data_section->raw_data_size = grub_host_to_target32 (layout.kernel_size - layout.exec_size);
80913e
+	data_section->raw_data_offset = grub_host_to_target32 (header_size + layout.exec_size);
80913e
 	data_section->characteristics
80913e
 	  = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA
80913e
 			      | GRUB_PE32_SCN_MEM_READ
80913e
@@ -1376,10 +1376,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
80913e
     
80913e
 	mods_section = data_section + 1;
80913e
 	strcpy (mods_section->name, "mods");
80913e
-	mods_section->virtual_size = grub_cpu_to_le32 (reloc_addr - layout.kernel_size - header_size);
80913e
-	mods_section->virtual_address = grub_cpu_to_le32 (header_size + layout.kernel_size + layout.bss_size);
80913e
-	mods_section->raw_data_size = grub_cpu_to_le32 (reloc_addr - layout.kernel_size - header_size);
80913e
-	mods_section->raw_data_offset = grub_cpu_to_le32 (header_size + layout.kernel_size);
80913e
+	mods_section->virtual_size = grub_host_to_target32 (reloc_addr - layout.kernel_size - header_size);
80913e
+	mods_section->virtual_address = grub_host_to_target32 (header_size + layout.kernel_size + layout.bss_size);
80913e
+	mods_section->raw_data_size = grub_host_to_target32 (reloc_addr - layout.kernel_size - header_size);
80913e
+	mods_section->raw_data_offset = grub_host_to_target32 (header_size + layout.kernel_size);
80913e
 	mods_section->characteristics
80913e
 	  = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA
80913e
 			      | GRUB_PE32_SCN_MEM_READ
80913e
@@ -1387,10 +1387,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
80913e
 
80913e
 	reloc_section = mods_section + 1;
80913e
 	strcpy (reloc_section->name, ".reloc");
80913e
-	reloc_section->virtual_size = grub_cpu_to_le32 (layout.reloc_size);
80913e
-	reloc_section->virtual_address = grub_cpu_to_le32 (reloc_addr + layout.bss_size);
80913e
-	reloc_section->raw_data_size = grub_cpu_to_le32 (layout.reloc_size);
80913e
-	reloc_section->raw_data_offset = grub_cpu_to_le32 (reloc_addr);
80913e
+	reloc_section->virtual_size = grub_host_to_target32 (layout.reloc_size);
80913e
+	reloc_section->virtual_address = grub_host_to_target32 (reloc_addr + layout.bss_size);
80913e
+	reloc_section->raw_data_size = grub_host_to_target32 (layout.reloc_size);
80913e
+	reloc_section->raw_data_offset = grub_host_to_target32 (reloc_addr);
80913e
 	reloc_section->characteristics
80913e
 	  = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA
80913e
 			      | GRUB_PE32_SCN_MEM_DISCARDABLE