1*4882a593SmuzhiyunFrom 1710452aca05ccdd21e74390ec08c63fdf0ee10a Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Peter Jones <pjones@redhat.com>
3*4882a593SmuzhiyunDate: Mon, 15 Feb 2021 13:59:21 +0100
4*4882a593SmuzhiyunSubject: [PATCH] util/mkimage: Use grub_host_to_target32() instead of
5*4882a593Smuzhiyun grub_cpu_to_le32()
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunThe latter doesn't take into account the target image endianness. There is
8*4882a593Smuzhiyuna grub_cpu_to_le32_compile_time() but no compile time variant for function
9*4882a593Smuzhiyungrub_host_to_target32(). So, let's keep using the other one for this case.
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunSigned-off-by: Peter Jones <pjones@redhat.com>
12*4882a593SmuzhiyunSigned-off-by: Javier Martinez Canillas <javierm@redhat.com>
13*4882a593SmuzhiyunReviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14*4882a593SmuzhiyunSigned-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
15*4882a593Smuzhiyun---
16*4882a593Smuzhiyun util/mkimage.c | 44 ++++++++++++++++++++++----------------------
17*4882a593Smuzhiyun 1 file changed, 22 insertions(+), 22 deletions(-)
18*4882a593Smuzhiyun
19*4882a593Smuzhiyundiff --git a/util/mkimage.c b/util/mkimage.c
20*4882a593Smuzhiyunindex 32bb8ea..02944f2 100644
21*4882a593Smuzhiyun--- a/util/mkimage.c
22*4882a593Smuzhiyun+++ b/util/mkimage.c
23*4882a593Smuzhiyun@@ -1302,10 +1302,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
24*4882a593Smuzhiyun 	       + sizeof (struct grub_pe32_coff_header));
25*4882a593Smuzhiyun 	    o->magic = grub_host_to_target16 (GRUB_PE32_PE32_MAGIC);
26*4882a593Smuzhiyun 	    o->code_size = grub_host_to_target32 (layout.exec_size);
27*4882a593Smuzhiyun-	    o->data_size = grub_cpu_to_le32 (reloc_addr - layout.exec_size
28*4882a593Smuzhiyun+	    o->data_size = grub_host_to_target32 (reloc_addr - layout.exec_size
29*4882a593Smuzhiyun 					     - header_size);
30*4882a593Smuzhiyun-	    o->entry_addr = grub_cpu_to_le32 (layout.start_address);
31*4882a593Smuzhiyun-	    o->code_base = grub_cpu_to_le32 (header_size);
32*4882a593Smuzhiyun+	    o->entry_addr = grub_host_to_target32 (layout.start_address);
33*4882a593Smuzhiyun+	    o->code_base = grub_host_to_target32 (header_size);
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun 	    o->data_base = grub_host_to_target32 (header_size + layout.exec_size);
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun@@ -1339,10 +1339,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
38*4882a593Smuzhiyun 	       + sizeof (struct grub_pe32_coff_header));
39*4882a593Smuzhiyun 	    o->magic = grub_host_to_target16 (GRUB_PE32_PE64_MAGIC);
40*4882a593Smuzhiyun 	    o->code_size = grub_host_to_target32 (layout.exec_size);
41*4882a593Smuzhiyun-	    o->data_size = grub_cpu_to_le32 (reloc_addr - layout.exec_size
42*4882a593Smuzhiyun+	    o->data_size = grub_host_to_target32 (reloc_addr - layout.exec_size
43*4882a593Smuzhiyun 					     - header_size);
44*4882a593Smuzhiyun-	    o->entry_addr = grub_cpu_to_le32 (layout.start_address);
45*4882a593Smuzhiyun-	    o->code_base = grub_cpu_to_le32 (header_size);
46*4882a593Smuzhiyun+	    o->entry_addr = grub_host_to_target32 (layout.start_address);
47*4882a593Smuzhiyun+	    o->code_base = grub_host_to_target32 (header_size);
48*4882a593Smuzhiyun 	    o->image_base = 0;
49*4882a593Smuzhiyun 	    o->section_alignment = grub_host_to_target32 (image_target->section_align);
50*4882a593Smuzhiyun 	    o->file_alignment = grub_host_to_target32 (GRUB_PE32_FILE_ALIGNMENT);
51*4882a593Smuzhiyun@@ -1366,10 +1366,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
52*4882a593Smuzhiyun 	/* The sections.  */
53*4882a593Smuzhiyun 	text_section = sections;
54*4882a593Smuzhiyun 	strcpy (text_section->name, ".text");
55*4882a593Smuzhiyun-	text_section->virtual_size = grub_cpu_to_le32 (layout.exec_size);
56*4882a593Smuzhiyun-	text_section->virtual_address = grub_cpu_to_le32 (header_size);
57*4882a593Smuzhiyun-	text_section->raw_data_size = grub_cpu_to_le32 (layout.exec_size);
58*4882a593Smuzhiyun-	text_section->raw_data_offset = grub_cpu_to_le32 (header_size);
59*4882a593Smuzhiyun+	text_section->virtual_size = grub_host_to_target32 (layout.exec_size);
60*4882a593Smuzhiyun+	text_section->virtual_address = grub_host_to_target32 (header_size);
61*4882a593Smuzhiyun+	text_section->raw_data_size = grub_host_to_target32 (layout.exec_size);
62*4882a593Smuzhiyun+	text_section->raw_data_offset = grub_host_to_target32 (header_size);
63*4882a593Smuzhiyun 	text_section->characteristics = grub_cpu_to_le32_compile_time (
64*4882a593Smuzhiyun 						  GRUB_PE32_SCN_CNT_CODE
65*4882a593Smuzhiyun 						| GRUB_PE32_SCN_MEM_EXECUTE
66*4882a593Smuzhiyun@@ -1377,10 +1377,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun 	data_section = text_section + 1;
69*4882a593Smuzhiyun 	strcpy (data_section->name, ".data");
70*4882a593Smuzhiyun-	data_section->virtual_size = grub_cpu_to_le32 (layout.kernel_size - layout.exec_size);
71*4882a593Smuzhiyun-	data_section->virtual_address = grub_cpu_to_le32 (header_size + layout.exec_size);
72*4882a593Smuzhiyun-	data_section->raw_data_size = grub_cpu_to_le32 (layout.kernel_size - layout.exec_size);
73*4882a593Smuzhiyun-	data_section->raw_data_offset = grub_cpu_to_le32 (header_size + layout.exec_size);
74*4882a593Smuzhiyun+	data_section->virtual_size = grub_host_to_target32 (layout.kernel_size - layout.exec_size);
75*4882a593Smuzhiyun+	data_section->virtual_address = grub_host_to_target32 (header_size + layout.exec_size);
76*4882a593Smuzhiyun+	data_section->raw_data_size = grub_host_to_target32 (layout.kernel_size - layout.exec_size);
77*4882a593Smuzhiyun+	data_section->raw_data_offset = grub_host_to_target32 (header_size + layout.exec_size);
78*4882a593Smuzhiyun 	data_section->characteristics
79*4882a593Smuzhiyun 	  = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA
80*4882a593Smuzhiyun 			      | GRUB_PE32_SCN_MEM_READ
81*4882a593Smuzhiyun@@ -1388,10 +1388,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun 	mods_section = data_section + 1;
84*4882a593Smuzhiyun 	strcpy (mods_section->name, "mods");
85*4882a593Smuzhiyun-	mods_section->virtual_size = grub_cpu_to_le32 (reloc_addr - layout.kernel_size - header_size);
86*4882a593Smuzhiyun-	mods_section->virtual_address = grub_cpu_to_le32 (header_size + layout.kernel_size + layout.bss_size);
87*4882a593Smuzhiyun-	mods_section->raw_data_size = grub_cpu_to_le32 (reloc_addr - layout.kernel_size - header_size);
88*4882a593Smuzhiyun-	mods_section->raw_data_offset = grub_cpu_to_le32 (header_size + layout.kernel_size);
89*4882a593Smuzhiyun+	mods_section->virtual_size = grub_host_to_target32 (reloc_addr - layout.kernel_size - header_size);
90*4882a593Smuzhiyun+	mods_section->virtual_address = grub_host_to_target32 (header_size + layout.kernel_size + layout.bss_size);
91*4882a593Smuzhiyun+	mods_section->raw_data_size = grub_host_to_target32 (reloc_addr - layout.kernel_size - header_size);
92*4882a593Smuzhiyun+	mods_section->raw_data_offset = grub_host_to_target32 (header_size + layout.kernel_size);
93*4882a593Smuzhiyun 	mods_section->characteristics
94*4882a593Smuzhiyun 	  = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA
95*4882a593Smuzhiyun 			      | GRUB_PE32_SCN_MEM_READ
96*4882a593Smuzhiyun@@ -1399,10 +1399,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun 	reloc_section = mods_section + 1;
99*4882a593Smuzhiyun 	strcpy (reloc_section->name, ".reloc");
100*4882a593Smuzhiyun-	reloc_section->virtual_size = grub_cpu_to_le32 (layout.reloc_size);
101*4882a593Smuzhiyun-	reloc_section->virtual_address = grub_cpu_to_le32 (reloc_addr + layout.bss_size);
102*4882a593Smuzhiyun-	reloc_section->raw_data_size = grub_cpu_to_le32 (layout.reloc_size);
103*4882a593Smuzhiyun-	reloc_section->raw_data_offset = grub_cpu_to_le32 (reloc_addr);
104*4882a593Smuzhiyun+	reloc_section->virtual_size = grub_host_to_target32 (layout.reloc_size);
105*4882a593Smuzhiyun+	reloc_section->virtual_address = grub_host_to_target32 (reloc_addr + layout.bss_size);
106*4882a593Smuzhiyun+	reloc_section->raw_data_size = grub_host_to_target32 (layout.reloc_size);
107*4882a593Smuzhiyun+	reloc_section->raw_data_offset = grub_host_to_target32 (reloc_addr);
108*4882a593Smuzhiyun 	reloc_section->characteristics
109*4882a593Smuzhiyun 	  = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA
110*4882a593Smuzhiyun 			      | GRUB_PE32_SCN_MEM_DISCARDABLE
111*4882a593Smuzhiyun--
112*4882a593Smuzhiyun2.14.2
113*4882a593Smuzhiyun
114