-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add -E option to enable erasing only used flash
- Loading branch information
Fabio Utzig
committed
Jun 11, 2013
1 parent
dbd6d7f
commit 0e55c4f
Showing
1 changed file
with
21 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ static const uint8_t ENDPOINT_OUT = 0x02; | |
#define END_LEN (strlen(END) + 2) | ||
|
||
#define FLASH_BLOCK_SIZE 512 | ||
#define FLASH_ERASE_SIZE 1024 | ||
|
||
/* Prefix + potentially every flash byte escaped */ | ||
#define BUF_SIZE 64 + 2*FLASH_BLOCK_SIZE | ||
|
@@ -91,7 +92,7 @@ static union { | |
void show_version(void) | ||
{ | ||
printf("%s", | ||
"LM4Flash version 0.1 - Flasher for Stellaris Launchpad ICDI boards\n" | ||
"LM4Flash version 0.1.1 - Flasher for Stellaris Launchpad ICDI boards\n" | ||
"Copyright (C) 2012 Fabio Utzig <[email protected]>\n" | ||
"Copyright (C) 2012 Peter Stuge <[email protected]>\n" | ||
"This is free software; see the source for copying conditions. There is NO\n" | ||
|
@@ -114,6 +115,7 @@ static uint32_t le32_to_cpu(const uint32_t x) | |
} | ||
|
||
static int do_verify = 0; | ||
static int erase_used = 0; | ||
|
||
#define cpu_to_le32 le32_to_cpu | ||
|
||
|
@@ -473,6 +475,7 @@ static int write_firmware(libusb_device_handle *handle, FILE *f) | |
uint32_t addr; | ||
size_t rdbytes; | ||
int retval = 0; | ||
uint32_t size; | ||
|
||
print_icdi_version(handle); | ||
|
||
|
@@ -498,7 +501,17 @@ static int write_firmware(libusb_device_handle *handle, FILE *f) | |
|
||
MEM_WRITE(FMA, 0x0); | ||
MEM_READ(DHCSR, &val); | ||
FLASH_ERASE(0, 0); | ||
|
||
if (erase_used) { | ||
fseek(f, 0, SEEK_END); | ||
size = ftell(f); | ||
for (addr = 0; addr < size; addr += FLASH_ERASE_SIZE) | ||
FLASH_ERASE(addr, FLASH_ERASE_SIZE); | ||
fseek(f, 0, SEEK_SET); | ||
} else { | ||
FLASH_ERASE(0, 0); | ||
} | ||
|
||
SEND_COMMAND("debug creset"); | ||
MEM_READ(DHCSR, &val); | ||
|
||
|
@@ -686,6 +699,8 @@ static void flasher_usage() | |
printf("\t\tPrint usage information\n"); | ||
printf("\t-v\n"); | ||
printf("\t\tEnables verification after write\n"); | ||
printf("\t-E\n"); | ||
printf("\t\tOnly erase blocks where binary file will be written\n"); | ||
printf("\t-s SERIAL\n"); | ||
printf("\t\tFlash device with the following serial\n"); | ||
} | ||
|
@@ -769,14 +784,17 @@ int main(int argc, char *argv[]) | |
const char *rom_name = NULL; | ||
int opt; | ||
|
||
while ((opt = getopt(argc, argv, "Vhvs:")) != -1) { | ||
while ((opt = getopt(argc, argv, "VEhvs:")) != -1) { | ||
switch (opt) { | ||
case 'V': | ||
show_version(); | ||
return 0; | ||
case 'h': | ||
flasher_usage(); | ||
return 0; | ||
case 'E': | ||
erase_used = 1; | ||
break; | ||
case 'v': | ||
do_verify = 1; | ||
break; | ||
|