1 2 Previous Next 24 Replies Latest reply on May 27, 2015 7:02 PM by userc_2727

    OTA Upgrade from the Application

      Hi,

      I can build and run snip/ota.fr properly in SDK 3.1.2. But the example doesn't show how to initiate the OTA app from any project application. Our product requires the user  to initiate the ota upgrade from an Android app. Is there any API call to initiate the OTA application from the project application?  After the API call, if the device will reboot, how can I have the Bootloader be able to copy the OTA Application from external flash into MCU RAM ? Any example code and documents?

       

      Thanks

        • 1. Re: OTA Upgrade from the Application

          Hi,

          have a look at  Apps/snip/ota_fr/ota_fr.c. This file is just a small wrapper around the main API to start an OTA server ( WICED_ota_server_start ), calling this API from any application, will start an OTA server, try to receive the file, and after receiving it, set the boot loader to boot from the received file, restart the platform (and then the boot loader kicks in and copy the new received file). you can embed this API in any application you need and it will do the same. your application can use a signal from you phone (in any way like) to call this function and start the upgrade process.

           

          Hope this answers your question.

           

          Regards,

          Bassem

          • 2. Re: OTA Upgrade from the Application

            Hi,

             

            Our application is very cpu intense with 2 threads. Adding the ota_fr by calling wiced_ota_server_start() will create another thread, may use up all memories,  and dramatically delay our real time audio streaming to the smartphone. So We want the OTA as an independent app from FR(Factory Reset) app and want to have an API call(very minimum task) to just initiate the OTA upgrade process from the Application. After the API call, the device reboots, bootloader copies the OTA App into MCU RAM. How can we achieve this?

             

            In addition, are there any make target commands in SDK to do followings

            1. build and download the otr_fr App to external flash.

            2. build and download FR APP + FR DCT to external flash.

             

            Thanks

            • 3. Re: OTA Upgrade from the Application

              Hi,

              What you are suggesting is totally valid and supported by WICED. WICED supports what we call multiapp file system in external flash. Its a list of applications written in external flash and can be booted from at any time. Some of those applications are specific to certain operations, while others are generic for the user. The list of supported applications are:

              FR_APP: Factory reset application

              DCT_IMAGE: Factory reset DCT Image

              OTA_APP: OTA application

              WIFI_FIRMWARE: A WLAN Firmware image (not fully supported yet)

              FILESYSTEM_IMAGE: A read only file system

              APP0: application 0

              APP1: application 1

              APP2: application 2

               

              To put a certain application in its location in the multiapp file system (in external flash), all is required is the set the make variable for this application, for example (as in ota_fr.mk) to set the factory reset to the application we want we add in ota_fr.mk

              FR_APP    := $(OUTPUT_DIR)/binary/$(CLEANED_BUILD_STRING).stripped.elf

              DCT_IMAGE := $(OUTPUT_DIR)/DCT.stripped.elf

              So in your case, you need to create an app (very close to ota_fr, probably remove the LEG toggeling stuff), compile it and in your main application set your OTA_APP variable to point to it:

              OTA_APP := build/snip_ota_fr-BCM943362WCD4/binary/snip_ota_fr-BCM943362WCD4.stripped.elf

               

              your  make target should also include download and download_apps (to download the mutli apps to external flash)

               

              To reset the MCU and start the OTA application, you need two calls:

              - static inline wiced_result_t wiced_framework_set_boot( uint8_t app_id, char load_once );

              This will tell the boot loader to boot from the this application when restrted, app id, should be  DCT_OTA_APP_INDEX and load_once should be true

              - A call wiced_framework_reboot to reboot your MCU

               

              Those functions are in wiced_framework.h (with documentation), also the ota_server is used them (to reboot in to the application again), you can use it as a guide on how to use them.

               

              Hope this answers your question,

               

              Regards,

              Bassem

              • 4. Re: OTA Upgrade from the Application

                Hi,

                 

                Our main application has a DSP firmware that will be stored in the same external flash and will be loaded to the DSP after the main application is started. We want to upgrade  the DSP firmware using the ota-fr example. My understanding is the existing ota-fr can only upgrade the app and save it to internal flash. How can we use the ota-fr to upgrade the DSP firmware and save it to external flash like application 0/1/2?  I guess we have to modify the code in wiced_ota_server.c


                Thanks

                • 5. Re: OTA Upgrade from the Application

                  Hi,

                  Yes, for now ota_server is writing only to APP0. in wiced_ota_server.c, you will find

                  if (wiced_framework_app_open( DCT_APP0_INDEX, &app ) != WICED_SUCCESS)

                  {

                         return -1;

                  }

                  replace DCT_APP0_INDEX with whatever index you want (APP1, APP2 would be a typical case). do the same thing for

                  wiced_framework_set_boot ( DCT_APP0_INDEX, PLATFORM_DEFAULT_LOAD );

                   

                  we have also recently developed a tftp server and tftp snip applicatin that (based on name of received file) can update any of the files in the multi-app file system. it is not part of the release but if interested, I can pass it here.

                   

                  Regards,

                  Bassem

                  • 6. Re: OTA Upgrade from the Application
                    JoYi_1844281

                    Dear Bdawood,

                     

                    I am interesting the tftp server and tftp snip, Would you send a copy of the snip to me!

                     

                    Thanks in advance!

                     

                    Jone

                    • 7. Re: OTA Upgrade from the Application

                      Hi Bassem,

                       

                      I am using SDK 3.1.2. Could you please send me a copy of the tftp server and tftp snip application?

                       

                      Thanks

                      • 8. Re: OTA Upgrade from the Application

                        Hi Bassem,

                         

                        We want to upgrade two separate  images. One is WICED main host(STM MCU) application. The other is the DSP firmware. The DSP chip is connected to STM MCU through SPI bus. The DSP image will be loaded through SPI interface in the WICED main host application and run on the DSP chip. We want to store  the DSP image in the external flash that also stores FR_APP, DCT_IMAGE, OTA_APP, APP0, etc. Beside upgrading the host main application, we also want to upgrade the DSP image. I have following questions.

                         

                        1.  Can I use the ota_fr example to achieve the goal above? What changes I need to make?

                         

                         

                        2. I try to add  APP0  := $(OUTPUT_DIR)/binary/(CLEANED_BUILD_STRING).stripped.elf in ota_fr.mk file and  make target "snip.ota_fr_feng-ISM43362_M3G_L44 download download_apps run". I observe that it doesn't write the app0 image to the external flash.

                         

                         

                         

                         

                        Thanks in advance

                        • 9. Re: OTA Upgrade from the Application

                          Hi Feng,

                          currently the ota_fr app is using the ota_server. The ota_server is doing two things that you need to change:

                          1- by default it writes to APP0, you need to need to change this to write to any other APP, Like APP1 for example (if you still want to keep APP0 for WICED upgrade)

                          2- After receiving the full file, ota_server call set boot function to tell WICED to load the new APP0 in to internal flash, you probably don't wan to do this when your APP is the DSP image.

                           

                          Those 2 parts in are in libraries/deamons/ota_server/wiced_ota_server.c:

                          replace DCT_APP0_INDEX in wiced_framework_app_open with whatever app you need to write to

                          and comment out wiced_framework_set_boot function call.

                           

                          Also note, this change is rather a proof of concept, because then you need to way later to tell the ota_server to either write to APP0 or APP1, depending on which one you want to update. Right now this is not included in the ota_server (may be the tftp apps that I'll try to upload soon may help)

                           

                          finally, after writing an to serial flash, please not the the file size is aligned to sector size of the your flash (currently 4K), is if your DSP file size is 14K for example, the multi-app will see it as 16K, for our applications this is not big deal, because we put elf files so all data we need are within the file, if however your DSP image is a binary, you need a way to retrieve the actual size that you need to write to the DSP.

                           

                          Hope this answers your question.

                           

                          Regards,

                          Bassem

                          • 10. Re: OTA Upgrade from the Application

                            Hi Bassem,

                            We want to keep APP0 for WICED upgrade and use APP1 for DSP upgarde.

                            First step, I want to use WICED SDK 3.1.2 build to write the DSP image to external flash APP1. I  add  APP1  :=  silabs_image\fmhd_radio_4.0.10.bin in ota_fr.mk file below and  make target "snip.ota_fr_feng-ISM43362_M3G_L44 download download_apps run". I observe that it doesn't write the DSP image to the external flash.

                             

                            //ota_fr.mk

                            ....

                            #Set factory reset application to be this same application.

                            FR_APP     := $(OUTPUT_DIR)/binary/$(CLEANED_BUILD_STRING).stripped.elf

                            DCT_IMAGE  := $(OUTPUT_DIR)/DCT.stripped.elf

                            APP1      := silabs_image\fmhd_radio_4.0.10.bin

                             

                             

                            //console output

                            Downloading Bootloader ...

                            Building apps lookup table

                            No changes detected

                             

                             

                            Downloading DCT ...

                            No changes detected

                             

                            Downloading Application ...

                            No changes detected

                             

                            Downloading FR_APP (build/snip_ota_fr_feng-ISM43362_M3G_L44/binary/snip_ota_fr_feng-ISM43362_M3G_L44.stripped.elf) at sector 1...

                            Downloading DCT_IMAGE (build/snip_ota_fr_feng-ISM43362_M3G_L44/DCT.stripped.elf) at sector 122...

                            Downloading APP1 (silabs_image\fmhd_radio_4.0.10.bin) at sector 128...

                            tools/makefiles/wiced_apps.mk:125: recipe for target 'APP1_DOWNLOAD' failed

                            Makefile:185: recipe for target 'main_app' failed

                            make.exe[1]: *** [APP1_DOWNLOAD] Error 1

                            make: *** [main_app] Error 2

                             

                             

                            Thanks

                            • 11. Re: OTA Upgrade from the Application

                              Hi Bassem,

                               

                              I have fixed the APP1 loading issue. Now I can use  the WICED SDK 3.1.2 build to write the DSP image to external flash APP1.

                               

                              Thanks

                              • 12. Re: OTA Upgrade from the Application

                                Hi,

                                Sorry for the delay, please find the attached patch for tftp library and snip app. The application can be configured as a client or a sever (to put or get files). if using windows please give good attention to windows firewall as it tends to block tftp applications. Linux is easier in this point.

                                 

                                This patch is based on WICED version 3.3.0, but I don't expect any problems if applied to WICED 3.1.2

                                 

                                This is a preliminary version, feel free to point me to bugs so that we can work on next release.

                                 

                                Regards,

                                Bassem

                                • 13. Re: OTA Upgrade from the Application
                                  JoYi_1844281

                                  Hi Bassem,

                                   

                                  Got it.

                                  And put  into SDK 3.1.2 without any issue!

                                  I will verify and update status to you!

                                   

                                  Thanks

                                   

                                  Jone 

                                  • 14. Re: OTA Upgrade from the Application

                                    Hi Bassem,

                                     

                                    I hit below issue when the size of new firmware is different from origianl firmware.

                                     

                                    It seems the writing error start when reach the current size.

                                    I print the current_size and file_size (tftp->transfer_size)in snip_tftp_establish().

                                    printf( "current size %lu file_size=%u\n", current_size, (unsigned) file_size);

                                    Maybe the problem is why the file_size is 0 here.

                                    Any comments? Did I miss something?

                                     

                                    Below is my test step:

                                     

                                    $ tftp 192.168.10.1

                                    tftp> binary

                                    tftp> put app0.elf

                                    Sent 328520 bytes in 7.4 seconds

                                    tftp> q

                                     

                                    current size 331776 file_size=0

                                     

                                    new size 331776

                                    Writing size 512 from offset 0 [0x7f]

                                    Writing size 512 from offset 512 [0x0]

                                    Writing size 512 from offset 1024 [0x0]

                                     

                                    ....

                                     

                                    Writing size 512 from offset 330752 [0x72]

                                    Writing size 512 from offset 331264 [0x1]

                                    Writing size 512 from offset 331776 [0x61]

                                    Error Writing

                                    Writing size 512 from offset 332288 [0x6e]

                                    Error Writing

                                    Writing size 512 from offset 332800 [0x54]

                                    Error Writing

                                    Writing size 512 from offset 333312 [0x25]

                                     

                                    .......

                                     

                                    Error Writing

                                    Writing size 512 from offset 360960 [0xf4]

                                    Error Writing

                                    Writing size 512 from offset 361472 [0xf4]

                                    Error Writing

                                    Writing size 512 from offset 361984 [0x0]

                                    Error Writing

                                    Writing size 192 from offset 362496 [0x3]

                                    Error Writing

                                    File transfer complete.

                                    Restarting...

                                    1 2 Previous Next