libflashprog: Fix comparison of layout entries
A `next` pointer was added to `struct romentry` in commit 49258610ebd4
(layout: Use linked list for `struct romentry`). Hence, comparing the
whole contents to match entries doesn't work anymore. Solve that by
comparing the `start`, `end` and `name` fields individually.
Change-Id: I125d3892d9efc68e8fc19eef559c82d46c3bdc94
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/399
diff --git a/libflashprog.c b/libflashprog.c
index 948fbde..9c28eff 100644
--- a/libflashprog.c
+++ b/libflashprog.c
@@ -342,6 +342,23 @@
* @{
*/
+#ifdef __FLASHPROG_LITTLE_ENDIAN__
+static int layout_cmp(const struct romentry *const a, const struct romentry *const b)
+{
+ int ret;
+
+ ret = (int)a->start - (int)b->start;
+ if (ret)
+ return ret;
+
+ ret = (int)a->end - (int)b->end;
+ if (ret)
+ return ret;
+
+ return strcmp(a->name, b->name);
+}
+#endif
+
/**
* @brief Read a layout from the Intel ICH descriptor in the flash.
*
@@ -400,7 +417,7 @@
const struct romentry *chip_entry = layout_next(chip_layout, NULL);
const struct romentry *dump_entry = layout_next(dump_layout, NULL);
- while (chip_entry && dump_entry && !memcmp(chip_entry, dump_entry, sizeof(*chip_entry))) {
+ while (chip_entry && dump_entry && !layout_cmp(chip_entry, dump_entry)) {
chip_entry = layout_next(chip_layout, chip_entry);
dump_entry = layout_next(dump_layout, dump_entry);
}