Recognizing out of tree device driver bindings for mcuboot child image.

I'm using NCS V2.5.1 to program an NRF52833DK hooked up to an external AT25XE41B spi-nor flash chip. I'll be using the external flash as the secondary mcuboot image parition.


Because this flash chip doesn't have an existing driver in the zephyr tree I've had to modify the "jedec,spi-nor" flash driver to suit my needs. I've successfully copied and modified the spi_flash sample to write and read from the external flash, using out of tree drivers in my project. Here's my folder structure:

├── CMakeLists.txt
├── Kconfig
├── drivers
│   ├── CMakeLists.txt
│   ├── Kconfig
│   └── flash
│       ├── CMakeLists.txt
│       ├── Kconfig
|       ├── renesas_at25x.h
│       └── renesas_at25x.c 
├── dts
│   └── bindings
│       └── renesas,at25x.yaml
├── src
│   └── <src code>
├── boards
│   └── <overlays and confs>
├── west.yml
└── zephyr
    └── module.yml

When I enable mcuboot as a bootloader, I'm unable to get the mcuboot child image to pick up my device binding (renesas_at25x.yaml), while the main image picks it up fine. I'm able to get the mcuboot fully working with the external flash if I simply move my binding (renesas_at25x.yaml) into the zephyr tree (zephyr/dts/bindings/mtd/renesas_at25x.yaml), and keep my driver source files within my project.

This isn't a clean way to handle the custom driver dependency. I'd really like my binding to be picked up without having to move it into the zephyr tree. I've tried changing the project folder structure in many ways to try and get this to work with no luck. How can I get the mcuboot child image to pick up my custom binding?

  • Hi,

    If you want MCUboot to also use the spi-nor flash device you've added you will have to add the device into mcuboot.overlay in a folder named child_image/mcuboot.overlay in your project as well as in a .overlay related to your application. See how it has been done here github.com/.../mcuboot_smp_uart_feat_external_flash

    Could you try that and see if this resolves the issue?

    Kind regards,
    Andreas

  • I've already applied an mucboot overlay (specifying the nordic,pm-ext-flash property to my custom binding) in my existing project through my CMakeLists, this works fine. Everything works as long as the dts binding is in the zephyr tree instead of my project folder.

    I've tried setting up my project as shown in that example by creating a folder called child_image and using this to set my mcuboot overlay and conf. The result is the same. The project doesn't recognize the custom driver binding (renesas_at25x.yaml) in my project folder, I have to move it into the zephyr tree for it to get picked up. If I do move it into the zephyr tree, everything works.

    For more information at the top of my devicetree_generated.h file for the parent image I can see the binding directory in my project folder getting picked up:

     * Directories with bindings:
     *   /home/user/Desktop/git_repos/misc_ncs_workspace/nrf/dts/bindings, /home/user/Desktop/git_repos/misc_ncs_workspace/spi_flash/dts/bindings, $ZEPHYR_BASE/dts/bindings
     *

    but in the mcuboot child image's devicetree_generated.h file the binding directory in my project folder isn't getting picked up.

     * Generated by gen_defines.py
     *
     * DTS input file:
     *   /home/user/Desktop/git_repos/misc_ncs_workspace/spi_flash/build/mcuboot/zephyr/zephyr.dts.pre
     *
     * Directories with bindings:
     *   /home/user/Desktop/git_repos/misc_ncs_workspace/nrf/dts/bindings, $ZEPHYR_BASE/dts/bindings
     *
     * Node dependency ordering (ordinal and path):
     *   0   /
     *   1   /aliases
     *   2   /chosen

  • Hi

    This isn't a clean way to handle the custom driver dependency. I'd really like my binding to be picked up without having to move it into the zephyr tree. I've tried changing the project folder structure in many ways to try and get this to work with no luck. How can I get the mcuboot child image to pick up my custom binding?

    Ah, my mistake. I was a bit quick when reading through the case yesterday. 

    So there are two ways to do this, the first is to add the driver in tree, as you've done through modifying the existing jedec,spi-nor driver to fit the renesas_at25x device your using (alternatively you could've created a new instance instead of modifying the existing one), or you can add your custom driver out of tree (which is what I now read that you're struggling with finding a way to do).

    From what I've found when looking around it looks like the process of an out-of-tree driver is not straight forward, but I have a sample a colleague of mine has created that might show how to do this:

    1. To your CMakeLists.txt add this before find_package(...):
      list(APPEND ZEPHYR_EXTRA_MODULES
        ${CMAKE_CURRENT_SOURCE_DIR}/drivers
      )


    2. Create file driver/zephyr/module.yml containing
      build:
        cmake: .
        kconfig: Kconfig


      This will point to the "ZEPHYR_EXTRA_MODULS" and append it to the zephyr build system

    Here's a zip from another sample that showcases how an out of tree driver could be implemented

    0474.testlcd_outoftree_driver.zip

    Let me know if this answers your question and resolves the issue

    Kind regards,
    Andreas

  • The method you describe for adding out of tree drivers is what I was already doing as it turns out. My folder structure I posted above was incomplete to be concise, I actually already had the drivers/zephyr/module.yml file and I was already adding the module in cmake. The issue is still the same: this works for the main image but not for the mucboot child image.

    My workaround for the time being is to just copy the binding into the zephyr tree in my CMakeLists file (this segment is before find_package(...):

    list(APPEND ZEPHYR_EXTRA_MODULES
    		${CMAKE_SOURCE_DIR}/drivers
    )
    
    ##now copy the custom flash driver binding into the zephyr tree to work with mcuboot
    configure_file(${CMAKE_SOURCE_DIR}/dts/bindings/renesas,at25x.yaml.in $ENV{ZEPHYR_BASE}/dts/bindings/mtd/renesas,at25x.yaml COPYONLY)
    message(STATUS "Copied flash binding to zephyr tree under: $ENV{ZEPHYR_BASE}/dts/bindings/mtd/renesas,at25x.yaml")

    This is workable for the time being but it would be nice if the build system could recognize this binding for the mucboot child image without having to modify the zephyr tree.

  • Hi,

    I've discussed this a bit with my colleagues and they share the same experiences that you do. The only way to add a child_image binding is either in tree or as you've done/I've described. But, we also have a new build system (sysbuild), which might resolve this issue https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/build/sysbuild/index.html 

    Kind regards,
    Andreas

Related