Skip to content

Commit

Permalink
Merge pull request #1169 from gszy/fix-parsing-hexs
Browse files Browse the repository at this point in the history
Fixed parsing hex numbers in chip config files
  • Loading branch information
Nightwalker-87 authored Aug 1, 2021
2 parents f58e536 + ebac01c commit 9605d21
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions inc/stlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ enum stlink_flash_type {
STLINK_FLASH_TYPE_G4,
STLINK_FLASH_TYPE_WB,
STLINK_FLASH_TYPE_H7,
STLINK_FLASH_TYPE_MAX,
};

struct stlink_reg {
Expand Down
32 changes: 21 additions & 11 deletions src/stlink-lib/chipid.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ void process_chipfile(char *fname)
char *p, *pp, buf[1025];
char word[64], value[64];
struct stlink_chipid_params *ts;
int nc, ival;
int nc;

//fprintf (stderr, "processing chipfile %s.\n", fname);
fp = fopen(fname, "r");
Expand All @@ -991,30 +991,40 @@ void process_chipfile(char *fname)
if (*p == '#') continue; // ignore comments.

sscanf(p, "%s %s", word, value);
ival = atoi (value);
if (strcmp(word, "chip_id") == 0) {
ts->chip_id = ival;
if (sscanf(value, "%i", &ts->chip_id) < 1)
fprintf(stderr, "Failed to parse chip id\n");
} else if (strcmp (word, "description") == 0) {
//ts->description = strdup (value);
buf[strlen(p)-1] = 0; // chomp newline
sscanf(p, "%*s %n", &nc);
ts->description = strdup(p+nc);
} else if (strcmp (word, "flash_type") == 0) {
ts->flash_type = ival;
if (sscanf(value, "%i", (int *) &ts->flash_type) < 1)
fprintf(stderr, "Failed to parse flash type\n");
else if (ts->flash_type <= STLINK_FLASH_TYPE_UNKNOWN || ts->flash_type >= STLINK_FLASH_TYPE_MAX)
fprintf(stderr, "Unrecognized flash type\n");
} else if (strcmp (word, "flash_size_reg") == 0) {
ts->flash_size_reg = ival;
if (sscanf(value, "%i", &ts->flash_size_reg) < 1)
fprintf(stderr, "Failed to parse flash size reg\n");
} else if (strcmp (word, "flash_pagesize") == 0) {
ts->flash_pagesize = ival;
if (sscanf(value, "%i", &ts->flash_pagesize) < 1)
fprintf(stderr, "Failed to parse flash page size\n");
} else if (strcmp (word, "sram_size") == 0) {
ts->sram_size = ival;
if (sscanf(value, "%i", &ts->sram_size) < 1)
fprintf(stderr, "Failed to parse SRAM size\n");
} else if (strcmp (word, "bootrom_base") == 0) {
ts->bootrom_base = ival;
if (sscanf(value, "%i", &ts->bootrom_base) < 1)
fprintf(stderr, "Failed to parse BootROM base\n");
} else if (strcmp (word, "bootrom_size") == 0) {
ts->bootrom_size = ival;
if (sscanf(value, "%i", &ts->bootrom_size) < 1)
fprintf(stderr, "Failed to parse BootROM size\n");
} else if (strcmp (word, "option_base") == 0) {
ts->option_base = ival;
if (sscanf(value, "%i", &ts->option_base) < 1)
fprintf(stderr, "Failed to parse option base\n");
} else if (strcmp (word, "option_size") == 0) {
ts->option_size = ival;
if (sscanf(value, "%i", &ts->option_size) < 1)
fprintf(stderr, "Failed to parse option size\n");
} else if (strcmp (word, "flags") == 0) {
pp = strtok (p, " \t\n");
while ((pp = strtok (NULL, " \t\n")) ) {
Expand Down

0 comments on commit 9605d21

Please sign in to comment.