From 64925a7beb607b861e21a0ffdfcb3b205512d591 Mon Sep 17 00:00:00 2001 From: "Deomid \"rojer\" Ryabkov" Date: Sat, 23 Oct 2021 02:09:14 +0300 Subject: [PATCH] Improve ROM connection setup on ESP32 --- cli/console.go | 2 +- cli/flash/cc3200/flasher.go | 5 +++-- cli/flash/cc3220/flasher.go | 5 +++-- cli/flash/cc32xx/rom_client.go | 5 +++-- cli/flash/esp/flasher/flasher_client.go | 5 +++-- cli/flash/esp/rom_client/rom_client.go | 9 ++++++--- common/mgrpc/codec/serial.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- 9 files changed, 23 insertions(+), 16 deletions(-) diff --git a/cli/console.go b/cli/console.go index 9a62edcd..b1c965fa 100644 --- a/cli/console.go +++ b/cli/console.go @@ -42,8 +42,8 @@ import ( "github.com/mongoose-os/mos/common/mgrpc/codec" "github.com/mongoose-os/mos/common/mgrpc/frame" - "github.com/cesanta/go-serial/serial" "github.com/juju/errors" + "github.com/mongoose-os/go-serial/serial" flag "github.com/spf13/pflag" ) diff --git a/cli/flash/cc3200/flasher.go b/cli/flash/cc3200/flasher.go index 14b17be3..56d23562 100644 --- a/cli/flash/cc3200/flasher.go +++ b/cli/flash/cc3200/flasher.go @@ -9,11 +9,12 @@ import ( "fmt" "sort" - "github.com/cesanta/go-serial/serial" "github.com/juju/errors" - "github.com/mongoose-os/mos/common/fwbundle" + "github.com/mongoose-os/go-serial/serial" + "github.com/mongoose-os/mos/cli/flash/cc32xx" "github.com/mongoose-os/mos/cli/flash/common" + "github.com/mongoose-os/mos/common/fwbundle" ) type FlashOpts struct { diff --git a/cli/flash/cc3220/flasher.go b/cli/flash/cc3220/flasher.go index 74ae4d81..8c040d09 100644 --- a/cli/flash/cc3220/flasher.go +++ b/cli/flash/cc3220/flasher.go @@ -8,11 +8,12 @@ package cc3220 import ( - "github.com/cesanta/go-serial/serial" "github.com/juju/errors" - "github.com/mongoose-os/mos/common/fwbundle" + "github.com/mongoose-os/go-serial/serial" + "github.com/mongoose-os/mos/cli/flash/cc32xx" "github.com/mongoose-os/mos/cli/flash/common" + "github.com/mongoose-os/mos/common/fwbundle" ) type FlashOpts struct { diff --git a/cli/flash/cc32xx/rom_client.go b/cli/flash/cc32xx/rom_client.go index 2414f260..629024ee 100644 --- a/cli/flash/cc32xx/rom_client.go +++ b/cli/flash/cc32xx/rom_client.go @@ -24,10 +24,11 @@ import ( "io/ioutil" "time" - "github.com/cesanta/go-serial/serial" "github.com/juju/errors" - "github.com/mongoose-os/mos/cli/flash/common" + "github.com/mongoose-os/go-serial/serial" glog "k8s.io/klog/v2" + + "github.com/mongoose-os/mos/cli/flash/common" ) type loaderCmd uint8 diff --git a/cli/flash/esp/flasher/flasher_client.go b/cli/flash/esp/flasher/flasher_client.go index fe513a0d..bafdc60a 100644 --- a/cli/flash/esp/flasher/flasher_client.go +++ b/cli/flash/esp/flasher/flasher_client.go @@ -28,14 +28,15 @@ import ( "time" "unsafe" - "github.com/cesanta/go-serial/serial" "github.com/juju/errors" + "github.com/mongoose-os/go-serial/serial" + glog "k8s.io/klog/v2" + "github.com/mongoose-os/mos/cli/flash/common" "github.com/mongoose-os/mos/cli/flash/esp" "github.com/mongoose-os/mos/cli/flash/esp/rom_client" "github.com/mongoose-os/mos/cli/flash/esp32" "github.com/mongoose-os/mos/cli/flash/esp8266" - glog "k8s.io/klog/v2" ) const ( diff --git a/cli/flash/esp/rom_client/rom_client.go b/cli/flash/esp/rom_client/rom_client.go index d6747033..d21356de 100644 --- a/cli/flash/esp/rom_client/rom_client.go +++ b/cli/flash/esp/rom_client/rom_client.go @@ -26,13 +26,14 @@ import ( "math" "time" - "github.com/cesanta/go-serial/serial" "github.com/juju/errors" + "github.com/mongoose-os/go-serial/serial" + glog "k8s.io/klog/v2" + "github.com/mongoose-os/mos/cli/flash/common" "github.com/mongoose-os/mos/cli/flash/esp" "github.com/mongoose-os/mos/cli/flash/esp32" "github.com/mongoose-os/mos/cli/flash/esp8266" - glog "k8s.io/klog/v2" ) const ( @@ -199,6 +200,7 @@ func (rc *ROMClient) sendCommand(cmd romCmd, arg []byte, csum uint8) error { binary.Write(cmdBuf, binary.LittleEndian, uint32(csum)) // Yes, uint8 -> uint32 cmdBuf.Write(arg) _, err := rc.srw.Write(cmdBuf.Bytes()) + rc.sd.Flush() return err } @@ -278,6 +280,7 @@ func (rc *ROMClient) trySync() error { if err := rc.sendCommand(cmdSync, argBuf.Bytes(), 0); err != nil { return errors.Trace(err) } + rc.sd.Flush() for i := 1; i <= 8; i++ { var r *romResponse for { @@ -305,7 +308,7 @@ func (rc *ROMClient) trySync() error { func (rc *ROMClient) sync() error { var err error // Usually there is no response to the first command, and the second is successful. - for i := 0; i < 2; i++ { + for i := 0; i < 5; i++ { err = rc.trySync() if err == nil { return nil diff --git a/common/mgrpc/codec/serial.go b/common/mgrpc/codec/serial.go index af12efba..70b72a5e 100644 --- a/common/mgrpc/codec/serial.go +++ b/common/mgrpc/codec/serial.go @@ -22,8 +22,8 @@ import ( "sync" "time" - "github.com/cesanta/go-serial/serial" "github.com/juju/errors" + "github.com/mongoose-os/go-serial/serial" glog "k8s.io/klog/v2" ) diff --git a/go.mod b/go.mod index 990024a5..64282f8d 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/Microsoft/hcsshim v0.9.0 // indirect github.com/ProtonMail/go-crypto v0.0.0-20210920160938-87db9fbc61c7 // indirect github.com/aws/aws-sdk-go v1.41.4 - github.com/cesanta/go-serial v0.0.0-20170105152649-4dff7aff019e github.com/cesanta/hid v0.0.0-20190304122332-79d86877855b github.com/containerd/cgroups v1.0.2 // indirect github.com/docker/docker v20.10.9+incompatible // indirect @@ -32,6 +31,7 @@ require ( github.com/mattn/go-colorable v0.1.7 // indirect github.com/mattn/go-shellwords v1.0.6 github.com/mcuadros/go-version v0.0.0-20180611085657-6d5863ca60fa + github.com/mongoose-os/go-serial v0.0.0-20211022230256-bb7bd0b47c67 github.com/sergi/go-diff v1.2.0 github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c github.com/smartystreets/goconvey v1.6.4 // indirect diff --git a/go.sum b/go.sum index d34be068..98ba8144 100644 --- a/go.sum +++ b/go.sum @@ -131,8 +131,6 @@ github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8n github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50= github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cesanta/go-serial v0.0.0-20170105152649-4dff7aff019e h1:C++Ag/pucyWyaAN0ZVi1TQoVPLDXP8XElP0GR4DPDRY= -github.com/cesanta/go-serial v0.0.0-20170105152649-4dff7aff019e/go.mod h1:8NcZR8jUd1YKVUMGAzeu2cVpWHQAxeb1oVLFBapFwmQ= github.com/cesanta/hid v0.0.0-20190304122332-79d86877855b h1:sis04aP3W+T6iw+rr1PtowTyzGk2C/uW4Yt5kxJGtoU= github.com/cesanta/hid v0.0.0-20190304122332-79d86877855b/go.mod h1:TyHSqYNeVEvfBfk5Sg9kTkH7sH+yZSpnbhk+KOlqyS0= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= @@ -602,6 +600,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mongoose-os/go-serial v0.0.0-20211022230256-bb7bd0b47c67 h1:jQ1TgzH8eS3e4F42kCE9NdCqRrbidJq+qTa5gVFM6E0= +github.com/mongoose-os/go-serial v0.0.0-20211022230256-bb7bd0b47c67/go.mod h1:HZ7dmippnLpPxYlKfmEyOhXr6eqwu/UtOcYICIE5SH0= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=