mirror of
https://review.coreboot.org/flashrom.git
synced 2025-11-04 23:20:43 +01:00
libflashrom: Add new layout_compare() function with test
Add a new layout_compare() function which will be used in a subsequent
patch to test equality between two layouts. Add a test function for
layout_compare(). Fix a small bug in compare_region_with_dump() which
was introduced in commit 74a1a54892 ("libflashrom: Fix comparison of
layout romentry regions"), which was discovered with the new test.
Change-Id: Ib37556bb83d4e1c26545a90b49128f1f78ffe2c6
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/89629
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
committed by
Anastasia Klimchuk
parent
8e0bfee62f
commit
b0b975d0ea
@@ -458,12 +458,49 @@ bool flashrom_flag_get(const struct flashrom_flashctx *const flashctx, const enu
|
||||
#ifdef __FLASHROM_LITTLE_ENDIAN__
|
||||
static int compare_region_with_dump(const struct romentry *const a, const struct romentry *const b)
|
||||
{
|
||||
if (a->region.start != b->region.end
|
||||
if (a->region.start != b->region.start
|
||||
|| a->region.end != b->region.end
|
||||
|| strcmp(a->region.name, b->region.name))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int flashrom_layout_compare(const struct flashrom_layout *layout1,
|
||||
const struct flashrom_layout *layout2)
|
||||
{
|
||||
if (!layout1 || !layout2) {
|
||||
msg_gerr("Error: NULL layout pointer in comparison.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const struct romentry *entry1 = layout_next(layout1, NULL);
|
||||
const struct romentry *entry2 = layout_next(layout2, NULL);
|
||||
|
||||
while (entry1 && entry2) {
|
||||
if (compare_region_with_dump(entry1, entry2)) {
|
||||
msg_gerr("Layout region mismatch:\n");
|
||||
msg_gerr(" Region 1: '%s' [0x%08" PRIx32 ":0x%08" PRIx32 "]\n",
|
||||
entry1->region.name, entry1->region.start, entry1->region.end);
|
||||
msg_gerr(" Region 2: '%s' [0x%08" PRIx32 ":0x%08" PRIx32 "]\n",
|
||||
entry2->region.name, entry2->region.start, entry2->region.end);
|
||||
return 1;
|
||||
}
|
||||
entry1 = layout_next(layout1, entry1);
|
||||
entry2 = layout_next(layout2, entry2);
|
||||
}
|
||||
|
||||
/* If one layout has more regions than the other */
|
||||
if (entry1 || entry2) {
|
||||
msg_gerr("Layout region count mismatch.\n");
|
||||
if (entry1)
|
||||
msg_gerr(" Extra region in layout 1: '%s'\n", entry1->region.name);
|
||||
if (entry2)
|
||||
msg_gerr(" Extra region in layout 2: '%s'\n", entry2->region.name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* __FLASHROM_LITTLE_ENDIAN__ */
|
||||
|
||||
int flashrom_layout_read_from_ifd(struct flashrom_layout **const layout, struct flashctx *const flashctx,
|
||||
|
||||
Reference in New Issue
Block a user