cbfstool: Make add-stage support multiple loadable segments

For x86 eXecute-In-Place (XIP) pre-memory `.data` section support, we
have to use an extra segment as the VMA/LMA of the data is different
than the VMA/LMA of the code.

To support this requirement, this patch makes cbfstool:
1. Allow the load of an ELF with an extra segment
2. Makes add-stage for XIP (cf. parse_elf_to_xip_stage()) write its
   content to the output binary.

To prevent the creation of unsuitable binaries, cbfstool verifies that
the LMA addresses of the segments are consecutives.

TEST=XIP pre-memory stages with a `.data` section have the `.data`
     section covered by a second segment properly included right after
     the code.

Change-Id: I480b4b047546c8aa4e12dfb688e0299f80283234
Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/77584
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Jeremy Compostella
2023-08-30 15:35:46 -07:00
committed by Julius Werner
parent c9cae530e5
commit 79f2e1fc8b
3 changed files with 87 additions and 21 deletions

View File

@ -29,6 +29,8 @@ struct rmod_context {
struct parsed_elf pelf;
/* Program segment. */
Elf64_Phdr *phdr;
/* Number of loadable segments. */
size_t nsegments;
/* Symbol string table. */
char *strtab;