Skip to content

Commit

Permalink
add erase region command
Browse files Browse the repository at this point in the history
  • Loading branch information
igrr committed Feb 17, 2018
1 parent e2ddc2b commit ee33240
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Argument | Description
```-ca <address>``` | Address in flash memory to upload the data to. This address is interpreted as hexadecimal. Default is 0x00000000.
```-cf <filename>``` | Upload the file to flash. Parameters that set the port, baud rate, and address must precede the -cf command.
```-cp <size>``` | Pad last written section of firmware image to the given size, in bytes.
```-cz <size>``` | Erase `size` bytes of flash starting from address set using `-ca` flag. Erase region boundaries must be aligned to 4kB.
```-ce``` | Erase flash
```-cr``` | Reset chip into app using the selected reset method

Expand Down
3 changes: 3 additions & 0 deletions argparse/argparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ they are given.\n\
Upload the file to flash. Parameters that set the port, baud rate, and address\n\
must precede the -cf command.\n\
\n\
-cz <size>\n\
Erase <size> bytes, starting from the address set using -ca flag.\n\
\n\
-cr\n\
Reset chip into app using the selected reset method.\n\
\n\
Expand Down
11 changes: 11 additions & 0 deletions argparse/argparse_commcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ int argparse_commcmd(int num_args, char **arg_ptr)
}
break;

case 'z':
if (num_args < 1)
{
return 0;
}
if (espcomm_erase_region(arg_ptr[0]))
{
return 2;
}
break;

case 'd':
if (num_args < 1)
{
Expand Down
24 changes: 24 additions & 0 deletions espcomm/espcomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,30 @@ bool espcomm_upload_file(const char *name)
return true;
}

bool espcomm_erase_region(const char* size)
{
uint32_t erase_size = (uint32_t) strtol(size, NULL, 16);
LOGDEBUG("setting erase size to 0x%08X",erase_size);

if(!espcomm_open())
{
LOGERR("espcomm_open failed");
return false;
}

INFO("Erasing 0x%X bytes starting at 0x%08X\n", erase_size, espcomm_address);
LOGDEBUG("erasing flash");
int res = espcomm_start_flash(erase_size, espcomm_address);
if (res == 0)
{
LOGWARN("espcomm_send_command(FLASH_DOWNLOAD_BEGIN) failed");
espcomm_close();
return false;
}

return true;
}

int espcomm_start_app(int reboot)
{
if(!espcomm_open())
Expand Down
2 changes: 1 addition & 1 deletion espcomm/espcomm.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool espcomm_upload_file_compressed(const char* name);
int espcomm_file_uploaded();
int espcomm_start_app(int reboot);
bool espcomm_reset();

bool espcomm_erase_region(const char* size);
bool espcomm_erase_flash();

#endif

0 comments on commit ee33240

Please sign in to comment.