Mapping a binary file to a flash partition

Hi there,

I have multiple flash partitions defined in pm_static.yml.

I want one specific partition to contain a binary data file so that when I flash the image with J-Link, the bootloader, the application firmware, and the binary file are flashed together.

The binary file doesn't occupy the entire flash partition. The rest of the partition content doesn't matter.

Thanks in advance!

- Laci

Parents
  • Hello,

    Sorry for the delayed response. It's summer vacation here in Norway, and we have a limited number of staff working, which is why it took me some time to get back to you.

    I am not 100% sure, as I haven't tried this before, but I think this can be achievable. Define the partition for the binary in the `pm_static.yml` file and keep your binary file in the root of your application. Edit your main `CMakeLists.txt` file to include the binary file in the custom partition. In the CMake configuration, you need to define the binary file to be included and then add the binary to the build system.

    Kind regards,

    Abhijith

  • Well this is an extremely vague response. Here are two approaches I have tried so far, without success:

    First relatively naive approach: use Zephyr's cmake linker tooling to create a custom linker section, insert the binary in there with assembly .incbin, and link it to the final image. No build errors, but also no effect. Application's CMakeLists.txt code that was used:

    set(CONFIG_BIN_PATH "${CMAKE_CURRENT_SOURCE_DIR}/config.bin")
    
    # create linker script section for user configuration from DT information
    dt_nodelabel(USER_CONFIG_PARTITION_PATH NODELABEL "user_config_partition")
    dt_reg_addr(USER_CONFIG_PARTITION_ADDRESS PATH ${USER_CONFIG_PARTITION_PATH})
    dt_reg_size(USER_CONFIG_PARTITION_SIZE PATH ${USER_CONFIG_PARTITION_PATH})
    
    zephyr_linker_memory(NAME USER_CONFIG
        FLAGS r
        START ${USER_CONFIG_PARTITION_ADDRESS}
        SIZE ${USER_CONFIG_PARTITION_SIZE}
    )
    zephyr_linker_section(NAME .userconfig KEEP GROUP USER_CONFIG)
    
    # the assembly file places the binaries in the correct memory regions
    set(CONFIGS_ASM_FILE "${CMAKE_BINARY_DIR}/configs_assembly.S")
    file(WRITE "${CONFIGS_ASM_FILE}" ".section .userconfig
    .incbin \"${CONFIG_BIN_PATH}\"
    ")
    set_source_files_properties(${CONFIGS_ASM_FILE} PROPERTIES GENERATED TRUE)
    
    # add it to the final elf image target
    target_sources(${logical_target_for_zephyr_elf} PRIVATE ${CONFIGS_ASM_FILE})

    Second approach: use nRF SDK partition manager tooling. This is the static configuration:

    app:
      address: 0x10200
      end_address: 0xfd000
      region: flash_primary
      size: 0xece00
    mcuboot:
      address: 0x0
      end_address: 0x10000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0x10000
    mcuboot_pad:
      address: 0x10000
      end_address: 0x10200
      placement:
        align:
          start: 0x1000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0x10000
      end_address: 0xed000
      orig_span: &id001
      - app
      - mcuboot_pad
      region: flash_primary
      size: 0xdd000
      span: *id001
    mcuboot_primary_app:
      address: 0x10200
      end_address: 0xed000
      orig_span: &id002
      - app
      region: flash_primary
      size: 0xdce00
      span: *id002
    hardware_config_partition:
      address: 0xec000
      end_address: 0xed000
      size: 0x1000
    user_config_partition:
      address: 0xed000
      end_address: 0xfd000
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: flash_primary
      size: 0x10000
    settings_storage:
      address: 0xfd000
      end_address: 0x100000
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: flash_primary
      size: 0x3000
    sram_primary:
      address: 0x20000000
      end_address: 0x20040000
      region: sram_primary
      size: 0x40000
    

    and this is the CMakeLists.txt addition I used, again build goes without error or warning, but no effect:

    set(CONFIG_BIN_PATH "${CMAKE_CURRENT_SOURCE_DIR}/config.bin")
    set(USER_CONFIG_HEX "${CMAKE_BINARY_DIR}/user_config.hex")
    
    add_custom_command(
        COMMAND ${CMAKE_OBJCOPY} -I binary -O ihex ${CONFIG_BIN_PATH} ${USER_CONFIG_HEX}
        OUTPUT ${USER_CONFIG_HEX}
        DEPENDS ${CONFIG_BIN_PATH}
        COMMENT "Converting user config to hex"
        VERBATIM
    )
    add_custom_target(user_config
        DEPENDS ${USER_CONFIG_HEX}
    )
    set_property(GLOBAL PROPERTY
      user_config_partition_PM_HEX_FILE ${USER_CONFIG_HEX}
    )
    set_property(GLOBAL PROPERTY
      user_config_partition_PM_TARGET user_config
    )

    Can we get some more concrete pointers on how to solve this?

    Thanks in advance

Reply
  • Well this is an extremely vague response. Here are two approaches I have tried so far, without success:

    First relatively naive approach: use Zephyr's cmake linker tooling to create a custom linker section, insert the binary in there with assembly .incbin, and link it to the final image. No build errors, but also no effect. Application's CMakeLists.txt code that was used:

    set(CONFIG_BIN_PATH "${CMAKE_CURRENT_SOURCE_DIR}/config.bin")
    
    # create linker script section for user configuration from DT information
    dt_nodelabel(USER_CONFIG_PARTITION_PATH NODELABEL "user_config_partition")
    dt_reg_addr(USER_CONFIG_PARTITION_ADDRESS PATH ${USER_CONFIG_PARTITION_PATH})
    dt_reg_size(USER_CONFIG_PARTITION_SIZE PATH ${USER_CONFIG_PARTITION_PATH})
    
    zephyr_linker_memory(NAME USER_CONFIG
        FLAGS r
        START ${USER_CONFIG_PARTITION_ADDRESS}
        SIZE ${USER_CONFIG_PARTITION_SIZE}
    )
    zephyr_linker_section(NAME .userconfig KEEP GROUP USER_CONFIG)
    
    # the assembly file places the binaries in the correct memory regions
    set(CONFIGS_ASM_FILE "${CMAKE_BINARY_DIR}/configs_assembly.S")
    file(WRITE "${CONFIGS_ASM_FILE}" ".section .userconfig
    .incbin \"${CONFIG_BIN_PATH}\"
    ")
    set_source_files_properties(${CONFIGS_ASM_FILE} PROPERTIES GENERATED TRUE)
    
    # add it to the final elf image target
    target_sources(${logical_target_for_zephyr_elf} PRIVATE ${CONFIGS_ASM_FILE})

    Second approach: use nRF SDK partition manager tooling. This is the static configuration:

    app:
      address: 0x10200
      end_address: 0xfd000
      region: flash_primary
      size: 0xece00
    mcuboot:
      address: 0x0
      end_address: 0x10000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0x10000
    mcuboot_pad:
      address: 0x10000
      end_address: 0x10200
      placement:
        align:
          start: 0x1000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0x10000
      end_address: 0xed000
      orig_span: &id001
      - app
      - mcuboot_pad
      region: flash_primary
      size: 0xdd000
      span: *id001
    mcuboot_primary_app:
      address: 0x10200
      end_address: 0xed000
      orig_span: &id002
      - app
      region: flash_primary
      size: 0xdce00
      span: *id002
    hardware_config_partition:
      address: 0xec000
      end_address: 0xed000
      size: 0x1000
    user_config_partition:
      address: 0xed000
      end_address: 0xfd000
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: flash_primary
      size: 0x10000
    settings_storage:
      address: 0xfd000
      end_address: 0x100000
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: flash_primary
      size: 0x3000
    sram_primary:
      address: 0x20000000
      end_address: 0x20040000
      region: sram_primary
      size: 0x40000
    

    and this is the CMakeLists.txt addition I used, again build goes without error or warning, but no effect:

    set(CONFIG_BIN_PATH "${CMAKE_CURRENT_SOURCE_DIR}/config.bin")
    set(USER_CONFIG_HEX "${CMAKE_BINARY_DIR}/user_config.hex")
    
    add_custom_command(
        COMMAND ${CMAKE_OBJCOPY} -I binary -O ihex ${CONFIG_BIN_PATH} ${USER_CONFIG_HEX}
        OUTPUT ${USER_CONFIG_HEX}
        DEPENDS ${CONFIG_BIN_PATH}
        COMMENT "Converting user config to hex"
        VERBATIM
    )
    add_custom_target(user_config
        DEPENDS ${USER_CONFIG_HEX}
    )
    set_property(GLOBAL PROPERTY
      user_config_partition_PM_HEX_FILE ${USER_CONFIG_HEX}
    )
    set_property(GLOBAL PROPERTY
      user_config_partition_PM_TARGET user_config
    )

    Can we get some more concrete pointers on how to solve this?

    Thanks in advance

Children
No Data
Related