@@ -13,6 +13,7 @@ import (
13
13
"github.com/arduino/FirmwareUploader/modules/winc"
14
14
"github.com/arduino/FirmwareUploader/utils"
15
15
"github.com/arduino/FirmwareUploader/utils/context"
16
+ "github.com/arduino/go-paths-helper"
16
17
)
17
18
18
19
var ctx = & context.Context {}
@@ -24,7 +25,7 @@ func init() {
24
25
flag .StringVar (& ctx .FirmwareFile , "firmware" , "" , "firmware file to flash" )
25
26
flag .BoolVar (& ctx .ReadAll , "read" , false , "read all firmware and output to stdout" )
26
27
flag .StringVar (& ctx .FWUploaderBinary , "flasher" , "" , "firmware upload binary (precompiled for the right target)" )
27
- flag .StringVar (& ctx .BinaryToRestore , "restore_binary" , "" , "firmware upload binary (precompiled for the right target)" )
28
+ flag .StringVar (& ctx .BinaryToRestore , "restore_binary" , "" , "binary to restore after the firmware upload (precompiled for the right target)" )
28
29
flag .StringVar (& ctx .ProgrammerPath , "programmer" , "" , "path of programmer in use (avrdude/bossac)" )
29
30
flag .StringVar (& ctx .Model , "model" , "" , "module model (winc, nina or sara)" )
30
31
flag .StringVar (& ctx .Compatible , "get_available_for" , "" , "Ask for available firmwares matching a given board" )
@@ -43,6 +44,22 @@ func main() {
43
44
log .Fatal ("Please specify a serial port" )
44
45
}
45
46
47
+ if ctx .BinaryToRestore != "" {
48
+ // sanity check for BinaryToRestore
49
+ f := paths .New (ctx .BinaryToRestore )
50
+ info , err := f .Stat ()
51
+ if err != nil {
52
+ log .Fatalf ("Error opening restore_binary: %s" , err )
53
+ }
54
+ if info .IsDir () {
55
+ log .Fatalf ("Error opening restore_binary: is a directory..." )
56
+ }
57
+ if info .Size () == 0 {
58
+ log .Println ("WARNING: restore_binary is empty! Will not restore binary after upload." )
59
+ ctx .BinaryToRestore = ""
60
+ }
61
+ }
62
+
46
63
if ctx .Model == "nina" || strings .Contains (ctx .FirmwareFile , "NINA" ) || strings .Contains (ctx .FWUploaderBinary , "NINA" ) {
47
64
nina .Run (ctx )
48
65
} else if ctx .Model == "winc" || strings .Contains (ctx .FirmwareFile , "WINC" ) || strings .Contains (ctx .FWUploaderBinary , "WINC" ) {
0 commit comments