Skip to content

Commit

Permalink
Fix for option byte read (Closes #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 1d301a5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
38 changes: 24 additions & 14 deletions src/st-flash/flash.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
/* Simple wrapper around the stlink_flash_write function */

// TODO - this should be done as just a simple flag to the st-util command line...

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>

#include <stm32.h>
#include <stlink.h>

#include <common_flash.h>
#include <map_file.h>
#include <option_bytes.h>

#include "flash.h"
#include "option_bytes.h"

static stlink_t *connected_stlink = NULL;

Expand Down Expand Up @@ -215,20 +220,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;
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) {
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;
}
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);
err = (uint32_t)write(fd, &option_byte, 4);
if (err == -1) {
printf("could not read option bytes (%d)\n", err);
printf("could not write buffer to file (%d)\n", err);
goto on_error;
} else {
printf("%08x\n", option_byte);
}
close(fd);
} else {
printf("%08x\n", option_byte);
}
} else if (o.area == FLASH_OPTION_BYTES_BOOT_ADD) {
uint32_t option_byte = 0;
Expand Down
9 changes: 5 additions & 4 deletions src/st-util/semihosting.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>

#include <stlink.h>

#include <logging.h>
#include "semihosting.h"

Expand Down Expand Up @@ -256,8 +258,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
return(-1);
}

DLOG("Semihosting: write(%d, target_addr:0x%08x, %u)\n", fd, buffer_address,
buffer_len);
DLOG("Semihosting: write(%d, target_addr:0x%08x, %u)\n", fd, buffer_address, buffer_len);

*ret = (uint32_t)write(fd, buffer, buffer_len);
saved_errno = errno;
Expand Down
15 changes: 9 additions & 6 deletions src/stlink-lib/common.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#include <helper.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <fcntl.h>
#include <helper.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <md5.h>

#include <stlink.h>
#include <stm32.h>

#include "common_flash.h"
#include "calculate.h"
#include "common_flash.h"
#include "map_file.h"
#include "md5.h"

#include "common.h"

#ifndef O_BINARY
Expand Down
3 changes: 0 additions & 3 deletions src/stlink-lib/option_bytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,11 +1007,8 @@ int stlink_read_option_bytes32(stlink_t *sl, uint32_t *option_byte) {
case STM32_CHIPID_F76xxx:
return stlink_read_option_bytes_f7(sl, option_byte);
case STM32_CHIPID_G0_CAT1:
return stlink_read_option_bytes_gx(sl, option_byte);
case STM32_CHIPID_G0_CAT2:
return stlink_read_option_bytes_gx(sl, option_byte);
case STM32_CHIPID_G4_CAT2:
return stlink_read_option_bytes_gx(sl, option_byte);
case STM32_CHIPID_G4_CAT3:
return stlink_read_option_bytes_gx(sl, option_byte);
default:
Expand Down

0 comments on commit 1d301a5

Please sign in to comment.