MCUBoot: adding custom serial flash driver as secondary partition

We use spi flash with custom driver and goal is to set it to act as secondary partition for MCUBoot.

The question is how to adapt driver to be accepted by MCUBoot, maybe there is an example on how driver should look like?

As far as I understand Nordic supports mx25r64, what files have to be produced and where to place them to enable custom driver to be accepted by MCUBoot?

Parents Reply
  • I checked build/mcuboot/zephyr/zephyr.dts, at25x appears in spi2 node. Also device_get_binding is called with correct label.

    However init function is not called. In driver file the following macro is added at the end of file:

    DEVICE_DT_INST_DEFINE(0, &spi_flash_init, NULL,
             &spi_flash_data_0, &spi_flash_config_0,
             POST_KERNEL, 80,
             &spi_flash_api);
    And spi_flash_init is not called. What I am still missing?
Children
  • mesh777 said:
    However init function is not called. In driver file the following macro is added at the end of file:

    If your custom init function is not called, maybe it is because the custom driver file is not seen by the build system and added to the executable? Have you modified the CMakeLists.txt to include the source file? Like done for spi_nor.c for example here: https://github.com/nrfconnect/sdk-zephyr/blob/v2.7.0-ncs1/drivers/flash/CMakeLists.txt#L6 (try adding your driver in-tree first, just to make sure it works). You can check that the source file is included by looking in /<sample>/build/mcuboot/zephyr/drivers/flash/CMakeFiles/drivers__flash.dir I think (or just open build folder in vscode, click ctrl+P and search for the source (.c) file).

    Again, I do think the spi_nor.c driver might support the at25x, at least it's worth checking out.

    mesh777 said:
    And spi_flash_init is not called. What I am still missing?

    Where did you find this function? I search through the whole NCS v1.8.0 (based on earlier logs, it seems like you're using this version).

  • This is my own static function which resides in the driver.

    I need to make it out-of-tree anyway, could you please check how to proceed with that.

    Thank you again.

  • mesh777 said:
    I need to make it out-of-tree anyway, could you please check how to proceed with that.

    Yes, of course I can look into that. I'll do it tomorrow.

    However, I think it is smart to try to resolve one issue at the time. So I would recommend this approach:

    1. Add your driver in-tree and make sure it works
    2. Add your fully working driver out-of-tree
  • mesh777 said:
    I need to make it out-of-tree anyway, could you please check how to proceed with that.

    I talked to the developer of the out-of-tree-driver examples and got some hints on how to go about this.

    1. First, add your custom SPI flash driver like done in the out_of_tree_driver example
    2. Remove the header file in https://github.com/nrfconnect/sdk-zephyr/tree/v3.0.99-ncs1/samples/application_development/out_of_tree_driver/hello_world_module/zephyr
    3. Use #include <drivers/flash.h> in your driver and implement all the functions needed from flash.h"
    4. Instead of zephyr_library(), use zephyr_library_amend(), like done in lpuart
      • Read about the zephyr_library amend future in PR 19980 
    5. Put your driver/CMakeList.txt into the file structure <zephyr_module_oot>/drivers/flash, like explained here.
    6. Set CONFIG_FLASH_NRF_FORCE_ALT=y in <ncs>/bootloader/mcuboot/boot/zephyr/prj.conf (or through the main application using the approaches in this ticket)
    7. Make sure your custom flash driver is visible to mcuboot. For example if you have made an if statement like this then you need to make sure CONFIG_HELLO_WORLD_DRIVER=y in mcuboot.

    Also, the developer I talked to said that it may be simpler to just maintan a fork of NCS/nrf that has just that driver, instead of making it out-of-tree.

    Best regards,

    Simon

  • Thanks a lot for detailed information. I managed to make that driver is found and init function is called.

    I have some more questions: 

    Where to put/how to reference at25xe081.yaml in the module? At the moment I have same problem as before that dts property is not found.

    How to include files to the module from the project? I have shared files between module and application (driver itself is used by application and the wrapper inside the module). So module has to find source file and header files which belong to project tree.

Related