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

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