Skip to content

Added sanity check for restore_firmware flag #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/arduino/FirmwareUploader/modules/winc"
"github.com/arduino/FirmwareUploader/utils"
"github.com/arduino/FirmwareUploader/utils/context"
"github.com/arduino/go-paths-helper"
)

var ctx = &context.Context{}
Expand All @@ -25,7 +26,7 @@ func init() {
flag.StringVar(&ctx.FirmwareFile, "firmware", "", "firmware file to flash")
flag.BoolVar(&ctx.ReadAll, "read", false, "read all firmware and output to stdout")
flag.StringVar(&ctx.FWUploaderBinary, "flasher", "", "firmware upload binary (precompiled for the right target)")
flag.StringVar(&ctx.BinaryToRestore, "restore_binary", "", "firmware upload binary (precompiled for the right target)")
flag.StringVar(&ctx.BinaryToRestore, "restore_binary", "", "binary to restore after the firmware upload (precompiled for the right target)")
flag.StringVar(&ctx.ProgrammerPath, "programmer", "", "path of programmer in use (avrdude/bossac)")
flag.StringVar(&ctx.Model, "model", "", "module model (winc, nina or sara)")
flag.StringVar(&ctx.Compatible, "get_available_for", "", "Ask for available firmwares matching a given board")
Expand All @@ -44,6 +45,22 @@ func main() {
log.Fatal("Please specify a serial port")
}

if ctx.BinaryToRestore != "" {
// sanity check for BinaryToRestore
f := paths.New(ctx.BinaryToRestore)
info, err := f.Stat()
if err != nil {
log.Fatalf("Error opening restore_binary: %s", err)
}
if info.IsDir() {
log.Fatalf("Error opening restore_binary: is a directory...")
}
if info.Size() == 0 {
log.Println("WARNING: restore_binary is empty! Will not restore binary after upload.")
ctx.BinaryToRestore = ""
}
}

retry := 0
for {
var ctxCopy context.Context
Expand Down