2121 verbose = flag .Bool ("v" , false , "Show verbose logging" )
2222 quiet = flag .Bool ("q" , true , "Show quiet logging" )
2323 force = flag .Bool ("f" , false , "Force firmware update" )
24+ copier = flag .Bool ("c" , false , "Copy bin_file to bin_save" )
25+ from = flag .String ("from" , "" , "Original file location" )
26+ to = flag .String ("to" , "" , "Save file location" )
2427 dfu_path = flag .String ("dfu" , "" , "Location of dfu-util binaries" )
2528 bin_file_name = flag .String ("bin" , "" , "Location of sketch binary" )
2629 com_port = flag .String ("port" , "" , "Upload serial port" )
@@ -304,6 +307,15 @@ func main() {
304307
305308 PrintlnVerbose (name + " " + Version + " - compiled with " + runtime .Version ())
306309
310+ if * copier {
311+ if * from == "" || * to == "" {
312+ fmt .Println ("ERROR: need -from and -to arguments" )
313+ os .Exit (1 )
314+ }
315+ copy (* from , * to )
316+ os .Exit (0 )
317+ }
318+
307319 if strings .Contains (name , "load" ) {
308320 fmt .Println ("Starting download script..." )
309321 main_load ()
@@ -318,6 +330,36 @@ func main() {
318330 os .Exit (1 )
319331}
320332
333+ // Copy a file
334+ func copy (source , destination string ) {
335+ // Open original file
336+ originalFile , err := os .Open (source )
337+ if err != nil {
338+ os .Exit (1 )
339+ }
340+ defer originalFile .Close ()
341+
342+ // Create new file
343+ newFile , err := os .Create (destination )
344+ if err != nil {
345+ os .Exit (1 )
346+ }
347+ defer newFile .Close ()
348+
349+ // Copy the bytes to destination from source
350+ _ , err = io .Copy (newFile , originalFile )
351+ if err != nil {
352+ os .Exit (1 )
353+ }
354+
355+ // Commit the file contents
356+ // Flushes memory to disk
357+ err = newFile .Sync ()
358+ if err != nil {
359+ os .Exit (1 )
360+ }
361+ }
362+
321363func searchVersionInDFU (file string , string_to_search string ) bool {
322364 read , _ := ioutil .ReadFile (file )
323365 return strings .Contains (string (read ), string_to_search )
0 commit comments