This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

write protection mechanism is not working in the internal flash of nrf5340 dk

Hi ,

My environment :

  1. nrf connect sdk
  2. nrf5340 dk
  3. segger studio IDE

verified method 1:

As per nrf5340 product specification document , we can protect the flash erase and flash write operations using write protection.

CONFIG is a register in NVMC . we can set read only access when set 0 in CONFIG register
NRF_NVMC->CONFIG = 0; // read only access
but, I am able to erase the flash and write the flash. It should not happen.

Verified method 2:

As per below link

docs.zephyrproject.org/.../group__flash__interface_gaf0cda694a08f6bcf230b08790c12b3c2.html

If we want erase the flash and write the flash need to pass false in the second argument to the below function.

flash_write_protection_set(flash_dev, false);

If we want to protect the flash erase and flash write need to pass true in the second argument to the below function .

flash_write_protection_set(flash_dev, true);


but, I am able to erase the flash and write the flash even if pass true in the second argument .

Note : In two methods, I am not able to protect the erase and write operation in the internal flash . please let me know , how can I proceed to use write protection mechanism for block the erase and write flash.

Thanks & Regards,

Srinivas Rao.

Parents
  • Hi Srinivas,

    Can you explain in detail how you write protect and then erase, as it is not clear to me exactly what you do.

    Also note that the while the CONFIG register of the NVMC can be used to enable or disable flash operations, it can be changed at any time. There are other mechanisms that can be used to provide more protection, such as ACL. I am not sure what your use case and requirements is, though.

    Einar


  • Method 1:
    const struct device *dev;
    void erasefunction()    // NVMC header file included in my file.
    {
    NRF_NVMC->CONFIG = 0; // read only access so, it should not allow to erase or write operation
    flash_erase(dev, flash_page_address, 4096); // it will erase the page if write protection disable
    }

    it should not erase the page why because i have enabled write protection in the above function.

    void writefunction()  // NVMC header file included in my file.
    {
    NRF_NVMC->CONFIG = 0; // read only access so, it should not allow to erase or write operation
    flash_write(dev, flash_page_address, buf, 4096); // it will write the page if write protection disable
    }

    It should not write the page why because I have enabled write protection in the above function.

    Method 2:
    const struct device *dev;
    void erasefunction()
    {
    flash_write_protection_set(dev, true); // write protection enabled .so, it should not allow to erase or write operation
    flash_erase(dev, flash_page_address, 4096); // it will erase the page if write protection disable
    }

    it should not erase the page why because i have enabled write protection in the above function.

    void writefunction()
    {
    flash_write_protection_set(dev, true); // write protection enabled .so, it should not allow to erase or write operation
    flash_write(dev, flash_page_address, buf, 4096); // it will write the page if write protection disable
    }

    It should not write the page why because I have enabled write protection in the above function.

    I hope, you can understand as per above functionality

    how can I block the erase and write operations

  • Hi,

    Regarding flash_write_protection_set() that is implemented by flash_nrf_write_protection() zephyr\drivers\flash\soc_flash_nrf.c, and the implementation is empty. So that is not functional. I have not been able to clarify why that is yet.

    Regarding writing to the register directly that should work. But note that NRF_NVMC is only relevant for the network core, for the application core you have NRF_NVMC_NS and NRF_NVMC_S.

    Also, you you may memory barriers before writing immediately after, so something like this:

    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen; // or NVMC_CONFIG_WEN_Ren or NVMC_CONFIG_WEN_Een
    __DSB();
    __ISB();

  • As per your suggestion, I have updated code as shown in the below . still , I am able to write and erase the page in the flash.

    Method 1:
    const struct device *dev;
    void erasefunction() // NVMC header file included in my file.
    {

    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; // or NVMC_CONFIG_WEN_Wen or NVMC_CONFIG_WEN_Een
    __DSB();
    __ISB();
    flash_erase(dev, flash_page_address, 4096); // it will erase the page if write protection disable
    }

    it should not erase the page why because i have enabled write protection in the above function.

    void writefunction() // NVMC header file included in my file.
    {
    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; // or NVMC_CONFIG_WEN_Wen or NVMC_CONFIG_WEN_Een
    __DSB();
    __ISB();
    flash_write(dev, flash_page_address, buf, 4096); // it will write the page if write protection disable
    }

    For your information, NRF_NVMC macro defined in the below file

    \v1.5.0\zephyr\modules\hal_nordic\nrfx\nrfx_config_nrf5340_application.h 

    please let me know the solution for this issue. 

    Regards,

    Srinivas 

Reply
  • As per your suggestion, I have updated code as shown in the below . still , I am able to write and erase the page in the flash.

    Method 1:
    const struct device *dev;
    void erasefunction() // NVMC header file included in my file.
    {

    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; // or NVMC_CONFIG_WEN_Wen or NVMC_CONFIG_WEN_Een
    __DSB();
    __ISB();
    flash_erase(dev, flash_page_address, 4096); // it will erase the page if write protection disable
    }

    it should not erase the page why because i have enabled write protection in the above function.

    void writefunction() // NVMC header file included in my file.
    {
    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; // or NVMC_CONFIG_WEN_Wen or NVMC_CONFIG_WEN_Een
    __DSB();
    __ISB();
    flash_write(dev, flash_page_address, buf, 4096); // it will write the page if write protection disable
    }

    For your information, NRF_NVMC macro defined in the below file

    \v1.5.0\zephyr\modules\hal_nordic\nrfx\nrfx_config_nrf5340_application.h 

    please let me know the solution for this issue. 

    Regards,

    Srinivas 

Children
Related