0 Replies Latest reply on Mar 2, 2017 9:41 PM by erthc_2130261

    OTA2 bootloader appears to crash if WPRINT_LIB_* macros are called in an added component

      I wanted to see some debug output from the libraries/filesystems/ota2 component when the WICED 4.1 OTA2 bootloader called functions from that component. I removed WICED_DISABLE_STDIO which allowed debug messages to be printed in the OTA2 bootloader, but not in the OTA2 component, because the debug output was only set to print when the component was not being used by the bootloader. Since this component's makefile already had the required mini_printf component added, I removed the restriction. The console displayed nothing. It did not even display the debug messages from the bootloader. As far as I could tell the bootloader appeared to have completely crashed before it printed anything.

       

      In the component's source file, libraries/filesystems/ota2/wiced_ota2_image.c, I discovered that when expanded, the three OTA2_WPRINT_* called printf() instead of mini_printf(). I changed the definitions from using WPRINT_LIB_* macros to using mini_printf(). I also changed the restriction that barred debug messages when this component was added to the bootloader to a constraint that barred debug messages when WICED_DISABLE_STDIO was defined. Then when I removed the WICED_DISABLE_STDIO from the bootloader I got debug messages from both the bootloader and the component. When I added WICED_DISABLE_STDIO back, neither the bootloader nor the component displayed any output, but the program that was loaded by the bootloader did display output on the console.

       

      // Here is the code I changed:

       

      #if defined(BOOTLOADER)

      #define OTA2_WPRINT_ERROR(arg)

      #define OTA2_WPRINT_INFO(arg)

      #define OTA2_WPRINT_DEBUG(arg)

      #else

       

      #include "mini_printf.h"

      #define OTA2_WPRINT_ERROR(arg)  WPRINT_LIB_ERROR(arg)

      #define OTA2_WPRINT_INFO(arg)  WPRINT_LIB_INFO(arg)

      #define OTA2_WPRINT_DEBUG(arg)  WPRINT_LIB_DEBUG(arg)

       

      #endif

       

      // This is what I changed it into:

       

      #ifdef WICED_DISABLE_STDIO

      #define OTA2_WPRINT_ERROR(arg)

      #define OTA2_WPRINT_INFO(arg)

      #define OTA2_WPRINT_DEBUG(arg)

      #else

       

      #include "mini_printf.h"

      #define OTA2_WPRINT_ERROR(arg)  {mini_printf arg;}

      #define OTA2_WPRINT_INFO(arg)   {mini_printf arg;}

      #define OTA2_WPRINT_DEBUG(arg)  {mini_printf arg;}

       

      #endif

       

      Additional Notes:

       

      The "#ifdef WICED_DISABLE_STDIO" clause of the conditional probably doesn't really matter. When I built and ran code containing calls to mini_printf() and WICED_DISABLE_STDIO was defined, I got no output, but the code built and ran without a hitch. If all you had was #include "mini_printf.h"... #define OTA2_WPRINT_DEBUG(arg)  {mini_printf arg;}, the code should run fine without any #ifdef.

       

      I also made a couple of other changes that ultimately didn't really make any difference. 1) In ota2_bootloader.mk the mini_printf component isn't explicitly added. As far as I can tell, the bootloader inherits the mini_printf component from the ota2 component because calls to mini_printf() do work in the bootloader. I suspect if either the ota2 component was removed from the bootloader or the mini_printf component was removed from the ota2_component then calls to mini_printf() in the bootloader would cause the bootloader to fail to build. I felt it would be better if ota2_bootloader.mk explicitly added the mini_printf component, so I did that. 2) In wiced_ota2_image.c there were several direct calls to mini_printf() that did not use one of the macros. I changed those mini_printf() calls to use a macro instead.