1
1
/*
2
2
stm32flash - Open Source ST STM32 flash program for *nix
3
3
Copyright (C) 2010 Geoffrey McRae <geoff@spacevs.com>
4
+ ..Copyright (C) 2011 Steve Markgraf <steve@steve-m.de>
4
5
5
6
This program is free software; you can redistribute it and/or
6
7
modify it under the terms of the GNU General Public License
@@ -46,6 +47,7 @@ char *device = NULL;
46
47
serial_baud_t baudRate = SERIAL_BAUD_57600 ;
47
48
int rd = 0 ;
48
49
int wr = 0 ;
50
+ int wu = 0 ;
49
51
int npages = 0xFF ;
50
52
char verify = 0 ;
51
53
int retry = 10 ;
@@ -164,7 +166,7 @@ int main(int argc, char* argv[]) {
164
166
uint32_t left = stm -> dev -> fl_end - addr ;
165
167
len = sizeof (buffer ) > left ? left : sizeof (buffer );
166
168
if (!stm32_read_memory (stm , addr , buffer , len )) {
167
- fprintf (stderr , "Failed to read memory at address 0x%08x\n" , addr );
169
+ fprintf (stderr , "Failed to read memory at address 0x%08x, target write-protected? \n" , addr );
168
170
goto close ;
169
171
}
170
172
assert (parser -> write (p_st , buffer , len ) == PARSER_ERR_OK );
@@ -180,8 +182,15 @@ int main(int argc, char* argv[]) {
180
182
fprintf (stdout , "Done.\n" );
181
183
ret = 0 ;
182
184
goto close ;
183
- } else
184
- if (wr ) {
185
+
186
+ } else if (wu ) {
187
+ fprintf (stdout , "Write-unprotecting flash\n" );
188
+ /* the device automatically performs a reset after the sending the ACK */
189
+ reset_flag = 0 ;
190
+ stm32_wunprot_memory (stm );
191
+ fprintf (stdout , "Done.\n" );
192
+
193
+ } else if (wr ) {
185
194
printf ("\n" );
186
195
187
196
off_t offset = 0 ;
@@ -287,7 +296,7 @@ int main(int argc, char* argv[]) {
287
296
288
297
int parse_options (int argc , char * argv []) {
289
298
int c ;
290
- while ((c = getopt (argc , argv , "b:r:w:e:vn:g:fch " )) != -1 ) {
299
+ while ((c = getopt (argc , argv , "b:r:w:e:vn:g:fchu " )) != -1 ) {
291
300
switch (c ) {
292
301
case 'b' :
293
302
baudRate = serial_get_baud (strtoul (optarg , NULL , 0 ));
@@ -316,7 +325,13 @@ int parse_options(int argc, char *argv[]) {
316
325
return 1 ;
317
326
}
318
327
break ;
319
-
328
+ case 'u' :
329
+ wu = 1 ;
330
+ if (rd || wr ) {
331
+ fprintf (stderr , "ERROR: Invalid options, can't write unprotect and read/write at the same time\n" );
332
+ return 1 ;
333
+ }
334
+ break ;
320
335
case 'v' :
321
336
verify = 1 ;
322
337
break ;
@@ -374,6 +389,7 @@ void show_help(char *name) {
374
389
" -b rate Baud rate (default 57600)\n"
375
390
" -r filename Read flash to file\n"
376
391
" -w filename Write flash to file\n"
392
+ " -u Disable the flash write-protection\n"
377
393
" -e n Only erase n pages before writing the flash\n"
378
394
" -v Verify writes\n"
379
395
" -n count Retry failed writes up to count times (default 10)\n"
0 commit comments