This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Zephyr with MCUboot and Simple Management Protocol (SMP)

Dear community,

i'm working on an application for the nRF52832. I would like to use MCUboot as Bootloader and Zephyr for the main application. The current situation is that i'm using the west tool for buildung and flashing the software. Not sure if it's my fault but the west tool has issues with debugging (that's what im doing with Segger Studio for NRF now). Mainly im working with the examples from ncs (Zephyr + NRF) and with the contributions of the devzone community to figure how things are working - many thanks!

But i'm stuck now: 

  • When i'm uploading the application (currently it is the smp_svr app) and the bootloader the microcontroller can be reset by mcumgr and the 'echo' command works also fine. The upload does not work. Does the application needs to be signed?
  • When i'm uploading only the bootloader it's not possible to communicate with mcumgr. Do i need to setup the smp features for the MCUboot, too?

In both cases i'm using the serial line.

Many thanks in advance!

Kind regards,

Michael

Parents
  • Hello Carl,

    thanks for your reply. Do i need MCUBoot with mcumgr? What's the common way to use MCUBoot with Zephyr?

    I have built the smp_svr (zephyr\samples\subsys\mgmt\mcumgr\smp_svr) example within the ncs folder and after building there weren't no signed files in the <project_folder>/<build_folder>/zephyr/.

    # Enable mcumgr.
    CONFIG_MCUMGR=y
    
    # Some command handlers require a large stack.
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    
    # Ensure an MCUboot-compatible binary is generated.
    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_ROM_START_OFFSET=0xc000 <-- That's the only flag i add, because imgtool was complaining about the offset
    
    # Enable flash operations.
    CONFIG_FLASH=y
    
    # Required by the `taskstat` command.
    CONFIG_THREAD_MONITOR=y
    
    # Enable statistics and statistic names.
    CONFIG_STATS=y
    CONFIG_STATS_NAMES=y
    
    # Enable most core commands.
    CONFIG_MCUMGR_CMD_IMG_MGMT=y
    CONFIG_MCUMGR_CMD_OS_MGMT=y
    CONFIG_MCUMGR_CMD_STAT_MGMT=y
    
    # Enable logging
    CONFIG_LOG=y
    CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y

    The smp_svr software was built with the command  west build -b nrf52dk_nrf52832. The MCUboot was built with the same command without any changes in the prj.conf.

    Kind regards,

    Michael

Reply
  • Hello Carl,

    thanks for your reply. Do i need MCUBoot with mcumgr? What's the common way to use MCUBoot with Zephyr?

    I have built the smp_svr (zephyr\samples\subsys\mgmt\mcumgr\smp_svr) example within the ncs folder and after building there weren't no signed files in the <project_folder>/<build_folder>/zephyr/.

    # Enable mcumgr.
    CONFIG_MCUMGR=y
    
    # Some command handlers require a large stack.
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    
    # Ensure an MCUboot-compatible binary is generated.
    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_ROM_START_OFFSET=0xc000 <-- That's the only flag i add, because imgtool was complaining about the offset
    
    # Enable flash operations.
    CONFIG_FLASH=y
    
    # Required by the `taskstat` command.
    CONFIG_THREAD_MONITOR=y
    
    # Enable statistics and statistic names.
    CONFIG_STATS=y
    CONFIG_STATS_NAMES=y
    
    # Enable most core commands.
    CONFIG_MCUMGR_CMD_IMG_MGMT=y
    CONFIG_MCUMGR_CMD_OS_MGMT=y
    CONFIG_MCUMGR_CMD_STAT_MGMT=y
    
    # Enable logging
    CONFIG_LOG=y
    CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y

    The smp_svr software was built with the command  west build -b nrf52dk_nrf52832. The MCUboot was built with the same command without any changes in the prj.conf.

    Kind regards,

    Michael

Children
  • Hi again!

    You do not need MCUBoot with mcumgr. As explained in the Zephyr DFU documentation MCUBoot should be flashed initially, and then the application image can be upgraded using mcumgr. It's the DFU subsystem in the that interacts with MCUBoot, not mcumgr directly. 

    Are you using Zephyr standalone or the nRF Connect SDK? Below is some of the images that should be present in the zephyr folder after building with NCS:

    app_signed.hex
    app_test_update.hex
    app_to_sign.bin
    app_update.bin

    I'm not sure if Zephyr standalone does this signing process. If not you must sign the image as described in the SMP Server documentation. Make sure that you build with serial support as well: 
    west build -b nrf52dk_nrf52832 -p -- -DOVERLAY_CONFIG='overlay-serial.conf;'

    Best regards,
    Carl Richard

  • I'm working with the nRF Connect SDK. The path in my previous reply was relative. My fault... i'm building the software over command line like follows:

    smp_svr:

    west build -b nrf52dk_nrf52832 -s app --pristine -d build\app -- -DOVERLAY_CONFIG='overlay-serial.conf;overlay-fs.conf'
    mcuboot:
    west build -b nrf52dk_nrf52832 -s ..\ncs\bootloader\mcuboot\boot\zephyr\ --pristine -d build\bootloader
    The smp_svr project was copied to <project-name>/<app>
    Kind regards,
    Michael
  • Hi, Michael!

    I understand. With NCS the bootloader is built automatically and added in the build folder, so there should not be any need to build it separately. Could you have a look at the contents in your build/app folder? It should contain something like this:

    d-----        09.03.2021     14:19                app
    d-----        09.03.2021     14:19                CMakeFiles
    d-----        09.03.2021     14:19                Kconfig
    d-----        09.03.2021     14:19                mcuboot
    d-----        09.03.2021     14:19                modules
    d-----        09.03.2021     14:19                zephyr
    -a----        09.03.2021     14:19         103504 .ninja_deps
    -a----        09.03.2021     14:19          24897 .ninja_log
    -a----        09.03.2021     14:19         925615 build.ninja
    -a----        09.03.2021     14:19          21613 CMakeCache.txt
    -a----        09.03.2021     14:19           1839 cmake_install.cmake
    -a----        09.03.2021     10:37          17920 libapp.a
    -a----        09.03.2021     14:19           1221 partitions.yml
    -a----        09.03.2021     14:19           2136 pm.config
    -a----        09.03.2021     14:19            327 regions.yml
    -a----        09.03.2021     14:19           1877 zephyr_modules.txt
    -a----        09.03.2021     14:19             84 zephyr_settings.txt


    Best regards,
    Carl Richard

  • Hi Carl,

    many thanks for your help. After following some How-To's i have messed up my NRF Connect SDK folder - cleaning everything up was the solution. Your proposed solution works with NRF Connect SDK v1.4.0 and NRF Connect SDK v1.5.0. The smg_svr example works fine.

    The prj.conf is set up as necessary for mcumgr:

    # Enable mcumgr.
    CONFIG_MCUMGR=y
    
    # Some command handlers require a large stack.
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    
    # Ensure an MCUboot-compatible binary is generated.
    CONFIG_BOOTLOADER_MCUBOOT=y
    
    # Enable flash operations.
    CONFIG_FLASH=y
    
    # Required by the `taskstat` command.
    CONFIG_THREAD_MONITOR=y
    
    # Enable statistics and statistic names.
    CONFIG_STATS=y
    CONFIG_STATS_NAMES=y
    
    # Enable most core commands.
    CONFIG_MCUMGR_CMD_IMG_MGMT=y
    CONFIG_MCUMGR_CMD_OS_MGMT=y
    CONFIG_MCUMGR_CMD_STAT_MGMT=y
    
    # Enable logging
    CONFIG_LOG=y
    

    My build command is:

    west build -b nrf52dk_nrf52832 -s . --pristine -d build\app -- -DOVERLAY_CONFIG='overlay-serial.conf;overlay-fs.conf'

    My build output <project_folder>/<build_folder>/zephyr/ looks like follows:

    -a----        11.03.2021     08:06         633702 app_moved_test_update.hex
    -a----        11.03.2021     08:06         186842 app_signed.hex
    -a----        11.03.2021     08:06         191314 app_test_update.hex
    -a----        11.03.2021     08:06          65568 app_to_sign.bin
    -a----        11.03.2021     08:06          66416 app_update.bin
    -a----        11.03.2021     08:05           5258 cmake_install.cmake
    -a----        11.03.2021     08:06          67040 dfu_application.zip

    I'm getting an echo response with the following command:

    mcumgr.exe --conntype=serial --connstring='COM6,baud=115200' echo hello

    With the following list command i'm getting the flashed images:

    mcumgr.exe --conntype=serial --connstring='COM6,baud=115200' image list
    
    # Output
    
    Images:
     image=0 slot=0
        version: 0.0.0
        bootable: true
        flags: active confirmed
        hash: 22870947a1db8e9d0ead516a71868b01d04ad6d25823373d327ad6dc5099579c
     image=0 slot=1
        version: 0.0.0
        bootable: true
        flags:
        hash: ec5c943d376968638609abfa20737644e1e6f10ea8a2fc50fa83efa14ffc3c45
    Split status: N/A (0)

    The updating works with the following command:

     mcumgr.exe --conntype=serial --connstring='COM6,baud=115200' image upload .\build\app\zephyr\app_update.bin
     
     # Output
     
      mcumgr.exe --conntype=serial --connstring='COM6,baud=115200' image upload .\build\app\zephyr\app_update.bin
     22.20 KiB / 61.84 KiB [========================>-------------------------------------------]  35.90% 2.10 KiB/s 00m18s

    Kind regards,

    Michael

  • Great to hear! It's my pleasure to help!

    Please reach out if you face any other issues.

    Best regards,
    Carl Richard

Related