Skip to content

Commit

Permalink
Fix for option byte read (#1156)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightwalker-87 committed Apr 7, 2023
1 parent 8da1ae8 commit de1f205
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/st-flash/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>

#include <stm32.h>
Expand Down Expand Up @@ -215,21 +216,25 @@ int main(int ac, char** av) {
(unsigned)remaining_option_length,
sl->option_base);

if (NULL != o.filename) {
if (0 == o.size) {
o.size = sl->option_size;
}
err = stlink_fread(sl, o.filename, o.format == FLASH_FORMAT_IHEX, sl->option_base, o.size);
} else {
uint32_t option_byte = 0;
err = stlink_read_option_bytes32(sl, &option_byte);
if (err == -1) {
printf("could not read option bytes (%d)\n", err);
uint32_t option_byte = 0;
err = stlink_read_option_bytes32(sl, &option_byte);
if (err == -1) {
printf("could not read option bytes (%d)\n", err);
goto on_error;
} else if (NULL != o.filename) {
// if (0 == o.size) { o.size = sl->option_size; }
// err = stlink_fread(sl, o.filename, o.format == FLASH_FORMAT_IHEX, sl->option_base, o.size);
int fd = open(o.filename, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 00700);
if (fd == -1) {
fprintf(stderr, "open(%s) == -1\n", o.filename);
goto on_error;
} else {
printf("%08x\n", option_byte);
}
write(fd, option_byte, 4);
close(fd);
} else {
printf("%08x\n", option_byte);
}

} else if (o.area == FLASH_OPTION_BYTES_BOOT_ADD) {
uint32_t option_byte = 0;
err = stlink_read_option_bytes_boot_add32(sl, &option_byte);
Expand Down

0 comments on commit de1f205

Please sign in to comment.