@@ -92,7 +92,7 @@ static union {
9292void show_version (void )
9393{
9494 printf ("%s" ,
95- "LM4Flash version 0.1.1 - Flasher for Stellaris Launchpad ICDI boards\n"
95+ "LM4Flash version 0.1.2 - Flasher for Stellaris Launchpad ICDI boards\n"
9696 "Copyright (C) 2012 Fabio Utzig <fabio@utzig.net>\n"
9797 "Copyright (C) 2012 Peter Stuge <peter@stuge.se>\n"
9898 "This is free software; see the source for copying conditions. There is NO\n"
@@ -116,6 +116,7 @@ static uint32_t le32_to_cpu(const uint32_t x)
116116
117117static int do_verify = 0 ;
118118static int erase_used = 0 ;
119+ static uint32_t start_addr = 0 ;
119120
120121#define cpu_to_le32 le32_to_cpu
121122
@@ -505,7 +506,7 @@ static int write_firmware(libusb_device_handle *handle, FILE *f)
505506 if (erase_used ) {
506507 fseek (f , 0 , SEEK_END );
507508 size = ftell (f );
508- for (addr = 0 ; addr < size ; addr += FLASH_ERASE_SIZE )
509+ for (addr = start_addr ; addr < ( start_addr + size ) ; addr += FLASH_ERASE_SIZE )
509510 FLASH_ERASE (addr , FLASH_ERASE_SIZE );
510511 fseek (f , 0 , SEEK_SET );
511512 } else {
@@ -521,7 +522,7 @@ static int write_firmware(libusb_device_handle *handle, FILE *f)
521522 MEM_WRITE (ROMCTL , 0x0 );
522523 MEM_READ (DHCSR , & val );
523524
524- for (addr = 0 ; !feof (f ); addr += sizeof (flash_block )) {
525+ for (addr = start_addr ; !feof (f ); addr += sizeof (flash_block )) {
525526 rdbytes = fread (flash_block , 1 , sizeof (flash_block ), f );
526527
527528 if (rdbytes < sizeof (flash_block ) && !feof (f )) {
@@ -540,7 +541,7 @@ static int write_firmware(libusb_device_handle *handle, FILE *f)
540541 if (do_verify ) {
541542 fseek (f , 0 , SEEK_SET );
542543
543- for (addr = 0 ; !feof (f ); addr += sizeof (flash_block )) {
544+ for (addr = start_addr ; !feof (f ); addr += sizeof (flash_block )) {
544545 rdbytes = fread (flash_block , 1 , sizeof (flash_block ), f );
545546
546547 if (rdbytes < sizeof (flash_block ) && !feof (f )) {
@@ -701,6 +702,8 @@ static void flasher_usage()
701702 printf ("\t\tEnables verification after write\n" );
702703 printf ("\t-E\n" );
703704 printf ("\t\tOnly erase blocks where binary file will be written\n" );
705+ printf ("\t-S address\n" );
706+ printf ("\t\tWrite binary at the given address (in hexadecimal)\n" );
704707 printf ("\t-s SERIAL\n" );
705708 printf ("\t\tFlash device with the following serial\n" );
706709}
@@ -784,7 +787,7 @@ int main(int argc, char *argv[])
784787 const char * rom_name = NULL ;
785788 int opt ;
786789
787- while ((opt = getopt (argc , argv , "VEhvs :" )) != -1 ) {
790+ while ((opt = getopt (argc , argv , "VES:hvs :" )) != -1 ) {
788791 switch (opt ) {
789792 case 'V' :
790793 show_version ();
@@ -795,6 +798,11 @@ int main(int argc, char *argv[])
795798 case 'E' :
796799 erase_used = 1 ;
797800 break ;
801+ case 'S' :
802+ start_addr = strtol (optarg , NULL , 16 );
803+ /* force erasing only the used blocks */
804+ erase_used = 1 ;
805+ break ;
798806 case 'v' :
799807 do_verify = 1 ;
800808 break ;
@@ -813,5 +821,10 @@ int main(int argc, char *argv[])
813821 } else
814822 rom_name = argv [optind ];
815823
824+ if (start_addr && (start_addr % FLASH_ERASE_SIZE )) {
825+ printf ("Address given to -S must be 0x%x aligned\n" , FLASH_ERASE_SIZE );
826+ return EXIT_FAILURE ;
827+ }
828+
816829 return flasher_flash (serial , rom_name );
817830}
0 commit comments