coreboot_tables: Make existing alignment conventions more explicit

There seem to be some recurring vague concerns about the alignment of
coreboot table entries. While the existing implementation has been
producing tables with a well-defined alignment (4 bytes) for a long
time, the code doesn't always make it very clear. This patch adds an
explicit constant to codify that alignment, assertions to check it after
each entry, and adds explicit padding to the few entry structures that
were relying on compiler padding to return a correct sizeof() value.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Iaeef29ef255047a855066469e03b5481812e5975
Reviewed-on: https://review.coreboot.org/c/coreboot/+/70158
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-by: Jakub Czapiga <jacz@semihalf.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Peter Stuge <peter@stuge.se>
This commit is contained in:
Julius Werner
2022-11-30 16:18:01 -08:00
parent ad6c407927
commit 9a9b2778a1
3 changed files with 23 additions and 12 deletions

View File

@ -109,7 +109,8 @@ static void test_lb_new_record(void **state)
accumulated_size = sizeof(struct lb_record);
for (i = 0; i < entries; ++i) {
curr = lb_new_record(header);
curr->size = sizeof(struct lb_record) + ((i + 2) * 7) % 32;
curr->size = sizeof(struct lb_record) +
ALIGN_UP(((i + 2) * 7) % 32, LB_ENTRY_ALIGN);
assert_int_equal(entries_offset + (i + 1), header->table_entries);
assert_int_equal(accumulated_size, header->table_bytes);
@ -359,31 +360,31 @@ static void test_write_tables(void **state)
assert_int_equal(ALIGN_UP(sizeof(struct lb_mainboard)
+ ARRAY_SIZE(mainboard_vendor)
+ ARRAY_SIZE(mainboard_part_number),
8),
LB_ENTRY_ALIGN),
record->size);
break;
case LB_TAG_VERSION:
assert_int_equal(ALIGN_UP(sizeof(struct lb_string)
+ ARRAY_SIZE(coreboot_version),
8),
LB_ENTRY_ALIGN),
record->size);
break;
case LB_TAG_EXTRA_VERSION:
assert_int_equal(ALIGN_UP(sizeof(struct lb_string)
+ ARRAY_SIZE(coreboot_extra_version),
8),
LB_ENTRY_ALIGN),
record->size);
break;
case LB_TAG_BUILD:
assert_int_equal(
ALIGN_UP(sizeof(struct lb_string) + ARRAY_SIZE(coreboot_build),
8),
LB_ENTRY_ALIGN),
record->size);
break;
case LB_TAG_COMPILE_TIME:
assert_int_equal(ALIGN_UP(sizeof(struct lb_string)
+ ARRAY_SIZE(coreboot_compile_time),
8),
LB_ENTRY_ALIGN),
record->size);
break;
case LB_TAG_SERIAL: