Generation of MCUboot and application addresses, offsets, and padding when pm_static.yml is not present (Peripheral LBS Sample).

I am using peipheral lbs sample and modifying it for my project use. By default it doesnot has pm_static.yml where addresses could have been defined. Once i build the modified application it results in partitions.yml file and pm.config file. These files have all the relevant placement data of mcuboot, primary and secondary partitions, padding etc. From where these files are getting the relevant data ?
I have checked the following files but couldnt get much info. 

  • C:/ncs/v2.7.0/nrf/cmake/partition_manager.cmake
  • files in C:/ncs/v2.7.0/nrf/subsys/partition_manager/
  • files in C:/ncs/v2.7.0/zephyr/boards/nordic/nrf52dk/
  • .dts file for nrf52dk , this one has some info but not all of it
1- From where these files partitions.yml file and pm.config are getting the relevant addresses, offsets and size of mcuboot and app?
2- I want to have and understanding of this process. The purpose is to know how to flash bootloader and app separately on relevant addresses.
3- Where can I find documentation or literature explaining how to define and use macros in pm_static.yml for configuring flash partitions?
4- Which CMake file in NCS is responsible for merging the bootloader and application into the final firmware image?
  • build/partitions.yml

    app:
      address0xc200
      end_address0x45000
      regionflash_primary
      size0x38e00
    mcuboot:
      address0x0
      end_address0xc000
      placement:
        before:
        - mcuboot_primary
      regionflash_primary
      size0xc000
    mcuboot_pad:
      address0xc000
      end_address0xc200
      placement:
        align:
          start0x1000
        before:
        - mcuboot_primary_app
      regionflash_primary
      size0x200
    mcuboot_primary:
      address0xc000
      end_address0x45000
      orig_span&id001
      - mcuboot_pad
      - app
      regionflash_primary
      sharers0x1
      size0x39000
      span*id001
    mcuboot_primary_app:
      address0xc200
      end_address0x45000
      orig_span&id002
      - app
      regionflash_primary
      size0x38e00
      span*id002
    mcuboot_secondary:
      address0x45000
      end_address0x7e000
      placement:
        after:
        - mcuboot_primary
        align:
          start0x1000
      regionflash_primary
      share_size:
      - mcuboot_primary
      size0x39000
    settings_storage:
      address0x7e000
      end_address0x80000
      placement:
        align:
          start0x1000
        before:
        - end
      regionflash_primary
      size0x2000
    sram_primary:
      address0x20000000
      end_address0x20010000
      regionsram_primary
      size0x10000
  • prj.conf

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    CONFIG_NCS_SAMPLES_DEFAULTS=y

    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="SG2"

    # Enable the LBS service
    #CONFIG_BT_LBS=y
    #CONFIG_BT_LBS_POLL_BUTTON=y
    CONFIG_DK_LIBRARY=y

    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

    CONFIG_PARTITION_MANAGER_ENABLED=y

    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y

    CONFIG_BT_BAS=y
    CONFIG_BT_NUS=y
  • Build Logs

    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base).
    -- Application: Directory/Project
    -- CMake version: 3.21.0
    -- Found Python3: C:/ncs/toolchains/ce3b5ff664/opt/bin/python.exe (found suitable version "3.9.13", minimum required is "3.8") found components: Interpreter
    -- Cache files will be written to: C:/ncs/v2.7.0/zephyr/.cache
    -- Zephyr version: 3.6.99 (C:/ncs/v2.7.0/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf52dk, qualifiers: nrf52832
    -- Found host-tools: zephyr 0.16.5 (C:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.5 (C:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk)
    -- Found Dtc: C:/ncs/toolchains/ce3b5ff664/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
    -- Found BOARD.dts: C:/ncs/v2.7.0/zephyr/boards/nordic/nrf52dk/nrf52dk_nrf52832.dts
    -- Generated zephyr.dts: Directory/Project/build_2/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: Directory/Project/build_2/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: Directory/Project/build_2/zephyr/dts.cmake
    Parsing Directory/Project/Kconfig
    Loaded configuration 'C:/ncs/v2.7.0/zephyr/boards/nordic/nrf52dk/nrf52dk_nrf52832_defconfig'
    Merged configuration 'Directory/Project/prj.conf'
    Configuration saved to 'Directory/Project/build_2/zephyr/.config'
    Kconfig header saved to 'Directory/Project/build_2/zephyr/include/generated/autoconf.h'
    -- Found GnuLd: c:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38")
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: C:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
    -- Found Python3: C:/ncs/toolchains/ce3b5ff664/opt/bin/python.exe (found version "3.9.13") found components: Interpreter

    === child image mcuboot - begin ===
    loading initial cache file Directory/Project/build_2/mcuboot/child_image_preload.cmake
    Loading Zephyr default modules (Zephyr base).
    -- Application: C:/ncs/v2.7.0/bootloader/mcuboot/boot/zephyr
    -- CMake version: 3.21.0
    -- Found Python3: C:/ncs/toolchains/ce3b5ff664/opt/bin/python.exe (found suitable version "3.9.13", minimum required is "3.8") found components: Interpreter
    -- Cache files will be written to: C:/ncs/v2.7.0/zephyr/.cache
    -- Zephyr version: 3.6.99 (C:/ncs/v2.7.0/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf52dk, qualifiers: nrf52832
    -- Found host-tools: zephyr 0.16.5 (C:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.5 (C:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk)
    -- Found Dtc: C:/ncs/toolchains/ce3b5ff664/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
    -- Found BOARD.dts: C:/ncs/v2.7.0/zephyr/boards/nordic/nrf52dk/nrf52dk_nrf52832.dts
    -- Found devicetree overlay: C:/ncs/v2.7.0/bootloader/mcuboot/boot/zephyr/app.overlay
    -- Generated zephyr.dts: Directory/Project/build_2/mcuboot/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: Directory/Project/build_2/mcuboot/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: Directory/Project/build_2/mcuboot/zephyr/dts.cmake
    Parsing C:/ncs/v2.7.0/bootloader/mcuboot/boot/zephyr/Kconfig
    Loaded configuration 'C:/ncs/v2.7.0/zephyr/boards/nordic/nrf52dk/nrf52dk_nrf52832_defconfig'
    Merged configuration 'C:/ncs/v2.7.0/bootloader/mcuboot/boot/zephyr/prj.conf'
    Merged configuration 'C:/ncs/v2.7.0/nrf/subsys/partition_manager/partition_manager_enabled.conf'
    Merged configuration 'Directory/Project/build_2/mcuboot/zephyr/misc/generated/extra_kconfig_options.conf'
    Configuration saved to 'Directory/Project/build_2/mcuboot/zephyr/.config'
    Kconfig header saved to 'Directory/Project/build_2/mcuboot/zephyr/include/generated/autoconf.h'
    -- Found GnuLd: c:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38")
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: C:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
    CMake Deprecation Warning at C:/ncs/v2.7.0/nrf/cmake/partition_manager.cmake:32 (message):

    ---------------------------------------------------------------------
    --- WARNING: Child and parent image functionality is deprecated ---
    --- and should be replaced with sysbuild. Child and parent image ---
    --- support remains only to allow existing customer applications ---
    --- to build and allow porting to sysbuild, it is no longer ---
    --- receiving updates or new features and it will not be possible ---
    --- to build using child/parent image at all in nRF Connect SDK ---
    --- version 2.9 onwards. ---
    ---------------------------------------------------------------------
    Call Stack (most recent call first):
    C:/ncs/v2.7.0/zephyr/cmake/modules/kernel.cmake:253 (include)
    C:/ncs/v2.7.0/zephyr/cmake/modules/zephyr_default.cmake:141 (include)
    C:/ncs/v2.7.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
    C:/ncs/v2.7.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
    CMakeLists.txt:12 (find_package)


    MCUBoot bootloader key file: C:/ncs/v2.7.0/bootloader/mcuboot/root-rsa-2048.pem
    -- Configuring done
    -- Generating done
    -- Build files have been written to: Directory/Project/build_2/mcuboot
    === child image mcuboot - end ===

    CMake Warning at C:/ncs/v2.7.0/nrf/modules/mcuboot/CMakeLists.txt:382 (message):

    ---------------------------------------------------------
    --- WARNING: Using default MCUBoot key, it should not ---
    --- be used for production. ---
    ---------------------------------------------------------

     

    CMake Warning at C:/ncs/v2.7.0/zephyr/CMakeLists.txt:2027 (message):
    __ASSERT() statements are globally ENABLED


    CMake Deprecation Warning at C:/ncs/v2.7.0/nrf/cmake/partition_manager.cmake:32 (message):

    ---------------------------------------------------------------------
    --- WARNING: Child and parent image functionality is deprecated ---
    --- and should be replaced with sysbuild. Child and parent image ---
    --- support remains only to allow existing customer applications ---
    --- to build and allow porting to sysbuild, it is no longer ---
    --- receiving updates or new features and it will not be possible ---
    --- to build using child/parent image at all in nRF Connect SDK ---
    --- version 2.9 onwards. ---
    ---------------------------------------------------------------------
    Call Stack (most recent call first):
    C:/ncs/v2.7.0/zephyr/cmake/modules/kernel.cmake:253 (include)
    C:/ncs/v2.7.0/zephyr/cmake/modules/zephyr_default.cmake:141 (include)
    C:/ncs/v2.7.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
    C:/ncs/v2.7.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
    CMakeLists.txt:8 (find_package)


    CMake Warning at C:/ncs/v2.7.0/nrf/cmake/partition_manager.cmake:102 (message):

    ---------------------------------------------------------------------
    --- WARNING: Using a bootloader without pm_static.yml. ---
    --- There are cases where a deployed product can consist of ---
    --- multiple images, and only a subset of these images can be ---
    --- upgraded through a firmware update mechanism. In such cases, ---
    --- the upgradable images must have partitions that are static ---
    --- and are matching the partition map used by the bootloader ---
    --- programmed onto the device. ---
    ---------------------------------------------------------------------

    Call Stack (most recent call first):
    C:/ncs/v2.7.0/zephyr/cmake/modules/kernel.cmake:253 (include)
    C:/ncs/v2.7.0/zephyr/cmake/modules/zephyr_default.cmake:141 (include)
    C:/ncs/v2.7.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
    C:/ncs/v2.7.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
    CMakeLists.txt:8 (find_package)


    -- Configuring done
    -- Generating done
    -- Build files have been written to: Directory/Project/build_2
    -- west build: building application
    [8/270] Generating include/generated/version.h
    -- Zephyr version: 3.6.99 (C:/ncs/v2.7.0/zephyr), build: v3.6.99-ncs2
    [6/271] Generating include/generated/version.h
    -- Zephyr version: 3.6.99 (C:/ncs/v2.7.0/zephyr), build: v3.6.99-ncs2
    [271/271] Linking C executable zephyr\zephyr.elf
    Memory region Used Size Region Size %age Used
    FLASH: 32848 B 48 KB 66.83%
    RAM: 23744 B 64 KB 36.23%
    IDT_LIST: 0 GB 32 KB 0.00%
    Generating files from Directory/Project/build_2/mcuboot/zephyr/zephyr.elf for board: nrf52dk
    [262/270] Linking C executable zephyr\zephyr.elf
    Memory region Used Size Region Size %age Used
    FLASH: 192984 B 232960 B 82.84%
    RAM: 50784 B 64 KB 77.49%
    IDT_LIST: 0 GB 32 KB 0.00%
    Generating files from Directory/Project/build_2/zephyr/zephyr.elf for board: nrf52dk
    [265/270] Generating ../../zephyr/app_update.bin
    image.py: sign the payload
    [266/270] Generating ../../zephyr/app_signed.hex
    image.py: sign the payload
    [268/270] Generating ../../zephyr/app_test_update.hex
    image.py: sign the payload
    [270/270] Generating zephyr/merged.hex
    * Terminal will be reused by tasks, press any key to close it.

  • Hello,

    From where these files partitions.yml file and pm.config are getting the relevant addresses, offsets and size of mcuboot and app?

    From Partition Manager, which processes .dts files, CMake scripts, and optionally pm_static.yml. Since you are working with peripheral_lbs sample pm_static.yml is not present and partition manager determines the layout dynamically. Check https://github.com/nrfconnect/sdk-nrf/blob/v2.7-branch/cmake/partition_manager.cmake and  https://github.com/nrfconnect/sdk-nrf/tree/v2.7-branch/subsys/partition_manager, see the device tree files which contains the flash memory definitions.

    I want to have and understanding of this process. The purpose is to know how to flash bootloader and app separately on relevant addresses.

    If you check the generated build/partition you could see that the bootloader (MCUBoot) and application have separate memory regions, you can flash them independently. MCUBoot starts at 0x00000 and occupies 0xC000, and the application starts at 0x0C200 and occupies 0x38E00.

    Where can I find documentation or literature explaining how to define and use macros in pm_static.yml for configuring flash partitions?

    See the section "Partition Manager" in the technical documentation. There, you can also find the section on configuring static partitions.

    Kind Regards,

    Abhijith

Related