Skip to content

Commit 80ec9d3

Browse files
committed
don't allow sideload to complete until notecard dfu is completed
1 parent 93eb683 commit 80ec9d3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

notecard/dfu.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ func loadBin(filetype string, filename string, bin []byte, binaryMax int) (err e
268268
// {dfu-not-ready} shows up when the DFU is ready, but the Notecard hasn't synced yet.
269269
// The DFU should kick off after the next successful sync.
270270
if (note.ErrorContains(err, note.ErrDFUNotReady) ||
271-
note.ErrorContains(err, "firmware update is in progress") ||
272-
note.ErrorContains(err, note.ErrDFUInProgress)) && lenRemaining == 0 {
271+
note.ErrorContains(err, "firmware update is in progress") ||
272+
note.ErrorContains(err, note.ErrDFUInProgress)) && lenRemaining == 0 {
273273
err = nil
274274
break
275275
}
@@ -280,10 +280,22 @@ func loadBin(filetype string, filename string, bin []byte, binaryMax int) (err e
280280
}
281281

282282
}
283-
elapsedSecs := (time.Now().UTC().Unix() - beganSecs) + 1
284-
fmt.Printf("%d seconds (%.0f Bps)\n", elapsedSecs, float64(totalLen)/float64(elapsedSecs))
283+
284+
// Wait until the DFU has completed. This is particularly important for notecard
285+
// sideloads where we must restart the module.
286+
if filetype == notehub.HubFileTypeCardFirmware {
287+
for i := 0; i < 90; i++ {
288+
rsp, err = card.TransactionRequest(notecard.Request{Req: "dfu.status", Name: "card"})
289+
if err == nil && !rsp.Pending {
290+
break
291+
}
292+
time.Sleep(1000 * time.Millisecond)
293+
}
294+
}
285295

286296
// Done
297+
elapsedSecs := (time.Now().UTC().Unix() - beganSecs) + 1
298+
fmt.Printf("%d seconds (%.0f Bps)\n", elapsedSecs, float64(totalLen)/float64(elapsedSecs))
287299
return
288300

289301
}

0 commit comments

Comments
 (0)