Skip to content

Commit d4e105b

Browse files
committed
Prepared scaffolding for flash-firmware command using plugins
1 parent 555dacb commit d4e105b

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

cli/firmware/flash.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
var (
4141
commonFlags arguments.Flags // contains fqbn and address
4242
module string
43-
retries uint8
43+
retries int
4444
fwFile string
4545
)
4646

@@ -60,7 +60,7 @@ func NewFlashCommand() *cobra.Command {
6060
}
6161
commonFlags.AddToCommand(command)
6262
command.Flags().StringVarP(&module, "module", "m", "", "Firmware module ID, e.g.: WINC1500, NINA")
63-
command.Flags().Uint8Var(&retries, "retries", 9, "Number of retries in case of upload failure (default 9)")
63+
command.Flags().IntVar(&retries, "retries", 9, "Number of retries in case of upload failure (default 9)")
6464
command.Flags().StringVarP(&fwFile, "input-file", "i", "", "Path of the firmware to upload")
6565
return command
6666
}
@@ -114,22 +114,31 @@ func runFlash(cmd *cobra.Command, args []string) {
114114
logrus.Debugf("firmware file downloaded in %s", firmwareFilePath.String())
115115
}
116116

117-
loaderSketchPath, err := download.DownloadSketch(board.LoaderSketch)
118-
if err != nil {
119-
feedback.Fatal(fmt.Sprintf("Error downloading loader sketch from %s: %s", board.LoaderSketch.URL, err), feedback.ErrGeneric)
117+
loaderSketch := ""
118+
if !board.IsPlugin() {
119+
loaderSketchPath, err := download.DownloadSketch(board.LoaderSketch)
120+
if err != nil {
121+
feedback.Fatal(fmt.Sprintf("Error downloading loader sketch from %s: %s", board.LoaderSketch.URL, err), feedback.ErrGeneric)
122+
}
123+
logrus.Debugf("loader sketch downloaded in %s", loaderSketchPath.String())
124+
loaderSketch = strings.ReplaceAll(loaderSketchPath.String(), loaderSketchPath.Ext(), "")
125+
} else {
126+
// TODO...
120127
}
121-
logrus.Debugf("loader sketch downloaded in %s", loaderSketchPath.String())
122128

123-
loaderSketch := strings.ReplaceAll(loaderSketchPath.String(), loaderSketchPath.Ext(), "")
124-
125-
for retry := 1; retry <= int(retries); retry++ {
126-
err = updateFirmware(board, loaderSketch, moduleName, uploadToolDir, firmwareFilePath)
129+
for retry := 1; retry <= retries; retry++ {
130+
var err error
131+
if !board.IsPlugin() {
132+
err = updateFirmware(board, loaderSketch, moduleName, uploadToolDir, firmwareFilePath)
133+
} else {
134+
err = nil // TODO...
135+
}
127136
if err == nil {
128137
logrus.Info("Operation completed: success! :-)")
129138
break
130139
}
131140
logrus.Error(err)
132-
if retry == int(retries) {
141+
if retry == retries {
133142
logrus.Fatal("Operation failed. :-(")
134143
}
135144
logrus.Info("Waiting 1 second before retrying...")

0 commit comments

Comments
 (0)