Firmware checks, nearly ready to push firmware to device
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/go-playground/log/v7"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -18,8 +18,8 @@ func FwExists(path string) bool {
|
||||
return !errors.Is(err, os.ErrNotExist)
|
||||
}
|
||||
|
||||
func ChkHeader(fwfile string) bool {
|
||||
fmt.Println("checking ", fwfile)
|
||||
func ChkHeader(fwfile string) error {
|
||||
log.Info("checking ", fwfile)
|
||||
// SCS has two different file layouts, one for the "Dragons", the other for any older modem
|
||||
var offset uint32
|
||||
if path.Ext(fwfile) == ".dr7" {
|
||||
@@ -29,32 +29,30 @@ func ChkHeader(fwfile string) bool {
|
||||
}
|
||||
r, err := os.Open(fwfile)
|
||||
if err != nil {
|
||||
return false
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
var header [2]byte
|
||||
_, err = io.ReadFull(r, header[:])
|
||||
if err != nil {
|
||||
return false
|
||||
return err
|
||||
}
|
||||
|
||||
if offset == 0 {
|
||||
if header != [2]byte{0x50, 0x34} {
|
||||
fmt.Println("ERROR: wrong firmware header")
|
||||
//return false
|
||||
return errors.New("ERROR: wrong firmware header")
|
||||
}
|
||||
} else {
|
||||
if header != [2]byte{0x60, 0xea} {
|
||||
fmt.Println("ERROR: wrong firmware header")
|
||||
//return false
|
||||
return errors.New("ERROR: wrong firmware header")
|
||||
}
|
||||
}
|
||||
|
||||
r.Close()
|
||||
firmware, err := ioutil.ReadFile(fwfile)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR: ReadFile operation failed")
|
||||
return errors.New("ERROR: ReadFile operation failed")
|
||||
}
|
||||
|
||||
var size uint32
|
||||
@@ -68,10 +66,9 @@ func ChkHeader(fwfile string) bool {
|
||||
binary.LittleEndian.PutUint32(a, crc32.ChecksumIEEE(firmware[offset:offset+size]))
|
||||
//if bytes.Equal(a, firmware[4+size:8+size]) { // PTC-3
|
||||
if bytes.Equal(a, firmware[offset+size:offset+size+4]) {
|
||||
fmt.Println("CRC checksum ok!")
|
||||
log.Info("CRC checksum ok!")
|
||||
} else {
|
||||
fmt.Println("CRC checksum NOT ok!")
|
||||
return false
|
||||
return errors.New("CRC checksum NOT ok!")
|
||||
}
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
24
go.mod
24
go.mod
@@ -4,15 +4,23 @@ go 1.17
|
||||
|
||||
require (
|
||||
github.com/akamensky/argparse v1.3.1
|
||||
github.com/albenik/go-serial v1.2.0
|
||||
github.com/albenik/go-serial/v2 v2.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/creack/goselect v0.1.0 // indirect
|
||||
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 // indirect
|
||||
github.com/sigurn/crc8 v0.0.0-20160107002456-e55481d6f45c // indirect
|
||||
github.com/sigurn/utils v0.0.0-20190728110027-e1fefb11a144 // indirect
|
||||
go.uber.org/atomic v1.4.0 // indirect
|
||||
go.uber.org/multierr v1.1.0 // indirect
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 // indirect
|
||||
github.com/creack/goselect v0.1.2 // indirect
|
||||
github.com/go-playground/ansi/v3 v3.0.0 // indirect
|
||||
github.com/go-playground/errors/v5 v5.1.1 // indirect
|
||||
github.com/go-playground/log/v7 v7.0.2 // indirect
|
||||
github.com/go-playground/pkg/v4 v4.0.0 // indirect
|
||||
github.com/go-playground/pkg/v5 v5.3.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/schollz/progressbar/v3 v3.8.3 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.7.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
|
||||
)
|
||||
|
103
go.sum
103
go.sum
@@ -1,26 +1,95 @@
|
||||
github.com/RackSec/srslog v0.0.0-20180709174129-a4725f04ec91/go.mod h1:cDLGBht23g0XQdLjzn6xOGXDkLK182YfINAaZEQLCHQ=
|
||||
github.com/akamensky/argparse v1.3.1 h1:kP6+OyvR0fuBH6UhbE6yh/nskrDEIQgEA1SUXDPjx4g=
|
||||
github.com/akamensky/argparse v1.3.1/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
|
||||
github.com/albenik/go-serial v1.2.0 h1:VhEIWqP5tbWtsWoCjeBHHQEf6qeXpsJXvZBP9px5F84=
|
||||
github.com/albenik/go-serial v1.2.0/go.mod h1:9NHUOwCBJER+lAaitTWLJda/GnYoP4Vga7KU3vn1lmM=
|
||||
github.com/creack/goselect v0.1.0 h1:4QiXIhcpSQF50XGaBsFzesjwX/1qOY5bOveQPmN9CXY=
|
||||
github.com/creack/goselect v0.1.0/go.mod h1:gHrIcH/9UZDn2qgeTUeW5K9eZsVYCH6/60J/FHysWyE=
|
||||
github.com/albenik/go-serial/v2 v2.4.0 h1:2yIM9C0l0YznmMbHF8Yw+j0XY1ZDy5YciqhGdOik6r8=
|
||||
github.com/albenik/go-serial/v2 v2.4.0/go.mod h1:JUrQKdczCMB0FlXt2rlJJ8zbfFzmjTIAkLPyyVfr5ho=
|
||||
github.com/aws/aws-sdk-go v1.25.31/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
||||
github.com/aws/aws-sdk-go v1.32.11/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
|
||||
github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0=
|
||||
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-playground/ansi/v3 v3.0.0 h1:TXexAx1sXuL/N/cqV472ffRdkoiqPA3LeKMXCoz8t4Y=
|
||||
github.com/go-playground/ansi/v3 v3.0.0/go.mod h1:btm11Vjtjy20mZiJwufDvdVAVxjLuYFDu164b83ekBs=
|
||||
github.com/go-playground/assert v1.2.1/go.mod h1:Lgy+k19nOB/wQG/fVSQ7rra5qYugmytMQqvQ2dgjWn8=
|
||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/errors/v5 v5.0.1/go.mod h1:p7HVwyH3I0esuPnvChd2Uf4ceZwG2GcaDT/KpzCN18M=
|
||||
github.com/go-playground/errors/v5 v5.1.1 h1:H/igfatbYnCqa4Xednb1nnxljpPWnogA4TgsA4U891I=
|
||||
github.com/go-playground/errors/v5 v5.1.1/go.mod h1:xyrVVz3LrfHZQmZQ1ri/8rdiis2F96q15wGX89xWsL0=
|
||||
github.com/go-playground/form/v4 v4.0.0/go.mod h1:bodWfd97U9PVMZFcDsbVzSbQQTtaWrebnTwQtWjSW1M=
|
||||
github.com/go-playground/form/v4 v4.1.1/go.mod h1:q1a2BY+AQUUzhl6xA/6hBetay6dEIhMHjgvJiGo6K7U=
|
||||
github.com/go-playground/log/v7 v7.0.2 h1:jHdecwWiVlQsOr9CKnAy1yjlwMTXITwUB2Tb3jVUrfU=
|
||||
github.com/go-playground/log/v7 v7.0.2/go.mod h1:AWMsaRSXCVhwbCSvvchHqQfyREAODmWrX435KTjpuYU=
|
||||
github.com/go-playground/pkg/v4 v4.0.0 h1:0lTr9H8RyCwom4TcfNhMCNvlTlFuin7uUlXcZQuxrA4=
|
||||
github.com/go-playground/pkg/v4 v4.0.0/go.mod h1:TLowM3d3a/m04JlHK/zM6Ia8zf8+0C/9pTwhDEUqKO0=
|
||||
github.com/go-playground/pkg/v5 v5.0.0/go.mod h1:0380E0lsFB1POWFypOLL8tX2f0O1OBCBpSdVmEy4mg0=
|
||||
github.com/go-playground/pkg/v5 v5.3.0 h1:G+DOJRqMoQTpnSGEjc1rWat6pE4EKp7ejM3udkjCi78=
|
||||
github.com/go-playground/pkg/v5 v5.3.0/go.mod h1:HXedFsSf7dogjVi5wmbOK7P+doyvzvLYMNlyX+PfGZI=
|
||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
|
||||
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 h1:aQKxg3+2p+IFXXg97McgDGT5zcMrQoi0EICZs8Pgchs=
|
||||
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3/go.mod h1:9/etS5gpQq9BJsJMWg1wpLbfuSnkm8dPF6FdW2JXVhA=
|
||||
github.com/sigurn/crc8 v0.0.0-20160107002456-e55481d6f45c h1:hk0Jigjfq59yDMgd6bzi22Das5tyxU0CtOkh7a9io84=
|
||||
github.com/sigurn/crc8 v0.0.0-20160107002456-e55481d6f45c/go.mod h1:cyrWuItcOVIGX6fBZ/G00z4ykprWM7hH58fSavNkjRg=
|
||||
github.com/sigurn/utils v0.0.0-20190728110027-e1fefb11a144 h1:ccb8W1+mYuZvlpn/mJUMAbsFHTMCpcJBS78AsBQxNcY=
|
||||
github.com/sigurn/utils v0.0.0-20190728110027-e1fefb11a144/go.mod h1:VRI4lXkrUH5Cygl6mbG1BRUfMMoT2o8BkrtBDUAm+GU=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/schollz/progressbar/v3 v3.8.3 h1:FnLGl3ewlDUP+YdSwveXBaXs053Mem/du+wr7XSYKl8=
|
||||
github.com/schollz/progressbar/v3 v3.8.3/go.mod h1:pWnVCjSBZsT2X3nx9HfRdnCDrpbevliMeoEVhStwHko=
|
||||
github.com/segmentio/errors-go v1.0.0/go.mod h1:RDVEREUrpa4/jM8rt5KsQpu+JoXPi6i07vG7m4tX0MY=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
|
||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI=
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
|
||||
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M=
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190509141414-a5b02f93d862/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210223212115-eede4237b368/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
43
main.go
43
main.go
@@ -3,7 +3,10 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/akamensky/argparse"
|
||||
"github.com/go-playground/log/v7"
|
||||
"github.com/go-playground/log/v7/handlers/console"
|
||||
"go-scsupdate/firmware"
|
||||
"go-scsupdate/update"
|
||||
"go-scsupdate/usb"
|
||||
"os"
|
||||
)
|
||||
@@ -12,40 +15,52 @@ func main() {
|
||||
parser := argparse.NewParser("go-scsupdate", "Update Firmware of SCS PACTOR modems")
|
||||
serialDevice := parser.String("s", "serialDevice", &argparse.Options{Required: false, Help: "(optional) serial device the modem is attached to, e.g. /dev/ttyUSB0. If not set, go-scsupdate will search for SCS modems."})
|
||||
_ = parser.String("b", "baudrate", &argparse.Options{Required: false, Help: "(optional) sets the serial baudrate, e.g. 115200"})
|
||||
f := parser.String("f", "file", &argparse.Options{Required: false, Help: "(required) the file to flash, e.g. profi41r.pro"})
|
||||
f := parser.String("f", "file", &argparse.Options{Required: true, Help: "(required) the file to flash, e.g. profi41r.pro"})
|
||||
debug := parser.Flag("d", "debug", &argparse.Options{Required: false, Help: "(optional) enable debug logs"})
|
||||
err := parser.Parse(os.Args)
|
||||
cLog := console.New(true)
|
||||
if *debug {
|
||||
log.AddHandler(cLog, log.AllLevels...)
|
||||
log.Debug("DEBUG logging enabled")
|
||||
} else {
|
||||
log.AddHandler(cLog, log.InfoLevel, log.ErrorLevel, log.AlertLevel, log.WarnLevel, log.NoticeLevel, log.PanicLevel)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Print(parser.Usage(err))
|
||||
log.Fatal(parser.Usage(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println(*serialDevice)
|
||||
var ports []usb.Scsid
|
||||
if *serialDevice == "" {
|
||||
if ports, err = usb.FindSCS(); err == nil {
|
||||
fmt.Println(ports)
|
||||
if len(ports) == 0 {
|
||||
fmt.Println("Found no SCS modem.")
|
||||
//os.Exit(1)
|
||||
log.Fatal("Found no SCS modem.")
|
||||
}
|
||||
if len(ports) != 1 {
|
||||
fmt.Println("Found more than one SCS modem. You need to choose one with the -s flag.\nfound: ")
|
||||
msg := "Found more than one SCS modem. You need to choose one with the -s flag.\nfound: "
|
||||
for _, p := range ports {
|
||||
fmt.Printf("Port: %30s : Name: %s\n", p.Port, p.Name)
|
||||
msg += fmt.Sprintf("Port: %30s : Name: %s\n", p.Port, p.Name)
|
||||
}
|
||||
log.Fatal(msg)
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Error while seaching SCS modems: ", err)
|
||||
log.Fatal("Error while seaching SCS modems: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
if !firmware.FwExists(*f) {
|
||||
fmt.Printf("Error: firmware file %s does not exist.\n", *f)
|
||||
os.Exit(1)
|
||||
log.Panicf("Error: firmware file %s does not exist.\n", *f)
|
||||
}
|
||||
|
||||
if !firmware.ChkHeader(*f) {
|
||||
os.Exit(1)
|
||||
if firmware.ChkHeader(*f) != nil {
|
||||
log.Panic(err)
|
||||
|
||||
} else {
|
||||
fmt.Println("all ok")
|
||||
log.Debug("checks passed")
|
||||
}
|
||||
|
||||
err = update.Update("/dev/ttyUSB0", 829400, *f)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
155
update/update.go
Normal file
155
update/update.go
Normal file
@@ -0,0 +1,155 @@
|
||||
package update
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/albenik/go-serial/v2"
|
||||
"github.com/go-playground/log/v7"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const CHUNKSIZE = 256
|
||||
|
||||
type modem struct {
|
||||
port serial.Port
|
||||
}
|
||||
|
||||
func initmodem(serport string, baudrate int) (*modem, error) {
|
||||
p, err := serial.Open(serport,
|
||||
serial.WithBaudrate(baudrate),
|
||||
serial.WithDataBits(8),
|
||||
serial.WithParity(serial.NoParity),
|
||||
serial.WithStopBits(serial.OneStopBit),
|
||||
serial.WithReadTimeout(1000),
|
||||
serial.WithWriteTimeout(1000))
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: File %s could not be opened\n", serport)
|
||||
return nil, err
|
||||
}
|
||||
m := &modem{*p}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m *modem) write(out string, nolog ...bool) ([]byte, error) {
|
||||
if len(nolog) == 0 {
|
||||
log.Debug("Sending " + out)
|
||||
} else {
|
||||
log.Debugf("Sending %d byte(s)", len(out))
|
||||
}
|
||||
m.port.Write([]byte(out))
|
||||
buff := make([]byte, 1024)
|
||||
time.Sleep(100 * time.Millisecond) // give the PTC some time to answer
|
||||
n, err := m.port.Read(buff)
|
||||
// fmt.Printf("Read %d bytes\n", n)
|
||||
if err != nil {
|
||||
log.Errorf("ERROR: cannot read answer from command: %s\n", out)
|
||||
return []byte(""), err
|
||||
}
|
||||
// TODO: Handle EOF
|
||||
return buff[:n], nil
|
||||
|
||||
}
|
||||
|
||||
func (m *modem) getSerNum() (string, error) {
|
||||
answer, err := m.write("\rsys sern\r")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
re := regexp.MustCompile(`Serial number: \w{2,16}`)
|
||||
sn := strings.ReplaceAll(string(re.Find(answer)), "Serial number: ", "")
|
||||
log.Infof("Serial Number is: %s", sn)
|
||||
return sn, nil
|
||||
}
|
||||
|
||||
func (m *modem) setDateTime() error {
|
||||
ct := time.Now()
|
||||
answer, err := m.write("DATE " + ct.Format("020106\r"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.Contains(string(answer), "BAD ARGUMENT") {
|
||||
return errors.New("setting DATE returns a BAD ARGUMENT error!")
|
||||
}
|
||||
answer, err = m.write("TIME " + ct.Format("150405\r"))
|
||||
if strings.Contains(string(answer), "BAD ARGUMENT") {
|
||||
return errors.New("setting TIME returns a BAD ARGUMENT error!")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *modem) writeUpdate(fwfile string) error {
|
||||
_, err := m.write("UPDATE\r")
|
||||
if err != nil {
|
||||
_, _ = m.write("\033", true) // send ESC to cancel the update
|
||||
return err
|
||||
}
|
||||
answer, err := m.write("\006", true)
|
||||
if err != nil {
|
||||
_, _ = m.write("\033", true) // send ESC to cancel the update
|
||||
return err
|
||||
}
|
||||
// TODO: remove that once write process is established
|
||||
_, err = m.write("\033", true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("flash stamp: % X", binary.LittleEndian.Uint32(answer[2:6]))
|
||||
flashId := binary.LittleEndian.Uint16(answer[0:2])
|
||||
log.Infof("flash id: % X", flashId)
|
||||
if flashId != 0xa41f && flashId != 0x5b1f && flashId != 0xda1f {
|
||||
_, _ = m.write("\033", true) // send ESC to cancel the update
|
||||
return errors.New("wrong flash id")
|
||||
}
|
||||
r, err := os.Open(fwfile)
|
||||
if err != nil {
|
||||
_, _ = m.write("\033", true) // send ESC to cancel the update
|
||||
return err
|
||||
}
|
||||
fstat, _ := r.Stat()
|
||||
fsize := fstat.Size()
|
||||
r.Close()
|
||||
|
||||
_, err = ioutil.ReadFile(fwfile)
|
||||
if err != nil {
|
||||
_, _ = m.write("\033", true) // send ESC to cancel the update
|
||||
return err
|
||||
}
|
||||
// fmt.Println(fsize)
|
||||
chunks := uint16(fsize / 256)
|
||||
if fsize%256 != 0 {
|
||||
chunks++
|
||||
}
|
||||
|
||||
// a := make([]byte, 2)
|
||||
// binary.BigEndian.PutUint16(a, chunks)
|
||||
|
||||
bar := progressbar.Default(int64(chunks), "flashing chunk")
|
||||
for i := 0; i < int(chunks); i++ {
|
||||
bar.Add(1)
|
||||
time.Sleep(3 * time.Millisecond)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Update(serport string, baudrate int, fwfile string) error {
|
||||
m, err := initmodem(serport, baudrate)
|
||||
defer m.port.Close()
|
||||
if err != nil {
|
||||
return errors.New("FEHLER in Update")
|
||||
}
|
||||
_, _ = m.getSerNum()
|
||||
if m.setDateTime() != nil {
|
||||
return err
|
||||
}
|
||||
if m.writeUpdate(fwfile) != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
10
usb/usb.go
10
usb/usb.go
@@ -2,9 +2,8 @@ package usb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/albenik/go-serial/enumerator"
|
||||
"log"
|
||||
enumerator2 "github.com/albenik/go-serial/v2/enumerator"
|
||||
"github.com/go-playground/log/v7"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -41,9 +40,8 @@ var scsbaudrates map[string]int = map[string]int{
|
||||
func FindSCS() ([]Scsid, error) {
|
||||
|
||||
foundids := []Scsid{}
|
||||
ports, err := enumerator.GetDetailedPortsList()
|
||||
ports, err := enumerator2.GetDetailedPortsList()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return nil, err
|
||||
}
|
||||
if len(ports) == 0 {
|
||||
@@ -51,7 +49,7 @@ func FindSCS() ([]Scsid, error) {
|
||||
}
|
||||
|
||||
for _, port := range ports {
|
||||
fmt.Printf("Found Port: %s\n", port.Name)
|
||||
log.Debugf("Found Port: %s", port.Name)
|
||||
if port.IsUSB {
|
||||
// fmt.Printf(" USB ID %s:%s\n", Port.VID, Port.PID)
|
||||
// fmt.Printf(" USB serial %s\n", Port.SerialNumber)
|
||||
|
Reference in New Issue
Block a user