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
  • mesh777 said:

    And placed it in the same folder of project files, where my_board.dts resides. But still get the same error.

    Also I tried to modify my_board.yaml and added include of the new file, but it did not change anything.

    Try placing it in the same folder as jedec,spi-nor.yaml, the folder zephyr/dts/bindings/mtd.

    This section may be useful to learn more about compatible/bindings: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.2/zephyr/build/dts/bindings.html 

    mesh777 said:
    At the end it is important that MCUBoot builds using the new driver and I am not sure where to place files in order to accomplish that. Can these files be part of project or I have to modify SDK folder (that we want to avoid if possible).

    I'm not sure how to add a dts bindings out of tree. However, adding it directly to Zephyr might not be a bad idea, then you could create a Pull Request at the end, making your driver a part of Zephyr upstream (and Nordic Zephyr downstream). If this is not preferable, let me know, and I can look into do this out-of-tree.

Children
  • If this is not preferable, let me know, and I can look into do this out-of-tree.

    Many thanks for fast response.

    Yes, I think it would be better to have out-of-tree solution.

  • Try adding the binding to your board folder like it's done here (<board>/dts/bindings): https://github.com/nrfconnect/sdk-nrf/tree/v2.0.2/boards/arm/thingy91_nrf9160/dts/bindings.

    Regarding adding your driver out-of-tree, I'm not sure if it will work by simply following this approach: https://github.com/nrfconnect/sdk-zephyr/tree/v3.0.99-ncs1/samples/application_development/out_of_tree_driver, since your driver should not be used directly, but rather through the flash.h API. The other flash drivers are put in https://github.com/nrfconnect/sdk-zephyr/tree/v3.0.99-ncs1/drivers/flash.

    I'll ask internally tomorrow how to go about this.

    I realized that it might be possible that the spi_nor driver actually supports the at25xe081, I'll look into this as well.

  • Is it possible to run debugger in bootloader (using VS Code) ?

    I managed to build the project, however get the following error from the bootloader:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    *** Booting Zephyr OS build v2.7.0-ncs1 ***
    00> I: Starting bootloader
    00> W: Failed reading sectors; BOOT_MAX_IMG_SECTORS=128 - too small?
    00> E: ***** MPU FAULT *****
    00> E: Instruction Access Violation
    00> E: r0/a1: 0x00000000 r1/a2: 0x00000000 r2/a3: 0x20000284
    00> E: r3/a4: 0x00000020 r12/ip: 0xe6f7fbb5 r14/lr: 0x00000e4f
    00> E: xpsr: 0x61000000
    00> E: Faulting instruction address (r15/pc): 0xe6f7fbb4
    00> E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
    00> E: Current thread: 0x20000128 (unknown)
    00> E: Resetting system
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    And this is my pm_static.yml:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    external_flash:
    address: 0x0
    region: external_flash
    size: 0x800000
    app:
    address: 0xc200
    end_address: 0x6DC80
    region: flash_primary
    size: 0x61A80
    mcuboot:
    address: 0x0
    end_address: 0xc000
    placement:
    before:
    - mcuboot_primary
    region: flash_primary
    size: 0xc000
    mcuboot_pad:
    address: 0xc000
    end_address: 0xc200
    placement:
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • I just talked to a colleague familiar with this stuff, and asked if at25xe081 was supported by the spi_nor driver. He said as far as he knew, most of the NOR chips should be supported by the spi_nor driver, and most of the commands from the data sheets seems to be generic, so it should not be a problem as far as he knew.

    To get more details, and a more certain answer, try to ask the Zephyr experts on Zephyr Discord, if at25xe081 is supported by the spi_nor driver (Maybe add a link to the data sheet). If that is the case, you may save a lot of time.

    Best regards,

    Simon

  • Thank you for information, Simon.

    Maybe you can also provide a hint on how to debug the bootloader?