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

smp_srv example works but my project gives: E: Image in the secondary slot is not valid!

I'm writing an application for the nrf5340 with nrfConnect v1.6.1,

I've been able to do the FOTA upgrade through BLE with the example smp_srv located inside zephyr/samples/subsys/mgmt/mcumgr/smp_svr

These were the step I've followed:

  1. Copy the smp_srv folder to my workspace folder (~/Documents/zephyr_projects/smp_srv)
  2. west build -b nrf5340dk_nrf5340_cpuappns -p -- -DOVERLAY_CONFIG=overlay-bt.conf (build pristine for non-secure app)
  3. west flash (as far as I know, the mcuboot is compiled as a child image, using the default debug key)
  4. Change code (adding some logs to see the changes)
  5. execute again  west build -b nrf5340dk_nrf5340_cpuappns -- -DOVERLAY_CONFIG=overlay-bt.conf to generate a new app_update.bin file with the modifications
  6. Upload the app_update.bin to my android
  7. Open nrfConnect application on my android
  8. connect to the board
  9. start DFU selecting the new app_update.bin file
  10. Transfer completes, Validate
  11. I can verify the new logs are applied

Everything works fine in this sample project

Important to notice that I've tested the smp_srv project with the following configuration:

# 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
CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y

and the overlay-bt,conf I've stripped everyhing related to LITTLE_FS

# Allow for large Bluetooth data packets.
CONFIG_BT_L2CAP_TX_MTU=252
CONFIG_BT_BUF_ACL_RX_SIZE=256

# Enable the Bluetooth (unauthenticated) and shell mcumgr transports.
CONFIG_MCUMGR_SMP_BT=y
CONFIG_MCUMGR_SMP_BT_AUTHEN=n
CONFIG_MCUMGR_SMP_SHELL=y

# Enable the LittleFS file system.
# CONFIG_FILE_SYSTEM=y
# CONFIG_FILE_SYSTEM_LITTLEFS=y

# Add 256 bytes to accommodate upload command (lfs_stat overflows)
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304

# Enable file system commands
CONFIG_MCUMGR_CMD_FS_MGMT=y

Then in my project, which I've added the same configuration located on the smp_srv prj.conf and overlay-bt.conf

# Incresed stack due to settings API usage
# CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_SMP=y
CONFIG_BT_SIGNING=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DIS=y
CONFIG_BT_ATT_PREPARE_COUNT=5
CONFIG_BT_BAS=y
CONFIG_BT_PRIVACY=y
CONFIG_BT_DEVICE_NAME="MyProject"
CONFIG_BT_DEVICE_APPEARANCE=833
CONFIG_BT_DEVICE_NAME_DYNAMIC=n
# CONFIG_BT_DEVICE_NAME_MAX=65
CONFIG_BT_USER_DATA_LEN_UPDATE=y
CONFIG_BT_BONDABLE=y
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE=y
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
# CONFIG_FLASH_PAGE_LAYOUT=y
# CONFIG_FLASH_MAP=y
# CONFIG_NVS=y
# CONFIG_SETTINGS=y


CONFIG_SPI=y
CONFIG_SENSOR=y

CONFIG_LIS3DH=y
CONFIG_LIS3DH_ACCEL_RANGE_2G=y
CONFIG_LIS3DH_ODR_5=y
CONFIG_LIS3DH_TRIGGER_OWN_THREAD=y
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_LIS3DH_CLICK_THS=64
CONFIG_LIS3DH_TIME_LIMIT=50
CONFIG_LIS3DH_TIME_LATENCY=2
CONFIG_LIS3DH_TIME_WINDOW=100
CONFIG_PM=y


CONFIG_MAX30005=y
CONFIG_MAX30005_TRIGGER_OWN_THREAD=y

CONFIG_I2C=y
CONFIG_ADP5360=y
CONFIG_ADP5360_TRIGGER_OWN_THREAD=y

# Required to disable default behavior of deep sleep on timeout
CONFIG_PM_DEVICE=y


# Allow for large Bluetooth data packets.
CONFIG_BT_L2CAP_TX_MTU=508
CONFIG_BT_BUF_ACL_RX_SIZE=512

# Enable the Bluetooth (unauthenticated) and shell mcumgr transports.
CONFIG_MCUMGR_SMP_BT=y
CONFIG_MCUMGR_SMP_BT_AUTHEN=n
CONFIG_MCUMGR_SMP_SHELL=y

# Enable the LittleFS file system.
# CONFIG_FILE_SYSTEM=y
# CONFIG_FILE_SYSTEM_LITTLEFS=y

# Add 256 bytes to accommodate upload command (lfs_stat overflows)
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2560

# Enable file system commands
# CONFIG_MCUMGR_CMD_FS_MGMT=y

# Enable mcumgr.
CONFIG_MCUMGR=y


# 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
CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y
# CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="root-rsa-2048.pem"

I've also added the necesary code to be able to initialize the smp service:

Includes:

#ifdef CONFIG_MCUMGR_SMP_BT
#include <mgmt/mcumgr/smp_bt.h>
#endif
#ifdef CONFIG_MCUMGR_CMD_OS_MGMT
#include "os_mgmt/os_mgmt.h"
#endif
#ifdef CONFIG_MCUMGR_CMD_IMG_MGMT
#include "img_mgmt/img_mgmt.h"
#endif
#ifdef CONFIG_MCUMGR_CMD_STAT_MGMT
#include "stat_mgmt/stat_mgmt.h"
#endif
#ifdef CONFIG_MCUMGR_CMD_SHELL_MGMT
#include "shell_mgmt/shell_mgmt.h"
#endif
in the main function:
#ifdef CONFIG_MCUMGR_CMD_OS_MGMT
os_mgmt_register_group();
#endif
#ifdef CONFIG_MCUMGR_CMD_IMG_MGMT
img_mgmt_register_group();
#endif
#ifdef CONFIG_MCUMGR_CMD_STAT_MGMT
stat_mgmt_register_group();
#endif
#ifdef CONFIG_MCUMGR_CMD_SHELL_MGMT
shell_mgmt_register_group();
#endif
and after enabling ble and registering the callbacks:
#ifdef CONFIG_MCUMGR_SMP_BT
smp_bt_register();
#endif

Then I execute the following steps:

  1. west build -b nrf5340dk_nrf5340_cpuappns -p (build pristine for non-secure app)
  2. west flash (as far as I know, the mcuboot is compiled as a child image, using the default debug key)
  3. Change code (adding some logs to see the changes)
  4. execute again  west build -b nrf5340dk_nrf5340_cpuappns to generate a new app_update.bin file with the modifications
  5. Upload the app_update.bin to my android
  6. Open nrfConnect application on my android
  7. connect to the board
  8. start DFU selecting the new app_update.bin file
  9. Transfer completes.

Then I can see the logs where the mcuboot says that:

*** Booting Zephyr OS build v2.6.0-rc1-ncs1 ***
I: Starting bootloader
I: Primary image: magic=bad, swap_type=0x1, copy_done=0x2, image_ok=0x2
I: Secondary image: magic=good, swap_type=0x2, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Swap type: test
E: Image in the secondary slot is not valid!
I: Bootloader chainload address offset: 0xc000
*** Booting Zephyr OS build v2.6.0-rc1-ncs1 ***

          

and then it loads the old image

What can be wrong?

I've tried enabling and disabling configurations but nothing seems to work

Parents Reply Children
Related