Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed parsing hex numbers in chip config files #1169

Merged
merged 3 commits into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -973,7 +973,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 @@ -989,30 +989,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