0135-util-mkimage-Use-grub_host_to_target32-instead-of-gr.patch 6.3 KB

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