MCU boot loader in combination with CPP libraries does not work

Hi,

In order to make firmware updates over Bluetooth work, I need to enable the MCU boot loader. Is use CONFIG_BOOTLOADER_MCUBOOT=y in my prj.conf file to enable it. My code makes us of the standard CPP libraries and I enable them with CONFIG_LIB_CPLUSPLUS=y. The standard libraries work fine however when I enable the MCU boot loader I get the following error message:

fatal error: algorithm: No such file or directory
6 | #include <algorithm>
  |          ^~~~~~~~~~~

and

fatal error: cstdlib: No such file or directory
    2 | #include <cstdlib>
      |          ^~~~~~~~~

Do I miss some extra configurations or is there something else I am missing?

Thanks,
Stan

  • Hi There!

    I went a head and picked this up today and found a solution which immediately came to mind after I had to tackle a power-consumption issue. The power consumption was too high because the MCUboot bootloader enabled UART; something that draws around ~600uA.

    But, back to topic. One would expect linking to go wrong between a C++ application and C bootloader, but not compiling. Somehow, not having C++ enabled in MCUboot also affects the compiler during compilation of the application. As a result, the fix is using a custom configuration file for the bootloader, to be passed via an extra CMake argument.

    The configuration file (boot.conf) in the root directory of my application looks like this. Please note that I've just copied the default project configuration from ```ncs\v2.0.0\bootloader\mcuboot\boot\zephyr\prj.conf``` and added the three C++ related lines underneath.

    CONFIG_PM=n
    
    CONFIG_NEWLIB_LIBC=y
    CONFIG_LIB_CPLUSPLUS=y
    CONFIG_CPLUSPLUS=y
    
    CONFIG_MAIN_STACK_SIZE=10240
    CONFIG_MBEDTLS_CFG_FILE="mcuboot-mbedtls-cfg.h"
    
    CONFIG_BOOT_SWAP_SAVE_ENCTLV=n
    CONFIG_BOOT_ENCRYPT_RSA=n
    CONFIG_BOOT_ENCRYPT_EC256=n
    CONFIG_BOOT_ENCRYPT_X25519=n
    
    CONFIG_BOOT_UPGRADE_ONLY=n
    CONFIG_BOOT_BOOTSTRAP=n
    
    ### mbedTLS has its own heap
    # CONFIG_HEAP_MEM_POOL_SIZE is not set
    
    ### We never want Zephyr's copy of tinycrypt.  If tinycrypt is needed,
    ### MCUboot has its own copy in tree.
    # CONFIG_TINYCRYPT is not set
    # CONFIG_TINYCRYPT_ECC_DSA is not set
    # CONFIG_TINYCRYPT_SHA256 is not set
    
    CONFIG_FLASH=y
    CONFIG_FPROTECT=y
    
    ### Various Zephyr boards enable features that we don't want.
    # CONFIG_BT is not set
    # CONFIG_BT_CTLR is not set
    # CONFIG_I2C is not set
    
    CONFIG_LOG_MODE_MINIMAL=y # former CONFIG_MODE_MINIMAL
    ### Ensure Zephyr logging changes don't use more resources
    CONFIG_LOG_DEFAULT_LEVEL=0
    ### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y
    CONFIG_CBPRINTF_NANO=y
    CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT=0
    

    Above file is included like this with the Build-Configuration tool from Visual Studio Code.

    -Db0_CONF_FILE:STRING="boot.conf"

    Kind regards,

    Jochem (a colleague of Stan)

Related