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

Added --flash=n[k][m] command line option to override device model #576

Merged
merged 8 commits into from
Mar 24, 2017
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
8 changes: 8 additions & 0 deletions doc/man/st-flash.1
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ TODO
TODO
.RS
.RE
.TP
.B --flash=\f[I]size\f[]
Override the device's normal flash size, where size is the flash size in bytes.
It can be specified in decimal, octal or hexadecimal.
The size argument can optionally be followed by 'k' for KB or 'm' for MB.
Examples --flash=128k or --flash=0x080k.
.RS
.RE
.SH EXAMPLES
.PP
Flash \f[C]firmware.bin\f[] to device
Expand Down
4 changes: 4 additions & 0 deletions doc/man/st-flash.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ reset
--serial *iSerial*
: TODO

--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 "0x" to specify hexadecimal, or a leading zero for octal.

# EXAMPLES
Flash `firmware.bin` to device
Expand Down
3 changes: 2 additions & 1 deletion include/stlink/tools/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ struct flash_opts
int reset;
int log_level;
enum flash_format format;
size_t flash_size; /* --flash=n[k][m] */
};

#define FLASH_OPTS_INITIALIZER {0, NULL, {}, NULL, 0, 0, 0, 0, 0 }
#define FLASH_OPTS_INITIALIZER {0, NULL, {}, NULL, 0, 0, 0, 0, 0, 0 }

int flash_get_opts(struct flash_opts* o, int ac, char** av);

Expand Down
10 changes: 8 additions & 2 deletions src/tools/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ static void cleanup(int signum) {

static void usage(void)
{
puts("stlinkv1 command line: ./st-flash [--debug] [--reset] [--format <format>] {read|write} /dev/sgX <path> <addr> <size>");
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] /dev/sgX erase");
puts("stlinkv2 command line: ./st-flash [--debug] [--reset] [--serial <serial>] [--format <format>] {read|write} <path> <addr> <size>");
puts("stlinkv2 command line: ./st-flash [--debug] [--reset] [--serial <serial>] [--format <format>] [--flash=<fsize>] {read|write} <path> <addr> <size>");
puts("stlinkv2 command line: ./st-flash [--debug] [--serial <serial>] erase");
puts("stlinkv2 command line: ./st-flash [--debug] [--serial <serial>] reset");
puts(" Use hex format for addr, <serial> and <size>.");
puts(" fsize: Use decimal, octal or hex by prefix 0xXXX for hex, optionally followed by k=KB, or m=MB (eg. --flash=128k)");
puts(" Format may be 'binary' (default) or 'ihex', although <addr> must be specified for binary format only.");
puts(" ./st-flash [--version]");
}
Expand Down Expand Up @@ -64,6 +65,11 @@ int main(int ac, char** av)
if (sl == NULL)
return -1;

if ( o.flash_size != 0u && o.flash_size != sl->flash_size ) {
sl->flash_size = o.flash_size;
printf("Forcing flash size: --flash=0x%08zX\n",sl->flash_size);
}

sl->verbose = o.log_level;

connected_stlink = sl;
Expand Down
25 changes: 24 additions & 1 deletion src/tools/flash_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,30 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av)
else
return -1;
}
else {
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 {
break; // non-option found
}

Expand Down