0211-powerpc-ieee1275-load-grub-at-4MB-not-2MB.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Daniel Axtens <dja@axtens.net>
  3. Date: Fri, 22 Oct 2021 09:53:15 +1100
  4. Subject: [PATCH] powerpc-ieee1275: load grub at 4MB, not 2MB
  5. This was first reported under PFW but reproduces under SLOF.
  6. - The core.elf was 2126152 = 0x207148 bytes in size with the following
  7. program headers (per readelf):
  8. Entry point 0x200000
  9. There are 4 program headers, starting at offset 52
  10. Program Headers:
  11. Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
  12. LOAD 0x000160 0x00200000 0x00200000 0x21f98 0x2971c RWE 0x8
  13. GNU_STACK 0x0220f8 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4
  14. LOAD 0x0220f8 0x00232000 0x00232000 0x1e4e50 0x1e4e50 RWE 0x4
  15. NOTE 0x206f48 0x00000000 0x00000000 0x00200 0x00000 R 0x4
  16. - SLOF places the ELF file at 0x4000 (after the reserved space for
  17. interrupt handlers etc.) upwards. The image was 2126152 = 0x207148
  18. bytes in size, so it runs from 0x4000 - 0x20b148. We'll call 0x4000 the
  19. load address.
  20. 0x0 0x4000 0x20b148
  21. |----------|--------------|
  22. | reserved | ELF contents |
  23. - SLOF then copies the first LOAD program header (for .text). That runs
  24. for 0x21f98 bytes. It runs from
  25. (load addr + 0x160) to (load addr + 0x160 + 0x21f98)
  26. = 0x4160 to 0x260f8
  27. and we copy it to 0x200000 to 0x221f98. This overwrites the end of the
  28. image:
  29. 0x0 0x4000 0x200000 0x221f98
  30. |----------|------------|---------------|
  31. | reserved | ELF cont.. | .text section |
  32. - SLOF zeros the bss up to PhysAddr + MemSize = 0x22971c
  33. 0x0 0x4000 0x200000 0x221f98 0x22971c
  34. |----------|------------|---------------|--------|
  35. | reserved | ELF cont.. | .text section | bss 0s |
  36. - SLOF then goes to fulfil the next LOAD header (for mods), which is
  37. for 0x1e4e50 bytes. We copy from
  38. (load addr + 0x220f8) to (load addr + 0x220f8 + 0x1e4e50)
  39. = 0x260f8 to 0x20af48
  40. and we copy it to 0x232000 to 0x416e50:
  41. 0x0 0x4000 0x200000 0x221f98 0x22971c
  42. |----------|------------|---------------|--------|
  43. | reserved | ELF cont.. | .text section | bss 0s |
  44. |-------------|
  45. | copied area |
  46. 0x260f8 0x20af48
  47. This goes poorly:
  48. 0x0 0x4000 0x200000 0x221f98 0x22971c 0x232000 0x40bf08 0x416e50
  49. |----------|------------|---------------|--------|-----|-----------|-------------|
  50. | reserved | ELF cont.. | .text section | bss 0s | pad | some mods | .text start |
  51. This matches the observations on the running system - 0x40bf08 was where
  52. the contents of memory no longer matched the contents of the ELF file.
  53. This was reported as a license verification failure on SLOF as the
  54. last module's .module_license section fell past where the corruption
  55. began.
  56. Signed-off-by: Daniel Axtens <dja@axtens.net>
  57. [rharwood@redhat.com: trim very detailed commit message]
  58. Signed-off-by: Robbie Harwood <rharwood@redhat.com>
  59. ---
  60. grub-core/Makefile.core.def | 2 +-
  61. include/grub/offsets.h | 2 +-
  62. 2 files changed, 2 insertions(+), 2 deletions(-)
  63. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
  64. index 3f3459b2c70..6b00eb55575 100644
  65. --- a/grub-core/Makefile.core.def
  66. +++ b/grub-core/Makefile.core.def
  67. @@ -89,7 +89,7 @@ kernel = {
  68. i386_xen_pvh_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x100000';
  69. mips_loongson_ldflags = '-Wl,-Ttext,0x80200000';
  70. - powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000';
  71. + powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x400000';
  72. sparc64_ieee1275_ldflags = '-Wl,-Ttext,0x4400';
  73. mips_arc_ldflags = '-Wl,-Ttext,$(TARGET_LINK_ADDR)';
  74. mips_qemu_mips_ldflags = '-Wl,-Ttext,0x80200000';
  75. diff --git a/include/grub/offsets.h b/include/grub/offsets.h
  76. index 871e1cd4c38..69211aa798b 100644
  77. --- a/include/grub/offsets.h
  78. +++ b/include/grub/offsets.h
  79. @@ -63,7 +63,7 @@
  80. #define GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR 0x4400
  81. #define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ALIGN 4
  82. -#define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ADDR 0x200000
  83. +#define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ADDR 0x400000
  84. #define GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR 0x80200000