aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2021-07-15 15:32:31 +0100
committerMichael Brown <mcb30@ipxe.org>2021-07-15 15:45:24 +0100
commitc64dfff0a93b5f967ae21339313e61baf0b7a3a0 (patch)
tree643f5c75d0269065dfd200d9c9fd6be1c73c4be2
parent8d08300ad945988e0ce2fc24a34c19613154bae5 (diff)
downloadipxe-c64dfff0a93b5f967ae21339313e61baf0b7a3a0.zip
ipxe-c64dfff0a93b5f967ae21339313e61baf0b7a3a0.tar.gz
ipxe-c64dfff0a93b5f967ae21339313e61baf0b7a3a0.tar.bz2
[efi] Match signtool expectations for file alignment
As of commit f1e9e2b ("[efi] Align EFI image sections by page size"), our SectionAlignment has been increased to 4kB in order to allow for page-level memory protection to be applied by the UEFI firmware, with FileAlignment left at 32 bytes. The PE specification states that the value for FileAlignment "should be a power of 2 between 512 and 64k, inclusive", and that "if the SectionAlignment is less than the architecture's page size, then FileAlignment must match SectionAlignment". Testing shows that signtool.exe will reject binaries where FileAlignment is less than 512, unless FileAlignment is equal to SectionAlignment. This indicates a somewhat zealous interpretation of the word "should" in the PE specification. Work around this interpretation by increasing FileAlignment from 32 bytes to 512 bytes, and add explanatory comments for both FileAlignment and SectionAlignment. Debugged-by: Andreas Hammarskjöld <junior@2PintSoftware.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/util/elf2efi.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/util/elf2efi.c b/src/util/elf2efi.c
index 5542b99..8af53ae 100644
--- a/src/util/elf2efi.c
+++ b/src/util/elf2efi.c
@@ -125,7 +125,21 @@
#define R_ARM_V4BX 40
#endif
-#define EFI_FILE_ALIGN 0x20
+/**
+ * Alignment of raw data of sections in the image file
+ *
+ * Some versions of signtool.exe will spuriously complain if this
+ * value is less than 512.
+ */
+#define EFI_FILE_ALIGN 0x200
+
+/**
+ * Alignment of sections when loaded into memory
+ *
+ * This must equal the architecture page size, in order to allow for
+ * the possibility of the firmware using page-level protection to
+ * enforce section attributes at runtime.
+ */
#define EFI_IMAGE_ALIGN 0x1000
struct elf_file {