Skip to content

Commit

Permalink
Add --no-verify
Browse files Browse the repository at this point in the history
  • Loading branch information
rojer committed Jun 12, 2022
1 parent 7b81e1f commit 26e6a2c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
3 changes: 3 additions & 0 deletions cli/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ var (
)
BuildImage = flag.String("build-image", "", "Override the Docker image used for build.")
BuildParalellism = flag.Int("build-parallelism", 0, "build parallelism. default is to use number of CPUs.")

// Flashing flags
NoVerify = flag.Bool("no-verify", false, "Do not verify flashed image")
)

func Platform() string {
Expand Down
2 changes: 2 additions & 0 deletions cli/flash.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
//go:build !noflash
// +build !noflash

package main
Expand Down Expand Up @@ -172,6 +173,7 @@ func flash(ctx context.Context, devConn dev.DevConn) error {
}

espFlashOpts.InvertedControlLines = *flags.InvertedControlLines
espFlashOpts.NoVerify = *flags.NoVerify

switch strings.ToLower(fw.Platform) {
case "cc3200":
Expand Down
1 change: 1 addition & 0 deletions cli/flash/esp/esp.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type FlashOpts struct {
ESP32EncryptionKeyFile string
ESP32FlashCryptConf uint32
KeepFS bool
NoVerify bool
}

type RegReader interface {
Expand Down
56 changes: 32 additions & 24 deletions cli/flash/esp/flasher/flash.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,33 +271,41 @@ func writeImages(ct esp.ChipType, cfr *cfResult, images []*image, opts *esp.Flas
common.Reportf("Wrote %d bytes in %.2f seconds (%.2f KBit/sec)", totalBytesWritten, seconds, bytesPerSecond*8/1024)
}

common.Reportf("Verifying...")
for _, im := range images {
common.Reportf(" %7d @ 0x%x", len(im.Data), im.Addr)
addr, done := im.Addr, 0
for done < len(im.Data) {
size := len(im.Data) - done
if size > 0x100000 {
size = 0x100000
}
data := im.Data[done : done+size]
digest, err := cfr.fc.Digest(addr, uint32(size), 0 /* blockSize */)
if err != nil {
return errors.Annotatef(err, "%s: failed to compute digest %d @ 0x%x", im.Name, size, addr)
}
if len(digest) != 1 || len(digest[0]) != 16 {
return errors.Errorf("unexpected digest packetresult %+v", digest)
}
digestHex := strings.ToLower(hex.EncodeToString(digest[0]))
expectedDigest := md5.Sum(data)
expectedDigestHex := strings.ToLower(hex.EncodeToString(expectedDigest[:]))
if digestHex != expectedDigestHex {
return errors.Errorf("%d @ 0x%x: digest mismatch: expected %s, got %s", size, addr, expectedDigestHex, digestHex)
if !opts.NoVerify {
common.Reportf("Verifying...")
numBytes := 0
start := time.Now()
for _, im := range images {
numBytes += len(im.Data)
common.Reportf(" %7d @ 0x%x", len(im.Data), im.Addr)
addr, done := im.Addr, 0
for done < len(im.Data) {
size := len(im.Data) - done
if size > 0x100000 {
size = 0x100000
}
data := im.Data[done : done+size]
digest, err := cfr.fc.Digest(addr, uint32(size), 0 /* blockSize */)
if err != nil {
return errors.Annotatef(err, "%s: failed to compute digest %d @ 0x%x", im.Name, size, addr)
}
if len(digest) != 1 || len(digest[0]) != 16 {
return errors.Errorf("unexpected digest packetresult %+v", digest)
}
digestHex := strings.ToLower(hex.EncodeToString(digest[0]))
expectedDigest := md5.Sum(data)
expectedDigestHex := strings.ToLower(hex.EncodeToString(expectedDigest[:]))
if digestHex != expectedDigestHex {
return errors.Errorf("%d @ 0x%x: digest mismatch: expected %s, got %s", size, addr, expectedDigestHex, digestHex)
}
addr += uint32(size)
done += size
}
addr += uint32(size)
done += size
}
elapsed := time.Since(start)
glog.Infof("Verified %d bytes in %s, %.2f Kbit/sec", numBytes, elapsed, float64(numBytes*8)/elapsed.Seconds()/1000)
}

if opts.BootFirmware {
common.Reportf("Booting firmware...")
if err = cfr.fc.BootFirmware(); err != nil {
Expand Down

0 comments on commit 26e6a2c

Please sign in to comment.