From 90a1ed9964110c17971181ade1c674d38f0cd90c Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Wed, 16 Jun 2021 14:36:17 +0200 Subject: [PATCH 1/4] enhance reset logic (port could change after reset) --- cli/certificates/flash.go | 15 ++++++++++----- cli/firmware/flash.go | 14 ++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cli/certificates/flash.go b/cli/certificates/flash.go index c18a4402..75737ba0 100644 --- a/cli/certificates/flash.go +++ b/cli/certificates/flash.go @@ -133,13 +133,18 @@ func run(cmd *cobra.Command, args []string) { } // Check if board needs a 1200bps touch for upload + uploadPort := address if board.UploadTouch { logrus.Info("Putting board into bootloader mode") - _, err := serialutils.Reset(address, board.UploadWait, nil) + newUploadPort, err := serialutils.Reset(address, board.UploadWait, nil) if err != nil { - feedback.Errorf("Error during certificates flashing: missing board address") + feedback.Errorf("Error during firmware flashing: missing board address") os.Exit(errorcodes.ErrGeneric) } + if newUploadPort != "" { + logrus.Infof("Found port to upload Loader: %s", newUploadPort) + uploadPort = newUploadPort + } } // Flash loader Sketch @@ -164,11 +169,11 @@ func run(cmd *cobra.Command, args []string) { moduleName := board.Module switch moduleName { case "NINA": - f, err = flasher.NewNinaFlasher(address) + f, err = flasher.NewNinaFlasher(uploadPort) case "SARA": - f, err = flasher.NewSaraFlasher(address) + f, err = flasher.NewSaraFlasher(uploadPort) case "WINC1500": - f, err = flasher.NewWincFlasher(address) + f, err = flasher.NewWincFlasher(uploadPort) default: err = fmt.Errorf("unknown module: %s", moduleName) } diff --git a/cli/firmware/flash.go b/cli/firmware/flash.go index af073cc0..58ae7db3 100644 --- a/cli/firmware/flash.go +++ b/cli/firmware/flash.go @@ -160,14 +160,20 @@ func run(cmd *cobra.Command, args []string) { } // Check if board needs a 1200bps touch for upload + uploadPort := address if board.UploadTouch { logrus.Info("Putting board into bootloader mode") - _, err := serialutils.Reset(address, board.UploadWait, nil) + newUploadPort, err := serialutils.Reset(address, board.UploadWait, nil) if err != nil { feedback.Errorf("Error during firmware flashing: missing board address") os.Exit(errorcodes.ErrGeneric) } + if newUploadPort != "" { + logrus.Infof("Found port to upload Loader: %s", newUploadPort) + uploadPort = newUploadPort + } } + // TODO use uploadPort instead of address // Flash loader Sketch programmerOut := new(bytes.Buffer) @@ -190,11 +196,11 @@ func run(cmd *cobra.Command, args []string) { var f flasher.Flasher switch moduleName { case "NINA": - f, err = flasher.NewNinaFlasher(address) + f, err = flasher.NewNinaFlasher(uploadPort) case "SARA": - f, err = flasher.NewSaraFlasher(address) + f, err = flasher.NewSaraFlasher(uploadPort) case "WINC1500": - f, err = flasher.NewWincFlasher(address) + f, err = flasher.NewWincFlasher(uploadPort) default: err = fmt.Errorf("unknown module: %s", moduleName) } From b8b1c4aaf77afc993f479c1cc13cc6230aa670d0 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Wed, 16 Jun 2021 14:40:40 +0200 Subject: [PATCH 2/4] increment wait time: the board could still be unavailable after 1 sec --- cli/certificates/flash.go | 2 +- cli/firmware/flash.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/certificates/flash.go b/cli/certificates/flash.go index 75737ba0..a51ebcb9 100644 --- a/cli/certificates/flash.go +++ b/cli/certificates/flash.go @@ -162,7 +162,7 @@ func run(cmd *cobra.Command, args []string) { // Wait a bit after flashing the loader sketch for the board to become // available again. - time.Sleep(1 * time.Second) + time.Sleep(2 * time.Second) // Get flasher depending on which module to use var f flasher.Flasher diff --git a/cli/firmware/flash.go b/cli/firmware/flash.go index 58ae7db3..ef3e09fb 100644 --- a/cli/firmware/flash.go +++ b/cli/firmware/flash.go @@ -190,7 +190,7 @@ func run(cmd *cobra.Command, args []string) { // Wait a bit after flashing the loader sketch for the board to become // available again. - time.Sleep(1 * time.Second) + time.Sleep(2 * time.Second) // Get flasher depending on which module to use var f flasher.Flasher From 9fc0ab75f84263f5f272fce23cc27ee87c5ae89a Mon Sep 17 00:00:00 2001 From: Umberto Baldi <34278123+umbynos@users.noreply.github.com> Date: Wed, 16 Jun 2021 17:02:49 +0200 Subject: [PATCH 3/4] Remove useless comment --- cli/firmware/flash.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/firmware/flash.go b/cli/firmware/flash.go index ef3e09fb..38af33f7 100644 --- a/cli/firmware/flash.go +++ b/cli/firmware/flash.go @@ -173,7 +173,6 @@ func run(cmd *cobra.Command, args []string) { uploadPort = newUploadPort } } - // TODO use uploadPort instead of address // Flash loader Sketch programmerOut := new(bytes.Buffer) From c4df98fbb5ebe578bfcb68de2904ee8213410852 Mon Sep 17 00:00:00 2001 From: Umberto Baldi <34278123+umbynos@users.noreply.github.com> Date: Wed, 16 Jun 2021 17:03:05 +0200 Subject: [PATCH 4/4] Update cli/certificates/flash.go Co-authored-by: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com> --- cli/certificates/flash.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/certificates/flash.go b/cli/certificates/flash.go index a51ebcb9..60e06e7c 100644 --- a/cli/certificates/flash.go +++ b/cli/certificates/flash.go @@ -138,7 +138,7 @@ func run(cmd *cobra.Command, args []string) { logrus.Info("Putting board into bootloader mode") newUploadPort, err := serialutils.Reset(address, board.UploadWait, nil) if err != nil { - feedback.Errorf("Error during firmware flashing: missing board address") + feedback.Errorf("Error during certificates flashing: missing board address") os.Exit(errorcodes.ErrGeneric) } if newUploadPort != "" {