[NF5340] MCUBoot never launch my app after moving mcuboot_secondary to external flash

Hello,

I’m using the Thingy91X board (nRF5340). For my application, I need to run BLE and Wi-Fi simultaneously, so I have to increase the application size. To do this, I moved the secondary and secondary_1 slots to the external flash (I simply applied Nordic’s thingy91x_nrf5340_pm_static_ext_flash.yml in /nrf/boards/nordic/thingy91x).

According to common.dts, I enabled the external flash in my overlay:

/{
	chosen {
		zephyr,console = &rtt0; 
		zephyr,shell-uart = &rtt0;
		zephyr,uart-mcumgr = &rtt0;
		zephyr,bt-mon-uart = &rtt0;
		zephyr,bt-c2h-uart = &rtt0;
        nordic,pm-ext-flash = &flash_ext; //here
	};
};

&spi3 {
    status = "okay";

    flash_ext: GD25LE255E@0 {
        status = "okay";              
        reg = <0>;                    
        compatible = "jedec,spi-nor"; 
    };
};

I added the following Kconfig options to my prj.conf:

CONFIG_GPIO=y
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_SFDP_DEVICETREE=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

CONFIG_FLASH=y
CONFIG_FLASH_MAP=y

CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y

Following this tutorial: https://academy.nordicsemi.com/courses/nrf-connect-sdk-intermediate/lessons/lesson-9-bootloaders-and-dfu-fota/topic/exercise-3-dfu-with-external-flash/

mcuboot.conf

# Step 1.2 - Enable SPI driver for MCUboot
CONFIG_GPIO=y
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_SFDP_DEVICETREE=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
# QSPI drivers are enabled by defualt for some chips.
# Disable it explicitly to be sure QSPI is disabled.
CONFIG_NORDIC_QSPI_NOR=n 

# required by SPI driver
CONFIG_MULTITHREADING=y

CONFIG_BOOT_MAX_IMG_SECTORS=512

mucboot.overlay

/ {
	chosen {
        nordic,pm-ext-flash = &flash_ext;
	};
};

&spi3 {
    status = "okay";
    pinctrl-0 = <&spi3_default>;
    pinctrl-1 = <&spi3_sleep>;
    pinctrl-names = "default", "sleep";


    flash_ext: GD25LE255E@0 {
        status = "okay";              
        reg = <0>;                    
        compatible = "jedec,spi-nor"; 
    };
};

Then, I created the sysbuild.conf and added the Kconfigs : 

SB_CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
SB_CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y

My pm_static.yml is : 

b0:
  address: 0x0
  size: 0x8000
  region: flash_primary
b0_container:
  address: 0x0
  size: 0x8000
  region: flash_primary
  span: [b0]
s0:
  address: 0x8000
  size: 0x14000
  span: [mcuboot, s0_pad]
  region: flash_primary
s0_pad:
  address: 0x8000
  size: 0x200
  share_size: [mcuboot_pad]
  region: flash_primary
s0_image:
  address: 0x8200
  size: 0x13e00
  span: [mcuboot]
  region: flash_primary
mcuboot:
  address: 0x8200
  size: 0x13e00
  region: flash_primary
s1:
  address: 0x1c000
  size: 0x14000
  span: [s1_pad, s1_image]
  region: flash_primary
s1_pad:
  address: 0x1c000
  size: 0x200
  region: flash_primary
  share_size: [mcuboot_pad]
s1_image:
  address: 0x1c200
  size: 0x13e00
  share_size: [mcuboot]
  region: flash_primary
mcuboot_primary:
  address: 0x30000
  size: 0xcc000
  span: [mcuboot_pad, app]
  region: flash_primary
mcuboot_pad:
  address: 0x30000
  size: 0x200
  region: flash_primary
mcuboot_primary_app:
  address: 0x30200
  size: 0xcbe00
  span: [app]
  region: flash_primary
app_image:
  address: 0x30200
  size: 0xcbe00
  span: [app]
  region: flash_primary
app:
  address: 0x30200
  size: 0xcbe00
  region: flash_primary
settings_storage:
  address: 0xfc000
  size: 0x4000
  region: flash_primary

external_flash:
  device: DT_CHOSEN(nordic_pm_ext_flash)
  address: 0x0
  size: 0x2000000
  span: [mcuboot_secondary]
  region: external_flash
mcuboot_secondary:
  device: DT_CHOSEN(nordic_pm_ext_flash)
  address: 0x0
  size: 0xcc000
  share_size: [mcuboot_primary]
  region: external_flash
mcuboot_secondary_1:
  address: 0xcc000
  size: 0x40000
  device: DT_CHOSEN(nordic_pm_ext_flash)
  region: external_flash
pcd_sram:
  address: 0x20000000
  size: 0x2000
  region: sram_primary
sram_retained_mem:
  region: sram_primary
  address: 0x2007FC00
  size: 0x400

My main app just blink a led (it works without changing partition).

#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/drivers/gpio.h>

#define LED0_NODE DT_ALIAS(led0)

static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

int main(void) {
  printk("BOOTING...\n");

  if (!gpio_is_ready_dt(&led)) {
    printk("1\n");
    return 0;        
  }

  int ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
  if (ret < 0)
  {
    printk("2\n");
    return 0;
  }

  while (1) {
    k_msleep(100);
    ret = gpio_pin_toggle_dt(&led);
    if( ret < 0)
    {
      printk("3\n");
      return 0;
    }
    printk("BOOTING...\n");
  }
}

I used J-Link GDB to check whether the code is the issue. When I load the .elf and set a breakpoint at main, the breakpoint is hit, but I see nothing on RTT and the LED does not toggle.

Do you have any ideas ?

  • Hello,

    I do not see any particular issue in your Partition Manager file. However, while reviewing the logs you shared from when you tried to build the Zephyr sample I mentioned, I noticed that the path indicates Silicon Labs EFR32MG12P. How did this SoC get selected during the build process?


    Kind Regards,

    Abhijith

  • Hello, 

    I’m not sure how that SoC was selected. I simply followed the link you sent: https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/samples/drivers/jesd216/README.html

    May I ask if someone is working on my issue? It has been 10 days, and there have been no updates to this thread?

  • Hello,

    I understand your frustration, but I need  to identify the real cause of the issue before I can investigate further.

    From the partition details you shared, it shows: mcuboot_secondary.region = external_flash with device: DT_CHOSEN(nordic_pm_ext_flash), which confirms that the secondary partition is located on the external flash. On my end, the alignment looks correct, so I believe this is not an issue caused by the Partition Manager.

    You can also check the memory report in VS Code to verify whether the pm_static file you defined is properly reflected and placed.

    Additionally, please check why RTT is not working ,the logs could provide useful information about what or where exactly the crash is occurring.

    Try using the following configurations inside sysbuild/mcuboot.conf and see if it prints the MCUboot logs. You can refer to the lesson that explains how to enable MCUboot logging for guidance.

    CONFIG_USE_SEGGER_RTT=y
    CONFIG_PRINTK=y
    CONFIG_LOG=y
    CONFIG_MCUBOOT_LOG_LEVEL_INF=y
    

    If you still can’t get the logs to print, please share a minimal sample that reproduces the issue so I can run it locally and test it with my setup.

    Kind regards,
    Abhijith

  • I activate the logs such as you mention and it does not work.

    Here the files you need to run it : 

    SDK version: 2.9.2

    Board: nrf5340

    Files:

    main.c 

    #include <zephyr/kernel.h>
    #include <zephyr/sys/printk.h>
    #include <zephyr/drivers/gpio.h>
    
    #define LED0_NODE DT_ALIAS(led0)
    
    static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
    
    int main(void) {
      printk("BOOTING...\n");
    
      if (!gpio_is_ready_dt(&led)) {
        printk("1\n");
        return 0;        
      }
    
      int ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
      if (ret < 0)
      {
        printk("2\n");
        return 0;
      }
      // starting_app_infos();  // si tu veux garder
    
      while (1) {
        k_msleep(100);
        ret = gpio_pin_toggle_dt(&led);
        if( ret < 0)
        {
          printk("3\n");
          return 0;
        }
        printk("BOOTING...\n");
      }
    }

    CMakeLists.txt 

    cmake_minimum_required(VERSION 3.20.0)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(external_flash_test)
    
    target_sources(app PRIVATE 
                    src/main.c)
    

    board overlay

    /*
     * Copyright (c) 2023 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
     */
    
    
    / {
    	dp0 {
    		compatible = "zephyr,swdp-gpio";
    		status = "okay";
    		clk-gpios = <&gpio0 25 GPIO_ACTIVE_HIGH>;
    		dio-gpios = <&gpio0 27 GPIO_ACTIVE_HIGH>;
    		reset-gpios = <&gpio1 7 GPIO_ACTIVE_HIGH>;
    		port-write-cycles = <12>;
    	};
    
    	zephyr,user {
    		reset-gpios = <&gpio1 7 GPIO_ACTIVE_HIGH>;
    	};
    
    	chosen {
    		zephyr,console = &rtt0;
    		zephyr,shell-uart = &rtt0;
    		zephyr,uart-mcumgr = &rtt0;
    		zephyr,bt-mon-uart = &rtt0;
    		zephyr,bt-c2h-uart = &rtt0;
            nordic,pm-ext-flash = &flash_ext;
    	};
    
    	ramdisk0 {
    		compatible = "zephyr,ram-disk";
    		disk-name = "RAM";
    		sector-size = <512>;
    		sector-count = <128>;
    	};
    };
    
    &spi3 {
        status = "okay";
    
        flash_ext: GD25LE255E@0 {
            status = "okay";              
            reg = <0>;                    
            compatible = "jedec,spi-nor"; 
        };
    };
    
    &uart0 {
    	status = "okay";
    };
    
    &uart1 {
    	current-speed = <115200>;
    	status = "okay";
    };
    
    
    &zephyr_udc0 {
    	cdc_acm_uart0: cdc_acm_uart0 {
    		compatible = "zephyr,cdc-acm-uart";
    	};
    
    	cdc_acm_uart1: cdc_acm_uart1 {
    		compatible = "zephyr,cdc-acm-uart";
    	};
    };
    

    pm static.yml

    b0:
      address: 0x0
      size: 0x8000
      region: flash_primary
    b0_container:
      address: 0x0
      size: 0x8000
      region: flash_primary
      span: [b0]
    s0:
      address: 0x8000
      size: 0x14000
      span: [mcuboot, s0_pad]
      region: flash_primary
    s0_pad:
      address: 0x8000
      size: 0x200
      share_size: [mcuboot_pad]
      region: flash_primary
    s0_image:
      address: 0x8200
      size: 0x13e00
      span: [mcuboot]
      region: flash_primary
    mcuboot:
      address: 0x8200
      size: 0x13e00
      region: flash_primary
    s1:
      address: 0x1c000
      size: 0x14000
      span: [s1_pad, s1_image]
      region: flash_primary
    s1_pad:
      address: 0x1c000
      size: 0x200
      region: flash_primary
      share_size: [mcuboot_pad]
    s1_image:
      address: 0x1c200
      size: 0x13e00
      share_size: [mcuboot]
      region: flash_primary
    mcuboot_primary:
      address: 0x30000
      size: 0xcc000
      span: [mcuboot_pad, app]
      region: flash_primary
    mcuboot_pad:
      address: 0x30000
      size: 0x200
      region: flash_primary
    mcuboot_primary_app:
      address: 0x30200
      size: 0xcbe00
      span: [app]
      region: flash_primary
    app_image:
      address: 0x30200
      size: 0xcbe00
      span: [app]
      region: flash_primary
    app:
      address: 0x30200
      size: 0xcbe00
      region: flash_primary
    settings_storage:
      address: 0xfc000
      size: 0x4000
      region: flash_primary
    
    external_flash:
      device: DT_CHOSEN(nordic_pm_ext_flash)
      address: 0x0
      size: 0x2000000
      span: [mcuboot_secondary]
      region: external_flash
    mcuboot_secondary:
      device: DT_CHOSEN(nordic_pm_ext_flash)
      address: 0x0
      size: 0xcc000
      share_size: [mcuboot_primary]
      region: external_flash
    mcuboot_secondary_1:
      address: 0xcc000
      size: 0x40000
      device: DT_CHOSEN(nordic_pm_ext_flash)
      region: external_flash
    pcd_sram:
      address: 0x20000000
      size: 0x2000
      region: sram_primary
    sram_retained_mem:
      region: sram_primary
      address: 0x2007FC00
      size: 0x400

    sysbuild/mcuboot.conf

    # Step 1.2 - Enable SPI driver for MCUboot
    CONFIG_GPIO=y
    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_SFDP_DEVICETREE=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    # QSPI drivers are enabled by defualt for some chips.
    # Disable it explicitly to be sure QSPI is disabled.
    CONFIG_NORDIC_QSPI_NOR=n 
    
    # required by SPI driver
    CONFIG_MULTITHREADING=y
    
    CONFIG_BOOT_MAX_IMG_SECTORS=512
    
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_RTT_CONSOLE=y
    CONFIG_PRINTK=y
    CONFIG_LOG=y
    CONFIG_MCUBOOT_LOG_LEVEL_INF=y

    mcuboot overlay 

    / {
    	chosen {
            nordic,pm-ext-flash = &flash_ext;
    	};
    };
    
    &spi3 {
        status = "okay";
        pinctrl-0 = <&spi3_default>;
        pinctrl-1 = <&spi3_sleep>;
        pinctrl-names = "default", "sleep";
    
    
        flash_ext: GD25LE255E@0 {
            status = "okay";              
            reg = <0>;                    
            compatible = "jedec,spi-nor"; 
        };
    };
    

    prj.conf (ble activate because my app use it and i let it on kconfig)

    # General config
    CONFIG_GPIO=y
    CONFIG_SPI=y
    CONFIG_SPI_NOR=y
    CONFIG_SPI_NOR_SFDP_DEVICETREE=y
    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    
    CONFIG_REBOOT=y
    CONFIG_SMF=y
    CONFIG_EVENTS=y
    CONFIG_HEAP_MEM_POOL_SIZE=63024
    CONFIG_MAIN_STACK_SIZE=8192
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
    CONFIG_WATCHDOG=y
    CONFIG_MCUBOOT_IMG_MANAGER=y
    CONFIG_IMG_MANAGER=y
    
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    
    CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
    CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE=y
    CONFIG_PRINTK=y
    CONFIG_GPIO=y
    CONFIG_IMG_ERASE_PROGRESSIVELY=y
    #security
    CONFIG_HW_STACK_PROTECTION=y
    CONFIG_STACK_CANARIES=n
    CONFIG_STACK_SENTINEL=y
    
    #Uart
    CONFIG_SERIAL=y
    CONFIG_UART_ASYNC_API=y
    
    #bluetooth
    CONFIG_BT=y
    CONFIG_BT_CENTRAL=y
    CONFIG_BT_OBSERVER=y
    CONFIG_BT_GATT_CLIENT=y
    CONFIG_BT_GATT_DM=y
    CONFIG_BT_RX_STACK_SIZE=2048
    
    
    # Subsystem Settings
    CONFIG_SETTINGS=y
    CONFIG_SETTINGS_RUNTIME=y
    CONFIG_SETTINGS_FCB=y 
    
    # Backend NVS
    CONFIG_NVS=y
    CONFIG_SETTINGS_NVS=y

    kconfig.sysbuild 

    #
    # Copyright (c) 2023 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    source "${ZEPHYR_BASE}/share/sysbuild/Kconfig"
    
    config NRF_DEFAULT_IPC_RADIO
    	default y
    
    config NETCORE_IPC_RADIO_BT_HCI_IPC
    	default y
    

    sysbuild.conf

    SB_CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
    SB_CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y

    Regards, 

  • Hello  ,

    Have you been able to reproduce the issue?

    Regards,

Related