This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

factory reset example

Hello,

I need somebody to explain this piece of code from the ota_update_os example, from the factoryResetTask: 

  //
  // Read the boot Info
  //
  if( 0 == sl_FsOpen((unsigned char *)IMG_BOOT_INFO, FS_MODE_OPEN_READ,
                     &ulToken, &lFileHandle) )
  {
      if( 0 > sl_FsRead(lFileHandle, 0, (unsigned char *)&sBootInfo,
                       sizeof(sBootInfo_t)) )
      {
        while(1)
        {

        }
      }
      sl_FsClose(lFileHandle, 0, 0, 0);
  }

Why is the while(1) there? The IMG_BOOT_INFO file is "/sys/mcubootinfo.bin. In case it is not readable I don't see stalling into the while(1) of any use. Or maybe the developer wanted to put some code inside the while(1) and forgot to do it? Also, if we are stalling there, why take care of closing the file? Or is there any condition in that project that may trigger a break from the while(1)?

Thanks and regards

  • Hi Leonardo,

    'IMG_BOOT_INFO' file isn't the application binary but the file used to keep track of the active image. This file is created by the secondary boot loader. If the application is not able to read the data of this file, it's considered an error case (corruption on serial flash) and we implemented it this way (infinite while loop) to capture and keep the context of the application.
    User can very well write a logic to get out of the error case as per the requirement.

    Regards,
    Ankur
  • Ok, then I'll log this in our software as a critical error condition instead of stopping. I may suggest to put a comment in that example to make it clear.

    I know from documentation that the boot info file is written automatically after the first power cycle. Is this right?
    If I can't find the info file can I do something to fix the problem? Can I try to create the info file and write something to recover the situation (e.g. report that the factory image is the one to boot)?
    Thanks
  • Hi Leonardo,

    We will capture this in comment in next release.

    Yes, the boot info file is written after the first power cycle. If you are using the proper mechanism to update the file (as used in flc.c file) then the file should not be corrupted. If it's getting corrupted the corruption may not be limited to this file only.
    If you want to recover this file by rewriting to default, you can use the logic used in 'application_bootloader'.

    Regards,
    Ankur
  • Ok, I'll look into that example eventually.

    Best