IFU problems when downloading file

Hey all,
I’m trying to do an IFU, basically using the example code from the site. I’m trying to pull the files from a web server. For reference, my app TCA file is 587KB. Here’s what I have:

 public void updateFw(string url, string fwUrl)
        {
           
            Debug.WriteLine("App " + url);
            Debug.WriteLine("FW " + fwUrl);

                var qspiController = StorageController.FromName(SC20260.StorageController.QuadSpi);
                var indicatorPin = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PB5);

                var appKey = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // your key, assumming they are all zero as example.

                var updater = new InFieldUpdate(qspiController)
                {
                    ActivityPin = indicatorPin
                };

                var dataChunk = new byte[1 * 1024]; // must be multiple of 1K
                var dataChunkFW = new byte[1 * 1024]; // must be multiple of 1K

//Application
                var req = HttpWebRequest.Create(url) as HttpWebRequest;
                    req.KeepAlive = true;
                    req.ReadWriteTimeout = 2000;
                    var res = req.GetResponse() as HttpWebResponse;

                // Buffer application
                var idxApp = 0;
                var appStream = res.GetResponseStream();

                while (idxApp < appStream.Length)
                {
                    var count = appStream.Read(dataChunk, 0, dataChunk.Length);
                    idxApp += updater.LoadApplicationChunk(dataChunk, 0, count);
                }

//Firmware
                var reqFw = HttpWebRequest.Create(fwUrl) as HttpWebRequest;
                reqFw.KeepAlive = true;
                reqFw.ReadWriteTimeout = 2000;

                var resFw = reqFw.GetResponse() as HttpWebResponse;
                var steamFW = resFw.GetResponseStream();
                // Buffer firmware
                var idxFirmware = 0;
                while (idxFirmware < steamFW.Length)
                {
                    var count = steamFW.Read(dataChunk, 0, dataChunk.Length);

                    idxFirmware += updater.LoadFirmwareChunk(dataChunk, 0, count);
                }


                //Load key
                updater.LoadApplicationKey(appKey);

                Debug.WriteLine("Verifying application.... ");
                Debug.WriteLine("Application version: " + updater.VerifyApplication());

                Debug.WriteLine("Verify firmware.... ");
                Debug.WriteLine("Firmware version: " + updater.VerifyFirmware());

                // Flashing

                updater.FlashAndReset();
        }

I have an IP address and confirmed network connection. This fails with:

App http://loledvirtual.com/conduit/conduitx4/App.tca
FW http://files.ghielectronics.com/downloads/TinyCLR/Firmwares/SITCore/SITCore-SC20-Firmware-v2.1.0.6500.ghi
Verifying application.... 
    #### Exception System.ArgumentException - 0xfd000000 (1) ####
    #### Message: 
    #### GHIElectronics.TinyCLR.Update.InFieldUpdate::NativeAuthenticateApplication [IP: 0000] ####
    #### GHIElectronics.TinyCLR.Update.InFieldUpdate::VerifyApplication [IP: 0016] ####
    #### Conduit.FirmwareUpdater::OnFirmwareUpdate [IP: 000d] ####
    #### Conduit.UDPManager::checkForData [IP: 00e4] ####
    #### Conduit.Program::Main [IP: 0310] ####
Exception thrown: 'System.ArgumentException' in GHIElectronics.TinyCLR.Update.dll
Exception was thrown: System.ArgumentException
The thread '<No Name>' (0x5) has exited with code 0 (0x0).

Not really sure what the proper way of handling this is, any advice appreciated.

var count = appStream.Read(dataChunk, 0, dataChunk.Length);

make sure count is always multiple of 1K.

Read from network stream not always 1K. You need to wait enough 1K before do

idxApp += updater.LoadApplicationChunk(dataChunk, 0, count);

This can also be related to the version number you entered in tinyclr config when making your tca file.

Make sure the version number is in the same format: x.x.x.x otherwise you’ll also get this exception.

1 Like

Is there any concern that the app file size won’t be multiple of 1024, or is the size padded to ensure it’s not a problem?

It’s my understanding that the file will always be in multiples of 1024.

1 Like