From 6ed0ba1e93f99edef7a62c3670b4ec61103e0ae9 Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Mon, 29 Apr 2024 10:04:59 +0200 Subject: cbfstool: Read XIP stage alignment requirements from ELF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/82102 Reviewed-by: Shuo Liu Tested-by: build bot (Jenkins) Reviewed-by: Jérémy Compostella Reviewed-by: Julius Werner --- util/cbfstool/cbfstool.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'util/cbfstool/cbfstool.c') diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index 88bf22b649..f81c133bf1 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -1156,23 +1156,26 @@ static int cbfstool_convert_mkstage(struct buffer *buffer, uint32_t *offset, struct cbfs_file *header) { struct buffer output; - size_t data_size; int ret; - if (elf_program_file_size(buffer, &data_size) < 0) { - ERROR("Could not obtain ELF size\n"); - return 1; - } - /* * We need a final location for XIP parsing, so we need to call do_cbfs_locate() early * here. That is okay because XIP stages may not be compressed, so their size cannot * change anymore at a later point. */ - if (param.stage_xip && - do_cbfs_locate(offset, data_size)) { - ERROR("Could not find location for stage.\n"); - return 1; + if (param.stage_xip) { + size_t data_size, alignment; + if (elf_program_file_size_align(buffer, &data_size, &alignment) < 0) { + ERROR("Could not obtain ELF size & alignment\n"); + return 1; + } + + param.alignment = MAX(alignment, param.alignment); + + if (do_cbfs_locate(offset, data_size)) { + ERROR("Could not find location for stage.\n"); + return 1; + } } struct cbfs_file_attr_stageheader *stageheader = (void *) -- cgit v1.2.3