This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nRF5340 MCUBoot single slot using either serial or ACM0

Hi fellas,

First of all sorry for the long post but I'm stuck for quite some time now and I need your help. I guess better provide more info than less.

I am working with a custom board which is very-very similar to the evaluation kit using the nRF5340.

The image I currently have is quite hefty around 500K.

So using the MCU boot loader with dual banks is not feasible. Also we would like to use the remaining flash for other actions.

I have been reading all around the net for a possible solution.

There must be something that I am missing, mostly concerning the conf file

SDK nRF Connect 1.9.1

My starting point is the smp sample.

I have tried it with simple smaller applications using both newtmgr and mcumgr and they work perfectly fine.

I am able to list, upload, confirm and finally erase unwanted slots.

All previously described actions have been done using ACM0 (usb-serial), using the cdc-overlay.

Default overlays:

proj.conf

# Enable mcumgr.
CONFIG_MCUMGR=y

# Some command handlers require a large stack.
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304
CONFIG_MAIN_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

# Support for taskstat command
CONFIG_OS_MGMT_TASKSTAT=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

cdc-overlay.conf

# Enable USB subsystem
CONFIG_USB_DEVICE_STACK=y
CONFIG_SERIAL=y
CONFIG_UART_LINE_CTRL=y
# USB backend is serial device
CONFIG_MCUMGR_SMP_UART=y

 I created an overlay (nrf5340dk_nrf5340_cpuapp.overlay)

/delete-node/ &boot_partition;
/delete-node/ &slot0_partition;

&flash0 {
	/*
	 * For more information, see:
	 * https://docs.zephyrproject.org/latest/guides/dts/legacy-macros.html#legacy-flash-partitions
	 */
	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x00000000 0x10000>;
		};
		slot0_partition: partition@10000 {
			label = "image-0";
			reg = <0x00010000 0xF0000>;
		};
	};
};

/ {
	chosen {
		zephyr,code-partition = &slot0_partition;
		zephyr,flash = &flash0;
	};
};

giving 65KB to the bootloader and the rest (1MB-65KB) for the application

I also declared

CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000
CONFIG_SINGLE_APPLICATION_SLOT=y

inside

 \ncs\v1.9.1\bootloader\mcuboot\boot\zephyr\prj.conf

I know that the last one might not be elegant or approved and maybe I should've used KConfig for that

While compiling I get the following:

In file included from C:\***\v1.9.1\zephyr\include\storage\flash_map.h:260,
                 from C:\***\v1.9.1\zephyr\subsys\mgmt\mcumgr\lib\cmd\img_mgmt\src\zephyr_img_mgmt.c:14:
C:/Users/dnin/ncs/v1.9.1/zephyr/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/zephyr_img_mgmt.c: In function 'zephyr_img_mgmt_flash_area_id':
C:\***\v1.9.1\nrf\include\flash_map_pm.h:30:22: error: 'PM_mcuboot_secondary_ID' undeclared (first use in this function); did you mean 'PM_mcuboot_primary_ID'?
   30 | #define PM_ID(label) PM_##label##_ID
      |                      ^~~
C:\***\v1.9.1\nrf\include\flash_map_pm.h:35:30: note: in expansion of macro 'PM_ID'
   35 | #define FLASH_AREA_ID(label) PM_ID(label)
      |                              ^~~~~
C:\***\v1.9.1\zephyr\subsys\mgmt\mcumgr\lib\cmd\img_mgmt\src\zephyr_img_mgmt.c:120:11: note: in expansion of macro 'FLASH_AREA_ID'
  120 |   fa_id = FLASH_AREA_ID(image_1);
      |           ^~~~~~~~~~~~~
C:\***\v1.9.1\nrf\include\flash_map_pm.h:30:22: note: each undeclared identifier is reported only once for each function it appears in
   30 | #define PM_ID(label) PM_##label##_ID
      |                      ^~~
C:\***\v1.9.1\nrf\include\flash_map_pm.h:35:30: note: in expansion of macro 'PM_ID'
   35 | #define FLASH_AREA_ID(label) PM_ID(label)
      |                              ^~~~~
C:\***\v1.9.1\zephyr\subsys\mgmt\mcumgr\lib\cmd\img_mgmt\src\zephyr_img_mgmt.c:120:11: note: in expansion of macro 'FLASH_AREA_ID'
  120 |   fa_id = FLASH_AREA_ID(image_1);
      |           ^~~~~~~~~~~~~
[74/226] Building C object zephyr/soc/arm/common/cortex_m/CMakeFiles/soc__arm__common__cortex_m.dir/arm_mpu_regions.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'c:\***\v1.9.1\toolchain\opt\bin\cmake.EXE' --build 'c:\Users\dnin\wrks\smp_svr_9\build'

From what I can understand it's looking for "image-1" which he is not finding.

When I remove

CONFIG_SINGLE_APPLICATION_SLOT=y

it works and compiles fine. Then again I don't have enough space to use the dual slots.

It all boils up to these questions:

  1. Am looking at this the wrong way?
  2. Do I need to provide a mapping of the memory (from what I've seen around probably yes)
  3. Are there any configurations options that I can add inside proj.conf to solve this issue

If you need any other information which I did not include please feel free to ask for them.

  • Just something I found out during my experimentations:

    CONFIG_MCUMGR_CMD_IMG_MGMT=y
    CONFIG_MCUMGR_CMD_OS_MGMT=y
    CONFIG_MCUMGR_CMD_STAT_MGMT=y

    require dual bank to function

  • Hi,

    CONFIG_MCUMGR_CMD_IMG_MGMT is the issue. It requires a mcuboot_secondary flash partition.

  • Hi Oivind,

    Thanks for the reply.

    I will check it out

    Do you have any other tips to make this work?

    Do I need to mess around with:

    \ncs\v1.9.1\bootloader\mcuboot\boot\zephyr\prj.conf

    One more thing:

    Do I need to put the board in bootloader mode?
    I can see that the default button for the 5340DK is GPIO_0 -- port 23 || Button 1

    I have had problems trying to communicate with the board using newtmgr. It just hangs

    Thanks,

    Dorian

  • Is there a sample or some guidelines to make a hello word application with a single slot mcuboot?

  • I have some news for anyone interested


    So far I have achieved the following:

    1. Enabled and compile with Single slot

    2. Enable serial MCUBoot functionality

    3. Switch the dev board into bootloader mode

    4. Transfer and write and update.bin

    Settings for all the above

    C:\Users\xxxx\ncs\v1.9.1\bootloader\mcuboot\boot\zephyr

    CONFIG_PM=n
    
    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=y
    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
    
    
    #########################################################################
    # Declare for single slot and partition size for MCUBoot
    CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000
    CONFIG_SINGLE_APPLICATION_SLOT=y
    
    # Maybe needed TBD
    #CONFIG_MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD=y
    #CONFIG_BOOT_ERASE_PROGRESSIVELY=y
    
    #Enable MCUBoot serial functionality
    CONFIG_MCUBOOT_SERIAL=y
    
    #Pin detection for bootloader for different boards
    #Use first decalration for a nrf5340 devkit
    #pins aer the default ones already decalred in KConfig
    CONFIG_BOOT_SERIAL_DETECT_PORT="GPIO_0"
    CONFIG_BOOT_SERIAL_DETECT_PIN=23
    #CONFIG_BOOT_SERIAL_DETECT_PORT="GPIO_1"
    #CONFIG_BOOT_SERIAL_DETECT_PIN=7
    #CONFIG_BOOT_SERIAL_DETECT_PORT="GPIO_0"
    #CONFIG_BOOT_SERIAL_DETECT_PIN=5
    
    # Check which high value is HIGH --> usually 0 is high
    #CONFIG_BOOT_SERIAL_DETECT_PIN_VAL=1
    CONFIG_BOOT_SERIAL_DETECT_PIN_VAL=0
    
    # Check if LED is on
    CONFIG_MCUBOOT_INDICATION_LED=y
    
    CONFIG_BOOT_SERIAL_UART=y

    --------------------------------------------------------------

    # Settings inside your project --> proj.conf
    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_SPEED_OPTIMIZATIONS=y
    
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304
    CONFIG_MAIN_STACK_SIZE=2048
    CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE=y
    
    # Enable USB subsystem
    CONFIG_USB_DEVICE_STACK=y
    CONFIG_BOOT_DELAY=1000
    
    CONFIG_UART_CONSOLE=y

    --------------------------------------------------------------

    C:\Users\xxxx\ncs\v1.9.1\zephyr\boards\arm\nrf5340dk_nrf5340\nrf5340dk_nrf5340_cpuapp_defconfig

    # SPDX-License-Identifier: Apache-2.0
    
    CONFIG_SOC_SERIES_NRF53X=y
    CONFIG_SOC_NRF5340_CPUAPP_QKAA=y
    CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP=y
    
    # Enable MPU
    CONFIG_ARM_MPU=y
    
    # Enable hardware stack protection
    CONFIG_HW_STACK_PROTECTION=y
    
    # Enable TrustZone-M
    CONFIG_ARM_TRUSTZONE_M=y
    
    # enable GPIO
    CONFIG_GPIO=y
    
    # Enable uart driver
    CONFIG_SERIAL=y
    
    # Chanegs needed here
    # enable console
    CONFIG_CONSOLE=y
    CONFIG_UART_CONSOLE=n

    Solution is pretty hacky but it works for now.

    Will update when I find a more elegant solution

Related