From 61168bd6c5abb00787426b4e58f28a67bd563427 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Thu, 7 Aug 2025 11:29:21 +0300 Subject: [PATCH 1/2] tools/efs_parser: move magic and cookie values to global scope --- tools/efs_parser.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tools/efs_parser.py b/tools/efs_parser.py index a16830a..9501bb8 100644 --- a/tools/efs_parser.py +++ b/tools/efs_parser.py @@ -3,10 +3,15 @@ from struct import unpack import zlib +EFS_MAGIC = b"\xAA\x55\xAA\x55" +PSP_COOKIE = b"$PSP" +PSPL2_COOKIE = b"$PL2" +PSP2_COOKIE = b"2PSP" +BHD_COOKIE = b"$BHD" +BHDL2_COOKIE = b"$BL2" +BHD2_COOKIE = b"2BHD" def extract_efs(rom): - efs_magic = b"\xAA\x55\xAA\x55" - efs_offsets = [ 0x020000, 0x820000, @@ -17,14 +22,13 @@ def extract_efs(rom): ] for offset in efs_offsets: - if rom[offset:offset+4] == efs_magic: + if rom[offset:offset+4] == EFS_MAGIC: return rom[offset:offset+0x4B] def parse_efs(efs): print("Parsing EFS") - efs_magic = b"\xAA\x55\xAA\x55" - if efs[0x0:0x4] != efs_magic: + if efs[0x0:0x4] != EFS_MAGIC: print(f"Invalid EFS magic {efs[0:4]}") exit() @@ -45,13 +49,13 @@ def parse_efs(efs): def parse_dir(rom, offset): magic = rom[offset:offset+4] - if magic == b"$PSP": + if magic == PSP_COOKIE: parse_psp_dir(rom, offset) pass - elif magic == b"2PSP" or magic == b"2BHD": + elif magic == PSP2_COOKIE or magic == BHD2_COOKIE: parse_psp_combodir(rom, offset) pass - elif magic == b"$BHD": + elif magic == BHD_COOKIE: parse_bios_dir(rom, offset) pass else: @@ -66,7 +70,7 @@ def parse_psp_dir(rom, offset): psp_hdr = rom[offset:offset+0x10] psp_magic = psp_hdr[0:4] - if psp_magic != b"$PSP" and psp_magic != b"$PL2": + if psp_magic != PSP_COOKIE and psp_magic != PSPL2_COOKIE: print(f"Invalid magic {psp_magic} when parsing PSP directory") exit() @@ -149,7 +153,7 @@ def parse_psp_combodir(rom, offset): psp_hdr = rom[offset:offset+0x20] psp_magic = psp_hdr[0:4] - if psp_magic != b"2PSP" and psp_magic != b"2BHD": + if psp_magic != PSP2_COOKIE and psp_magic != BHD2_COOKIE: print(f"Invalid magic {psp_magic} when parsing PSP directory") exit() @@ -214,7 +218,7 @@ def parse_bios_dir(rom, offset): bios_hdr = rom[offset:offset+0x10] bios_magic = bios_hdr[0x0:0x4] - if bios_magic != b"$BHD" and bios_magic != b"$BL2": + if bios_magic != BHD_COOKIE and bios_magic != BHDL2_COOKIE: print(f"Invalid magic {bios_magic} when parsing BIOS directory") exit() From 6d4f2a9bf4367b6a3d0b8d531ec09b28ff75137f Mon Sep 17 00:00:00 2001 From: Joursoir Date: Thu, 7 Aug 2025 11:35:13 +0300 Subject: [PATCH 2/2] tools/efs_parser: fix offset decision for directories lookup According to AMD documentation offset to PSP dir can also be at offset 0x10 (however, only for older generation). The docs do not specify any special value indicating a change of offset. Coreboot binaries use an 0xffffffff address in this directory field, which caused incorrect offset handling. --- tools/efs_parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/efs_parser.py b/tools/efs_parser.py index 9501bb8..cbcb0aa 100644 --- a/tools/efs_parser.py +++ b/tools/efs_parser.py @@ -34,9 +34,9 @@ def parse_efs(efs): dir_offsets = [] - for offset in range(0x14, 0x30, 4): + for offset in range(0x10, 0x30, 4): ptr = int.from_bytes(efs[offset:offset+4], "little") - if ptr != 0x00000000 and ptr != 0xFFFFFFFE: + if ptr != 0x00000000 and ptr != 0xFFFFFFFE and ptr != 0xFFFFFFFF: dir_offsets.append(ptr) print(f"# EFS entries: {len(dir_offsets)}")