Attention is currently required from: Arthur Heymans, Julius Werner.
Subrata Banik has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/81964?usp=email )
Change subject: util/cbfstool: Add --64 option for 64-bit payload stitching ......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
Why not parse the ELF for architecture?
Also it's confusing/meaningless for !x86 payloads.
can you please elaborate a bit your review comments ?
for sure, I should have guarded those against x86 arch alone. But are you suggesting not to use any cmdline (like --64) and use ELF arch to know if the payload is 64-bit binary and then insert specific magic data into the header ?
I think you only need a cmdline if you cannot figure it out differently. OTOH the ELF does not conclusively say something about the entry point. For other type of payloads like flat binaries it's not possible to know this either I suppose.
32-bit depthcharge
readelf -h /build/rex/firmware/rex/depthcharge/depthcharge.elf ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Intel 80386
64-bit depthcharge
readelf -h /build/rex/firmware/rex/depthcharge/depthcharge.elf ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Advanced Micro Devices X86-64 Version: 0x1
I believe in that case, I don't need any cmdline.
Well the entry point code be in .code16, .code32, .code64 assembly so it's not straightforward to know which mode the entry point is compiled for. One idea is to look for R_X86_64_PC32 or R_X86_64_PC16. If the ELF file contains those it's more likely that the entry point is 32bit (coreboot never support 16bit entry so I doubt PC16 is something you'll ever see). However if the arch is AMD64 and there no PC32 or PC16 then a 64bit entry point is more likely. It's not conclusive for sure but maybe those heuristics are good enough?
thanks for the prompt response. I got your point now, as not all payload has would expect the entry point also written in 64-bit mode although the payload support x86_64 arch. Hence, it's important to know if the entry point itself is 32-bit or 64-bit to jump in the correct mode.