nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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