Skip to content

harden cert flash on windows pt3 (was using port before touch) #87

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
Jul 16, 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
33 changes: 17 additions & 16 deletions cli/certificates/flash.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,8 @@ func run(cmd *cobra.Command, args []string) {

loaderSketch := strings.ReplaceAll(loaderSketchPath.String(), loaderSketchPath.Ext(), "")

uploaderCommand := board.GetUploaderCommand()
uploaderCommand = strings.ReplaceAll(uploaderCommand, "{tool_dir}", filepath.FromSlash(uploadToolDir.String()))
uploaderCommand = strings.ReplaceAll(uploaderCommand, "{serial.port.file}", address)
uploaderCommand = strings.ReplaceAll(uploaderCommand, "{loader.sketch}", loaderSketch)

commandLine, err := properties.SplitQuotedString(uploaderCommand, "\"", false)
if err != nil {
feedback.Errorf(`Error splitting command line "%s": %s`, uploaderCommand, err)
os.Exit(errorcodes.ErrGeneric)
}

// Check if board needs a 1200bps touch for upload
uploadPort := address
bootloaderPort := address
if board.UploadTouch {
logrus.Info("Putting board into bootloader mode")
newUploadPort, err := serialutils.Reset(address, board.UploadWait, nil)
Expand All @@ -143,10 +132,21 @@ func run(cmd *cobra.Command, args []string) {
}
if newUploadPort != "" {
logrus.Infof("Found port to upload Loader: %s", newUploadPort)
uploadPort = newUploadPort
bootloaderPort = newUploadPort
}
}

uploaderCommand := board.GetUploaderCommand()
uploaderCommand = strings.ReplaceAll(uploaderCommand, "{tool_dir}", filepath.FromSlash(uploadToolDir.String()))
uploaderCommand = strings.ReplaceAll(uploaderCommand, "{serial.port.file}", bootloaderPort)
uploaderCommand = strings.ReplaceAll(uploaderCommand, "{loader.sketch}", loaderSketch)

commandLine, err := properties.SplitQuotedString(uploaderCommand, "\"", false)
if err != nil {
feedback.Errorf(`Error splitting command line "%s": %s`, uploaderCommand, err)
os.Exit(errorcodes.ErrGeneric)
}

// Flash loader Sketch
programmerOut := new(bytes.Buffer)
programmerErr := new(bytes.Buffer)
Expand All @@ -162,16 +162,17 @@ func run(cmd *cobra.Command, args []string) {

// Wait a bit after flashing the loader sketch for the board to become
// available again.
time.Sleep(2 * time.Second)
time.Sleep(3 * time.Second)

// Get flasher depending on which module to use
var f flasher.Flasher
moduleName := board.Module
switch moduleName {
case "NINA":
f, err = flasher.NewNinaFlasher(uploadPort)
// we use address and not bootloaderPort because the board should not be in bootloader mode
f, err = flasher.NewNinaFlasher(address)
case "WINC1500":
f, err = flasher.NewWincFlasher(uploadPort)
f, err = flasher.NewWincFlasher(address)
default:
err = fmt.Errorf("unknown module: %s", moduleName)
}
Expand Down