Need help on enabling MCUBoot on a custom board based on the NRF5340 (BL5340PA) using internal flash for ncs version 2.6.2

Hello, I' needing some help on setting up the MCUBoot for the BL5340PA using the ncs 2.6.2. Currently I have the below add on for the prj.conf for the application core:

CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y

The built successfully went through but the problem is that I can't see the BLE device anymore and I don't really know where to start to debug the problem as the image was built with mcuboot enable. 
Would be greatly appreciated if anyone can provide a step by step walkthrough the process of setting up the MCUBoot for the nrf5340 (BL5340PA) on the ncs 2.6.2 ! 
Parents
  • Hi,

    The course https://academy.nordicsemi.com/courses/nrf-connect-sdk-intermediate/lessons/lesson-8-bootloaders-and-dfu-fota/ support v2.6.2.
    I suggest that you take this course and see if that helps.

    Then let me know if you still have problems and I will help you figure it out.

    Regards,
    Sigurd Hellesvik

  • Hello thank you for the link! I was able to went through the tutorial however, I still have some problems setting up the pm_static.yml for the internal flash usage with FOTA using BLE. Any guidance or example code would be great! Below is my pm_static.yml

    app:
      address:     0x00c200
      end_address: 0x074000
      region: flash_primary
      size:        0x067e00
    
    mcuboot:
      address:     0x000000
      end_address: 0x00c000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size:        0x00c000
    
    mcuboot_pad:
      address:     0x00c000
      end_address: 0x00c200
      placement:
        align:
          start:   0x004000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size:        0x000200
    
    mcuboot_primary:
      address:     0x00c000
      end_address: 0x074000
      orig_span: &id001
      - mcuboot_pad
      - app
      region: flash_primary
      sharers: 0x1
      size:        0x068000
      span: *id001
    
    mcuboot_primary_app:
      address:     0x00c200
      end_address: 0x074000
      orig_span: &id002
      - app
      region: flash_primary
      size:        0x067e00
      span: *id002
    
    mcuboot_secondary:
      address:     0x074000
      end_address: 0x0dc000
      placement:
        after:
        - mcuboot_primary
        align:
          start:   0x004000
      region: flash_primary
      share_size:
      - mcuboot_primary
      size:        0x068000
    
    #NetCore partitions
    # NetCore primary partition in AppCore RAM. Needed for DFU
    mcuboot_primary_1:
      address: 0x20000
      end_address: 0x40000
      device: flash_ctrl
      region: ram_flash
      size: 0x20000
    
    
    # RAM allocation for NetCore primary partition. Used by MCUBoot. Needed for DFU
    ram_flash:
      address: 0x20000
      end_address: 0x40000  # 0x20000 + 0x20000
      region: ram_flash
      size: 0x20000
    
    # NetCore secondary partition in internal flash. Needed for DFU
    mcuboot_secondary_1:
      address:     0x0dc000
      end_address: 0x0fc000
      placement:
        after:
        - mcuboot_secondary
      region: flash_primary
      size:        0x020000
    
    nvs_storage:
      address:     0x0fc000
      end_address: 0x100000
      placement:
        after:
        - mcuboot_secondary_1
      region: flash_primary
      size:        0x004000
      
    otp:
      address: 0xff8100
      end_address: 0xff83fc
      region: otp
      size: 0x2fc
    
    pcd_sram:
      address: 0x2006f000
      end_address: 0x20071000
      placement:
        before:
        - networkCore_sram
        - end
      region: sram_primary
      size: 0x2000
      
    networkCore_sram:
      address: 0x20071000
      end_address: 0x20080000
      placement:
        before:
        - end
      region: sram_primary
      size: 0xF000
      
    shared_sram:
      address: 0x20000000
      end_address: 0x20001000
      placement:
        before:
        - sram_primary
      region: sram_primary
      size: 0x1000
    
    sram_primary:
      address: 0x20010000
      end_address: 0x2006f000
      region: sram_primary
      size: 0x6e000

    I'm keep getting bellow error
    pm_sysflash.h:48:37: error: 'PM_MCUBOOT_PRIMARY_1_ID' undeclared (first use in this function); did you mean 'PM_MCUBOOT_PRIMARY_ID'?
       48 | #define FLASH_AREA_IMAGE_1_SLOTS    PM_MCUBOOT_PRIMARY_1_ID, PM_MCUBOOT_SECONDARY_1_ID
          |                                     ^~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.2/bootloader/mcuboot/boot/zephyr/include/sysflash/pm_sysflash.h:55:29: note: in expansion of macro 'FLASH_AREA_IMAGE_1_SLOTS'
       55 |                             FLASH_AREA_IMAGE_1_SLOTS
          |                             ^~~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.2/bootloader/mcuboot/boot/zephyr/include/sysflash/pm_sysflash.h:67:9: note: in expansion of macro 'ALL_AVAILABLE_SLOTS'
       67 |         ALL_AVAILABLE_SLOTS
          |         ^~~~~~~~~~~~~~~~~~~

  • Generally, I do not recommend trying to craft your own pm_static.yml. We mere humans are bad at hex calculations and tend to get these wrong. I know I do.

    The partition manager will dynamically partition your memory for you, and this is the method I recommend for developing.

    In my opinion, static partitioning is for the two following use-cases:

    1. Static partition requirement for DFU. For this, you simply copy build/partitions.yml to pm_static.yml when done developing. This will freeze partitioning as is, and will not require that you write your own
    2. Adding a custom partition. For this, you can often define only the custom partition, and then the partition manager will partition around it

    Are you statically partitioning for any of the above reasons?
    Or do you have some other use-case for this?

Reply
  • Generally, I do not recommend trying to craft your own pm_static.yml. We mere humans are bad at hex calculations and tend to get these wrong. I know I do.

    The partition manager will dynamically partition your memory for you, and this is the method I recommend for developing.

    In my opinion, static partitioning is for the two following use-cases:

    1. Static partition requirement for DFU. For this, you simply copy build/partitions.yml to pm_static.yml when done developing. This will freeze partitioning as is, and will not require that you write your own
    2. Adding a custom partition. For this, you can often define only the custom partition, and then the partition manager will partition around it

    Are you statically partitioning for any of the above reasons?
    Or do you have some other use-case for this?

Children
  • I'm trying to configure the FOTA for my custom board based on the nrf5340. Majority of posts I found on the forum and the tutorials are in combination with an external flash specifically the mx25r64. However my custom board doesn't have an external flash, and I'm trying to utilize the internal flash for such scenario. It would be great if you provide some proper guidance on how to configure it. Currently, I have the below setup which work for my case of use but as you mentioned above it would not be a recommended way of doing it.

    I have the following pm_static.yml in the root directory

    app:
      address:     0x00c200
      end_address: 0x074000
      region: flash_primary
      size:        0x067e00
    
    mcuboot:
      address:     0x000000
      end_address: 0x00c000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size:        0x00c000
    
    mcuboot_pad:
      address:     0x00c000
      end_address: 0x00c200
      placement:
        align:
          start:   0x004000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size:        0x000200
    
    mcuboot_primary:
      address:     0x00c000
      end_address: 0x074000
      orig_span: &id001
      - mcuboot_pad
      - app
      region: flash_primary
      sharers: 0x1
      size:        0x068000
      span: *id001
    
    mcuboot_primary_app:
      address:     0x00c200
      end_address: 0x074000
      orig_span: &id002
      - app
      region: flash_primary
      size:        0x067e00
      span: *id002
    
    mcuboot_secondary:
      address:     0x074000
      end_address: 0x0dc000
      placement:
        after:
        - mcuboot_primary
        align:
          start:   0x004000
      region: flash_primary
      share_size:
      - mcuboot_primary
      size:        0x068000
    
    #NetCore partitions
    # NetCore primary partition in AppCore RAM. Needed for DFU
    mcuboot_primary_1:
      address: 0x0
      device: flash_ctrl
      end_address: 0x020000
      region: ram_flash
      size: 0x020000
    
    # RAM allocation for NetCore primary partition. Used by MCUBoot. Needed for DFU
    ram_flash:
      address: 0x20000
      end_address: 0x20000
      region: ram_flash
      size: 0x0
    
    # NetCore secondary partition in internal flash. Needed for DFU
    mcuboot_secondary_1:
      address:     0x0dc000
      end_address: 0x0fc000
      placement:
        after:
        - mcuboot_secondary
      region: flash_primary
      size:        0x020000
    
    nvs_storage:
      address:     0x0fc000
      end_address: 0x100000
      placement:
        after:
        - mcuboot_secondary_1
      region: flash_primary
      size:        0x004000
      
    otp:
      address: 0xff8100
      end_address: 0xff83fc
      region: otp
      size: 0x2fc
    
    pcd_sram:
      address: 0x2006f000
      end_address: 0x20071000
      placement:
        before:
        - networkCore_sram
        - end
      region: sram_primary
      size: 0x2000
      
    networkCore_sram:
      address: 0x20071000
      end_address: 0x20080000
      placement:
        before:
        - end
      region: sram_primary
      size: 0xF000
      
    shared_sram:
      address: 0x20000000
      end_address: 0x20001000
      placement:
        before:
        - sram_primary
      region: sram_primary
      size: 0x1000
    
    sram_primary:
      address: 0x20010000
      end_address: 0x2006f000
      region: sram_primary
      size: 0x6e000

    and the following pm_static.yml in the child_image directory

    app:
      address: 0x1008800
      end_address: 0x1020000
      orig_span: &id001
      - nodeNetworkCore
      region: flash_primary
      size: 0x17800
      span: *id001
    b0n:
      address: 0x1000000
      end_address: 0x1008580
      placement:
        after:
        - start
      region: flash_primary
      size: 0x8580
    b0n_container:
      address: 0x1000000
      end_address: 0x1008800
      orig_span: &id002
      - b0n
      - provision
      region: flash_primary
      size: 0x8800
      span: *id002
    nodeNetworkCore:
      address: 0x1008800
      end_address: 0x1020000
      region: flash_primary
      size: 0x17800
    provision:
      address: 0x1008580
      end_address: 0x1008800
      placement:
        after:
        - b0n
      region: flash_primary
      size: 0x280
    sram_primary:
      address: 0x21000000
      end_address: 0x21010000
      region: sram_primary
      size: 0x10000

    and the overlay for the mcuboot (mcuboot.overlay) --> this is a walk around recommended by a post in the forum. My custom board do not have the mx25r64 external flash. 

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

    It would be great if you can point/guide me in the right direction of setting up FOTA for the nrf5340 based MCU using internal flash. 

  • Here is a sample for simultaneous DFU for nRF5340 with Sysbuild and only internal flash.

    See patches for both sdk-nrf and sdk-mcuboot.

    The sample only has UART transport for now, but adding BLE transport should not impact it any, so that I will leave up to you.

    nrf5340_simul_dfu_internal_flash_sysbuild.zip

Related