Skip to content

Commit 937c20b

Browse files
committed
Fixes for X86 FSP QEMU test
1 parent 7be56a7 commit 937c20b

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/tpm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ static int TPM2_IoCb(TPM2_CTX* ctx, const uint8_t* txBuf, uint8_t* rxBuf,
242242
#define SELF_HASH_SZ ((uint32_t)((uintptr_t)WOLFBOOT_PARTITION_BOOT_ADDRESS - \
243243
(uintptr_t)ARCH_FLASH_OFFSET))
244244
#endif
245+
#elif defined(WOLFBOOT_FSP)
246+
/* FSP: stage1 boot_x86_fsp.c handles measurement via self_extend_pcr()
247+
* and wolfBoot_image_measure(). Skip generic self-measurement here since
248+
* stage2 .data is interleaved with .text making the hash non-deterministic */
245249
#else
246250
/* Default: measure wolfBoot's own code using linker script symbols */
247251
extern unsigned int _start_text;

tools/scripts/x86_fsp/compute_pcr.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,21 @@ def get_sha256_hash_of_wolfboot_image(file_path: str):
6161
return data[4:4+l]
6262
data = data[4+l:]
6363

64+
def get_sym_addr(elf_file: str, sym_name: str) -> int:
65+
"""
66+
get the address of a symbol from ELF file
67+
"""
68+
symbols = subprocess.check_output(['nm', elf_file]).split(b'\n')
69+
matches = list(filter(lambda x: sym_name.encode() in x, symbols))
70+
if not matches:
71+
return None
72+
return int(matches[0].split(b' ')[0], 16)
73+
6474
def get_keystore_sym_addr() -> int:
6575
"""
6676
get the address of symbol keystore from ELF file image
6777
"""
68-
symbols = subprocess.check_output(['nm', 'stage1/loader_stage1.elf']).split(b'\n')
69-
_start_keystore = int(list(filter(lambda x: b'_start_keystore' in x, symbols))[0].split(b' ')[0], 16)
70-
return _start_keystore
78+
return get_sym_addr('stage1/loader_stage1.elf', '_start_keystore')
7179

7280
def pcr_extend(pcr: bytearray, data: bytearray) -> bytearray:
7381
"""
@@ -95,23 +103,25 @@ def pcr_extend(pcr: bytearray, data: bytearray) -> bytearray:
95103

96104
pcr0 = bytearray(b'\x00'*32)
97105
if args.target == 'qemu':
106+
# self_extend_pcr() in boot_x86_fsp.c
107+
# Hashes from _start_keystore to end of 4GB (keystore + vectors)
98108
keystore_addr = get_keystore_sym_addr()
99109
keystore_off = addr_to_off(keystore_addr, image_size = len(image))
100110
ibb = image[keystore_off:]
101-
h = hashlib.sha256()
102-
h.update(ibb)
103-
pcr0_data_hash = h.digest()
104-
pcr0 = pcr_extend(b'\x00'*32, pcr0_data_hash)
111+
pcr0 = pcr_extend(pcr0, get_sha256_hash(ibb))
105112

106113
print(f"Initial PCR0: {pcr0.hex()}")
107114

108115
is_stage1_auth_enabled = get_config_value(config, 'STAGE1_AUTH') == '1'
109116
print(f"stage1 auth is {'enabled' if is_stage1_auth_enabled else 'disabled'}")
110117

111-
if is_stage1_auth_enabled:
118+
is_measured_boot = get_config_value(config, 'MEASURED_BOOT') == '1'
119+
120+
# wolfBoot_image_measure() extends PCR with wolfboot image hash
121+
if is_measured_boot:
112122
wb_hash = get_sha256_hash_of_wolfboot_image('stage1/wolfboot_raw_v1_signed.bin')
113123
pcr0 = pcr_extend(pcr0, wb_hash)
114-
print(f"PCR0 after wolfboot: {pcr0.hex()}")
124+
print(f"PCR0 after wolfboot image measure: {pcr0.hex()}")
115125

116126
# the pcrdigest needed by policy_sign tool is the hash of the concatenation of all PCRs involved in the policy.
117127
# we have only one PCR here

0 commit comments

Comments
 (0)