Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions notecard/dfu.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,34 @@ import (
"github.com/golang/snappy"
)

// Maximum bytes to embed inline in a single dfu.put request when we bypass the
// card.binary path.
const dfuInlineChunkMax = 8192

// Side-loads a file to the DFU area of the notecard, to avoid download
func dfuSideload(filename string, verbose bool) (err error) {
func dfuSideload(filename string, noBin bool, verbose bool) (err error) {

// Do a card.binary transaction to see if the notecard is capable of
// doing binary sideloads, and if so, how large.
// Do a card.binary transaction to see if the Notecard is capable of
// doing binary sideloads, and if so, how large. The -nobin flag forces
// the slower inline dfu.put path that doesn't use card.binary at all.
binaryMax := 0
var rsp notecard.Request
rsp, err = card.TransactionRequest(notecard.Request{Req: "card.binary"})
if note.ErrorContains(err, note.ErrCardIo) {
return err
}
if !noBin {
rsp, err = card.TransactionRequest(notecard.Request{Req: "card.binary"})
if note.ErrorContains(err, note.ErrCardIo) {
return err
}

if err == nil {
if err == nil {

// Get the maximum size that the notecard can handle
binaryMax = int(rsp.Max)
// Get the maximum size that the notecard can handle
binaryMax = int(rsp.Max)

// Use shorter delays when sending to Notecard, for performance
notecard.RequestSegmentMaxLen = 1024
notecard.RequestSegmentDelayMs = 5
// Use shorter delays when sending to Notecard, for performance
notecard.RequestSegmentMaxLen = 1024
notecard.RequestSegmentDelayMs = 5

}
}

// Read the file up-front so we can handle this common failure
Expand Down Expand Up @@ -179,6 +186,8 @@ func loadBin(filetype notehub.UploadType, filename string, bin []byte, binaryMax
// notecard will tell us not to use compression.
if binaryMax > 0 {
chunkLen = binaryMax
} else if chunkLen > dfuInlineChunkMax {
chunkLen = dfuInlineChunkMax
}

// Occasionally because of comms being out-of-sync (because of killing
Expand Down
7 changes: 5 additions & 2 deletions notecard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func getFlagGroups() []lib.FlagGroup {
lib.GetFlagByName("setup-sku"),
lib.GetFlagByName("provision"),
lib.GetFlagByName("sideload"),
lib.GetFlagByName("nobin"),
},
},
{
Expand Down Expand Up @@ -239,6 +240,8 @@ func main() {
flag.BoolVar(&actionFast, "fast", false, "use low timeouts and big buffers when sending to Notecard knowing that {io} errors are to be expected")
var actionSideload string
flag.StringVar(&actionSideload, "sideload", "", "side-load a .bin or .bins into the Notecard's storage")
var actionNoBin bool
flag.BoolVar(&actionNoBin, "nobin", false, "when side-loading, force the inline dfu.put path and do not use card.binary")
var actionEcho int
flag.IntVar(&actionEcho, "echo", 0, "perform <N> iterations of a communications reliability test to the Notecard")
var actionRTC string
Expand Down Expand Up @@ -742,7 +745,7 @@ func main() {
}

if err == nil && actionSideload != "" && actionScan == "" {
err = dfuSideload(actionSideload, actionVerbose)
err = dfuSideload(actionSideload, actionNoBin, actionVerbose)
}

if err == nil && actionUpload != "" {
Expand Down Expand Up @@ -882,7 +885,7 @@ func main() {
}

if err == nil && actionScan != "" {
err = scan(actionVerbose, actionFactory, actionSetup, actionSetupSKU, actionProvision, actionFactory, actionSideload, actionScan)
err = scan(actionVerbose, actionFactory, actionSetup, actionSetupSKU, actionProvision, actionFactory, actionSideload, actionNoBin, actionScan)
}

if err == nil && actionCommtest {
Expand Down
4 changes: 2 additions & 2 deletions notecard/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ScannedSIM struct {
}

// Scan of a set of notecards, appending to JSON file. Press ^C when done.
func scan(debugEnabled bool, init bool, fnSetup string, fnSetupSKU string, carrierProvision string, factoryReset bool, sideload string, outfile string) (err error) {
func scan(debugEnabled bool, init bool, fnSetup string, fnSetupSKU string, carrierProvision string, factoryReset bool, sideload string, noBin bool, outfile string) (err error) {

// Only allow one of the two
if fnSetup != "" && fnSetupSKU != "" {
Expand Down Expand Up @@ -206,7 +206,7 @@ func scan(debugEnabled bool, init bool, fnSetup string, fnSetupSKU string, carri

// If a sideload, do it
if sideload != "" {
err = dfuSideload(sideload, debugEnabled)
err = dfuSideload(sideload, noBin, debugEnabled)
if err != nil {
break
}
Expand Down
Loading