diff --git a/notecard/dfu.go b/notecard/dfu.go index 312a9a8..0828af8 100644 --- a/notecard/dfu.go +++ b/notecard/dfu.go @@ -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 @@ -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 diff --git a/notecard/main.go b/notecard/main.go index 9d5331f..c9d003e 100644 --- a/notecard/main.go +++ b/notecard/main.go @@ -57,6 +57,7 @@ func getFlagGroups() []lib.FlagGroup { lib.GetFlagByName("setup-sku"), lib.GetFlagByName("provision"), lib.GetFlagByName("sideload"), + lib.GetFlagByName("nobin"), }, }, { @@ -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 iterations of a communications reliability test to the Notecard") var actionRTC string @@ -742,7 +745,7 @@ func main() { } if err == nil && actionSideload != "" && actionScan == "" { - err = dfuSideload(actionSideload, actionVerbose) + err = dfuSideload(actionSideload, actionNoBin, actionVerbose) } if err == nil && actionUpload != "" { @@ -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 { diff --git a/notecard/scan.go b/notecard/scan.go index c0a86a5..96760df 100644 --- a/notecard/scan.go +++ b/notecard/scan.go @@ -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 != "" { @@ -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 }