Fix incorrect chipid params comparison
The current chipid params comparison code is based on a simple
memcmp. This doesn't work since the structure contains a string
pointer. Replace it with a simple field-by-field comparison.
@@ -916,6 +916,22 @@ void dump_a_chip (FILE *fp, struct stlink_chipid_params *dev) {
fprintf(fp, "flags %d\n\n", dev->flags);
}
+static int chipid_params_eq(struct stlink_chipid_params *p1, struct stlink_chipid_params *p2)
+{
+ return p1->chip_id == p2->chip_id &&
+ p1->description && p2->description &&
+ strcmp(p1->description, p2->description) == 0 &&
+ p1->flash_type == p2->flash_type &&
+ p1->flash_size_reg == p2->flash_size_reg &&
+ p1->flash_pagesize == p2->flash_pagesize &&
+ p1->sram_size == p2->sram_size &&
+ p1->bootrom_base == p2->bootrom_base &&
+ p1->bootrom_size == p2->bootrom_size &&
+ p1->option_base == p2->option_base &&
+ p1->option_size == p2->option_size &&
+ p1->flags == p2->flags;
+}
+
struct stlink_chipid_params *stlink_chipid_get_params(uint32_t chipid) {
struct stlink_chipid_params *params = NULL;
struct stlink_chipid_params *p2;
@@ -931,7 +947,7 @@ struct stlink_chipid_params *stlink_chipid_get_params(uint32_t chipid) {
#if 1
if (params == NULL) {
params = p2;
- } else if (memcmp (p2, params, sizeof(struct stlink_chipid_params) - sizeof(struct stlink_chipid_params *)) != 0) {
+ } else if (!chipid_params_eq(params, p2)) {
// fprintf (stderr, "Error, chipid params not identical\n");
// return NULL;
fprintf(stderr, "---------- old ------------\n");
