Skip to content
Snippets Groups Projects
Commit 1d80d645 authored by Edward O'Callaghan's avatar Edward O'Callaghan
Browse files

cbtable.c: Factor out lb_table_validation logic


Write a pure function for the table validation logic, it is
easier to unit-test.

Change-Id: I07b0f95ec0443fa6a8f54eb93f4a7ea1875cccad
Signed-off-by: default avatarEdward O'Callaghan <quasisec@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/37239


Tested-by: default avatarbuild bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: default avatarStefan Reinauer <stefan.reinauer@coreboot.org>
parent 4a55e688
No related branches found
No related tags found
No related merge requests found
...@@ -170,6 +170,23 @@ static int lb_header_valid(struct lb_header *head, unsigned long addr) ...@@ -170,6 +170,23 @@ static int lb_header_valid(struct lb_header *head, unsigned long addr)
return 1; return 1;
} }
static int lb_table_valid(struct lb_header *head, struct lb_record *recs)
{
if (compute_checksum(recs, head->table_bytes)
!= head->table_checksum) {
msg_perr("Bad table checksum: %04x.\n",
head->table_checksum);
return 0;
}
if (count_lb_records(head) != head->table_entries) {
msg_perr("Bad record count: %d.\n",
head->table_entries);
return 0;
}
return 1;
}
static struct lb_header *find_lb_table(void *base, unsigned long start, static struct lb_header *find_lb_table(void *base, unsigned long start,
unsigned long end) unsigned long end)
{ {
...@@ -183,17 +200,8 @@ static struct lb_header *find_lb_table(void *base, unsigned long start, ...@@ -183,17 +200,8 @@ static struct lb_header *find_lb_table(void *base, unsigned long start,
(struct lb_record *)(((char *)base) + addr + sizeof(*head)); (struct lb_record *)(((char *)base) + addr + sizeof(*head));
if (!lb_header_valid(head, addr)) if (!lb_header_valid(head, addr))
continue; continue;
if (count_lb_records(head) != head->table_entries) { if (!lb_table_valid(head, recs))
msg_perr("Bad record count: %d.\n",
head->table_entries);
continue; continue;
}
if (compute_checksum(recs, head->table_bytes)
!= head->table_checksum) {
msg_perr("Bad table checksum: %04x.\n",
head->table_checksum);
continue;
}
msg_pdbg("Found coreboot table at 0x%08lx.\n", addr); msg_pdbg("Found coreboot table at 0x%08lx.\n", addr);
return head; return head;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment