Skip to content

Commit ee33240

Browse files
committed
add erase region command
1 parent e2ddc2b commit ee33240

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Argument | Description
3737
```-ca <address>``` | Address in flash memory to upload the data to. This address is interpreted as hexadecimal. Default is 0x00000000.
3838
```-cf <filename>``` | Upload the file to flash. Parameters that set the port, baud rate, and address must precede the -cf command.
3939
```-cp <size>``` | Pad last written section of firmware image to the given size, in bytes.
40+
```-cz <size>``` | Erase `size` bytes of flash starting from address set using `-ca` flag. Erase region boundaries must be aligned to 4kB.
4041
```-ce``` | Erase flash
4142
```-cr``` | Reset chip into app using the selected reset method
4243

argparse/argparse.c

+3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ they are given.\n\
115115
Upload the file to flash. Parameters that set the port, baud rate, and address\n\
116116
must precede the -cf command.\n\
117117
\n\
118+
-cz <size>\n\
119+
Erase <size> bytes, starting from the address set using -ca flag.\n\
120+
\n\
118121
-cr\n\
119122
Reset chip into app using the selected reset method.\n\
120123
\n\

argparse/argparse_commcmd.c

+11
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ int argparse_commcmd(int num_args, char **arg_ptr)
8686
}
8787
break;
8888

89+
case 'z':
90+
if (num_args < 1)
91+
{
92+
return 0;
93+
}
94+
if (espcomm_erase_region(arg_ptr[0]))
95+
{
96+
return 2;
97+
}
98+
break;
99+
89100
case 'd':
90101
if (num_args < 1)
91102
{

espcomm/espcomm.c

+24
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,30 @@ bool espcomm_upload_file(const char *name)
565565
return true;
566566
}
567567

568+
bool espcomm_erase_region(const char* size)
569+
{
570+
uint32_t erase_size = (uint32_t) strtol(size, NULL, 16);
571+
LOGDEBUG("setting erase size to 0x%08X",erase_size);
572+
573+
if(!espcomm_open())
574+
{
575+
LOGERR("espcomm_open failed");
576+
return false;
577+
}
578+
579+
INFO("Erasing 0x%X bytes starting at 0x%08X\n", erase_size, espcomm_address);
580+
LOGDEBUG("erasing flash");
581+
int res = espcomm_start_flash(erase_size, espcomm_address);
582+
if (res == 0)
583+
{
584+
LOGWARN("espcomm_send_command(FLASH_DOWNLOAD_BEGIN) failed");
585+
espcomm_close();
586+
return false;
587+
}
588+
589+
return true;
590+
}
591+
568592
int espcomm_start_app(int reboot)
569593
{
570594
if(!espcomm_open())

espcomm/espcomm.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ bool espcomm_upload_file_compressed(const char* name);
8080
int espcomm_file_uploaded();
8181
int espcomm_start_app(int reboot);
8282
bool espcomm_reset();
83-
83+
bool espcomm_erase_region(const char* size);
8484
bool espcomm_erase_flash();
8585

8686
#endif

0 commit comments

Comments
 (0)