From 9a9b2778a1f04ba5d570de154f4b6f38f3b5807a Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Wed, 30 Nov 2022 16:18:01 -0800 Subject: 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 Change-Id: Iaeef29ef255047a855066469e03b5481812e5975 Reviewed-on: https://review.coreboot.org/c/coreboot/+/70158 Reviewed-by: Arthur Heymans Reviewed-by: Jakub Czapiga Tested-by: build bot (Jenkins) Reviewed-by: Peter Stuge --- tests/lib/coreboot_table-test.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/lib/coreboot_table-test.c b/tests/lib/coreboot_table-test.c index aa10f6534b..9547ee07a6 100644 --- a/tests/lib/coreboot_table-test.c +++ b/tests/lib/coreboot_table-test.c @@ -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: -- cgit v1.2.3