@@ -14,6 +14,7 @@ import (
14
14
"github.com/arduino/FirmwareUploader/modules/winc"
15
15
"github.com/arduino/FirmwareUploader/utils"
16
16
"github.com/arduino/FirmwareUploader/utils/context"
17
+ "github.com/arduino/go-paths-helper"
17
18
)
18
19
19
20
var ctx = & context.Context {}
@@ -25,7 +26,7 @@ func init() {
25
26
flag .StringVar (& ctx .FirmwareFile , "firmware" , "" , "firmware file to flash" )
26
27
flag .BoolVar (& ctx .ReadAll , "read" , false , "read all firmware and output to stdout" )
27
28
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)" )
29
30
flag .StringVar (& ctx .ProgrammerPath , "programmer" , "" , "path of programmer in use (avrdude/bossac)" )
30
31
flag .StringVar (& ctx .Model , "model" , "" , "module model (winc, nina or sara)" )
31
32
flag .StringVar (& ctx .Compatible , "get_available_for" , "" , "Ask for available firmwares matching a given board" )
@@ -44,6 +45,22 @@ func main() {
44
45
log .Fatal ("Please specify a serial port" )
45
46
}
46
47
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
+
47
64
retry := 0
48
65
for {
49
66
var ctxCopy context.Context
0 commit comments