summaryrefslogtreecommitdiff
path: root/src/lib/coreboot_table.c
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2022-11-30 16:18:01 -0800
committerJulius Werner <jwerner@chromium.org>2022-12-22 15:34:28 +0000
commit9a9b2778a1f04ba5d570de154f4b6f38f3b5807a (patch)
treece5c6fcc45240198711ab0f159a543bab6d629b6 /src/lib/coreboot_table.c
parentad6c407927a2aa05cb7ecb47c833b230c227db36 (diff)
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>
Diffstat (limited to 'src/lib/coreboot_table.c')
-rw-r--r--src/lib/coreboot_table.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c
index 0f20735204..eaf487ff4e 100644
--- a/src/lib/coreboot_table.c
+++ b/src/lib/coreboot_table.c
@@ -76,9 +76,11 @@ struct lb_record *lb_new_record(struct lb_header *header)
{
struct lb_record *rec;
rec = lb_last_record(header);
- if (header->table_entries)
+ if (header->table_entries) {
+ assert(IS_ALIGNED(rec->size, LB_ENTRY_ALIGN));
header->table_bytes += rec->size;
- rec = lb_last_record(header);
+ rec = lb_last_record(header);
+ }
header->table_entries++;
rec->tag = LB_TAG_UNUSED;
rec->size = sizeof(*rec);
@@ -301,7 +303,7 @@ static struct lb_mainboard *lb_mainboard(struct lb_header *header)
mainboard->size = ALIGN_UP(sizeof(*mainboard) +
strlen(mainboard_vendor) + 1 +
- strlen(mainboard_part_number) + 1, 8);
+ strlen(mainboard_part_number) + 1, LB_ENTRY_ALIGN);
mainboard->vendor_idx = 0;
mainboard->part_number_idx = strlen(mainboard_vendor) + 1;
@@ -380,7 +382,7 @@ static void lb_strings(struct lb_header *header)
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 = ALIGN_UP(sizeof(*rec) + len + 1, LB_ENTRY_ALIGN);
memcpy(rec->string, strings[i].string, len+1);
}
@@ -422,8 +424,10 @@ static unsigned long lb_table_fini(struct lb_header *head)
{
struct lb_record *rec, *first_rec;
rec = lb_last_record(head);
- if (head->table_entries)
+ if (head->table_entries) {
+ assert(IS_ALIGNED(rec->size, LB_ENTRY_ALIGN));
head->table_bytes += rec->size;
+ }
first_rec = lb_first_record(head);
head->table_checksum = compute_ip_checksum(first_rec,