@@ -14,6 +14,7 @@ import (
1414 "github.com/arduino/FirmwareUploader/modules/winc"
1515 "github.com/arduino/FirmwareUploader/utils"
1616 "github.com/arduino/FirmwareUploader/utils/context"
17+ "github.com/arduino/go-paths-helper"
1718)
1819
1920var ctx = & context.Context {}
@@ -25,7 +26,7 @@ func init() {
2526 flag .StringVar (& ctx .FirmwareFile , "firmware" , "" , "firmware file to flash" )
2627 flag .BoolVar (& ctx .ReadAll , "read" , false , "read all firmware and output to stdout" )
2728 flag .StringVar (& ctx .FWUploaderBinary , "flasher" , "" , "firmware upload binary (precompiled for the right target)" )
28- flag .StringVar (& ctx .BinaryToRestore , "restore_binary" , "" , "firmware upload binary (precompiled for the right target)" )
29+ flag .StringVar (& ctx .BinaryToRestore , "restore_binary" , "" , "binary to restore after the firmware upload (precompiled for the right target)" )
2930 flag .StringVar (& ctx .ProgrammerPath , "programmer" , "" , "path of programmer in use (avrdude/bossac)" )
3031 flag .StringVar (& ctx .Model , "model" , "" , "module model (winc, nina or sara)" )
3132 flag .StringVar (& ctx .Compatible , "get_available_for" , "" , "Ask for available firmwares matching a given board" )
@@ -44,6 +45,22 @@ func main() {
4445 log .Fatal ("Please specify a serial port" )
4546 }
4647
48+ if ctx .BinaryToRestore != "" {
49+ // sanity check for BinaryToRestore
50+ f := paths .New (ctx .BinaryToRestore )
51+ info , err := f .Stat ()
52+ if err != nil {
53+ log .Fatalf ("Error opening restore_binary: %s" , err )
54+ }
55+ if info .IsDir () {
56+ log .Fatalf ("Error opening restore_binary: is a directory..." )
57+ }
58+ if info .Size () == 0 {
59+ log .Println ("WARNING: restore_binary is empty! Will not restore binary after upload." )
60+ ctx .BinaryToRestore = ""
61+ }
62+ }
63+
4764 retry := 0
4865 for {
4966 var ctxCopy context.Context
0 commit comments