kopia lustrzana https://github.com/stlink-org/stlink
Merge pull request #917 from chenguokai/develop
Fixed st-flash write 0xff ignored issuepull/920/head
commit
ecbbd6db7a
|
@ -26,4 +26,3 @@ script:
|
|||
- printenv
|
||||
- cmake --version
|
||||
- ./.travis.sh
|
||||
- ./.travis-lin-mingw.sh
|
||||
|
|
|
@ -1,52 +1,55 @@
|
|||
.\" Automatically generated by Pandoc 2.4
|
||||
.\" Automatically generated by Pandoc 2.9
|
||||
.\"
|
||||
.TH "st\-flash" "1" "Feb 2018" "Open Source STMicroelectronics Stlink Tools" "stlink"
|
||||
.TH "st-flash" "1" "Feb 2018" "Open Source STMicroelectronics Stlink Tools" "stlink"
|
||||
.hy
|
||||
.SH NAME
|
||||
.PP
|
||||
st\-flash \- Flash binary files to STM32 device
|
||||
st-flash - Flash binary files to STM32 device
|
||||
.SH SYNOPSIS
|
||||
.PP
|
||||
\f[I]st\-flash\f[R] [\f[I]OPTIONS\f[R]] {read|write|erase}
|
||||
\f[I]st-flash\f[R] [\f[I]OPTIONS\f[R]] {read|write|erase}
|
||||
[\f[I]FILE\f[R]] <ADDR> <SIZE>
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
Flash binary files to arbitrary sections of memory, or read arbitrary
|
||||
addresses of memory out to a binary file.
|
||||
.PP
|
||||
You can use this instead of st\-util(1) if you prefer, but remember to
|
||||
You can use this instead of st-util(1) if you prefer, but remember to
|
||||
use the \f[B].bin\f[R] image, rather than the \f[B].elf\f[R] file.
|
||||
.PP
|
||||
Use hexadecimal format for the \f[I]ADDR\f[R] and \f[I]SIZE\f[R].
|
||||
.SH COMMANDS
|
||||
.TP
|
||||
.B write \f[I]FILE\f[R] \f[I]ADDR\f[R]
|
||||
write \f[I]FILE\f[R] \f[I]ADDR\f[R]
|
||||
Write firmware \f[I]FILE\f[R] to device starting from \f[I]ADDR\f[R]
|
||||
.TP
|
||||
.B read \f[I]FILE\f[R] \f[I]ADDR\f[R] \f[I]SIZE\f[R]
|
||||
read \f[I]FILE\f[R] \f[I]ADDR\f[R] \f[I]SIZE\f[R]
|
||||
Read firmware from device starting from \f[I]ADDR\f[R] up to
|
||||
\f[I]SIZE\f[R] bytes to \f[I]FILE\f[R]
|
||||
.TP
|
||||
.B erase
|
||||
erase
|
||||
Perform a mass erasing of the device firmware
|
||||
.TP
|
||||
.B reset
|
||||
reset
|
||||
Reset the target
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-\-version
|
||||
--version
|
||||
Print version information
|
||||
.TP
|
||||
.B \-\-debug
|
||||
--debug
|
||||
TODO
|
||||
.TP
|
||||
.B \-\-reset
|
||||
--reset
|
||||
TODO
|
||||
.TP
|
||||
.B \-\-serial \f[I]iSerial\f[R]
|
||||
--opt
|
||||
Enable ignore ending empty bytes optimization
|
||||
.TP
|
||||
--serial \f[I]iSerial\f[R]
|
||||
TODO
|
||||
.TP
|
||||
.B \-\-flash=fsize
|
||||
--flash=fsize
|
||||
Where fsize is the size in decimal, octal, or hex followed by an
|
||||
optional multiplier `k' for KB, or `m' for MB.
|
||||
Use a leading \[lq]0x\[rq] to specify hexadecimal, or a leading zero for
|
||||
|
@ -57,7 +60,7 @@ Flash \f[C]firmware.bin\f[R] to device
|
|||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
$ st\-flash write firmware.bin 0x8000000
|
||||
$ st-flash write firmware.bin 0x8000000
|
||||
\f[R]
|
||||
.fi
|
||||
.PP
|
||||
|
@ -65,7 +68,7 @@ Read firmware from device (4096 bytes)
|
|||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
$ st\-flash read firmware.bin 0x8000000 0x1000
|
||||
$ st-flash read firmware.bin 0x8000000 0x1000
|
||||
\f[R]
|
||||
.fi
|
||||
.PP
|
||||
|
@ -73,12 +76,12 @@ Erase firmware from device
|
|||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
$ st\-flash erase
|
||||
$ st-flash erase
|
||||
\f[R]
|
||||
.fi
|
||||
.SH SEE ALSO
|
||||
.PP
|
||||
st\-util(1), st\-info(1)
|
||||
st-util(1), st-info(1)
|
||||
.SH COPYRIGHT
|
||||
.PP
|
||||
This work is copyrighted.
|
||||
|
|
|
@ -45,6 +45,9 @@ reset
|
|||
\--reset
|
||||
: TODO
|
||||
|
||||
\--opt
|
||||
: Enable ignore ending empty bytes optimization
|
||||
|
||||
\--serial *iSerial*
|
||||
: TODO
|
||||
|
||||
|
|
|
@ -151,6 +151,7 @@ typedef struct flash_loader {
|
|||
|
||||
// transport layer verboseness: 0 for no debug info, 10 for lots
|
||||
int verbose;
|
||||
int opt;
|
||||
uint32_t core_id; // set by stlink_core_id(), result from STLINK_DEBUGREADCOREID
|
||||
uint32_t chip_id; // set by stlink_load_device_params(), used to identify flash and sram
|
||||
int core_stat; // set by stlink_status(), values STLINK_CORE_xxxxx
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#define DEBUG_LOG_LEVEL 100
|
||||
#define STND_LOG_LEVEL 50
|
||||
#define ENABLE_OPT 1
|
||||
|
||||
enum flash_cmd {FLASH_CMD_NONE = 0, FLASH_CMD_WRITE = 1, FLASH_CMD_READ = 2, FLASH_CMD_ERASE = 3, CMD_RESET = 4};
|
||||
enum flash_format {FLASH_FORMAT_BINARY = 0, FLASH_FORMAT_IHEX = 1};
|
||||
|
@ -24,9 +25,10 @@ struct flash_opts
|
|||
enum flash_area area;
|
||||
uint32_t val;
|
||||
size_t flash_size; /* --flash=n[k][m] */
|
||||
int opt;
|
||||
};
|
||||
|
||||
#define FLASH_OPTS_INITIALIZER {0, NULL, { 0 }, NULL, 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||
#define FLASH_OPTS_INITIALIZER {0, NULL, { 0 }, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
|
||||
int flash_get_opts(struct flash_opts* o, int ac, char** av);
|
||||
|
||||
|
|
62
src/common.c
62
src/common.c
|
@ -2621,17 +2621,31 @@ int stlink_mwrite_flash(stlink_t *sl, uint8_t* data, uint32_t length, stm32_addr
|
|||
unsigned int num_empty, idx;
|
||||
uint8_t erased_pattern = stlink_get_erased_pattern(sl);
|
||||
|
||||
idx = (unsigned int)length;
|
||||
for(num_empty = 0; num_empty != length; ++num_empty) {
|
||||
if (data[--idx] != erased_pattern) {
|
||||
break;
|
||||
/*
|
||||
* This optimization may cause unexpected garbage data remaining
|
||||
* Turned off by default
|
||||
*/
|
||||
if (sl->opt) {
|
||||
idx = (unsigned int)length;
|
||||
for(num_empty = 0; num_empty != length; ++num_empty) {
|
||||
if (data[--idx] != erased_pattern) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Round down to words */
|
||||
num_empty -= (num_empty & 3);
|
||||
if(num_empty != 0) {
|
||||
ILOG("Ignoring %d bytes of 0x%02x at end of file\n", num_empty, erased_pattern);
|
||||
}
|
||||
} else {
|
||||
num_empty = 0;
|
||||
}
|
||||
/* Round down to words */
|
||||
num_empty -= (num_empty & 3);
|
||||
if(num_empty != 0) {
|
||||
ILOG("Ignoring %d bytes of 0x%02x at end of file\n", num_empty, erased_pattern);
|
||||
}
|
||||
/*
|
||||
* TODO: investigate:
|
||||
* a kind of weird behaviour here:
|
||||
* if the file is identified to be all-empty and four-bytes aligned,
|
||||
* still flash the whole file even if ignoring message is printed
|
||||
*/
|
||||
err = stlink_write_flash(sl, addr, data, (num_empty == length) ? (uint32_t) length : (uint32_t) length - num_empty, num_empty == length);
|
||||
stlink_fwrite_finalize(sl, addr);
|
||||
return err;
|
||||
|
@ -2655,18 +2669,28 @@ int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr) {
|
|||
ELOG("map_file() == -1\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
idx = (unsigned int) mf.len;
|
||||
for(num_empty = 0; num_empty != mf.len; ++num_empty) {
|
||||
if (mf.base[--idx] != erased_pattern) {
|
||||
break;
|
||||
|
||||
if (sl->opt) {
|
||||
idx = (unsigned int) mf.len;
|
||||
for(num_empty = 0; num_empty != mf.len; ++num_empty) {
|
||||
if (mf.base[--idx] != erased_pattern) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Round down to words */
|
||||
num_empty -= (num_empty & 3);
|
||||
if(num_empty != 0) {
|
||||
ILOG("Ignoring %d bytes of 0x%02x at end of file\n", num_empty, erased_pattern);
|
||||
}
|
||||
} else {
|
||||
num_empty = 0;
|
||||
}
|
||||
/* Round down to words */
|
||||
num_empty -= (num_empty & 3);
|
||||
if(num_empty != 0) {
|
||||
ILOG("Ignoring %d bytes of 0x%02x at end of file\n", num_empty, erased_pattern);
|
||||
}
|
||||
/*
|
||||
* TODO: investigate:
|
||||
* a kind of weird behaviour here:
|
||||
* if the file is identified to be all-empty and four-bytes aligned,
|
||||
* still flash the whole file even if ignoring message is printed
|
||||
*/
|
||||
err = stlink_write_flash(sl, addr, mf.base, (num_empty == mf.len) ? (uint32_t) mf.len : (uint32_t) mf.len - num_empty, num_empty == mf.len);
|
||||
stlink_fwrite_finalize(sl, addr);
|
||||
unmap_file(&mf);
|
||||
|
|
|
@ -29,9 +29,9 @@ static void cleanup(int signum) {
|
|||
|
||||
static void usage(void)
|
||||
{
|
||||
puts("stlinkv1 command line: ./st-flash [--debug] [--reset] [--format <format>] [--flash=<fsize>] {read|write} /dev/sgX <path> <addr> <size>");
|
||||
puts("stlinkv1 command line: ./st-flash [--debug] [--reset] [--opt] [--format <format>] [--flash=<fsize>] {read|write} /dev/sgX <path> <addr> <size>");
|
||||
puts("stlinkv1 command line: ./st-flash [--debug] /dev/sgX erase");
|
||||
puts("stlinkv2/3 command line: ./st-flash [--debug] [--reset] [--serial <serial>] [--format <format>] [--flash=<fsize>] {read|write} <path> <addr> <size>");
|
||||
puts("stlinkv2/3 command line: ./st-flash [--debug] [--reset] [--opt] [--serial <serial>] [--format <format>] [--flash=<fsize>] {read|write} <path> <addr> <size>");
|
||||
puts("stlinkv2/3 command line: ./st-flash [--debug] [--serial <serial>] erase");
|
||||
puts("stlinkv2/3 command line: ./st-flash [--debug] [--serial <serial>] reset");
|
||||
puts(" <addr>, <serial> and <size>: Use hex format.");
|
||||
|
@ -73,6 +73,7 @@ int main(int ac, char** av)
|
|||
}
|
||||
|
||||
sl->verbose = o.log_level;
|
||||
sl->opt = o.opt;
|
||||
|
||||
connected_stlink = sl;
|
||||
signal(SIGINT, &cleanup);
|
||||
|
|
|
@ -27,6 +27,9 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
|
|||
else if (strcmp(av[0], "--debug") == 0) {
|
||||
o->log_level = DEBUG_LOG_LEVEL;
|
||||
}
|
||||
else if (strcmp(av[0], "--opt") == 0) {
|
||||
o->opt = ENABLE_OPT;
|
||||
}
|
||||
else if (strcmp(av[0], "--reset") == 0) {
|
||||
o->reset = 1;
|
||||
}
|
||||
|
@ -93,30 +96,30 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
|
|||
else
|
||||
return -1;
|
||||
}
|
||||
else if ( starts_with(av[0], "--flash=") ) {
|
||||
const char *arg = av[0] + strlen("--flash=");
|
||||
char *ep = 0;
|
||||
else if ( starts_with(av[0], "--flash=") ) {
|
||||
const char *arg = av[0] + strlen("--flash=");
|
||||
char *ep = 0;
|
||||
|
||||
o->flash_size = (uint32_t)strtoul(arg,&ep,0);
|
||||
while ( *ep ) {
|
||||
switch ( *ep++ ) {
|
||||
case 0:
|
||||
break;
|
||||
case 'k':
|
||||
case 'K':
|
||||
o->flash_size *= 1024u;
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
o->flash_size *= 1024u * 1024u;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"Invalid --flash=%s\n",arg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
o->flash_size = (uint32_t)strtoul(arg,&ep,0);
|
||||
while ( *ep ) {
|
||||
switch ( *ep++ ) {
|
||||
case 0:
|
||||
break;
|
||||
case 'k':
|
||||
case 'K':
|
||||
o->flash_size *= 1024u;
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
o->flash_size *= 1024u * 1024u;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"Invalid --flash=%s\n",arg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
break; // non-option found
|
||||
}
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@ static bool execute_test(const struct Test * test) {
|
|||
|
||||
// parse (tokenize) the test command line
|
||||
#if defined(_MSC_VER)
|
||||
char *cmd_line = alloca(strlen(test->cmd_line));
|
||||
char *cmd_line = alloca(strlen(test->cmd_line) + 1);
|
||||
#else
|
||||
char cmd_line[strlen(test->cmd_line)];
|
||||
char cmd_line[strlen(test->cmd_line) + 1];
|
||||
#endif
|
||||
strcpy(cmd_line, test->cmd_line);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue