cbfstool: Read XIP stage alignment requirements from ELF

On x86_64 romstage can contain page tables and a page table pointer
which have an larger alignment requirement of 4096. Instead of
hardcoding it, read if from the ELF phdrs.

Change-Id: I94e4a4209b7441ecb2966a1342c3d46625771bb8
Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/82102
Reviewed-by: Shuo Liu <shuo.liu@intel.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Jérémy Compostella <jeremy.compostella@intel.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
diff --git a/util/cbfstool/elfheaders.c b/util/cbfstool/elfheaders.c
index 39faff2..5bcac15 100644
--- a/util/cbfstool/elfheaders.c
+++ b/util/cbfstool/elfheaders.c
@@ -1434,12 +1434,13 @@
 	return add_rel(rel_sec, &rel);
 }
 
-int elf_program_file_size(const struct buffer *input, size_t *file_size)
+int elf_program_file_size_align(const struct buffer *input, size_t *file_size, size_t *align)
 {
 	Elf64_Ehdr ehdr;
 	Elf64_Phdr *phdr;
 	int i;
 	size_t loadable_file_size = 0;
+	size_t align_size = 0;
 
 	if (elf_headers(input, &ehdr, &phdr, NULL))
 		return -1;
@@ -1448,9 +1449,11 @@
 		if (phdr[i].p_type != PT_LOAD)
 			continue;
 		loadable_file_size += phdr[i].p_filesz;
+		align_size = MAX(align_size, phdr[i].p_align);
 	}
 
 	*file_size = loadable_file_size;
+	*align = align_size;
 
 	free(phdr);