Skip to content

Commit

Permalink
Merge pull request #90 from jacmet/feature/flash-erase-first
Browse files Browse the repository at this point in the history
arguments.c: add --erase-first argument to flash for devices with lockbits set
  • Loading branch information
cinderblock committed Jul 6, 2023
2 parents 997c851 + 5d7d90c commit 19e4e78
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ static void usage()
" [--suppress-validation]\n"
" [--suppress-bootloader-mem]\n"
" [--validate-first]\n"
" [--erase-first]\n"
" [--ignore-outside]\n"
" [--serial=hexdigits:offset] {file|STDIN}\n" );
fprintf( stderr, " setsecure\n" );
Expand Down Expand Up @@ -605,6 +606,24 @@ static int32_t assign_global_options( struct programmer_arguments *args,
}
}

/* Find '--erase-first' if it is here - even though it is not
* used by all this is easier. */
for( i = 0; i < argc; i++ ) {
if( 0 == strcmp("--erase-first", argv[i]) ) {
*argv[i] = '\0';

switch( args->command ) {
case com_flash:
args->com_flash_data.erase_first = 1;
break;
default:
/* not supported. */
return -1;
}
break;
}
}

/* Find '--ignore-outside' if it is here - even though it is not
* used by all this is easier. */
for( i = 0; i < argc; i++ ) {
Expand Down
1 change: 1 addition & 0 deletions src/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ struct programmer_arguments {
bootloader - force overwrite required */
bool validate_first; /* Do a validate before flashing */
bool ignore_outside; /* Ignore validate errors outside region */
bool erase_first; /* Erase flash before writing */
enum atmel_memory_unit_enum segment;
} com_flash_data;

Expand Down
13 changes: 13 additions & 0 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,19 @@ static int32_t execute_flash( dfu_device_t *device,
if( mem_type == mem_user ) {
result = atmel_user( device, &bout );
} else {
if ( 1 == args->com_flash_data.erase_first ) {
if( args->device_type & GRP_STM32 ) {
result = stm32_erase_flash( device, args->quiet );
} else {
result = atmel_erase_flash( device, ATMEL_ERASE_ALL, args->quiet );
}

if( 0 != result ) {
DEBUG( "Error erasing flash. (err %d)\n", result );
return result;
}
}

if( args->device_type & GRP_STM32 ) {
result = stm32_write_flash( device, &bout,
mem_type == mem_eeprom ? true : false,
Expand Down

0 comments on commit 19e4e78

Please sign in to comment.