Xiang Wang has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/29916
Change subject: Fix coreboot table record alignment to 8-byte boundary ......................................................................
Fix coreboot table record alignment to 8-byte boundary
I found that I triggered an unaligned memory access exception when debugging riscv's coreboot code. Because some records are aligned to a 4-byte boundary, such as lb_timestamp. It is defined as follows struct lb_timestamp { uint32_t tag; uint32_t size; uint32_t timestamp; }; This may causes data misaligned access exceptions at 64bit machine.
Change-Id: I1846be0e26ab3c81858d8cf727517e1462035e64 Signed-off-by: Xiang Wang wxjstz@126.com --- M src/lib/coreboot_table.c 1 file changed, 6 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/16/29916/1
diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c index c2ae094..20f9aae 100644 --- a/src/lib/coreboot_table.c +++ b/src/lib/coreboot_table.c @@ -84,8 +84,10 @@ { struct lb_record *rec; rec = lb_last_record(header); - if (header->table_entries) + if (header->table_entries) { + rec->size = ALIGN_UP(rec->size, 8); header->table_bytes += rec->size; + } rec = lb_last_record(header); header->table_entries++; rec->tag = LB_TAG_UNUSED; @@ -358,9 +360,9 @@ mainboard = (struct lb_mainboard *)rec; mainboard->tag = LB_TAG_MAINBOARD;
- mainboard->size = ALIGN_UP(sizeof(*mainboard) + + mainboard->size = sizeof(*mainboard) + strlen(mainboard_vendor) + 1 + - strlen(mainboard_part_number) + 1, 8); + strlen(mainboard_part_number) + 1;
mainboard->vendor_idx = 0; mainboard->part_number_idx = strlen(mainboard_vendor) + 1; @@ -411,7 +413,7 @@ rec = (struct lb_string *)lb_new_record(header); len = strlen(strings[i].string); rec->tag = strings[i].tag; - rec->size = ALIGN_UP(sizeof(*rec) + len + 1, 8); + rec->size = sizeof(*rec) + len + 1; memcpy(rec->string, strings[i].string, len+1); }