Skip to content

Commit b8b94c7

Browse files
cleanup support for flashing module in favor of plugins only
1 parent ad9f3ff commit b8b94c7

File tree

1 file changed

+5
-76
lines changed

1 file changed

+5
-76
lines changed

cli/firmware/flash.go

+5-76
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package firmware
2020

2121
import (
22-
"bytes"
2322
"fmt"
2423
"io"
2524
"os"
@@ -120,35 +119,17 @@ func runFlash(cmd *cobra.Command, args []string) {
120119
logrus.Debugf("firmware file downloaded in %s", firmwareFilePath.String())
121120
}
122121

123-
loaderSketch := ""
124-
var uploader *plugin.FwUploader
125-
if !board.IsPlugin() {
126-
loaderSketchPath, err := download.DownloadSketch(board.LoaderSketch)
127-
if err != nil {
128-
feedback.Fatal(fmt.Sprintf("Error downloading loader sketch from %s: %s", board.LoaderSketch.URL, err), feedback.ErrGeneric)
129-
}
130-
logrus.Debugf("loader sketch downloaded in %s", loaderSketchPath.String())
131-
loaderSketch = strings.ReplaceAll(loaderSketchPath.String(), loaderSketchPath.Ext(), "")
132-
} else {
133-
var err error
134-
uploader, err = plugin.NewFWUploaderPlugin(uploadToolDir)
135-
if err != nil {
136-
feedback.Fatal(fmt.Sprintf("Could not open uploader plugin: %s", err), feedback.ErrGeneric)
137-
}
122+
uploader, err := plugin.NewFWUploaderPlugin(uploadToolDir)
123+
if err != nil {
124+
feedback.Fatal(fmt.Sprintf("Could not open uploader plugin: %s", err), feedback.ErrGeneric)
138125
}
139126

140127
retry := 0
141128
for {
142129
retry++
143130
logrus.Infof("Uploading firmware (try %d of %d)", retry, retries)
144131

145-
var res *flasher.FlashResult
146-
var err error
147-
if !board.IsPlugin() {
148-
res, err = updateFirmware(board, loaderSketch, moduleName, uploadToolDir, firmwareFilePath)
149-
} else {
150-
res, err = updateFirmwareWithPlugin(uploader, firmwareFilePath)
151-
}
132+
res, err := updateFirmware(uploader, firmwareFilePath)
152133
if err == nil {
153134
feedback.PrintResult(res)
154135
logrus.Info("Operation completed: success! :-)")
@@ -165,7 +146,7 @@ func runFlash(cmd *cobra.Command, args []string) {
165146
}
166147
}
167148

168-
func updateFirmwareWithPlugin(uploader *plugin.FwUploader, fwPath *paths.Path) (*flasher.FlashResult, error) {
149+
func updateFirmware(uploader *plugin.FwUploader, fwPath *paths.Path) (*flasher.FlashResult, error) {
169150
var stdout, stderr io.Writer
170151
if feedback.GetFormat() == feedback.Text {
171152
stdout = os.Stdout
@@ -183,58 +164,6 @@ func updateFirmwareWithPlugin(uploader *plugin.FwUploader, fwPath *paths.Path) (
183164
}, nil
184165
}
185166

186-
func updateFirmware(board *firmwareindex.IndexBoard, loaderSketch, moduleName string, uploadToolDir, firmwareFile *paths.Path) (*flasher.FlashResult, error) {
187-
programmerOut, programmerErr, err := common.FlashSketch(board, loaderSketch, uploadToolDir, commonFlags.Address)
188-
if err != nil {
189-
return nil, err
190-
}
191-
// Wait a bit after flashing the loader sketch for the board to become
192-
// available again.
193-
logrus.Debug("sleeping for 3 sec")
194-
time.Sleep(3 * time.Second)
195-
196-
// Get flasher depending on which module to use
197-
var f flasher.Flasher
198-
199-
// This matches the baudrate used in the FirmwareUpdater.ino sketch
200-
const baudRate = 1000000
201-
switch moduleName {
202-
default:
203-
err = fmt.Errorf("unknown module: %s", moduleName)
204-
feedback.Fatal(fmt.Sprintf("Error during firmware flashing: %s", err), feedback.ErrGeneric)
205-
}
206-
if err != nil {
207-
return nil, fmt.Errorf("error during firmware flashing: %s", err)
208-
}
209-
defer f.Close()
210-
211-
// now flash the actual firmware
212-
flasherOut := new(bytes.Buffer)
213-
flasherErr := new(bytes.Buffer)
214-
if feedback.GetFormat() == feedback.JSON {
215-
err = f.FlashFirmware(firmwareFile, flasherOut)
216-
} else {
217-
f.SetProgressCallback(printProgress)
218-
err = f.FlashFirmware(firmwareFile, os.Stdout)
219-
}
220-
if err != nil {
221-
flasherErr.Write([]byte(fmt.Sprintf("Error during firmware flashing: %s", err)))
222-
return nil, err
223-
}
224-
225-
// Print the results
226-
return &flasher.FlashResult{
227-
Programmer: (&flasher.ExecOutput{
228-
Stdout: programmerOut.String(),
229-
Stderr: programmerErr.String(),
230-
}),
231-
Flasher: (&flasher.ExecOutput{
232-
Stdout: flasherOut.String(),
233-
Stderr: flasherErr.String(),
234-
}),
235-
}, nil
236-
}
237-
238167
// callback used to print the progress
239168
func printProgress(progress int) {
240169
fmt.Printf("Flashing progress: %d%%\r", progress)

0 commit comments

Comments
 (0)